mirror of
https://github.com/FossifyOrg/Gallery.git
synced 2024-11-26 22:47:59 +01:00
make use of some of the new extension functions
This commit is contained in:
parent
42be5de0cb
commit
9e5936b8a0
12 changed files with 31 additions and 76 deletions
|
@ -18,7 +18,6 @@ import com.simplemobiletools.filepicker.extensions.getFileDocument
|
||||||
import com.simplemobiletools.filepicker.extensions.hasStoragePermission
|
import com.simplemobiletools.filepicker.extensions.hasStoragePermission
|
||||||
import com.simplemobiletools.filepicker.extensions.needsStupidWritePermissions
|
import com.simplemobiletools.filepicker.extensions.needsStupidWritePermissions
|
||||||
import com.simplemobiletools.filepicker.extensions.toast
|
import com.simplemobiletools.filepicker.extensions.toast
|
||||||
import com.simplemobiletools.gallery.dialogs.WritePermissionDialog
|
|
||||||
import com.simplemobiletools.gallery.extensions.scanFile
|
import com.simplemobiletools.gallery.extensions.scanFile
|
||||||
import com.simplemobiletools.gallery.models.Medium
|
import com.simplemobiletools.gallery.models.Medium
|
||||||
import java.io.File
|
import java.io.File
|
||||||
|
@ -150,22 +149,6 @@ class Utils {
|
||||||
context.contentResolver.takePersistableUriPermission(treeUri, takeFlags)
|
context.contentResolver.takePersistableUriPermission(treeUri, takeFlags)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun isShowingWritePermissions(activity: Activity, file: File): Boolean {
|
fun scanFiles(context: Context, paths: Array<String>) = context.scanFile(paths)
|
||||||
return if ((needsStupidWritePermissions(activity, file.absolutePath) && Config.newInstance(activity).treeUri.isEmpty())) {
|
|
||||||
WritePermissionDialog(activity, object : WritePermissionDialog.OnWritePermissionListener {
|
|
||||||
override fun onConfirmed() {
|
|
||||||
val intent = Intent(Intent.ACTION_OPEN_DOCUMENT_TREE)
|
|
||||||
activity.startActivityForResult(intent, Constants.OPEN_DOCUMENT_TREE)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
true
|
|
||||||
} else {
|
|
||||||
false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fun scanFiles(context: Context, paths: Array<String>) {
|
|
||||||
context.scanFile(paths)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -199,7 +199,7 @@ public class MainActivity extends SimpleActivity
|
||||||
}
|
}
|
||||||
|
|
||||||
for (String path : mToBeDeleted) {
|
for (String path : mToBeDeleted) {
|
||||||
if (Utils.Companion.isShowingWritePermissions(this, new File(path))) {
|
if (isShowingPermDialog(new File(path))) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -254,7 +254,7 @@ public class MainActivity extends SimpleActivity
|
||||||
|
|
||||||
private void deleteItem(File file) {
|
private void deleteItem(File file) {
|
||||||
if (Utils.Companion.needsStupidWritePermissions(this, file.getAbsolutePath())) {
|
if (Utils.Companion.needsStupidWritePermissions(this, file.getAbsolutePath())) {
|
||||||
if (!Utils.Companion.isShowingWritePermissions(this, file)) {
|
if (!isShowingPermDialog(file)) {
|
||||||
final DocumentFile document = Utils.Companion.getFileDocument(this, file.getAbsolutePath(), mConfig.getTreeUri());
|
final DocumentFile document = Utils.Companion.getFileDocument(this, file.getAbsolutePath(), mConfig.getTreeUri());
|
||||||
document.delete();
|
document.delete();
|
||||||
}
|
}
|
||||||
|
|
|
@ -306,7 +306,7 @@ public class MediaActivity extends SimpleActivity
|
||||||
}
|
}
|
||||||
|
|
||||||
private void prepareForDeleting() {
|
private void prepareForDeleting() {
|
||||||
if (Utils.Companion.isShowingWritePermissions(this, new File(mPath)))
|
if (isShowingPermDialog(new File(mPath)))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
Utils.Companion.showToast(this, R.string.deleting);
|
Utils.Companion.showToast(this, R.string.deleting);
|
||||||
|
@ -358,7 +358,7 @@ public class MediaActivity extends SimpleActivity
|
||||||
final File file = new File(delPath);
|
final File file = new File(delPath);
|
||||||
if (file.exists()) {
|
if (file.exists()) {
|
||||||
if (Utils.Companion.needsStupidWritePermissions(this, delPath)) {
|
if (Utils.Companion.needsStupidWritePermissions(this, delPath)) {
|
||||||
if (Utils.Companion.isShowingWritePermissions(this, file))
|
if (isShowingPermDialog(file))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
final DocumentFile document = Utils.Companion.getFileDocument(this, delPath, mConfig.getTreeUri());
|
final DocumentFile document = Utils.Companion.getFileDocument(this, delPath, mConfig.getTreeUri());
|
||||||
|
|
|
@ -260,7 +260,7 @@ public class ViewPagerActivity extends SimpleActivity
|
||||||
}
|
}
|
||||||
|
|
||||||
private void notifyDeletion() {
|
private void notifyDeletion() {
|
||||||
if (Utils.Companion.isShowingWritePermissions(this, new File(mPath)))
|
if (isShowingPermDialog(new File(mPath)))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
mToBeDeleted = getCurrentFile().getAbsolutePath();
|
mToBeDeleted = getCurrentFile().getAbsolutePath();
|
||||||
|
@ -284,7 +284,7 @@ public class ViewPagerActivity extends SimpleActivity
|
||||||
|
|
||||||
final File file = new File(mToBeDeleted);
|
final File file = new File(mToBeDeleted);
|
||||||
if (Utils.Companion.needsStupidWritePermissions(this, mToBeDeleted)) {
|
if (Utils.Companion.needsStupidWritePermissions(this, mToBeDeleted)) {
|
||||||
if (!Utils.Companion.isShowingWritePermissions(this, file)) {
|
if (!isShowingPermDialog(file)) {
|
||||||
final DocumentFile document = Utils.Companion.getFileDocument(this, mToBeDeleted, mConfig.getTreeUri());
|
final DocumentFile document = Utils.Companion.getFileDocument(this, mToBeDeleted, mConfig.getTreeUri());
|
||||||
if (document.canWrite()) {
|
if (document.canWrite()) {
|
||||||
mWasFileDeleted = document.delete();
|
mWasFileDeleted = document.delete();
|
||||||
|
|
|
@ -98,7 +98,7 @@ class EditActivity : SimpleActivity(), CropImageView.OnCropImageCompleteListener
|
||||||
finish()
|
finish()
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
//toast("${getString(R.string.image_editing_failed)}: ${result.error.message}")
|
toast("${getString(R.string.image_editing_failed)}: ${result.error.message}")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -108,7 +108,7 @@ class EditActivity : SimpleActivity(), CropImageView.OnCropImageCompleteListener
|
||||||
var out: OutputStream? = null
|
var out: OutputStream? = null
|
||||||
try {
|
try {
|
||||||
if (needsStupidWritePermissions(path)) {
|
if (needsStupidWritePermissions(path)) {
|
||||||
if (Utils.isShowingWritePermissions(this, file))
|
if (isShowingPermDialog(file))
|
||||||
return
|
return
|
||||||
|
|
||||||
var document = getFileDocument(path, mConfig.treeUri)
|
var document = getFileDocument(path, mConfig.treeUri)
|
||||||
|
|
|
@ -83,7 +83,7 @@ class SetWallpaperActivity : SimpleActivity(), CropImageView.OnCropImageComplete
|
||||||
finish()
|
finish()
|
||||||
}).start()
|
}).start()
|
||||||
} else {
|
} else {
|
||||||
//toast("${getString(R.string.image_editing_failed)}: ${result.error.message}")
|
toast("${getString(R.string.image_editing_failed)}: ${result.error.message}")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -5,10 +5,12 @@ import android.content.Intent
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import android.support.v7.app.AppCompatActivity
|
import android.support.v7.app.AppCompatActivity
|
||||||
import android.view.MenuItem
|
import android.view.MenuItem
|
||||||
|
import com.simplemobiletools.filepicker.extensions.isShowingWritePermissions
|
||||||
import com.simplemobiletools.gallery.Config
|
import com.simplemobiletools.gallery.Config
|
||||||
import com.simplemobiletools.gallery.Constants
|
import com.simplemobiletools.gallery.Constants
|
||||||
import com.simplemobiletools.gallery.R
|
import com.simplemobiletools.gallery.R
|
||||||
import com.simplemobiletools.gallery.Utils
|
import com.simplemobiletools.gallery.Utils
|
||||||
|
import java.io.File
|
||||||
|
|
||||||
open class SimpleActivity : AppCompatActivity() {
|
open class SimpleActivity : AppCompatActivity() {
|
||||||
lateinit var mConfig: Config
|
lateinit var mConfig: Config
|
||||||
|
@ -39,4 +41,6 @@ open class SimpleActivity : AppCompatActivity() {
|
||||||
Utils.saveTreeUri(this, resultData)
|
Utils.saveTreeUri(this, resultData)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun isShowingPermDialog(file: File) = isShowingWritePermissions(file, mConfig.treeUri, Constants.OPEN_DOCUMENT_TREE)
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,7 +6,7 @@ import android.support.v4.util.Pair
|
||||||
import android.util.Log
|
import android.util.Log
|
||||||
import com.simplemobiletools.filepicker.extensions.getFileDocument
|
import com.simplemobiletools.filepicker.extensions.getFileDocument
|
||||||
import com.simplemobiletools.filepicker.extensions.needsStupidWritePermissions
|
import com.simplemobiletools.filepicker.extensions.needsStupidWritePermissions
|
||||||
import com.simplemobiletools.filepicker.extensions.rescanItem
|
import com.simplemobiletools.filepicker.extensions.rescanFile
|
||||||
import com.simplemobiletools.gallery.Config
|
import com.simplemobiletools.gallery.Config
|
||||||
import java.io.*
|
import java.io.*
|
||||||
import java.lang.ref.WeakReference
|
import java.lang.ref.WeakReference
|
||||||
|
@ -92,7 +92,7 @@ class CopyTask(listener: CopyTask.CopyDoneListener, val context: Context) : Asyn
|
||||||
out = FileOutputStream(destination)
|
out = FileOutputStream(destination)
|
||||||
}
|
}
|
||||||
|
|
||||||
context.rescanItem(destination)
|
context.rescanFile(destination)
|
||||||
copyStream(inputStream, out)
|
copyStream(inputStream, out)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,25 +1,26 @@
|
||||||
package com.simplemobiletools.gallery.dialogs
|
package com.simplemobiletools.gallery.dialogs
|
||||||
|
|
||||||
import android.app.Activity
|
|
||||||
import android.support.v4.util.Pair
|
import android.support.v4.util.Pair
|
||||||
import android.support.v7.app.AlertDialog
|
import android.support.v7.app.AlertDialog
|
||||||
import android.view.LayoutInflater
|
import android.view.LayoutInflater
|
||||||
import android.view.WindowManager
|
import android.view.WindowManager
|
||||||
import com.simplemobiletools.filepicker.extensions.humanizePath
|
import com.simplemobiletools.filepicker.extensions.humanizePath
|
||||||
import com.simplemobiletools.filepicker.extensions.toast
|
import com.simplemobiletools.filepicker.extensions.toast
|
||||||
|
import com.simplemobiletools.gallery.Config
|
||||||
import com.simplemobiletools.gallery.R
|
import com.simplemobiletools.gallery.R
|
||||||
import com.simplemobiletools.gallery.Utils
|
import com.simplemobiletools.gallery.activities.SimpleActivity
|
||||||
import com.simplemobiletools.gallery.asynctasks.CopyTask
|
import com.simplemobiletools.gallery.asynctasks.CopyTask
|
||||||
import kotlinx.android.synthetic.main.copy_item.view.*
|
import kotlinx.android.synthetic.main.copy_item.view.*
|
||||||
import java.io.File
|
import java.io.File
|
||||||
|
|
||||||
class CopyDialog(val activity: Activity, val files: List<File>, val copyListener: CopyTask.CopyDoneListener, val listener: OnCopyListener) {
|
class CopyDialog(val activity: SimpleActivity, val files: List<File>, val copyListener: CopyTask.CopyDoneListener, val listener: OnCopyListener) {
|
||||||
|
|
||||||
init {
|
init {
|
||||||
val context = activity
|
val context = activity
|
||||||
val view = LayoutInflater.from(context).inflate(R.layout.copy_item, null)
|
val view = LayoutInflater.from(context).inflate(R.layout.copy_item, null)
|
||||||
val sourcePath = files[0].parent.trimEnd('/')
|
val sourcePath = files[0].parent.trimEnd('/')
|
||||||
var destinationPath = ""
|
var destinationPath = ""
|
||||||
|
val config = Config.newInstance(context)
|
||||||
|
|
||||||
view.source.text = context.humanizePath(sourcePath)
|
view.source.text = context.humanizePath(sourcePath)
|
||||||
|
|
||||||
|
@ -65,15 +66,15 @@ class CopyDialog(val activity: Activity, val files: List<File>, val copyListener
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Utils.isShowingWritePermissions(context, destinationDir)) {
|
if (activity.isShowingPermDialog(destinationDir)) {
|
||||||
return@setOnClickListener
|
return@setOnClickListener
|
||||||
}
|
}
|
||||||
|
|
||||||
//if (view.dialog_radio_group.checkedRadioButtonId == R.id.dialog_radio_copy) {
|
//if (view.dialog_radio_group.checkedRadioButtonId == R.id.dialog_radio_copy) {
|
||||||
context.toast(R.string.copying)
|
context.toast(R.string.copying)
|
||||||
val pair = Pair<List<File>, File>(files, destinationDir)
|
val pair = Pair<List<File>, File>(files, destinationDir)
|
||||||
CopyTask(copyListener, context).execute(pair)
|
CopyTask(copyListener, context).execute(pair)
|
||||||
dismiss()
|
dismiss()
|
||||||
/*} else {
|
/*} else {
|
||||||
if (Utils.isPathOnSD(context, sourcePath) && Utils.isPathOnSD(context, destinationPath)) {
|
if (Utils.isPathOnSD(context, sourcePath) && Utils.isPathOnSD(context, destinationPath)) {
|
||||||
val paths = ArrayList<String>()
|
val paths = ArrayList<String>()
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
package com.simplemobiletools.gallery.dialogs
|
package com.simplemobiletools.gallery.dialogs
|
||||||
|
|
||||||
import android.app.Activity
|
|
||||||
import android.support.v7.app.AlertDialog
|
import android.support.v7.app.AlertDialog
|
||||||
import android.view.LayoutInflater
|
import android.view.LayoutInflater
|
||||||
import android.view.WindowManager
|
import android.view.WindowManager
|
||||||
|
@ -10,13 +9,13 @@ import com.simplemobiletools.filepicker.extensions.needsStupidWritePermissions
|
||||||
import com.simplemobiletools.filepicker.extensions.toast
|
import com.simplemobiletools.filepicker.extensions.toast
|
||||||
import com.simplemobiletools.gallery.Config
|
import com.simplemobiletools.gallery.Config
|
||||||
import com.simplemobiletools.gallery.R
|
import com.simplemobiletools.gallery.R
|
||||||
import com.simplemobiletools.gallery.Utils
|
import com.simplemobiletools.gallery.activities.SimpleActivity
|
||||||
import com.simplemobiletools.gallery.extensions.value
|
import com.simplemobiletools.gallery.extensions.value
|
||||||
import kotlinx.android.synthetic.main.rename_directory.view.*
|
import kotlinx.android.synthetic.main.rename_directory.view.*
|
||||||
import java.io.File
|
import java.io.File
|
||||||
import java.util.*
|
import java.util.*
|
||||||
|
|
||||||
class RenameDirectoryDialog(val activity: Activity, val dir: File, val listener: OnRenameDirListener) {
|
class RenameDirectoryDialog(val activity: SimpleActivity, val dir: File, val listener: OnRenameDirListener) {
|
||||||
val context = activity
|
val context = activity
|
||||||
|
|
||||||
init {
|
init {
|
||||||
|
@ -46,7 +45,7 @@ class RenameDirectoryDialog(val activity: Activity, val dir: File, val listener:
|
||||||
val newDir = File(dir.parent, newDirName)
|
val newDir = File(dir.parent, newDirName)
|
||||||
|
|
||||||
if (context.needsStupidWritePermissions(dir.absolutePath)) {
|
if (context.needsStupidWritePermissions(dir.absolutePath)) {
|
||||||
if (Utils.isShowingWritePermissions(activity, dir))
|
if (activity.isShowingPermDialog(dir))
|
||||||
return@setOnClickListener
|
return@setOnClickListener
|
||||||
|
|
||||||
val document = context.getFileDocument(dir.absolutePath, Config.newInstance(context).treeUri)
|
val document = context.getFileDocument(dir.absolutePath, Config.newInstance(context).treeUri)
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
package com.simplemobiletools.gallery.dialogs
|
package com.simplemobiletools.gallery.dialogs
|
||||||
|
|
||||||
import android.app.Activity
|
|
||||||
import android.media.MediaScannerConnection
|
import android.media.MediaScannerConnection
|
||||||
import android.support.v7.app.AlertDialog
|
import android.support.v7.app.AlertDialog
|
||||||
import android.view.LayoutInflater
|
import android.view.LayoutInflater
|
||||||
|
@ -11,12 +10,12 @@ import com.simplemobiletools.filepicker.extensions.needsStupidWritePermissions
|
||||||
import com.simplemobiletools.filepicker.extensions.toast
|
import com.simplemobiletools.filepicker.extensions.toast
|
||||||
import com.simplemobiletools.gallery.Config
|
import com.simplemobiletools.gallery.Config
|
||||||
import com.simplemobiletools.gallery.R
|
import com.simplemobiletools.gallery.R
|
||||||
import com.simplemobiletools.gallery.Utils
|
import com.simplemobiletools.gallery.activities.SimpleActivity
|
||||||
import com.simplemobiletools.gallery.extensions.value
|
import com.simplemobiletools.gallery.extensions.value
|
||||||
import kotlinx.android.synthetic.main.rename_file.view.*
|
import kotlinx.android.synthetic.main.rename_file.view.*
|
||||||
import java.io.File
|
import java.io.File
|
||||||
|
|
||||||
class RenameFileDialog(val activity: Activity, val file: File, val listener: OnRenameFileListener) {
|
class RenameFileDialog(val activity: SimpleActivity, val file: File, val listener: OnRenameFileListener) {
|
||||||
|
|
||||||
init {
|
init {
|
||||||
val context = activity
|
val context = activity
|
||||||
|
@ -54,7 +53,7 @@ class RenameFileDialog(val activity: Activity, val file: File, val listener: OnR
|
||||||
val newFile = File(file.parent, "$fileName.$extension")
|
val newFile = File(file.parent, "$fileName.$extension")
|
||||||
|
|
||||||
if (context.needsStupidWritePermissions(file.absolutePath)) {
|
if (context.needsStupidWritePermissions(file.absolutePath)) {
|
||||||
if (Utils.isShowingWritePermissions(activity, file))
|
if (activity.isShowingPermDialog(file))
|
||||||
return@setOnClickListener
|
return@setOnClickListener
|
||||||
|
|
||||||
val document = context.getFileDocument(file.absolutePath, Config.newInstance(context).treeUri)
|
val document = context.getFileDocument(file.absolutePath, Config.newInstance(context).treeUri)
|
||||||
|
|
|
@ -1,31 +0,0 @@
|
||||||
package com.simplemobiletools.gallery.dialogs
|
|
||||||
|
|
||||||
import android.content.Context
|
|
||||||
import android.support.v7.app.AlertDialog
|
|
||||||
import android.view.LayoutInflater
|
|
||||||
import com.simplemobiletools.gallery.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() })
|
|
||||||
.create()
|
|
||||||
|
|
||||||
dialog?.show()
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun dialogConfirmed() {
|
|
||||||
dialog?.dismiss()
|
|
||||||
listener.onConfirmed()
|
|
||||||
}
|
|
||||||
|
|
||||||
interface OnWritePermissionListener {
|
|
||||||
fun onConfirmed()
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
Reference in a new issue