Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ fun RestorePackageItem(
onClick: (Package, Boolean, Boolean) -> Unit = { _: Package, _: Boolean, _: Boolean -> },
onBackupApkClick: (String, Boolean, Int) -> Unit = { _: String, _: Boolean, _: Int -> },
onBackupDataClick: (String, Boolean, Int) -> Unit = { _: String, _: Boolean, _: Int -> },
searchQuery: String = "",
) {
val packageItem by remember(item) { mutableStateOf(item) }
val apkBC by apkBackupChecked
Expand Down Expand Up @@ -239,9 +240,19 @@ fun RestorePackageItem(
)
}
}
item.backupsNewestFirst.forEachIndexed { index, item ->
// filter by note search, but keep the original indices of
// backupsNewestFirst, since they are used to address the
// backup to restore
val indexedBackups =
item.backupsNewestFirst.mapIndexed { index, backup -> index to backup }
val displayedBackups =
if (searchQuery.isEmpty()) indexedBackups
else indexedBackups
.filter { it.second.note.contains(searchQuery, ignoreCase = true) }
.ifEmpty { indexedBackups }
displayedBackups.forEach { (index, backup) ->
RestoreBackupItem(
item = item,
item = backup,
index = index,
isApkChecked = index == apkBC,
isDataChecked = index == dataBC,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ fun BatchPackageRecycler(
modifier: Modifier = Modifier,
productsList: PersistentList<Package>?,
restore: Boolean = false,
searchQuery: String = "",
apkBackupCheckedList: SnapshotStateMap<String, Int>,
dataBackupCheckedList: SnapshotStateMap<String, Int>,
onBackupApkClick: (String, Boolean, Int) -> Unit = { _: String, _: Boolean, _: Int -> },
Expand All @@ -129,6 +130,7 @@ fun BatchPackageRecycler(
onClick,
onBackupApkClick,
onBackupDataClick,
searchQuery,
)
else BatchPackageItem(
it,
Expand Down
4 changes: 3 additions & 1 deletion src/main/java/com/machiav3lli/backup/ui/pages/AppPage.kt
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ import com.machiav3lli.backup.ui.dialogs.RestoreDialogUI
import com.machiav3lli.backup.ui.dialogs.StringInputDialogUI
import com.machiav3lli.backup.utils.BackupShareUtils
import com.machiav3lli.backup.utils.TraceUtils
import com.machiav3lli.backup.utils.applyNoteSearch
import com.machiav3lli.backup.utils.extensions.koinNeoViewModel
import com.machiav3lli.backup.utils.infoChips
import com.machiav3lli.backup.viewmodels.AppVM
Expand All @@ -121,6 +122,7 @@ import timber.log.Timber
@Composable
fun AppPage(
packageName: String,
searchQuery: String = "",
viewModel: AppVM = koinNeoViewModel(),
onDismiss: () -> Unit,
) {
Expand Down Expand Up @@ -502,7 +504,7 @@ fun AppPage(
}
}
this.items(
items = pkg.backupsNewestFirst,
items = pkg.backupsNewestFirst.applyNoteSearch(searchQuery),
span = { GridItemSpan(columns) }) {
BackupItem(
it,
Expand Down
1 change: 1 addition & 0 deletions src/main/java/com/machiav3lli/backup/ui/pages/BatchPage.kt
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,7 @@ fun BatchPage(
.fillMaxSize(),
productsList = state.filteredPackages,
restore = !backupBoolean,
searchQuery = state.searchQuery,
apkBackupCheckedList = viewModel.apkBackupCheckedList,
dataBackupCheckedList = viewModel.dataBackupCheckedList,
onBackupApkClick = { packageName: String, b: Boolean, i: Int ->
Expand Down
1 change: 1 addition & 0 deletions src/main/java/com/machiav3lli/backup/ui/pages/HomePage.kt
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,7 @@ fun HomePage(
AnimatedPane {
AppPage(
packageName = packageName,
searchQuery = mainState.searchQuery,
onDismiss = onDismiss,
)
}
Expand Down
12 changes: 11 additions & 1 deletion src/main/java/com/machiav3lli/backup/utils/FilterUtils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ import com.machiav3lli.backup.R
import com.machiav3lli.backup.Sort
import com.machiav3lli.backup.UpdatedFilter
import com.machiav3lli.backup.data.dbs.entity.AppExtras
import com.machiav3lli.backup.data.dbs.entity.Backup
import com.machiav3lli.backup.data.entity.Package
import com.machiav3lli.backup.data.entity.SortFilterModel
import com.machiav3lli.backup.data.entity.SpecialFilter
Expand Down Expand Up @@ -106,9 +107,18 @@ fun Collection<Package>.applySearch(
)
)
.any { it.contains(query, ignoreCase = true) }
)
) || item.backupList.any { it.note.contains(query, ignoreCase = true) }
}

/**
* Filters a list of backups by matching their note against the search query.
* Falls back to the full list when no backup's note matches
* (e.g. when the app was found by its name instead of a note).
*/
fun List<Backup>.applyNoteSearch(query: String): List<Backup> =
if (query.isEmpty()) this
else filter { it.note.contains(query, ignoreCase = true) }.ifEmpty { this }

fun Collection<Package>.applyFilter(
filter: SortFilterModel,
tagsMap: Map<String, Set<String>>,
Expand Down