diff --git a/src/main/kotlin/com/looker/droidify/ui/adapters/AppDetailAdapter.kt b/src/main/kotlin/com/looker/droidify/ui/adapters/AppDetailAdapter.kt index 19ef3288..c70549b5 100644 --- a/src/main/kotlin/com/looker/droidify/ui/adapters/AppDetailAdapter.kt +++ b/src/main/kotlin/com/looker/droidify/ui/adapters/AppDetailAdapter.kt @@ -337,6 +337,8 @@ class AppDetailAdapter(private val callbacks: Callbacks) : val name = itemView.findViewById(R.id.name)!! val packageName = itemView.findViewById(R.id.package_name)!! val action = itemView.findViewById(R.id.action)!! + val secondaryAction = itemView.findViewById(R.id.secondary_action)!! + val info = itemView.findViewById(R.id.info)!! val statusLayout = itemView.findViewById(R.id.status_layout)!! val status = itemView.findViewById(R.id.status)!! val progress = itemView.findViewById(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 diff --git a/src/main/kotlin/com/looker/droidify/ui/fragments/AppSheetX.kt b/src/main/kotlin/com/looker/droidify/ui/fragments/AppSheetX.kt index 93ffc584..162fed8b 100644 --- a/src/main/kotlin/com/looker/droidify/ui/fragments/AppSheetX.kt +++ b/src/main/kotlin/com/looker/droidify/ui/fragments/AppSheetX.kt @@ -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) } }