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 { 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 'com.theartofdev.edmodo:android-image-cropper:2.8.0'
implementation 'androidx.multidex:multidex:2.0.1' implementation 'androidx.multidex:multidex:2.0.1'
implementation 'it.sephiroth.android.exif:library:1.0.1' implementation 'it.sephiroth.android.exif:library:1.0.1'

View file

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

View file

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

View file

@ -159,10 +159,12 @@ class DirectoryAdapter(activity: BaseSimpleActivity, var dirs: ArrayList<Directo
if (selectedKeys.size <= 1) { if (selectedKeys.size <= 1) {
val path = getFirstSelectedItemPath() ?: return val path = getFirstSelectedItemPath() ?: return
if (path != FAVORITES && path != RECYCLE_BIN) { if (path != FAVORITES && path != RECYCLE_BIN) {
activity.handleLockedFolderOpening(path) { activity.handleLockedFolderOpening(path) { success ->
if (success) {
PropertiesDialog(activity, path, config.shouldShowHidden) PropertiesDialog(activity, path, config.shouldShowHidden)
} }
} }
}
} else { } else {
PropertiesDialog(activity, getSelectedPaths().filter { PropertiesDialog(activity, getSelectedPaths().filter {
it != FAVORITES && it != RECYCLE_BIN && !activity.config.isFolderProtected(it) it != FAVORITES && it != RECYCLE_BIN && !activity.config.isFolderProtected(it)
@ -180,7 +182,8 @@ class DirectoryAdapter(activity: BaseSimpleActivity, var dirs: ArrayList<Directo
return return
} }
activity.handleLockedFolderOpening(sourcePath) { activity.handleLockedFolderOpening(sourcePath) { success ->
if (success) {
RenameItemDialog(activity, dir.absolutePath) { RenameItemDialog(activity, dir.absolutePath) {
activity.runOnUiThread { activity.runOnUiThread {
firstDir.apply { firstDir.apply {
@ -196,6 +199,7 @@ class DirectoryAdapter(activity: BaseSimpleActivity, var dirs: ArrayList<Directo
} }
} }
} }
}
} else { } else {
val paths = getSelectedPaths().filter { !activity.isAStorageRootFolder(it) && !activity.config.isFolderProtected(it) } as ArrayList<String> val paths = getSelectedPaths().filter { !activity.isAStorageRootFolder(it) && !activity.config.isFolderProtected(it) } as ArrayList<String>
RenameItemsDialog(activity, paths) { RenameItemsDialog(activity, paths) {
@ -218,19 +222,24 @@ class DirectoryAdapter(activity: BaseSimpleActivity, var dirs: ArrayList<Directo
val path = it val path = it
if (hide) { if (hide) {
if (config.wasHideFolderTooltipShown) { if (config.wasHideFolderTooltipShown) {
activity.handleLockedFolderOpening(path) { activity.handleLockedFolderOpening(path) { success ->
if (success) {
hideFolder(path) hideFolder(path)
} }
}
} else { } else {
config.wasHideFolderTooltipShown = true config.wasHideFolderTooltipShown = true
ConfirmationDialog(activity, activity.getString(R.string.hide_folder_description)) { ConfirmationDialog(activity, activity.getString(R.string.hide_folder_description)) {
activity.handleLockedFolderOpening(path) { activity.handleLockedFolderOpening(path) { success ->
if (success) {
hideFolder(path) hideFolder(path)
} }
} }
} }
}
} else { } else {
activity.handleLockedFolderOpening(path) { activity.handleLockedFolderOpening(path) { success ->
if (success) {
activity.removeNoMedia(path) { activity.removeNoMedia(path) {
if (activity.config.shouldShowHidden) { if (activity.config.shouldShowHidden) {
updateFolderNames() updateFolderNames()
@ -245,6 +254,7 @@ class DirectoryAdapter(activity: BaseSimpleActivity, var dirs: ArrayList<Directo
} }
} }
} }
}
private fun tryEmptyRecycleBin(askConfirmation: Boolean) { private fun tryEmptyRecycleBin(askConfirmation: Boolean) {
if (askConfirmation) { if (askConfirmation) {
@ -257,15 +267,18 @@ class DirectoryAdapter(activity: BaseSimpleActivity, var dirs: ArrayList<Directo
} }
private fun emptyRecycleBin() { private fun emptyRecycleBin() {
activity.handleLockedFolderOpening(RECYCLE_BIN) { activity.handleLockedFolderOpening(RECYCLE_BIN) { success ->
if (success) {
activity.emptyTheRecycleBin { activity.emptyTheRecycleBin {
listener?.refreshItems() listener?.refreshItems()
} }
} }
} }
}
private fun emptyAndDisableRecycleBin() { private fun emptyAndDisableRecycleBin() {
activity.handleLockedFolderOpening(RECYCLE_BIN) { activity.handleLockedFolderOpening(RECYCLE_BIN) { success ->
if (success) {
activity.showRecycleBinEmptyingDialog { activity.showRecycleBinEmptyingDialog {
activity.emptyAndDisableTheRecycleBin { activity.emptyAndDisableTheRecycleBin {
listener?.refreshItems() listener?.refreshItems()
@ -273,6 +286,7 @@ class DirectoryAdapter(activity: BaseSimpleActivity, var dirs: ArrayList<Directo
} }
} }
} }
}
private fun updateFolderNames() { private fun updateFolderNames() {
val includedFolders = activity.config.includedFolders val includedFolders = activity.config.includedFolders
@ -424,10 +438,12 @@ class DirectoryAdapter(activity: BaseSimpleActivity, var dirs: ArrayList<Directo
} }
private fun tryCreateShortcut() { private fun tryCreateShortcut() {
activity.handleLockedFolderOpening(getFirstSelectedItemPath() ?: "") { activity.handleLockedFolderOpening(getFirstSelectedItemPath() ?: "") { success ->
if (success) {
createShortcut() createShortcut()
} }
} }
}
@SuppressLint("NewApi") @SuppressLint("NewApi")
private fun createShortcut() { private fun createShortcut() {
@ -524,9 +540,11 @@ class DirectoryAdapter(activity: BaseSimpleActivity, var dirs: ArrayList<Directo
} }
if (foldersToDelete.size == 1) { if (foldersToDelete.size == 1) {
activity.handleLockedFolderOpening(foldersToDelete.first().absolutePath) { activity.handleLockedFolderOpening(foldersToDelete.first().absolutePath) { success ->
if (success) {
listener?.deleteFolders(foldersToDelete) listener?.deleteFolders(foldersToDelete)
} }
}
} else { } else {
foldersToDelete = foldersToDelete.filter { !activity.config.isFolderProtected(it.absolutePath) }.toMutableList() as ArrayList<File> foldersToDelete = foldersToDelete.filter { !activity.config.isFolderProtected(it.absolutePath) }.toMutableList() as ArrayList<File>
listener?.deleteFolders(foldersToDelete) listener?.deleteFolders(foldersToDelete)
@ -535,10 +553,12 @@ class DirectoryAdapter(activity: BaseSimpleActivity, var dirs: ArrayList<Directo
} }
private fun tryChangeAlbumCover(useDefault: Boolean) { private fun tryChangeAlbumCover(useDefault: Boolean) {
activity.handleLockedFolderOpening(getFirstSelectedItemPath() ?: "") { activity.handleLockedFolderOpening(getFirstSelectedItemPath() ?: "") { success ->
if (success) {
changeAlbumCover(useDefault) changeAlbumCover(useDefault)
} }
} }
}
private fun changeAlbumCover(useDefault: Boolean) { private fun changeAlbumCover(useDefault: Boolean) {
if (selectedKeys.size != 1) if (selectedKeys.size != 1)

View file

@ -76,11 +76,13 @@ class PickDirectoryDialog(val activity: BaseSimpleActivity, val sourcePath: Stri
private fun showOtherFolder() { private fun showOtherFolder() {
FilePickerDialog(activity, sourcePath, false, showHidden, true, true) { FilePickerDialog(activity, sourcePath, false, showHidden, true, true) {
activity.handleLockedFolderOpening(it) { activity.handleLockedFolderOpening(it) { success ->
if (success) {
callback(it) callback(it)
} }
} }
} }
}
private fun gotDirectories(newDirs: ArrayList<Directory>) { private fun gotDirectories(newDirs: ArrayList<Directory>) {
if (allDirectories.isEmpty()) { if (allDirectories.isEmpty()) {
@ -102,9 +104,11 @@ class PickDirectoryDialog(val activity: BaseSimpleActivity, val sourcePath: Stri
activity.toast(R.string.source_and_destination_same) activity.toast(R.string.source_and_destination_same)
return@DirectoryAdapter return@DirectoryAdapter
} else { } else {
activity.handleLockedFolderOpening(path) { activity.handleLockedFolderOpening(path) { success ->
if (success) {
callback(path) callback(path)
} }
}
dialog.dismiss() dialog.dismiss()
} }
} else { } else {