mirror of
https://github.com/FossifyOrg/Gallery.git
synced 2024-11-23 04:57:59 +01:00
allow restoring files from the recycle bin at the fullscreen view
This commit is contained in:
parent
e57a8d60eb
commit
4923d5e4af
3 changed files with 43 additions and 0 deletions
|
@ -298,6 +298,7 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View
|
||||||
findItem(R.id.menu_unhide).isVisible = currentMedium.name.startsWith('.')
|
findItem(R.id.menu_unhide).isVisible = currentMedium.name.startsWith('.')
|
||||||
findItem(R.id.menu_add_to_favorites).isVisible = !currentMedium.isFavorite && !config.bottomActions
|
findItem(R.id.menu_add_to_favorites).isVisible = !currentMedium.isFavorite && !config.bottomActions
|
||||||
findItem(R.id.menu_remove_from_favorites).isVisible = currentMedium.isFavorite && !config.bottomActions
|
findItem(R.id.menu_remove_from_favorites).isVisible = currentMedium.isFavorite && !config.bottomActions
|
||||||
|
findItem(R.id.menu_restore_file).isVisible = currentMedium.path.startsWith(filesDir.toString())
|
||||||
findItem(R.id.menu_lock_orientation).isVisible = mRotationDegrees == 0
|
findItem(R.id.menu_lock_orientation).isVisible = mRotationDegrees == 0
|
||||||
findItem(R.id.menu_lock_orientation).title = getString(if (mIsOrientationLocked) R.string.unlock_orientation else R.string.lock_orientation)
|
findItem(R.id.menu_lock_orientation).title = getString(if (mIsOrientationLocked) R.string.unlock_orientation else R.string.lock_orientation)
|
||||||
findItem(R.id.menu_rotate).setShowAsAction(
|
findItem(R.id.menu_rotate).setShowAsAction(
|
||||||
|
@ -336,6 +337,7 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View
|
||||||
R.id.menu_rotate_left -> rotateImage(270)
|
R.id.menu_rotate_left -> rotateImage(270)
|
||||||
R.id.menu_add_to_favorites -> toggleFavorite()
|
R.id.menu_add_to_favorites -> toggleFavorite()
|
||||||
R.id.menu_remove_from_favorites -> toggleFavorite()
|
R.id.menu_remove_from_favorites -> toggleFavorite()
|
||||||
|
R.id.menu_restore_file -> restoreFile()
|
||||||
R.id.menu_rotate_one_eighty -> rotateImage(180)
|
R.id.menu_rotate_one_eighty -> rotateImage(180)
|
||||||
R.id.menu_lock_orientation -> toggleLockOrientation()
|
R.id.menu_lock_orientation -> toggleLockOrientation()
|
||||||
R.id.menu_save_as -> saveImageAs()
|
R.id.menu_save_as -> saveImageAs()
|
||||||
|
@ -809,6 +811,12 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View
|
||||||
}.start()
|
}.start()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun restoreFile() {
|
||||||
|
restoreRecycleBinPath(getCurrentPath()) {
|
||||||
|
refreshViewPager()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
override fun onActivityResult(requestCode: Int, resultCode: Int, resultData: Intent?) {
|
override fun onActivityResult(requestCode: Int, resultCode: Int, resultData: Intent?) {
|
||||||
if (requestCode == REQUEST_EDIT_IMAGE) {
|
if (requestCode == REQUEST_EDIT_IMAGE) {
|
||||||
if (resultCode == Activity.RESULT_OK && resultData != null) {
|
if (resultCode == Activity.RESULT_OK && resultData != null) {
|
||||||
|
|
|
@ -16,6 +16,8 @@ import com.simplemobiletools.gallery.activities.SimpleActivity
|
||||||
import com.simplemobiletools.gallery.dialogs.PickDirectoryDialog
|
import com.simplemobiletools.gallery.dialogs.PickDirectoryDialog
|
||||||
import com.simplemobiletools.gallery.helpers.NOMEDIA
|
import com.simplemobiletools.gallery.helpers.NOMEDIA
|
||||||
import java.io.File
|
import java.io.File
|
||||||
|
import java.io.InputStream
|
||||||
|
import java.io.OutputStream
|
||||||
import java.util.*
|
import java.util.*
|
||||||
|
|
||||||
fun Activity.sharePath(path: String) {
|
fun Activity.sharePath(path: String) {
|
||||||
|
@ -205,6 +207,35 @@ fun BaseSimpleActivity.movePathsInRecycleBin(paths: ArrayList<String>, callback:
|
||||||
}.start()
|
}.start()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun BaseSimpleActivity.restoreRecycleBinPath(path: String, callback: () -> Unit) {
|
||||||
|
restoreRecycleBinPaths(arrayListOf(path), callback)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun BaseSimpleActivity.restoreRecycleBinPaths(paths: ArrayList<String>, callback: () -> Unit) {
|
||||||
|
Thread {
|
||||||
|
val mediumDao = galleryDB.MediumDao()
|
||||||
|
paths.forEach {
|
||||||
|
val source = it
|
||||||
|
val destination = it.removePrefix(filesDir.toString())
|
||||||
|
|
||||||
|
var inputStream: InputStream? = null
|
||||||
|
var out: OutputStream? = null
|
||||||
|
try {
|
||||||
|
out = getFileOutputStreamSync(destination, source.getMimeType())
|
||||||
|
inputStream = getFileInputStreamSync(source)!!
|
||||||
|
inputStream.copyTo(out!!)
|
||||||
|
mediumDao.updateDeleted(destination, 0)
|
||||||
|
} catch (e: Exception) {
|
||||||
|
showErrorToast(e)
|
||||||
|
} finally {
|
||||||
|
inputStream?.close()
|
||||||
|
out?.close()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
callback()
|
||||||
|
}.start()
|
||||||
|
}
|
||||||
|
|
||||||
fun BaseSimpleActivity.emptyTheRecycleBin(callback: (() -> Unit)? = null) {
|
fun BaseSimpleActivity.emptyTheRecycleBin(callback: (() -> Unit)? = null) {
|
||||||
Thread {
|
Thread {
|
||||||
filesDir.deleteRecursively()
|
filesDir.deleteRecursively()
|
||||||
|
|
|
@ -44,6 +44,10 @@
|
||||||
android:icon="@drawable/ic_star_on"
|
android:icon="@drawable/ic_star_on"
|
||||||
android:title="@string/remove_from_favorites"
|
android:title="@string/remove_from_favorites"
|
||||||
app:showAsAction="ifRoom"/>
|
app:showAsAction="ifRoom"/>
|
||||||
|
<item
|
||||||
|
android:id="@+id/menu_restore_file"
|
||||||
|
android:title="@string/restore_this_file"
|
||||||
|
app:showAsAction="never"/>
|
||||||
<item
|
<item
|
||||||
android:id="@+id/menu_lock_orientation"
|
android:id="@+id/menu_lock_orientation"
|
||||||
android:title="@string/lock_orientation"
|
android:title="@string/lock_orientation"
|
||||||
|
|
Loading…
Reference in a new issue