Skip to content

Commit

Permalink
make progress bars global (in all pages)
Browse files Browse the repository at this point in the history
  • Loading branch information
hg42 committed Oct 18, 2022
1 parent ce4c6eb commit 09c8cf1
Show file tree
Hide file tree
Showing 13 changed files with 190 additions and 189 deletions.
1 change: 1 addition & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
android:installLocation="auto">

<!-- for Android 12 -->
<uses-permission android:name="android.permission.POST_NOTIFICATIONS" />
<uses-permission android:name="android.permission.SCHEDULE_EXACT_ALARM" />

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ import androidx.core.content.ContextCompat
import androidx.navigation.NavHostController
import com.google.accompanist.navigation.animation.rememberAnimatedNavController
import com.machiav3lli.backup.OABX
import com.machiav3lli.backup.preferences.persist_beenWelcomed
import com.machiav3lli.backup.R
import com.machiav3lli.backup.preferences.persist_beenWelcomed
import com.machiav3lli.backup.ui.compose.navigation.IntroNavHost
import com.machiav3lli.backup.ui.compose.navigation.NavItem
import com.machiav3lli.backup.ui.compose.theme.AppTheme
Expand All @@ -62,7 +62,7 @@ class IntroActivityX : BaseActivity() {

Scaffold(
containerColor = Color.Transparent,
contentColor = MaterialTheme.colorScheme.onBackground,
contentColor = MaterialTheme.colorScheme.onBackground
) { paddingValues ->
IntroNavHost(
modifier = Modifier.padding(paddingValues),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ import com.machiav3lli.backup.dialogs.PackagesListDialogFragment
import com.machiav3lli.backup.fragments.SortFilterSheet
import com.machiav3lli.backup.handler.LogsHandler
import com.machiav3lli.backup.handler.WorkHandler
import com.machiav3lli.backup.items.Package
import com.machiav3lli.backup.items.SortFilterModel
import com.machiav3lli.backup.preferences.persist_skippedEncryptionCounter
import com.machiav3lli.backup.preferences.pref_catchUncaughtException
Expand Down Expand Up @@ -105,8 +104,6 @@ class MainActivityX : BaseActivity() {

private lateinit var prefs: SharedPreferences
private val crScope: CoroutineScope = CoroutineScope(Dispatchers.Default)
private lateinit var refreshViewController: RefreshViewController // TODO replace
private lateinit var progressViewController: ProgressViewController // TODO replace

val viewModel by viewModels<MainViewModel> {
MainViewModel.Factory(ODatabase.getInstance(OABX.context), application)
Expand Down Expand Up @@ -304,8 +301,11 @@ class MainActivityX : BaseActivity() {
}
}
},
bottomBar = { BottomNavBar(page = NAV_MAIN, navController = navController) }
bottomBar = {
BottomNavBar(page = NAV_MAIN, navController = navController)
}
) { paddingValues ->

MainNavHost(
modifier = Modifier.padding(paddingValues),
navController = navController,
Expand All @@ -330,6 +330,7 @@ class MainActivityX : BaseActivity() {
super.onDestroy()
}

@Deprecated("Deprecated in Java")
override fun onBackPressed() {
finishAffinity()
}
Expand Down Expand Up @@ -378,27 +379,16 @@ class MainActivityX : BaseActivity() {
viewModel.updatePackage(packageName)
}

fun setRefreshViewController(refreshViewController: RefreshViewController) {
this.refreshViewController = refreshViewController
}

fun refreshView() {
crScope.launch { _modelSortFilter.emit(sortFilterModel) }
if (::refreshViewController.isInitialized) refreshViewController.refreshView(viewModel.packageList.value)
}

fun setProgressViewController(progressViewController: ProgressViewController) {
this.progressViewController = progressViewController
}

fun updateProgress(progress: Int, max: Int) {
if (::progressViewController.isInitialized)
this.progressViewController.updateProgress(progress, max)
viewModel.progress.value = Pair(true, 1f*progress/max)
}

fun hideProgress() {
if (::progressViewController.isInitialized)
this.progressViewController.hideProgress()
viewModel.progress.value = Pair(false, 0f)
}

fun showSnackBar(message: String) {
Expand Down Expand Up @@ -495,12 +485,3 @@ class MainActivityX : BaseActivity() {
}
}
}

interface RefreshViewController {
fun refreshView(list: MutableList<Package>?)
}

interface ProgressViewController {
fun updateProgress(progress: Int, max: Int)
fun hideProgress()
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import android.os.Bundle
import androidx.activity.compose.setContent
import androidx.activity.viewModels
import androidx.compose.animation.ExperimentalAnimationApi
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.material3.ExperimentalMaterial3Api
Expand Down Expand Up @@ -82,22 +83,24 @@ class PrefsActivityX : BaseActivity() {
containerColor = Color.Transparent,
contentColor = MaterialTheme.colorScheme.onBackground,
topBar = {
TopBar(
title = stringResource(id = pageTitle ?: NavItem.Settings.title)
) {
RoundButton(
modifier = Modifier
.padding(horizontal = 4.dp)
.size(32.dp),
icon = Phosphor.Info,
description = stringResource(id = R.string.help),
) {
if (helpSheet != null && helpSheet!!.isVisible) helpSheet?.dismissAllowingStateLoss()
helpSheet = HelpSheet()
helpSheet!!.showNow(supportFragmentManager, "HELPSHEET")
Column {
TopBar(
title = stringResource(id = pageTitle ?: NavItem.Settings.title)
) {
RoundButton(
modifier = Modifier
.padding(horizontal = 4.dp)
.size(32.dp),
icon = Phosphor.Info,
description = stringResource(id = R.string.help),
) {
if (helpSheet != null && helpSheet!!.isVisible) helpSheet?.dismissAllowingStateLoss()
helpSheet = HelpSheet()
helpSheet!!.showNow(supportFragmentManager, "HELPSHEET")
}
}
}
}
},
},
bottomBar = { BottomNavBar(page = NAV_PREFS, navController = navController) }
) { paddingValues ->
PrefsNavHost(
Expand Down
13 changes: 0 additions & 13 deletions app/src/main/java/com/machiav3lli/backup/pages/BatchPage.kt
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
*/
package com.machiav3lli.backup.pages

import androidx.compose.animation.AnimatedVisibility
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
Expand All @@ -26,7 +25,6 @@ import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.material3.LinearProgressIndicator
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Scaffold
import androidx.compose.runtime.Composable
Expand Down Expand Up @@ -105,8 +103,6 @@ fun BatchPage(viewModel: BatchViewModel, backupBoolean: Boolean) {
)
}

val refreshing by viewModel.refreshing.observeAsState()
val progress by viewModel.progress.observeAsState(Pair(false, 0f))
val batchConfirmListener = object : BatchDialogFragment.ConfirmListener {
override fun onConfirmed(selectedPackages: List<String?>, selectedModes: List<Int>) {
mainActivityX.startBatchAction(backupBoolean, selectedPackages, selectedModes) {
Expand All @@ -133,15 +129,6 @@ fun BatchPage(viewModel: BatchViewModel, backupBoolean: Boolean) {
.padding(paddingValues)
.fillMaxSize()
) {
AnimatedVisibility(visible = refreshing ?: false) {
LinearProgressIndicator(modifier = Modifier.fillMaxWidth())
}
AnimatedVisibility(visible = progress?.first == true) {
LinearProgressIndicator(
modifier = Modifier.fillMaxWidth(),
progress = progress.second
)
}
BatchPackageRecycler(
modifier = Modifier
.weight(1f)
Expand Down
16 changes: 0 additions & 16 deletions app/src/main/java/com/machiav3lli/backup/pages/HomePage.kt
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.wrapContentHeight
import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.material3.LinearProgressIndicator
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Scaffold
import androidx.compose.runtime.Composable
Expand All @@ -47,7 +46,6 @@ import com.machiav3lli.backup.ALT_MODE_APK
import com.machiav3lli.backup.ALT_MODE_BOTH
import com.machiav3lli.backup.ALT_MODE_DATA
import com.machiav3lli.backup.ALT_MODE_UNSET
import com.machiav3lli.backup.OABX
import com.machiav3lli.backup.R
import com.machiav3lli.backup.activities.MainActivityX
import com.machiav3lli.backup.dialogs.BatchDialogFragment
Expand Down Expand Up @@ -82,17 +80,12 @@ fun HomePage(viewModel: HomeViewModel) {
val query by mainActivityX.searchQuery.collectAsState(initial = "")
val updatedApps = filteredList?.filter { it.isUpdated }
var updatedVisible by remember(viewModel.filteredList.value) { mutableStateOf(false) }
OABX.main?.viewModel?.isNeedRefresh?.observeForever {
viewModel.refreshing.postValue(it)
}

val filterPredicate = { item: Package ->
query.isEmpty() || listOf(item.packageName, item.packageLabel)
.find { it.contains(query, true) } != null
}
val queriedList = filteredList?.filter(filterPredicate)
val refreshing by viewModel.refreshing.observeAsState()
val progress by viewModel.progress.observeAsState(Pair(false, 0f))

val batchConfirmListener = object : BatchDialogFragment.ConfirmListener {
override fun onConfirmed(selectedPackages: List<String?>, selectedModes: List<Int>) {
Expand Down Expand Up @@ -120,15 +113,6 @@ fun HomePage(viewModel: HomeViewModel) {
.padding(paddingValues)
.fillMaxSize()
) {
AnimatedVisibility(visible = refreshing ?: false) {
LinearProgressIndicator(modifier = Modifier.fillMaxWidth())
}
AnimatedVisibility(visible = progress?.first == true) {
LinearProgressIndicator(
modifier = Modifier.fillMaxWidth(),
progress = progress.second
)
}
HomePackageRecycler(
modifier = Modifier
.weight(1f)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,12 @@
*/
package com.machiav3lli.backup.pages

import androidx.compose.animation.AnimatedVisibility
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.material3.LinearProgressIndicator
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Scaffold
import androidx.compose.runtime.Composable
Expand Down Expand Up @@ -52,16 +50,9 @@ fun SchedulerPage(viewModel: SchedulerViewModel) {
val context = LocalContext.current
var sheetSchedule: ScheduleSheet? = null
val schedules by viewModel.schedules.observeAsState(null)
val progress by viewModel.progress.observeAsState(Pair(false, 0f))

Scaffold(containerColor = Color.Transparent) { paddingValues ->
Column {
AnimatedVisibility(visible = progress?.first == true) {
LinearProgressIndicator(
modifier = Modifier.fillMaxWidth(),
progress = progress.second
)
}
ScheduleRecycler(
modifier = Modifier
.padding(paddingValues)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ fun BatchPackageItem(
}
)
}
Timber.i("recompose BatchPackageItem ${packageItem.packageName}")
//Timber.i("recompose BatchPackageItem ${packageItem.packageName}")

OutlinedCard(
modifier = Modifier,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ fun MainPackageItem(

val menuExpanded = remember { mutableStateOf(false) }

Timber.i("recompose MainPackageItem ${packageItem.packageName}")
//Timber.i("recompose MainPackageItem ${packageItem.packageName}")

OutlinedCard(
modifier = Modifier,
Expand Down
Loading

0 comments on commit 09c8cf1

Please sign in to comment.