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 { dependencies {
implementation 'com.simplemobiletools:commons:5.7.5' implementation 'com.simplemobiletools:commons:5.8.2'
implementation 'com.github.Stericson:RootTools:df729dcb13' implementation 'com.github.Stericson:RootTools:df729dcb13'
implementation 'com.alexvasilkov:gesture-views:2.5.2' implementation 'com.alexvasilkov:gesture-views:2.5.2'
} }

View File

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

View File

@ -17,7 +17,6 @@ import com.simplemobiletools.commons.dialogs.*
import com.simplemobiletools.commons.extensions.* import com.simplemobiletools.commons.extensions.*
import com.simplemobiletools.commons.helpers.CONFLICT_OVERWRITE import com.simplemobiletools.commons.helpers.CONFLICT_OVERWRITE
import com.simplemobiletools.commons.helpers.CONFLICT_SKIP 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.FileDirItem
import com.simplemobiletools.commons.models.RadioItem import com.simplemobiletools.commons.models.RadioItem
import com.simplemobiletools.commons.views.FastScroller 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>) { private fun addFileUris(path: String, paths: ArrayList<String>) {
if (activity.getIsPathDirectory(path)) { if (File(path).isDirectory) {
val shouldShowHidden = activity.config.shouldShowHidden 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 { activity.getDocumentFile(path)?.listFiles()?.filter { if (shouldShowHidden) true else !it.name!!.startsWith(".") }?.forEach {
addFileUris(it.uri.toString(), paths) addFileUris(it.uri.toString(), paths)
} }
@ -285,17 +284,18 @@ class ItemsAdapter(activity: SimpleActivity, var fileDirItems: MutableList<FileD
private fun compressSelection() { private fun compressSelection() {
val firstPath = getFirstSelectedItemPath() val firstPath = getFirstSelectedItemPath()
if (firstPath.startsWith(OTG_PATH)) { if (activity.isPathOnOTG(firstPath)) {
activity.toast(R.string.unknown_error_occurred) activity.toast(R.string.unknown_error_occurred)
return return
} }
CompressAsDialog(activity, firstPath) { CompressAsDialog(activity, firstPath) {
val destination = it
activity.handleSAFDialog(firstPath) { activity.handleSAFDialog(firstPath) {
activity.toast(R.string.compressing) activity.toast(R.string.compressing)
val paths = getSelectedFileDirItems().map { it.path } val paths = getSelectedFileDirItems().map { it.path }
Thread { Thread {
if (compressPaths(paths, it)) { if (compressPaths(paths, destination)) {
activity.runOnUiThread { activity.runOnUiThread {
activity.toast(R.string.compression_successful) activity.toast(R.string.compression_successful)
listener?.refreshItems() listener?.refreshItems()
@ -311,7 +311,7 @@ class ItemsAdapter(activity: SimpleActivity, var fileDirItems: MutableList<FileD
private fun decompressSelection() { private fun decompressSelection() {
val firstPath = getFirstSelectedItemPath() val firstPath = getFirstSelectedItemPath()
if (firstPath.startsWith(OTG_PATH)) { if (activity.isPathOnOTG(firstPath)) {
activity.toast(R.string.unknown_error_occurred) activity.toast(R.string.unknown_error_occurred)
return return
} }
@ -364,18 +364,14 @@ class ItemsAdapter(activity: SimpleActivity, var fileDirItems: MutableList<FileD
val entries = zipFile.entries() val entries = zipFile.entries()
while (entries.hasMoreElements()) { while (entries.hasMoreElements()) {
val entry = entries.nextElement() val entry = entries.nextElement()
var parentPath = it.getParentPath() val parentPath = it.getParentPath()
if (parentPath != OTG_PATH) {
parentPath = "${parentPath.trimEnd('/')}/"
}
val newPath = "$parentPath${entry.name.trimEnd('/')}" val newPath = "$parentPath${entry.name.trimEnd('/')}"
val resolution = getConflictResolution(conflictResolutions, newPath) val resolution = getConflictResolution(conflictResolutions, newPath)
val doesPathExist = activity.getDoesFilePathExist(newPath) val doesPathExist = File(newPath).exists()
if (doesPathExist && resolution == CONFLICT_OVERWRITE) { if (doesPathExist && resolution == CONFLICT_OVERWRITE) {
val fileDirItem = FileDirItem(newPath, newPath.getFilenameFromPath(), entry.isDirectory) val fileDirItem = FileDirItem(newPath, newPath.getFilenameFromPath(), entry.isDirectory)
if (activity.getIsPathDirectory(it)) { if (File(it).isDirectory) {
activity.deleteFolderBg(fileDirItem, false) { activity.deleteFolderBg(fileDirItem, false) {
if (it) { if (it) {
extractEntry(newPath, entry, zipFile) 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) { private fun extractEntry(newPath: String, entry: ZipEntry, zipFile: ZipFile) {
if (entry.isDirectory) { 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) val error = String.format(activity.getString(R.string.could_not_create_file), newPath)
activity.showErrorToast(error) activity.showErrorToast(error)
} }
@ -584,9 +580,6 @@ class ItemsAdapter(activity: SimpleActivity, var fileDirItems: MutableList<FileD
} }
if (!activity.isDestroyed) { 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) 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.R
import com.simplemobiletools.filemanager.pro.extensions.config import com.simplemobiletools.filemanager.pro.extensions.config
import kotlinx.android.synthetic.main.dialog_compress_as.view.* 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) { 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) private val view = activity.layoutInflater.inflate(R.layout.dialog_compress_as, null)
init { init {
val filename = path.getFilenameFromPath() 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) val baseFilename = filename.substring(0, indexOfDot)
var realPath = path.getParentPath() 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.isEmpty() -> activity.toast(R.string.empty_name)
name.isAValidFilename() -> { name.isAValidFilename() -> {
val newPath = "$realPath/$name.zip" val newPath = "$realPath/$name.zip"
if (activity.getDoesFilePathExist(newPath)) { if (File(newPath).exists()) {
activity.toast(R.string.name_taken) activity.toast(R.string.name_taken)
return@OnClickListener return@OnClickListener
} }

View File

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

View File

@ -7,6 +7,7 @@ import com.simplemobiletools.commons.dialogs.FilePickerDialog
import com.simplemobiletools.commons.extensions.* import com.simplemobiletools.commons.extensions.*
import com.simplemobiletools.filemanager.pro.R import com.simplemobiletools.filemanager.pro.R
import kotlinx.android.synthetic.main.dialog_save_as.view.* 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) { 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 return@setOnClickListener
} }
if (activity.getDoesFilePathExist(newPath)) { if (File(newPath).exists()) {
val title = String.format(activity.getString(R.string.file_already_exists_overwrite), newFilename) val title = String.format(activity.getString(R.string.file_already_exists_overwrite), newFilename)
ConfirmationDialog(activity, title) { ConfirmationDialog(activity, title) {
callback(newPath) callback(newPath)

View File

@ -1,10 +1,10 @@
package com.simplemobiletools.filemanager.pro.extensions package com.simplemobiletools.filemanager.pro.extensions
import android.content.Context import android.content.Context
import com.simplemobiletools.commons.extensions.hasExternalSDCard import com.simplemobiletools.commons.extensions.isPathOnOTG
import com.simplemobiletools.commons.helpers.OTG_PATH import com.simplemobiletools.commons.extensions.isPathOnSD
import com.simplemobiletools.filemanager.pro.helpers.Config import com.simplemobiletools.filemanager.pro.helpers.Config
val Context.config: Config get() = Config.newInstance(applicationContext) 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.activities.BaseSimpleActivity
import com.simplemobiletools.commons.dialogs.StoragePickerDialog import com.simplemobiletools.commons.dialogs.StoragePickerDialog
import com.simplemobiletools.commons.extensions.* import com.simplemobiletools.commons.extensions.*
import com.simplemobiletools.commons.helpers.OTG_PATH
import com.simplemobiletools.commons.helpers.SORT_BY_SIZE import com.simplemobiletools.commons.helpers.SORT_BY_SIZE
import com.simplemobiletools.commons.models.FileDirItem import com.simplemobiletools.commons.models.FileDirItem
import com.simplemobiletools.commons.views.Breadcrumbs import com.simplemobiletools.commons.views.Breadcrumbs
@ -115,7 +114,7 @@ class ItemsFragment : Fragment(), ItemOperationsListener, Breadcrumbs.Breadcrumb
return return
} }
var realPath = if (path == OTG_PATH) OTG_PATH else path.trimEnd('/') var realPath = path.trimEnd('/')
if (realPath.isEmpty()) { if (realPath.isEmpty()) {
realPath = "/" realPath = "/"
} }
@ -174,12 +173,12 @@ class ItemsFragment : Fragment(), ItemOperationsListener, Breadcrumbs.Breadcrumb
skipItemUpdating = false skipItemUpdating = false
Thread { Thread {
if (activity?.isDestroyed == false) { if (activity?.isDestroyed == false) {
if (path.startsWith(OTG_PATH)) { /*if (path.startsWith(OTG_PATH)) {
val getProperFileSize = context!!.config.sorting and SORT_BY_SIZE != 0 val getProperFileSize = context!!.config.sorting and SORT_BY_SIZE != 0
context!!.getOTGItems(path, context!!.config.shouldShowHidden, getProperFileSize) { context!!.getOTGItems(path, context!!.config.shouldShowHidden, getProperFileSize) {
callback(path, it) callback(path, it)
} }
} else if (!context!!.config.enableRootAccess || !context!!.isPathOnRoot(path)) { } else */if (!context!!.config.enableRootAccess || !context!!.isPathOnRoot(path)) {
getRegularItemsOf(path, callback) getRegularItemsOf(path, callback)
} else { } else {
RootHelpers(activity!!).getFiles(path, callback) RootHelpers(activity!!).getFiles(path, callback)

View File

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

View File

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