properly handle locked folders and third party intents

This commit is contained in:
tibbi 2019-07-02 23:18:07 +02:00
parent 3b2d9322fd
commit 9809930390
5 changed files with 98 additions and 57 deletions

View file

@ -61,7 +61,7 @@ android {
}
dependencies {
implementation 'com.simplemobiletools:commons:5.14.9'
implementation 'com.simplemobiletools:commons:5.14.11'
implementation 'com.theartofdev.edmodo:android-image-cropper:2.8.0'
implementation 'androidx.multidex:multidex:2.0.1'
implementation 'it.sephiroth.android.exif:library:1.0.1'

View file

@ -769,10 +769,12 @@ class MainActivity : SimpleActivity(), DirectoryOperationsListener {
}
private fun itemClicked(path: String) {
handleLockedFolderOpening(path) {
Intent(this, MediaActivity::class.java).apply {
putExtra(DIRECTORY, path)
handleMediaIntent(this)
handleLockedFolderOpening(path) { success ->
if (success) {
Intent(this, MediaActivity::class.java).apply {
putExtra(DIRECTORY, path)
handleMediaIntent(this)
}
}
}
}

View file

@ -98,8 +98,13 @@ open class PhotoVideoActivity : SimpleActivity(), ViewPagerFragment.FragmentList
if (realPath != null && File(realPath).exists()) {
if (realPath.getFilenameFromPath().contains('.') || filename.contains('.')) {
if (isFileTypeVisible(realPath)) {
sendViewPagerIntent(realPath)
finish()
bottom_actions.beGone()
handleLockedFolderOpening(realPath.getParentPath()) { success ->
if (success) {
sendViewPagerIntent(realPath)
}
finish()
}
return
}
} else {
@ -110,18 +115,28 @@ open class PhotoVideoActivity : SimpleActivity(), ViewPagerFragment.FragmentList
if (mUri!!.scheme == "file") {
if (filename.contains('.')) {
rescanPaths(arrayListOf(mUri!!.path))
sendViewPagerIntent(mUri!!.path)
finish()
return
bottom_actions.beGone()
handleLockedFolderOpening(mUri!!.path.getParentPath()) { success ->
if (success) {
rescanPaths(arrayListOf(mUri!!.path))
sendViewPagerIntent(mUri!!.path)
}
finish()
}
}
return
} else {
val path = applicationContext.getRealPathFromURI(mUri!!) ?: ""
if (path != mUri.toString() && path.isNotEmpty() && mUri!!.authority != "mms" && filename.contains('.') && File(path).exists()) {
if (isFileTypeVisible(path)) {
rescanPaths(arrayListOf(mUri!!.path))
sendViewPagerIntent(path)
finish()
bottom_actions.beGone()
handleLockedFolderOpening(path.getParentPath()) { success ->
if (success) {
rescanPaths(arrayListOf(mUri!!.path))
sendViewPagerIntent(path)
}
finish()
}
return
}
}

View file

@ -159,8 +159,10 @@ class DirectoryAdapter(activity: BaseSimpleActivity, var dirs: ArrayList<Directo
if (selectedKeys.size <= 1) {
val path = getFirstSelectedItemPath() ?: return
if (path != FAVORITES && path != RECYCLE_BIN) {
activity.handleLockedFolderOpening(path) {
PropertiesDialog(activity, path, config.shouldShowHidden)
activity.handleLockedFolderOpening(path) { success ->
if (success) {
PropertiesDialog(activity, path, config.shouldShowHidden)
}
}
}
} else {
@ -180,18 +182,20 @@ class DirectoryAdapter(activity: BaseSimpleActivity, var dirs: ArrayList<Directo
return
}
activity.handleLockedFolderOpening(sourcePath) {
RenameItemDialog(activity, dir.absolutePath) {
activity.runOnUiThread {
firstDir.apply {
path = it
name = it.getFilenameFromPath()
tmb = File(it, tmb.getFilenameFromPath()).absolutePath
}
updateDirs(dirs)
ensureBackgroundThread {
activity.galleryDB.DirectoryDao().updateDirectoryAfterRename(firstDir.tmb, firstDir.name, firstDir.path, sourcePath)
listener?.refreshItems()
activity.handleLockedFolderOpening(sourcePath) { success ->
if (success) {
RenameItemDialog(activity, dir.absolutePath) {
activity.runOnUiThread {
firstDir.apply {
path = it
name = it.getFilenameFromPath()
tmb = File(it, tmb.getFilenameFromPath()).absolutePath
}
updateDirs(dirs)
ensureBackgroundThread {
activity.galleryDB.DirectoryDao().updateDirectoryAfterRename(firstDir.tmb, firstDir.name, firstDir.path, sourcePath)
listener?.refreshItems()
}
}
}
}
@ -218,26 +222,32 @@ class DirectoryAdapter(activity: BaseSimpleActivity, var dirs: ArrayList<Directo
val path = it
if (hide) {
if (config.wasHideFolderTooltipShown) {
activity.handleLockedFolderOpening(path) {
hideFolder(path)
activity.handleLockedFolderOpening(path) { success ->
if (success) {
hideFolder(path)
}
}
} else {
config.wasHideFolderTooltipShown = true
ConfirmationDialog(activity, activity.getString(R.string.hide_folder_description)) {
activity.handleLockedFolderOpening(path) {
hideFolder(path)
activity.handleLockedFolderOpening(path) { success ->
if (success) {
hideFolder(path)
}
}
}
}
} else {
activity.handleLockedFolderOpening(path) {
activity.removeNoMedia(path) {
if (activity.config.shouldShowHidden) {
updateFolderNames()
} else {
activity.runOnUiThread {
listener?.refreshItems()
finishActMode()
activity.handleLockedFolderOpening(path) { success ->
if (success) {
activity.removeNoMedia(path) {
if (activity.config.shouldShowHidden) {
updateFolderNames()
} else {
activity.runOnUiThread {
listener?.refreshItems()
finishActMode()
}
}
}
}
@ -257,18 +267,22 @@ class DirectoryAdapter(activity: BaseSimpleActivity, var dirs: ArrayList<Directo
}
private fun emptyRecycleBin() {
activity.handleLockedFolderOpening(RECYCLE_BIN) {
activity.emptyTheRecycleBin {
listener?.refreshItems()
activity.handleLockedFolderOpening(RECYCLE_BIN) { success ->
if (success) {
activity.emptyTheRecycleBin {
listener?.refreshItems()
}
}
}
}
private fun emptyAndDisableRecycleBin() {
activity.handleLockedFolderOpening(RECYCLE_BIN) {
activity.showRecycleBinEmptyingDialog {
activity.emptyAndDisableTheRecycleBin {
listener?.refreshItems()
activity.handleLockedFolderOpening(RECYCLE_BIN) { success ->
if (success) {
activity.showRecycleBinEmptyingDialog {
activity.emptyAndDisableTheRecycleBin {
listener?.refreshItems()
}
}
}
}
@ -424,8 +438,10 @@ class DirectoryAdapter(activity: BaseSimpleActivity, var dirs: ArrayList<Directo
}
private fun tryCreateShortcut() {
activity.handleLockedFolderOpening(getFirstSelectedItemPath() ?: "") {
createShortcut()
activity.handleLockedFolderOpening(getFirstSelectedItemPath() ?: "") { success ->
if (success) {
createShortcut()
}
}
}
@ -524,8 +540,10 @@ class DirectoryAdapter(activity: BaseSimpleActivity, var dirs: ArrayList<Directo
}
if (foldersToDelete.size == 1) {
activity.handleLockedFolderOpening(foldersToDelete.first().absolutePath) {
listener?.deleteFolders(foldersToDelete)
activity.handleLockedFolderOpening(foldersToDelete.first().absolutePath) { success ->
if (success) {
listener?.deleteFolders(foldersToDelete)
}
}
} else {
foldersToDelete = foldersToDelete.filter { !activity.config.isFolderProtected(it.absolutePath) }.toMutableList() as ArrayList<File>
@ -535,8 +553,10 @@ class DirectoryAdapter(activity: BaseSimpleActivity, var dirs: ArrayList<Directo
}
private fun tryChangeAlbumCover(useDefault: Boolean) {
activity.handleLockedFolderOpening(getFirstSelectedItemPath() ?: "") {
changeAlbumCover(useDefault)
activity.handleLockedFolderOpening(getFirstSelectedItemPath() ?: "") { success ->
if (success) {
changeAlbumCover(useDefault)
}
}
}

View file

@ -76,8 +76,10 @@ class PickDirectoryDialog(val activity: BaseSimpleActivity, val sourcePath: Stri
private fun showOtherFolder() {
FilePickerDialog(activity, sourcePath, false, showHidden, true, true) {
activity.handleLockedFolderOpening(it) {
callback(it)
activity.handleLockedFolderOpening(it) { success ->
if (success) {
callback(it)
}
}
}
}
@ -102,8 +104,10 @@ class PickDirectoryDialog(val activity: BaseSimpleActivity, val sourcePath: Stri
activity.toast(R.string.source_and_destination_same)
return@DirectoryAdapter
} else {
activity.handleLockedFolderOpening(path) {
callback(path)
activity.handleLockedFolderOpening(path) { success ->
if (success) {
callback(path)
}
}
dialog.dismiss()
}