use Scoped Storage at importing app settings

This commit is contained in:
tibbi 2020-03-18 23:10:20 +01:00
parent 2262829077
commit bdccb98895
1 changed files with 31 additions and 8 deletions

View File

@ -1,5 +1,6 @@
package com.simplemobiletools.gallery.pro.activities package com.simplemobiletools.gallery.pro.activities
import android.app.Activity
import android.content.Intent import android.content.Intent
import android.os.Bundle import android.os.Bundle
import android.text.TextUtils import android.text.TextUtils
@ -18,9 +19,11 @@ import com.simplemobiletools.gallery.pro.helpers.*
import com.simplemobiletools.gallery.pro.models.AlbumCover import com.simplemobiletools.gallery.pro.models.AlbumCover
import kotlinx.android.synthetic.main.activity_settings.* import kotlinx.android.synthetic.main.activity_settings.*
import java.io.File import java.io.File
import java.io.InputStream
import java.util.* import java.util.*
class SettingsActivity : SimpleActivity() { class SettingsActivity : SimpleActivity() {
private val PICK_IMPORT_SOURCE_INTENT = 1
private var mRecycleBinContentSize = 0L private var mRecycleBinContentSize = 0L
override fun onCreate(savedInstanceState: Bundle?) { override fun onCreate(savedInstanceState: Bundle?) {
@ -94,6 +97,14 @@ class SettingsActivity : SimpleActivity() {
return super.onCreateOptionsMenu(menu) return super.onCreateOptionsMenu(menu)
} }
override fun onActivityResult(requestCode: Int, resultCode: Int, resultData: Intent?) {
super.onActivityResult(requestCode, resultCode, resultData)
if (requestCode == PICK_IMPORT_SOURCE_INTENT && resultCode == Activity.RESULT_OK && resultData != null && resultData.data != null) {
val inputStream = contentResolver.openInputStream(resultData.data!!)
parseFile(inputStream)
}
}
private fun setupSectionColors() { private fun setupSectionColors() {
val adjustedPrimaryColor = getAdjustedPrimaryColor() val adjustedPrimaryColor = getAdjustedPrimaryColor()
arrayListOf(visibility_label, videos_label, thumbnails_label, scrolling_label, fullscreen_media_label, security_label, arrayListOf(visibility_label, videos_label, thumbnails_label, scrolling_label, fullscreen_media_label, security_label,
@ -700,20 +711,32 @@ class SettingsActivity : SimpleActivity() {
private fun setupImportSettings() { private fun setupImportSettings() {
settings_import_holder.setOnClickListener { settings_import_holder.setOnClickListener {
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) { FilePickerDialog(this) {
ensureBackgroundThread { ensureBackgroundThread {
try { parseFile(File(it).inputStream())
parseFile(it) }
} catch (e: Exception) { }
showErrorToast(e)
} }
} }
} }
} }
} }
private fun parseFile(path: String) { private fun parseFile(inputStream: InputStream?) {
val inputStream = File(path).inputStream() if (inputStream == null) {
toast(R.string.unknown_error_occurred)
return
}
var importedItems = 0 var importedItems = 0
val configValues = LinkedHashMap<String, Any>() val configValues = LinkedHashMap<String, Any>()
inputStream.bufferedReader().use { inputStream.bufferedReader().use {