use the write permissions dialog which comes with the filepicker

This commit is contained in:
tibbi 2016-11-15 20:59:01 +01:00
parent a3f466b762
commit f2b6eb4c74
11 changed files with 9 additions and 92 deletions

View File

@ -12,17 +12,17 @@ import android.view.View
import android.widget.AdapterView
import com.simplemobiletools.camera.Constants
import com.simplemobiletools.camera.R
import com.simplemobiletools.camera.dialogs.WritePermissionDialog
import com.simplemobiletools.filepicker.dialogs.FilePickerDialog
import com.simplemobiletools.filepicker.extensions.getBasePath
import com.simplemobiletools.filepicker.extensions.getHumanReadablePath
import com.simplemobiletools.filepicker.extensions.needsStupidWritePermissions
import com.simplemobiletools.filepicker.extensions.isShowingWritePermissions
import kotlinx.android.synthetic.main.activity_settings.*
import java.io.File
class SettingsActivity : SimpleActivity() {
val OPEN_DOCUMENT_TREE = 1
var mCurrPath: String = ""
var mCurrPath = ""
var mWantedPath = ""
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
@ -69,19 +69,9 @@ class SettingsActivity : SimpleActivity() {
}
override fun onSuccess(pickedPath: String) {
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() {
mCurrPath = mConfig.savePhotosFolder
}
override fun onConfirmed() {
val intent = Intent(Intent.ACTION_OPEN_DOCUMENT_TREE)
startActivityForResult(intent, OPEN_DOCUMENT_TREE)
}
})
} else {
mWantedPath = pickedPath
if (!isShowingWritePermissions(File(pickedPath), mConfig.treeUri, OPEN_DOCUMENT_TREE)) {
mCurrPath = if (pickedPath.length == 1) pickedPath else pickedPath.trimEnd('/')
mConfig.savePhotosFolder = mCurrPath
settings_save_photos.text = getHumanPath()
}
@ -107,11 +97,13 @@ class SettingsActivity : SimpleActivity() {
super.onActivityResult(requestCode, resultCode, resultData)
if (requestCode == OPEN_DOCUMENT_TREE) {
if (resultCode == Activity.RESULT_OK && resultData != null) {
mCurrPath = mWantedPath
mConfig.savePhotosFolder = mCurrPath
settings_save_photos.text = getHumanPath()
saveTreeUri(resultData)
} else {
mCurrPath = mConfig.savePhotosFolder
settings_save_photos.text = getHumanPath()
}
}
}
@ -119,7 +111,7 @@ class SettingsActivity : SimpleActivity() {
@TargetApi(Build.VERSION_CODES.KITKAT)
private fun saveTreeUri(resultData: Intent) {
val treeUri = resultData.data
mConfig.treeUri = resultData.data.toString()
mConfig.treeUri = treeUri.toString()
val takeFlags = Intent.FLAG_GRANT_READ_URI_PERMISSION or Intent.FLAG_GRANT_WRITE_URI_PERMISSION
contentResolver.takePersistableUriPermission(treeUri, takeFlags)

View File

@ -1,34 +0,0 @@
package com.simplemobiletools.camera.dialogs
import android.content.Context
import android.support.v7.app.AlertDialog
import android.view.LayoutInflater
import com.simplemobiletools.camera.R
class WritePermissionDialog(val context: Context, val listener: OnWritePermissionListener) {
var dialog: AlertDialog? = null
init {
val view = LayoutInflater.from(context).inflate(R.layout.dialog_write_permission, null)
dialog = AlertDialog.Builder(context)
.setTitle(context.resources.getString(R.string.confirm_storage_access_title))
.setView(view)
.setPositiveButton(R.string.ok, { dialog, which -> dialogConfirmed() })
.setOnCancelListener { listener.onCancelled() }
.create()
dialog?.show()
}
private fun dialogConfirmed() {
dialog?.dismiss()
listener.onConfirmed()
}
interface OnWritePermissionListener {
fun onConfirmed()
fun onCancelled()
}
}

View File

@ -1,25 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/dialog_holder"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:padding="@dimen/activity_margin">
<TextView
android:id="@+id/dialog_text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="@dimen/activity_margin"
android:text="@string/confirm_storage_access_text"/>
<ImageView
android:id="@+id/dialog_image"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:adjustViewBounds="true"
android:scaleType="fitCenter"
android:src="@mipmap/write_storage"/>
</LinearLayout>

View File

@ -14,8 +14,6 @@
<string name="no_gallery_app_available">Keine Galerie App verfügbar</string>
<string name="no_valid_resolution_found">Keine gültige Auflösung mit gewähltem Seitenverhältnis gefunden, nutze maximale Auflösung</string>
<string name="ok">OK</string>
<string name="confirm_storage_access_title">Confirm external storage access</string>
<string name="confirm_storage_access_text">Please choose the root folder of the SD card to grant write access on the next screen</string>
<!-- Settings -->
<string name="settings">Einstellungen</string>

View File

@ -14,8 +14,6 @@
<string name="no_gallery_app_available">Nessuna app galleria disponibile</string>
<string name="no_valid_resolution_found">No valid resolution with selected aspect ratio found, using max resolution</string>
<string name="ok">OK</string>
<string name="confirm_storage_access_title">Confirm external storage access</string>
<string name="confirm_storage_access_text">Please choose the root folder of the SD card to grant write access on the next screen</string>
<!-- Settings -->
<string name="settings">Impostazioni</string>

View File

@ -14,8 +14,6 @@
<string name="no_gallery_app_available">利用可能なギャラリーアプリがありません</string>
<string name="no_valid_resolution_found">No valid resolution with selected aspect ratio found, using max resolution</string>
<string name="ok">OK</string>
<string name="confirm_storage_access_title">Confirm external storage access</string>
<string name="confirm_storage_access_text">Please choose the root folder of the SD card to grant write access on the next screen</string>
<!-- Settings -->
<string name="settings">設定</string>

View File

@ -14,8 +14,6 @@
<string name="no_gallery_app_available">Nėra galerijos programėlės</string>
<string name="no_valid_resolution_found">Nerasta tinkamos raiškos su with pasirinktu kraštinių santykiu, naudojant maksimalią raišką</string>
<string name="ok">Gerai</string>
<string name="confirm_storage_access_title">Patvirtinti išorinės saugyklos prieigą</string>
<string name="confirm_storage_access_text">Pasirinkite šakninį sd kortelės aplankalą, kad patvirtintumėte įrašymo leidimą kitame aplankale</string>
<!-- Settings -->
<string name="settings">Nustatymai</string>

View File

@ -14,8 +14,6 @@
<string name="no_gallery_app_available">Nenhuma aplicação de galeria disponível</string>
<string name="no_valid_resolution_found">Nenhuma resolução encontrada que seja compatível com o rácio selecionado, a utilizar a resolução máxima</string>
<string name="ok">OK</string>
<string name="confirm_storage_access_title">Confirmação de acesso ao armazenamento externo</string>
<string name="confirm_storage_access_text">Por favor escolha a pasta raiz do cartão SD para conceder o acesso de escrita no próximo ecrã</string>
<!-- Settings -->
<string name="settings">Definições</string>

View File

@ -14,8 +14,6 @@
<string name="no_gallery_app_available">Нет доступного приложения-галереи</string>
<string name="no_valid_resolution_found">No valid resolution with selected aspect ratio found, using max resolution</string>
<string name="ok">OK</string>
<string name="confirm_storage_access_title">Confirm external storage access</string>
<string name="confirm_storage_access_text">Please choose the root folder of the SD card to grant write access on the next screen</string>
<!-- Settings -->
<string name="settings">Настройки</string>

View File

@ -14,8 +14,6 @@
<string name="no_gallery_app_available">Ingen galleri-app finns tillgänglig</string>
<string name="no_valid_resolution_found">No valid resolution with selected aspect ratio found, using max resolution</string>
<string name="ok">OK</string>
<string name="confirm_storage_access_title">Confirm external storage access</string>
<string name="confirm_storage_access_text">Please choose the root folder of the SD card to grant write access on the next screen</string>
<!-- Settings -->
<string name="settings">Inställningar</string>

View File

@ -14,8 +14,6 @@
<string name="no_gallery_app_available">No gallery app available</string>
<string name="no_valid_resolution_found">No valid resolution with selected aspect ratio found, using max resolution</string>
<string name="ok">OK</string>
<string name="confirm_storage_access_title">Confirm external storage access</string>
<string name="confirm_storage_access_text">Please choose the root folder of the SD card to grant write access on the next screen</string>
<!-- Settings -->
<string name="settings">Settings</string>