mirror of
https://github.com/FossifyOrg/Gallery.git
synced 2024-11-26 22:47:59 +01:00
remove the Undo option of deleting at viewpager, as there is a confirmation box
This commit is contained in:
parent
bbdafef491
commit
c4644c73a5
7 changed files with 25 additions and 96 deletions
|
@ -10,7 +10,6 @@ import android.support.v4.view.ViewPager
|
||||||
import android.view.Menu
|
import android.view.Menu
|
||||||
import android.view.MenuItem
|
import android.view.MenuItem
|
||||||
import android.view.View
|
import android.view.View
|
||||||
import android.widget.RelativeLayout
|
|
||||||
import com.simplemobiletools.filepicker.asynctasks.CopyMoveTask
|
import com.simplemobiletools.filepicker.asynctasks.CopyMoveTask
|
||||||
import com.simplemobiletools.filepicker.dialogs.ConfirmationDialog
|
import com.simplemobiletools.filepicker.dialogs.ConfirmationDialog
|
||||||
import com.simplemobiletools.filepicker.extensions.*
|
import com.simplemobiletools.filepicker.extensions.*
|
||||||
|
@ -33,11 +32,8 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View
|
||||||
private var mMedia: MutableList<Medium>? = null
|
private var mMedia: MutableList<Medium>? = null
|
||||||
private var mPath = ""
|
private var mPath = ""
|
||||||
private var mDirectory = ""
|
private var mDirectory = ""
|
||||||
private var mToBeDeleted = ""
|
|
||||||
private var mBeingDeleted = ""
|
|
||||||
|
|
||||||
private var mIsFullScreen = false
|
private var mIsFullScreen = false
|
||||||
private var mIsUndoShown = false
|
|
||||||
private var mPos = 0
|
private var mPos = 0
|
||||||
|
|
||||||
override fun onCreate(savedInstanceState: Bundle?) {
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
|
@ -75,11 +71,8 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View
|
||||||
|
|
||||||
mPos = 0
|
mPos = 0
|
||||||
mIsFullScreen = false
|
mIsFullScreen = false
|
||||||
mToBeDeleted = ""
|
|
||||||
mBeingDeleted = ""
|
|
||||||
|
|
||||||
scanPath(mPath) {}
|
scanPath(mPath) {}
|
||||||
addUndoMargin()
|
|
||||||
mDirectory = File(mPath).parent
|
mDirectory = File(mPath).parent
|
||||||
mMedia = getMedia()
|
mMedia = getMedia()
|
||||||
if (isDirEmpty())
|
if (isDirEmpty())
|
||||||
|
@ -88,7 +81,6 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View
|
||||||
updatePagerItems()
|
updatePagerItems()
|
||||||
window.decorView.setOnSystemUiVisibilityChangeListener(this)
|
window.decorView.setOnSystemUiVisibilityChangeListener(this)
|
||||||
updateActionbarTitle()
|
updateActionbarTitle()
|
||||||
undo_delete.setOnClickListener { undoDeletion() }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onResume() {
|
override fun onResume() {
|
||||||
|
@ -98,14 +90,6 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun undoDeletion() {
|
|
||||||
mIsUndoShown = false
|
|
||||||
mToBeDeleted = ""
|
|
||||||
mBeingDeleted = ""
|
|
||||||
undo_delete.visibility = View.GONE
|
|
||||||
reloadViewPager()
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun onCreateOptionsMenu(menu: Menu): Boolean {
|
override fun onCreateOptionsMenu(menu: Menu): Boolean {
|
||||||
menuInflater.inflate(R.menu.viewpager_menu, menu)
|
menuInflater.inflate(R.menu.viewpager_menu, menu)
|
||||||
menu.findItem(R.id.menu_set_as_wallpaper).isVisible = getCurrentMedium().isImage()
|
menu.findItem(R.id.menu_set_as_wallpaper).isVisible = getCurrentMedium().isImage()
|
||||||
|
@ -206,59 +190,35 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View
|
||||||
|
|
||||||
private fun askConfirmDelete() {
|
private fun askConfirmDelete() {
|
||||||
ConfirmationDialog(this) {
|
ConfirmationDialog(this) {
|
||||||
notifyDeletion()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun notifyDeletion() {
|
|
||||||
if (isShowingPermDialog(File(mPath)))
|
|
||||||
return
|
|
||||||
|
|
||||||
mToBeDeleted = getCurrentFile().absolutePath
|
|
||||||
if (mMedia!!.size <= 1) {
|
|
||||||
deleteFile()
|
deleteFile()
|
||||||
} else {
|
|
||||||
toast(R.string.file_deleted)
|
|
||||||
undo_delete.visibility = View.VISIBLE
|
|
||||||
mIsUndoShown = true
|
|
||||||
reloadViewPager()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun deleteFile() {
|
private fun deleteFile() {
|
||||||
if (mToBeDeleted.isEmpty())
|
val file = File(mPath)
|
||||||
|
if (isShowingPermDialog(file))
|
||||||
return
|
return
|
||||||
|
|
||||||
mIsUndoShown = false
|
if (needsStupidWritePermissions(mPath)) {
|
||||||
mBeingDeleted = ""
|
|
||||||
var mWasFileDeleted = false
|
|
||||||
|
|
||||||
val file = File(mToBeDeleted)
|
|
||||||
if (needsStupidWritePermissions(mToBeDeleted)) {
|
|
||||||
if (!isShowingPermDialog(file)) {
|
if (!isShowingPermDialog(file)) {
|
||||||
val document = getFileDocument(mToBeDeleted, mConfig.treeUri)
|
val document = getFileDocument(mPath, mConfig.treeUri)
|
||||||
if (document.uri.toString().endsWith(file.absolutePath.getFilenameFromPath()) && !document.isDirectory)
|
if (document.uri.toString().endsWith(file.absolutePath.getFilenameFromPath()) && !document.isDirectory)
|
||||||
mWasFileDeleted = document.delete()
|
document.delete()
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
mWasFileDeleted = file.delete()
|
file.delete()
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!mWasFileDeleted) {
|
|
||||||
try {
|
try {
|
||||||
mWasFileDeleted = file.delete()
|
if (file.exists())
|
||||||
|
file.delete()
|
||||||
} catch (ignored: Exception) {
|
} catch (ignored: Exception) {
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if (mWasFileDeleted) {
|
scanFile(file) {
|
||||||
mBeingDeleted = mToBeDeleted
|
reloadViewPager()
|
||||||
scanPath(mToBeDeleted) { scanCompleted() }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
mToBeDeleted = ""
|
|
||||||
undo_delete.visibility = View.GONE
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun isDirEmpty(): Boolean {
|
private fun isDirEmpty(): Boolean {
|
||||||
|
@ -323,7 +283,6 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View
|
||||||
val pathIndex = cursor.getColumnIndex(MediaStore.Images.Media.DATA)
|
val pathIndex = cursor.getColumnIndex(MediaStore.Images.Media.DATA)
|
||||||
do {
|
do {
|
||||||
val curPath = cursor.getString(pathIndex) ?: continue
|
val curPath = cursor.getString(pathIndex) ?: continue
|
||||||
if (curPath != mToBeDeleted && curPath != mBeingDeleted) {
|
|
||||||
val file = File(curPath)
|
val file = File(curPath)
|
||||||
val size = cursor.getLongValue(MediaStore.Images.Media.SIZE)
|
val size = cursor.getLongValue(MediaStore.Images.Media.SIZE)
|
||||||
|
|
||||||
|
@ -339,7 +298,6 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View
|
||||||
val name = cursor.getStringValue(MediaStore.Images.Media.DISPLAY_NAME)
|
val name = cursor.getStringValue(MediaStore.Images.Media.DISPLAY_NAME)
|
||||||
val timestamp = cursor.getLongValue(MediaStore.Images.Media.DATE_MODIFIED)
|
val timestamp = cursor.getLongValue(MediaStore.Images.Media.DATE_MODIFIED)
|
||||||
media.add(Medium(name, curPath, i == 1, timestamp, size))
|
media.add(Medium(name, curPath, i == 1, timestamp, size))
|
||||||
}
|
|
||||||
} while (cursor.moveToNext())
|
} while (cursor.moveToNext())
|
||||||
}
|
}
|
||||||
} finally {
|
} finally {
|
||||||
|
@ -383,19 +341,6 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View
|
||||||
|
|
||||||
private fun getCurrentFile() = File(getCurrentMedium().path)
|
private fun getCurrentFile() = File(getCurrentMedium().path)
|
||||||
|
|
||||||
private fun addUndoMargin() {
|
|
||||||
val res = resources
|
|
||||||
val params = undo_delete.layoutParams as RelativeLayout.LayoutParams
|
|
||||||
val topMargin = res.getStatusBarHeight() + res.getActionBarHeight(applicationContext)
|
|
||||||
var rightMargin = params.rightMargin
|
|
||||||
|
|
||||||
if (res.configuration.orientation != Configuration.ORIENTATION_PORTRAIT) {
|
|
||||||
rightMargin += res.getNavBarHeight()
|
|
||||||
}
|
|
||||||
|
|
||||||
params.setMargins(params.leftMargin, topMargin, rightMargin, params.bottomMargin)
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun onPageScrolled(position: Int, positionOffset: Float, positionOffsetPixels: Int) {
|
override fun onPageScrolled(position: Int, positionOffset: Float, positionOffsetPixels: Int) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -423,16 +368,10 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun scanCompleted() {
|
private fun scanCompleted() {
|
||||||
mBeingDeleted = ""
|
|
||||||
runOnUiThread {
|
runOnUiThread {
|
||||||
if (mMedia != null && mMedia!!.size <= 1) {
|
if (mMedia != null && mMedia!!.size <= 1) {
|
||||||
reloadViewPager()
|
reloadViewPager()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onPause() {
|
|
||||||
super.onPause()
|
|
||||||
deleteFile()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,14 +10,4 @@
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent"/>
|
android:layout_height="match_parent"/>
|
||||||
|
|
||||||
<ImageView
|
|
||||||
android:id="@+id/undo_delete"
|
|
||||||
android:layout_width="@dimen/undo_size"
|
|
||||||
android:layout_height="@dimen/undo_size"
|
|
||||||
android:layout_alignParentRight="true"
|
|
||||||
android:layout_alignParentTop="true"
|
|
||||||
android:padding="@dimen/undo_padding"
|
|
||||||
android:src="@mipmap/undo"
|
|
||||||
android:visibility="gone"/>
|
|
||||||
|
|
||||||
</RelativeLayout>
|
</RelativeLayout>
|
||||||
|
|
Binary file not shown.
Before Width: | Height: | Size: 477 B |
Binary file not shown.
Before Width: | Height: | Size: 339 B |
Binary file not shown.
Before Width: | Height: | Size: 606 B |
Binary file not shown.
Before Width: | Height: | Size: 894 B |
Binary file not shown.
Before Width: | Height: | Size: 1.1 KiB |
Loading…
Reference in a new issue