mirror of
https://github.com/SimpleMobileTools/Simple-Notes.git
synced 2025-04-13 15:02:05 +02:00
handle storage permissions before trying to save note as file
This commit is contained in:
parent
78f6cfcbde
commit
9a0530bf83
@ -34,6 +34,7 @@ import java.io.File
|
||||
|
||||
class MainActivity : SimpleActivity(), ViewPager.OnPageChangeListener {
|
||||
val STORAGE_OPEN_FILE = 1
|
||||
val STORAGE_SAVE_AS_FILE = 2
|
||||
|
||||
lateinit var mCurrentNote: Note
|
||||
lateinit var mAdapter: NotesPagerAdapter
|
||||
@ -108,7 +109,7 @@ class MainActivity : SimpleActivity(), ViewPager.OnPageChangeListener {
|
||||
R.id.rename_note -> displayRenameDialog()
|
||||
R.id.share -> shareText()
|
||||
R.id.open_file -> tryOpenFile()
|
||||
R.id.save_as_file -> saveAsFile()
|
||||
R.id.save_as_file -> trySaveAsFile()
|
||||
R.id.delete_note -> displayDeleteNotePrompt()
|
||||
R.id.settings -> startActivity(Intent(applicationContext, SettingsActivity::class.java))
|
||||
R.id.about -> launchAbout()
|
||||
@ -176,6 +177,14 @@ class MainActivity : SimpleActivity(), ViewPager.OnPageChangeListener {
|
||||
}
|
||||
}
|
||||
|
||||
private fun trySaveAsFile() {
|
||||
if (hasWriteStoragePermission()) {
|
||||
saveAsFile()
|
||||
} else {
|
||||
ActivityCompat.requestPermissions(this, arrayOf(Manifest.permission.WRITE_EXTERNAL_STORAGE), STORAGE_SAVE_AS_FILE)
|
||||
}
|
||||
}
|
||||
|
||||
private fun saveAsFile() {
|
||||
|
||||
}
|
||||
@ -241,6 +250,8 @@ class MainActivity : SimpleActivity(), ViewPager.OnPageChangeListener {
|
||||
if (grantResults.isNotEmpty() && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
|
||||
if (requestCode == STORAGE_OPEN_FILE) {
|
||||
openFile()
|
||||
} else if (requestCode == STORAGE_SAVE_AS_FILE) {
|
||||
saveAsFile()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user