Improve: Remove "Installed" Notification after 5 seconds

Improve: Scrolling performance in AppDetail
This commit is contained in:
LooKeR 2021-12-19 23:29:54 +05:30
parent 26902110f1
commit 6eb3b96a83
2 changed files with 84 additions and 61 deletions

View File

@ -93,6 +93,8 @@ class InstallerService : Service() {
Common.NOTIFICATION_ID_DOWNLOADING, Common.NOTIFICATION_ID_DOWNLOADING,
notification notification
) )
Thread.sleep(5000)
notificationManager.cancel(notificationTag, Common.NOTIFICATION_ID_DOWNLOADING)
} }
} }
PackageInstaller.STATUS_FAILURE_ABORTED -> { PackageInstaller.STATUS_FAILURE_ABORTED -> {

View File

@ -256,9 +256,11 @@ class AppDetailFragment() : ScreenFragment(), AppDetailAdapter.Callbacks {
updateButtons(ProductPreferences[packageName]) updateButtons(ProductPreferences[packageName])
} }
private suspend fun updateButtons(preference: ProductPreference) { private suspend fun updateButtons(preference: ProductPreference) =
withContext(Dispatchers.Default) {
val installed = installed val installed = installed
val product = Product.findSuggested(products, installed?.installedItem) { it.first }?.first val product =
Product.findSuggested(products, installed?.installedItem) { it.first }?.first
val compatible = product != null && product.selectedReleases.firstOrNull() val compatible = product != null && product.selectedReleases.firstOrNull()
.let { it != null && it.incompatibilities.isEmpty() } .let { it != null && it.incompatibilities.isEmpty() }
val canInstall = product != null && installed == null && compatible val canInstall = product != null && installed == null && compatible
@ -271,24 +273,36 @@ class AppDetailFragment() : ScreenFragment(), AppDetailAdapter.Callbacks {
val canShare = product != null && products[0].second.name == "F-Droid" val canShare = product != null && products[0].second.name == "F-Droid"
val actions = mutableSetOf<Action>() val actions = mutableSetOf<Action>()
launch {
if (canInstall) { if (canInstall) {
actions += Action.INSTALL actions += Action.INSTALL
} }
}
launch {
if (canUpdate) { if (canUpdate) {
actions += Action.UPDATE actions += Action.UPDATE
} }
}
launch {
if (canLaunch) { if (canLaunch) {
actions += Action.LAUNCH actions += Action.LAUNCH
} }
}
launch {
if (installed != null) { if (installed != null) {
actions += Action.DETAILS actions += Action.DETAILS
} }
}
launch {
if (canUninstall) { if (canUninstall) {
actions += Action.UNINSTALL actions += Action.UNINSTALL
} }
}
launch {
if (canShare) { if (canShare) {
actions += Action.SHARE actions += Action.SHARE
} }
}
val primaryAction = when { val primaryAction = when {
canUpdate -> Action.UPDATE canUpdate -> Action.UPDATE
canLaunch -> Action.LAUNCH canLaunch -> Action.LAUNCH
@ -298,10 +312,10 @@ class AppDetailFragment() : ScreenFragment(), AppDetailAdapter.Callbacks {
else -> null else -> null
} }
launch(Dispatchers.Main) {
val adapterAction = val adapterAction =
if (downloading) AppDetailAdapter.Action.CANCEL else primaryAction?.adapterAction if (downloading) AppDetailAdapter.Action.CANCEL else primaryAction?.adapterAction
(recyclerView?.adapter as? AppDetailAdapter)?.setAction(adapterAction) (recyclerView?.adapter as? AppDetailAdapter)?.setAction(adapterAction)
for (action in sequenceOf( for (action in sequenceOf(
Action.INSTALL, Action.INSTALL,
Action.SHARE, Action.SHARE,
@ -310,19 +324,22 @@ class AppDetailFragment() : ScreenFragment(), AppDetailAdapter.Callbacks {
)) { )) {
toolbar.menu.findItem(action.id).isEnabled = !downloading toolbar.menu.findItem(action.id).isEnabled = !downloading
} }
this.actions = Pair(actions, primaryAction) }
withContext(Dispatchers.Main) { updateToolbarButtons() } launch { this@AppDetailFragment.actions = Pair(actions, primaryAction) }
launch(Dispatchers.Main) { updateToolbarButtons() }
} }
private suspend fun updateToolbarTitle() { private suspend fun updateToolbarTitle() {
withContext(Dispatchers.Main) { withContext(Dispatchers.Main) {
val showPackageName = recyclerView val showPackageName = recyclerView
?.let { (it.layoutManager as LinearLayoutManager).findFirstVisibleItemPosition() != 0 } == true ?.let { (it.layoutManager as LinearLayoutManager).findFirstVisibleItemPosition() != 0 } == true
launch {
collapsingToolbar.title = collapsingToolbar.title =
if (showPackageName) products[0].first.name.trimAfter(' ', 2) if (showPackageName) products[0].first.name.trimAfter(' ', 2)
else getString(R.string.application) else getString(R.string.application)
} }
} }
}
private suspend fun updateToolbarButtons() { private suspend fun updateToolbarButtons() {
withContext(Dispatchers.Default) { withContext(Dispatchers.Default) {
@ -330,12 +347,16 @@ class AppDetailFragment() : ScreenFragment(), AppDetailAdapter.Callbacks {
val showPrimaryAction = recyclerView val showPrimaryAction = recyclerView
?.let { (it.layoutManager as LinearLayoutManager).findFirstVisibleItemPosition() != 0 } == true ?.let { (it.layoutManager as LinearLayoutManager).findFirstVisibleItemPosition() != 0 } == true
val displayActions = actions.toMutableSet() val displayActions = actions.toMutableSet()
launch {
if (!showPrimaryAction && primaryAction != null) { if (!showPrimaryAction && primaryAction != null) {
displayActions -= primaryAction displayActions -= primaryAction
} }
}
launch {
if (displayActions.size >= 4 && resources.configuration.screenWidthDp < 400) { if (displayActions.size >= 4 && resources.configuration.screenWidthDp < 400) {
displayActions -= Action.DETAILS displayActions -= Action.DETAILS
} }
}
launch(Dispatchers.Main) { launch(Dispatchers.Main) {
for (action in Action.values()) for (action in Action.values())