From 54c56c559ec7da931b3fa2b9908eab375e4c46ef Mon Sep 17 00:00:00 2001 From: tibbi Date: Mon, 19 Jun 2017 23:41:57 +0200 Subject: [PATCH] make zooming disabled by default in the recyclerview --- .../gallery/activities/MainActivity.kt | 1 + .../gallery/activities/MediaActivity.kt | 1 + .../gallery/adapters/DirectoryAdapter.kt | 16 ++++++---------- .../gallery/adapters/MediaAdapter.kt | 16 ++++++---------- .../gallery/views/MyScalableRecyclerView.kt | 6 +++++- 5 files changed, 19 insertions(+), 21 deletions(-) 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 85d5bc3f6..5b2d10852 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MainActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MainActivity.kt @@ -239,6 +239,7 @@ class MainActivity : SimpleActivity(), DirectoryAdapter.DirOperationsListener { directories_refresh_layout.layoutParams = FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT) } + directories_grid.isZoomingEnabled = true layoutManager.spanCount = config.dirColumnCnt MyScalableRecyclerView.mListener = object : MyScalableRecyclerView.MyScalableRecyclerViewListener { override fun zoomIn() { 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 2d90e98c7..be48e9082 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MediaActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MediaActivity.kt @@ -315,6 +315,7 @@ class MediaActivity : SimpleActivity(), MediaAdapter.MediaOperationsListener { media_refresh_layout.layoutParams = FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT) } + media_grid.isZoomingEnabled = true layoutManager.spanCount = config.mediaColumnCnt MyScalableRecyclerView.mListener = object : MyScalableRecyclerView.MyScalableRecyclerViewListener { override fun zoomIn() { 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 02abb93f7..d42de7466 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/adapters/DirectoryAdapter.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/adapters/DirectoryAdapter.kt @@ -39,7 +39,7 @@ class DirectoryAdapter(val activity: SimpleActivity, var dirs: MutableList() val selectedPositions = HashSet() - var foregroundColor = 0 + var foregroundColor = config.primaryColor var pinnedFolders = config.pinnedFolders var scrollVertically = !config.scrollHorizontally @@ -97,10 +97,6 @@ class DirectoryAdapter(val activity: SimpleActivity, var dirs: MutableList = selectedPositions } - init { - foregroundColor = config.primaryColor - } - val multiSelectorMode = object : ModalMultiSelectorCallback(multiSelector) { override fun onActionItemClicked(mode: ActionMode, item: MenuItem): Boolean { when (item.itemId) { @@ -423,7 +419,7 @@ class DirectoryAdapter(val activity: SimpleActivity, var dirs: MutableList (Unit)) : SwappingHolder(view, MultiSelector()) { fun bindView(directory: Directory, isPinned: Boolean, scrollVertically: Boolean): View { @@ -436,15 +432,15 @@ class DirectoryAdapter(val activity: SimpleActivity, var dirs: MutableList, var actMode: ActionMode? = null var itemViews = SparseArray() val selectedPositions = HashSet() - var foregroundColor = 0 + var foregroundColor = config.primaryColor var displayFilenames = config.displayFileNames var scrollVertically = !config.scrollHorizontally @@ -90,10 +90,6 @@ class MediaAdapter(val activity: SimpleActivity, var media: MutableList, override fun getSelectedPositions(): HashSet = selectedPositions } - init { - foregroundColor = config.primaryColor - } - val multiSelectorMode = object : ModalMultiSelectorCallback(multiSelector) { override fun onActionItemClicked(mode: ActionMode, item: MenuItem): Boolean { when (item.itemId) { @@ -336,7 +332,7 @@ class MediaAdapter(val activity: SimpleActivity, var media: MutableList, } } - class ViewHolder(val view: View, val adapter: MyAdapterListener, val activity: SimpleActivity, val multiSelectorCallback: ModalMultiSelectorCallback, + class ViewHolder(val view: View, val adapterListener: MyAdapterListener, val activity: SimpleActivity, val multiSelectorCallback: ModalMultiSelectorCallback, val multiSelector: MultiSelector, val listener: MediaOperationsListener?, val itemClick: (Medium) -> (Unit)) : SwappingHolder(view, MultiSelector()) { fun bindView(medium: Medium, displayFilenames: Boolean, scrollVertically: Boolean): View { itemView.apply { @@ -348,15 +344,15 @@ class MediaAdapter(val activity: SimpleActivity, var media: MutableList, setOnClickListener { viewClicked(medium) } setOnLongClickListener { viewLongClicked(); true } - adapter.setupItemForeground(this) + adapterListener.setupItemForeground(this) } return itemView } fun viewClicked(medium: Medium) { if (multiSelector.isSelectable) { - val isSelected = adapter.getSelectedPositions().contains(layoutPosition) - adapter.toggleItemSelectionAdapter(!isSelected, layoutPosition) + val isSelected = adapterListener.getSelectedPositions().contains(layoutPosition) + adapterListener.toggleItemSelectionAdapter(!isSelected, layoutPosition) } else { itemClick(medium) } @@ -366,7 +362,7 @@ class MediaAdapter(val activity: SimpleActivity, var media: MutableList, if (listener != null) { if (!multiSelector.isSelectable) { activity.startSupportActionMode(multiSelectorCallback) - adapter.toggleItemSelectionAdapter(true, layoutPosition) + adapterListener.toggleItemSelectionAdapter(true, layoutPosition) } listener.itemLongClicked(layoutPosition) diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/views/MyScalableRecyclerView.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/views/MyScalableRecyclerView.kt index 3b1a6add8..aeab0cf4e 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/views/MyScalableRecyclerView.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/views/MyScalableRecyclerView.kt @@ -11,6 +11,7 @@ import com.simplemobiletools.gallery.R // drag selection is based on https://github.com/afollestad/drag-select-recyclerview class MyScalableRecyclerView : RecyclerView { private val AUTO_SCROLL_DELAY = 25L + var isZoomingEnabled = false private var mScaleDetector: ScaleGestureDetector @@ -149,7 +150,10 @@ class MyScalableRecyclerView : RecyclerView { } } } - return mScaleDetector.onTouchEvent(ev) + return if (isZoomingEnabled) + mScaleDetector.onTouchEvent(ev) + else + true } fun setDragSelectActive(initialSelection: Int) {