Skip to content

Commit f08f747

Browse files
committed
updating Commons with the new way of handling OTG files
1 parent 3a47c2a commit f08f747

File tree

10 files changed

+28
-38
lines changed

10 files changed

+28
-38
lines changed

app/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ android {
5151
}
5252

5353
dependencies {
54-
implementation 'com.simplemobiletools:commons:5.7.5'
54+
implementation 'com.simplemobiletools:commons:5.8.2'
5555
implementation 'com.github.Stericson:RootTools:df729dcb13'
5656
implementation 'com.alexvasilkov:gesture-views:2.5.2'
5757
}

app/src/main/kotlin/com/simplemobiletools/filemanager/pro/activities/MainActivity.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ class MainActivity : SimpleActivity() {
183183
val file = File(path)
184184
if (file.exists() && !file.isDirectory) {
185185
newPath = file.parent
186-
} else if (!file.exists() && !newPath.startsWith(OTG_PATH)) {
186+
} else if (!file.exists() && !isPathOnOTG(newPath)) {
187187
newPath = internalStoragePath
188188
}
189189

@@ -290,7 +290,7 @@ class MainActivity : SimpleActivity() {
290290
private fun checkInvalidFavorites() {
291291
Thread {
292292
config.favorites.forEach {
293-
if (!it.startsWith(OTG_PATH) && !isPathOnSD(it) && !getDoesFilePathExist(it)) {
293+
if (!isPathOnOTG(it) && !isPathOnSD(it) && !File(it).exists()) {
294294
config.removeFavorite(it)
295295
}
296296
}

app/src/main/kotlin/com/simplemobiletools/filemanager/pro/adapters/ItemsAdapter.kt

Lines changed: 10 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ import com.simplemobiletools.commons.dialogs.*
1717
import com.simplemobiletools.commons.extensions.*
1818
import com.simplemobiletools.commons.helpers.CONFLICT_OVERWRITE
1919
import com.simplemobiletools.commons.helpers.CONFLICT_SKIP
20-
import com.simplemobiletools.commons.helpers.OTG_PATH
2120
import com.simplemobiletools.commons.models.FileDirItem
2221
import com.simplemobiletools.commons.models.RadioItem
2322
import com.simplemobiletools.commons.views.FastScroller
@@ -203,9 +202,9 @@ class ItemsAdapter(activity: SimpleActivity, var fileDirItems: MutableList<FileD
203202
}
204203

205204
private fun addFileUris(path: String, paths: ArrayList<String>) {
206-
if (activity.getIsPathDirectory(path)) {
205+
if (File(path).isDirectory) {
207206
val shouldShowHidden = activity.config.shouldShowHidden
208-
if (path.startsWith(OTG_PATH)) {
207+
if (activity.isPathOnOTG(path)) {
209208
activity.getDocumentFile(path)?.listFiles()?.filter { if (shouldShowHidden) true else !it.name!!.startsWith(".") }?.forEach {
210209
addFileUris(it.uri.toString(), paths)
211210
}
@@ -285,17 +284,18 @@ class ItemsAdapter(activity: SimpleActivity, var fileDirItems: MutableList<FileD
285284

286285
private fun compressSelection() {
287286
val firstPath = getFirstSelectedItemPath()
288-
if (firstPath.startsWith(OTG_PATH)) {
287+
if (activity.isPathOnOTG(firstPath)) {
289288
activity.toast(R.string.unknown_error_occurred)
290289
return
291290
}
292291

293292
CompressAsDialog(activity, firstPath) {
293+
val destination = it
294294
activity.handleSAFDialog(firstPath) {
295295
activity.toast(R.string.compressing)
296296
val paths = getSelectedFileDirItems().map { it.path }
297297
Thread {
298-
if (compressPaths(paths, it)) {
298+
if (compressPaths(paths, destination)) {
299299
activity.runOnUiThread {
300300
activity.toast(R.string.compression_successful)
301301
listener?.refreshItems()
@@ -311,7 +311,7 @@ class ItemsAdapter(activity: SimpleActivity, var fileDirItems: MutableList<FileD
311311

312312
private fun decompressSelection() {
313313
val firstPath = getFirstSelectedItemPath()
314-
if (firstPath.startsWith(OTG_PATH)) {
314+
if (activity.isPathOnOTG(firstPath)) {
315315
activity.toast(R.string.unknown_error_occurred)
316316
return
317317
}
@@ -364,18 +364,14 @@ class ItemsAdapter(activity: SimpleActivity, var fileDirItems: MutableList<FileD
364364
val entries = zipFile.entries()
365365
while (entries.hasMoreElements()) {
366366
val entry = entries.nextElement()
367-
var parentPath = it.getParentPath()
368-
if (parentPath != OTG_PATH) {
369-
parentPath = "${parentPath.trimEnd('/')}/"
370-
}
371-
367+
val parentPath = it.getParentPath()
372368
val newPath = "$parentPath${entry.name.trimEnd('/')}"
373369

374370
val resolution = getConflictResolution(conflictResolutions, newPath)
375-
val doesPathExist = activity.getDoesFilePathExist(newPath)
371+
val doesPathExist = File(newPath).exists()
376372
if (doesPathExist && resolution == CONFLICT_OVERWRITE) {
377373
val fileDirItem = FileDirItem(newPath, newPath.getFilenameFromPath(), entry.isDirectory)
378-
if (activity.getIsPathDirectory(it)) {
374+
if (File(it).isDirectory) {
379375
activity.deleteFolderBg(fileDirItem, false) {
380376
if (it) {
381377
extractEntry(newPath, entry, zipFile)
@@ -406,7 +402,7 @@ class ItemsAdapter(activity: SimpleActivity, var fileDirItems: MutableList<FileD
406402

407403
private fun extractEntry(newPath: String, entry: ZipEntry, zipFile: ZipFile) {
408404
if (entry.isDirectory) {
409-
if (!activity.createDirectorySync(newPath) && !activity.getDoesFilePathExist(newPath)) {
405+
if (!activity.createDirectorySync(newPath) && !File(newPath).exists()) {
410406
val error = String.format(activity.getString(R.string.could_not_create_file), newPath)
411407
activity.showErrorToast(error)
412408
}
@@ -584,9 +580,6 @@ class ItemsAdapter(activity: SimpleActivity, var fileDirItems: MutableList<FileD
584580
}
585581

586582
if (!activity.isDestroyed) {
587-
if (hasOTGConnected && itemToLoad is String && itemToLoad.startsWith(OTG_PATH)) {
588-
itemToLoad = itemToLoad.getOTGPublicPath(activity)
589-
}
590583
Glide.with(activity).load(itemToLoad).transition(DrawableTransitionOptions.withCrossFade()).apply(options).into(item_icon)
591584
}
592585
}

app/src/main/kotlin/com/simplemobiletools/filemanager/pro/dialogs/CompressAsDialog.kt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,14 @@ import com.simplemobiletools.commons.extensions.*
88
import com.simplemobiletools.filemanager.pro.R
99
import com.simplemobiletools.filemanager.pro.extensions.config
1010
import kotlinx.android.synthetic.main.dialog_compress_as.view.*
11+
import java.io.File
1112

1213
class CompressAsDialog(val activity: BaseSimpleActivity, val path: String, val callback: (destination: String) -> Unit) {
1314
private val view = activity.layoutInflater.inflate(R.layout.dialog_compress_as, null)
1415

1516
init {
1617
val filename = path.getFilenameFromPath()
17-
val indexOfDot = if (filename.contains('.') && !activity.getIsPathDirectory(path)) filename.lastIndexOf(".") else filename.length
18+
val indexOfDot = if (filename.contains('.') && !File(path).isDirectory) filename.lastIndexOf(".") else filename.length
1819
val baseFilename = filename.substring(0, indexOfDot)
1920
var realPath = path.getParentPath()
2021

@@ -42,7 +43,7 @@ class CompressAsDialog(val activity: BaseSimpleActivity, val path: String, val c
4243
name.isEmpty() -> activity.toast(R.string.empty_name)
4344
name.isAValidFilename() -> {
4445
val newPath = "$realPath/$name.zip"
45-
if (activity.getDoesFilePathExist(newPath)) {
46+
if (File(newPath).exists()) {
4647
activity.toast(R.string.name_taken)
4748
return@OnClickListener
4849
}

app/src/main/kotlin/com/simplemobiletools/filemanager/pro/dialogs/CreateNewItemDialog.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ class CreateNewItemDialog(val activity: SimpleActivity, val path: String, val ca
2626
activity.toast(R.string.empty_name)
2727
} else if (name.isAValidFilename()) {
2828
val newPath = "$path/$name"
29-
if (activity.getDoesFilePathExist(newPath)) {
29+
if (File(newPath).exists()) {
3030
activity.toast(R.string.name_taken)
3131
return@OnClickListener
3232
}

app/src/main/kotlin/com/simplemobiletools/filemanager/pro/dialogs/SaveAsDialog.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import com.simplemobiletools.commons.dialogs.FilePickerDialog
77
import com.simplemobiletools.commons.extensions.*
88
import com.simplemobiletools.filemanager.pro.R
99
import kotlinx.android.synthetic.main.dialog_save_as.view.*
10+
import java.io.File
1011

1112
class SaveAsDialog(val activity: BaseSimpleActivity, var path: String, val callback: (savePath: String) -> Unit) {
1213

@@ -64,7 +65,7 @@ class SaveAsDialog(val activity: BaseSimpleActivity, var path: String, val callb
6465
return@setOnClickListener
6566
}
6667

67-
if (activity.getDoesFilePathExist(newPath)) {
68+
if (File(newPath).exists()) {
6869
val title = String.format(activity.getString(R.string.file_already_exists_overwrite), newFilename)
6970
ConfirmationDialog(activity, title) {
7071
callback(newPath)
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
package com.simplemobiletools.filemanager.pro.extensions
22

33
import android.content.Context
4-
import com.simplemobiletools.commons.extensions.hasExternalSDCard
5-
import com.simplemobiletools.commons.helpers.OTG_PATH
4+
import com.simplemobiletools.commons.extensions.isPathOnOTG
5+
import com.simplemobiletools.commons.extensions.isPathOnSD
66
import com.simplemobiletools.filemanager.pro.helpers.Config
77

88
val Context.config: Config get() = Config.newInstance(applicationContext)
99

10-
fun Context.isPathOnRoot(path: String) = !(path.startsWith(config.internalStoragePath) || path.startsWith(OTG_PATH) || (hasExternalSDCard() && path.startsWith(config.sdCardPath)))
10+
fun Context.isPathOnRoot(path: String) = !(path.startsWith(config.internalStoragePath) || isPathOnOTG(path) || (isPathOnSD(path)))

app/src/main/kotlin/com/simplemobiletools/filemanager/pro/fragments/ItemsFragment.kt

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import androidx.fragment.app.Fragment
99
import com.simplemobiletools.commons.activities.BaseSimpleActivity
1010
import com.simplemobiletools.commons.dialogs.StoragePickerDialog
1111
import com.simplemobiletools.commons.extensions.*
12-
import com.simplemobiletools.commons.helpers.OTG_PATH
1312
import com.simplemobiletools.commons.helpers.SORT_BY_SIZE
1413
import com.simplemobiletools.commons.models.FileDirItem
1514
import com.simplemobiletools.commons.views.Breadcrumbs
@@ -115,7 +114,7 @@ class ItemsFragment : Fragment(), ItemOperationsListener, Breadcrumbs.Breadcrumb
115114
return
116115
}
117116

118-
var realPath = if (path == OTG_PATH) OTG_PATH else path.trimEnd('/')
117+
var realPath = path.trimEnd('/')
119118
if (realPath.isEmpty()) {
120119
realPath = "/"
121120
}
@@ -174,12 +173,12 @@ class ItemsFragment : Fragment(), ItemOperationsListener, Breadcrumbs.Breadcrumb
174173
skipItemUpdating = false
175174
Thread {
176175
if (activity?.isDestroyed == false) {
177-
if (path.startsWith(OTG_PATH)) {
176+
/*if (path.startsWith(OTG_PATH)) {
178177
val getProperFileSize = context!!.config.sorting and SORT_BY_SIZE != 0
179178
context!!.getOTGItems(path, context!!.config.shouldShowHidden, getProperFileSize) {
180179
callback(path, it)
181180
}
182-
} else if (!context!!.config.enableRootAccess || !context!!.isPathOnRoot(path)) {
181+
} else */if (!context!!.config.enableRootAccess || !context!!.isPathOnRoot(path)) {
183182
getRegularItemsOf(path, callback)
184183
} else {
185184
RootHelpers(activity!!).getFiles(path, callback)

app/src/main/kotlin/com/simplemobiletools/filemanager/pro/helpers/Config.kt

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
package com.simplemobiletools.filemanager.pro.helpers
22

33
import android.content.Context
4-
import com.simplemobiletools.commons.extensions.getDocumentFile
54
import com.simplemobiletools.commons.extensions.getInternalStoragePath
65
import com.simplemobiletools.commons.helpers.BaseConfig
7-
import com.simplemobiletools.commons.helpers.OTG_PATH
86
import java.io.File
97

108
class Config(context: Context) : BaseConfig(context) {
@@ -25,9 +23,7 @@ class Config(context: Context) : BaseConfig(context) {
2523
var homeFolder: String
2624
get(): String {
2725
var path = prefs.getString(HOME_FOLDER, "")
28-
if (path.isEmpty() ||
29-
(path.startsWith(OTG_PATH) && context.getDocumentFile(path)?.isDirectory != true) ||
30-
(!path.startsWith(OTG_PATH) && !File(path).isDirectory)) {
26+
if (path.isEmpty() || !File(path).isDirectory) {
3127
path = context.getInternalStoragePath()
3228
homeFolder = path
3329
}

build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
// Top-level build file where you can add configuration options common to all sub-projects/modules.
22

33
buildscript {
4-
ext.kotlin_version = '1.3.20'
4+
ext.kotlin_version = '1.3.21'
55

66
repositories {
77
google()
88
jcenter()
99
}
1010

1111
dependencies {
12-
classpath 'com.android.tools.build:gradle:3.3.0'
12+
classpath 'com.android.tools.build:gradle:3.3.1'
1313
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
1414

1515
// NOTE: Do not place your application dependencies here; they belong

0 commit comments

Comments
 (0)