Skip to content

Commit

Permalink
Merge pull request #175 from DeKaN/fix-small-detekt-issues
Browse files Browse the repository at this point in the history
Fix some small detekt issues
  • Loading branch information
andrewtavis authored Oct 9, 2024
2 parents 039f12e + 54d62bc commit 0ce5921
Show file tree
Hide file tree
Showing 9 changed files with 37 additions and 44 deletions.
12 changes: 6 additions & 6 deletions app/src/main/java/be/scri/activities/BaseSimpleActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,7 @@ abstract class BaseSimpleActivity : AppCompatActivity() {
} else if (requestCode == OPEN_DOCUMENT_TREE_FOR_ANDROID_DATA_OR_OBB) {
if (resultCode == Activity.RESULT_OK && resultData != null && resultData.data != null) {
if (isProperAndroidRoot(checkedDocumentPath, resultData.data!!)) {
if (resultData.dataString == baseConfig.OTGTreeUri || resultData.dataString == baseConfig.sdTreeUri) {
if (resultData.dataString == baseConfig.otgTreeUri || resultData.dataString == baseConfig.sdTreeUri) {
val pathToSelect = createAndroidDataOrObbPath(checkedDocumentPath)
toast(getString(R.string.wrong_folder_selected, pathToSelect))
return
Expand Down Expand Up @@ -378,7 +378,7 @@ abstract class BaseSimpleActivity : AppCompatActivity() {
resultData.dataString!!.contains(partition)
)
if (isProperSDRootFolder(resultData.data!!) && isProperPartition) {
if (resultData.dataString == baseConfig.OTGTreeUri) {
if (resultData.dataString == baseConfig.otgTreeUri) {
toast(R.string.sd_card_usb_same)
return
}
Expand Down Expand Up @@ -416,9 +416,9 @@ abstract class BaseSimpleActivity : AppCompatActivity() {
toast(R.string.sd_card_usb_same)
return
}
baseConfig.OTGTreeUri = resultData.dataString!!
baseConfig.OTGPartition =
baseConfig.OTGTreeUri
baseConfig.otgTreeUri = resultData.dataString!!
baseConfig.otgPartition =
baseConfig.otgTreeUri
.removeSuffix("%3A")
.substringAfterLast('/')
.trimEnd('/')
Expand Down Expand Up @@ -589,7 +589,7 @@ abstract class BaseSimpleActivity : AppCompatActivity() {

fun handleOTGPermission(callback: (success: Boolean) -> Unit) {
hideKeyboard()
if (baseConfig.OTGTreeUri.isNotEmpty()) {
if (baseConfig.otgTreeUri.isNotEmpty()) {
callback(true)
return
}
Expand Down
7 changes: 4 additions & 3 deletions app/src/main/java/be/scri/extensions/Activity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ import be.scri.helpers.REQUEST_SET_AS
import be.scri.helpers.SIDELOADING_FALSE
import be.scri.helpers.SIDELOADING_TRUE
import be.scri.helpers.SILENT
import be.scri.helpers.STORE_URL
import be.scri.helpers.ensureBackgroundThread
import be.scri.helpers.isMarshmallowPlus
import be.scri.helpers.isOnMainThread
Expand Down Expand Up @@ -302,7 +303,7 @@ fun BaseSimpleActivity.isShowingAndroidSAFDialog(path: String): Boolean {
}

fun BaseSimpleActivity.isShowingOTGDialog(path: String): Boolean =
if (!isRPlus() && isPathOnOTG(path) && (baseConfig.OTGTreeUri.isEmpty() || !hasProperStoredTreeUri(true))) {
if (!isRPlus() && isPathOnOTG(path) && (baseConfig.otgTreeUri.isEmpty() || !hasProperStoredTreeUri(true))) {
showOTGPermissionDialog(path)
true
} else {
Expand Down Expand Up @@ -348,7 +349,7 @@ fun Activity.launchUpgradeToProIntent() {
try {
launchViewIntent("market://details?id=${baseConfig.appId.removeSuffix(".debug")}.pro")
} catch (ignored: Exception) {
launchViewIntent(getStoreUrl())
launchViewIntent(STORE_URL)
}
}

Expand All @@ -366,7 +367,7 @@ fun Activity.redirectToRateUs() {
try {
launchViewIntent("market://details?id=${packageName.removeSuffix(".debug")}")
} catch (ignored: ActivityNotFoundException) {
launchViewIntent(getStoreUrl())
launchViewIntent(STORE_URL)
}
}

Expand Down
4 changes: 1 addition & 3 deletions app/src/main/java/be/scri/extensions/CommonsContext.kt
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ fun Context.showErrorToast(
val Context.baseConfig: BaseConfig get() = BaseConfig.newInstance(this)
val Context.sdCardPath: String get() = baseConfig.sdCardPath
val Context.internalStoragePath: String get() = baseConfig.internalStoragePath
val Context.otgPath: String get() = baseConfig.OTGPath
val Context.otgPath: String get() = baseConfig.otgPath

val Context.targetSdkVersion: Int get() = applicationInfo.targetSdkVersion

Expand Down Expand Up @@ -722,8 +722,6 @@ fun Context.getCanAppBeUpgraded() = proPackages.contains(baseConfig.appId.remove

fun Context.getProUrl() = "https://play.google.com/store/apps/details?id=${baseConfig.appId.removeSuffix(".debug")}.pro"

fun Context.getStoreUrl() = "https://play.google.com/store/apps/"

fun Context.getTimeFormat() = if (baseConfig.use24HourFormat) TIME_FORMAT_24 else TIME_FORMAT_12

fun Context.getResolution(path: String): Point? =
Expand Down
40 changes: 20 additions & 20 deletions app/src/main/java/be/scri/extensions/ContextStorage.kt
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ fun Context.getSDCardPath(): String {
"/storage/emulated/0",
true,
) &&
(baseConfig.OTGPartition.isEmpty() || !it.endsWith(baseConfig.OTGPartition))
(baseConfig.otgPartition.isEmpty() || !it.endsWith(baseConfig.otgPartition))
}

val fullSDpattern = Pattern.compile(SD_OTG_PATTERN)
Expand Down Expand Up @@ -186,11 +186,11 @@ fun Context.needsStupidWritePermissions(path: String) = !isRPlus() && (isPathOnS
fun Context.isSDCardSetAsDefaultStorage() = sdCardPath.isNotEmpty() && Environment.getExternalStorageDirectory().absolutePath.equals(sdCardPath, true)

fun Context.hasProperStoredTreeUri(isOTG: Boolean): Boolean {
val uri = if (isOTG) baseConfig.OTGTreeUri else baseConfig.sdTreeUri
val uri = if (isOTG) baseConfig.otgTreeUri else baseConfig.sdTreeUri
val hasProperUri = contentResolver.persistedUriPermissions.any { it.uri.toString() == uri }
if (!hasProperUri) {
if (isOTG) {
baseConfig.OTGTreeUri = ""
baseConfig.otgTreeUri = ""
} else {
baseConfig.sdTreeUri = ""
}
Expand Down Expand Up @@ -318,22 +318,22 @@ fun Context.getOTGFastDocumentFile(
path: String,
otgPathToUse: String? = null,
): DocumentFile? {
if (baseConfig.OTGTreeUri.isEmpty()) {
if (baseConfig.otgTreeUri.isEmpty()) {
return null
}

val otgPath = otgPathToUse ?: baseConfig.OTGPath
if (baseConfig.OTGPartition.isEmpty()) {
baseConfig.OTGPartition =
baseConfig.OTGTreeUri
val otgPath = otgPathToUse ?: baseConfig.otgPath
if (baseConfig.otgPartition.isEmpty()) {
baseConfig.otgPartition =
baseConfig.otgTreeUri
.removeSuffix("%3A")
.substringAfterLast('/')
.trimEnd('/')
updateOTGPathFromPartition()
}

val relativePath = Uri.encode(path.substring(otgPath.length).trim('/'))
val fullUri = "${baseConfig.OTGTreeUri}/document/${baseConfig.OTGPartition}%3A$relativePath"
val fullUri = "${baseConfig.otgTreeUri}/document/${baseConfig.otgPartition}%3A$relativePath"
return DocumentFile.fromSingleUri(this, Uri.parse(fullUri))
}

Expand All @@ -345,7 +345,7 @@ fun Context.getDocumentFile(path: String): DocumentFile? {
}

return try {
val treeUri = Uri.parse(if (isOTG) baseConfig.OTGTreeUri else baseConfig.sdTreeUri)
val treeUri = Uri.parse(if (isOTG) baseConfig.otgTreeUri else baseConfig.sdTreeUri)
var document = DocumentFile.fromTreeUri(applicationContext, treeUri)
val parts = relativePath.split("/").filter { it.isNotEmpty() }
for (part in parts) {
Expand Down Expand Up @@ -537,15 +537,15 @@ fun Context.getOTGItems(
callback: (ArrayList<FileDirItem>) -> Unit,
) {
val items = ArrayList<FileDirItem>()
val otgTreeUri = baseConfig.OTGTreeUri
val otgTreeUri = baseConfig.otgTreeUri
var rootUri =
try {
DocumentFile.fromTreeUri(applicationContext, Uri.parse(otgTreeUri))
} catch (e: Exception) {
showErrorToast(e)
baseConfig.OTGPath = ""
baseConfig.OTGTreeUri = ""
baseConfig.OTGPartition = ""
baseConfig.otgPath = ""
baseConfig.otgTreeUri = ""
baseConfig.otgPartition = ""
null
}

Expand All @@ -572,7 +572,7 @@ fun Context.getOTGItems(

val files = rootUri!!.listFiles().filter { it.exists() }

val basePath = "${baseConfig.OTGTreeUri}/document/${baseConfig.OTGPartition}%3A"
val basePath = "${baseConfig.otgTreeUri}/document/${baseConfig.otgPartition}%3A"
for (file in files) {
val name = file.name ?: continue
if (!shouldShowHidden && name.startsWith(".")) {
Expand Down Expand Up @@ -960,20 +960,20 @@ fun Context.getFileInputStreamSync(path: String): InputStream? =
}

fun Context.updateOTGPathFromPartition() {
val otgPath = "/storage/${baseConfig.OTGPartition}"
baseConfig.OTGPath =
val otgPath = "/storage/${baseConfig.otgPartition}"
baseConfig.otgPath =
if (getOTGFastDocumentFile(otgPath, otgPath)?.exists() == true) {
"/storage/${baseConfig.OTGPartition}"
"/storage/${baseConfig.otgPartition}"
} else {
"/mnt/media_rw/${baseConfig.OTGPartition}"
"/mnt/media_rw/${baseConfig.otgPartition}"
}
}

fun Context.getDoesFilePathExist(
path: String,
otgPathToUse: String? = null,
): Boolean {
val otgPath = otgPathToUse ?: baseConfig.OTGPath
val otgPath = otgPathToUse ?: baseConfig.otgPath
return when {
isRestrictedSAFOnlyRoot(path) -> getFastAndroidSAFDocument(path)?.exists() ?: false
otgPath.isNotEmpty() && path.startsWith(otgPath) -> getOTGFastDocumentFile(path)?.exists() ?: false
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/java/be/scri/extensions/String.kt
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ fun String.isAValidFilename(): Boolean {
}

fun String.getOTGPublicPath(context: Context) =
"${context.baseConfig.OTGTreeUri}/document/${context.baseConfig.OTGPartition}%3A${substring(context.baseConfig.OTGPath.length).replace("/", "%2F")}"
"${context.baseConfig.otgTreeUri}/document/${context.baseConfig.otgPartition}%3A${substring(context.baseConfig.otgPath.length).replace("/", "%2F")}"

fun String.isMediaFile() = isImageFast() || isVideoFast() || isGif() || isRawFast() || isSvg() || isPortrait()

Expand Down
6 changes: 3 additions & 3 deletions app/src/main/java/be/scri/helpers/BaseConfig.kt
Original file line number Diff line number Diff line change
Expand Up @@ -56,15 +56,15 @@ open class BaseConfig(
get() = prefs.getString(SD_TREE_URI, "")!!
set(uri) = prefs.edit().putString(SD_TREE_URI, uri).apply()

var OTGTreeUri: String
var otgTreeUri: String
get() = prefs.getString(OTG_TREE_URI, "")!!
set(OTGTreeUri) = prefs.edit().putString(OTG_TREE_URI, OTGTreeUri).apply()

var OTGPartition: String
var otgPartition: String
get() = prefs.getString(OTG_PARTITION, "")!!
set(OTGPartition) = prefs.edit().putString(OTG_PARTITION, OTGPartition).apply()

var OTGPath: String
var otgPath: String
get() = prefs.getString(OTG_REAL_PATH, "")!!
set(OTGPath) = prefs.edit().putString(OTG_REAL_PATH, OTGPath).apply()

Expand Down
2 changes: 2 additions & 0 deletions app/src/main/java/be/scri/helpers/CommonsConstants.kt
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,8 @@ const val TAB_FILES = 16
const val TAB_RECENT_FILES = 32
const val TAB_STORAGE_ANALYSIS = 64

internal const val STORE_URL = "https://play.google.com/store/apps/"

val photoExtensions: Array<String> get() = arrayOf(".jpg", ".png", ".jpeg", ".bmp", ".webp", ".heic", ".heif", ".apng")
val videoExtensions: Array<String> get() = arrayOf(".mp4", ".mkv", ".webm", ".avi", ".3gp", ".mov", ".m4v", ".3gpp")
val audioExtensions: Array<String> get() = arrayOf(".mp3", ".wav", ".wma", ".ogg", ".m4a", ".opus", ".flac", ".aac")
Expand Down
8 changes: 0 additions & 8 deletions detekt.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@ style:
active: true
UnusedParameter:
active: true
FunctionOnlyReturningConstant:
active: false
UtilityClassWithPublicConstructor:
active: false

Expand All @@ -34,12 +32,6 @@ complexity:
LargeClass:
active: false

naming:
VariableNaming:
active: false
InvalidPackageDeclaration:
active: false

potential-bugs:
ImplicitDefaultLocale:
active: false
Expand Down

0 comments on commit 0ce5921

Please sign in to comment.