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,
notification
)
Thread.sleep(5000)
notificationManager.cancel(notificationTag, Common.NOTIFICATION_ID_DOWNLOADING)
}
}
PackageInstaller.STATUS_FAILURE_ABORTED -> {

View File

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