add some helper menu buttons for emptying and disabling recycle bin

This commit is contained in:
tibbi 2018-06-27 16:56:22 +02:00
parent 0856abfb83
commit 8397ebac66
5 changed files with 50 additions and 0 deletions

View File

@ -198,6 +198,9 @@ class MediaActivity : SimpleActivity(), MediaAdapter.MediaOperationsListener {
findItem(R.id.unhide_folder).isVisible = isFolderHidden && !mShowAll && mPath != FAVORITES && mPath != RECYCLE_BIN
findItem(R.id.exclude_folder).isVisible = !mShowAll && mPath != FAVORITES && mPath != RECYCLE_BIN
findItem(R.id.empty_recycle_bin).isVisible = mPath == RECYCLE_BIN
findItem(R.id.empty_disable_recycle_bin).isVisible = mPath == RECYCLE_BIN
findItem(R.id.folder_view).isVisible = mShowAll
findItem(R.id.open_camera).isVisible = mShowAll
findItem(R.id.about).isVisible = mShowAll
@ -219,6 +222,8 @@ class MediaActivity : SimpleActivity(), MediaAdapter.MediaOperationsListener {
when (item.itemId) {
R.id.sort -> showSortingDialog()
R.id.filter -> showFilterMediaDialog()
R.id.empty_recycle_bin -> emptyRecycleBin()
R.id.empty_disable_recycle_bin -> emptyAndDisableRecycleBin()
R.id.toggle_filename -> toggleFilenameVisibility()
R.id.open_camera -> launchCamera()
R.id.folder_view -> switchToFolderView()
@ -418,6 +423,18 @@ class MediaActivity : SimpleActivity(), MediaAdapter.MediaOperationsListener {
}
}
private fun emptyRecycleBin() {
emptyTheRecycleBin {
finish()
}
}
private fun emptyAndDisableRecycleBin() {
emptyAndDisableTheRecycleBin {
finish()
}
}
private fun toggleFilenameVisibility() {
config.displayFileNames = !config.displayFileNames
getMediaAdapter()?.updateDisplayFilenames(config.displayFileNames)

View File

@ -204,3 +204,21 @@ fun BaseSimpleActivity.movePathsInRecycleBin(paths: ArrayList<String>, callback:
callback?.invoke(pathsCnt == 0)
}.start()
}
fun BaseSimpleActivity.emptyTheRecycleBin(callback: () -> Unit) {
Thread {
filesDir.deleteRecursively()
galleryDB.MediumDao().clearRecycleBin()
galleryDB.DirectoryDao().deleteRecycleBin()
callback()
}.start()
}
fun BaseSimpleActivity.emptyAndDisableTheRecycleBin(callback: () -> Unit) {
Thread {
emptyTheRecycleBin {
config.useRecycleBin = false
callback()
}
}.start()
}

View File

@ -4,6 +4,7 @@ import android.arch.persistence.room.Dao
import android.arch.persistence.room.Insert
import android.arch.persistence.room.OnConflictStrategy.REPLACE
import android.arch.persistence.room.Query
import com.simplemobiletools.gallery.helpers.RECYCLE_BIN
import com.simplemobiletools.gallery.models.Directory
@Dao
@ -25,4 +26,7 @@ interface DirectoryDao {
@Query("UPDATE directories SET thumbnail = :thumbnail, filename = :name, path = :newPath WHERE path = :oldPath COLLATE NOCASE")
fun updateDirectoryAfterRename(thumbnail: String, name: String, newPath: String, oldPath: String)
@Query("DELETE FROM directories WHERE path = \'$RECYCLE_BIN\' COLLATE NOCASE")
fun deleteRecycleBin()
}

View File

@ -37,4 +37,7 @@ interface MediumDao {
@Query("UPDATE media SET deleted_ts = :deletedTS WHERE full_path = :path COLLATE NOCASE")
fun updateDeleted(path: String, deletedTS: Long)
@Query("DELETE FROM media WHERE deleted_ts != 0")
fun clearRecycleBin()
}

View File

@ -22,6 +22,14 @@
android:icon="@drawable/ic_filter"
android:title="@string/filter_media"
app:showAsAction="ifRoom"/>
<item
android:id="@+id/empty_recycle_bin"
android:title="@string/empty_recycle_bin"
app:showAsAction="never"/>
<item
android:id="@+id/empty_disable_recycle_bin"
android:title="@string/empty_and_disable_recycle_bin"
app:showAsAction="never"/>
<item
android:id="@+id/folder_view"
android:title="@string/folder_view"