Skip to content

Commit 2964d1c

Browse files
committed
nicely format the picked save folder
1 parent 52190cf commit 2964d1c

2 files changed

Lines changed: 22 additions & 6 deletions

File tree

app/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ dependencies {
3737
testCompile 'junit:junit:4.12'
3838
compile 'com.android.support:appcompat-v7:23.4.0'
3939
compile 'com.jakewharton:butterknife:8.0.1'
40-
compile 'com.simplemobiletools:filepicker:1.3.6@aar'
40+
compile 'com.simplemobiletools:filepicker:1.3.7@aar'
4141
compile 'com.github.bumptech.glide:glide:3.7.0'
4242
compile "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
4343

app/src/main/kotlin/com/simplemobiletools/camera/activities/SettingsActivity.kt

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ import com.simplemobiletools.camera.R
1515
import com.simplemobiletools.camera.dialogs.WritePermissionDialog
1616
import com.simplemobiletools.camera.extensions.needsStupidWritePermissions
1717
import com.simplemobiletools.filepicker.dialogs.FilePickerDialog
18+
import com.simplemobiletools.filepicker.extensions.getBasePath
19+
import com.simplemobiletools.filepicker.extensions.getHumanReadablePath
1820
import kotlinx.android.synthetic.main.activity_settings.*
1921
import 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

Comments
 (0)