nicely format the picked save folder

This commit is contained in:
tibbi 2016-11-06 14:51:24 +01:00
parent 52190cf797
commit 2964d1ce37
2 changed files with 22 additions and 6 deletions

View File

@ -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"

View File

@ -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