[Backup & Restore] Code Cleanup
This commit is contained in:
parent
ab5015d4b1
commit
cbf410f0cd
3 changed files with 23 additions and 12 deletions
|
@ -47,7 +47,7 @@ class BackupFragment : Fragment(R.layout.fragment_backup), BackupAdapter.BackupC
|
|||
else
|
||||
backupAdapter?.swapDataset(listOf())
|
||||
}
|
||||
backupViewModel.loadBackups()
|
||||
backupViewModel.loadBackups(requireContext())
|
||||
val openFilePicker = registerForActivityResult(ActivityResultContracts.OpenDocument()) {
|
||||
lifecycleScope.launch(Dispatchers.IO) {
|
||||
it?.let {
|
||||
|
@ -95,11 +95,11 @@ class BackupFragment : Fragment(R.layout.fragment_backup), BackupAdapter.BackupC
|
|||
MaterialDialog(requireContext()).show {
|
||||
cornerRadius(res = R.dimen.m3_card_corner_radius)
|
||||
title(res = R.string.action_rename)
|
||||
input(prefill = System.currentTimeMillis().toString()) { _, text ->
|
||||
input(prefill = BackupHelper.getTimeStamp()) { _, text ->
|
||||
// Text submitted with the action button
|
||||
lifecycleScope.launch {
|
||||
BackupHelper.createBackup(requireContext(), text.sanitize())
|
||||
backupViewModel.loadBackups()
|
||||
backupViewModel.loadBackups(requireContext())
|
||||
}
|
||||
}
|
||||
positiveButton(android.R.string.ok)
|
||||
|
@ -129,7 +129,7 @@ class BackupFragment : Fragment(R.layout.fragment_backup), BackupAdapter.BackupC
|
|||
Toast.LENGTH_SHORT
|
||||
).show()
|
||||
}
|
||||
backupViewModel.loadBackups()
|
||||
backupViewModel.loadBackups(requireContext())
|
||||
return true
|
||||
}
|
||||
R.id.action_share -> {
|
||||
|
@ -147,10 +147,10 @@ class BackupFragment : Fragment(R.layout.fragment_backup), BackupAdapter.BackupC
|
|||
input(prefill = file.nameWithoutExtension) { _, text ->
|
||||
// Text submitted with the action button
|
||||
val renamedFile =
|
||||
File(file.parent + File.separator + text + BackupHelper.APPEND_EXTENSION)
|
||||
File(file.parent, "$text${BackupHelper.APPEND_EXTENSION}")
|
||||
if (!renamedFile.exists()) {
|
||||
file.renameTo(renamedFile)
|
||||
backupViewModel.loadBackups()
|
||||
backupViewModel.loadBackups(requireContext())
|
||||
} else {
|
||||
Toast.makeText(
|
||||
requireContext(),
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package code.name.monkey.retromusic.fragments.backup
|
||||
|
||||
import android.app.Activity
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import androidx.lifecycle.LiveData
|
||||
import androidx.lifecycle.MutableLiveData
|
||||
|
@ -19,8 +20,8 @@ class BackupViewModel : ViewModel() {
|
|||
private val backupsMutableLiveData = MutableLiveData<List<File>>()
|
||||
val backupsLiveData: LiveData<List<File>> = backupsMutableLiveData
|
||||
|
||||
fun loadBackups() {
|
||||
File(BackupHelper.backupRootPath).listFiles { _, name ->
|
||||
fun loadBackups(context: Context) {
|
||||
BackupHelper.getBackupRoot(context).listFiles { _, name ->
|
||||
return@listFiles name.endsWith(BackupHelper.BACKUP_EXTENSION)
|
||||
}?.toList()?.let {
|
||||
backupsMutableLiveData.value = it
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue