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 1e1e3d866..000000000 Binary files a/app/src/main/res/mipmap-hdpi/undo.png and /dev/null differ 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 c4c28d0a4..000000000 Binary files a/app/src/main/res/mipmap-mdpi/undo.png and /dev/null differ diff --git a/app/src/main/res/mipmap-xhdpi/undo.png b/app/src/main/res/mipmap-xhdpi/undo.png deleted file mode 100644 index 6b10718b9..000000000 Binary files a/app/src/main/res/mipmap-xhdpi/undo.png and /dev/null differ diff --git a/app/src/main/res/mipmap-xxhdpi/undo.png b/app/src/main/res/mipmap-xxhdpi/undo.png deleted file mode 100644 index a47587c36..000000000 Binary files a/app/src/main/res/mipmap-xxhdpi/undo.png and /dev/null differ 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 9959132c6..000000000 Binary files a/app/src/main/res/mipmap-xxxhdpi/undo.png and /dev/null differ