From 2964d1ce378ae04ab1fd3b70025a60fd355bd448 Mon Sep 17 00:00:00 2001 From: tibbi Date: Sun, 6 Nov 2016 14:51:24 +0100 Subject: [PATCH] nicely format the picked save folder --- app/build.gradle | 2 +- .../camera/activities/SettingsActivity.kt | 26 +++++++++++++++---- 2 files changed, 22 insertions(+), 6 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index cc7d5ed3..923a16f7 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -37,7 +37,7 @@ dependencies { testCompile 'junit:junit:4.12' compile 'com.android.support:appcompat-v7:23.4.0' compile 'com.jakewharton:butterknife:8.0.1' - compile 'com.simplemobiletools:filepicker:1.3.6@aar' + compile 'com.simplemobiletools:filepicker:1.3.7@aar' compile 'com.github.bumptech.glide:glide:3.7.0' compile "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version" diff --git a/app/src/main/kotlin/com/simplemobiletools/camera/activities/SettingsActivity.kt b/app/src/main/kotlin/com/simplemobiletools/camera/activities/SettingsActivity.kt index 94ec4c81..4f2b225d 100644 --- a/app/src/main/kotlin/com/simplemobiletools/camera/activities/SettingsActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/camera/activities/SettingsActivity.kt @@ -15,6 +15,8 @@ import com.simplemobiletools.camera.R import com.simplemobiletools.camera.dialogs.WritePermissionDialog import com.simplemobiletools.camera.extensions.needsStupidWritePermissions import com.simplemobiletools.filepicker.dialogs.FilePickerDialog +import com.simplemobiletools.filepicker.extensions.getBasePath +import com.simplemobiletools.filepicker.extensions.getHumanReadablePath import kotlinx.android.synthetic.main.activity_settings.* import java.io.File @@ -60,14 +62,14 @@ class SettingsActivity : SimpleActivity() { private fun setupSavePhotosFolder() { mCurrPath = mConfig.savePhotosFolder - settings_save_photos.text = mCurrPath.substring(mCurrPath.lastIndexOf("/") + 1) + settings_save_photos.text = getHumanPath() settings_save_photos_holder.setOnClickListener { - FilePickerDialog(this, mCurrPath, false, false, false, object : FilePickerDialog.OnFilePickerListener { + FilePickerDialog(this, mCurrPath, false, false, object : FilePickerDialog.OnFilePickerListener { override fun onFail(error: FilePickerDialog.FilePickerResult) { } override fun onSuccess(pickedPath: String) { - mCurrPath = pickedPath.trimEnd('/') + mCurrPath = if (pickedPath.length == 1) pickedPath else pickedPath.trimEnd('/') if (!File(pickedPath).canWrite() && needsStupidWritePermissions(pickedPath) && mConfig.treeUri.isEmpty()) { WritePermissionDialog(this@SettingsActivity, object : WritePermissionDialog.OnWritePermissionListener { override fun onCancelled() { @@ -81,20 +83,34 @@ class SettingsActivity : SimpleActivity() { }) } else { mConfig.savePhotosFolder = mCurrPath - settings_save_photos.text = mCurrPath.substring(mCurrPath.lastIndexOf("/") + 1) + settings_save_photos.text = getHumanPath() } } }) } } + private fun getHumanPath(): String { + val basePath = mCurrPath.getBasePath(applicationContext) + val path = mCurrPath.replaceFirst(basePath, getStorageName(basePath)).trimEnd('/') + + return if (path.contains('/')) + path.substring(path.lastIndexOf("/") + 1) + else + path + } + + private fun getStorageName(basePath: String): String { + return getHumanReadablePath(basePath) + "/" + } + @TargetApi(Build.VERSION_CODES.KITKAT) override fun onActivityResult(requestCode: Int, resultCode: Int, resultData: Intent?) { super.onActivityResult(requestCode, resultCode, resultData) if (requestCode == OPEN_DOCUMENT_TREE) { if (resultCode == Activity.RESULT_OK && resultData != null) { mConfig.savePhotosFolder = mCurrPath - settings_save_photos.text = mCurrPath.substring(mCurrPath.lastIndexOf("/") + 1) + settings_save_photos.text = getHumanPath() saveTreeUri(resultData) } else { mCurrPath = mConfig.savePhotosFolder