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.0.3' propVersionName = '4.0.19' kotlin_version = '1.2.41' support_libs = '27.1.1' } Loading commons/src/main/kotlin/com/simplemobiletools/commons/adapters/FilepickerItemsAdapter.kt +1 −1 Original line number Diff line number Diff line Loading @@ -37,7 +37,7 @@ class FilepickerItemsAdapter(activity: BaseSimpleActivity, val fileDirItems: Lis override fun onBindViewHolder(holder: MyRecyclerViewAdapter.ViewHolder, position: Int) { val fileDirItem = fileDirItems[position] val view = holder.bindView(fileDirItem, false) { itemView, layoutPosition -> val view = holder.bindView(fileDirItem, false) { itemView, adapterPosition -> setupView(itemView, fileDirItem) } bindViewHolder(holder, position, view) Loading commons/src/main/kotlin/com/simplemobiletools/commons/adapters/MyRecyclerViewAdapter.kt +2 −2 Original line number Diff line number Diff line Loading @@ -261,9 +261,9 @@ abstract class MyRecyclerViewAdapter(val activity: BaseSimpleActivity, val recyc open class ViewHolder(view: View, val adapterListener: MyAdapterListener? = null, val activity: BaseSimpleActivity? = null, val multiSelectorCallback: ModalMultiSelectorCallback? = null, val multiSelector: MultiSelector, val positionOffset: Int = 0, val itemClick: ((Any) -> (Unit))? = null) : SwappingHolder(view, multiSelector) { fun bindView(any: Any, allowLongClick: Boolean = true, callback: (itemView: View, layoutPosition: Int) -> Unit): View { fun bindView(any: Any, allowLongClick: Boolean = true, callback: (itemView: View, adapterPosition: Int) -> Unit): View { return itemView.apply { callback(this, layoutPosition) callback(this, adapterPosition) if (isClickable) { setOnClickListener { viewClicked(any) } Loading commons/src/main/kotlin/com/simplemobiletools/commons/extensions/Activity.kt +2 −2 Original line number Diff line number Diff line Loading @@ -524,7 +524,7 @@ fun BaseSimpleActivity.renameFile(oldPath: String, newPath: String, callback: (( val uri = DocumentsContract.renameDocument(applicationContext.contentResolver, document.uri, newPath.getFilenameFromPath()) if (document.uri != uri) { updateInMediaStore(oldPath, newPath) scanPaths(arrayListOf(oldPath, newPath)) { rescanPaths(arrayListOf(oldPath, newPath)) { if (!baseConfig.keepLastModified) { updateLastModified(newPath, System.currentTimeMillis()) } Loading @@ -547,7 +547,7 @@ fun BaseSimpleActivity.renameFile(oldPath: String, newPath: String, callback: (( } else if (File(oldPath).renameTo(File(newPath))) { if (File(newPath).isDirectory) { deleteFromMediaStore(oldPath) scanPath(newPath) { rescanPaths(arrayListOf(newPath)) { runOnUiThread { callback?.invoke(true) } Loading commons/src/main/kotlin/com/simplemobiletools/commons/extensions/Context-storage.kt +28 −31 Original line number Diff line number Diff line Loading @@ -3,7 +3,6 @@ package com.simplemobiletools.commons.extensions import android.annotation.SuppressLint import android.content.ContentValues import android.content.Context import android.content.ReceiverCallNotAllowedException import android.hardware.usb.UsbManager import android.media.MediaScannerConnection import android.net.Uri Loading Loading @@ -247,30 +246,11 @@ fun Context.scanPaths(paths: ArrayList<String>, callback: (() -> Unit)? = null) fun Context.rescanPaths(paths: ArrayList<String>, callback: (() -> Unit)? = null) { var cnt = paths.size var connection: MediaScannerConnection? = null val connectionClient = object : MediaScannerConnection.MediaScannerConnectionClient { override fun onMediaScannerConnected() { paths.forEach { if (connection?.isConnected == true) { connection?.scanFile(it, it.getMimeType()) } } } override fun onScanCompleted(path: String?, uri: Uri?) { MediaScannerConnection.scanFile(applicationContext, paths.toTypedArray(), null, { s, uri -> if (--cnt == 0) { connection?.disconnect() callback?.invoke() } } } connection = MediaScannerConnection(this, connectionClient) try { connection.connect() } catch (ignored: ReceiverCallNotAllowedException) { } }) } fun getPaths(file: File): ArrayList<String> { Loading Loading @@ -338,7 +318,7 @@ fun Context.updateLastModified(path: String, lastModified: Long) { } } fun Context.getOTGItems(path: String, countHiddenItems: Boolean, getProperFileSize: Boolean, callback: (ArrayList<FileDirItem>) -> Unit) { fun Context.getOTGItems(path: String, shouldShowHidden: Boolean, getProperFileSize: Boolean, callback: (ArrayList<FileDirItem>) -> Unit) { val items = ArrayList<FileDirItem>() val OTGTreeUri = baseConfig.OTGTreeUri var rootUri = DocumentFile.fromTreeUri(applicationContext, Uri.parse(OTGTreeUri)) Loading @@ -363,17 +343,34 @@ fun Context.getOTGItems(path: String, countHiddenItems: Boolean, getProperFileSi } } val files = rootUri.listFiles() val files = rootUri.listFiles().filter { it.exists() } val basePath = "${baseConfig.OTGTreeUri}/document/${baseConfig.OTGPartition}%3A" for (file in files) { if (file.exists()) { val name = file.name if (!shouldShowHidden && name.startsWith(".")) { continue } val isDirectory = file.isDirectory val filePath = file.uri.toString().substring(basePath.length) val decodedPath = OTG_PATH + "/" + URLDecoder.decode(filePath, "UTF-8") val fileSize = if (getProperFileSize) file.getItemSize(countHiddenItems) else file.length() items.add(FileDirItem(decodedPath, file.name, file.isDirectory, file.listFiles()?.size ?: 0, fileSize)) val fileSize = when { getProperFileSize -> file.getItemSize(shouldShowHidden) isDirectory -> 0L else -> file.length() } val childrenCount = if (isDirectory) { file.listFiles()?.size ?: 0 } else { 0 } val fileDirItem = FileDirItem(decodedPath, name, isDirectory, childrenCount, fileSize) items.add(fileDirItem) } callback(items) } 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.0.3' propVersionName = '4.0.19' kotlin_version = '1.2.41' support_libs = '27.1.1' } Loading
commons/src/main/kotlin/com/simplemobiletools/commons/adapters/FilepickerItemsAdapter.kt +1 −1 Original line number Diff line number Diff line Loading @@ -37,7 +37,7 @@ class FilepickerItemsAdapter(activity: BaseSimpleActivity, val fileDirItems: Lis override fun onBindViewHolder(holder: MyRecyclerViewAdapter.ViewHolder, position: Int) { val fileDirItem = fileDirItems[position] val view = holder.bindView(fileDirItem, false) { itemView, layoutPosition -> val view = holder.bindView(fileDirItem, false) { itemView, adapterPosition -> setupView(itemView, fileDirItem) } bindViewHolder(holder, position, view) Loading
commons/src/main/kotlin/com/simplemobiletools/commons/adapters/MyRecyclerViewAdapter.kt +2 −2 Original line number Diff line number Diff line Loading @@ -261,9 +261,9 @@ abstract class MyRecyclerViewAdapter(val activity: BaseSimpleActivity, val recyc open class ViewHolder(view: View, val adapterListener: MyAdapterListener? = null, val activity: BaseSimpleActivity? = null, val multiSelectorCallback: ModalMultiSelectorCallback? = null, val multiSelector: MultiSelector, val positionOffset: Int = 0, val itemClick: ((Any) -> (Unit))? = null) : SwappingHolder(view, multiSelector) { fun bindView(any: Any, allowLongClick: Boolean = true, callback: (itemView: View, layoutPosition: Int) -> Unit): View { fun bindView(any: Any, allowLongClick: Boolean = true, callback: (itemView: View, adapterPosition: Int) -> Unit): View { return itemView.apply { callback(this, layoutPosition) callback(this, adapterPosition) if (isClickable) { setOnClickListener { viewClicked(any) } Loading
commons/src/main/kotlin/com/simplemobiletools/commons/extensions/Activity.kt +2 −2 Original line number Diff line number Diff line Loading @@ -524,7 +524,7 @@ fun BaseSimpleActivity.renameFile(oldPath: String, newPath: String, callback: (( val uri = DocumentsContract.renameDocument(applicationContext.contentResolver, document.uri, newPath.getFilenameFromPath()) if (document.uri != uri) { updateInMediaStore(oldPath, newPath) scanPaths(arrayListOf(oldPath, newPath)) { rescanPaths(arrayListOf(oldPath, newPath)) { if (!baseConfig.keepLastModified) { updateLastModified(newPath, System.currentTimeMillis()) } Loading @@ -547,7 +547,7 @@ fun BaseSimpleActivity.renameFile(oldPath: String, newPath: String, callback: (( } else if (File(oldPath).renameTo(File(newPath))) { if (File(newPath).isDirectory) { deleteFromMediaStore(oldPath) scanPath(newPath) { rescanPaths(arrayListOf(newPath)) { runOnUiThread { callback?.invoke(true) } Loading
commons/src/main/kotlin/com/simplemobiletools/commons/extensions/Context-storage.kt +28 −31 Original line number Diff line number Diff line Loading @@ -3,7 +3,6 @@ package com.simplemobiletools.commons.extensions import android.annotation.SuppressLint import android.content.ContentValues import android.content.Context import android.content.ReceiverCallNotAllowedException import android.hardware.usb.UsbManager import android.media.MediaScannerConnection import android.net.Uri Loading Loading @@ -247,30 +246,11 @@ fun Context.scanPaths(paths: ArrayList<String>, callback: (() -> Unit)? = null) fun Context.rescanPaths(paths: ArrayList<String>, callback: (() -> Unit)? = null) { var cnt = paths.size var connection: MediaScannerConnection? = null val connectionClient = object : MediaScannerConnection.MediaScannerConnectionClient { override fun onMediaScannerConnected() { paths.forEach { if (connection?.isConnected == true) { connection?.scanFile(it, it.getMimeType()) } } } override fun onScanCompleted(path: String?, uri: Uri?) { MediaScannerConnection.scanFile(applicationContext, paths.toTypedArray(), null, { s, uri -> if (--cnt == 0) { connection?.disconnect() callback?.invoke() } } } connection = MediaScannerConnection(this, connectionClient) try { connection.connect() } catch (ignored: ReceiverCallNotAllowedException) { } }) } fun getPaths(file: File): ArrayList<String> { Loading Loading @@ -338,7 +318,7 @@ fun Context.updateLastModified(path: String, lastModified: Long) { } } fun Context.getOTGItems(path: String, countHiddenItems: Boolean, getProperFileSize: Boolean, callback: (ArrayList<FileDirItem>) -> Unit) { fun Context.getOTGItems(path: String, shouldShowHidden: Boolean, getProperFileSize: Boolean, callback: (ArrayList<FileDirItem>) -> Unit) { val items = ArrayList<FileDirItem>() val OTGTreeUri = baseConfig.OTGTreeUri var rootUri = DocumentFile.fromTreeUri(applicationContext, Uri.parse(OTGTreeUri)) Loading @@ -363,17 +343,34 @@ fun Context.getOTGItems(path: String, countHiddenItems: Boolean, getProperFileSi } } val files = rootUri.listFiles() val files = rootUri.listFiles().filter { it.exists() } val basePath = "${baseConfig.OTGTreeUri}/document/${baseConfig.OTGPartition}%3A" for (file in files) { if (file.exists()) { val name = file.name if (!shouldShowHidden && name.startsWith(".")) { continue } val isDirectory = file.isDirectory val filePath = file.uri.toString().substring(basePath.length) val decodedPath = OTG_PATH + "/" + URLDecoder.decode(filePath, "UTF-8") val fileSize = if (getProperFileSize) file.getItemSize(countHiddenItems) else file.length() items.add(FileDirItem(decodedPath, file.name, file.isDirectory, file.listFiles()?.size ?: 0, fileSize)) val fileSize = when { getProperFileSize -> file.getItemSize(shouldShowHidden) isDirectory -> 0L else -> file.length() } val childrenCount = if (isDirectory) { file.listFiles()?.size ?: 0 } else { 0 } val fileDirItem = FileDirItem(decodedPath, name, isDirectory, childrenCount, fileSize) items.add(fileDirItem) } callback(items) } Loading