From 596edde553d4401f8707b739e5f1a9a194b9414c Mon Sep 17 00:00:00 2001 From: tibbi Date: Mon, 28 Jan 2019 12:45:29 +0100 Subject: [PATCH] adding some boilerplate related to importing settings --- app/build.gradle | 2 +- .../pro/activities/SettingsActivity.kt | 23 +++++++++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/app/build.gradle b/app/build.gradle index 95e8b7992..76213278d 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -61,7 +61,7 @@ android { } dependencies { - implementation 'com.simplemobiletools:commons:5.7.0' + implementation 'com.simplemobiletools:commons:5.7.1' implementation 'com.theartofdev.edmodo:android-image-cropper:2.8.0' implementation 'androidx.multidex:multidex:2.0.1' implementation 'it.sephiroth.android.exif:library:1.0.1' diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/activities/SettingsActivity.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/activities/SettingsActivity.kt index a65059c23..1eea8f42b 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/activities/SettingsActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/activities/SettingsActivity.kt @@ -4,6 +4,7 @@ import android.content.Intent import android.os.Bundle import android.text.TextUtils import com.simplemobiletools.commons.dialogs.ConfirmationDialog +import com.simplemobiletools.commons.dialogs.FilePickerDialog import com.simplemobiletools.commons.dialogs.RadioGroupDialog import com.simplemobiletools.commons.dialogs.SecurityDialog import com.simplemobiletools.commons.extensions.* @@ -18,6 +19,7 @@ import com.simplemobiletools.gallery.pro.extensions.galleryDB import com.simplemobiletools.gallery.pro.extensions.showRecycleBinEmptyingDialog import com.simplemobiletools.gallery.pro.helpers.* import kotlinx.android.synthetic.main.activity_settings.* +import java.io.File import java.util.* class SettingsActivity : SimpleActivity() { @@ -657,7 +659,28 @@ class SettingsActivity : SimpleActivity() { private fun setupImportSettings() { settings_import_holder.setOnClickListener { + FilePickerDialog(this) { + Thread { + parseFile(it) + }.start() + } + } + } + private fun parseFile(path: String) { + val inputStream = File(path).inputStream() + inputStream.bufferedReader().use { + var importedItems = 0 + while (true) { + try { + var line = it.readLine() ?: break + importedItems++ + } catch (e: Exception) { + showErrorToast(e) + } + } + + toast(if (importedItems > 0) R.string.settings_imported_successfully else R.string.no_entries_for_importing) } } }