updating Commons, min Android version to 5 + adapter changes

This commit is contained in:
tibbi 2018-10-16 23:56:05 +02:00
parent f4f77ae013
commit 78bcf8adb8
20 changed files with 209 additions and 296 deletions

View file

@ -9,7 +9,7 @@ android {
defaultConfig { defaultConfig {
applicationId "com.simplemobiletools.gallery" applicationId "com.simplemobiletools.gallery"
minSdkVersion 16 minSdkVersion 21
targetSdkVersion 28 targetSdkVersion 28
versionCode 201 versionCode 201
versionName "4.6.5" versionName "4.6.5"
@ -43,7 +43,7 @@ android {
} }
dependencies { dependencies {
implementation 'com.simplemobiletools:commons:4.9.1' implementation 'com.simplemobiletools:commons:5.1.2'
implementation 'com.theartofdev.edmodo:android-image-cropper:2.7.0' implementation 'com.theartofdev.edmodo:android-image-cropper:2.7.0'
implementation 'androidx.multidex:multidex:2.0.0' implementation 'androidx.multidex:multidex:2.0.0'
implementation 'it.sephiroth.android.exif:library:1.0.1' implementation 'it.sephiroth.android.exif:library:1.0.1'
@ -65,7 +65,7 @@ dependencies {
implementation 'com.github.tibbi:subsampling-scale-image-view:v3.10.1-fork' implementation 'com.github.tibbi:subsampling-scale-image-view:v3.10.1-fork'
// implementation 'com.github.chrisbanes:PhotoView:2.1.4' // implementation 'com.github.chrisbanes:PhotoView:2.1.4'
implementation 'com.github.tibbi:PhotoView:2.1.4-fork' implementation 'com.github.tibbi:PhotoView:2.2.0-fork'
} }
Properties props = new Properties() Properties props = new Properties()

View file

@ -12,7 +12,6 @@ import android.view.MenuItem
import android.view.ViewGroup import android.view.ViewGroup
import android.widget.FrameLayout import android.widget.FrameLayout
import android.widget.Toast import android.widget.Toast
import androidx.recyclerview.widget.GridLayoutManager
import androidx.recyclerview.widget.RecyclerView import androidx.recyclerview.widget.RecyclerView
import com.simplemobiletools.commons.dialogs.CreateNewFolderDialog import com.simplemobiletools.commons.dialogs.CreateNewFolderDialog
import com.simplemobiletools.commons.dialogs.FilePickerDialog import com.simplemobiletools.commons.dialogs.FilePickerDialog
@ -966,7 +965,7 @@ class MainActivity : SimpleActivity(), DirectoryOperationsListener {
} }
private fun checkLastMediaChanged() { private fun checkLastMediaChanged() {
if (isActivityDestroyed()) { if (isDestroyed) {
return return
} }

View file

@ -398,7 +398,7 @@ class MediaActivity : SimpleActivity(), MediaOperationsListener {
} }
private fun checkLastMediaChanged() { private fun checkLastMediaChanged() {
if (isActivityDestroyed()) { if (isDestroyed) {
return return
} }

View file

@ -1,11 +1,9 @@
package com.simplemobiletools.gallery.activities package com.simplemobiletools.gallery.activities
import android.annotation.TargetApi
import android.content.res.Configuration import android.content.res.Configuration
import android.graphics.Bitmap import android.graphics.Bitmap
import android.graphics.BitmapFactory import android.graphics.BitmapFactory
import android.graphics.Color import android.graphics.Color
import android.os.Build
import android.os.Bundle import android.os.Bundle
import android.view.View import android.view.View
import android.view.Window import android.view.Window
@ -17,7 +15,6 @@ import com.simplemobiletools.commons.extensions.beVisible
import com.simplemobiletools.commons.extensions.showErrorToast import com.simplemobiletools.commons.extensions.showErrorToast
import com.simplemobiletools.commons.extensions.toast import com.simplemobiletools.commons.extensions.toast
import com.simplemobiletools.commons.helpers.PERMISSION_WRITE_STORAGE import com.simplemobiletools.commons.helpers.PERMISSION_WRITE_STORAGE
import com.simplemobiletools.commons.helpers.isLollipopPlus
import com.simplemobiletools.commons.helpers.isPiePlus import com.simplemobiletools.commons.helpers.isPiePlus
import com.simplemobiletools.gallery.R import com.simplemobiletools.gallery.R
import com.simplemobiletools.gallery.extensions.* import com.simplemobiletools.gallery.extensions.*
@ -65,7 +62,6 @@ open class PanoramaActivity : SimpleActivity() {
} }
} }
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
override fun onResume() { override fun onResume() {
super.onResume() super.onResume()
panorama_view.resumeRendering() panorama_view.resumeRendering()
@ -74,10 +70,8 @@ open class PanoramaActivity : SimpleActivity() {
updateStatusbarColor(Color.BLACK) updateStatusbarColor(Color.BLACK)
} }
if (isLollipopPlus()) {
window.statusBarColor = resources.getColor(R.color.circle_black_background) window.statusBarColor = resources.getColor(R.color.circle_black_background)
} }
}
override fun onPause() { override fun onPause() {
super.onPause() super.onPause()

View file

@ -10,7 +10,6 @@ import android.os.Bundle
import android.view.Menu import android.view.Menu
import android.view.MenuItem import android.view.MenuItem
import com.simplemobiletools.commons.dialogs.RadioGroupDialog import com.simplemobiletools.commons.dialogs.RadioGroupDialog
import com.simplemobiletools.commons.extensions.isActivityDestroyed
import com.simplemobiletools.commons.extensions.toast import com.simplemobiletools.commons.extensions.toast
import com.simplemobiletools.commons.helpers.isNougatPlus import com.simplemobiletools.commons.helpers.isNougatPlus
import com.simplemobiletools.commons.models.RadioItem import com.simplemobiletools.commons.models.RadioItem
@ -113,7 +112,7 @@ class SetWallpaperActivity : SimpleActivity(), CropImageView.OnCropImageComplete
@SuppressLint("NewApi") @SuppressLint("NewApi")
override fun onCropImageComplete(view: CropImageView?, result: CropImageView.CropResult) { override fun onCropImageComplete(view: CropImageView?, result: CropImageView.CropResult) {
if (isActivityDestroyed()) if (isDestroyed)
return return
if (result.error == null) { if (result.error == null) {

View file

@ -2,7 +2,6 @@ package com.simplemobiletools.gallery.activities
import android.animation.Animator import android.animation.Animator
import android.animation.ValueAnimator import android.animation.ValueAnimator
import android.annotation.SuppressLint
import android.annotation.TargetApi import android.annotation.TargetApi
import android.app.Activity import android.app.Activity
import android.content.Intent import android.content.Intent
@ -20,13 +19,13 @@ import android.os.Build
import android.os.Bundle import android.os.Bundle
import android.os.Handler import android.os.Handler
import android.provider.MediaStore import android.provider.MediaStore
import androidx.viewpager.widget.ViewPager
import android.util.DisplayMetrics import android.util.DisplayMetrics
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.view.WindowManager import android.view.WindowManager
import android.view.animation.DecelerateInterpolator import android.view.animation.DecelerateInterpolator
import androidx.viewpager.widget.ViewPager
import com.bumptech.glide.Glide import com.bumptech.glide.Glide
import com.simplemobiletools.commons.dialogs.PropertiesDialog import com.simplemobiletools.commons.dialogs.PropertiesDialog
import com.simplemobiletools.commons.dialogs.RenameItemDialog import com.simplemobiletools.commons.dialogs.RenameItemDialog
@ -103,7 +102,6 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View
initFavorites() initFavorites()
} }
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
override fun onResume() { override fun onResume() {
super.onResume() super.onResume()
if (!hasPermission(PERMISSION_WRITE_STORAGE)) { if (!hasPermission(PERMISSION_WRITE_STORAGE)) {
@ -112,9 +110,7 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View
} }
if (config.bottomActions) { if (config.bottomActions) {
if (isLollipopPlus()) {
window.navigationBarColor = Color.TRANSPARENT window.navigationBarColor = Color.TRANSPARENT
}
} else { } else {
setTranslucentNavigation() setTranslucentNavigation()
} }
@ -135,10 +131,8 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View
} }
supportActionBar?.setBackgroundDrawable(ColorDrawable(Color.TRANSPARENT)) supportActionBar?.setBackgroundDrawable(ColorDrawable(Color.TRANSPARENT))
if (isLollipopPlus()) {
window.statusBarColor = Color.TRANSPARENT window.statusBarColor = Color.TRANSPARENT
} }
}
override fun onPause() { override fun onPause() {
super.onPause() super.onPause()
@ -225,7 +219,7 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View
supportActionBar?.title = mPath.getFilenameFromPath() supportActionBar?.title = mPath.getFilenameFromPath()
view_pager.onGlobalLayout { view_pager.onGlobalLayout {
if (!isActivityDestroyed()) { if (!isDestroyed) {
if (mMediaFiles.isNotEmpty()) { if (mMediaFiles.isNotEmpty()) {
gotMedia(mMediaFiles as ArrayList<ThumbnailItem>) gotMedia(mMediaFiles as ArrayList<ThumbnailItem>)
} }
@ -365,7 +359,7 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View
private fun updatePagerItems(media: MutableList<Medium>) { private fun updatePagerItems(media: MutableList<Medium>) {
val pagerAdapter = MyPagerAdapter(this, supportFragmentManager, media) val pagerAdapter = MyPagerAdapter(this, supportFragmentManager, media)
if (!isActivityDestroyed()) { if (!isDestroyed) {
view_pager.apply { view_pager.apply {
adapter = pagerAdapter adapter = pagerAdapter
currentItem = mPos currentItem = mPos
@ -384,7 +378,7 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View
private fun startSlideshow() { private fun startSlideshow() {
if (getMediaForSlideshow()) { if (getMediaForSlideshow()) {
view_pager.onGlobalLayout { view_pager.onGlobalLayout {
if (!isActivityDestroyed()) { if (!isDestroyed) {
hideSystemUI(true) hideSystemUI(true)
mSlideshowInterval = config.slideshowInterval mSlideshowInterval = config.slideshowInterval
mSlideshowMoveBackwards = config.slideshowMoveBackwards mSlideshowMoveBackwards = config.slideshowMoveBackwards
@ -474,7 +468,7 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View
if (mIsSlideshowActive) { if (mIsSlideshowActive) {
if (getCurrentMedium()!!.isImage() || getCurrentMedium()!!.isGIF()) { if (getCurrentMedium()!!.isImage() || getCurrentMedium()!!.isGIF()) {
mSlideshowHandler.postDelayed({ mSlideshowHandler.postDelayed({
if (mIsSlideshowActive && !isActivityDestroyed()) { if (mIsSlideshowActive && !isDestroyed) {
swipeToNextMedium() swipeToNextMedium()
} }
}, mSlideshowInterval * 1000L) }, mSlideshowInterval * 1000L)
@ -980,18 +974,11 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View
initBottomActionsLayout() initBottomActionsLayout()
} }
@SuppressLint("NewApi")
private fun measureScreen() { private fun measureScreen() {
val metrics = DisplayMetrics() val metrics = DisplayMetrics()
if (isJellyBean1Plus()) {
windowManager.defaultDisplay.getRealMetrics(metrics) windowManager.defaultDisplay.getRealMetrics(metrics)
screenWidth = metrics.widthPixels screenWidth = metrics.widthPixels
screenHeight = metrics.heightPixels screenHeight = metrics.heightPixels
} else {
windowManager.defaultDisplay.getMetrics(metrics)
screenWidth = metrics.widthPixels
screenHeight = metrics.heightPixels
}
} }
private fun refreshViewPager() { private fun refreshViewPager() {

View file

@ -1,6 +1,5 @@
package com.simplemobiletools.gallery.adapters package com.simplemobiletools.gallery.adapters
import android.util.SparseArray
import android.view.Menu import android.view.Menu
import android.view.View import android.view.View
import android.view.ViewGroup import android.view.ViewGroup
@ -26,8 +25,6 @@ import com.simplemobiletools.gallery.models.AlbumCover
import com.simplemobiletools.gallery.models.Directory import com.simplemobiletools.gallery.models.Directory
import kotlinx.android.synthetic.main.directory_item_list.view.* import kotlinx.android.synthetic.main.directory_item_list.view.*
import java.io.File import java.io.File
import java.util.*
import kotlin.collections.ArrayList
class DirectoryAdapter(activity: BaseSimpleActivity, var dirs: ArrayList<Directory>, val listener: DirectoryOperationsListener?, recyclerView: MyRecyclerView, class DirectoryAdapter(activity: BaseSimpleActivity, var dirs: ArrayList<Directory>, val listener: DirectoryOperationsListener?, recyclerView: MyRecyclerView,
val isPickIntent: Boolean, fastScroller: FastScroller? = null, itemClick: (Any) -> Unit) : val isPickIntent: Boolean, fastScroller: FastScroller? = null, itemClick: (Any) -> Unit) :
@ -48,14 +45,6 @@ class DirectoryAdapter(activity: BaseSimpleActivity, var dirs: ArrayList<Directo
override fun getActionMenuId() = R.menu.cab_directories override fun getActionMenuId() = R.menu.cab_directories
override fun prepareItemSelection(viewHolder: ViewHolder) {
viewHolder.itemView.dir_check?.background?.applyColorFilter(primaryColor)
}
override fun markViewHolderSelection(select: Boolean, viewHolder: ViewHolder?) {
viewHolder?.itemView?.dir_check?.beVisibleIf(select)
}
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder { override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
val layoutType = if (isListViewType) R.layout.directory_item_list else R.layout.directory_item_grid val layoutType = if (isListViewType) R.layout.directory_item_list else R.layout.directory_item_grid
return createViewHolder(layoutType, parent) return createViewHolder(layoutType, parent)
@ -63,10 +52,10 @@ class DirectoryAdapter(activity: BaseSimpleActivity, var dirs: ArrayList<Directo
override fun onBindViewHolder(holder: MyRecyclerViewAdapter.ViewHolder, position: Int) { override fun onBindViewHolder(holder: MyRecyclerViewAdapter.ViewHolder, position: Int) {
val dir = dirs.getOrNull(position) ?: return val dir = dirs.getOrNull(position) ?: return
val view = holder.bindView(dir, true, !isPickIntent) { itemView, adapterPosition -> holder.bindView(dir, true, !isPickIntent) { itemView, adapterPosition ->
setupView(itemView, dir) setupView(itemView, dir)
} }
bindViewHolder(holder, position, view) bindViewHolder(holder)
} }
override fun getItemCount() = dirs.size override fun getItemCount() = dirs.size
@ -90,7 +79,7 @@ class DirectoryAdapter(activity: BaseSimpleActivity, var dirs: ArrayList<Directo
} }
override fun actionItemPressed(id: Int) { override fun actionItemPressed(id: Int) {
if (selectedPositions.isEmpty()) { if (selectedKeys.isEmpty()) {
return return
} }
@ -117,17 +106,21 @@ class DirectoryAdapter(activity: BaseSimpleActivity, var dirs: ArrayList<Directo
override fun getIsItemSelectable(position: Int) = true override fun getIsItemSelectable(position: Int) = true
override fun getItemSelectionKey(position: Int) = dirs.getOrNull(position)?.path?.hashCode()
override fun getItemKeyPosition(key: Int) = dirs.indexOfFirst { it.path.hashCode() == key }
override fun onViewRecycled(holder: ViewHolder) { override fun onViewRecycled(holder: ViewHolder) {
super.onViewRecycled(holder) super.onViewRecycled(holder)
if (!activity.isActivityDestroyed()) { if (!activity.isDestroyed) {
Glide.with(activity).clear(holder.itemView?.dir_thumbnail!!) Glide.with(activity).clear(holder.itemView.dir_thumbnail!!)
} }
} }
private fun checkHideBtnVisibility(menu: Menu) { private fun checkHideBtnVisibility(menu: Menu) {
var hiddenCnt = 0 var hiddenCnt = 0
var unhiddenCnt = 0 var unhiddenCnt = 0
selectedPositions.mapNotNull { dirs.getOrNull(it)?.path }.forEach { getSelectedPaths().forEach {
if (File(it).doesThisOrParentHaveNoMedia()) { if (File(it).doesThisOrParentHaveNoMedia()) {
hiddenCnt++ hiddenCnt++
} else { } else {
@ -143,7 +136,7 @@ class DirectoryAdapter(activity: BaseSimpleActivity, var dirs: ArrayList<Directo
val pinnedFolders = config.pinnedFolders val pinnedFolders = config.pinnedFolders
var pinnedCnt = 0 var pinnedCnt = 0
var unpinnedCnt = 0 var unpinnedCnt = 0
selectedPositions.mapNotNull { dirs.getOrNull(it)?.path }.forEach { getSelectedPaths().forEach {
if (pinnedFolders.contains(it)) { if (pinnedFolders.contains(it)) {
pinnedCnt++ pinnedCnt++
} else { } else {
@ -156,10 +149,10 @@ class DirectoryAdapter(activity: BaseSimpleActivity, var dirs: ArrayList<Directo
} }
private fun showProperties() { private fun showProperties() {
if (selectedPositions.size <= 1) { if (selectedKeys.size <= 1) {
val path = dirs[selectedPositions.first()].path val path = getFirstSelectedItemPath() ?: return
if (path != FAVORITES && path != RECYCLE_BIN) { if (path != FAVORITES && path != RECYCLE_BIN) {
PropertiesDialog(activity, dirs[selectedPositions.first()].path, config.shouldShowHidden) PropertiesDialog(activity, path, config.shouldShowHidden)
} }
} else { } else {
PropertiesDialog(activity, getSelectedPaths().filter { it != FAVORITES && it != RECYCLE_BIN }.toMutableList(), config.shouldShowHidden) PropertiesDialog(activity, getSelectedPaths().filter { it != FAVORITES && it != RECYCLE_BIN }.toMutableList(), config.shouldShowHidden)
@ -167,7 +160,7 @@ class DirectoryAdapter(activity: BaseSimpleActivity, var dirs: ArrayList<Directo
} }
private fun renameDir() { private fun renameDir() {
val firstDir = dirs[selectedPositions.first()] val firstDir = getFirstSelectedItem() ?: return
val sourcePath = firstDir.path val sourcePath = firstDir.path
val dir = File(sourcePath) val dir = File(sourcePath)
if (activity.isAStorageRootFolder(dir.absolutePath)) { if (activity.isAStorageRootFolder(dir.absolutePath)) {
@ -283,18 +276,6 @@ class DirectoryAdapter(activity: BaseSimpleActivity, var dirs: ArrayList<Directo
notifyItemRemoved(it) notifyItemRemoved(it)
} }
val newViewHolders = SparseArray<ViewHolder>()
val cnt = viewHolders.size()
for (i in 0..cnt) {
if (affectedPositions.contains(i)) {
continue
}
val view = viewHolders.get(i, null)
val newIndex = i - selectedPositions.count { it <= i }
newViewHolders.put(newIndex, view)
}
viewHolders = newViewHolders
currentDirectoriesHash = newDirs.hashCode() currentDirectoriesHash = newDirs.hashCode()
dirs = newDirs dirs = newDirs
@ -330,9 +311,9 @@ class DirectoryAdapter(activity: BaseSimpleActivity, var dirs: ArrayList<Directo
private fun pinFolders(pin: Boolean) { private fun pinFolders(pin: Boolean) {
if (pin) { if (pin) {
config.addPinnedFolders(getSelectedPaths()) config.addPinnedFolders(getSelectedPaths().toHashSet())
} else { } else {
config.removePinnedFolders(getSelectedPaths()) config.removePinnedFolders(getSelectedPaths().toHashSet())
} }
pinnedFolders = config.pinnedFolders pinnedFolders = config.pinnedFolders
@ -344,12 +325,11 @@ class DirectoryAdapter(activity: BaseSimpleActivity, var dirs: ArrayList<Directo
private fun copyMoveTo(isCopyOperation: Boolean) { private fun copyMoveTo(isCopyOperation: Boolean) {
val paths = ArrayList<String>() val paths = ArrayList<String>()
val showHidden = activity.config.shouldShowHidden val showHidden = activity.config.shouldShowHidden
selectedPositions.forEach { getSelectedPaths().forEach {
val path = dirs[it].path if (it.startsWith(OTG_PATH)) {
if (path.startsWith(OTG_PATH)) { paths.addAll(getOTGFilePaths(it, showHidden))
paths.addAll(getOTGFilePaths(path, showHidden)) } else if (it != FAVORITES) {
} else if (path != FAVORITES) { File(it).listFiles()?.filter {
File(path).listFiles()?.filter {
!activity.getIsPathDirectory(it.absolutePath) && it.isMediaFile() && (showHidden || !it.name.startsWith('.')) !activity.getIsPathDirectory(it.absolutePath) && it.isMediaFile() && (showHidden || !it.name.startsWith('.'))
}?.mapTo(paths) { it.absolutePath } }?.mapTo(paths) { it.absolutePath }
} }
@ -378,9 +358,9 @@ class DirectoryAdapter(activity: BaseSimpleActivity, var dirs: ArrayList<Directo
if (config.skipDeleteConfirmation) { if (config.skipDeleteConfirmation) {
deleteFolders() deleteFolders()
} else { } else {
val itemsCnt = selectedPositions.size val itemsCnt = selectedKeys.size
val items = resources.getQuantityString(R.plurals.delete_items, itemsCnt, itemsCnt) val items = resources.getQuantityString(R.plurals.delete_items, itemsCnt, itemsCnt)
val fileDirItem = dirs.getOrNull(selectedPositions.first()) ?: return val fileDirItem = getFirstSelectedItem() ?: return
val baseString = if (!config.useRecycleBin || (isOneItemSelected() && fileDirItem.isRecycleBin()) || (isOneItemSelected() && fileDirItem.areFavorites())) { val baseString = if (!config.useRecycleBin || (isOneItemSelected() && fileDirItem.isRecycleBin()) || (isOneItemSelected() && fileDirItem.areFavorites())) {
R.string.deletion_confirmation R.string.deletion_confirmation
} else { } else {
@ -397,29 +377,24 @@ class DirectoryAdapter(activity: BaseSimpleActivity, var dirs: ArrayList<Directo
} }
private fun deleteFolders() { private fun deleteFolders() {
if (selectedPositions.isEmpty()) { if (selectedKeys.isEmpty()) {
return return
} }
val folders = ArrayList<File>(selectedPositions.size)
val removeFolders = ArrayList<Directory>(selectedPositions.size)
var SAFPath = "" var SAFPath = ""
selectedPositions.forEach { val selectedDirs = getSelectedItems()
if (dirs.size > it) { selectedDirs.forEach {
val path = dirs[it].path val path = it.path
if (activity.needsStupidWritePermissions(path) && config.treeUri.isEmpty()) { if (activity.needsStupidWritePermissions(path) && config.treeUri.isEmpty()) {
SAFPath = path SAFPath = path
} }
} }
}
activity.handleSAFDialog(SAFPath) { activity.handleSAFDialog(SAFPath) {
selectedPositions.sortedDescending().forEach { val foldersToDelete = ArrayList<File>(selectedKeys.size)
val directory = dirs.getOrNull(it) selectedDirs.forEach {
if (directory != null) { if (it.areFavorites() || it.isRecycleBin()) {
if (directory.areFavorites() || directory.isRecycleBin()) { if (it.isRecycleBin()) {
if (directory.isRecycleBin()) {
tryEmptyRecycleBin(false) tryEmptyRecycleBin(false)
} else { } else {
Thread { Thread {
@ -428,28 +403,23 @@ class DirectoryAdapter(activity: BaseSimpleActivity, var dirs: ArrayList<Directo
}.start() }.start()
} }
if (selectedPositions.size == 1) { if (selectedKeys.size == 1) {
finishActMode() finishActMode()
} else {
selectedPositions.remove(it)
toggleItemSelection(false, it)
} }
} else { } else {
folders.add(File(directory.path)) foldersToDelete.add(File(it.path))
removeFolders.add(directory)
}
} }
} }
listener?.deleteFolders(folders) listener?.deleteFolders(foldersToDelete)
} }
} }
private fun changeAlbumCover(useDefault: Boolean) { private fun changeAlbumCover(useDefault: Boolean) {
if (selectedPositions.size != 1) if (selectedKeys.size != 1)
return return
val path = dirs[selectedPositions.first()].path val path = getFirstSelectedItemPath() ?: return
if (useDefault) { if (useDefault) {
val albumCovers = getAlbumCoversWithout(path) val albumCovers = getAlbumCoversWithout(path)
@ -480,15 +450,15 @@ class DirectoryAdapter(activity: BaseSimpleActivity, var dirs: ArrayList<Directo
listener?.refreshItems() listener?.refreshItems()
} }
private fun getSelectedPaths(): HashSet<String> { private fun getSelectedItems() = dirs.filter { selectedKeys.contains(it.path.hashCode()) } as ArrayList<Directory>
val paths = HashSet<String>(selectedPositions.size)
selectedPositions.forEach { private fun getSelectedPaths() = getSelectedItems().map { it.path } as ArrayList<String>
(dirs.getOrNull(it))?.apply {
paths.add(path) private fun getFirstSelectedItem() = getItemWithKey(selectedKeys.first())
}
} private fun getFirstSelectedItemPath() = getFirstSelectedItem()?.path
return paths
} private fun getItemWithKey(key: Int): Directory? = dirs.firstOrNull { it.path.hashCode() == key }
fun updateDirs(newDirs: ArrayList<Directory>) { fun updateDirs(newDirs: ArrayList<Directory>) {
val directories = newDirs.clone() as ArrayList<Directory> val directories = newDirs.clone() as ArrayList<Directory>
@ -516,6 +486,7 @@ class DirectoryAdapter(activity: BaseSimpleActivity, var dirs: ArrayList<Directo
} }
private fun setupView(view: View, directory: Directory) { private fun setupView(view: View, directory: Directory) {
val isSelected = selectedKeys.contains(directory.path.hashCode())
view.apply { view.apply {
dir_name.text = directory.name dir_name.text = directory.name
dir_path?.text = "${directory.path.substringBeforeLast("/")}/" dir_path?.text = "${directory.path.substringBeforeLast("/")}/"
@ -528,6 +499,11 @@ class DirectoryAdapter(activity: BaseSimpleActivity, var dirs: ArrayList<Directo
else -> TYPE_IMAGES else -> TYPE_IMAGES
} }
dir_check?.beVisibleIf(isSelected)
if (isSelected) {
dir_check.background?.applyColorFilter(primaryColor)
}
activity.loadImage(thumbnailType, directory.tmb, dir_thumbnail, scrollHorizontally, animateGifs, cropThumbnails) activity.loadImage(thumbnailType, directory.tmb, dir_thumbnail, scrollHorizontally, animateGifs, cropThumbnails)
dir_pin.beVisibleIf(pinnedFolders.contains(directory.path)) dir_pin.beVisibleIf(pinnedFolders.contains(directory.path))
dir_location.beVisibleIf(directory.location != LOCAITON_INTERNAL) dir_location.beVisibleIf(directory.location != LOCAITON_INTERNAL)

View file

@ -1,37 +1,34 @@
package com.simplemobiletools.gallery.adapters package com.simplemobiletools.gallery.adapters
import android.content.Context import android.content.Context
import android.graphics.drawable.Drawable
import android.view.LayoutInflater import android.view.LayoutInflater
import android.view.View import android.view.View
import android.view.ViewGroup import android.view.ViewGroup
import androidx.recyclerview.widget.RecyclerView import androidx.recyclerview.widget.RecyclerView
import com.simplemobiletools.gallery.R import com.simplemobiletools.gallery.R
import com.simplemobiletools.gallery.interfaces.FilterAdapterListener
import com.simplemobiletools.gallery.models.FilterItem import com.simplemobiletools.gallery.models.FilterItem
import kotlinx.android.synthetic.main.editor_filter_item.view.* import kotlinx.android.synthetic.main.editor_filter_item.view.*
import java.util.* import java.util.*
class FiltersAdapter(val context: Context, val filterItems: ArrayList<FilterItem>, val itemClick: (Int) -> Unit) : RecyclerView.Adapter<FiltersAdapter.ViewHolder>(), class FiltersAdapter(val context: Context, val filterItems: ArrayList<FilterItem>, val itemClick: (Int) -> Unit) : RecyclerView.Adapter<FiltersAdapter.ViewHolder>() {
FilterAdapterListener {
private var currentSelection = filterItems.first() private var currentSelection = filterItems.first()
private var strokeBackground = context.resources.getDrawable(R.drawable.stroke_background) private var strokeBackground = context.resources.getDrawable(R.drawable.stroke_background)
override fun onBindViewHolder(holder: ViewHolder, position: Int) { override fun onBindViewHolder(holder: ViewHolder, position: Int) {
holder.bindView(filterItems[position], strokeBackground) holder.bindView(filterItems[position])
} }
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder { override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
val view = LayoutInflater.from(parent.context).inflate(R.layout.editor_filter_item, parent, false) val view = LayoutInflater.from(parent.context).inflate(R.layout.editor_filter_item, parent, false)
return ViewHolder(view, this) return ViewHolder(view)
} }
override fun getItemCount() = filterItems.size override fun getItemCount() = filterItems.size
override fun getCurrentFilter() = currentSelection fun getCurrentFilter() = currentSelection
override fun setCurrentFilter(position: Int) { private fun setCurrentFilter(position: Int) {
val filterItem = filterItems.getOrNull(position) ?: return val filterItem = filterItems.getOrNull(position) ?: return
if (currentSelection != filterItem) { if (currentSelection != filterItem) {
currentSelection = filterItem currentSelection = filterItem
@ -40,19 +37,19 @@ class FiltersAdapter(val context: Context, val filterItems: ArrayList<FilterItem
} }
} }
class ViewHolder(view: View, val filterAdapterListener: FilterAdapterListener) : RecyclerView.ViewHolder(view) { inner class ViewHolder(view: View) : RecyclerView.ViewHolder(view) {
fun bindView(filterItem: FilterItem, strokeBackground: Drawable): View { fun bindView(filterItem: FilterItem): View {
itemView.apply { itemView.apply {
editor_filter_item_label.text = filterItem.filter.name editor_filter_item_label.text = filterItem.filter.name
editor_filter_item_thumbnail.setImageBitmap(filterItem.bitmap) editor_filter_item_thumbnail.setImageBitmap(filterItem.bitmap)
editor_filter_item_thumbnail.background = if (filterAdapterListener.getCurrentFilter() == filterItem) { editor_filter_item_thumbnail.background = if (getCurrentFilter() == filterItem) {
strokeBackground strokeBackground
} else { } else {
null null
} }
setOnClickListener { setOnClickListener {
filterAdapterListener.setCurrentFilter(adapterPosition) setCurrentFilter(adapterPosition)
} }
} }
return itemView return itemView

View file

@ -25,12 +25,6 @@ class ManageFoldersAdapter(activity: BaseSimpleActivity, var folders: ArrayList<
override fun prepareActionMode(menu: Menu) {} override fun prepareActionMode(menu: Menu) {}
override fun prepareItemSelection(viewHolder: ViewHolder) {}
override fun markViewHolderSelection(select: Boolean, viewHolder: ViewHolder?) {
viewHolder?.itemView?.manage_folder_holder?.isSelected = select
}
override fun actionItemPressed(id: Int) { override fun actionItemPressed(id: Int) {
when (id) { when (id) {
R.id.cab_remove -> removeSelection() R.id.cab_remove -> removeSelection()
@ -41,20 +35,27 @@ class ManageFoldersAdapter(activity: BaseSimpleActivity, var folders: ArrayList<
override fun getIsItemSelectable(position: Int) = true override fun getIsItemSelectable(position: Int) = true
override fun getItemSelectionKey(position: Int) = folders.getOrNull(position)?.hashCode()
override fun getItemKeyPosition(key: Int) = folders.indexOfFirst { it.hashCode() == key }
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int) = createViewHolder(R.layout.item_manage_folder, parent) override fun onCreateViewHolder(parent: ViewGroup, viewType: Int) = createViewHolder(R.layout.item_manage_folder, parent)
override fun onBindViewHolder(holder: ViewHolder, position: Int) { override fun onBindViewHolder(holder: ViewHolder, position: Int) {
val folder = folders[position] val folder = folders[position]
val view = holder.bindView(folder, true, true) { itemView, adapterPosition -> holder.bindView(folder, true, true) { itemView, adapterPosition ->
setupView(itemView, folder) setupView(itemView, folder)
} }
bindViewHolder(holder, position, view) bindViewHolder(holder)
} }
override fun getItemCount() = folders.size override fun getItemCount() = folders.size
private fun getSelectedItems() = folders.filter { selectedKeys.contains(it.hashCode()) } as ArrayList<String>
private fun setupView(view: View, folder: String) { private fun setupView(view: View, folder: String) {
view.apply { view.apply {
manage_folder_holder?.isSelected = selectedKeys.contains(folder.hashCode())
manage_folder_title.apply { manage_folder_title.apply {
text = folder text = folder
setTextColor(config.textColor) setTextColor(config.textColor)
@ -63,20 +64,20 @@ class ManageFoldersAdapter(activity: BaseSimpleActivity, var folders: ArrayList<
} }
private fun removeSelection() { private fun removeSelection() {
val removeFolders = ArrayList<String>(selectedPositions.size) val removeFolders = ArrayList<String>(selectedKeys.size)
val positions = getSelectedItemPositions()
selectedPositions.sortedDescending().forEach { getSelectedItems().forEach {
val folder = folders[it] removeFolders.add(it)
removeFolders.add(folder)
if (isShowingExcludedFolders) { if (isShowingExcludedFolders) {
config.removeExcludedFolder(folder) config.removeExcludedFolder(it)
} else { } else {
config.removeIncludedFolder(folder) config.removeIncludedFolder(it)
} }
} }
folders.removeAll(removeFolders) folders.removeAll(removeFolders)
removeSelectedItems() removeSelectedItems(positions)
if (folders.isEmpty()) { if (folders.isEmpty()) {
listener?.refreshItems() listener?.refreshItems()
} }

View file

@ -27,12 +27,6 @@ class ManageHiddenFoldersAdapter(activity: BaseSimpleActivity, var folders: Arra
override fun prepareActionMode(menu: Menu) {} override fun prepareActionMode(menu: Menu) {}
override fun prepareItemSelection(viewHolder: ViewHolder) {}
override fun markViewHolderSelection(select: Boolean, viewHolder: ViewHolder?) {
viewHolder?.itemView?.manage_folder_holder?.isSelected = select
}
override fun actionItemPressed(id: Int) { override fun actionItemPressed(id: Int) {
when (id) { when (id) {
R.id.cab_unhide -> tryUnhideFolders() R.id.cab_unhide -> tryUnhideFolders()
@ -43,20 +37,27 @@ class ManageHiddenFoldersAdapter(activity: BaseSimpleActivity, var folders: Arra
override fun getIsItemSelectable(position: Int) = true override fun getIsItemSelectable(position: Int) = true
override fun getItemSelectionKey(position: Int) = folders.getOrNull(position)?.hashCode()
override fun getItemKeyPosition(key: Int) = folders.indexOfFirst { it.hashCode() == key }
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int) = createViewHolder(R.layout.item_manage_folder, parent) override fun onCreateViewHolder(parent: ViewGroup, viewType: Int) = createViewHolder(R.layout.item_manage_folder, parent)
override fun onBindViewHolder(holder: ViewHolder, position: Int) { override fun onBindViewHolder(holder: ViewHolder, position: Int) {
val folder = folders[position] val folder = folders[position]
val view = holder.bindView(folder, true, true) { itemView, adapterPosition -> holder.bindView(folder, true, true) { itemView, adapterPosition ->
setupView(itemView, folder) setupView(itemView, folder)
} }
bindViewHolder(holder, position, view) bindViewHolder(holder)
} }
override fun getItemCount() = folders.size override fun getItemCount() = folders.size
private fun getSelectedItems() = folders.filter { selectedKeys.contains(it.hashCode()) } as ArrayList<String>
private fun setupView(view: View, folder: String) { private fun setupView(view: View, folder: String) {
view.apply { view.apply {
manage_folder_holder?.isSelected = selectedKeys.contains(folder.hashCode())
manage_folder_title.apply { manage_folder_title.apply {
text = folder text = folder
setTextColor(config.textColor) setTextColor(config.textColor)
@ -65,12 +66,12 @@ class ManageHiddenFoldersAdapter(activity: BaseSimpleActivity, var folders: Arra
} }
private fun tryUnhideFolders() { private fun tryUnhideFolders() {
val removeFolders = ArrayList<String>(selectedPositions.size) val removeFolders = ArrayList<String>(selectedKeys.size)
val sdCardPaths = ArrayList<String>() val sdCardPaths = ArrayList<String>()
selectedPositions.forEach { getSelectedItems().forEach {
if (activity.isPathOnSD(folders[it])) { if (activity.isPathOnSD(it)) {
sdCardPaths.add(folders[it]) sdCardPaths.add(it)
} }
} }
@ -84,14 +85,14 @@ class ManageHiddenFoldersAdapter(activity: BaseSimpleActivity, var folders: Arra
} }
private fun unhideFolders(removeFolders: ArrayList<String>) { private fun unhideFolders(removeFolders: ArrayList<String>) {
selectedPositions.sortedDescending().forEach { val position = getSelectedItemPositions()
val folder = folders[it] getSelectedItems().forEach {
removeFolders.add(folder) removeFolders.add(it)
activity.removeNoMedia(folder) activity.removeNoMedia(it)
} }
folders.removeAll(removeFolders) folders.removeAll(removeFolders)
removeSelectedItems() removeSelectedItems(position)
if (folders.isEmpty()) { if (folders.isEmpty()) {
listener?.refreshItems() listener?.refreshItems()
} }

View file

@ -61,14 +61,6 @@ class MediaAdapter(activity: BaseSimpleActivity, var media: MutableList<Thumbnai
override fun getActionMenuId() = R.menu.cab_media override fun getActionMenuId() = R.menu.cab_media
override fun prepareItemSelection(viewHolder: ViewHolder) {
viewHolder.itemView?.medium_check?.background?.applyColorFilter(primaryColor)
}
override fun markViewHolderSelection(select: Boolean, viewHolder: ViewHolder?) {
viewHolder?.itemView?.medium_check?.beVisibleIf(select)
}
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder { override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
val layoutType = if (viewType == ITEM_SECTION) { val layoutType = if (viewType == ITEM_SECTION) {
R.layout.thumbnail_section R.layout.thumbnail_section
@ -89,14 +81,14 @@ class MediaAdapter(activity: BaseSimpleActivity, var media: MutableList<Thumbnai
} }
val allowLongPress = !allowMultiplePicks && tmbItem is Medium val allowLongPress = !allowMultiplePicks && tmbItem is Medium
val view = holder.bindView(tmbItem, tmbItem is Medium, allowLongPress) { itemView, adapterPosition -> holder.bindView(tmbItem, tmbItem is Medium, allowLongPress) { itemView, adapterPosition ->
if (tmbItem is Medium) { if (tmbItem is Medium) {
setupThumbnail(itemView, tmbItem) setupThumbnail(itemView, tmbItem)
} else { } else {
setupSection(itemView, tmbItem as ThumbnailSection) setupSection(itemView, tmbItem as ThumbnailSection)
} }
} }
bindViewHolder(holder, position, view) bindViewHolder(holder)
} }
override fun getItemCount() = media.size override fun getItemCount() = media.size
@ -112,9 +104,9 @@ class MediaAdapter(activity: BaseSimpleActivity, var media: MutableList<Thumbnai
override fun prepareActionMode(menu: Menu) { override fun prepareActionMode(menu: Menu) {
menu.apply { menu.apply {
findItem(R.id.cab_rename).isVisible = isOneItemSelected() && getSelectedMedia().firstOrNull()?.getIsInRecycleBin() == false findItem(R.id.cab_rename).isVisible = isOneItemSelected() && getSelectedItems().firstOrNull()?.getIsInRecycleBin() == false
findItem(R.id.cab_open_with).isVisible = isOneItemSelected() findItem(R.id.cab_open_with).isVisible = isOneItemSelected()
findItem(R.id.cab_confirm_selection).isVisible = isAGetIntent && allowMultiplePicks && selectedPositions.size > 0 findItem(R.id.cab_confirm_selection).isVisible = isAGetIntent && allowMultiplePicks && selectedKeys.size > 0
findItem(R.id.cab_restore_recycle_bin_files).isVisible = getSelectedPaths().all { it.startsWith(activity.filesDir.absolutePath) } findItem(R.id.cab_restore_recycle_bin_files).isVisible = getSelectedPaths().all { it.startsWith(activity.filesDir.absolutePath) }
checkHideBtnVisibility(this) checkHideBtnVisibility(this)
@ -123,7 +115,7 @@ class MediaAdapter(activity: BaseSimpleActivity, var media: MutableList<Thumbnai
} }
override fun actionItemPressed(id: Int) { override fun actionItemPressed(id: Int) {
if (selectedPositions.isEmpty()) { if (selectedKeys.isEmpty()) {
return return
} }
@ -141,9 +133,9 @@ class MediaAdapter(activity: BaseSimpleActivity, var media: MutableList<Thumbnai
R.id.cab_copy_to -> copyMoveTo(true) R.id.cab_copy_to -> copyMoveTo(true)
R.id.cab_move_to -> copyMoveTo(false) R.id.cab_move_to -> copyMoveTo(false)
R.id.cab_select_all -> selectAll() R.id.cab_select_all -> selectAll()
R.id.cab_open_with -> activity.openPath(getCurrentPath(), true) R.id.cab_open_with -> openPath()
R.id.cab_fix_date_taken -> fixDateTaken() R.id.cab_fix_date_taken -> fixDateTaken()
R.id.cab_set_as -> activity.setAs(getCurrentPath()) R.id.cab_set_as -> setAs()
R.id.cab_delete -> checkDeleteConfirmation() R.id.cab_delete -> checkDeleteConfirmation()
} }
} }
@ -152,9 +144,13 @@ class MediaAdapter(activity: BaseSimpleActivity, var media: MutableList<Thumbnai
override fun getIsItemSelectable(position: Int) = !isASectionTitle(position) override fun getIsItemSelectable(position: Int) = !isASectionTitle(position)
override fun getItemSelectionKey(position: Int) = (media.getOrNull(position) as? Medium)?.path?.hashCode()
override fun getItemKeyPosition(key: Int) = media.indexOfFirst { (it as? Medium)?.path?.hashCode() == key }
override fun onViewRecycled(holder: ViewHolder) { override fun onViewRecycled(holder: ViewHolder) {
super.onViewRecycled(holder) super.onViewRecycled(holder)
if (!activity.isActivityDestroyed()) { if (!activity.isDestroyed) {
val itemView = holder.itemView val itemView = holder.itemView
visibleItemPaths.remove(itemView?.photo_name?.tag) visibleItemPaths.remove(itemView?.photo_name?.tag)
val tmb = itemView?.medium_thumbnail val tmb = itemView?.medium_thumbnail
@ -169,7 +165,7 @@ class MediaAdapter(activity: BaseSimpleActivity, var media: MutableList<Thumbnai
private fun checkHideBtnVisibility(menu: Menu) { private fun checkHideBtnVisibility(menu: Menu) {
var hiddenCnt = 0 var hiddenCnt = 0
var unhiddenCnt = 0 var unhiddenCnt = 0
getSelectedMedia().forEach { getSelectedItems().forEach {
if (it.isHidden()) { if (it.isHidden()) {
hiddenCnt++ hiddenCnt++
} else { } else {
@ -177,7 +173,7 @@ class MediaAdapter(activity: BaseSimpleActivity, var media: MutableList<Thumbnai
} }
} }
val isInRecycleBin = getSelectedMedia().firstOrNull()?.getIsInRecycleBin() == true val isInRecycleBin = getSelectedItems().firstOrNull()?.getIsInRecycleBin() == true
menu.findItem(R.id.cab_hide).isVisible = unhiddenCnt > 0 && !isInRecycleBin menu.findItem(R.id.cab_hide).isVisible = unhiddenCnt > 0 && !isInRecycleBin
menu.findItem(R.id.cab_unhide).isVisible = hiddenCnt > 0 && !isInRecycleBin menu.findItem(R.id.cab_unhide).isVisible = hiddenCnt > 0 && !isInRecycleBin
} }
@ -185,7 +181,7 @@ class MediaAdapter(activity: BaseSimpleActivity, var media: MutableList<Thumbnai
private fun checkFavoriteBtnVisibility(menu: Menu) { private fun checkFavoriteBtnVisibility(menu: Menu) {
var favoriteCnt = 0 var favoriteCnt = 0
var nonFavoriteCnt = 0 var nonFavoriteCnt = 0
getSelectedMedia().forEach { getSelectedItems().forEach {
if (it.isFavorite) { if (it.isFavorite) {
favoriteCnt++ favoriteCnt++
} else { } else {
@ -202,8 +198,9 @@ class MediaAdapter(activity: BaseSimpleActivity, var media: MutableList<Thumbnai
} }
private fun showProperties() { private fun showProperties() {
if (selectedPositions.size <= 1) { if (selectedKeys.size <= 1) {
PropertiesDialog(activity, (media[selectedPositions.first()] as Medium).path, config.shouldShowHidden) val path = getFirstSelectedItemPath() ?: return
PropertiesDialog(activity, path, config.shouldShowHidden)
} else { } else {
val paths = getSelectedPaths() val paths = getSelectedPaths()
PropertiesDialog(activity, paths, config.shouldShowHidden) PropertiesDialog(activity, paths, config.shouldShowHidden)
@ -211,7 +208,7 @@ class MediaAdapter(activity: BaseSimpleActivity, var media: MutableList<Thumbnai
} }
private fun renameFile() { private fun renameFile() {
val oldPath = getCurrentPath() val oldPath = getFirstSelectedItemPath() ?: return
RenameItemDialog(activity, oldPath) { RenameItemDialog(activity, oldPath) {
Thread { Thread {
activity.updateDBMediaPath(oldPath, it) activity.updateDBMediaPath(oldPath, it)
@ -226,12 +223,23 @@ class MediaAdapter(activity: BaseSimpleActivity, var media: MutableList<Thumbnai
} }
private fun editFile() { private fun editFile() {
activity.openEditor(getCurrentPath()) val path = getFirstSelectedItemPath() ?: return
activity.openEditor(path)
}
private fun openPath() {
val path = getFirstSelectedItemPath() ?: return
activity.openPath(path, true)
}
private fun setAs() {
val path = getFirstSelectedItemPath() ?: return
activity.setAs(path)
} }
private fun toggleFileVisibility(hide: Boolean) { private fun toggleFileVisibility(hide: Boolean) {
Thread { Thread {
getSelectedMedia().forEach { getSelectedItems().forEach {
activity.toggleFileVisibility(it.path, hide) activity.toggleFileVisibility(it.path, hide)
} }
activity.runOnUiThread { activity.runOnUiThread {
@ -244,7 +252,7 @@ class MediaAdapter(activity: BaseSimpleActivity, var media: MutableList<Thumbnai
private fun toggleFavorites(add: Boolean) { private fun toggleFavorites(add: Boolean) {
Thread { Thread {
val mediumDao = activity.galleryDB.MediumDao() val mediumDao = activity.galleryDB.MediumDao()
getSelectedMedia().forEach { getSelectedItems().forEach {
it.isFavorite = add it.isFavorite = add
mediumDao.updateFavorite(it.path, add) mediumDao.updateFavorite(it.path, add)
} }
@ -263,9 +271,9 @@ class MediaAdapter(activity: BaseSimpleActivity, var media: MutableList<Thumbnai
} }
private fun shareMedia() { private fun shareMedia() {
if (selectedPositions.size == 1 && selectedPositions.first() != -1) { if (selectedKeys.size == 1 && selectedKeys.first() != -1) {
activity.shareMediumPath(getSelectedMedia().first().path) activity.shareMediumPath(getSelectedItems().first().path)
} else if (selectedPositions.size > 1) { } else if (selectedKeys.size > 1) {
activity.shareMediaPaths(getSelectedPaths()) activity.shareMediaPaths(getSelectedPaths())
} }
} }
@ -345,7 +353,7 @@ class MediaAdapter(activity: BaseSimpleActivity, var media: MutableList<Thumbnai
} }
private fun askConfirmDelete() { private fun askConfirmDelete() {
val items = resources.getQuantityString(R.plurals.delete_items, selectedPositions.size, selectedPositions.size) val items = resources.getQuantityString(R.plurals.delete_items, selectedKeys.size, selectedKeys.size)
val isRecycleBin = getSelectedPaths().first().startsWith(activity.filesDir.absolutePath) val isRecycleBin = getSelectedPaths().first().startsWith(activity.filesDir.absolutePath)
val baseString = if (config.useRecycleBin && !isRecycleBin) R.string.move_to_recycle_bin_confirmation else R.string.deletion_confirmation val baseString = if (config.useRecycleBin && !isRecycleBin) R.string.move_to_recycle_bin_confirmation else R.string.deletion_confirmation
val question = String.format(resources.getString(baseString), items) val question = String.format(resources.getString(baseString), items)
@ -355,48 +363,35 @@ class MediaAdapter(activity: BaseSimpleActivity, var media: MutableList<Thumbnai
} }
} }
private fun getCurrentPath() = (media[selectedPositions.first()] as Medium).path
private fun deleteFiles() { private fun deleteFiles() {
if (selectedPositions.isEmpty()) { if (selectedKeys.isEmpty()) {
return return
} }
val fileDirItems = ArrayList<FileDirItem>(selectedPositions.size) val SAFPath = getFirstSelectedItemPath() ?: return
val removeMedia = ArrayList<Medium>(selectedPositions.size)
if (media.size <= selectedPositions.first()) {
finishActMode()
return
}
val SAFPath = (media[selectedPositions.first()] as Medium).path
activity.handleSAFDialog(SAFPath) { activity.handleSAFDialog(SAFPath) {
selectedPositions.sortedDescending().forEach { val fileDirItems = ArrayList<FileDirItem>(selectedKeys.size)
val thumbnailItem = media.getOrNull(it) val removeMedia = ArrayList<Medium>(selectedKeys.size)
if (thumbnailItem is Medium) { val position = getSelectedItemPositions()
fileDirItems.add(FileDirItem(thumbnailItem.path, thumbnailItem.name))
removeMedia.add(thumbnailItem) getSelectedItems().forEach {
} fileDirItems.add(FileDirItem(it.path, it.name))
removeMedia.add(it)
} }
media.removeAll(removeMedia) media.removeAll(removeMedia)
listener?.tryDeleteFiles(fileDirItems) listener?.tryDeleteFiles(fileDirItems)
removeSelectedItems() removeSelectedItems(position)
} }
} }
private fun getSelectedMedia(): List<Medium> { private fun getSelectedItems() = media.filter { selectedKeys.contains((it as? Medium)?.path?.hashCode()) } as ArrayList<Medium>
val selectedMedia = ArrayList<Medium>(selectedPositions.size)
selectedPositions.forEach {
(media.getOrNull(it) as? Medium)?.apply {
selectedMedia.add(this)
}
}
return selectedMedia
}
private fun getSelectedPaths() = getSelectedMedia().map { it.path } as ArrayList<String> private fun getSelectedPaths() = getSelectedItems().map { it.path } as ArrayList<String>
private fun getFirstSelectedItemPath() = getItemWithKey(selectedKeys.first())?.path
private fun getItemWithKey(key: Int): Medium? = media.firstOrNull { (it as? Medium)?.path?.hashCode() == key } as? Medium
fun updateMedia(newMedia: ArrayList<ThumbnailItem>) { fun updateMedia(newMedia: ArrayList<ThumbnailItem>) {
val thumbnailItems = newMedia.clone() as ArrayList<ThumbnailItem> val thumbnailItems = newMedia.clone() as ArrayList<ThumbnailItem>
@ -437,12 +432,18 @@ class MediaAdapter(activity: BaseSimpleActivity, var media: MutableList<Thumbnai
fun getItemBubbleText(position: Int, sorting: Int) = (media[position] as? Medium)?.getBubbleText(sorting) fun getItemBubbleText(position: Int, sorting: Int) = (media[position] as? Medium)?.getBubbleText(sorting)
private fun setupThumbnail(view: View, medium: Medium) { private fun setupThumbnail(view: View, medium: Medium) {
val isSelected = selectedKeys.contains(medium.path.hashCode())
view.apply { view.apply {
play_outline.beVisibleIf(medium.isVideo()) play_outline.beVisibleIf(medium.isVideo())
photo_name.beVisibleIf(displayFilenames || isListViewType) photo_name.beVisibleIf(displayFilenames || isListViewType)
photo_name.text = medium.name photo_name.text = medium.name
photo_name.tag = medium.path photo_name.tag = medium.path
medium_check?.beVisibleIf(isSelected)
if (isSelected) {
medium_check?.background?.applyColorFilter(primaryColor)
}
var path = medium.path var path = medium.path
if (hasOTGConnected && path.startsWith(OTG_PATH)) { if (hasOTGConnected && path.startsWith(OTG_PATH)) {
path = path.getOTGPublicPath(context) path = path.getOTGPublicPath(context)

View file

@ -2,11 +2,11 @@ package com.simplemobiletools.gallery.adapters
import android.os.Bundle import android.os.Bundle
import android.os.Parcelable import android.os.Parcelable
import android.view.ViewGroup
import androidx.fragment.app.Fragment import androidx.fragment.app.Fragment
import androidx.fragment.app.FragmentManager import androidx.fragment.app.FragmentManager
import androidx.fragment.app.FragmentStatePagerAdapter import androidx.fragment.app.FragmentStatePagerAdapter
import androidx.viewpager.widget.PagerAdapter import androidx.viewpager.widget.PagerAdapter
import android.view.ViewGroup
import com.simplemobiletools.gallery.activities.ViewPagerActivity import com.simplemobiletools.gallery.activities.ViewPagerActivity
import com.simplemobiletools.gallery.fragments.PhotoFragment import com.simplemobiletools.gallery.fragments.PhotoFragment
import com.simplemobiletools.gallery.fragments.VideoFragment import com.simplemobiletools.gallery.fragments.VideoFragment

View file

@ -3,8 +3,8 @@ package com.simplemobiletools.gallery.extensions
import android.app.Activity import android.app.Activity
import android.content.Intent import android.content.Intent
import android.provider.MediaStore import android.provider.MediaStore
import androidx.appcompat.app.AppCompatActivity
import android.view.View import android.view.View
import androidx.appcompat.app.AppCompatActivity
import com.simplemobiletools.commons.activities.BaseSimpleActivity import com.simplemobiletools.commons.activities.BaseSimpleActivity
import com.simplemobiletools.commons.dialogs.ConfirmationDialog import com.simplemobiletools.commons.dialogs.ConfirmationDialog
import com.simplemobiletools.commons.extensions.* import com.simplemobiletools.commons.extensions.*
@ -60,8 +60,8 @@ fun Activity.launchCamera() {
} }
fun SimpleActivity.launchAbout() { fun SimpleActivity.launchAbout() {
val licenses = LICENSE_GLIDE or LICENSE_CROPPER or LICENSE_MULTISELECT or LICENSE_RTL or LICENSE_SUBSAMPLING or LICENSE_PATTERN or val licenses = LICENSE_GLIDE or LICENSE_CROPPER or LICENSE_RTL or LICENSE_SUBSAMPLING or LICENSE_PATTERN or LICENSE_REPRINT or LICENSE_GIF_DRAWABLE or
LICENSE_REPRINT or LICENSE_GIF_DRAWABLE or LICENSE_PHOTOVIEW or LICENSE_PICASSO or LICENSE_EXOPLAYER or LICENSE_PANORAMA_VIEW or LICENSE_SANSELAN or LICENSE_FILTERS LICENSE_PHOTOVIEW or LICENSE_PICASSO or LICENSE_EXOPLAYER or LICENSE_PANORAMA_VIEW or LICENSE_SANSELAN or LICENSE_FILTERS
val faqItems = arrayListOf( val faqItems = arrayListOf(
FAQItem(R.string.faq_5_title_commons, R.string.faq_5_text_commons), FAQItem(R.string.faq_5_title_commons, R.string.faq_5_text_commons),

View file

@ -8,7 +8,6 @@ import android.database.sqlite.SQLiteException
import android.graphics.Point import android.graphics.Point
import android.graphics.drawable.PictureDrawable import android.graphics.drawable.PictureDrawable
import android.media.AudioManager import android.media.AudioManager
import android.os.Build
import android.provider.MediaStore import android.provider.MediaStore
import android.view.WindowManager import android.view.WindowManager
import android.widget.ImageView import android.widget.ImageView
@ -88,7 +87,6 @@ val Context.usableScreenSize: Point
val Context.realScreenSize: Point val Context.realScreenSize: Point
get() { get() {
val size = Point() val size = Point()
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1)
windowManager.defaultDisplay.getRealSize(size) windowManager.defaultDisplay.getRealSize(size)
return size return size
} }

View file

@ -1,6 +1,5 @@
package com.simplemobiletools.gallery.fragments package com.simplemobiletools.gallery.fragments
import android.annotation.SuppressLint
import android.content.Intent import android.content.Intent
import android.content.res.Configuration import android.content.res.Configuration
import android.graphics.Bitmap import android.graphics.Bitmap
@ -29,8 +28,6 @@ import com.davemorrissey.labs.subscaleview.ImageSource
import com.davemorrissey.labs.subscaleview.SubsamplingScaleImageView import com.davemorrissey.labs.subscaleview.SubsamplingScaleImageView
import com.simplemobiletools.commons.extensions.* import com.simplemobiletools.commons.extensions.*
import com.simplemobiletools.commons.helpers.OTG_PATH import com.simplemobiletools.commons.helpers.OTG_PATH
import com.simplemobiletools.commons.helpers.isJellyBean1Plus
import com.simplemobiletools.commons.helpers.isLollipopPlus
import com.simplemobiletools.gallery.R import com.simplemobiletools.gallery.R
import com.simplemobiletools.gallery.activities.PanoramaActivity import com.simplemobiletools.gallery.activities.PanoramaActivity
import com.simplemobiletools.gallery.activities.PhotoActivity import com.simplemobiletools.gallery.activities.PhotoActivity
@ -208,18 +205,11 @@ class PhotoFragment : ViewPagerFragment() {
} }
} }
@SuppressLint("NewApi")
private fun measureScreen() { private fun measureScreen() {
val metrics = DisplayMetrics() val metrics = DisplayMetrics()
if (isJellyBean1Plus()) {
activity!!.windowManager.defaultDisplay.getRealMetrics(metrics) activity!!.windowManager.defaultDisplay.getRealMetrics(metrics)
ViewPagerActivity.screenWidth = metrics.widthPixels ViewPagerActivity.screenWidth = metrics.widthPixels
ViewPagerActivity.screenHeight = metrics.heightPixels ViewPagerActivity.screenHeight = metrics.heightPixels
} else {
activity!!.windowManager.defaultDisplay.getMetrics(metrics)
ViewPagerActivity.screenWidth = metrics.widthPixels
ViewPagerActivity.screenHeight = metrics.heightPixels
}
} }
private fun photoFragmentVisibilityChanged(isVisible: Boolean) { private fun photoFragmentVisibilityChanged(isVisible: Boolean) {
@ -280,7 +270,7 @@ class PhotoFragment : ViewPagerFragment() {
} }
private fun loadSVG() { private fun loadSVG() {
Glide.with(this) Glide.with(context!!)
.`as`(PictureDrawable::class.java) .`as`(PictureDrawable::class.java)
.listener(SvgSoftwareLayerSetter()) .listener(SvgSoftwareLayerSetter())
.load(medium.path) .load(medium.path)
@ -440,7 +430,7 @@ class PhotoFragment : ViewPagerFragment() {
false false
} }
view.panorama_outline.beVisibleIf(isPanorama && isLollipopPlus()) view.panorama_outline.beVisibleIf(isPanorama)
} }
private fun getImageOrientation(): Int { private fun getImageOrientation(): Int {
@ -514,7 +504,7 @@ class PhotoFragment : ViewPagerFragment() {
override fun onDestroyView() { override fun onDestroyView() {
super.onDestroyView() super.onDestroyView()
if (activity?.isActivityDestroyed() == false) { if (activity?.isDestroyed == false) {
view.subsampling_view.recycle() view.subsampling_view.recycle()
} }
loadZoomableViewHandler.removeCallbacksAndMessages(null) loadZoomableViewHandler.removeCallbacksAndMessages(null)

View file

@ -1,13 +1,11 @@
package com.simplemobiletools.gallery.fragments package com.simplemobiletools.gallery.fragments
import android.annotation.TargetApi
import android.content.res.Configuration import android.content.res.Configuration
import android.graphics.Point import android.graphics.Point
import android.graphics.SurfaceTexture import android.graphics.SurfaceTexture
import android.media.AudioManager import android.media.AudioManager
import android.media.MediaMetadataRetriever import android.media.MediaMetadataRetriever
import android.net.Uri import android.net.Uri
import android.os.Build
import android.os.Bundle import android.os.Bundle
import android.os.Handler import android.os.Handler
import android.util.DisplayMetrics import android.util.DisplayMetrics
@ -28,7 +26,6 @@ import com.google.android.exoplayer2.upstream.DataSpec
import com.google.android.exoplayer2.upstream.FileDataSource import com.google.android.exoplayer2.upstream.FileDataSource
import com.google.android.exoplayer2.video.VideoListener import com.google.android.exoplayer2.video.VideoListener
import com.simplemobiletools.commons.extensions.* import com.simplemobiletools.commons.extensions.*
import com.simplemobiletools.commons.helpers.isJellyBean1Plus
import com.simplemobiletools.gallery.R import com.simplemobiletools.gallery.R
import com.simplemobiletools.gallery.activities.VideoActivity import com.simplemobiletools.gallery.activities.VideoActivity
import com.simplemobiletools.gallery.extensions.* import com.simplemobiletools.gallery.extensions.*
@ -312,7 +309,6 @@ class VideoFragment : ViewPagerFragment(), TextureView.SurfaceTextureListener, S
} }
private fun hasNavBar(): Boolean { private fun hasNavBar(): Boolean {
return if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
val display = context!!.windowManager.defaultDisplay val display = context!!.windowManager.defaultDisplay
val realDisplayMetrics = DisplayMetrics() val realDisplayMetrics = DisplayMetrics()
@ -327,12 +323,7 @@ class VideoFragment : ViewPagerFragment(), TextureView.SurfaceTextureListener, S
val displayHeight = displayMetrics.heightPixels val displayHeight = displayMetrics.heightPixels
val displayWidth = displayMetrics.widthPixels val displayWidth = displayMetrics.widthPixels
realWidth - displayWidth > 0 || realHeight - displayHeight > 0 return realWidth - displayWidth > 0 || realHeight - displayHeight > 0
} else {
val hasMenuKey = ViewConfiguration.get(context).hasPermanentMenuKey()
val hasBackKey = KeyCharacterMap.deviceHasKey(KeyEvent.KEYCODE_BACK)
!hasMenuKey && !hasBackKey
}
} }
private fun setupTimeHolder() { private fun setupTimeHolder() {
@ -514,7 +505,6 @@ class VideoFragment : ViewPagerFragment(), TextureView.SurfaceTextureListener, S
}.start() }.start()
} }
@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1)
private fun setVideoSize() { private fun setVideoSize() {
if (activity == null || mTextureView == null) if (activity == null || mTextureView == null)
return return
@ -524,15 +514,10 @@ class VideoFragment : ViewPagerFragment(), TextureView.SurfaceTextureListener, S
val screenWidth: Int val screenWidth: Int
val screenHeight: Int val screenHeight: Int
if (isJellyBean1Plus()) {
val realMetrics = DisplayMetrics() val realMetrics = DisplayMetrics()
display.getRealMetrics(realMetrics) display.getRealMetrics(realMetrics)
screenWidth = realMetrics.widthPixels screenWidth = realMetrics.widthPixels
screenHeight = realMetrics.heightPixels screenHeight = realMetrics.heightPixels
} else {
screenWidth = display.width
screenHeight = display.height
}
val screenProportion = screenWidth.toFloat() / screenHeight.toFloat() val screenProportion = screenWidth.toFloat() / screenHeight.toFloat()

View file

@ -1,9 +0,0 @@
package com.simplemobiletools.gallery.interfaces
import com.simplemobiletools.gallery.models.FilterItem
interface FilterAdapterListener {
fun getCurrentFilter(): FilterItem
fun setCurrentFilter(position: Int)
}

View file

@ -1,7 +0,0 @@
<resources>
<style name="FullScreenTheme" parent="AppTheme.Base">
<item name="android:windowTranslucentNavigation">true</item>
</style>
</resources>

View file

@ -4,6 +4,7 @@
<style name="FullScreenTheme.Base" parent="AppTheme"> <style name="FullScreenTheme.Base" parent="AppTheme">
<item name="android:windowContentOverlay">@null</item> <item name="android:windowContentOverlay">@null</item>
<item name="android:windowTranslucentNavigation">true</item>
</style> </style>
<style name="FullScreenTheme" parent="FullScreenTheme.Base"/> <style name="FullScreenTheme" parent="FullScreenTheme.Base"/>

View file

@ -9,7 +9,7 @@ buildscript {
} }
dependencies { dependencies {
classpath 'com.android.tools.build:gradle:3.2.0' classpath 'com.android.tools.build:gradle:3.2.1'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
// NOTE: Do not place your application dependencies here; they belong // NOTE: Do not place your application dependencies here; they belong