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.MenuItem
|
||||
import android.view.View
|
||||
import android.widget.RelativeLayout
|
||||
import com.simplemobiletools.filepicker.asynctasks.CopyMoveTask
|
||||
import com.simplemobiletools.filepicker.dialogs.ConfirmationDialog
|
||||
import com.simplemobiletools.filepicker.extensions.*
|
||||
|
@ -33,11 +32,8 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View
|
|||
private var mMedia: MutableList<Medium>? = null
|
||||
private var mPath = ""
|
||||
private var mDirectory = ""
|
||||
private var mToBeDeleted = ""
|
||||
private var mBeingDeleted = ""
|
||||
|
||||
private var mIsFullScreen = false
|
||||
private var mIsUndoShown = false
|
||||
private var mPos = 0
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
|
@ -75,11 +71,8 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View
|
|||
|
||||
mPos = 0
|
||||
mIsFullScreen = false
|
||||
mToBeDeleted = ""
|
||||
mBeingDeleted = ""
|
||||
|
||||
scanPath(mPath) {}
|
||||
addUndoMargin()
|
||||
mDirectory = File(mPath).parent
|
||||
mMedia = getMedia()
|
||||
if (isDirEmpty())
|
||||
|
@ -88,7 +81,6 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View
|
|||
updatePagerItems()
|
||||
window.decorView.setOnSystemUiVisibilityChangeListener(this)
|
||||
updateActionbarTitle()
|
||||
undo_delete.setOnClickListener { undoDeletion() }
|
||||
}
|
||||
|
||||
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 {
|
||||
menuInflater.inflate(R.menu.viewpager_menu, menu)
|
||||
menu.findItem(R.id.menu_set_as_wallpaper).isVisible = getCurrentMedium().isImage()
|
||||
|
@ -206,59 +190,35 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View
|
|||
|
||||
private fun askConfirmDelete() {
|
||||
ConfirmationDialog(this) {
|
||||
notifyDeletion()
|
||||
}
|
||||
}
|
||||
|
||||
private fun notifyDeletion() {
|
||||
if (isShowingPermDialog(File(mPath)))
|
||||
return
|
||||
|
||||
mToBeDeleted = getCurrentFile().absolutePath
|
||||
if (mMedia!!.size <= 1) {
|
||||
deleteFile()
|
||||
} else {
|
||||
toast(R.string.file_deleted)
|
||||
undo_delete.visibility = View.VISIBLE
|
||||
mIsUndoShown = true
|
||||
reloadViewPager()
|
||||
}
|
||||
}
|
||||
|
||||
private fun deleteFile() {
|
||||
if (mToBeDeleted.isEmpty())
|
||||
val file = File(mPath)
|
||||
if (isShowingPermDialog(file))
|
||||
return
|
||||
|
||||
mIsUndoShown = false
|
||||
mBeingDeleted = ""
|
||||
var mWasFileDeleted = false
|
||||
|
||||
val file = File(mToBeDeleted)
|
||||
if (needsStupidWritePermissions(mToBeDeleted)) {
|
||||
if (needsStupidWritePermissions(mPath)) {
|
||||
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)
|
||||
mWasFileDeleted = document.delete()
|
||||
document.delete()
|
||||
}
|
||||
} else {
|
||||
mWasFileDeleted = file.delete()
|
||||
file.delete()
|
||||
}
|
||||
|
||||
if (!mWasFileDeleted) {
|
||||
try {
|
||||
mWasFileDeleted = file.delete()
|
||||
if (file.exists())
|
||||
file.delete()
|
||||
} catch (ignored: Exception) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
if (mWasFileDeleted) {
|
||||
mBeingDeleted = mToBeDeleted
|
||||
scanPath(mToBeDeleted) { scanCompleted() }
|
||||
scanFile(file) {
|
||||
reloadViewPager()
|
||||
}
|
||||
|
||||
mToBeDeleted = ""
|
||||
undo_delete.visibility = View.GONE
|
||||
}
|
||||
|
||||
private fun isDirEmpty(): Boolean {
|
||||
|
@ -323,7 +283,6 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View
|
|||
val pathIndex = cursor.getColumnIndex(MediaStore.Images.Media.DATA)
|
||||
do {
|
||||
val curPath = cursor.getString(pathIndex) ?: continue
|
||||
if (curPath != mToBeDeleted && curPath != mBeingDeleted) {
|
||||
val file = File(curPath)
|
||||
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 timestamp = cursor.getLongValue(MediaStore.Images.Media.DATE_MODIFIED)
|
||||
media.add(Medium(name, curPath, i == 1, timestamp, size))
|
||||
}
|
||||
} while (cursor.moveToNext())
|
||||
}
|
||||
} finally {
|
||||
|
@ -383,19 +341,6 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View
|
|||
|
||||
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) {
|
||||
|
||||
}
|
||||
|
@ -423,16 +368,10 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View
|
|||
}
|
||||
|
||||
private fun scanCompleted() {
|
||||
mBeingDeleted = ""
|
||||
runOnUiThread {
|
||||
if (mMedia != null && mMedia!!.size <= 1) {
|
||||
reloadViewPager()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun onPause() {
|
||||
super.onPause()
|
||||
deleteFile()
|
||||
}
|
||||
}
|
||||
|
|
|
@ -10,14 +10,4 @@
|
|||
android:layout_width="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>
|
||||
|
|
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