From 78bcf8adb8e7a892fa1ecf20f75027482d9199bc Mon Sep 17 00:00:00 2001 From: tibbi Date: Tue, 16 Oct 2018 23:56:05 +0200 Subject: [PATCH] updating Commons, min Android version to 5 + adapter changes --- app/build.gradle | 6 +- .../gallery/activities/MainActivity.kt | 3 +- .../gallery/activities/MediaActivity.kt | 2 +- .../gallery/activities/PanoramaActivity.kt | 8 +- .../activities/SetWallpaperActivity.kt | 3 +- .../gallery/activities/ViewPagerActivity.kt | 33 ++-- .../gallery/adapters/DirectoryAdapter.kt | 150 ++++++++---------- .../gallery/adapters/FiltersAdapter.kt | 21 ++- .../gallery/adapters/ManageFoldersAdapter.kt | 31 ++-- .../adapters/ManageHiddenFoldersAdapter.kt | 35 ++-- .../gallery/adapters/MediaAdapter.kt | 117 +++++++------- .../gallery/adapters/MyPagerAdapter.kt | 2 +- .../gallery/extensions/Activity.kt | 6 +- .../gallery/extensions/Context.kt | 4 +- .../gallery/fragments/PhotoFragment.kt | 22 +-- .../gallery/fragments/VideoFragment.kt | 43 ++--- .../interfaces/FilterAdapterListener.kt | 9 -- app/src/main/res/values-v21/styles.xml | 7 - app/src/main/res/values/styles.xml | 1 + build.gradle | 2 +- 20 files changed, 209 insertions(+), 296 deletions(-) delete mode 100644 app/src/main/kotlin/com/simplemobiletools/gallery/interfaces/FilterAdapterListener.kt delete mode 100644 app/src/main/res/values-v21/styles.xml diff --git a/app/build.gradle b/app/build.gradle index 1141d8232..50299afc5 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -9,7 +9,7 @@ android { defaultConfig { applicationId "com.simplemobiletools.gallery" - minSdkVersion 16 + minSdkVersion 21 targetSdkVersion 28 versionCode 201 versionName "4.6.5" @@ -43,7 +43,7 @@ android { } 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 'androidx.multidex:multidex:2.0.0' 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.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() diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MainActivity.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MainActivity.kt index 4590512cb..ce4c12e27 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MainActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MainActivity.kt @@ -12,7 +12,6 @@ import android.view.MenuItem import android.view.ViewGroup import android.widget.FrameLayout import android.widget.Toast -import androidx.recyclerview.widget.GridLayoutManager import androidx.recyclerview.widget.RecyclerView import com.simplemobiletools.commons.dialogs.CreateNewFolderDialog import com.simplemobiletools.commons.dialogs.FilePickerDialog @@ -966,7 +965,7 @@ class MainActivity : SimpleActivity(), DirectoryOperationsListener { } private fun checkLastMediaChanged() { - if (isActivityDestroyed()) { + if (isDestroyed) { return } diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MediaActivity.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MediaActivity.kt index 1dd2514b6..0d37b2013 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MediaActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MediaActivity.kt @@ -398,7 +398,7 @@ class MediaActivity : SimpleActivity(), MediaOperationsListener { } private fun checkLastMediaChanged() { - if (isActivityDestroyed()) { + if (isDestroyed) { return } diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/PanoramaActivity.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/PanoramaActivity.kt index e1131e92f..e13f4e055 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/PanoramaActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/PanoramaActivity.kt @@ -1,11 +1,9 @@ package com.simplemobiletools.gallery.activities -import android.annotation.TargetApi import android.content.res.Configuration import android.graphics.Bitmap import android.graphics.BitmapFactory import android.graphics.Color -import android.os.Build import android.os.Bundle import android.view.View 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.toast import com.simplemobiletools.commons.helpers.PERMISSION_WRITE_STORAGE -import com.simplemobiletools.commons.helpers.isLollipopPlus import com.simplemobiletools.commons.helpers.isPiePlus import com.simplemobiletools.gallery.R import com.simplemobiletools.gallery.extensions.* @@ -65,7 +62,6 @@ open class PanoramaActivity : SimpleActivity() { } } - @TargetApi(Build.VERSION_CODES.LOLLIPOP) override fun onResume() { super.onResume() panorama_view.resumeRendering() @@ -74,9 +70,7 @@ open class PanoramaActivity : SimpleActivity() { 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() { diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/SetWallpaperActivity.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/SetWallpaperActivity.kt index 5f02df853..8fd8dcfb5 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/SetWallpaperActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/SetWallpaperActivity.kt @@ -10,7 +10,6 @@ import android.os.Bundle import android.view.Menu import android.view.MenuItem import com.simplemobiletools.commons.dialogs.RadioGroupDialog -import com.simplemobiletools.commons.extensions.isActivityDestroyed import com.simplemobiletools.commons.extensions.toast import com.simplemobiletools.commons.helpers.isNougatPlus import com.simplemobiletools.commons.models.RadioItem @@ -113,7 +112,7 @@ class SetWallpaperActivity : SimpleActivity(), CropImageView.OnCropImageComplete @SuppressLint("NewApi") override fun onCropImageComplete(view: CropImageView?, result: CropImageView.CropResult) { - if (isActivityDestroyed()) + if (isDestroyed) return if (result.error == null) { 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 9a318db83..03cd4a0fa 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/ViewPagerActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/ViewPagerActivity.kt @@ -2,7 +2,6 @@ package com.simplemobiletools.gallery.activities import android.animation.Animator import android.animation.ValueAnimator -import android.annotation.SuppressLint import android.annotation.TargetApi import android.app.Activity import android.content.Intent @@ -20,13 +19,13 @@ import android.os.Build import android.os.Bundle import android.os.Handler import android.provider.MediaStore -import androidx.viewpager.widget.ViewPager import android.util.DisplayMetrics import android.view.Menu import android.view.MenuItem import android.view.View import android.view.WindowManager import android.view.animation.DecelerateInterpolator +import androidx.viewpager.widget.ViewPager import com.bumptech.glide.Glide import com.simplemobiletools.commons.dialogs.PropertiesDialog import com.simplemobiletools.commons.dialogs.RenameItemDialog @@ -103,7 +102,6 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View initFavorites() } - @TargetApi(Build.VERSION_CODES.LOLLIPOP) override fun onResume() { super.onResume() if (!hasPermission(PERMISSION_WRITE_STORAGE)) { @@ -112,9 +110,7 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View } if (config.bottomActions) { - if (isLollipopPlus()) { - window.navigationBarColor = Color.TRANSPARENT - } + window.navigationBarColor = Color.TRANSPARENT } else { setTranslucentNavigation() } @@ -135,9 +131,7 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View } supportActionBar?.setBackgroundDrawable(ColorDrawable(Color.TRANSPARENT)) - if (isLollipopPlus()) { - window.statusBarColor = Color.TRANSPARENT - } + window.statusBarColor = Color.TRANSPARENT } override fun onPause() { @@ -225,7 +219,7 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View supportActionBar?.title = mPath.getFilenameFromPath() view_pager.onGlobalLayout { - if (!isActivityDestroyed()) { + if (!isDestroyed) { if (mMediaFiles.isNotEmpty()) { gotMedia(mMediaFiles as ArrayList) } @@ -365,7 +359,7 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View private fun updatePagerItems(media: MutableList) { val pagerAdapter = MyPagerAdapter(this, supportFragmentManager, media) - if (!isActivityDestroyed()) { + if (!isDestroyed) { view_pager.apply { adapter = pagerAdapter currentItem = mPos @@ -384,7 +378,7 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View private fun startSlideshow() { if (getMediaForSlideshow()) { view_pager.onGlobalLayout { - if (!isActivityDestroyed()) { + if (!isDestroyed) { hideSystemUI(true) mSlideshowInterval = config.slideshowInterval mSlideshowMoveBackwards = config.slideshowMoveBackwards @@ -474,7 +468,7 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View if (mIsSlideshowActive) { if (getCurrentMedium()!!.isImage() || getCurrentMedium()!!.isGIF()) { mSlideshowHandler.postDelayed({ - if (mIsSlideshowActive && !isActivityDestroyed()) { + if (mIsSlideshowActive && !isDestroyed) { swipeToNextMedium() } }, mSlideshowInterval * 1000L) @@ -980,18 +974,11 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View initBottomActionsLayout() } - @SuppressLint("NewApi") private fun measureScreen() { val metrics = DisplayMetrics() - if (isJellyBean1Plus()) { - windowManager.defaultDisplay.getRealMetrics(metrics) - screenWidth = metrics.widthPixels - screenHeight = metrics.heightPixels - } else { - windowManager.defaultDisplay.getMetrics(metrics) - screenWidth = metrics.widthPixels - screenHeight = metrics.heightPixels - } + windowManager.defaultDisplay.getRealMetrics(metrics) + screenWidth = metrics.widthPixels + screenHeight = metrics.heightPixels } private fun refreshViewPager() { diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/adapters/DirectoryAdapter.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/adapters/DirectoryAdapter.kt index 12b095d18..f03a9e92c 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/adapters/DirectoryAdapter.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/adapters/DirectoryAdapter.kt @@ -1,6 +1,5 @@ package com.simplemobiletools.gallery.adapters -import android.util.SparseArray import android.view.Menu import android.view.View import android.view.ViewGroup @@ -26,8 +25,6 @@ import com.simplemobiletools.gallery.models.AlbumCover import com.simplemobiletools.gallery.models.Directory import kotlinx.android.synthetic.main.directory_item_list.view.* import java.io.File -import java.util.* -import kotlin.collections.ArrayList class DirectoryAdapter(activity: BaseSimpleActivity, var dirs: ArrayList, val listener: DirectoryOperationsListener?, recyclerView: MyRecyclerView, val isPickIntent: Boolean, fastScroller: FastScroller? = null, itemClick: (Any) -> Unit) : @@ -48,14 +45,6 @@ class DirectoryAdapter(activity: BaseSimpleActivity, var dirs: ArrayList + holder.bindView(dir, true, !isPickIntent) { itemView, adapterPosition -> setupView(itemView, dir) } - bindViewHolder(holder, position, view) + bindViewHolder(holder) } override fun getItemCount() = dirs.size @@ -90,7 +79,7 @@ class DirectoryAdapter(activity: BaseSimpleActivity, var dirs: ArrayList() - 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() dirs = newDirs @@ -330,9 +311,9 @@ class DirectoryAdapter(activity: BaseSimpleActivity, var dirs: ArrayList() val showHidden = activity.config.shouldShowHidden - selectedPositions.forEach { - val path = dirs[it].path - if (path.startsWith(OTG_PATH)) { - paths.addAll(getOTGFilePaths(path, showHidden)) - } else if (path != FAVORITES) { - File(path).listFiles()?.filter { + getSelectedPaths().forEach { + if (it.startsWith(OTG_PATH)) { + paths.addAll(getOTGFilePaths(it, showHidden)) + } else if (it != FAVORITES) { + File(it).listFiles()?.filter { !activity.getIsPathDirectory(it.absolutePath) && it.isMediaFile() && (showHidden || !it.name.startsWith('.')) }?.mapTo(paths) { it.absolutePath } } @@ -378,9 +358,9 @@ class DirectoryAdapter(activity: BaseSimpleActivity, var dirs: ArrayList(selectedPositions.size) - val removeFolders = ArrayList(selectedPositions.size) - var SAFPath = "" - selectedPositions.forEach { - if (dirs.size > it) { - val path = dirs[it].path - if (activity.needsStupidWritePermissions(path) && config.treeUri.isEmpty()) { - SAFPath = path - } + val selectedDirs = getSelectedItems() + selectedDirs.forEach { + val path = it.path + if (activity.needsStupidWritePermissions(path) && config.treeUri.isEmpty()) { + SAFPath = path } } activity.handleSAFDialog(SAFPath) { - selectedPositions.sortedDescending().forEach { - val directory = dirs.getOrNull(it) - if (directory != null) { - if (directory.areFavorites() || directory.isRecycleBin()) { - if (directory.isRecycleBin()) { - tryEmptyRecycleBin(false) - } else { - Thread { - activity.galleryDB.MediumDao().clearFavorites() - listener?.refreshItems() - }.start() - } - - if (selectedPositions.size == 1) { - finishActMode() - } else { - selectedPositions.remove(it) - toggleItemSelection(false, it) - } + val foldersToDelete = ArrayList(selectedKeys.size) + selectedDirs.forEach { + if (it.areFavorites() || it.isRecycleBin()) { + if (it.isRecycleBin()) { + tryEmptyRecycleBin(false) } else { - folders.add(File(directory.path)) - removeFolders.add(directory) + Thread { + activity.galleryDB.MediumDao().clearFavorites() + listener?.refreshItems() + }.start() } + + if (selectedKeys.size == 1) { + finishActMode() + } + } else { + foldersToDelete.add(File(it.path)) } } - listener?.deleteFolders(folders) + listener?.deleteFolders(foldersToDelete) } } private fun changeAlbumCover(useDefault: Boolean) { - if (selectedPositions.size != 1) + if (selectedKeys.size != 1) return - val path = dirs[selectedPositions.first()].path + val path = getFirstSelectedItemPath() ?: return if (useDefault) { val albumCovers = getAlbumCoversWithout(path) @@ -480,15 +450,15 @@ class DirectoryAdapter(activity: BaseSimpleActivity, var dirs: ArrayList { - val paths = HashSet(selectedPositions.size) - selectedPositions.forEach { - (dirs.getOrNull(it))?.apply { - paths.add(path) - } - } - return paths - } + private fun getSelectedItems() = dirs.filter { selectedKeys.contains(it.path.hashCode()) } as ArrayList + + private fun getSelectedPaths() = getSelectedItems().map { it.path } as ArrayList + + private fun getFirstSelectedItem() = getItemWithKey(selectedKeys.first()) + + private fun getFirstSelectedItemPath() = getFirstSelectedItem()?.path + + private fun getItemWithKey(key: Int): Directory? = dirs.firstOrNull { it.path.hashCode() == key } fun updateDirs(newDirs: ArrayList) { val directories = newDirs.clone() as ArrayList @@ -516,6 +486,7 @@ class DirectoryAdapter(activity: BaseSimpleActivity, var dirs: ArrayList TYPE_IMAGES } + dir_check?.beVisibleIf(isSelected) + if (isSelected) { + dir_check.background?.applyColorFilter(primaryColor) + } + activity.loadImage(thumbnailType, directory.tmb, dir_thumbnail, scrollHorizontally, animateGifs, cropThumbnails) dir_pin.beVisibleIf(pinnedFolders.contains(directory.path)) dir_location.beVisibleIf(directory.location != LOCAITON_INTERNAL) diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/adapters/FiltersAdapter.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/adapters/FiltersAdapter.kt index 046abda1f..db8aa9c7d 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/adapters/FiltersAdapter.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/adapters/FiltersAdapter.kt @@ -1,37 +1,34 @@ package com.simplemobiletools.gallery.adapters import android.content.Context -import android.graphics.drawable.Drawable import android.view.LayoutInflater import android.view.View import android.view.ViewGroup import androidx.recyclerview.widget.RecyclerView import com.simplemobiletools.gallery.R -import com.simplemobiletools.gallery.interfaces.FilterAdapterListener import com.simplemobiletools.gallery.models.FilterItem import kotlinx.android.synthetic.main.editor_filter_item.view.* import java.util.* -class FiltersAdapter(val context: Context, val filterItems: ArrayList, val itemClick: (Int) -> Unit) : RecyclerView.Adapter(), - FilterAdapterListener { +class FiltersAdapter(val context: Context, val filterItems: ArrayList, val itemClick: (Int) -> Unit) : RecyclerView.Adapter() { private var currentSelection = filterItems.first() private var strokeBackground = context.resources.getDrawable(R.drawable.stroke_background) override fun onBindViewHolder(holder: ViewHolder, position: Int) { - holder.bindView(filterItems[position], strokeBackground) + holder.bindView(filterItems[position]) } override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder { 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 getCurrentFilter() = currentSelection + fun getCurrentFilter() = currentSelection - override fun setCurrentFilter(position: Int) { + private fun setCurrentFilter(position: Int) { val filterItem = filterItems.getOrNull(position) ?: return if (currentSelection != filterItem) { currentSelection = filterItem @@ -40,19 +37,19 @@ class FiltersAdapter(val context: Context, val filterItems: ArrayList removeSelection() @@ -41,20 +35,27 @@ class ManageFoldersAdapter(activity: BaseSimpleActivity, var folders: ArrayList< 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 onBindViewHolder(holder: ViewHolder, position: Int) { val folder = folders[position] - val view = holder.bindView(folder, true, true) { itemView, adapterPosition -> + holder.bindView(folder, true, true) { itemView, adapterPosition -> setupView(itemView, folder) } - bindViewHolder(holder, position, view) + bindViewHolder(holder) } override fun getItemCount() = folders.size + private fun getSelectedItems() = folders.filter { selectedKeys.contains(it.hashCode()) } as ArrayList + private fun setupView(view: View, folder: String) { view.apply { + manage_folder_holder?.isSelected = selectedKeys.contains(folder.hashCode()) manage_folder_title.apply { text = folder setTextColor(config.textColor) @@ -63,20 +64,20 @@ class ManageFoldersAdapter(activity: BaseSimpleActivity, var folders: ArrayList< } private fun removeSelection() { - val removeFolders = ArrayList(selectedPositions.size) + val removeFolders = ArrayList(selectedKeys.size) + val positions = getSelectedItemPositions() - selectedPositions.sortedDescending().forEach { - val folder = folders[it] - removeFolders.add(folder) + getSelectedItems().forEach { + removeFolders.add(it) if (isShowingExcludedFolders) { - config.removeExcludedFolder(folder) + config.removeExcludedFolder(it) } else { - config.removeIncludedFolder(folder) + config.removeIncludedFolder(it) } } folders.removeAll(removeFolders) - removeSelectedItems() + removeSelectedItems(positions) if (folders.isEmpty()) { listener?.refreshItems() } diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/adapters/ManageHiddenFoldersAdapter.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/adapters/ManageHiddenFoldersAdapter.kt index 101b12764..95e2c053f 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/adapters/ManageHiddenFoldersAdapter.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/adapters/ManageHiddenFoldersAdapter.kt @@ -27,12 +27,6 @@ class ManageHiddenFoldersAdapter(activity: BaseSimpleActivity, var folders: Arra 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) { when (id) { R.id.cab_unhide -> tryUnhideFolders() @@ -43,20 +37,27 @@ class ManageHiddenFoldersAdapter(activity: BaseSimpleActivity, var folders: Arra 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 onBindViewHolder(holder: ViewHolder, position: Int) { val folder = folders[position] - val view = holder.bindView(folder, true, true) { itemView, adapterPosition -> + holder.bindView(folder, true, true) { itemView, adapterPosition -> setupView(itemView, folder) } - bindViewHolder(holder, position, view) + bindViewHolder(holder) } override fun getItemCount() = folders.size + private fun getSelectedItems() = folders.filter { selectedKeys.contains(it.hashCode()) } as ArrayList + private fun setupView(view: View, folder: String) { view.apply { + manage_folder_holder?.isSelected = selectedKeys.contains(folder.hashCode()) manage_folder_title.apply { text = folder setTextColor(config.textColor) @@ -65,12 +66,12 @@ class ManageHiddenFoldersAdapter(activity: BaseSimpleActivity, var folders: Arra } private fun tryUnhideFolders() { - val removeFolders = ArrayList(selectedPositions.size) + val removeFolders = ArrayList(selectedKeys.size) val sdCardPaths = ArrayList() - selectedPositions.forEach { - if (activity.isPathOnSD(folders[it])) { - sdCardPaths.add(folders[it]) + getSelectedItems().forEach { + if (activity.isPathOnSD(it)) { + sdCardPaths.add(it) } } @@ -84,14 +85,14 @@ class ManageHiddenFoldersAdapter(activity: BaseSimpleActivity, var folders: Arra } private fun unhideFolders(removeFolders: ArrayList) { - selectedPositions.sortedDescending().forEach { - val folder = folders[it] - removeFolders.add(folder) - activity.removeNoMedia(folder) + val position = getSelectedItemPositions() + getSelectedItems().forEach { + removeFolders.add(it) + activity.removeNoMedia(it) } folders.removeAll(removeFolders) - removeSelectedItems() + removeSelectedItems(position) if (folders.isEmpty()) { listener?.refreshItems() } diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/adapters/MediaAdapter.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/adapters/MediaAdapter.kt index d88895b59..06ef2b350 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/adapters/MediaAdapter.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/adapters/MediaAdapter.kt @@ -61,14 +61,6 @@ class MediaAdapter(activity: BaseSimpleActivity, var media: MutableList + holder.bindView(tmbItem, tmbItem is Medium, allowLongPress) { itemView, adapterPosition -> if (tmbItem is Medium) { setupThumbnail(itemView, tmbItem) } else { setupSection(itemView, tmbItem as ThumbnailSection) } } - bindViewHolder(holder, position, view) + bindViewHolder(holder) } override fun getItemCount() = media.size @@ -112,9 +104,9 @@ class MediaAdapter(activity: BaseSimpleActivity, var media: MutableList 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) } checkHideBtnVisibility(this) @@ -123,7 +115,7 @@ class MediaAdapter(activity: BaseSimpleActivity, var media: MutableList copyMoveTo(true) R.id.cab_move_to -> copyMoveTo(false) 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_set_as -> activity.setAs(getCurrentPath()) + R.id.cab_set_as -> setAs() R.id.cab_delete -> checkDeleteConfirmation() } } @@ -152,9 +144,13 @@ class MediaAdapter(activity: BaseSimpleActivity, var media: MutableList 0 && !isInRecycleBin menu.findItem(R.id.cab_unhide).isVisible = hiddenCnt > 0 && !isInRecycleBin } @@ -185,7 +181,7 @@ class MediaAdapter(activity: BaseSimpleActivity, var media: MutableList 1) { + if (selectedKeys.size == 1 && selectedKeys.first() != -1) { + activity.shareMediumPath(getSelectedItems().first().path) + } else if (selectedKeys.size > 1) { activity.shareMediaPaths(getSelectedPaths()) } } @@ -345,7 +353,7 @@ class MediaAdapter(activity: BaseSimpleActivity, var media: MutableList(selectedPositions.size) - val removeMedia = ArrayList(selectedPositions.size) - - if (media.size <= selectedPositions.first()) { - finishActMode() - return - } - - val SAFPath = (media[selectedPositions.first()] as Medium).path + val SAFPath = getFirstSelectedItemPath() ?: return activity.handleSAFDialog(SAFPath) { - selectedPositions.sortedDescending().forEach { - val thumbnailItem = media.getOrNull(it) - if (thumbnailItem is Medium) { - fileDirItems.add(FileDirItem(thumbnailItem.path, thumbnailItem.name)) - removeMedia.add(thumbnailItem) - } + val fileDirItems = ArrayList(selectedKeys.size) + val removeMedia = ArrayList(selectedKeys.size) + val position = getSelectedItemPositions() + + getSelectedItems().forEach { + fileDirItems.add(FileDirItem(it.path, it.name)) + removeMedia.add(it) } media.removeAll(removeMedia) listener?.tryDeleteFiles(fileDirItems) - removeSelectedItems() + removeSelectedItems(position) } } - private fun getSelectedMedia(): List { - val selectedMedia = ArrayList(selectedPositions.size) - selectedPositions.forEach { - (media.getOrNull(it) as? Medium)?.apply { - selectedMedia.add(this) - } - } - return selectedMedia - } + private fun getSelectedItems() = media.filter { selectedKeys.contains((it as? Medium)?.path?.hashCode()) } as ArrayList - private fun getSelectedPaths() = getSelectedMedia().map { it.path } as ArrayList + private fun getSelectedPaths() = getSelectedItems().map { it.path } as ArrayList + + 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) { val thumbnailItems = newMedia.clone() as ArrayList @@ -437,12 +432,18 @@ class MediaAdapter(activity: BaseSimpleActivity, var media: MutableList= Build.VERSION_CODES.JELLY_BEAN_MR1) - windowManager.defaultDisplay.getRealSize(size) + windowManager.defaultDisplay.getRealSize(size) return size } diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/fragments/PhotoFragment.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/fragments/PhotoFragment.kt index 1da94e93e..f0581f9ce 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/fragments/PhotoFragment.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/fragments/PhotoFragment.kt @@ -1,6 +1,5 @@ package com.simplemobiletools.gallery.fragments -import android.annotation.SuppressLint import android.content.Intent import android.content.res.Configuration import android.graphics.Bitmap @@ -29,8 +28,6 @@ import com.davemorrissey.labs.subscaleview.ImageSource import com.davemorrissey.labs.subscaleview.SubsamplingScaleImageView import com.simplemobiletools.commons.extensions.* 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.activities.PanoramaActivity import com.simplemobiletools.gallery.activities.PhotoActivity @@ -208,18 +205,11 @@ class PhotoFragment : ViewPagerFragment() { } } - @SuppressLint("NewApi") private fun measureScreen() { val metrics = DisplayMetrics() - if (isJellyBean1Plus()) { - activity!!.windowManager.defaultDisplay.getRealMetrics(metrics) - ViewPagerActivity.screenWidth = metrics.widthPixels - ViewPagerActivity.screenHeight = metrics.heightPixels - } else { - activity!!.windowManager.defaultDisplay.getMetrics(metrics) - ViewPagerActivity.screenWidth = metrics.widthPixels - ViewPagerActivity.screenHeight = metrics.heightPixels - } + activity!!.windowManager.defaultDisplay.getRealMetrics(metrics) + ViewPagerActivity.screenWidth = metrics.widthPixels + ViewPagerActivity.screenHeight = metrics.heightPixels } private fun photoFragmentVisibilityChanged(isVisible: Boolean) { @@ -280,7 +270,7 @@ class PhotoFragment : ViewPagerFragment() { } private fun loadSVG() { - Glide.with(this) + Glide.with(context!!) .`as`(PictureDrawable::class.java) .listener(SvgSoftwareLayerSetter()) .load(medium.path) @@ -440,7 +430,7 @@ class PhotoFragment : ViewPagerFragment() { false } - view.panorama_outline.beVisibleIf(isPanorama && isLollipopPlus()) + view.panorama_outline.beVisibleIf(isPanorama) } private fun getImageOrientation(): Int { @@ -514,7 +504,7 @@ class PhotoFragment : ViewPagerFragment() { override fun onDestroyView() { super.onDestroyView() - if (activity?.isActivityDestroyed() == false) { + if (activity?.isDestroyed == false) { view.subsampling_view.recycle() } loadZoomableViewHandler.removeCallbacksAndMessages(null) diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/fragments/VideoFragment.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/fragments/VideoFragment.kt index 470a061e0..751b98e4e 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/fragments/VideoFragment.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/fragments/VideoFragment.kt @@ -1,13 +1,11 @@ package com.simplemobiletools.gallery.fragments -import android.annotation.TargetApi import android.content.res.Configuration import android.graphics.Point import android.graphics.SurfaceTexture import android.media.AudioManager import android.media.MediaMetadataRetriever import android.net.Uri -import android.os.Build import android.os.Bundle import android.os.Handler 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.video.VideoListener import com.simplemobiletools.commons.extensions.* -import com.simplemobiletools.commons.helpers.isJellyBean1Plus import com.simplemobiletools.gallery.R import com.simplemobiletools.gallery.activities.VideoActivity import com.simplemobiletools.gallery.extensions.* @@ -312,27 +309,21 @@ class VideoFragment : ViewPagerFragment(), TextureView.SurfaceTextureListener, S } 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() - display.getRealMetrics(realDisplayMetrics) + val realDisplayMetrics = DisplayMetrics() + display.getRealMetrics(realDisplayMetrics) - val realHeight = realDisplayMetrics.heightPixels - val realWidth = realDisplayMetrics.widthPixels + val realHeight = realDisplayMetrics.heightPixels + val realWidth = realDisplayMetrics.widthPixels - val displayMetrics = DisplayMetrics() - display.getMetrics(displayMetrics) + val displayMetrics = DisplayMetrics() + display.getMetrics(displayMetrics) - val displayHeight = displayMetrics.heightPixels - val displayWidth = displayMetrics.widthPixels + val displayHeight = displayMetrics.heightPixels + val displayWidth = displayMetrics.widthPixels - realWidth - displayWidth > 0 || realHeight - displayHeight > 0 - } else { - val hasMenuKey = ViewConfiguration.get(context).hasPermanentMenuKey() - val hasBackKey = KeyCharacterMap.deviceHasKey(KeyEvent.KEYCODE_BACK) - !hasMenuKey && !hasBackKey - } + return realWidth - displayWidth > 0 || realHeight - displayHeight > 0 } private fun setupTimeHolder() { @@ -514,7 +505,6 @@ class VideoFragment : ViewPagerFragment(), TextureView.SurfaceTextureListener, S }.start() } - @TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1) private fun setVideoSize() { if (activity == null || mTextureView == null) return @@ -524,15 +514,10 @@ class VideoFragment : ViewPagerFragment(), TextureView.SurfaceTextureListener, S val screenWidth: Int val screenHeight: Int - if (isJellyBean1Plus()) { - val realMetrics = DisplayMetrics() - display.getRealMetrics(realMetrics) - screenWidth = realMetrics.widthPixels - screenHeight = realMetrics.heightPixels - } else { - screenWidth = display.width - screenHeight = display.height - } + val realMetrics = DisplayMetrics() + display.getRealMetrics(realMetrics) + screenWidth = realMetrics.widthPixels + screenHeight = realMetrics.heightPixels val screenProportion = screenWidth.toFloat() / screenHeight.toFloat() diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/interfaces/FilterAdapterListener.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/interfaces/FilterAdapterListener.kt deleted file mode 100644 index 379e9e964..000000000 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/interfaces/FilterAdapterListener.kt +++ /dev/null @@ -1,9 +0,0 @@ -package com.simplemobiletools.gallery.interfaces - -import com.simplemobiletools.gallery.models.FilterItem - -interface FilterAdapterListener { - fun getCurrentFilter(): FilterItem - - fun setCurrentFilter(position: Int) -} diff --git a/app/src/main/res/values-v21/styles.xml b/app/src/main/res/values-v21/styles.xml deleted file mode 100644 index 7f1ac50b0..000000000 --- a/app/src/main/res/values-v21/styles.xml +++ /dev/null @@ -1,7 +0,0 @@ - - - - - diff --git a/app/src/main/res/values/styles.xml b/app/src/main/res/values/styles.xml index 9bb53721a..fdde24e05 100644 --- a/app/src/main/res/values/styles.xml +++ b/app/src/main/res/values/styles.xml @@ -4,6 +4,7 @@