1
0
Fork 0
seedvault/app/src/main/java/com/stevesoltys/backup/ui/BackupLocationFragment.kt
Torsten Grote 1a7fdfa59a
Implement restoring of backup and show progress in UI
Note that the progress view is not exact as the progress reporting of
AOSP seems to be buggy.
2019-09-10 13:35:58 -03:00

46 lines
1.8 KiB
Kotlin

package com.stevesoltys.backup.ui
import android.content.ActivityNotFoundException
import android.content.Intent
import android.content.Intent.*
import android.os.Bundle
import android.provider.DocumentsContract.EXTRA_PROMPT
import android.widget.Toast
import android.widget.Toast.LENGTH_LONG
import androidx.preference.Preference
import androidx.preference.PreferenceFragmentCompat
import com.stevesoltys.backup.R
class BackupLocationFragment : PreferenceFragmentCompat() {
override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) {
setPreferencesFromResource(R.xml.backup_location, rootKey)
requireActivity().setTitle(R.string.settings_backup_location_title)
val externalStorage = Preference(requireContext()).apply {
setIcon(R.drawable.ic_storage)
setTitle(R.string.settings_backup_external_storage)
setOnPreferenceClickListener {
showChooseFolderActivity()
true
}
}
preferenceScreen.addPreference(externalStorage)
}
private fun showChooseFolderActivity() {
val openTreeIntent = Intent(ACTION_OPEN_DOCUMENT_TREE)
openTreeIntent.putExtra(EXTRA_PROMPT, getString(R.string.settings_backup_location_picker))
openTreeIntent.addFlags(FLAG_GRANT_PERSISTABLE_URI_PERMISSION or
FLAG_GRANT_READ_URI_PERMISSION or FLAG_GRANT_WRITE_URI_PERMISSION)
try {
val documentChooser = createChooser(openTreeIntent, null)
// start from the activity context, so we can receive and handle the result there
requireActivity().startActivityForResult(documentChooser, REQUEST_CODE_OPEN_DOCUMENT_TREE)
} catch (ex: ActivityNotFoundException) {
Toast.makeText(requireContext(), "Please install a file manager.", LENGTH_LONG).show()
}
}
}