From c4644c73a5f4359dbdebe9454cb074f379e75c9a Mon Sep 17 00:00:00 2001 From: tibbi Date: Sun, 4 Dec 2016 18:57:58 +0100 Subject: [PATCH] remove the Undo option of deleting at viewpager, as there is a confirmation box --- .../gallery/activities/ViewPagerActivity.kt | 111 ++++-------------- app/src/main/res/layout/activity_medium.xml | 10 -- app/src/main/res/mipmap-hdpi/undo.png | Bin 477 -> 0 bytes app/src/main/res/mipmap-mdpi/undo.png | Bin 339 -> 0 bytes app/src/main/res/mipmap-xhdpi/undo.png | Bin 606 -> 0 bytes app/src/main/res/mipmap-xxhdpi/undo.png | Bin 894 -> 0 bytes app/src/main/res/mipmap-xxxhdpi/undo.png | Bin 1169 -> 0 bytes 7 files changed, 25 insertions(+), 96 deletions(-) delete mode 100644 app/src/main/res/mipmap-hdpi/undo.png delete mode 100644 app/src/main/res/mipmap-mdpi/undo.png delete mode 100644 app/src/main/res/mipmap-xhdpi/undo.png delete mode 100644 app/src/main/res/mipmap-xxhdpi/undo.png delete mode 100644 app/src/main/res/mipmap-xxxhdpi/undo.png diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/ViewPagerActivity.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/ViewPagerActivity.kt index 5ec35837e..6c9c9671d 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/ViewPagerActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/ViewPagerActivity.kt @@ -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? = 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() - } catch (ignored: Exception) { + try { + 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,23 +283,21 @@ 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) + val file = File(curPath) + val size = cursor.getLongValue(MediaStore.Images.Media.SIZE) - if (size == 0L) { - invalidFiles.add(file) - continue - } - - // exclude images of subdirectories - if (file.parent != mDirectory) - continue - - 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)) + if (size == 0L) { + invalidFiles.add(file) + continue } + + // exclude images of subdirectories + if (file.parent != mDirectory) + continue + + 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() - } } diff --git a/app/src/main/res/layout/activity_medium.xml b/app/src/main/res/layout/activity_medium.xml index 4fee5a7ab..cfbab5d0f 100644 --- a/app/src/main/res/layout/activity_medium.xml +++ b/app/src/main/res/layout/activity_medium.xml @@ -10,14 +10,4 @@ android:layout_width="match_parent" android:layout_height="match_parent"/> - - diff --git a/app/src/main/res/mipmap-hdpi/undo.png b/app/src/main/res/mipmap-hdpi/undo.png deleted file mode 100644 index 1e1e3d866125bbeceb283decc5ed3b9f0f696bbe..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 477 zcmV<30V4j1P)D3GFD?@r<9B$_L#^*SyGd&g+Jmb7Sxo&$S^B*)YMEYl&O*2x^UI}yvXEwskcI2a*TTj-XPl1no0^H|`&&J`&+2iOWm%SGS(at}!x7@3b0c$+x9+x;wpo2(B+Ch~TpGoc$kEya<2PKmZ(&Q`Y`$Cfg z0w|GGrbCv-v?+_A7-<*xiO60=gQ5iTNay%~-h0k!pkJf{b!OLX@(Kv9^NOT?(5J;6 zu5pDM+@(XGh@@V!TL2~WmKrD7HuWu>pvDG&s?VNTgPw7U94>J=j?-q$wBGn64b$Up`%kb!;z6yinR TJ@r{w00000NkvXXu0mjf?+@0e diff --git a/app/src/main/res/mipmap-mdpi/undo.png b/app/src/main/res/mipmap-mdpi/undo.png deleted file mode 100644 index c4c28d0a4a8bf7746fff7a34a8df15aabc510bc9..0000000000000000000000000000000000000000 GIT binary pat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NJ;xR$Nv5AFKs0Bi)cnE-aU||jj)#QgRz#{nPiSm+&bnj|Ve(`kmb6Mw< G&;$TOr*3@! diff --git a/app/src/main/res/mipmap-xxxhdpi/undo.png b/app/src/main/res/mipmap-xxxhdpi/undo.png deleted file mode 100644 index 9959132c610b8a6556c0206a52b4ede0702f9853..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 1169 zcmeAS@N?(olHy`uVBq!ia0vp^2SAvE1xWt5x}=AJfhEGz#WAFU@y)?Tpcq5Lg1;-p zS2BT^=pgNWUHoRP#}<9_f9pJtUH#W#;j?8uY7;l?N#5niuahZgo9S|K(F_F@iJ5*BGZ9&}*n=V%^{$ z;AmXFsd>7khkU%zA&bdpHaN^He)419`k!+S?>Q{@?y=alg3jLz+c<+_T&?vl9@iJS zEU~wwSbD1;bA-Z&%q7iob?&QVU`Pd|$9t(MXJug~O|2l8v6Zx47yz z#xCU*i47_xQ=)z|JY&)Q;}s;8+FZ+E+@!;;veHs+15bj(hAHNrN$eiSj`?O1iiKn=p<@(B?JEzihw%MOh;eH^J`=eswTQ<9t!lx_zxeiFaJ9xai z=Jm^T!@1A6zB4X6u}S3oty>Zcf9zXyDYv0~<-yH+Ok#b4bN)`*#Wi8EsJ>eC;li%m z{j(X^BiqCm#~u+r6Bsi)mf7OG*dB>@QEi&bGNodfB$hGiFI)XY;Hb$Vqi_bhMO^yF zKHqd@{9NU^lko#j+?#Ui%QLp0Wn@U7_d7R5=<>fOUhE8W6eEsXER$7y%FtlU5?(BJ zdE03wje{0xe_i*gGzgg(wnnz6Fiu&}8hK_{q?iNeErZuAs+$Ek+XJ& ziQ7({1|gm2>^`@2c^9ypeZqN9W$GmcuM54N)=Pm}rwFs;PuXGuG;ET3Mf6j~DGBBW zrH@T#3uy8_DY(b_3FDLpaZT5i`4_O*IkV)>%c^8h%}}i9Z)IG-GGA!R)78&qol`;+05aRo_5c6?