mirror of
https://github.com/Aviortheking/Neo-Store.git
synced 2025-04-23 11:22:12 +00:00
Update: Link secondary action and info buttons to adapter logic
This commit is contained in:
parent
bc6e02559a
commit
8d51d97d21
@ -337,6 +337,8 @@ class AppDetailAdapter(private val callbacks: Callbacks) :
|
||||
val name = itemView.findViewById<MaterialTextView>(R.id.name)!!
|
||||
val packageName = itemView.findViewById<MaterialTextView>(R.id.package_name)!!
|
||||
val action = itemView.findViewById<MaterialButton>(R.id.action)!!
|
||||
val secondaryAction = itemView.findViewById<MaterialButton>(R.id.secondary_action)!!
|
||||
val info = itemView.findViewById<MaterialButton>(R.id.info)!!
|
||||
val statusLayout = itemView.findViewById<View>(R.id.status_layout)!!
|
||||
val status = itemView.findViewById<MaterialTextView>(R.id.status)!!
|
||||
val progress = itemView.findViewById<LinearProgressIndicator>(R.id.progress)!!
|
||||
@ -877,6 +879,7 @@ class AppDetailAdapter(private val callbacks: Callbacks) :
|
||||
}
|
||||
|
||||
private var action: Action? = null
|
||||
private var secondaryAction: Action? = null
|
||||
|
||||
fun setAction(action: Action?) {
|
||||
if (this.action != action) {
|
||||
@ -894,6 +897,22 @@ class AppDetailAdapter(private val callbacks: Callbacks) :
|
||||
}
|
||||
}
|
||||
|
||||
fun setSecondaryAction(action: Action?) {
|
||||
if (this.secondaryAction != action) {
|
||||
val translate = this.secondaryAction == null || action == null ||
|
||||
this.secondaryAction == Action.CANCEL || action == Action.CANCEL
|
||||
this.secondaryAction = action
|
||||
val index = items.indexOfFirst { it is Item.AppInfoItem }
|
||||
if (index >= 0) {
|
||||
if (translate) {
|
||||
notifyItemChanged(index)
|
||||
} else {
|
||||
notifyItemChanged(index, Payload.REFRESH)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private var status: Status? = null
|
||||
|
||||
fun setStatus(status: Status?) {
|
||||
@ -929,7 +948,15 @@ class AppDetailAdapter(private val callbacks: Callbacks) :
|
||||
): RecyclerView.ViewHolder {
|
||||
return when (viewType) {
|
||||
ViewType.APP_INFO -> AppInfoViewHolder(parent.inflate(R.layout.item_app_info_x)).apply {
|
||||
action.setOnClickListener { this@AppDetailAdapter.action?.let(callbacks::onActionClick) }
|
||||
action.setOnClickListener {
|
||||
this@AppDetailAdapter.action?.let(callbacks::onActionClick)
|
||||
}
|
||||
secondaryAction.setOnClickListener {
|
||||
this@AppDetailAdapter.secondaryAction?.let(callbacks::onActionClick)
|
||||
}
|
||||
info.setOnClickListener {
|
||||
AppDetailAdapter.Action.DETAILS?.let(callbacks::onActionClick)
|
||||
}
|
||||
}
|
||||
ViewType.SCREENSHOT -> ScreenShotViewHolder(parent.context)
|
||||
ViewType.SWITCH -> SwitchViewHolder(parent.inflate(R.layout.switch_item)).apply {
|
||||
@ -1106,6 +1133,14 @@ class AppDetailAdapter(private val callbacks: Callbacks) :
|
||||
iconTint = if (action == Action.CANCEL) holder.actionTintOnCancel
|
||||
else holder.actionTintOnNormal
|
||||
}
|
||||
val secondaryAction = secondaryAction
|
||||
holder.secondaryAction.apply {
|
||||
visibility = if (secondaryAction == null) View.GONE else View.VISIBLE
|
||||
if (secondaryAction != null) {
|
||||
icon = context.getDrawable(secondaryAction.iconResId)
|
||||
}
|
||||
}
|
||||
holder.info.visibility = if (installed == null) View.GONE else View.VISIBLE
|
||||
}
|
||||
if (updateAll || updateStatus) {
|
||||
val status = status
|
||||
|
@ -251,23 +251,25 @@ class AppSheetX() : FullscreenBottomSheetDialogFragment(), AppDetailAdapter.Call
|
||||
canUpdate -> Action.UPDATE
|
||||
canLaunch -> Action.LAUNCH
|
||||
canInstall -> Action.INSTALL
|
||||
installed != null -> Action.DETAILS
|
||||
canShare -> Action.SHARE
|
||||
else -> null
|
||||
}
|
||||
val secondaryAction = when {
|
||||
primaryAction != Action.SHARE && canShare -> Action.SHARE
|
||||
primaryAction != Action.LAUNCH && canLaunch -> Action.LAUNCH
|
||||
installed != null && canUninstall -> Action.UNINSTALL
|
||||
else -> null
|
||||
}
|
||||
|
||||
launch(Dispatchers.Main) {
|
||||
val adapterAction =
|
||||
if (downloading) AppDetailAdapter.Action.CANCEL else primaryAction?.adapterAction
|
||||
(binding.recyclerView.adapter as? AppDetailAdapter)?.setAction(adapterAction)
|
||||
for (action in sequenceOf(
|
||||
Action.INSTALL,
|
||||
Action.SHARE,
|
||||
Action.UPDATE,
|
||||
Action.UNINSTALL
|
||||
)) {
|
||||
//toolbar.menu.findItem(action.id).isEnabled = !downloading
|
||||
}
|
||||
val adapterSecondaryAction =
|
||||
if (downloading) null else secondaryAction?.adapterAction
|
||||
(binding.recyclerView.adapter as? AppDetailAdapter)
|
||||
?.setAction(adapterAction)
|
||||
(binding.recyclerView.adapter as? AppDetailAdapter)
|
||||
?.setSecondaryAction(adapterSecondaryAction)
|
||||
}
|
||||
launch { this@AppSheetX.actions = Pair(actions, primaryAction) }
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user