method renaming and reformat

This commit is contained in:
darthpaul
2021-11-14 22:19:28 +00:00
parent 627bbb519a
commit 781870e732
4 changed files with 37 additions and 46 deletions

View File

@@ -465,9 +465,9 @@ class ItemsAdapter(
CompressAsDialog(activity, firstPath) { CompressAsDialog(activity, firstPath) {
val destination = it val destination = it
activity.handlePrimaryAndroidSAFDialog(firstPath) { granted -> activity.handleAndroidSAFDialog(firstPath) { granted ->
if (!granted) { if (!granted) {
return@handlePrimaryAndroidSAFDialog return@handleAndroidSAFDialog
} }
activity.handleSAFDialog(firstPath) { activity.handleSAFDialog(firstPath) {
if (!it) { if (!it) {

View File

@@ -53,10 +53,10 @@ class CreateNewItemDialog(val activity: SimpleActivity, val path: String, val ca
when { when {
isRPlus() || path.startsWith(activity.internalStoragePath, true) -> { isRPlus() || path.startsWith(activity.internalStoragePath, true) -> {
if (activity.isRestrictedSAFOnlyRoot(path)) { if (activity.isRestrictedSAFOnlyRoot(path)) {
activity.handlePrimaryAndroidSAFDialog(path) { activity.handleAndroidSAFDialog(path) {
if (!it) { if (!it) {
callback(false) callback(false)
return@handlePrimaryAndroidSAFDialog return@handleAndroidSAFDialog
} }
if (activity.createAndroidSAFDirectory(path)) { if (activity.createAndroidSAFDirectory(path)) {
success(alertDialog) success(alertDialog)
@@ -103,10 +103,10 @@ class CreateNewItemDialog(val activity: SimpleActivity, val path: String, val ca
try { try {
when { when {
activity.isRestrictedSAFOnlyRoot(path) -> { activity.isRestrictedSAFOnlyRoot(path) -> {
activity.handlePrimaryAndroidSAFDialog(path) { activity.handleAndroidSAFDialog(path) {
if (!it) { if (!it) {
callback(false) callback(false)
return@handlePrimaryAndroidSAFDialog return@handleAndroidSAFDialog
} }
if (activity.createAndroidSAFFile(path)) { if (activity.createAndroidSAFFile(path)) {
success(alertDialog) success(alertDialog)

View File

@@ -162,7 +162,18 @@ class ItemsFragment(context: Context, attributeSet: AttributeSet) : MyViewPagerF
ensureBackgroundThread { ensureBackgroundThread {
if (activity?.isDestroyed == false && activity?.isFinishing == false) { if (activity?.isDestroyed == false && activity?.isFinishing == false) {
val config = context!!.config val config = context!!.config
if (context!!.isPathOnOTG(path) && config.OTGTreeUri.isNotEmpty()) { if (context.isRestrictedSAFOnlyRoot(path)) {
activity?.handleAndroidSAFDialog(path) {
if (!it) {
activity?.toast(R.string.no_storage_permissions)
return@handleAndroidSAFDialog
}
val getProperChildCount = context!!.config.getFolderViewType(currentPath) == VIEW_TYPE_LIST
context.getAndroidSAFFileItems(path, context.config.shouldShowHidden, getProperChildCount) { fileItems ->
callback(path, getListItemsFromFileDirItems(fileItems))
}
}
} else if (context!!.isPathOnOTG(path) && config.OTGTreeUri.isNotEmpty()) {
val getProperFileSize = context!!.config.getFolderSorting(currentPath) and SORT_BY_SIZE != 0 val getProperFileSize = context!!.config.getFolderSorting(currentPath) and SORT_BY_SIZE != 0
context!!.getOTGItems(path, config.shouldShowHidden, getProperFileSize) { context!!.getOTGItems(path, config.shouldShowHidden, getProperFileSize) {
callback(path, getListItemsFromFileDirItems(it)) callback(path, getListItemsFromFileDirItems(it))
@@ -178,52 +189,33 @@ class ItemsFragment(context: Context, attributeSet: AttributeSet) : MyViewPagerF
private fun getRegularItemsOf(path: String, callback: (originalPath: String, items: ArrayList<ListItem>) -> Unit) { private fun getRegularItemsOf(path: String, callback: (originalPath: String, items: ArrayList<ListItem>) -> Unit) {
val items = ArrayList<ListItem>() val items = ArrayList<ListItem>()
val files = File(path).listFiles()?.filterNotNull()
if (context == null) { if (context == null || files == null) {
callback(path, items) callback(path, items)
return return
} }
val isSortingBySize = context!!.config.getFolderSorting(currentPath) and SORT_BY_SIZE != 0 val isSortingBySize = context!!.config.getFolderSorting(currentPath) and SORT_BY_SIZE != 0
val getProperChildCount = context!!.config.getFolderViewType(currentPath) == VIEW_TYPE_LIST val getProperChildCount = context!!.config.getFolderViewType(currentPath) == VIEW_TYPE_LIST
val lastModifieds = context!!.getFolderLastModifieds(path)
if (context.isRestrictedSAFOnlyRoot(path)) { for (file in files) {
activity?.handlePrimaryAndroidSAFDialog(path) { val fileDirItem = getFileDirItemFromFile(file, isSortingBySize, lastModifieds, false)
if (!it) { if (fileDirItem != null) {
activity?.toast(R.string.no_storage_permissions) items.add(fileDirItem)
return@handlePrimaryAndroidSAFDialog
}
context.getAndroidSAFFileItems(path, context.config.shouldShowHidden, getProperChildCount) { fileItems ->
callback(path, getListItemsFromFileDirItems(fileItems))
}
} }
} else { }
val files = File(path).listFiles()?.filterNotNull()
if (files == null) {
callback(path, items)
return
}
val lastModifieds = context!!.getFolderLastModifieds(path)
for (file in files) { // send out the initial item list asap, get proper child count asynchronously as it can be slow
val fileDirItem = getFileDirItemFromFile(file, isSortingBySize, lastModifieds, false) callback(path, items)
if (fileDirItem != null) {
items.add(fileDirItem)
}
}
// send out the initial item list asap, get proper child count asynchronously as it can be slow if (getProperChildCount) {
callback(path, items) items.filter { it.mIsDirectory }.forEach {
if (context != null) {
if (getProperChildCount) { val childrenCount = it.getDirectChildrenCount(activity as BaseSimpleActivity, showHidden)
items.filter { it.mIsDirectory }.forEach { if (childrenCount != 0) {
if (context != null) { activity?.runOnUiThread {
val childrenCount = it.getDirectChildrenCount(activity as BaseSimpleActivity, showHidden) getRecyclerAdapter()?.updateChildCount(it.mPath, childrenCount)
if (childrenCount != 0) {
activity?.runOnUiThread {
getRecyclerAdapter()?.updateChildCount(it.mPath, childrenCount)
}
} }
} }
} }

View File

@@ -123,7 +123,7 @@ class RecentsFragment(context: Context, attributeSet: AttributeSet) : MyViewPage
) )
try { try {
val cursor = if (isOreoPlus()) { if (isOreoPlus()) {
val queryArgs = bundleOf( val queryArgs = bundleOf(
ContentResolver.QUERY_ARG_LIMIT to RECENTS_LIMIT, ContentResolver.QUERY_ARG_LIMIT to RECENTS_LIMIT,
ContentResolver.QUERY_ARG_SORT_COLUMNS to arrayOf(FileColumns.DATE_MODIFIED), ContentResolver.QUERY_ARG_SORT_COLUMNS to arrayOf(FileColumns.DATE_MODIFIED),
@@ -133,8 +133,7 @@ class RecentsFragment(context: Context, attributeSet: AttributeSet) : MyViewPage
} else { } else {
val sortOrder = "${FileColumns.DATE_MODIFIED} DESC LIMIT $RECENTS_LIMIT" val sortOrder = "${FileColumns.DATE_MODIFIED} DESC LIMIT $RECENTS_LIMIT"
context?.contentResolver?.query(uri, projection, null, null, sortOrder) context?.contentResolver?.query(uri, projection, null, null, sortOrder)
} }?.use { cursor ->
cursor?.use {
if (cursor.moveToFirst()) { if (cursor.moveToFirst()) {
do { do {
val path = cursor.getStringValue(FileColumns.DATA) val path = cursor.getStringValue(FileColumns.DATA)