add handling for importing settings with scoped storage
This commit is contained in:
parent
89519ab78c
commit
6bbdd935d1
1 changed files with 24 additions and 10 deletions
|
@ -1,5 +1,6 @@
|
|||
package com.simplemobiletools.calendar.pro.activities
|
||||
|
||||
import android.app.Activity
|
||||
import android.app.TimePickerDialog
|
||||
import android.content.Intent
|
||||
import android.content.res.Resources
|
||||
|
@ -20,10 +21,12 @@ import com.simplemobiletools.commons.models.RadioItem
|
|||
import kotlinx.android.synthetic.main.activity_settings.*
|
||||
import org.joda.time.DateTime
|
||||
import java.io.File
|
||||
import java.io.InputStream
|
||||
import java.util.*
|
||||
|
||||
class SettingsActivity : SimpleActivity() {
|
||||
private val GET_RINGTONE_URI = 1
|
||||
private val PICK_IMPORT_SOURCE_INTENT = 2
|
||||
|
||||
lateinit var res: Resources
|
||||
private var mStoredPrimaryColor = 0
|
||||
|
@ -105,6 +108,9 @@ class SettingsActivity : SimpleActivity() {
|
|||
if (requestCode == GET_RINGTONE_URI && resultCode == RESULT_OK && resultData != null) {
|
||||
val newAlarmSound = storeNewYourAlarmSound(resultData)
|
||||
updateReminderSound(newAlarmSound)
|
||||
} else if (requestCode == PICK_IMPORT_SOURCE_INTENT && resultCode == Activity.RESULT_OK && resultData != null && resultData.data != null) {
|
||||
val inputStream = contentResolver.openInputStream(resultData.data!!)
|
||||
parseFile(inputStream)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -703,14 +709,18 @@ class SettingsActivity : SimpleActivity() {
|
|||
|
||||
private fun setupImportSettings() {
|
||||
settings_import_holder.setOnClickListener {
|
||||
handlePermission(PERMISSION_READ_STORAGE) {
|
||||
if (it) {
|
||||
FilePickerDialog(this) {
|
||||
ensureBackgroundThread {
|
||||
try {
|
||||
parseFile(it)
|
||||
} catch (e: Exception) {
|
||||
showErrorToast(e)
|
||||
if (isQPlus()) {
|
||||
Intent(Intent.ACTION_GET_CONTENT).apply {
|
||||
addCategory(Intent.CATEGORY_OPENABLE)
|
||||
type = "text/plain"
|
||||
startActivityForResult(this, PICK_IMPORT_SOURCE_INTENT)
|
||||
}
|
||||
} else {
|
||||
handlePermission(PERMISSION_READ_STORAGE) {
|
||||
if (it) {
|
||||
FilePickerDialog(this) {
|
||||
ensureBackgroundThread {
|
||||
parseFile(File(it).inputStream())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -719,8 +729,12 @@ class SettingsActivity : SimpleActivity() {
|
|||
}
|
||||
}
|
||||
|
||||
private fun parseFile(path: String) {
|
||||
val inputStream = File(path).inputStream()
|
||||
private fun parseFile(inputStream: InputStream?) {
|
||||
if (inputStream == null) {
|
||||
toast(R.string.unknown_error_occurred)
|
||||
return
|
||||
}
|
||||
|
||||
var importedItems = 0
|
||||
val configValues = LinkedHashMap<String, Any>()
|
||||
inputStream.bufferedReader().use {
|
||||
|
|
Loading…
Reference in a new issue