From 6464c7eee4ae8aa805255bbb2daeee339322e550 Mon Sep 17 00:00:00 2001 From: tibbi Date: Tue, 24 Apr 2018 17:08:41 +0200 Subject: [PATCH] try adding OTG automatically once --- app/build.gradle | 2 +- .../gallery/activities/MainActivity.kt | 19 +++++++++++++++++++ .../gallery/helpers/Config.kt | 4 ++++ .../gallery/helpers/Constants.kt | 1 + 4 files changed, 25 insertions(+), 1 deletion(-) diff --git a/app/build.gradle b/app/build.gradle index 7f7228180..08a215ce4 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -47,7 +47,7 @@ ext { } dependencies { - implementation 'com.simplemobiletools:commons:3.19.11' + implementation 'com.simplemobiletools:commons:3.19.12' implementation 'com.theartofdev.edmodo:android-image-cropper:2.7.0' implementation 'com.android.support:multidex:1.0.3' implementation 'it.sephiroth.android.exif:library:1.0.1' diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MainActivity.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MainActivity.kt index 29a18a406..357f5d184 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MainActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MainActivity.kt @@ -100,6 +100,10 @@ class MainActivity : SimpleActivity(), DirectoryAdapter.DirOperationsListener { config.wasNewAppShown = true NewAppDialog(this, NEW_APP_PACKAGE, "Simple Clock") }*/ + + if (hasPermission(PERMISSION_WRITE_STORAGE)) { + checkOTGInclusion() + } } override fun onStart() { @@ -246,6 +250,21 @@ class MainActivity : SimpleActivity(), DirectoryAdapter.DirOperationsListener { } } + private fun checkOTGInclusion() { + if (!config.wasOTGHandled) { + Thread { + if (hasOTGConnected()) { + runOnUiThread { + handleOTGPermission { + config.addIncludedFolder(OTG_PATH) + } + } + config.wasOTGHandled = true + } + }.start() + } + } + private fun tryLoadGallery() { handlePermission(PERMISSION_WRITE_STORAGE) { if (it) { diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/helpers/Config.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/helpers/Config.kt index 86cd7caf8..596a672ab 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/helpers/Config.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/helpers/Config.kt @@ -327,4 +327,8 @@ class Config(context: Context) : BaseConfig(context) { var lastFilepickerPath: String get() = prefs.getString(LAST_FILEPICKER_PATH, "") set(lastFilepickerPath) = prefs.edit().putString(LAST_FILEPICKER_PATH, lastFilepickerPath).apply() + + var wasOTGHandled: Boolean + get() = prefs.getBoolean(WAS_OTG_HANDLED, false) + set(wasOTGHandled) = prefs.edit().putBoolean(WAS_OTG_HANDLED, wasOTGHandled).apply() } diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/helpers/Constants.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/helpers/Constants.kt index 12352ebf9..23d190fab 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/helpers/Constants.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/helpers/Constants.kt @@ -47,6 +47,7 @@ const val REPLACE_ZOOMABLE_IMAGES = "replace_zoomable_images" const val DO_EXTRA_CHECK = "do_extra_check" const val WAS_NEW_APP_SHOWN = "was_new_app_shown_clock" const val LAST_FILEPICKER_PATH = "last_filepicker_path" +const val WAS_OTG_HANDLED = "was_otg_handled" // slideshow const val SLIDESHOW_INTERVAL = "slideshow_interval"