Skip to content

Commit

Permalink
Fix the Status update logic (Touches #279)
Browse files Browse the repository at this point in the history
Signed-off-by: LooKeR <[email protected]>
  • Loading branch information
Iamlooker committed Mar 13, 2023
1 parent f2818b0 commit 64ecc31
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -909,23 +909,16 @@ class AppDetailAdapter(private val callbacks: Callbacks) :
set(value) {
if (field != value) {
val index = items.indexOf(Item.InstallButtonItem)
if (index >= 0) notifyItemChanged(index)
if (index > 0) notifyItemChanged(index)
}
field = value
}

var status: Status = Status.Idle
set(value) {
val statusIndex = items.indexOf(Item.DownloadStatusItem)
if (field != value && statusIndex > 0) {
when (field) {
is Status.Downloading -> notifyItemChanged(statusIndex)
Status.Connecting -> notifyItemChanged(statusIndex)
Status.Installing -> notifyItemChanged(statusIndex)
Status.PendingInstall -> notifyItemInserted(statusIndex)
Status.Pending -> notifyItemInserted(statusIndex)
Status.Idle -> notifyItemRemoved(statusIndex)
}
if (field != value) {
val index = items.indexOf(Item.DownloadStatusItem)
if (index > 0) notifyItemChanged(index)
}
field = value
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ class AppDetailFragment() : ScreenFragment(), AppDetailAdapter.Callbacks {
emptyList<Pair<Product, Repository>>()
private var installed: Installed? = null
private var downloading = false
private var installing = false

private var recyclerView: RecyclerView? = null

Expand Down Expand Up @@ -259,10 +260,7 @@ class AppDetailFragment() : ScreenFragment(), AppDetailAdapter.Callbacks {
adapterState?.let { outState.putParcelable(STATE_ADAPTER, it) }
}

private fun updateButtons(
preference: ProductPreference = ProductPreferences[packageName],
installing: Boolean = false
) {
private fun updateButtons(preference: ProductPreference = ProductPreferences[packageName]) {
val installed = installed
val product = Product.findSuggested(
products,
Expand Down Expand Up @@ -299,10 +297,11 @@ class AppDetailFragment() : ScreenFragment(), AppDetailAdapter.Callbacks {
else -> null
}

val adapterAction =
if (downloading) AppDetailAdapter.Action.CANCEL else primaryAction?.adapterAction
(recyclerView?.adapter as? AppDetailAdapter)?.action =
if (installing) null else adapterAction
val adapterAction = if (downloading) AppDetailAdapter.Action.CANCEL
else if (installing) null
else primaryAction?.adapterAction

(recyclerView?.adapter as? AppDetailAdapter)?.action = adapterAction

for (action in sequenceOf(
Action.INSTALL,
Expand Down Expand Up @@ -347,7 +346,11 @@ class AppDetailFragment() : ScreenFragment(), AppDetailAdapter.Callbacks {
) AppDetailAdapter.Status.Installing
else if (packageName in installerState.queued) AppDetailAdapter.Status.PendingInstall
else AppDetailAdapter.Status.Idle
updateButtons(installing = status != AppDetailAdapter.Status.Idle)
val installing = status != AppDetailAdapter.Status.Idle
if (this.installing != installing) {
this.installing = installing
updateButtons()
}
(recyclerView?.adapter as? AppDetailAdapter)?.status = status
}

Expand Down

0 comments on commit 64ecc31

Please sign in to comment.