2019-07-03 19:44:37 +02:00
|
|
|
package com.stevesoltys.backup.settings
|
|
|
|
|
|
|
|
import android.app.Application
|
|
|
|
import android.content.Intent
|
|
|
|
import android.content.Intent.FLAG_GRANT_READ_URI_PERMISSION
|
|
|
|
import android.content.Intent.FLAG_GRANT_WRITE_URI_PERMISSION
|
|
|
|
import androidx.lifecycle.AndroidViewModel
|
|
|
|
|
|
|
|
class SettingsViewModel(application: Application) : AndroidViewModel(application) {
|
|
|
|
|
|
|
|
private val app = application
|
|
|
|
|
2019-07-05 12:35:45 +02:00
|
|
|
fun recoveryCodeIsSet() = getBackupPassword(getApplication()) != null
|
2019-07-03 19:44:37 +02:00
|
|
|
fun locationIsSet() = getBackupFolderUri(getApplication()) != null
|
|
|
|
|
|
|
|
fun handleChooseFolderResult(result: Intent?) {
|
|
|
|
val folderUri = result?.data ?: return
|
|
|
|
|
|
|
|
// persist permission to access backup folder across reboots
|
|
|
|
val takeFlags = result.flags and (FLAG_GRANT_READ_URI_PERMISSION or FLAG_GRANT_WRITE_URI_PERMISSION)
|
|
|
|
app.contentResolver.takePersistableUriPermission(folderUri, takeFlags)
|
|
|
|
|
|
|
|
// store backup folder location in settings
|
|
|
|
setBackupFolderUri(app, folderUri)
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|