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

Unverified Commit 2ae7f719 authored by solokot's avatar solokot Committed by GitHub
Browse files

Merge pull request #29 from SimpleMobileTools/master

upd
parents 85cd160a d76dcd5e
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -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'
    }
+1 −1
Original line number Diff line number Diff line
@@ -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)
+2 −2
Original line number Diff line number Diff line
@@ -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) }
+2 −2
Original line number Diff line number Diff line
@@ -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())
                        }
@@ -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)
                }
+28 −31
Original line number Diff line number Diff line
@@ -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
@@ -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> {
@@ -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))
@@ -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