Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 693e4a6f authored by tibbi's avatar tibbi
Browse files

use integers for storing selected recyclerview items

parent ea634c69
Loading
Loading
Loading
Loading
+1 −1
Original line number Original line Diff line number Diff line
@@ -7,7 +7,7 @@ buildscript {
        propMinSdkVersion = 21
        propMinSdkVersion = 21
        propTargetSdkVersion = propCompileSdkVersion
        propTargetSdkVersion = propCompileSdkVersion
        propVersionCode = 1
        propVersionCode = 1
        propVersionName = '5.0.16'
        propVersionName = '5.0.18'
        kotlin_version = '1.2.71'
        kotlin_version = '1.2.71'
    }
    }


+2 −2
Original line number Original line Diff line number Diff line
@@ -52,9 +52,9 @@ class FilepickerItemsAdapter(activity: BaseSimpleActivity, val fileDirItems: Lis


    override fun getIsItemSelectable(position: Int) = false
    override fun getIsItemSelectable(position: Int) = false


    override fun getItemKeyPosition(key: String) = fileDirItems.indexOfFirst { it.path == key }
    override fun getItemKeyPosition(key: Int) = fileDirItems.indexOfFirst { it.path.hashCode() == key }


    override fun getItemSelectionKey(position: Int) = fileDirItems[position].path
    override fun getItemSelectionKey(position: Int) = fileDirItems[position].path.hashCode()


    override fun onViewRecycled(holder: MyRecyclerViewAdapter.ViewHolder) {
    override fun onViewRecycled(holder: MyRecyclerViewAdapter.ViewHolder) {
        super.onViewRecycled(holder)
        super.onViewRecycled(holder)
+5 −5
Original line number Original line Diff line number Diff line
@@ -25,7 +25,7 @@ abstract class MyRecyclerViewAdapter(val activity: BaseSimpleActivity, val recyc
    protected var textColor = baseConfig.textColor
    protected var textColor = baseConfig.textColor
    protected var backgroundColor = baseConfig.backgroundColor
    protected var backgroundColor = baseConfig.backgroundColor
    protected var actModeCallback: MyActionModeCallback
    protected var actModeCallback: MyActionModeCallback
    protected var selectedKeys = HashSet<String>()
    protected var selectedKeys = HashSet<Int>()
    protected var positionOffset = 0
    protected var positionOffset = 0


    private var actMode: ActionMode? = null
    private var actMode: ActionMode? = null
@@ -42,9 +42,9 @@ abstract class MyRecyclerViewAdapter(val activity: BaseSimpleActivity, val recyc


    abstract fun getIsItemSelectable(position: Int): Boolean
    abstract fun getIsItemSelectable(position: Int): Boolean


    abstract fun getItemSelectionKey(position: Int): String?
    abstract fun getItemSelectionKey(position: Int): Int?


    abstract fun getItemKeyPosition(key: String): Int
    abstract fun getItemKeyPosition(key: Int): Int


    protected fun isOneItemSelected() = selectedKeys.size == 1
    protected fun isOneItemSelected() = selectedKeys.size == 1


@@ -80,7 +80,7 @@ abstract class MyRecyclerViewAdapter(val activity: BaseSimpleActivity, val recyc


            override fun onDestroyActionMode(actionMode: ActionMode) {
            override fun onDestroyActionMode(actionMode: ActionMode) {
                isSelectable = false
                isSelectable = false
                (selectedKeys.clone() as HashSet<String>).forEach {
                (selectedKeys.clone() as HashSet<Int>).forEach {
                    val position = getItemKeyPosition(it)
                    val position = getItemKeyPosition(it)
                    if (position != -1) {
                    if (position != -1) {
                        toggleItemSelection(false, position)
                        toggleItemSelection(false, position)
@@ -145,7 +145,7 @@ abstract class MyRecyclerViewAdapter(val activity: BaseSimpleActivity, val recyc
        }
        }
    }
    }


    protected fun isKeySelected(key: String) = selectedKeys.contains(key)
    protected fun isKeySelected(key: Int) = selectedKeys.contains(key)


    protected fun selectAll() {
    protected fun selectAll() {
        val cnt = itemCount - positionOffset
        val cnt = itemCount - positionOffset