mirror of
				https://github.com/SimpleMobileTools/Simple-Gallery.git
				synced 2025-06-05 21:59:19 +02:00 
			
		
		
		
	updating Commons, min Android version to 5 + adapter changes
This commit is contained in:
		| @@ -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() | ||||
|   | ||||
| @@ -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 | ||||
|         } | ||||
|  | ||||
|   | ||||
| @@ -398,7 +398,7 @@ class MediaActivity : SimpleActivity(), MediaOperationsListener { | ||||
|     } | ||||
|  | ||||
|     private fun checkLastMediaChanged() { | ||||
|         if (isActivityDestroyed()) { | ||||
|         if (isDestroyed) { | ||||
|             return | ||||
|         } | ||||
|  | ||||
|   | ||||
| @@ -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() { | ||||
|   | ||||
| @@ -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) { | ||||
|   | ||||
| @@ -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<ThumbnailItem>) | ||||
|                 } | ||||
| @@ -365,7 +359,7 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View | ||||
|  | ||||
|     private fun updatePagerItems(media: MutableList<Medium>) { | ||||
|         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() { | ||||
|   | ||||
| @@ -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<Directory>, 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<Directo | ||||
|  | ||||
|     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 { | ||||
|         val layoutType = if (isListViewType) R.layout.directory_item_list else R.layout.directory_item_grid | ||||
|         return createViewHolder(layoutType, parent) | ||||
| @@ -63,10 +52,10 @@ class DirectoryAdapter(activity: BaseSimpleActivity, var dirs: ArrayList<Directo | ||||
|  | ||||
|     override fun onBindViewHolder(holder: MyRecyclerViewAdapter.ViewHolder, position: Int) { | ||||
|         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) | ||||
|         } | ||||
|         bindViewHolder(holder, position, view) | ||||
|         bindViewHolder(holder) | ||||
|     } | ||||
|  | ||||
|     override fun getItemCount() = dirs.size | ||||
| @@ -90,7 +79,7 @@ class DirectoryAdapter(activity: BaseSimpleActivity, var dirs: ArrayList<Directo | ||||
|     } | ||||
|  | ||||
|     override fun actionItemPressed(id: Int) { | ||||
|         if (selectedPositions.isEmpty()) { | ||||
|         if (selectedKeys.isEmpty()) { | ||||
|             return | ||||
|         } | ||||
|  | ||||
| @@ -117,17 +106,21 @@ class DirectoryAdapter(activity: BaseSimpleActivity, var dirs: ArrayList<Directo | ||||
|  | ||||
|     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) { | ||||
|         super.onViewRecycled(holder) | ||||
|         if (!activity.isActivityDestroyed()) { | ||||
|             Glide.with(activity).clear(holder.itemView?.dir_thumbnail!!) | ||||
|         if (!activity.isDestroyed) { | ||||
|             Glide.with(activity).clear(holder.itemView.dir_thumbnail!!) | ||||
|         } | ||||
|     } | ||||
|  | ||||
|     private fun checkHideBtnVisibility(menu: Menu) { | ||||
|         var hiddenCnt = 0 | ||||
|         var unhiddenCnt = 0 | ||||
|         selectedPositions.mapNotNull { dirs.getOrNull(it)?.path }.forEach { | ||||
|         getSelectedPaths().forEach { | ||||
|             if (File(it).doesThisOrParentHaveNoMedia()) { | ||||
|                 hiddenCnt++ | ||||
|             } else { | ||||
| @@ -143,7 +136,7 @@ class DirectoryAdapter(activity: BaseSimpleActivity, var dirs: ArrayList<Directo | ||||
|         val pinnedFolders = config.pinnedFolders | ||||
|         var pinnedCnt = 0 | ||||
|         var unpinnedCnt = 0 | ||||
|         selectedPositions.mapNotNull { dirs.getOrNull(it)?.path }.forEach { | ||||
|         getSelectedPaths().forEach { | ||||
|             if (pinnedFolders.contains(it)) { | ||||
|                 pinnedCnt++ | ||||
|             } else { | ||||
| @@ -156,10 +149,10 @@ class DirectoryAdapter(activity: BaseSimpleActivity, var dirs: ArrayList<Directo | ||||
|     } | ||||
|  | ||||
|     private fun showProperties() { | ||||
|         if (selectedPositions.size <= 1) { | ||||
|             val path = dirs[selectedPositions.first()].path | ||||
|         if (selectedKeys.size <= 1) { | ||||
|             val path = getFirstSelectedItemPath() ?: return | ||||
|             if (path != FAVORITES && path != RECYCLE_BIN) { | ||||
|                 PropertiesDialog(activity, dirs[selectedPositions.first()].path, config.shouldShowHidden) | ||||
|                 PropertiesDialog(activity, path, config.shouldShowHidden) | ||||
|             } | ||||
|         } else { | ||||
|             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() { | ||||
|         val firstDir = dirs[selectedPositions.first()] | ||||
|         val firstDir = getFirstSelectedItem() ?: return | ||||
|         val sourcePath = firstDir.path | ||||
|         val dir = File(sourcePath) | ||||
|         if (activity.isAStorageRootFolder(dir.absolutePath)) { | ||||
| @@ -283,18 +276,6 @@ class DirectoryAdapter(activity: BaseSimpleActivity, var dirs: ArrayList<Directo | ||||
|                         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() | ||||
|                     dirs = newDirs | ||||
|  | ||||
| @@ -330,9 +311,9 @@ class DirectoryAdapter(activity: BaseSimpleActivity, var dirs: ArrayList<Directo | ||||
|  | ||||
|     private fun pinFolders(pin: Boolean) { | ||||
|         if (pin) { | ||||
|             config.addPinnedFolders(getSelectedPaths()) | ||||
|             config.addPinnedFolders(getSelectedPaths().toHashSet()) | ||||
|         } else { | ||||
|             config.removePinnedFolders(getSelectedPaths()) | ||||
|             config.removePinnedFolders(getSelectedPaths().toHashSet()) | ||||
|         } | ||||
|  | ||||
|         pinnedFolders = config.pinnedFolders | ||||
| @@ -344,12 +325,11 @@ class DirectoryAdapter(activity: BaseSimpleActivity, var dirs: ArrayList<Directo | ||||
|     private fun copyMoveTo(isCopyOperation: Boolean) { | ||||
|         val paths = ArrayList<String>() | ||||
|         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<Directo | ||||
|         if (config.skipDeleteConfirmation) { | ||||
|             deleteFolders() | ||||
|         } else { | ||||
|             val itemsCnt = selectedPositions.size | ||||
|             val itemsCnt = selectedKeys.size | ||||
|             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())) { | ||||
|                 R.string.deletion_confirmation | ||||
|             } else { | ||||
| @@ -397,59 +377,49 @@ class DirectoryAdapter(activity: BaseSimpleActivity, var dirs: ArrayList<Directo | ||||
|     } | ||||
|  | ||||
|     private fun deleteFolders() { | ||||
|         if (selectedPositions.isEmpty()) { | ||||
|         if (selectedKeys.isEmpty()) { | ||||
|             return | ||||
|         } | ||||
|  | ||||
|         val folders = ArrayList<File>(selectedPositions.size) | ||||
|         val removeFolders = ArrayList<Directory>(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<File>(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<Directo | ||||
|         listener?.refreshItems() | ||||
|     } | ||||
|  | ||||
|     private fun getSelectedPaths(): HashSet<String> { | ||||
|         val paths = HashSet<String>(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<Directory> | ||||
|  | ||||
|     private fun getSelectedPaths() = getSelectedItems().map { it.path } as ArrayList<String> | ||||
|  | ||||
|     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<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) { | ||||
|         val isSelected = selectedKeys.contains(directory.path.hashCode()) | ||||
|         view.apply { | ||||
|             dir_name.text = directory.name | ||||
|             dir_path?.text = "${directory.path.substringBeforeLast("/")}/" | ||||
| @@ -528,6 +499,11 @@ class DirectoryAdapter(activity: BaseSimpleActivity, var dirs: ArrayList<Directo | ||||
|                 else -> 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) | ||||
|   | ||||
| @@ -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<FilterItem>, val itemClick: (Int) -> Unit) : RecyclerView.Adapter<FiltersAdapter.ViewHolder>(), | ||||
|         FilterAdapterListener { | ||||
| class FiltersAdapter(val context: Context, val filterItems: ArrayList<FilterItem>, val itemClick: (Int) -> Unit) : RecyclerView.Adapter<FiltersAdapter.ViewHolder>() { | ||||
|  | ||||
|     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<FilterItem | ||||
|         } | ||||
|     } | ||||
|  | ||||
|     class ViewHolder(view: View, val filterAdapterListener: FilterAdapterListener) : RecyclerView.ViewHolder(view) { | ||||
|         fun bindView(filterItem: FilterItem, strokeBackground: Drawable): View { | ||||
|     inner class ViewHolder(view: View) : RecyclerView.ViewHolder(view) { | ||||
|         fun bindView(filterItem: FilterItem): View { | ||||
|             itemView.apply { | ||||
|                 editor_filter_item_label.text = filterItem.filter.name | ||||
|                 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 | ||||
|                 } else { | ||||
|                     null | ||||
|                 } | ||||
|  | ||||
|                 setOnClickListener { | ||||
|                     filterAdapterListener.setCurrentFilter(adapterPosition) | ||||
|                     setCurrentFilter(adapterPosition) | ||||
|                 } | ||||
|             } | ||||
|             return itemView | ||||
|   | ||||
| @@ -25,12 +25,6 @@ class ManageFoldersAdapter(activity: BaseSimpleActivity, var folders: ArrayList< | ||||
|  | ||||
|     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_remove -> 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<String> | ||||
|  | ||||
|     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<String>(selectedPositions.size) | ||||
|         val removeFolders = ArrayList<String>(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() | ||||
|         } | ||||
|   | ||||
| @@ -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<String> | ||||
|  | ||||
|     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<String>(selectedPositions.size) | ||||
|         val removeFolders = ArrayList<String>(selectedKeys.size) | ||||
|  | ||||
|         val sdCardPaths = ArrayList<String>() | ||||
|         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<String>) { | ||||
|         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() | ||||
|         } | ||||
|   | ||||
| @@ -61,14 +61,6 @@ class MediaAdapter(activity: BaseSimpleActivity, var media: MutableList<Thumbnai | ||||
|  | ||||
|     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 { | ||||
|         val layoutType = if (viewType == ITEM_SECTION) { | ||||
|             R.layout.thumbnail_section | ||||
| @@ -89,14 +81,14 @@ class MediaAdapter(activity: BaseSimpleActivity, var media: MutableList<Thumbnai | ||||
|         } | ||||
|  | ||||
|         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) { | ||||
|                 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<Thumbnai | ||||
|  | ||||
|     override fun prepareActionMode(menu: Menu) { | ||||
|         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_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) } | ||||
|  | ||||
|             checkHideBtnVisibility(this) | ||||
| @@ -123,7 +115,7 @@ class MediaAdapter(activity: BaseSimpleActivity, var media: MutableList<Thumbnai | ||||
|     } | ||||
|  | ||||
|     override fun actionItemPressed(id: Int) { | ||||
|         if (selectedPositions.isEmpty()) { | ||||
|         if (selectedKeys.isEmpty()) { | ||||
|             return | ||||
|         } | ||||
|  | ||||
| @@ -141,9 +133,9 @@ class MediaAdapter(activity: BaseSimpleActivity, var media: MutableList<Thumbnai | ||||
|             R.id.cab_copy_to -> 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<Thumbnai | ||||
|  | ||||
|     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) { | ||||
|         super.onViewRecycled(holder) | ||||
|         if (!activity.isActivityDestroyed()) { | ||||
|         if (!activity.isDestroyed) { | ||||
|             val itemView = holder.itemView | ||||
|             visibleItemPaths.remove(itemView?.photo_name?.tag) | ||||
|             val tmb = itemView?.medium_thumbnail | ||||
| @@ -169,7 +165,7 @@ class MediaAdapter(activity: BaseSimpleActivity, var media: MutableList<Thumbnai | ||||
|     private fun checkHideBtnVisibility(menu: Menu) { | ||||
|         var hiddenCnt = 0 | ||||
|         var unhiddenCnt = 0 | ||||
|         getSelectedMedia().forEach { | ||||
|         getSelectedItems().forEach { | ||||
|             if (it.isHidden()) { | ||||
|                 hiddenCnt++ | ||||
|             } 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_unhide).isVisible = hiddenCnt > 0 && !isInRecycleBin | ||||
|     } | ||||
| @@ -185,7 +181,7 @@ class MediaAdapter(activity: BaseSimpleActivity, var media: MutableList<Thumbnai | ||||
|     private fun checkFavoriteBtnVisibility(menu: Menu) { | ||||
|         var favoriteCnt = 0 | ||||
|         var nonFavoriteCnt = 0 | ||||
|         getSelectedMedia().forEach { | ||||
|         getSelectedItems().forEach { | ||||
|             if (it.isFavorite) { | ||||
|                 favoriteCnt++ | ||||
|             } else { | ||||
| @@ -202,8 +198,9 @@ class MediaAdapter(activity: BaseSimpleActivity, var media: MutableList<Thumbnai | ||||
|     } | ||||
|  | ||||
|     private fun showProperties() { | ||||
|         if (selectedPositions.size <= 1) { | ||||
|             PropertiesDialog(activity, (media[selectedPositions.first()] as Medium).path, config.shouldShowHidden) | ||||
|         if (selectedKeys.size <= 1) { | ||||
|             val path = getFirstSelectedItemPath() ?: return | ||||
|             PropertiesDialog(activity, path, config.shouldShowHidden) | ||||
|         } else { | ||||
|             val paths = getSelectedPaths() | ||||
|             PropertiesDialog(activity, paths, config.shouldShowHidden) | ||||
| @@ -211,7 +208,7 @@ class MediaAdapter(activity: BaseSimpleActivity, var media: MutableList<Thumbnai | ||||
|     } | ||||
|  | ||||
|     private fun renameFile() { | ||||
|         val oldPath = getCurrentPath() | ||||
|         val oldPath = getFirstSelectedItemPath() ?: return | ||||
|         RenameItemDialog(activity, oldPath) { | ||||
|             Thread { | ||||
|                 activity.updateDBMediaPath(oldPath, it) | ||||
| @@ -226,12 +223,23 @@ class MediaAdapter(activity: BaseSimpleActivity, var media: MutableList<Thumbnai | ||||
|     } | ||||
|  | ||||
|     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) { | ||||
|         Thread { | ||||
|             getSelectedMedia().forEach { | ||||
|             getSelectedItems().forEach { | ||||
|                 activity.toggleFileVisibility(it.path, hide) | ||||
|             } | ||||
|             activity.runOnUiThread { | ||||
| @@ -244,7 +252,7 @@ class MediaAdapter(activity: BaseSimpleActivity, var media: MutableList<Thumbnai | ||||
|     private fun toggleFavorites(add: Boolean) { | ||||
|         Thread { | ||||
|             val mediumDao = activity.galleryDB.MediumDao() | ||||
|             getSelectedMedia().forEach { | ||||
|             getSelectedItems().forEach { | ||||
|                 it.isFavorite = add | ||||
|                 mediumDao.updateFavorite(it.path, add) | ||||
|             } | ||||
| @@ -263,9 +271,9 @@ class MediaAdapter(activity: BaseSimpleActivity, var media: MutableList<Thumbnai | ||||
|     } | ||||
|  | ||||
|     private fun shareMedia() { | ||||
|         if (selectedPositions.size == 1 && selectedPositions.first() != -1) { | ||||
|             activity.shareMediumPath(getSelectedMedia().first().path) | ||||
|         } else if (selectedPositions.size > 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<Thumbnai | ||||
|     } | ||||
|  | ||||
|     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 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) | ||||
| @@ -355,48 +363,35 @@ class MediaAdapter(activity: BaseSimpleActivity, var media: MutableList<Thumbnai | ||||
|         } | ||||
|     } | ||||
|  | ||||
|     private fun getCurrentPath() = (media[selectedPositions.first()] as Medium).path | ||||
|  | ||||
|     private fun deleteFiles() { | ||||
|         if (selectedPositions.isEmpty()) { | ||||
|         if (selectedKeys.isEmpty()) { | ||||
|             return | ||||
|         } | ||||
|  | ||||
|         val fileDirItems = ArrayList<FileDirItem>(selectedPositions.size) | ||||
|         val removeMedia = ArrayList<Medium>(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<FileDirItem>(selectedKeys.size) | ||||
|             val removeMedia = ArrayList<Medium>(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<Medium> { | ||||
|         val selectedMedia = ArrayList<Medium>(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<Medium> | ||||
|  | ||||
|     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>) { | ||||
|         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) | ||||
|  | ||||
|     private fun setupThumbnail(view: View, medium: Medium) { | ||||
|         val isSelected = selectedKeys.contains(medium.path.hashCode()) | ||||
|         view.apply { | ||||
|             play_outline.beVisibleIf(medium.isVideo()) | ||||
|             photo_name.beVisibleIf(displayFilenames || isListViewType) | ||||
|             photo_name.text = medium.name | ||||
|             photo_name.tag = medium.path | ||||
|  | ||||
|             medium_check?.beVisibleIf(isSelected) | ||||
|             if (isSelected) { | ||||
|                 medium_check?.background?.applyColorFilter(primaryColor) | ||||
|             } | ||||
|  | ||||
|             var path = medium.path | ||||
|             if (hasOTGConnected && path.startsWith(OTG_PATH)) { | ||||
|                 path = path.getOTGPublicPath(context) | ||||
|   | ||||
| @@ -2,11 +2,11 @@ package com.simplemobiletools.gallery.adapters | ||||
|  | ||||
| import android.os.Bundle | ||||
| import android.os.Parcelable | ||||
| import android.view.ViewGroup | ||||
| import androidx.fragment.app.Fragment | ||||
| import androidx.fragment.app.FragmentManager | ||||
| import androidx.fragment.app.FragmentStatePagerAdapter | ||||
| import androidx.viewpager.widget.PagerAdapter | ||||
| import android.view.ViewGroup | ||||
| import com.simplemobiletools.gallery.activities.ViewPagerActivity | ||||
| import com.simplemobiletools.gallery.fragments.PhotoFragment | ||||
| import com.simplemobiletools.gallery.fragments.VideoFragment | ||||
|   | ||||
| @@ -3,8 +3,8 @@ package com.simplemobiletools.gallery.extensions | ||||
| import android.app.Activity | ||||
| import android.content.Intent | ||||
| import android.provider.MediaStore | ||||
| import androidx.appcompat.app.AppCompatActivity | ||||
| import android.view.View | ||||
| import androidx.appcompat.app.AppCompatActivity | ||||
| import com.simplemobiletools.commons.activities.BaseSimpleActivity | ||||
| import com.simplemobiletools.commons.dialogs.ConfirmationDialog | ||||
| import com.simplemobiletools.commons.extensions.* | ||||
| @@ -60,8 +60,8 @@ fun Activity.launchCamera() { | ||||
| } | ||||
|  | ||||
| fun SimpleActivity.launchAbout() { | ||||
|     val licenses = LICENSE_GLIDE or LICENSE_CROPPER or LICENSE_MULTISELECT or LICENSE_RTL or LICENSE_SUBSAMPLING or LICENSE_PATTERN 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 | ||||
|     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_PHOTOVIEW or LICENSE_PICASSO or LICENSE_EXOPLAYER or LICENSE_PANORAMA_VIEW or LICENSE_SANSELAN or LICENSE_FILTERS | ||||
|  | ||||
|     val faqItems = arrayListOf( | ||||
|             FAQItem(R.string.faq_5_title_commons, R.string.faq_5_text_commons), | ||||
|   | ||||
| @@ -8,7 +8,6 @@ import android.database.sqlite.SQLiteException | ||||
| import android.graphics.Point | ||||
| import android.graphics.drawable.PictureDrawable | ||||
| import android.media.AudioManager | ||||
| import android.os.Build | ||||
| import android.provider.MediaStore | ||||
| import android.view.WindowManager | ||||
| import android.widget.ImageView | ||||
| @@ -88,8 +87,7 @@ val Context.usableScreenSize: Point | ||||
| val Context.realScreenSize: Point | ||||
|     get() { | ||||
|         val size = Point() | ||||
|         if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) | ||||
|             windowManager.defaultDisplay.getRealSize(size) | ||||
|         windowManager.defaultDisplay.getRealSize(size) | ||||
|         return size | ||||
|     } | ||||
|  | ||||
|   | ||||
| @@ -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) | ||||
|   | ||||
| @@ -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() | ||||
|  | ||||
|   | ||||
| @@ -1,9 +0,0 @@ | ||||
| package com.simplemobiletools.gallery.interfaces | ||||
|  | ||||
| import com.simplemobiletools.gallery.models.FilterItem | ||||
|  | ||||
| interface FilterAdapterListener { | ||||
|     fun getCurrentFilter(): FilterItem | ||||
|  | ||||
|     fun setCurrentFilter(position: Int) | ||||
| } | ||||
| @@ -1,7 +0,0 @@ | ||||
| <resources> | ||||
|  | ||||
|     <style name="FullScreenTheme" parent="AppTheme.Base"> | ||||
|         <item name="android:windowTranslucentNavigation">true</item> | ||||
|     </style> | ||||
|  | ||||
| </resources> | ||||
| @@ -4,6 +4,7 @@ | ||||
|  | ||||
|     <style name="FullScreenTheme.Base" parent="AppTheme"> | ||||
|         <item name="android:windowContentOverlay">@null</item> | ||||
|         <item name="android:windowTranslucentNavigation">true</item> | ||||
|     </style> | ||||
|  | ||||
|     <style name="FullScreenTheme" parent="FullScreenTheme.Base"/> | ||||
|   | ||||
| @@ -9,7 +9,7 @@ buildscript { | ||||
|     } | ||||
|  | ||||
|     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" | ||||
|  | ||||
|         // NOTE: Do not place your application dependencies here; they belong | ||||
|   | ||||
		Reference in New Issue
	
	Block a user