Loading build.gradle +1 −1 Original line number Diff line number Diff line Loading @@ -7,7 +7,7 @@ buildscript { propMinSdkVersion = 21 propTargetSdkVersion = propCompileSdkVersion propVersionCode = 1 propVersionName = '5.1.6' propVersionName = '5.2.0' kotlin_version = '1.2.71' } Loading commons/src/main/kotlin/com/simplemobiletools/commons/adapters/MyRecyclerViewAdapter.kt +23 −19 Original line number Diff line number Diff line Loading @@ -83,9 +83,10 @@ abstract class MyRecyclerViewAdapter(val activity: BaseSimpleActivity, val recyc (selectedKeys.clone() as HashSet<Int>).forEach { val position = getItemKeyPosition(it) if (position != -1) { toggleItemSelection(false, position) toggleItemSelection(false, position, false) } } updateTitle() selectedKeys.clear() actBarTextView?.text = "" actMode = null Loading @@ -94,7 +95,7 @@ abstract class MyRecyclerViewAdapter(val activity: BaseSimpleActivity, val recyc } } protected fun toggleItemSelection(select: Boolean, pos: Int) { protected fun toggleItemSelection(select: Boolean, pos: Int, updateTitle: Boolean = true) { if (select && !getIsItemSelectable(pos)) { return } Loading @@ -112,17 +113,18 @@ abstract class MyRecyclerViewAdapter(val activity: BaseSimpleActivity, val recyc notifyItemChanged(pos + positionOffset) if (updateTitle) { updateTitle() } if (selectedKeys.isEmpty()) { finishActMode() return } updateTitle(selectedKeys.size) } private fun updateTitle(cnt: Int) { private fun updateTitle() { val selectableItemCount = getSelectableItemCount() val selectedCount = Math.min(cnt, selectableItemCount) val selectedCount = Math.min(selectedKeys.size, selectableItemCount) val oldTitle = actBarTextView?.text val newTitle = "$selectedCount / $selectableItemCount" if (oldTitle != newTitle) { Loading @@ -139,8 +141,9 @@ abstract class MyRecyclerViewAdapter(val activity: BaseSimpleActivity, val recyc val min = Math.min(lastLongPressedItem, position) val max = Math.max(lastLongPressedItem, position) for (i in min..max) { toggleItemSelection(true, i) toggleItemSelection(true, i, false) } updateTitle() position } } Loading @@ -166,16 +169,17 @@ abstract class MyRecyclerViewAdapter(val activity: BaseSimpleActivity, val recyc protected fun selectAll() { val cnt = itemCount - positionOffset for (i in 0 until cnt) { toggleItemSelection(true, i) toggleItemSelection(true, i, false) } lastLongPressedItem = -1 updateTitle() } protected fun setupDragListener(enable: Boolean) { if (enable) { recyclerView.setupDragListener(object : MyRecyclerView.MyDragListener { override fun selectItem(position: Int) { toggleItemSelection(true, position) toggleItemSelection(true, position, true) } override fun selectRange(initialSelection: Int, lastDraggedIndex: Int, minReached: Int, maxReached: Int) { Loading @@ -190,36 +194,36 @@ abstract class MyRecyclerViewAdapter(val activity: BaseSimpleActivity, val recyc protected fun selectItemRange(from: Int, to: Int, min: Int, max: Int) { if (from == to) { (min..max).filter { it != from }.forEach { toggleItemSelection(false, it) } (min..max).filter { it != from }.forEach { toggleItemSelection(false, it, true) } return } if (to < from) { for (i in to..from) { toggleItemSelection(true, i) toggleItemSelection(true, i, true) } if (min > -1 && min < to) { (min until to).filter { it != from }.forEach { toggleItemSelection(false, it) } (min until to).filter { it != from }.forEach { toggleItemSelection(false, it, true) } } if (max > -1) { for (i in from + 1..max) { toggleItemSelection(false, i) toggleItemSelection(false, i, true) } } } else { for (i in from..to) { toggleItemSelection(true, i) toggleItemSelection(true, i, true) } if (max > -1 && max > to) { (to + 1..max).filter { it != from }.forEach { toggleItemSelection(false, it) } (to + 1..max).filter { it != from }.forEach { toggleItemSelection(false, it, true) } } if (min > -1) { for (i in min until from) { toggleItemSelection(false, i) toggleItemSelection(false, i, true) } } } Loading Loading @@ -295,7 +299,7 @@ abstract class MyRecyclerViewAdapter(val activity: BaseSimpleActivity, val recyc if (actModeCallback.isSelectable) { val currentPosition = adapterPosition - positionOffset val isSelected = selectedKeys.contains(getItemSelectionKey(currentPosition)) toggleItemSelection(!isSelected, currentPosition) toggleItemSelection(!isSelected, currentPosition, true) } else { itemClick.invoke(any) } Loading @@ -308,7 +312,7 @@ abstract class MyRecyclerViewAdapter(val activity: BaseSimpleActivity, val recyc activity.startSupportActionMode(actModeCallback) } toggleItemSelection(true, currentPosition) toggleItemSelection(true, currentPosition, true) itemLongClicked(currentPosition) } } Loading commons/src/main/kotlin/com/simplemobiletools/commons/dialogs/FileConflictDialog.kt +1 −1 Original line number Diff line number Diff line Loading @@ -33,7 +33,7 @@ class FileConflictDialog(val activity: Activity, val fileDirItem: FileDirItem, v } AlertDialog.Builder(activity) .setPositiveButton(R.string.ok, { dialog, which -> dialogConfirmed() }) .setPositiveButton(R.string.ok) { dialog, which -> dialogConfirmed() } .setNegativeButton(R.string.cancel, null) .create().apply { activity.setupDialogStuff(view, this) Loading commons/src/main/kotlin/com/simplemobiletools/commons/dialogs/RenameItemsDialog.kt 0 → 100644 +88 −0 Original line number Diff line number Diff line package com.simplemobiletools.commons.dialogs import androidx.appcompat.app.AlertDialog import com.simplemobiletools.commons.R import com.simplemobiletools.commons.activities.BaseSimpleActivity import com.simplemobiletools.commons.extensions.* import kotlinx.android.synthetic.main.dialog_rename_items.* import kotlinx.android.synthetic.main.dialog_rename_items.view.* import java.util.* class RenameItemsDialog(val activity: BaseSimpleActivity, val paths: ArrayList<String>, val callback: () -> Unit) { init { val view = activity.layoutInflater.inflate(R.layout.dialog_rename_items, null) AlertDialog.Builder(activity) .setPositiveButton(R.string.ok, null) .setNegativeButton(R.string.cancel, null) .create().apply { activity.setupDialogStuff(view, this, R.string.rename) { showKeyboard(view.rename_items_value) getButton(AlertDialog.BUTTON_POSITIVE).setOnClickListener { val valueToAdd = view.rename_items_value.value val append = view.rename_items_radio_group.checkedRadioButtonId == rename_items_radio_append.id if (valueToAdd.isEmpty()) { callback() dismiss() return@setOnClickListener } if (!valueToAdd.isAValidFilename()) { activity.toast(R.string.invalid_name) return@setOnClickListener } val validPaths = paths.filter { activity.getDoesFilePathExist(it) } val sdFilePath = validPaths.firstOrNull { activity.isPathOnSD(it) } ?: validPaths.firstOrNull() if (sdFilePath == null) { activity.toast(R.string.unknown_error_occurred) dismiss() return@setOnClickListener } var pathsCnt = validPaths.size activity.handleSAFDialog(sdFilePath) { for (path in validPaths) { val fullName = path.getFilenameFromPath() var dotAt = fullName.lastIndexOf(".") if (dotAt == -1) { dotAt = fullName.length } val name = fullName.substring(0, dotAt) val extension = if (fullName.contains(".")) ".${fullName.getFilenameExtension()}" else "" val newName = if (append) { "$name$valueToAdd$extension" } else { "$valueToAdd$fullName" } val newPath = "${path.getParentPath()}/$newName" if (activity.getDoesFilePathExist(newPath)) { continue } activity.renameFile(path, newPath) { if (it) { pathsCnt-- if (pathsCnt == 0) { callback() dismiss() } } else { activity.toast(R.string.unknown_error_occurred) dismiss() } } } } } } } } } commons/src/main/kotlin/com/simplemobiletools/commons/extensions/Activity.kt +5 −0 Original line number Diff line number Diff line Loading @@ -487,6 +487,11 @@ fun BaseSimpleActivity.deleteFile(fileDirItem: FileDirItem, allowDeleteFolder: B fun BaseSimpleActivity.deleteFileBg(fileDirItem: FileDirItem, allowDeleteFolder: Boolean = false, callback: ((wasSuccess: Boolean) -> Unit)? = null) { val path = fileDirItem.path val file = File(path) if (!file.canWrite()) { callback?.invoke(false) return } var fileDeleted = !path.startsWith(OTG_PATH) && ((!file.exists() && file.length() == 0L) || file.delete()) if (fileDeleted) { rescanDeletedPath(path) { Loading Loading
build.gradle +1 −1 Original line number Diff line number Diff line Loading @@ -7,7 +7,7 @@ buildscript { propMinSdkVersion = 21 propTargetSdkVersion = propCompileSdkVersion propVersionCode = 1 propVersionName = '5.1.6' propVersionName = '5.2.0' kotlin_version = '1.2.71' } Loading
commons/src/main/kotlin/com/simplemobiletools/commons/adapters/MyRecyclerViewAdapter.kt +23 −19 Original line number Diff line number Diff line Loading @@ -83,9 +83,10 @@ abstract class MyRecyclerViewAdapter(val activity: BaseSimpleActivity, val recyc (selectedKeys.clone() as HashSet<Int>).forEach { val position = getItemKeyPosition(it) if (position != -1) { toggleItemSelection(false, position) toggleItemSelection(false, position, false) } } updateTitle() selectedKeys.clear() actBarTextView?.text = "" actMode = null Loading @@ -94,7 +95,7 @@ abstract class MyRecyclerViewAdapter(val activity: BaseSimpleActivity, val recyc } } protected fun toggleItemSelection(select: Boolean, pos: Int) { protected fun toggleItemSelection(select: Boolean, pos: Int, updateTitle: Boolean = true) { if (select && !getIsItemSelectable(pos)) { return } Loading @@ -112,17 +113,18 @@ abstract class MyRecyclerViewAdapter(val activity: BaseSimpleActivity, val recyc notifyItemChanged(pos + positionOffset) if (updateTitle) { updateTitle() } if (selectedKeys.isEmpty()) { finishActMode() return } updateTitle(selectedKeys.size) } private fun updateTitle(cnt: Int) { private fun updateTitle() { val selectableItemCount = getSelectableItemCount() val selectedCount = Math.min(cnt, selectableItemCount) val selectedCount = Math.min(selectedKeys.size, selectableItemCount) val oldTitle = actBarTextView?.text val newTitle = "$selectedCount / $selectableItemCount" if (oldTitle != newTitle) { Loading @@ -139,8 +141,9 @@ abstract class MyRecyclerViewAdapter(val activity: BaseSimpleActivity, val recyc val min = Math.min(lastLongPressedItem, position) val max = Math.max(lastLongPressedItem, position) for (i in min..max) { toggleItemSelection(true, i) toggleItemSelection(true, i, false) } updateTitle() position } } Loading @@ -166,16 +169,17 @@ abstract class MyRecyclerViewAdapter(val activity: BaseSimpleActivity, val recyc protected fun selectAll() { val cnt = itemCount - positionOffset for (i in 0 until cnt) { toggleItemSelection(true, i) toggleItemSelection(true, i, false) } lastLongPressedItem = -1 updateTitle() } protected fun setupDragListener(enable: Boolean) { if (enable) { recyclerView.setupDragListener(object : MyRecyclerView.MyDragListener { override fun selectItem(position: Int) { toggleItemSelection(true, position) toggleItemSelection(true, position, true) } override fun selectRange(initialSelection: Int, lastDraggedIndex: Int, minReached: Int, maxReached: Int) { Loading @@ -190,36 +194,36 @@ abstract class MyRecyclerViewAdapter(val activity: BaseSimpleActivity, val recyc protected fun selectItemRange(from: Int, to: Int, min: Int, max: Int) { if (from == to) { (min..max).filter { it != from }.forEach { toggleItemSelection(false, it) } (min..max).filter { it != from }.forEach { toggleItemSelection(false, it, true) } return } if (to < from) { for (i in to..from) { toggleItemSelection(true, i) toggleItemSelection(true, i, true) } if (min > -1 && min < to) { (min until to).filter { it != from }.forEach { toggleItemSelection(false, it) } (min until to).filter { it != from }.forEach { toggleItemSelection(false, it, true) } } if (max > -1) { for (i in from + 1..max) { toggleItemSelection(false, i) toggleItemSelection(false, i, true) } } } else { for (i in from..to) { toggleItemSelection(true, i) toggleItemSelection(true, i, true) } if (max > -1 && max > to) { (to + 1..max).filter { it != from }.forEach { toggleItemSelection(false, it) } (to + 1..max).filter { it != from }.forEach { toggleItemSelection(false, it, true) } } if (min > -1) { for (i in min until from) { toggleItemSelection(false, i) toggleItemSelection(false, i, true) } } } Loading Loading @@ -295,7 +299,7 @@ abstract class MyRecyclerViewAdapter(val activity: BaseSimpleActivity, val recyc if (actModeCallback.isSelectable) { val currentPosition = adapterPosition - positionOffset val isSelected = selectedKeys.contains(getItemSelectionKey(currentPosition)) toggleItemSelection(!isSelected, currentPosition) toggleItemSelection(!isSelected, currentPosition, true) } else { itemClick.invoke(any) } Loading @@ -308,7 +312,7 @@ abstract class MyRecyclerViewAdapter(val activity: BaseSimpleActivity, val recyc activity.startSupportActionMode(actModeCallback) } toggleItemSelection(true, currentPosition) toggleItemSelection(true, currentPosition, true) itemLongClicked(currentPosition) } } Loading
commons/src/main/kotlin/com/simplemobiletools/commons/dialogs/FileConflictDialog.kt +1 −1 Original line number Diff line number Diff line Loading @@ -33,7 +33,7 @@ class FileConflictDialog(val activity: Activity, val fileDirItem: FileDirItem, v } AlertDialog.Builder(activity) .setPositiveButton(R.string.ok, { dialog, which -> dialogConfirmed() }) .setPositiveButton(R.string.ok) { dialog, which -> dialogConfirmed() } .setNegativeButton(R.string.cancel, null) .create().apply { activity.setupDialogStuff(view, this) Loading
commons/src/main/kotlin/com/simplemobiletools/commons/dialogs/RenameItemsDialog.kt 0 → 100644 +88 −0 Original line number Diff line number Diff line package com.simplemobiletools.commons.dialogs import androidx.appcompat.app.AlertDialog import com.simplemobiletools.commons.R import com.simplemobiletools.commons.activities.BaseSimpleActivity import com.simplemobiletools.commons.extensions.* import kotlinx.android.synthetic.main.dialog_rename_items.* import kotlinx.android.synthetic.main.dialog_rename_items.view.* import java.util.* class RenameItemsDialog(val activity: BaseSimpleActivity, val paths: ArrayList<String>, val callback: () -> Unit) { init { val view = activity.layoutInflater.inflate(R.layout.dialog_rename_items, null) AlertDialog.Builder(activity) .setPositiveButton(R.string.ok, null) .setNegativeButton(R.string.cancel, null) .create().apply { activity.setupDialogStuff(view, this, R.string.rename) { showKeyboard(view.rename_items_value) getButton(AlertDialog.BUTTON_POSITIVE).setOnClickListener { val valueToAdd = view.rename_items_value.value val append = view.rename_items_radio_group.checkedRadioButtonId == rename_items_radio_append.id if (valueToAdd.isEmpty()) { callback() dismiss() return@setOnClickListener } if (!valueToAdd.isAValidFilename()) { activity.toast(R.string.invalid_name) return@setOnClickListener } val validPaths = paths.filter { activity.getDoesFilePathExist(it) } val sdFilePath = validPaths.firstOrNull { activity.isPathOnSD(it) } ?: validPaths.firstOrNull() if (sdFilePath == null) { activity.toast(R.string.unknown_error_occurred) dismiss() return@setOnClickListener } var pathsCnt = validPaths.size activity.handleSAFDialog(sdFilePath) { for (path in validPaths) { val fullName = path.getFilenameFromPath() var dotAt = fullName.lastIndexOf(".") if (dotAt == -1) { dotAt = fullName.length } val name = fullName.substring(0, dotAt) val extension = if (fullName.contains(".")) ".${fullName.getFilenameExtension()}" else "" val newName = if (append) { "$name$valueToAdd$extension" } else { "$valueToAdd$fullName" } val newPath = "${path.getParentPath()}/$newName" if (activity.getDoesFilePathExist(newPath)) { continue } activity.renameFile(path, newPath) { if (it) { pathsCnt-- if (pathsCnt == 0) { callback() dismiss() } } else { activity.toast(R.string.unknown_error_occurred) dismiss() } } } } } } } } }
commons/src/main/kotlin/com/simplemobiletools/commons/extensions/Activity.kt +5 −0 Original line number Diff line number Diff line Loading @@ -487,6 +487,11 @@ fun BaseSimpleActivity.deleteFile(fileDirItem: FileDirItem, allowDeleteFolder: B fun BaseSimpleActivity.deleteFileBg(fileDirItem: FileDirItem, allowDeleteFolder: Boolean = false, callback: ((wasSuccess: Boolean) -> Unit)? = null) { val path = fileDirItem.path val file = File(path) if (!file.canWrite()) { callback?.invoke(false) return } var fileDeleted = !path.startsWith(OTG_PATH) && ((!file.exists() && file.length() == 0L) || file.delete()) if (fileDeleted) { rescanDeletedPath(path) { Loading