diff --git a/app/build.gradle b/app/build.gradle index 4cf89342f..b076fd8a1 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -47,10 +47,9 @@ ext { } dependencies { - compile 'com.simplemobiletools:commons:2.38.9' + compile 'com.simplemobiletools:commons:2.39.7' compile 'com.davemorrissey.labs:subsampling-scale-image-view:3.7.2' compile 'com.theartofdev.edmodo:android-image-cropper:2.4.0' - compile 'com.bignerdranch.android:recyclerview-multiselect:0.2' compile 'com.android.support:multidex:1.0.2' compile 'com.google.code.gson:gson:2.8.2' compile 'it.sephiroth.android.exif:library:1.0.1' 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 bf1dfe512..e2884e12e 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MainActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MainActivity.kt @@ -4,7 +4,6 @@ import android.app.Activity import android.content.ClipData import android.content.Intent import android.net.Uri -import android.os.Build import android.os.Bundle import android.os.Handler import android.provider.MediaStore @@ -23,7 +22,7 @@ import com.simplemobiletools.commons.helpers.SORT_BY_DATE_MODIFIED import com.simplemobiletools.commons.helpers.SORT_BY_DATE_TAKEN import com.simplemobiletools.commons.models.RadioItem import com.simplemobiletools.commons.models.Release -import com.simplemobiletools.commons.views.MyScalableRecyclerView +import com.simplemobiletools.commons.views.MyRecyclerView import com.simplemobiletools.gallery.BuildConfig import com.simplemobiletools.gallery.R import com.simplemobiletools.gallery.adapters.DirectoryAdapter @@ -64,6 +63,7 @@ class MainActivity : SimpleActivity(), DirectoryAdapter.DirOperationsListener { private var mLatestMediaId = 0L private var mLastMediaHandler = Handler() private var mCurrAsyncTask: GetDirectoriesAsynctask? = null + private var mZoomListener: MyRecyclerView.MyZoomListener? = null override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) @@ -178,7 +178,6 @@ class MainActivity : SimpleActivity(), DirectoryAdapter.DirOperationsListener { directories_refresh_layout.isRefreshing = false mIsGettingDirs = false storeStateVariables() - directories_grid.listener = null mLastMediaHandler.removeCallbacksAndMessages(null) if (!mDirs.isEmpty()) { @@ -341,6 +340,8 @@ class MainActivity : SimpleActivity(), DirectoryAdapter.DirOperationsListener { } else { setupListLayoutManager() } + getDirectoryAdapter()?.setupZoomListener(mZoomListener) + getDirectoryAdapter()?.setupDragListener(true) } private fun setupGridLayoutManager() { @@ -353,42 +354,30 @@ class MainActivity : SimpleActivity(), DirectoryAdapter.DirOperationsListener { directories_refresh_layout.layoutParams = FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT) } - directories_grid.isDragSelectionEnabled = true - directories_grid.isZoomingEnabled = true layoutManager.spanCount = config.dirColumnCnt - directories_grid.listener = object : MyScalableRecyclerView.MyScalableRecyclerViewListener { + mZoomListener = object : MyRecyclerView.MyZoomListener { override fun zoomIn() { if (layoutManager.spanCount > 1) { reduceColumnCount() - getRecyclerAdapter().actMode?.finish() + getRecyclerAdapter().finishActMode() } } override fun zoomOut() { if (layoutManager.spanCount < MAX_COLUMN_COUNT) { increaseColumnCount() - getRecyclerAdapter().actMode?.finish() + getRecyclerAdapter().finishActMode() } } - - override fun selectItem(position: Int) { - getRecyclerAdapter().selectItem(position) - } - - override fun selectRange(initialSelection: Int, lastDraggedIndex: Int, minReached: Int, maxReached: Int) { - getRecyclerAdapter().selectRange(initialSelection, lastDraggedIndex, minReached, maxReached) - } } } private fun setupListLayoutManager() { - directories_grid.isDragSelectionEnabled = true - directories_grid.isZoomingEnabled = false - val layoutManager = directories_grid.layoutManager as GridLayoutManager layoutManager.spanCount = 1 layoutManager.orientation = GridLayoutManager.VERTICAL directories_refresh_layout.layoutParams = FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT) + mZoomListener = null } private fun createNewFolder() { @@ -560,8 +549,8 @@ class MainActivity : SimpleActivity(), DirectoryAdapter.DirOperationsListener { private fun setupAdapter() { val currAdapter = directories_grid.adapter if (currAdapter == null) { - directories_grid.adapter = DirectoryAdapter(this, mDirs, this, isPickIntent(intent) || isGetAnyContentIntent(intent)) { - itemClicked(it.path) + directories_grid.adapter = DirectoryAdapter(this, mDirs, this, directories_grid, isPickIntent(intent) || isGetAnyContentIntent(intent)) { + itemClicked((it as Directory).path) } } else { (currAdapter as DirectoryAdapter).updateDirs(mDirs) @@ -587,7 +576,7 @@ class MainActivity : SimpleActivity(), DirectoryAdapter.DirOperationsListener { } private fun checkLastMediaChanged() { - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1 && isDestroyed) + if (isActivityDestroyed()) return mLastMediaHandler.removeCallbacksAndMessages(null) @@ -610,10 +599,6 @@ class MainActivity : SimpleActivity(), DirectoryAdapter.DirOperationsListener { getDirectories() } - override fun itemLongClicked(position: Int) { - directories_grid.setDragSelectActive(position) - } - override fun recheckPinnedFolders() { gotDirectories(movePinnedDirectoriesToFront(mDirs), true) } 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 c26f78104..076541e2b 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MediaActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MediaActivity.kt @@ -5,7 +5,6 @@ import android.app.WallpaperManager import android.content.Intent import android.graphics.Bitmap import android.net.Uri -import android.os.Build import android.os.Bundle import android.os.Handler import android.support.v7.widget.GridLayoutManager @@ -24,7 +23,6 @@ import com.simplemobiletools.commons.extensions.* import com.simplemobiletools.commons.helpers.PERMISSION_WRITE_STORAGE import com.simplemobiletools.commons.helpers.REQUEST_EDIT_IMAGE import com.simplemobiletools.commons.models.RadioItem -import com.simplemobiletools.commons.views.MyScalableRecyclerView import com.simplemobiletools.gallery.R import com.simplemobiletools.gallery.adapters.MediaAdapter import com.simplemobiletools.gallery.asynctasks.GetMediaAsynctask @@ -120,7 +118,6 @@ class MediaActivity : SimpleActivity(), MediaAdapter.MediaOperationsListener { mIsGettingMedia = false media_refresh_layout.isRefreshing = false storeStateVariables() - media_grid.listener = null mLastMediaHandler.removeCallbacksAndMessages(null) if (!mMedia.isEmpty()) { @@ -204,7 +201,7 @@ class MediaActivity : SimpleActivity(), MediaAdapter.MediaOperationsListener { } private fun checkLastMediaChanged() { - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1 && isDestroyed) + if (isActivityDestroyed()) return mLastMediaHandler.removeCallbacksAndMessages(null) @@ -414,7 +411,7 @@ class MediaActivity : SimpleActivity(), MediaAdapter.MediaOperationsListener { media_refresh_layout.layoutParams = FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT) } - media_grid.isDragSelectionEnabled = true + /*media_grid.isDragSelectionEnabled = true media_grid.isZoomingEnabled = true layoutManager.spanCount = config.mediaColumnCnt media_grid.listener = object : MyScalableRecyclerView.MyScalableRecyclerViewListener { @@ -439,12 +436,12 @@ class MediaActivity : SimpleActivity(), MediaAdapter.MediaOperationsListener { override fun selectRange(initialSelection: Int, lastDraggedIndex: Int, minReached: Int, maxReached: Int) { getRecyclerAdapter().selectRange(initialSelection, lastDraggedIndex, minReached, maxReached) } - } + }*/ } private fun setupListLayoutManager() { - media_grid.isDragSelectionEnabled = true - media_grid.isZoomingEnabled = false + //media_grid.isDragSelectionEnabled = true + //media_grid.isZoomingEnabled = false val layoutManager = media_grid.layoutManager as GridLayoutManager layoutManager.spanCount = 1 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 ec823353c..07a493239 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/SetWallpaperActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/SetWallpaperActivity.kt @@ -5,10 +5,10 @@ import android.app.WallpaperManager import android.content.Intent import android.graphics.Bitmap import android.net.Uri -import android.os.Build import android.os.Bundle import android.view.Menu import android.view.MenuItem +import com.simplemobiletools.commons.extensions.isActivityDestroyed import com.simplemobiletools.commons.extensions.toast import com.simplemobiletools.gallery.R import com.theartofdev.edmodo.cropper.CropImageView @@ -86,7 +86,7 @@ class SetWallpaperActivity : SimpleActivity(), CropImageView.OnCropImageComplete } override fun onCropImageComplete(view: CropImageView?, result: CropImageView.CropResult) { - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1 && isDestroyed) + if (isActivityDestroyed()) return if (result.error == null) { diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/SimpleActivity.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/SimpleActivity.kt index f30d65e31..42e8828dc 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/SimpleActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/SimpleActivity.kt @@ -1,36 +1,5 @@ package com.simplemobiletools.gallery.activities import com.simplemobiletools.commons.activities.BaseSimpleActivity -import com.simplemobiletools.commons.extensions.getFilenameFromPath -import com.simplemobiletools.commons.extensions.toast -import com.simplemobiletools.gallery.R -import com.simplemobiletools.gallery.dialogs.PickDirectoryDialog -import com.simplemobiletools.gallery.extensions.config -import com.simplemobiletools.gallery.models.Directory -import java.io.File -import java.util.* -open class SimpleActivity : BaseSimpleActivity() { - fun tryCopyMoveFilesTo(files: ArrayList, isCopyOperation: Boolean, callback: () -> Unit) { - if (files.isEmpty()) { - toast(R.string.unknown_error_occurred) - return - } - - val source = if (files[0].isFile) files[0].parent else files[0].absolutePath - PickDirectoryDialog(this, source) { - copyMoveFilesTo(files, source.trimEnd('/'), it, isCopyOperation, true, callback) - } - } - - fun addTempFolderIfNeeded(dirs: ArrayList): ArrayList { - val directories = ArrayList() - val tempFolderPath = config.tempFolderPath - if (tempFolderPath.isNotEmpty()) { - val newFolder = Directory(tempFolderPath, "", tempFolderPath.getFilenameFromPath(), 0, 0, 0, 0L) - directories.add(newFolder) - } - directories.addAll(dirs) - return directories - } -} +open class SimpleActivity : BaseSimpleActivity() 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 595e76c55..936a06623 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/ViewPagerActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/ViewPagerActivity.kt @@ -186,7 +186,7 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View title = mPath.getFilenameFromPath() view_pager.onGlobalLayout { - if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN_MR1 || !isDestroyed) { + if (!isActivityDestroyed()) { if (mMedia.isNotEmpty()) { gotMedia(mMedia) } @@ -304,7 +304,7 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View private fun updatePagerItems(media: MutableList) { val pagerAdapter = MyPagerAdapter(this, supportFragmentManager, media) - if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN_MR1 || !isDestroyed) { + if (!isActivityDestroyed()) { view_pager.apply { adapter = pagerAdapter currentItem = mPos @@ -322,7 +322,7 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View private fun startSlideshow() { if (getMediaForSlideshow()) { view_pager.onGlobalLayout { - if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN_MR1 || !isDestroyed) { + if (!isActivityDestroyed()) { hideSystemUI() mSlideshowInterval = config.slideshowInterval mSlideshowMoveBackwards = config.slideshowMoveBackwards @@ -402,7 +402,7 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View if (mIsSlideshowActive) { if (getCurrentMedium()!!.isImage() || getCurrentMedium()!!.isGif()) { mSlideshowHandler.postDelayed({ - if (mIsSlideshowActive && Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1 && !isDestroyed) { + if (mIsSlideshowActive && !isActivityDestroyed()) { swipeToNextMedium() } }, mSlideshowInterval * 1000L) 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 a4f057409..8042ff84f 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/adapters/DirectoryAdapter.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/adapters/DirectoryAdapter.kt @@ -1,23 +1,20 @@ package com.simplemobiletools.gallery.adapters import android.graphics.PorterDuff -import android.os.Build -import android.support.v7.view.ActionMode -import android.support.v7.widget.RecyclerView import android.util.SparseArray -import android.view.* -import com.bignerdranch.android.multiselector.ModalMultiSelectorCallback -import com.bignerdranch.android.multiselector.MultiSelector -import com.bignerdranch.android.multiselector.SwappingHolder +import android.view.Menu +import android.view.View +import android.view.ViewGroup import com.bumptech.glide.Glide import com.google.gson.Gson +import com.simplemobiletools.commons.activities.BaseSimpleActivity +import com.simplemobiletools.commons.adapters.MyRecyclerViewAdapter import com.simplemobiletools.commons.dialogs.ConfirmationDialog import com.simplemobiletools.commons.dialogs.PropertiesDialog import com.simplemobiletools.commons.dialogs.RenameItemDialog import com.simplemobiletools.commons.extensions.* -import com.simplemobiletools.commons.interfaces.MyAdapterListener +import com.simplemobiletools.commons.views.MyRecyclerView import com.simplemobiletools.gallery.R -import com.simplemobiletools.gallery.activities.SimpleActivity import com.simplemobiletools.gallery.dialogs.ExcludeFolderDialog import com.simplemobiletools.gallery.dialogs.PickMediumDialog import com.simplemobiletools.gallery.extensions.* @@ -28,134 +25,104 @@ import kotlinx.android.synthetic.main.directory_item_list.view.* import java.io.File import java.util.* -class DirectoryAdapter(val activity: SimpleActivity, var dirs: MutableList, val listener: DirOperationsListener?, val isPickIntent: Boolean, - val itemClick: (Directory) -> Unit) : RecyclerView.Adapter() { +class DirectoryAdapter(activity: BaseSimpleActivity, var dirs: MutableList, val listener: DirOperationsListener?, recyclerView: MyRecyclerView, + val isPickIntent: Boolean, itemClick: (Any) -> Unit) : MyRecyclerViewAdapter(activity, recyclerView, itemClick) { private val config = activity.config - var actMode: ActionMode? = null - var primaryColor = config.primaryColor - - private val multiSelector = MultiSelector() private val isListViewType = config.viewTypeFolders == VIEW_TYPE_LIST - private var itemViews = SparseArray() - private val selectedPositions = HashSet() - private var textColor = config.textColor private var pinnedFolders = config.pinnedFolders private var scrollHorizontally = config.scrollHorizontally private var showMediaCount = config.showMediaCount private var animateGifs = config.animateGifs private var cropThumbnails = config.cropThumbnails - fun toggleItemSelection(select: Boolean, pos: Int) { - if (select) { - if (itemViews[pos] != null) { - itemViews[pos].dir_check?.background?.applyColorFilter(primaryColor) - selectedPositions.add(pos) - } - } else { - selectedPositions.remove(pos) - } - - itemViews[pos]?.dir_check?.beVisibleIf(select) - - if (selectedPositions.isEmpty()) { - actMode?.finish() - return - } - - updateTitle(selectedPositions.size) + init { + selectableItemCount = dirs.count() } - private fun updateTitle(cnt: Int) { - actMode?.title = "$cnt / ${dirs.size}" - actMode?.invalidate() + override fun getActionMenuId() = R.menu.cab_directories + + override fun prepareItemSelection(view: View) { + view.dir_check?.background?.applyColorFilter(primaryColor) } - private val adapterListener = object : MyAdapterListener { - override fun toggleItemSelectionAdapter(select: Boolean, position: Int) { - toggleItemSelection(select, position) - } - - override fun getSelectedPositions(): HashSet = selectedPositions + override fun markItemSelection(select: Boolean, view: View?) { + view?.dir_check?.beVisibleIf(select) } - private val multiSelectorMode = object : ModalMultiSelectorCallback(multiSelector) { - override fun onActionItemClicked(mode: ActionMode, item: MenuItem): Boolean { - when (item.itemId) { - R.id.cab_properties -> showProperties() - R.id.cab_rename -> renameDir() - R.id.cab_pin -> pinFolders(true) - R.id.cab_unpin -> pinFolders(false) - R.id.cab_hide -> toggleFoldersVisibility(true) - R.id.cab_unhide -> toggleFoldersVisibility(false) - R.id.cab_exclude -> tryExcludeFolder() - R.id.cab_copy_to -> copyMoveTo(true) - R.id.cab_move_to -> copyMoveTo(false) - R.id.cab_select_all -> selectAll() - R.id.cab_delete -> askConfirmDelete() - R.id.cab_select_photo -> changeAlbumCover(false) - R.id.cab_use_default -> changeAlbumCover(true) - else -> return false + override fun onCreateViewHolder(parent: ViewGroup?, viewType: Int): ViewHolder { + val layoutType = if (isListViewType) R.layout.directory_item_list else R.layout.directory_item_grid + val view = activity.layoutInflater.inflate(layoutType, parent, false) + return createViewHolder(view) + } + + override fun onBindViewHolder(holder: MyRecyclerViewAdapter.ViewHolder, position: Int) { + val dir = dirs[position] + val view = holder.bindView(dir, isPickIntent) { + setupView(it, dir) + } + itemViews.put(position, view) + toggleItemSelection(selectedPositions.contains(position), position) + holder.itemView.tag = holder + } + + override fun getItemCount() = dirs.size + + override fun actionItemPressed(id: Int) { + when (id) { + R.id.cab_properties -> showProperties() + R.id.cab_rename -> renameDir() + R.id.cab_pin -> pinFolders(true) + R.id.cab_unpin -> pinFolders(false) + R.id.cab_hide -> toggleFoldersVisibility(true) + R.id.cab_unhide -> toggleFoldersVisibility(false) + R.id.cab_exclude -> tryExcludeFolder() + R.id.cab_copy_to -> copyMoveTo(true) + R.id.cab_move_to -> copyMoveTo(false) + R.id.cab_select_all -> selectAll() + R.id.cab_delete -> askConfirmDelete() + R.id.cab_select_photo -> changeAlbumCover(false) + R.id.cab_use_default -> changeAlbumCover(true) + } + } + + override fun prepareActionMode(menu: Menu) { + menu.findItem(R.id.cab_rename).isVisible = selectedPositions.size == 1 + menu.findItem(R.id.cab_change_cover_image).isVisible = selectedPositions.size == 1 + + checkHideBtnVisibility(menu) + checkPinBtnVisibility(menu) + } + + private fun checkHideBtnVisibility(menu: Menu) { + var hiddenCnt = 0 + var unhiddenCnt = 0 + selectedPositions.mapNotNull { dirs.getOrNull(it)?.path }.forEach { + if (File(it).containsNoMedia()) { + hiddenCnt++ + } else { + unhiddenCnt++ } - return true } - override fun onCreateActionMode(actionMode: ActionMode?, menu: Menu): Boolean { - super.onCreateActionMode(actionMode, menu) - actMode = actionMode - activity.menuInflater.inflate(R.menu.cab_directories, menu) - return true - } + menu.findItem(R.id.cab_hide).isVisible = unhiddenCnt > 0 + menu.findItem(R.id.cab_unhide).isVisible = hiddenCnt > 0 + } - override fun onPrepareActionMode(actionMode: ActionMode?, menu: Menu): Boolean { - menu.findItem(R.id.cab_rename).isVisible = selectedPositions.size == 1 - menu.findItem(R.id.cab_change_cover_image).isVisible = selectedPositions.size == 1 - - checkHideBtnVisibility(menu) - checkPinBtnVisibility(menu) - - return true - } - - override fun onDestroyActionMode(actionMode: ActionMode?) { - super.onDestroyActionMode(actionMode) - selectedPositions.forEach { - itemViews[it]?.dir_check?.beGone() + private fun checkPinBtnVisibility(menu: Menu) { + val pinnedFolders = config.pinnedFolders + var pinnedCnt = 0 + var unpinnedCnt = 0 + selectedPositions.mapNotNull { dirs.getOrNull(it)?.path }.forEach { + if (pinnedFolders.contains(it)) { + pinnedCnt++ + } else { + unpinnedCnt++ } - selectedPositions.clear() - actMode = null } - fun checkHideBtnVisibility(menu: Menu) { - var hiddenCnt = 0 - var unhiddenCnt = 0 - selectedPositions.mapNotNull { dirs.getOrNull(it)?.path }.forEach { - if (File(it).containsNoMedia()) { - hiddenCnt++ - } else { - unhiddenCnt++ - } - } - - menu.findItem(R.id.cab_hide).isVisible = unhiddenCnt > 0 - menu.findItem(R.id.cab_unhide).isVisible = hiddenCnt > 0 - } - - fun checkPinBtnVisibility(menu: Menu) { - val pinnedFolders = config.pinnedFolders - var pinnedCnt = 0 - var unpinnedCnt = 0 - selectedPositions.mapNotNull { dirs.getOrNull(it)?.path }.forEach { - if (pinnedFolders.contains(it)) { - pinnedCnt++ - } else { - unpinnedCnt++ - } - } - - menu.findItem(R.id.cab_pin).isVisible = unpinnedCnt > 0 - menu.findItem(R.id.cab_unpin).isVisible = pinnedCnt > 0 - } + menu.findItem(R.id.cab_pin).isVisible = unpinnedCnt > 0 + menu.findItem(R.id.cab_unpin).isVisible = pinnedCnt > 0 } private fun showProperties() { @@ -179,7 +146,7 @@ class DirectoryAdapter(val activity: SimpleActivity, var dirs: MutableList newItems.put(curIndex, itemViews[i]) } itemViews = newItems - actMode?.finish() + selectableItemCount = dirs.size + finishActMode() } } @@ -338,7 +297,7 @@ class DirectoryAdapter(val activity: SimpleActivity, var dirs: MutableList) { activity.config.albumCovers = Gson().toJson(albumCovers) - actMode?.finish() + finishActMode() listener?.refreshItems() } @@ -348,30 +307,18 @@ class DirectoryAdapter(val activity: SimpleActivity, var dirs: MutableList) { dirs = newDirs + selectableItemCount = dirs.size notifyDataSetChanged() - actMode?.finish() + finishActMode() } fun updateAnimateGifs(animateGifs: Boolean) { @@ -394,101 +341,23 @@ class DirectoryAdapter(val activity: SimpleActivity, var dirs: MutableList -1 && min < to) { - (min until to).filter { it != from } - .forEach { toggleItemSelection(false, it) } + if (isListViewType) { + dir_name.setTextColor(textColor) + dir_path.setTextColor(textColor) + photo_cnt.setTextColor(textColor) + dir_pin.setColorFilter(textColor, PorterDuff.Mode.SRC_IN) + dir_sd_card.setColorFilter(textColor, PorterDuff.Mode.SRC_IN) } - if (max > -1) { - for (i in from + 1..max) - toggleItemSelection(false, i) - } - } else { - for (i in from..to) - toggleItemSelection(true, i) - - if (max > -1 && max > to) { - (to + 1..max).filter { it != from } - .forEach { toggleItemSelection(false, it) } - } - - if (min > -1) { - for (i in min until from) - toggleItemSelection(false, i) - } - } - } - - class ViewHolder(val view: View, val adapterListener: MyAdapterListener, val activity: SimpleActivity, val multiSelectorCallback: ModalMultiSelectorCallback, - val multiSelector: MultiSelector, val listener: DirOperationsListener?, val isPickIntent: Boolean, val itemClick: (Directory) -> (Unit)) : - SwappingHolder(view, MultiSelector()) { - fun bindView(directory: Directory, isPinned: Boolean, scrollHorizontally: Boolean, isListView: Boolean, textColor: Int, showMediaCount: Boolean, - animateGifs: Boolean, cropThumbnails: Boolean): View { - itemView.apply { - dir_name.text = directory.name - dir_path?.text = "${directory.path.substringBeforeLast("/")}/" - photo_cnt.text = directory.mediaCnt.toString() - activity.loadImage(directory.tmb, dir_thumbnail, scrollHorizontally, animateGifs, cropThumbnails) - dir_pin.beVisibleIf(isPinned) - dir_sd_card.beVisibleIf(activity.isPathOnSD(directory.path)) - photo_cnt.beVisibleIf(showMediaCount) - - if (isListView) { - dir_name.setTextColor(textColor) - dir_path.setTextColor(textColor) - photo_cnt.setTextColor(textColor) - dir_pin.setColorFilter(textColor, PorterDuff.Mode.SRC_IN) - dir_sd_card.setColorFilter(textColor, PorterDuff.Mode.SRC_IN) - } - - setOnClickListener { viewClicked(directory) } - setOnLongClickListener { if (isPickIntent) viewClicked(directory) else viewLongClicked(); true } - } - return itemView - } - - private fun viewClicked(directory: Directory) { - if (multiSelector.isSelectable) { - val isSelected = adapterListener.getSelectedPositions().contains(adapterPosition) - adapterListener.toggleItemSelectionAdapter(!isSelected, adapterPosition) - } else { - itemClick(directory) - } - } - - private fun viewLongClicked() { - if (listener != null) { - if (!multiSelector.isSelectable) { - activity.startSupportActionMode(multiSelectorCallback) - adapterListener.toggleItemSelectionAdapter(true, adapterPosition) - } - - listener.itemLongClicked(adapterPosition) - } - } - - fun stopLoad() { - if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN_MR1 || !activity.isDestroyed) - Glide.with(activity).clear(view.dir_thumbnail) } } @@ -497,8 +366,6 @@ class DirectoryAdapter(val activity: SimpleActivity, var dirs: MutableList) - fun itemLongClicked(position: Int) - fun recheckPinnedFolders() } } 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 64b20fc49..097134681 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/adapters/MediaAdapter.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/adapters/MediaAdapter.kt @@ -2,7 +2,6 @@ package com.simplemobiletools.gallery.adapters import android.graphics.PorterDuff import android.net.Uri -import android.os.Build import android.support.v7.view.ActionMode import android.support.v7.widget.RecyclerView import android.util.SparseArray @@ -11,14 +10,15 @@ import com.bignerdranch.android.multiselector.ModalMultiSelectorCallback import com.bignerdranch.android.multiselector.MultiSelector import com.bignerdranch.android.multiselector.SwappingHolder import com.bumptech.glide.Glide +import com.simplemobiletools.commons.activities.BaseSimpleActivity import com.simplemobiletools.commons.dialogs.PropertiesDialog import com.simplemobiletools.commons.dialogs.RenameItemDialog import com.simplemobiletools.commons.extensions.applyColorFilter import com.simplemobiletools.commons.extensions.beGone import com.simplemobiletools.commons.extensions.beVisibleIf +import com.simplemobiletools.commons.extensions.isActivityDestroyed import com.simplemobiletools.commons.interfaces.MyAdapterListener import com.simplemobiletools.gallery.R -import com.simplemobiletools.gallery.activities.SimpleActivity import com.simplemobiletools.gallery.dialogs.DeleteWithRememberDialog import com.simplemobiletools.gallery.extensions.* import com.simplemobiletools.gallery.helpers.VIEW_TYPE_LIST @@ -27,7 +27,7 @@ import kotlinx.android.synthetic.main.photo_video_item_grid.view.* import java.io.File import java.util.* -class MediaAdapter(val activity: SimpleActivity, var media: MutableList, val listener: MediaOperationsListener?, val isAGetIntent: Boolean, +class MediaAdapter(val activity: BaseSimpleActivity, var media: MutableList, val listener: MediaOperationsListener?, val isAGetIntent: Boolean, val allowMultiplePicks: Boolean, val itemClick: (Medium) -> Unit) : RecyclerView.Adapter() { private val config = activity.config @@ -77,6 +77,8 @@ class MediaAdapter(val activity: SimpleActivity, var media: MutableList, } override fun getSelectedPositions(): HashSet = selectedPositions + + override fun itemLongClicked(position: Int) {} } private val multiSelectorMode = object : ModalMultiSelectorCallback(multiSelector) { @@ -366,7 +368,7 @@ class MediaAdapter(val activity: SimpleActivity, var media: MutableList, } } - class ViewHolder(val view: View, val adapterListener: MyAdapterListener, val activity: SimpleActivity, val multiSelectorCallback: ModalMultiSelectorCallback, + class ViewHolder(val view: View, val adapterListener: MyAdapterListener, val activity: BaseSimpleActivity, val multiSelectorCallback: ModalMultiSelectorCallback, val multiSelector: MultiSelector, val listener: MediaOperationsListener?, val allowMultiplePicks: Boolean, val itemClick: (Medium) -> (Unit)) : SwappingHolder(view, MultiSelector()) { @@ -410,7 +412,7 @@ class MediaAdapter(val activity: SimpleActivity, var media: MutableList, } fun stopLoad() { - if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN_MR1 || !activity.isDestroyed) + if (!activity.isActivityDestroyed()) Glide.with(activity).clear(view.medium_thumbnail) } } diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/dialogs/ChangeSortingDialog.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/dialogs/ChangeSortingDialog.kt index 95513a98e..0af86fd6a 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/dialogs/ChangeSortingDialog.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/dialogs/ChangeSortingDialog.kt @@ -4,15 +4,15 @@ import android.content.DialogInterface import android.support.v7.app.AlertDialog import android.view.LayoutInflater import android.view.View +import com.simplemobiletools.commons.activities.BaseSimpleActivity import com.simplemobiletools.commons.extensions.beVisibleIf import com.simplemobiletools.commons.extensions.setupDialogStuff import com.simplemobiletools.commons.helpers.* import com.simplemobiletools.gallery.R -import com.simplemobiletools.gallery.activities.SimpleActivity import com.simplemobiletools.gallery.extensions.config import kotlinx.android.synthetic.main.dialog_change_sorting.view.* -class ChangeSortingDialog(val activity: SimpleActivity, val isDirectorySorting: Boolean, showFolderCheckbox: Boolean, +class ChangeSortingDialog(val activity: BaseSimpleActivity, val isDirectorySorting: Boolean, showFolderCheckbox: Boolean, val path: String = "", val callback: () -> Unit) : DialogInterface.OnClickListener { private var currSorting = 0 diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/dialogs/ExcludeFolderDialog.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/dialogs/ExcludeFolderDialog.kt index ea386870f..e676fe0ad 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/dialogs/ExcludeFolderDialog.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/dialogs/ExcludeFolderDialog.kt @@ -5,15 +5,15 @@ import android.view.LayoutInflater import android.view.ViewGroup import android.widget.RadioButton import android.widget.RadioGroup +import com.simplemobiletools.commons.activities.BaseSimpleActivity import com.simplemobiletools.commons.extensions.beVisibleIf import com.simplemobiletools.commons.extensions.getBasePath import com.simplemobiletools.commons.extensions.setupDialogStuff import com.simplemobiletools.gallery.R -import com.simplemobiletools.gallery.activities.SimpleActivity import com.simplemobiletools.gallery.extensions.config import kotlinx.android.synthetic.main.dialog_exclude_folder.view.* -class ExcludeFolderDialog(val activity: SimpleActivity, val selectedPaths: List, val callback: () -> Unit) { +class ExcludeFolderDialog(val activity: BaseSimpleActivity, val selectedPaths: List, val callback: () -> Unit) { val alternativePaths = getAlternativePathsList() var radioGroup: RadioGroup? = null diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/dialogs/FilterMediaDialog.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/dialogs/FilterMediaDialog.kt index f99fc98c3..ce20eae97 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/dialogs/FilterMediaDialog.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/dialogs/FilterMediaDialog.kt @@ -3,16 +3,16 @@ package com.simplemobiletools.gallery.dialogs import android.support.v7.app.AlertDialog import android.view.LayoutInflater import android.view.View +import com.simplemobiletools.commons.activities.BaseSimpleActivity import com.simplemobiletools.commons.extensions.setupDialogStuff import com.simplemobiletools.gallery.R -import com.simplemobiletools.gallery.activities.SimpleActivity import com.simplemobiletools.gallery.extensions.config import com.simplemobiletools.gallery.helpers.GIFS import com.simplemobiletools.gallery.helpers.IMAGES import com.simplemobiletools.gallery.helpers.VIDEOS import kotlinx.android.synthetic.main.dialog_filter_media.view.* -class FilterMediaDialog(val activity: SimpleActivity, val callback: (result: Int) -> Unit) { +class FilterMediaDialog(val activity: BaseSimpleActivity, val callback: (result: Int) -> Unit) { private var view: View = LayoutInflater.from(activity).inflate(R.layout.dialog_filter_media, null) init { diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/dialogs/ManageExtendedDetailsDialog.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/dialogs/ManageExtendedDetailsDialog.kt index 3d8c5e3a7..bbc70402a 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/dialogs/ManageExtendedDetailsDialog.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/dialogs/ManageExtendedDetailsDialog.kt @@ -3,6 +3,7 @@ package com.simplemobiletools.gallery.dialogs import android.support.v7.app.AlertDialog import android.view.LayoutInflater import android.view.View +import com.simplemobiletools.commons.activities.BaseSimpleActivity import com.simplemobiletools.commons.extensions.setupDialogStuff import com.simplemobiletools.gallery.R import com.simplemobiletools.gallery.activities.SimpleActivity @@ -10,7 +11,7 @@ import com.simplemobiletools.gallery.extensions.config import com.simplemobiletools.gallery.helpers.* import kotlinx.android.synthetic.main.dialog_manage_extended_details.view.* -class ManageExtendedDetailsDialog(val activity: SimpleActivity, val callback: (result: Int) -> Unit) { +class ManageExtendedDetailsDialog(val activity: BaseSimpleActivity, val callback: (result: Int) -> Unit) { private var view: View = LayoutInflater.from(activity).inflate(R.layout.dialog_manage_extended_details, null) init { diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/dialogs/PickDirectoryDialog.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/dialogs/PickDirectoryDialog.kt index e72a3395c..937f98e07 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/dialogs/PickDirectoryDialog.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/dialogs/PickDirectoryDialog.kt @@ -3,15 +3,16 @@ package com.simplemobiletools.gallery.dialogs import android.support.v7.app.AlertDialog import android.support.v7.widget.GridLayoutManager import android.view.LayoutInflater +import com.simplemobiletools.commons.activities.BaseSimpleActivity import com.simplemobiletools.commons.dialogs.FilePickerDialog import com.simplemobiletools.commons.extensions.beGoneIf import com.simplemobiletools.commons.extensions.beVisibleIf import com.simplemobiletools.commons.extensions.setupDialogStuff import com.simplemobiletools.commons.extensions.toast import com.simplemobiletools.gallery.R -import com.simplemobiletools.gallery.activities.SimpleActivity import com.simplemobiletools.gallery.adapters.DirectoryAdapter import com.simplemobiletools.gallery.asynctasks.GetDirectoriesAsynctask +import com.simplemobiletools.gallery.extensions.addTempFolderIfNeeded import com.simplemobiletools.gallery.extensions.config import com.simplemobiletools.gallery.extensions.getCachedDirectories import com.simplemobiletools.gallery.extensions.getSortedDirectories @@ -19,7 +20,7 @@ import com.simplemobiletools.gallery.helpers.VIEW_TYPE_GRID import com.simplemobiletools.gallery.models.Directory import kotlinx.android.synthetic.main.dialog_directory_picker.view.* -class PickDirectoryDialog(val activity: SimpleActivity, val sourcePath: String, val callback: (path: String) -> Unit) { +class PickDirectoryDialog(val activity: BaseSimpleActivity, val sourcePath: String, val callback: (path: String) -> Unit) { var dialog: AlertDialog var shownDirectories = ArrayList() var view = LayoutInflater.from(activity).inflate(R.layout.dialog_directory_picker, null) @@ -62,8 +63,8 @@ class PickDirectoryDialog(val activity: SimpleActivity, val sourcePath: String, return shownDirectories = dirs - val adapter = DirectoryAdapter(activity, dirs, null, true) { - if (it.path.trimEnd('/') == sourcePath) { + val adapter = DirectoryAdapter(activity, dirs, null, view.directories_grid, true) { + if ((it as Directory).path.trimEnd('/') == sourcePath) { activity.toast(R.string.source_and_destination_same) return@DirectoryAdapter } else { diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/dialogs/PickMediumDialog.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/dialogs/PickMediumDialog.kt index 3596a6907..1903462c4 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/dialogs/PickMediumDialog.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/dialogs/PickMediumDialog.kt @@ -3,11 +3,11 @@ package com.simplemobiletools.gallery.dialogs import android.support.v7.app.AlertDialog import android.support.v7.widget.GridLayoutManager import android.view.LayoutInflater +import com.simplemobiletools.commons.activities.BaseSimpleActivity import com.simplemobiletools.commons.extensions.beGoneIf import com.simplemobiletools.commons.extensions.beVisibleIf import com.simplemobiletools.commons.extensions.setupDialogStuff import com.simplemobiletools.gallery.R -import com.simplemobiletools.gallery.activities.SimpleActivity import com.simplemobiletools.gallery.adapters.MediaAdapter import com.simplemobiletools.gallery.asynctasks.GetMediaAsynctask import com.simplemobiletools.gallery.extensions.config @@ -16,7 +16,7 @@ import com.simplemobiletools.gallery.helpers.VIEW_TYPE_GRID import com.simplemobiletools.gallery.models.Medium import kotlinx.android.synthetic.main.dialog_medium_picker.view.* -class PickMediumDialog(val activity: SimpleActivity, val path: String, val callback: (path: String) -> Unit) { +class PickMediumDialog(val activity: BaseSimpleActivity, val path: String, val callback: (path: String) -> Unit) { var dialog: AlertDialog var shownMedia = ArrayList() val view = LayoutInflater.from(activity).inflate(R.layout.dialog_medium_picker, null) diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/dialogs/ResizeDialog.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/dialogs/ResizeDialog.kt index c82c5fdce..cc2e9432f 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/dialogs/ResizeDialog.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/dialogs/ResizeDialog.kt @@ -7,14 +7,14 @@ import android.text.TextWatcher import android.view.LayoutInflater import android.view.WindowManager import android.widget.EditText +import com.simplemobiletools.commons.activities.BaseSimpleActivity import com.simplemobiletools.commons.extensions.setupDialogStuff import com.simplemobiletools.commons.extensions.toast import com.simplemobiletools.commons.extensions.value import com.simplemobiletools.gallery.R -import com.simplemobiletools.gallery.activities.SimpleActivity import kotlinx.android.synthetic.main.resize_image.view.* -class ResizeDialog(val activity: SimpleActivity, val size: Point, val callback: (newSize: Point) -> Unit) { +class ResizeDialog(val activity: BaseSimpleActivity, val size: Point, val callback: (newSize: Point) -> Unit) { init { val view = LayoutInflater.from(activity).inflate(R.layout.resize_image, null) val widthView = view.image_width diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/dialogs/SaveAsDialog.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/dialogs/SaveAsDialog.kt index f97e2fb99..4a401e289 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/dialogs/SaveAsDialog.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/dialogs/SaveAsDialog.kt @@ -3,15 +3,15 @@ package com.simplemobiletools.gallery.dialogs import android.support.v7.app.AlertDialog import android.view.LayoutInflater import android.view.WindowManager +import com.simplemobiletools.commons.activities.BaseSimpleActivity import com.simplemobiletools.commons.dialogs.ConfirmationDialog import com.simplemobiletools.commons.dialogs.FilePickerDialog import com.simplemobiletools.commons.extensions.* import com.simplemobiletools.gallery.R -import com.simplemobiletools.gallery.activities.SimpleActivity import kotlinx.android.synthetic.main.dialog_save_as.view.* import java.io.File -class SaveAsDialog(val activity: SimpleActivity, val path: String, val appendFilename: Boolean, val callback: (savePath: String) -> Unit) { +class SaveAsDialog(val activity: BaseSimpleActivity, val path: String, val appendFilename: Boolean, val callback: (savePath: String) -> Unit) { init { var realPath = File(path).parent.trimEnd('/') diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/dialogs/SlideshowDialog.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/dialogs/SlideshowDialog.kt index 493e8a980..e9dc60b49 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/dialogs/SlideshowDialog.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/dialogs/SlideshowDialog.kt @@ -4,16 +4,16 @@ import android.support.v7.app.AlertDialog import android.view.LayoutInflater import android.view.View import android.view.WindowManager +import com.simplemobiletools.commons.activities.BaseSimpleActivity import com.simplemobiletools.commons.extensions.hideKeyboard import com.simplemobiletools.commons.extensions.setupDialogStuff import com.simplemobiletools.commons.extensions.toast import com.simplemobiletools.gallery.R -import com.simplemobiletools.gallery.activities.SimpleActivity import com.simplemobiletools.gallery.extensions.config import com.simplemobiletools.gallery.helpers.SLIDESHOW_DEFAULT_INTERVAL import kotlinx.android.synthetic.main.dialog_slideshow.view.* -class SlideshowDialog(val activity: SimpleActivity, val callback: () -> Unit) { +class SlideshowDialog(val activity: BaseSimpleActivity, val callback: () -> Unit) { val view: View init { diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/extensions/activity.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/extensions/activity.kt index 0cfb3f900..143a5a4e4 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/extensions/activity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/extensions/activity.kt @@ -14,11 +14,13 @@ import com.bumptech.glide.load.resource.drawable.DrawableTransitionOptions import com.bumptech.glide.request.RequestOptions import com.google.gson.Gson import com.google.gson.reflect.TypeToken +import com.simplemobiletools.commons.activities.BaseSimpleActivity import com.simplemobiletools.commons.extensions.* import com.simplemobiletools.commons.helpers.* import com.simplemobiletools.gallery.BuildConfig import com.simplemobiletools.gallery.R import com.simplemobiletools.gallery.activities.SimpleActivity +import com.simplemobiletools.gallery.dialogs.PickDirectoryDialog import com.simplemobiletools.gallery.helpers.NOMEDIA import com.simplemobiletools.gallery.models.Directory import com.simplemobiletools.gallery.models.Medium @@ -89,7 +91,7 @@ fun AppCompatActivity.hideSystemUI() { View.SYSTEM_UI_FLAG_IMMERSIVE } -fun SimpleActivity.addNoMedia(path: String, callback: () -> Unit) { +fun BaseSimpleActivity.addNoMedia(path: String, callback: () -> Unit) { val file = File(path, NOMEDIA) if (file.exists()) return @@ -116,14 +118,14 @@ fun SimpleActivity.addNoMedia(path: String, callback: () -> Unit) { } } -fun SimpleActivity.removeNoMedia(path: String, callback: (() -> Unit)? = null) { +fun BaseSimpleActivity.removeNoMedia(path: String, callback: (() -> Unit)? = null) { val file = File(path, NOMEDIA) deleteFile(file) { callback?.invoke() } } -fun SimpleActivity.toggleFileVisibility(oldFile: File, hide: Boolean, callback: ((newFile: File) -> Unit)? = null) { +fun BaseSimpleActivity.toggleFileVisibility(oldFile: File, hide: Boolean, callback: ((newFile: File) -> Unit)? = null) { val path = oldFile.parent var filename = oldFile.name filename = if (hide) { @@ -162,6 +164,29 @@ fun Activity.loadImage(path: String, target: MySquareImageView, horizontalScroll } } +fun BaseSimpleActivity.tryCopyMoveFilesTo(files: ArrayList, isCopyOperation: Boolean, callback: () -> Unit) { + if (files.isEmpty()) { + toast(R.string.unknown_error_occurred) + return + } + + val source = if (files[0].isFile) files[0].parent else files[0].absolutePath + PickDirectoryDialog(this, source) { + copyMoveFilesTo(files, source.trimEnd('/'), it, isCopyOperation, true, callback) + } +} + +fun BaseSimpleActivity.addTempFolderIfNeeded(dirs: ArrayList): ArrayList { + val directories = ArrayList() + val tempFolderPath = config.tempFolderPath + if (tempFolderPath.isNotEmpty()) { + val newFolder = Directory(tempFolderPath, "", tempFolderPath.getFilenameFromPath(), 0, 0, 0, 0L) + directories.add(newFolder) + } + directories.addAll(dirs) + return directories +} + fun Activity.loadPng(path: String, target: MySquareImageView, cropThumbnails: Boolean) { val options = RequestOptions() .signature(path.getFileSignature()) 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 697434a6f..c46fbf60e 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/fragments/PhotoFragment.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/fragments/PhotoFragment.kt @@ -7,7 +7,6 @@ import android.graphics.Color import android.graphics.Matrix import android.graphics.drawable.ColorDrawable import android.net.Uri -import android.os.Build import android.os.Bundle import android.view.LayoutInflater import android.view.View @@ -302,7 +301,7 @@ class PhotoFragment : ViewPagerFragment() { override fun onDestroyView() { super.onDestroyView() - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1 && !activity!!.isDestroyed) { + if (activity?.isActivityDestroyed() == false) { Glide.with(context).clear(view.gif_view) } } diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml index 9432206a7..073f3fd19 100644 --- a/app/src/main/res/layout/activity_main.xml +++ b/app/src/main/res/layout/activity_main.xml @@ -33,7 +33,7 @@ android:text="@string/change_filters_underlined" android:visibility="gone"/> - - - - diff --git a/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml b/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml index 80b730f36..07b53a1c9 100644 --- a/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml +++ b/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml @@ -1,5 +1,5 @@ - + diff --git a/app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml b/app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml index 80b730f36..07b53a1c9 100644 --- a/app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml +++ b/app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml @@ -1,5 +1,5 @@ - + diff --git a/app/src/main/res/values/colors.xml b/app/src/main/res/values/colors.xml index ee1e5614a..8cb25a2bb 100644 --- a/app/src/main/res/values/colors.xml +++ b/app/src/main/res/values/colors.xml @@ -7,6 +7,4 @@ @color/default_dark_theme_text_color @color/default_dark_theme_background_color - - @color/color_primary