mirror of
https://github.com/Aviortheking/Neo-Store.git
synced 2025-04-23 19:32:16 +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 name = itemView.findViewById<MaterialTextView>(R.id.name)!!
|
||||||
val packageName = itemView.findViewById<MaterialTextView>(R.id.package_name)!!
|
val packageName = itemView.findViewById<MaterialTextView>(R.id.package_name)!!
|
||||||
val action = itemView.findViewById<MaterialButton>(R.id.action)!!
|
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 statusLayout = itemView.findViewById<View>(R.id.status_layout)!!
|
||||||
val status = itemView.findViewById<MaterialTextView>(R.id.status)!!
|
val status = itemView.findViewById<MaterialTextView>(R.id.status)!!
|
||||||
val progress = itemView.findViewById<LinearProgressIndicator>(R.id.progress)!!
|
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 action: Action? = null
|
||||||
|
private var secondaryAction: Action? = null
|
||||||
|
|
||||||
fun setAction(action: Action?) {
|
fun setAction(action: Action?) {
|
||||||
if (this.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
|
private var status: Status? = null
|
||||||
|
|
||||||
fun setStatus(status: Status?) {
|
fun setStatus(status: Status?) {
|
||||||
@ -929,7 +948,15 @@ class AppDetailAdapter(private val callbacks: Callbacks) :
|
|||||||
): RecyclerView.ViewHolder {
|
): RecyclerView.ViewHolder {
|
||||||
return when (viewType) {
|
return when (viewType) {
|
||||||
ViewType.APP_INFO -> AppInfoViewHolder(parent.inflate(R.layout.item_app_info_x)).apply {
|
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.SCREENSHOT -> ScreenShotViewHolder(parent.context)
|
||||||
ViewType.SWITCH -> SwitchViewHolder(parent.inflate(R.layout.switch_item)).apply {
|
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
|
iconTint = if (action == Action.CANCEL) holder.actionTintOnCancel
|
||||||
else holder.actionTintOnNormal
|
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) {
|
if (updateAll || updateStatus) {
|
||||||
val status = status
|
val status = status
|
||||||
|
@ -251,23 +251,25 @@ class AppSheetX() : FullscreenBottomSheetDialogFragment(), AppDetailAdapter.Call
|
|||||||
canUpdate -> Action.UPDATE
|
canUpdate -> Action.UPDATE
|
||||||
canLaunch -> Action.LAUNCH
|
canLaunch -> Action.LAUNCH
|
||||||
canInstall -> Action.INSTALL
|
canInstall -> Action.INSTALL
|
||||||
installed != null -> Action.DETAILS
|
|
||||||
canShare -> Action.SHARE
|
canShare -> Action.SHARE
|
||||||
else -> null
|
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) {
|
launch(Dispatchers.Main) {
|
||||||
val adapterAction =
|
val adapterAction =
|
||||||
if (downloading) AppDetailAdapter.Action.CANCEL else primaryAction?.adapterAction
|
if (downloading) AppDetailAdapter.Action.CANCEL else primaryAction?.adapterAction
|
||||||
(binding.recyclerView.adapter as? AppDetailAdapter)?.setAction(adapterAction)
|
val adapterSecondaryAction =
|
||||||
for (action in sequenceOf(
|
if (downloading) null else secondaryAction?.adapterAction
|
||||||
Action.INSTALL,
|
(binding.recyclerView.adapter as? AppDetailAdapter)
|
||||||
Action.SHARE,
|
?.setAction(adapterAction)
|
||||||
Action.UPDATE,
|
(binding.recyclerView.adapter as? AppDetailAdapter)
|
||||||
Action.UNINSTALL
|
?.setSecondaryAction(adapterSecondaryAction)
|
||||||
)) {
|
|
||||||
//toolbar.menu.findItem(action.id).isEnabled = !downloading
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
launch { this@AppSheetX.actions = Pair(actions, primaryAction) }
|
launch { this@AppSheetX.actions = Pair(actions, primaryAction) }
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user