@@ -15,6 +15,8 @@ import com.simplemobiletools.camera.R
1515import com.simplemobiletools.camera.dialogs.WritePermissionDialog
1616import com.simplemobiletools.camera.extensions.needsStupidWritePermissions
1717import com.simplemobiletools.filepicker.dialogs.FilePickerDialog
18+ import com.simplemobiletools.filepicker.extensions.getBasePath
19+ import com.simplemobiletools.filepicker.extensions.getHumanReadablePath
1820import kotlinx.android.synthetic.main.activity_settings.*
1921import java.io.File
2022
@@ -60,14 +62,14 @@ class SettingsActivity : SimpleActivity() {
6062
6163 private fun setupSavePhotosFolder () {
6264 mCurrPath = mConfig.savePhotosFolder
63- settings_save_photos.text = mCurrPath.substring(mCurrPath.lastIndexOf( " / " ) + 1 )
65+ settings_save_photos.text = getHumanPath( )
6466 settings_save_photos_holder.setOnClickListener {
65- FilePickerDialog (this , mCurrPath, false , false , false , object : FilePickerDialog .OnFilePickerListener {
67+ FilePickerDialog (this , mCurrPath, false , false , object : FilePickerDialog .OnFilePickerListener {
6668 override fun onFail (error : FilePickerDialog .FilePickerResult ) {
6769 }
6870
6971 override fun onSuccess (pickedPath : String ) {
70- mCurrPath = pickedPath.trimEnd(' /' )
72+ mCurrPath = if (pickedPath.length == 1 ) pickedPath else pickedPath.trimEnd(' /' )
7173 if (! File (pickedPath).canWrite() && needsStupidWritePermissions(pickedPath) && mConfig.treeUri.isEmpty()) {
7274 WritePermissionDialog (this @SettingsActivity, object : WritePermissionDialog .OnWritePermissionListener {
7375 override fun onCancelled () {
@@ -81,20 +83,34 @@ class SettingsActivity : SimpleActivity() {
8183 })
8284 } else {
8385 mConfig.savePhotosFolder = mCurrPath
84- settings_save_photos.text = mCurrPath.substring(mCurrPath.lastIndexOf( " / " ) + 1 )
86+ settings_save_photos.text = getHumanPath( )
8587 }
8688 }
8789 })
8890 }
8991 }
9092
93+ private fun getHumanPath (): String {
94+ val basePath = mCurrPath.getBasePath(applicationContext)
95+ val path = mCurrPath.replaceFirst(basePath, getStorageName(basePath)).trimEnd(' /' )
96+
97+ return if (path.contains(' /' ))
98+ path.substring(path.lastIndexOf(" /" ) + 1 )
99+ else
100+ path
101+ }
102+
103+ private fun getStorageName (basePath : String ): String {
104+ return getHumanReadablePath(basePath) + " /"
105+ }
106+
91107 @TargetApi(Build .VERSION_CODES .KITKAT )
92108 override fun onActivityResult (requestCode : Int , resultCode : Int , resultData : Intent ? ) {
93109 super .onActivityResult(requestCode, resultCode, resultData)
94110 if (requestCode == OPEN_DOCUMENT_TREE ) {
95111 if (resultCode == Activity .RESULT_OK && resultData != null ) {
96112 mConfig.savePhotosFolder = mCurrPath
97- settings_save_photos.text = mCurrPath.substring(mCurrPath.lastIndexOf( " / " ) + 1 )
113+ settings_save_photos.text = getHumanPath( )
98114 saveTreeUri(resultData)
99115 } else {
100116 mCurrPath = mConfig.savePhotosFolder
0 commit comments