|
|
@ -14,69 +14,37 @@ import androidx.lifecycle.Lifecycle
|
|
|
|
import androidx.lifecycle.LifecycleOwner
|
|
|
|
import androidx.lifecycle.LifecycleOwner
|
|
|
|
import androidx.lifecycle.lifecycleScope
|
|
|
|
import androidx.lifecycle.lifecycleScope
|
|
|
|
import androidx.lifecycle.repeatOnLifecycle
|
|
|
|
import androidx.lifecycle.repeatOnLifecycle
|
|
|
|
import androidx.recyclerview.widget.RecyclerView
|
|
|
|
|
|
|
|
import kotlinx.coroutines.launch
|
|
|
|
import kotlinx.coroutines.launch
|
|
|
|
import org.yuzu.yuzu_emu.R
|
|
|
|
import org.yuzu.yuzu_emu.R
|
|
|
|
import org.yuzu.yuzu_emu.databinding.CardHomeOptionBinding
|
|
|
|
import org.yuzu.yuzu_emu.databinding.CardHomeOptionBinding
|
|
|
|
import org.yuzu.yuzu_emu.fragments.MessageDialogFragment
|
|
|
|
import org.yuzu.yuzu_emu.fragments.MessageDialogFragment
|
|
|
|
import org.yuzu.yuzu_emu.model.HomeSetting
|
|
|
|
import org.yuzu.yuzu_emu.model.HomeSetting
|
|
|
|
|
|
|
|
import org.yuzu.yuzu_emu.viewholder.AbstractViewHolder
|
|
|
|
|
|
|
|
|
|
|
|
class HomeSettingAdapter(
|
|
|
|
class HomeSettingAdapter(
|
|
|
|
private val activity: AppCompatActivity,
|
|
|
|
private val activity: AppCompatActivity,
|
|
|
|
private val viewLifecycle: LifecycleOwner,
|
|
|
|
private val viewLifecycle: LifecycleOwner,
|
|
|
|
var options: List<HomeSetting>
|
|
|
|
options: List<HomeSetting>
|
|
|
|
) :
|
|
|
|
) : AbstractListAdapter<HomeSetting, HomeSettingAdapter.HomeOptionViewHolder>(options) {
|
|
|
|
RecyclerView.Adapter<HomeSettingAdapter.HomeOptionViewHolder>(),
|
|
|
|
|
|
|
|
View.OnClickListener {
|
|
|
|
|
|
|
|
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): HomeOptionViewHolder {
|
|
|
|
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): HomeOptionViewHolder {
|
|
|
|
val binding =
|
|
|
|
CardHomeOptionBinding.inflate(LayoutInflater.from(parent.context), parent, false)
|
|
|
|
CardHomeOptionBinding.inflate(LayoutInflater.from(parent.context), parent, false)
|
|
|
|
.also { return HomeOptionViewHolder(it) }
|
|
|
|
binding.root.setOnClickListener(this)
|
|
|
|
|
|
|
|
return HomeOptionViewHolder(binding)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
override fun getItemCount(): Int {
|
|
|
|
|
|
|
|
return options.size
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
override fun onBindViewHolder(holder: HomeOptionViewHolder, position: Int) {
|
|
|
|
|
|
|
|
holder.bind(options[position])
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
override fun onClick(view: View) {
|
|
|
|
|
|
|
|
val holder = view.tag as HomeOptionViewHolder
|
|
|
|
|
|
|
|
if (holder.option.isEnabled.invoke()) {
|
|
|
|
|
|
|
|
holder.option.onClick.invoke()
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
MessageDialogFragment.newInstance(
|
|
|
|
|
|
|
|
activity,
|
|
|
|
|
|
|
|
titleId = holder.option.disabledTitleId,
|
|
|
|
|
|
|
|
descriptionId = holder.option.disabledMessageId
|
|
|
|
|
|
|
|
).show(activity.supportFragmentManager, MessageDialogFragment.TAG)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
inner class HomeOptionViewHolder(val binding: CardHomeOptionBinding) :
|
|
|
|
inner class HomeOptionViewHolder(val binding: CardHomeOptionBinding) :
|
|
|
|
RecyclerView.ViewHolder(binding.root) {
|
|
|
|
AbstractViewHolder<HomeSetting>(binding) {
|
|
|
|
lateinit var option: HomeSetting
|
|
|
|
override fun bind(model: HomeSetting) {
|
|
|
|
|
|
|
|
binding.optionTitle.text = activity.resources.getString(model.titleId)
|
|
|
|
init {
|
|
|
|
binding.optionDescription.text = activity.resources.getString(model.descriptionId)
|
|
|
|
itemView.tag = this
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
fun bind(option: HomeSetting) {
|
|
|
|
|
|
|
|
this.option = option
|
|
|
|
|
|
|
|
binding.optionTitle.text = activity.resources.getString(option.titleId)
|
|
|
|
|
|
|
|
binding.optionDescription.text = activity.resources.getString(option.descriptionId)
|
|
|
|
|
|
|
|
binding.optionIcon.setImageDrawable(
|
|
|
|
binding.optionIcon.setImageDrawable(
|
|
|
|
ResourcesCompat.getDrawable(
|
|
|
|
ResourcesCompat.getDrawable(
|
|
|
|
activity.resources,
|
|
|
|
activity.resources,
|
|
|
|
option.iconId,
|
|
|
|
model.iconId,
|
|
|
|
activity.theme
|
|
|
|
activity.theme
|
|
|
|
)
|
|
|
|
)
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
when (option.titleId) {
|
|
|
|
when (model.titleId) {
|
|
|
|
R.string.get_early_access ->
|
|
|
|
R.string.get_early_access ->
|
|
|
|
binding.optionLayout.background =
|
|
|
|
binding.optionLayout.background =
|
|
|
|
ContextCompat.getDrawable(
|
|
|
|
ContextCompat.getDrawable(
|
|
|
@ -85,7 +53,7 @@ class HomeSettingAdapter(
|
|
|
|
)
|
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (!option.isEnabled.invoke()) {
|
|
|
|
if (!model.isEnabled.invoke()) {
|
|
|
|
binding.optionTitle.alpha = 0.5f
|
|
|
|
binding.optionTitle.alpha = 0.5f
|
|
|
|
binding.optionDescription.alpha = 0.5f
|
|
|
|
binding.optionDescription.alpha = 0.5f
|
|
|
|
binding.optionIcon.alpha = 0.5f
|
|
|
|
binding.optionIcon.alpha = 0.5f
|
|
|
@ -93,7 +61,7 @@ class HomeSettingAdapter(
|
|
|
|
|
|
|
|
|
|
|
|
viewLifecycle.lifecycleScope.launch {
|
|
|
|
viewLifecycle.lifecycleScope.launch {
|
|
|
|
viewLifecycle.repeatOnLifecycle(Lifecycle.State.CREATED) {
|
|
|
|
viewLifecycle.repeatOnLifecycle(Lifecycle.State.CREATED) {
|
|
|
|
option.details.collect { updateOptionDetails(it) }
|
|
|
|
model.details.collect { updateOptionDetails(it) }
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
binding.optionDetail.postDelayed(
|
|
|
|
binding.optionDetail.postDelayed(
|
|
|
@ -103,6 +71,20 @@ class HomeSettingAdapter(
|
|
|
|
},
|
|
|
|
},
|
|
|
|
3000
|
|
|
|
3000
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
binding.root.setOnClickListener { onClick(model) }
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private fun onClick(model: HomeSetting) {
|
|
|
|
|
|
|
|
if (model.isEnabled.invoke()) {
|
|
|
|
|
|
|
|
model.onClick.invoke()
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
MessageDialogFragment.newInstance(
|
|
|
|
|
|
|
|
activity,
|
|
|
|
|
|
|
|
titleId = model.disabledTitleId,
|
|
|
|
|
|
|
|
descriptionId = model.disabledMessageId
|
|
|
|
|
|
|
|
).show(activity.supportFragmentManager, MessageDialogFragment.TAG)
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private fun updateOptionDetails(detailString: String) {
|
|
|
|
private fun updateOptionDetails(detailString: String) {
|
|
|
|