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

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)) {
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('.')) {
bottom_actions.beGone()
handleLockedFolderOpening(mUri!!.path.getParentPath()) { success ->
if (success) {
rescanPaths(arrayListOf(mUri!!.path))
sendViewPagerIntent(mUri!!.path)
finish()
return
}
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)) {
bottom_actions.beGone()
handleLockedFolderOpening(path.getParentPath()) { success ->
if (success) {
rescanPaths(arrayListOf(mUri!!.path))
sendViewPagerIntent(path)
}
finish()
}
return
}
}

View file

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

View file

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