updating Commons with the new way of handling OTG files

This commit is contained in:
tibbi 2019-02-16 17:57:24 +01:00
parent 3a47c2af33
commit f08f7474ae
10 changed files with 28 additions and 38 deletions

View File

@ -51,7 +51,7 @@ android {
}
dependencies {
implementation 'com.simplemobiletools:commons:5.7.5'
implementation 'com.simplemobiletools:commons:5.8.2'
implementation 'com.github.Stericson:RootTools:df729dcb13'
implementation 'com.alexvasilkov:gesture-views:2.5.2'
}

View File

@ -183,7 +183,7 @@ class MainActivity : SimpleActivity() {
val file = File(path)
if (file.exists() && !file.isDirectory) {
newPath = file.parent
} else if (!file.exists() && !newPath.startsWith(OTG_PATH)) {
} else if (!file.exists() && !isPathOnOTG(newPath)) {
newPath = internalStoragePath
}
@ -290,7 +290,7 @@ class MainActivity : SimpleActivity() {
private fun checkInvalidFavorites() {
Thread {
config.favorites.forEach {
if (!it.startsWith(OTG_PATH) && !isPathOnSD(it) && !getDoesFilePathExist(it)) {
if (!isPathOnOTG(it) && !isPathOnSD(it) && !File(it).exists()) {
config.removeFavorite(it)
}
}

View File

@ -17,7 +17,6 @@ import com.simplemobiletools.commons.dialogs.*
import com.simplemobiletools.commons.extensions.*
import com.simplemobiletools.commons.helpers.CONFLICT_OVERWRITE
import com.simplemobiletools.commons.helpers.CONFLICT_SKIP
import com.simplemobiletools.commons.helpers.OTG_PATH
import com.simplemobiletools.commons.models.FileDirItem
import com.simplemobiletools.commons.models.RadioItem
import com.simplemobiletools.commons.views.FastScroller
@ -203,9 +202,9 @@ class ItemsAdapter(activity: SimpleActivity, var fileDirItems: MutableList<FileD
}
private fun addFileUris(path: String, paths: ArrayList<String>) {
if (activity.getIsPathDirectory(path)) {
if (File(path).isDirectory) {
val shouldShowHidden = activity.config.shouldShowHidden
if (path.startsWith(OTG_PATH)) {
if (activity.isPathOnOTG(path)) {
activity.getDocumentFile(path)?.listFiles()?.filter { if (shouldShowHidden) true else !it.name!!.startsWith(".") }?.forEach {
addFileUris(it.uri.toString(), paths)
}
@ -285,17 +284,18 @@ class ItemsAdapter(activity: SimpleActivity, var fileDirItems: MutableList<FileD
private fun compressSelection() {
val firstPath = getFirstSelectedItemPath()
if (firstPath.startsWith(OTG_PATH)) {
if (activity.isPathOnOTG(firstPath)) {
activity.toast(R.string.unknown_error_occurred)
return
}
CompressAsDialog(activity, firstPath) {
val destination = it
activity.handleSAFDialog(firstPath) {
activity.toast(R.string.compressing)
val paths = getSelectedFileDirItems().map { it.path }
Thread {
if (compressPaths(paths, it)) {
if (compressPaths(paths, destination)) {
activity.runOnUiThread {
activity.toast(R.string.compression_successful)
listener?.refreshItems()
@ -311,7 +311,7 @@ class ItemsAdapter(activity: SimpleActivity, var fileDirItems: MutableList<FileD
private fun decompressSelection() {
val firstPath = getFirstSelectedItemPath()
if (firstPath.startsWith(OTG_PATH)) {
if (activity.isPathOnOTG(firstPath)) {
activity.toast(R.string.unknown_error_occurred)
return
}
@ -364,18 +364,14 @@ class ItemsAdapter(activity: SimpleActivity, var fileDirItems: MutableList<FileD
val entries = zipFile.entries()
while (entries.hasMoreElements()) {
val entry = entries.nextElement()
var parentPath = it.getParentPath()
if (parentPath != OTG_PATH) {
parentPath = "${parentPath.trimEnd('/')}/"
}
val parentPath = it.getParentPath()
val newPath = "$parentPath${entry.name.trimEnd('/')}"
val resolution = getConflictResolution(conflictResolutions, newPath)
val doesPathExist = activity.getDoesFilePathExist(newPath)
val doesPathExist = File(newPath).exists()
if (doesPathExist && resolution == CONFLICT_OVERWRITE) {
val fileDirItem = FileDirItem(newPath, newPath.getFilenameFromPath(), entry.isDirectory)
if (activity.getIsPathDirectory(it)) {
if (File(it).isDirectory) {
activity.deleteFolderBg(fileDirItem, false) {
if (it) {
extractEntry(newPath, entry, zipFile)
@ -406,7 +402,7 @@ class ItemsAdapter(activity: SimpleActivity, var fileDirItems: MutableList<FileD
private fun extractEntry(newPath: String, entry: ZipEntry, zipFile: ZipFile) {
if (entry.isDirectory) {
if (!activity.createDirectorySync(newPath) && !activity.getDoesFilePathExist(newPath)) {
if (!activity.createDirectorySync(newPath) && !File(newPath).exists()) {
val error = String.format(activity.getString(R.string.could_not_create_file), newPath)
activity.showErrorToast(error)
}
@ -584,9 +580,6 @@ class ItemsAdapter(activity: SimpleActivity, var fileDirItems: MutableList<FileD
}
if (!activity.isDestroyed) {
if (hasOTGConnected && itemToLoad is String && itemToLoad.startsWith(OTG_PATH)) {
itemToLoad = itemToLoad.getOTGPublicPath(activity)
}
Glide.with(activity).load(itemToLoad).transition(DrawableTransitionOptions.withCrossFade()).apply(options).into(item_icon)
}
}

View File

@ -8,13 +8,14 @@ import com.simplemobiletools.commons.extensions.*
import com.simplemobiletools.filemanager.pro.R
import com.simplemobiletools.filemanager.pro.extensions.config
import kotlinx.android.synthetic.main.dialog_compress_as.view.*
import java.io.File
class CompressAsDialog(val activity: BaseSimpleActivity, val path: String, val callback: (destination: String) -> Unit) {
private val view = activity.layoutInflater.inflate(R.layout.dialog_compress_as, null)
init {
val filename = path.getFilenameFromPath()
val indexOfDot = if (filename.contains('.') && !activity.getIsPathDirectory(path)) filename.lastIndexOf(".") else filename.length
val indexOfDot = if (filename.contains('.') && !File(path).isDirectory) filename.lastIndexOf(".") else filename.length
val baseFilename = filename.substring(0, indexOfDot)
var realPath = path.getParentPath()
@ -42,7 +43,7 @@ class CompressAsDialog(val activity: BaseSimpleActivity, val path: String, val c
name.isEmpty() -> activity.toast(R.string.empty_name)
name.isAValidFilename() -> {
val newPath = "$realPath/$name.zip"
if (activity.getDoesFilePathExist(newPath)) {
if (File(newPath).exists()) {
activity.toast(R.string.name_taken)
return@OnClickListener
}

View File

@ -26,7 +26,7 @@ class CreateNewItemDialog(val activity: SimpleActivity, val path: String, val ca
activity.toast(R.string.empty_name)
} else if (name.isAValidFilename()) {
val newPath = "$path/$name"
if (activity.getDoesFilePathExist(newPath)) {
if (File(newPath).exists()) {
activity.toast(R.string.name_taken)
return@OnClickListener
}

View File

@ -7,6 +7,7 @@ import com.simplemobiletools.commons.dialogs.FilePickerDialog
import com.simplemobiletools.commons.extensions.*
import com.simplemobiletools.filemanager.pro.R
import kotlinx.android.synthetic.main.dialog_save_as.view.*
import java.io.File
class SaveAsDialog(val activity: BaseSimpleActivity, var path: String, val callback: (savePath: String) -> Unit) {
@ -64,7 +65,7 @@ class SaveAsDialog(val activity: BaseSimpleActivity, var path: String, val callb
return@setOnClickListener
}
if (activity.getDoesFilePathExist(newPath)) {
if (File(newPath).exists()) {
val title = String.format(activity.getString(R.string.file_already_exists_overwrite), newFilename)
ConfirmationDialog(activity, title) {
callback(newPath)

View File

@ -1,10 +1,10 @@
package com.simplemobiletools.filemanager.pro.extensions
import android.content.Context
import com.simplemobiletools.commons.extensions.hasExternalSDCard
import com.simplemobiletools.commons.helpers.OTG_PATH
import com.simplemobiletools.commons.extensions.isPathOnOTG
import com.simplemobiletools.commons.extensions.isPathOnSD
import com.simplemobiletools.filemanager.pro.helpers.Config
val Context.config: Config get() = Config.newInstance(applicationContext)
fun Context.isPathOnRoot(path: String) = !(path.startsWith(config.internalStoragePath) || path.startsWith(OTG_PATH) || (hasExternalSDCard() && path.startsWith(config.sdCardPath)))
fun Context.isPathOnRoot(path: String) = !(path.startsWith(config.internalStoragePath) || isPathOnOTG(path) || (isPathOnSD(path)))

View File

@ -9,7 +9,6 @@ import androidx.fragment.app.Fragment
import com.simplemobiletools.commons.activities.BaseSimpleActivity
import com.simplemobiletools.commons.dialogs.StoragePickerDialog
import com.simplemobiletools.commons.extensions.*
import com.simplemobiletools.commons.helpers.OTG_PATH
import com.simplemobiletools.commons.helpers.SORT_BY_SIZE
import com.simplemobiletools.commons.models.FileDirItem
import com.simplemobiletools.commons.views.Breadcrumbs
@ -115,7 +114,7 @@ class ItemsFragment : Fragment(), ItemOperationsListener, Breadcrumbs.Breadcrumb
return
}
var realPath = if (path == OTG_PATH) OTG_PATH else path.trimEnd('/')
var realPath = path.trimEnd('/')
if (realPath.isEmpty()) {
realPath = "/"
}
@ -174,12 +173,12 @@ class ItemsFragment : Fragment(), ItemOperationsListener, Breadcrumbs.Breadcrumb
skipItemUpdating = false
Thread {
if (activity?.isDestroyed == false) {
if (path.startsWith(OTG_PATH)) {
/*if (path.startsWith(OTG_PATH)) {
val getProperFileSize = context!!.config.sorting and SORT_BY_SIZE != 0
context!!.getOTGItems(path, context!!.config.shouldShowHidden, getProperFileSize) {
callback(path, it)
}
} else if (!context!!.config.enableRootAccess || !context!!.isPathOnRoot(path)) {
} else */if (!context!!.config.enableRootAccess || !context!!.isPathOnRoot(path)) {
getRegularItemsOf(path, callback)
} else {
RootHelpers(activity!!).getFiles(path, callback)

View File

@ -1,10 +1,8 @@
package com.simplemobiletools.filemanager.pro.helpers
import android.content.Context
import com.simplemobiletools.commons.extensions.getDocumentFile
import com.simplemobiletools.commons.extensions.getInternalStoragePath
import com.simplemobiletools.commons.helpers.BaseConfig
import com.simplemobiletools.commons.helpers.OTG_PATH
import java.io.File
class Config(context: Context) : BaseConfig(context) {
@ -25,9 +23,7 @@ class Config(context: Context) : BaseConfig(context) {
var homeFolder: String
get(): String {
var path = prefs.getString(HOME_FOLDER, "")
if (path.isEmpty() ||
(path.startsWith(OTG_PATH) && context.getDocumentFile(path)?.isDirectory != true) ||
(!path.startsWith(OTG_PATH) && !File(path).isDirectory)) {
if (path.isEmpty() || !File(path).isDirectory) {
path = context.getInternalStoragePath()
homeFolder = path
}

View File

@ -1,7 +1,7 @@
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
ext.kotlin_version = '1.3.20'
ext.kotlin_version = '1.3.21'
repositories {
google()
@ -9,7 +9,7 @@ buildscript {
}
dependencies {
classpath 'com.android.tools.build:gradle:3.3.0'
classpath 'com.android.tools.build:gradle:3.3.1'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
// NOTE: Do not place your application dependencies here; they belong