Loading build.gradle +1 −1 Original line number Diff line number Diff line Loading @@ -7,7 +7,7 @@ buildscript { propMinSdkVersion = 16 propTargetSdkVersion = propCompileSdkVersion propVersionCode = 1 propVersionName = '4.1.11' propVersionName = '4.2.8' kotlin_version = '1.2.50' support_libs = '27.1.1' } Loading commons/src/main/kotlin/com/simplemobiletools/commons/adapters/FilepickerItemsAdapter.kt +2 −2 Original line number Diff line number Diff line Loading @@ -29,9 +29,9 @@ class FilepickerItemsAdapter(activity: BaseSimpleActivity, val fileDirItems: Lis override fun getActionMenuId() = 0 override fun prepareItemSelection(view: View) {} override fun prepareItemSelection(viewHolder: ViewHolder) {} override fun markItemSelection(select: Boolean, view: View?) {} override fun markViewHolderSelection(select: Boolean, viewHolder: ViewHolder?) {} override fun onCreateViewHolder(parent: ViewGroup, viewType: Int) = createViewHolder(R.layout.filepicker_list_item, parent) Loading commons/src/main/kotlin/com/simplemobiletools/commons/adapters/MyRecyclerViewAdapter.kt +47 −16 Original line number Diff line number Diff line Loading @@ -28,19 +28,20 @@ abstract class MyRecyclerViewAdapter(val activity: BaseSimpleActivity, val recyc protected var primaryColor = baseConfig.primaryColor protected var textColor = baseConfig.textColor protected var backgroundColor = baseConfig.backgroundColor protected var itemViews = SparseArray<View>() protected var viewHolders = SparseArray<ViewHolder>() protected val selectedPositions = HashSet<Int>() protected var positionOffset = 0 private val multiSelector = MultiSelector() private var actMode: ActionMode? = null private var actBarTextView: TextView? = null private var lastLongPressedItem = -1 abstract fun getActionMenuId(): Int abstract fun prepareItemSelection(view: View) abstract fun prepareItemSelection(viewHolder: ViewHolder) abstract fun markItemSelection(select: Boolean, view: View?) abstract fun markViewHolderSelection(select: Boolean, viewHolder: ViewHolder?) abstract fun prepareActionMode(menu: Menu) Loading @@ -52,15 +53,15 @@ abstract class MyRecyclerViewAdapter(val activity: BaseSimpleActivity, val recyc protected fun toggleItemSelection(select: Boolean, pos: Int) { if (select) { if (itemViews[pos] != null) { prepareItemSelection(itemViews[pos]) selectedPositions.add(pos) if (viewHolders[pos] != null) { prepareItemSelection(viewHolders[pos]) } selectedPositions.add(pos) } else { selectedPositions.remove(pos) } markItemSelection(select, itemViews[pos]) markViewHolderSelection(select, viewHolders[pos]) if (selectedPositions.isEmpty()) { finishActMode() Loading Loading @@ -88,6 +89,7 @@ abstract class MyRecyclerViewAdapter(val activity: BaseSimpleActivity, val recyc notifyItemChanged(i + positionOffset) } updateTitle(cnt) lastLongPressedItem = -1 } protected fun setupDragListener(enable: Boolean) { Loading Loading @@ -184,12 +186,23 @@ abstract class MyRecyclerViewAdapter(val activity: BaseSimpleActivity, val recyc private val adapterListener = object : MyAdapterListener { override fun toggleItemSelectionAdapter(select: Boolean, position: Int) { toggleItemSelection(select, position) lastLongPressedItem = -1 } override fun getSelectedPositions() = selectedPositions override fun itemLongClicked(position: Int) { recyclerView.setDragSelectActive(position) lastLongPressedItem = if (lastLongPressedItem == -1) { position } else { val min = Math.min(lastLongPressedItem, position) val max = Math.max(lastLongPressedItem, position) for (i in min..max) { toggleItemSelection(true, i) } -1 } } } Loading Loading @@ -223,11 +236,12 @@ abstract class MyRecyclerViewAdapter(val activity: BaseSimpleActivity, val recyc override fun onDestroyActionMode(actionMode: ActionMode?) { super.onDestroyActionMode(actionMode) selectedPositions.forEach { markItemSelection(false, itemViews[it]) markViewHolderSelection(false, viewHolders[it]) } selectedPositions.clear() actBarTextView?.text = "" actMode = null lastLongPressedItem = -1 } } Loading @@ -237,23 +251,40 @@ abstract class MyRecyclerViewAdapter(val activity: BaseSimpleActivity, val recyc } protected fun bindViewHolder(holder: MyRecyclerViewAdapter.ViewHolder, position: Int, view: View) { itemViews.put(position, view) viewHolders.put(position, holder) toggleItemSelection(selectedPositions.contains(position), position) holder.itemView.tag = holder } override fun onViewRecycled(holder: ViewHolder) { super.onViewRecycled(holder) val pos = viewHolders.indexOfValue(holder) try { if (pos != -1) { viewHolders.removeAt(pos) } } catch (ignored: ArrayIndexOutOfBoundsException) { } } protected fun removeSelectedItems() { val newViewHolders = SparseArray<ViewHolder>() val cnt = viewHolders.size() for (i in 0..cnt) { if (selectedPositions.contains(i)) { continue } val view = viewHolders.get(i, null) val newIndex = i - selectedPositions.count { it <= i } newViewHolders.put(newIndex, view) } viewHolders = newViewHolders selectedPositions.sortedDescending().forEach { notifyItemRemoved(it + positionOffset) itemViews.put(it, null) } val newItems = SparseArray<View>() (0 until itemViews.size()) .filter { itemViews[it] != null } .forEachIndexed { curIndex, i -> newItems.put(curIndex, itemViews[i]) } itemViews = newItems finishActMode() fastScroller?.measureRecyclerView() } Loading commons/src/main/kotlin/com/simplemobiletools/commons/adapters/PasswordTypesAdapter.kt +3 −2 Original line number Diff line number Diff line Loading @@ -10,15 +10,16 @@ import com.simplemobiletools.commons.R import com.simplemobiletools.commons.extensions.isFingerPrintSensorAvailable import com.simplemobiletools.commons.interfaces.HashListener import com.simplemobiletools.commons.interfaces.SecurityTab import com.simplemobiletools.commons.views.MyScrollView class PasswordTypesAdapter(val context: Context, val requiredHash: String, val hashListener: HashListener) : PagerAdapter() { class PasswordTypesAdapter(val context: Context, val requiredHash: String, val hashListener: HashListener, val scrollView: MyScrollView) : PagerAdapter() { private val tabs = SparseArray<SecurityTab>() override fun instantiateItem(container: ViewGroup, position: Int): Any { val view = LayoutInflater.from(context).inflate(layoutSelection(position), container, false) container.addView(view) tabs.put(position, view as SecurityTab) (view as SecurityTab).initTab(requiredHash, hashListener) (view as SecurityTab).initTab(requiredHash, hashListener, scrollView) return view } Loading commons/src/main/kotlin/com/simplemobiletools/commons/dialogs/SecurityDialog.kt +2 −2 Original line number Diff line number Diff line Loading @@ -27,7 +27,7 @@ class SecurityDialog(val activity: Activity, val requiredHash: String, val showT view.apply { viewPager = findViewById(R.id.dialog_tab_view_pager) viewPager.offscreenPageLimit = 2 tabsAdapter = PasswordTypesAdapter(context, requiredHash, this@SecurityDialog) tabsAdapter = PasswordTypesAdapter(context, requiredHash, this@SecurityDialog, dialog_scrollview) viewPager.adapter = tabsAdapter viewPager.addOnPageChangeListener(object : ViewPager.OnPageChangeListener { override fun onPageScrollStateChanged(state: Int) { Loading Loading @@ -79,7 +79,7 @@ class SecurityDialog(val activity: Activity, val requiredHash: String, val showT dialog = AlertDialog.Builder(activity) .setOnCancelListener { onCancelFail() } .setNegativeButton(R.string.cancel, { dialog, which -> onCancelFail() }) .setNegativeButton(R.string.cancel) { dialog, which -> onCancelFail() } .create().apply { activity.setupDialogStuff(view, this) } Loading Loading
build.gradle +1 −1 Original line number Diff line number Diff line Loading @@ -7,7 +7,7 @@ buildscript { propMinSdkVersion = 16 propTargetSdkVersion = propCompileSdkVersion propVersionCode = 1 propVersionName = '4.1.11' propVersionName = '4.2.8' kotlin_version = '1.2.50' support_libs = '27.1.1' } Loading
commons/src/main/kotlin/com/simplemobiletools/commons/adapters/FilepickerItemsAdapter.kt +2 −2 Original line number Diff line number Diff line Loading @@ -29,9 +29,9 @@ class FilepickerItemsAdapter(activity: BaseSimpleActivity, val fileDirItems: Lis override fun getActionMenuId() = 0 override fun prepareItemSelection(view: View) {} override fun prepareItemSelection(viewHolder: ViewHolder) {} override fun markItemSelection(select: Boolean, view: View?) {} override fun markViewHolderSelection(select: Boolean, viewHolder: ViewHolder?) {} override fun onCreateViewHolder(parent: ViewGroup, viewType: Int) = createViewHolder(R.layout.filepicker_list_item, parent) Loading
commons/src/main/kotlin/com/simplemobiletools/commons/adapters/MyRecyclerViewAdapter.kt +47 −16 Original line number Diff line number Diff line Loading @@ -28,19 +28,20 @@ abstract class MyRecyclerViewAdapter(val activity: BaseSimpleActivity, val recyc protected var primaryColor = baseConfig.primaryColor protected var textColor = baseConfig.textColor protected var backgroundColor = baseConfig.backgroundColor protected var itemViews = SparseArray<View>() protected var viewHolders = SparseArray<ViewHolder>() protected val selectedPositions = HashSet<Int>() protected var positionOffset = 0 private val multiSelector = MultiSelector() private var actMode: ActionMode? = null private var actBarTextView: TextView? = null private var lastLongPressedItem = -1 abstract fun getActionMenuId(): Int abstract fun prepareItemSelection(view: View) abstract fun prepareItemSelection(viewHolder: ViewHolder) abstract fun markItemSelection(select: Boolean, view: View?) abstract fun markViewHolderSelection(select: Boolean, viewHolder: ViewHolder?) abstract fun prepareActionMode(menu: Menu) Loading @@ -52,15 +53,15 @@ abstract class MyRecyclerViewAdapter(val activity: BaseSimpleActivity, val recyc protected fun toggleItemSelection(select: Boolean, pos: Int) { if (select) { if (itemViews[pos] != null) { prepareItemSelection(itemViews[pos]) selectedPositions.add(pos) if (viewHolders[pos] != null) { prepareItemSelection(viewHolders[pos]) } selectedPositions.add(pos) } else { selectedPositions.remove(pos) } markItemSelection(select, itemViews[pos]) markViewHolderSelection(select, viewHolders[pos]) if (selectedPositions.isEmpty()) { finishActMode() Loading Loading @@ -88,6 +89,7 @@ abstract class MyRecyclerViewAdapter(val activity: BaseSimpleActivity, val recyc notifyItemChanged(i + positionOffset) } updateTitle(cnt) lastLongPressedItem = -1 } protected fun setupDragListener(enable: Boolean) { Loading Loading @@ -184,12 +186,23 @@ abstract class MyRecyclerViewAdapter(val activity: BaseSimpleActivity, val recyc private val adapterListener = object : MyAdapterListener { override fun toggleItemSelectionAdapter(select: Boolean, position: Int) { toggleItemSelection(select, position) lastLongPressedItem = -1 } override fun getSelectedPositions() = selectedPositions override fun itemLongClicked(position: Int) { recyclerView.setDragSelectActive(position) lastLongPressedItem = if (lastLongPressedItem == -1) { position } else { val min = Math.min(lastLongPressedItem, position) val max = Math.max(lastLongPressedItem, position) for (i in min..max) { toggleItemSelection(true, i) } -1 } } } Loading Loading @@ -223,11 +236,12 @@ abstract class MyRecyclerViewAdapter(val activity: BaseSimpleActivity, val recyc override fun onDestroyActionMode(actionMode: ActionMode?) { super.onDestroyActionMode(actionMode) selectedPositions.forEach { markItemSelection(false, itemViews[it]) markViewHolderSelection(false, viewHolders[it]) } selectedPositions.clear() actBarTextView?.text = "" actMode = null lastLongPressedItem = -1 } } Loading @@ -237,23 +251,40 @@ abstract class MyRecyclerViewAdapter(val activity: BaseSimpleActivity, val recyc } protected fun bindViewHolder(holder: MyRecyclerViewAdapter.ViewHolder, position: Int, view: View) { itemViews.put(position, view) viewHolders.put(position, holder) toggleItemSelection(selectedPositions.contains(position), position) holder.itemView.tag = holder } override fun onViewRecycled(holder: ViewHolder) { super.onViewRecycled(holder) val pos = viewHolders.indexOfValue(holder) try { if (pos != -1) { viewHolders.removeAt(pos) } } catch (ignored: ArrayIndexOutOfBoundsException) { } } protected fun removeSelectedItems() { val newViewHolders = SparseArray<ViewHolder>() val cnt = viewHolders.size() for (i in 0..cnt) { if (selectedPositions.contains(i)) { continue } val view = viewHolders.get(i, null) val newIndex = i - selectedPositions.count { it <= i } newViewHolders.put(newIndex, view) } viewHolders = newViewHolders selectedPositions.sortedDescending().forEach { notifyItemRemoved(it + positionOffset) itemViews.put(it, null) } val newItems = SparseArray<View>() (0 until itemViews.size()) .filter { itemViews[it] != null } .forEachIndexed { curIndex, i -> newItems.put(curIndex, itemViews[i]) } itemViews = newItems finishActMode() fastScroller?.measureRecyclerView() } Loading
commons/src/main/kotlin/com/simplemobiletools/commons/adapters/PasswordTypesAdapter.kt +3 −2 Original line number Diff line number Diff line Loading @@ -10,15 +10,16 @@ import com.simplemobiletools.commons.R import com.simplemobiletools.commons.extensions.isFingerPrintSensorAvailable import com.simplemobiletools.commons.interfaces.HashListener import com.simplemobiletools.commons.interfaces.SecurityTab import com.simplemobiletools.commons.views.MyScrollView class PasswordTypesAdapter(val context: Context, val requiredHash: String, val hashListener: HashListener) : PagerAdapter() { class PasswordTypesAdapter(val context: Context, val requiredHash: String, val hashListener: HashListener, val scrollView: MyScrollView) : PagerAdapter() { private val tabs = SparseArray<SecurityTab>() override fun instantiateItem(container: ViewGroup, position: Int): Any { val view = LayoutInflater.from(context).inflate(layoutSelection(position), container, false) container.addView(view) tabs.put(position, view as SecurityTab) (view as SecurityTab).initTab(requiredHash, hashListener) (view as SecurityTab).initTab(requiredHash, hashListener, scrollView) return view } Loading
commons/src/main/kotlin/com/simplemobiletools/commons/dialogs/SecurityDialog.kt +2 −2 Original line number Diff line number Diff line Loading @@ -27,7 +27,7 @@ class SecurityDialog(val activity: Activity, val requiredHash: String, val showT view.apply { viewPager = findViewById(R.id.dialog_tab_view_pager) viewPager.offscreenPageLimit = 2 tabsAdapter = PasswordTypesAdapter(context, requiredHash, this@SecurityDialog) tabsAdapter = PasswordTypesAdapter(context, requiredHash, this@SecurityDialog, dialog_scrollview) viewPager.adapter = tabsAdapter viewPager.addOnPageChangeListener(object : ViewPager.OnPageChangeListener { override fun onPageScrollStateChanged(state: Int) { Loading Loading @@ -79,7 +79,7 @@ class SecurityDialog(val activity: Activity, val requiredHash: String, val showT dialog = AlertDialog.Builder(activity) .setOnCancelListener { onCancelFail() } .setNegativeButton(R.string.cancel, { dialog, which -> onCancelFail() }) .setNegativeButton(R.string.cancel) { dialog, which -> onCancelFail() } .create().apply { activity.setupDialogStuff(view, this) } Loading