Update local backup timestamp after manual export

pull/1136/head
Alex Baker 4 years ago
parent a0b02c7e9c
commit 823b7a0650

@ -1,9 +1,12 @@
package org.tasks.dialogs package org.tasks.dialogs
import android.app.Activity.RESULT_OK
import android.app.Dialog import android.app.Dialog
import android.app.ProgressDialog import android.app.ProgressDialog
import android.content.DialogInterface
import android.os.Bundle import android.os.Bundle
import androidx.fragment.app.DialogFragment import androidx.fragment.app.DialogFragment
import androidx.fragment.app.Fragment
import androidx.lifecycle.lifecycleScope import androidx.lifecycle.lifecycleScope
import dagger.hilt.android.AndroidEntryPoint import dagger.hilt.android.AndroidEntryPoint
import kotlinx.coroutines.NonCancellable import kotlinx.coroutines.NonCancellable
@ -31,9 +34,15 @@ class ExportTasksDialog : DialogFragment() {
return progressDialog return progressDialog
} }
override fun onDismiss(dialog: DialogInterface) {
super.onDismiss(dialog)
targetFragment?.onActivityResult(targetRequestCode, RESULT_OK, null)
}
companion object { companion object {
fun newExportTasksDialog(): ExportTasksDialog { fun newExportTasksDialog(target: Fragment, rc: Int) = ExportTasksDialog().apply {
return ExportTasksDialog() setTargetFragment(target, rc)
} }
} }
} }

@ -60,7 +60,7 @@ class PreferencesViewModel @ViewModelInject constructor(
lastDriveBackup.value = files.firstOrNull()?.let { BackupConstants.getTimestamp(it) } lastDriveBackup.value = files.firstOrNull()?.let { BackupConstants.getTimestamp(it) }
} }
private fun updateLocalBackup() = viewModelScope.launch { fun updateLocalBackup() = viewModelScope.launch {
val uri = preferences.backupDirectory val uri = preferences.backupDirectory
val timestamps: List<Long>? = withContext(Dispatchers.IO) { val timestamps: List<Long>? = withContext(Dispatchers.IO) {
when (uri?.scheme) { when (uri?.scheme) {

@ -26,6 +26,7 @@ import javax.inject.Inject
private const val REQUEST_CODE_BACKUP_DIR = 10001 private const val REQUEST_CODE_BACKUP_DIR = 10001
const val REQUEST_DRIVE_BACKUP = 12002 const val REQUEST_DRIVE_BACKUP = 12002
private const val REQUEST_PICKER = 10003 private const val REQUEST_PICKER = 10003
private const val REQUEST_BACKUP_NOW = 10004
private const val FRAG_TAG_EXPORT_TASKS = "frag_tag_export_tasks" private const val FRAG_TAG_EXPORT_TASKS = "frag_tag_export_tasks"
private const val FRAG_TAG_IMPORT_TASKS = "frag_tag_import_tasks" private const val FRAG_TAG_IMPORT_TASKS = "frag_tag_import_tasks"
@ -55,7 +56,7 @@ class Backups : InjectingPreferenceFragment() {
findPreference(R.string.backup_BAc_export) findPreference(R.string.backup_BAc_export)
.setOnPreferenceClickListener { .setOnPreferenceClickListener {
ExportTasksDialog.newExportTasksDialog() ExportTasksDialog.newExportTasksDialog(this, REQUEST_BACKUP_NOW)
.show(parentFragmentManager, FRAG_TAG_EXPORT_TASKS) .show(parentFragmentManager, FRAG_TAG_EXPORT_TASKS)
false false
} }
@ -138,6 +139,7 @@ class Backups : InjectingPreferenceFragment() {
) )
preferences.setUri(R.string.p_backup_dir, uri) preferences.setUri(R.string.p_backup_dir, uri)
updateBackupDirectory() updateBackupDirectory()
viewModel.updateLocalBackup()
} }
} else if (requestCode == REQUEST_PICKER) { } else if (requestCode == REQUEST_PICKER) {
if (resultCode == RESULT_OK) { if (resultCode == RESULT_OK) {
@ -154,6 +156,10 @@ class Backups : InjectingPreferenceFragment() {
.show(parentFragmentManager, FRAG_TAG_IMPORT_TASKS) .show(parentFragmentManager, FRAG_TAG_IMPORT_TASKS)
} }
} }
} else if (requestCode == REQUEST_BACKUP_NOW) {
if (resultCode == RESULT_OK) {
viewModel.updateLocalBackup()
}
} else { } else {
super.onActivityResult(requestCode, resultCode, data) super.onActivityResult(requestCode, resultCode, data)
} }

Loading…
Cancel
Save