add some additional menu items for restoring recycle bin items

This commit is contained in:
tibbi 2018-06-27 20:46:14 +02:00
parent 4923d5e4af
commit 2dc18e7166
7 changed files with 54 additions and 9 deletions

View File

@ -200,6 +200,7 @@ class MediaActivity : SimpleActivity(), MediaAdapter.MediaOperationsListener {
findItem(R.id.empty_recycle_bin).isVisible = mPath == RECYCLE_BIN
findItem(R.id.empty_disable_recycle_bin).isVisible = mPath == RECYCLE_BIN
findItem(R.id.restore_all_files).isVisible = mPath == RECYCLE_BIN
findItem(R.id.folder_view).isVisible = mShowAll
findItem(R.id.open_camera).isVisible = mShowAll
@ -224,6 +225,7 @@ class MediaActivity : SimpleActivity(), MediaAdapter.MediaOperationsListener {
R.id.filter -> showFilterMediaDialog()
R.id.empty_recycle_bin -> emptyRecycleBin()
R.id.empty_disable_recycle_bin -> emptyAndDisableRecycleBin()
R.id.restore_all_files -> restoreAllFiles()
R.id.toggle_filename -> toggleFilenameVisibility()
R.id.open_camera -> launchCamera()
R.id.folder_view -> switchToFolderView()
@ -424,13 +426,24 @@ class MediaActivity : SimpleActivity(), MediaAdapter.MediaOperationsListener {
}
private fun emptyRecycleBin() {
emptyTheRecycleBin {
finish()
showRecycleBinEmptyingDialog {
emptyTheRecycleBin {
finish()
}
}
}
private fun emptyAndDisableRecycleBin() {
emptyAndDisableTheRecycleBin {
showRecycleBinEmptyingDialog {
emptyAndDisableTheRecycleBin {
finish()
}
}
}
private fun restoreAllFiles() {
val paths = mMedia.filter { it is Medium }.map { (it as Medium).path } as ArrayList<String>
restoreRecycleBinPaths(paths) {
finish()
}
}

View File

@ -16,6 +16,7 @@ import com.simplemobiletools.gallery.dialogs.ManageExtendedDetailsDialog
import com.simplemobiletools.gallery.extensions.config
import com.simplemobiletools.gallery.extensions.emptyTheRecycleBin
import com.simplemobiletools.gallery.extensions.galleryDB
import com.simplemobiletools.gallery.extensions.showRecycleBinEmptyingDialog
import com.simplemobiletools.gallery.helpers.ROTATE_BY_ASPECT_RATIO
import com.simplemobiletools.gallery.helpers.ROTATE_BY_DEVICE_ROTATION
import com.simplemobiletools.gallery.helpers.ROTATE_BY_SYSTEM_SETTING
@ -435,7 +436,7 @@ class SettingsActivity : SimpleActivity() {
if (mRecycleBinContentSize == 0L) {
toast(R.string.recycle_bin_empty)
} else {
ConfirmationDialog(this, "", R.string.empty_recycle_bin_confirmation, R.string.yes, R.string.no) {
showRecycleBinEmptyingDialog {
emptyTheRecycleBin()
mRecycleBinContentSize = 0L
settings_empty_recycle_bin_size.text = 0L.formatSize()

View File

@ -214,14 +214,18 @@ class DirectoryAdapter(activity: BaseSimpleActivity, var dirs: ArrayList<Directo
}
private fun emptyRecycleBin() {
activity.emptyTheRecycleBin {
listener?.refreshItems()
activity.showRecycleBinEmptyingDialog {
activity.emptyTheRecycleBin {
listener?.refreshItems()
}
}
}
private fun emptyAndDisableRecycleBin() {
activity.emptyAndDisableTheRecycleBin {
listener?.refreshItems()
activity.showRecycleBinEmptyingDialog {
activity.emptyAndDisableTheRecycleBin {
listener?.refreshItems()
}
}
}

View File

@ -108,6 +108,7 @@ class MediaAdapter(activity: BaseSimpleActivity, var media: MutableList<Thumbnai
findItem(R.id.cab_rename).isVisible = isOneItemSelected()
findItem(R.id.cab_open_with).isVisible = isOneItemSelected()
findItem(R.id.cab_confirm_selection).isVisible = isAGetIntent && allowMultiplePicks && selectedPositions.size > 0
findItem(R.id.cab_restore_recycle_bin_files).isVisible = getSelectedPaths().all { it.startsWith(activity.filesDir.toString()) }
checkHideBtnVisibility(this)
checkFavoriteBtnVisibility(this)
@ -128,6 +129,7 @@ class MediaAdapter(activity: BaseSimpleActivity, var media: MutableList<Thumbnai
R.id.cab_unhide -> toggleFileVisibility(false)
R.id.cab_add_to_favorites -> toggleFavorites(true)
R.id.cab_remove_from_favorites -> toggleFavorites(false)
R.id.cab_restore_recycle_bin_files -> restoreFiles()
R.id.cab_share -> shareMedia()
R.id.cab_copy_to -> copyMoveTo(true)
R.id.cab_move_to -> copyMoveTo(false)
@ -244,6 +246,13 @@ class MediaAdapter(activity: BaseSimpleActivity, var media: MutableList<Thumbnai
}.start()
}
private fun restoreFiles() {
activity.restoreRecycleBinPaths(getSelectedPaths()) {
listener?.refreshItems()
finishActMode()
}
}
private fun shareMedia() {
if (selectedPositions.size == 1 && selectedPositions.first() != -1) {
activity.shareMediumPath(getSelectedMedia().first().path)

View File

@ -6,6 +6,7 @@ import android.provider.MediaStore
import android.support.v7.app.AppCompatActivity
import android.view.View
import com.simplemobiletools.commons.activities.BaseSimpleActivity
import com.simplemobiletools.commons.dialogs.ConfirmationDialog
import com.simplemobiletools.commons.extensions.*
import com.simplemobiletools.commons.helpers.*
import com.simplemobiletools.commons.models.FAQItem
@ -232,7 +233,10 @@ fun BaseSimpleActivity.restoreRecycleBinPaths(paths: ArrayList<String>, callback
out?.close()
}
}
callback()
runOnUiThread {
callback()
}
}.start()
}
@ -254,3 +258,9 @@ fun BaseSimpleActivity.emptyAndDisableTheRecycleBin(callback: () -> Unit) {
}
}.start()
}
fun BaseSimpleActivity.showRecycleBinEmptyingDialog(callback: () -> Unit) {
ConfirmationDialog(this, "", R.string.empty_recycle_bin_confirmation, R.string.yes, R.string.no) {
callback()
}
}

View File

@ -56,6 +56,10 @@
android:icon="@drawable/ic_star_on"
android:title="@string/remove_from_favorites"
app:showAsAction="ifRoom"/>
<item
android:id="@+id/cab_restore_recycle_bin_files"
android:title="@string/restore_selected_files"
app:showAsAction="never"/>
<item
android:id="@+id/cab_open_with"
android:title="@string/open_with"

View File

@ -30,6 +30,10 @@
android:id="@+id/empty_disable_recycle_bin"
android:title="@string/empty_and_disable_recycle_bin"
app:showAsAction="never"/>
<item
android:id="@+id/restore_all_files"
android:title="@string/restore_all_files"
app:showAsAction="never"/>
<item
android:id="@+id/folder_view"
android:title="@string/folder_view"