use an interface for selecting items with drag selection
This commit is contained in:
parent
c174b7d395
commit
ffe7742334
|
@ -222,7 +222,7 @@ class MainActivity : SimpleActivity(), DirectoryAdapter.DirOperationsListener {
|
||||||
private fun handleZooming() {
|
private fun handleZooming() {
|
||||||
val layoutManager = directories_grid.layoutManager as GridLayoutManager
|
val layoutManager = directories_grid.layoutManager as GridLayoutManager
|
||||||
layoutManager.spanCount = config.dirColumnCnt
|
layoutManager.spanCount = config.dirColumnCnt
|
||||||
MyScalableRecyclerView.mListener = object : MyScalableRecyclerView.ZoomListener {
|
MyScalableRecyclerView.mListener = object : MyScalableRecyclerView.MyScalableRecyclerViewListener {
|
||||||
override fun zoomIn() {
|
override fun zoomIn() {
|
||||||
if (layoutManager.spanCount > 1) {
|
if (layoutManager.spanCount > 1) {
|
||||||
reduceColumnCount()
|
reduceColumnCount()
|
||||||
|
@ -236,6 +236,14 @@ class MainActivity : SimpleActivity(), DirectoryAdapter.DirOperationsListener {
|
||||||
DirectoryAdapter.actMode?.finish()
|
DirectoryAdapter.actMode?.finish()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun selectItem(position: Int) {
|
||||||
|
(directories_grid.adapter as DirectoryAdapter).selectItem(position)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun selectRange(initialSelection: Int, lastDraggedIndex: Int, minReached: Int, maxReached: Int) {
|
||||||
|
(directories_grid.adapter as DirectoryAdapter).selectRange(initialSelection, lastDraggedIndex, minReached, maxReached)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -260,7 +260,7 @@ class MediaActivity : SimpleActivity(), MediaAdapter.MediaOperationsListener {
|
||||||
private fun handleZooming() {
|
private fun handleZooming() {
|
||||||
val layoutManager = media_grid.layoutManager as GridLayoutManager
|
val layoutManager = media_grid.layoutManager as GridLayoutManager
|
||||||
layoutManager.spanCount = config.mediaColumnCnt
|
layoutManager.spanCount = config.mediaColumnCnt
|
||||||
MyScalableRecyclerView.mListener = object : MyScalableRecyclerView.ZoomListener {
|
MyScalableRecyclerView.mListener = object : MyScalableRecyclerView.MyScalableRecyclerViewListener {
|
||||||
override fun zoomIn() {
|
override fun zoomIn() {
|
||||||
if (layoutManager.spanCount > 1) {
|
if (layoutManager.spanCount > 1) {
|
||||||
reduceColumnCount()
|
reduceColumnCount()
|
||||||
|
@ -274,6 +274,13 @@ class MediaActivity : SimpleActivity(), MediaAdapter.MediaOperationsListener {
|
||||||
MediaAdapter.actMode?.finish()
|
MediaAdapter.actMode?.finish()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
override fun selectItem(position: Int) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun selectRange(initialSelection: Int, lastDraggedIndex: Int, minReached: Int, maxReached: Int) {
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -7,7 +7,6 @@ import android.util.AttributeSet
|
||||||
import android.view.MotionEvent
|
import android.view.MotionEvent
|
||||||
import android.view.ScaleGestureDetector
|
import android.view.ScaleGestureDetector
|
||||||
import com.simplemobiletools.gallery.R
|
import com.simplemobiletools.gallery.R
|
||||||
import com.simplemobiletools.gallery.adapters.DirectoryAdapter
|
|
||||||
|
|
||||||
// drag selection is based on https://github.com/afollestad/drag-select-recyclerview
|
// drag selection is based on https://github.com/afollestad/drag-select-recyclerview
|
||||||
class MyScalableRecyclerView : RecyclerView {
|
class MyScalableRecyclerView : RecyclerView {
|
||||||
|
@ -35,7 +34,7 @@ class MyScalableRecyclerView : RecyclerView {
|
||||||
private var inBottomHotspot = false
|
private var inBottomHotspot = false
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
var mListener: ZoomListener? = null
|
var mListener: MyScalableRecyclerViewListener? = null
|
||||||
var mCurrScaleFactor = 1.0f
|
var mCurrScaleFactor = 1.0f
|
||||||
var mLastUp = 0L // allow only pinch zoom, not double tap
|
var mLastUp = 0L // allow only pinch zoom, not double tap
|
||||||
}
|
}
|
||||||
|
@ -135,7 +134,7 @@ class MyScalableRecyclerView : RecyclerView {
|
||||||
minReached = lastDraggedIndex
|
minReached = lastDraggedIndex
|
||||||
}
|
}
|
||||||
|
|
||||||
(adapter as DirectoryAdapter).selectRange(initialSelection, lastDraggedIndex, minReached, maxReached)
|
mListener?.selectRange(initialSelection, lastDraggedIndex, minReached, maxReached)
|
||||||
|
|
||||||
if (initialSelection == lastDraggedIndex) {
|
if (initialSelection == lastDraggedIndex) {
|
||||||
minReached = lastDraggedIndex
|
minReached = lastDraggedIndex
|
||||||
|
@ -159,7 +158,7 @@ class MyScalableRecyclerView : RecyclerView {
|
||||||
maxReached = -1
|
maxReached = -1
|
||||||
this.initialSelection = initialSelection
|
this.initialSelection = initialSelection
|
||||||
dragSelectActive = true
|
dragSelectActive = true
|
||||||
(adapter as DirectoryAdapter).selectItem(initialSelection)
|
mListener?.selectItem(initialSelection)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun getItemPosition(e: MotionEvent): Int {
|
private fun getItemPosition(e: MotionEvent): Int {
|
||||||
|
@ -194,9 +193,13 @@ class MyScalableRecyclerView : RecyclerView {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
interface ZoomListener {
|
interface MyScalableRecyclerViewListener {
|
||||||
fun zoomOut()
|
fun zoomOut()
|
||||||
|
|
||||||
fun zoomIn()
|
fun zoomIn()
|
||||||
|
|
||||||
|
fun selectItem(position: Int)
|
||||||
|
|
||||||
|
fun selectRange(initialSelection: Int, lastDraggedIndex: Int, minReached: Int, maxReached: Int)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue