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

Commit 45745625 authored by tibbi's avatar tibbi
Browse files

adding a couple more cosmetic changes

parent 9ffd1a04
Loading
Loading
Loading
Loading
+0 −3
Original line number Diff line number Diff line
package com.simplemobiletools.commons.activities

import android.annotation.SuppressLint
import android.app.Activity
import android.app.ActivityManager
import android.content.Context
@@ -192,10 +191,8 @@ abstract class BaseSimpleActivity : AppCompatActivity() {

    private fun isProperOTGFolder(uri: Uri) = isExternalStorageDocument(uri) && isRootUri(uri) && !isInternalStorage(uri)

    @SuppressLint("NewApi")
    private fun isRootUri(uri: Uri) = DocumentsContract.getTreeDocumentId(uri).endsWith(":")

    @SuppressLint("NewApi")
    private fun isInternalStorage(uri: Uri) = isExternalStorageDocument(uri) && DocumentsContract.getTreeDocumentId(uri).contains("primary")

    private fun isExternalStorageDocument(uri: Uri) = "com.android.externalstorage.documents" == uri.authority
+5 −7
Original line number Diff line number Diff line
@@ -82,7 +82,6 @@ fun AppCompatActivity.updateActionBarSubtitle(text: String) {
    supportActionBar?.subtitle = Html.fromHtml("<font color='${baseConfig.primaryColor.getContrastColor().toHex()}'>$text</font>")
}

@SuppressLint("NewApi")
fun Activity.appLaunched(appId: String) {
    baseConfig.internalStoragePath = getInternalStoragePath()
    updateSDCardPath()
@@ -483,7 +482,6 @@ fun BaseSimpleActivity.deleteFile(fileDirItem: FileDirItem, allowDeleteFolder: B
    }
}

@SuppressLint("NewApi")
fun BaseSimpleActivity.deleteFileBg(fileDirItem: FileDirItem, allowDeleteFolder: Boolean = false, callback: ((wasSuccess: Boolean) -> Unit)? = null) {
    val path = fileDirItem.path
    val file = File(path)
@@ -547,7 +545,6 @@ fun Activity.rescanPaths(paths: ArrayList<String>, callback: (() -> Unit)? = nul
    applicationContext.rescanPaths(paths, callback)
}

@SuppressLint("NewApi")
fun BaseSimpleActivity.renameFile(oldPath: String, newPath: String, callback: ((success: Boolean) -> Unit)? = null) {
    if (needsStupidWritePermissions(newPath)) {
        handleSAFDialog(newPath) {
@@ -617,6 +614,7 @@ fun Activity.hideKeyboard() {
}

fun Activity.showKeyboard(et: EditText) {
    et.requestFocus()
    val imm = getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager
    imm.showSoftInput(et, InputMethodManager.SHOW_IMPLICIT)
}
@@ -683,7 +681,7 @@ fun BaseSimpleActivity.getFileOutputStreamSync(path: String, mimeType: String, p
        var documentFile = parentDocumentFile
        if (documentFile == null) {
            if (targetFile.parentFile.exists()) {
                documentFile = getDocumentFile(targetFile.parentFile.absolutePath)
                documentFile = getDocumentFile(targetFile.parent)
            } else {
                documentFile = getDocumentFile(targetFile.parentFile.parent)
                documentFile = documentFile!!.createDirectory(targetFile.parentFile.name)
@@ -804,7 +802,7 @@ fun Activity.setupDialogStuff(view: View, dialog: AlertDialog, titleId: Int = 0,
        getButton(AlertDialog.BUTTON_POSITIVE).setTextColor(baseConfig.textColor)
        getButton(AlertDialog.BUTTON_NEGATIVE).setTextColor(baseConfig.textColor)
        getButton(AlertDialog.BUTTON_NEUTRAL).setTextColor(baseConfig.textColor)
        window.setBackgroundDrawable(ColorDrawable(baseConfig.backgroundColor))
        window?.setBackgroundDrawable(ColorDrawable(baseConfig.backgroundColor))
    }
    callback?.invoke()
}
@@ -833,9 +831,9 @@ fun Activity.showPickSecondsDialog(curSeconds: Int, isSnoozePicker: Boolean = fa
    }

    val items = ArrayList<RadioItem>(seconds.size + 1)
    seconds.mapIndexedTo(items, { index, value ->
    seconds.mapIndexedTo(items) { index, value ->
        RadioItem(index, getFormattedSeconds(value, !isSnoozePicker), value)
    })
    }

    var selectedIndex = 0
    seconds.forEachIndexed { index, value ->
+0 −7
Original line number Diff line number Diff line
package com.simplemobiletools.commons.extensions

import android.annotation.SuppressLint
import android.content.ContentValues
import android.content.Context
import android.hardware.usb.UsbManager
@@ -58,7 +57,6 @@ fun Context.hasExternalSDCard() = sdCardPath.isNotEmpty()

fun Context.hasOTGConnected() = (getSystemService(Context.USB_SERVICE) as UsbManager).deviceList.isNotEmpty()

@SuppressLint("NewApi")
fun Context.getStorageDirectories(): Array<String> {
    val paths = HashSet<String>()
    val rawExternalStorage = System.getenv("EXTERNAL_STORAGE")
@@ -126,7 +124,6 @@ fun Context.isPathOnSD(path: String) = sdCardPath.isNotEmpty() && path.startsWit

fun Context.needsStupidWritePermissions(path: String) = (isPathOnSD(path) || path.startsWith(OTG_PATH))

@SuppressLint("NewApi")
fun Context.hasProperStoredTreeUri(): Boolean {
    val hasProperUri = contentResolver.persistedUriPermissions.any { it.uri.toString() == baseConfig.treeUri }
    if (!hasProperUri) {
@@ -148,7 +145,6 @@ fun Context.getMyFileUri(file: File): Uri {
    }
}

@SuppressLint("NewApi")
fun Context.tryFastDocumentDelete(path: String, allowDeleteFolder: Boolean): Boolean {
    val document = getFastDocumentFile(path)
    return if (document?.isFile == true || allowDeleteFolder) {
@@ -162,7 +158,6 @@ fun Context.tryFastDocumentDelete(path: String, allowDeleteFolder: Boolean): Boo
    }
}

@SuppressLint("NewApi")
fun Context.getFastDocumentFile(path: String): DocumentFile? {
    if (path.startsWith(OTG_PATH)) {
        return getOTGFastDocumentFile(path)
@@ -192,7 +187,6 @@ fun Context.getOTGFastDocumentFile(path: String): DocumentFile? {
    return DocumentFile.fromSingleUri(this, Uri.parse(fullUri))
}

@SuppressLint("NewApi")
fun Context.getDocumentFile(path: String): DocumentFile? {
    val isOTG = path.startsWith(OTG_PATH)
    var relativePath = path.substring(if (isOTG) OTG_PATH.length else sdCardPath.length)
@@ -394,7 +388,6 @@ fun Context.rescanDeletedPath(path: String, callback: (() -> Unit)? = null) {
    }
}

@SuppressLint("NewApi")
fun Context.trySAFFileDelete(fileDirItem: FileDirItem, allowDeleteFolder: Boolean = false, callback: ((wasSuccess: Boolean) -> Unit)? = null) {
    var fileDeleted = tryFastDocumentDelete(fileDirItem.path, allowDeleteFolder)
    if (!fileDeleted) {
+0 −3
Original line number Diff line number Diff line
package com.simplemobiletools.commons.extensions

import android.Manifest
import android.annotation.SuppressLint
import android.content.ComponentName
import android.content.ContentUris
import android.content.Context
@@ -104,7 +103,6 @@ val Context.baseConfig: BaseConfig get() = BaseConfig.newInstance(this)
val Context.sdCardPath: String get() = baseConfig.sdCardPath
val Context.internalStoragePath: String get() = baseConfig.internalStoragePath

@SuppressLint("InlinedApi", "NewApi")
fun Context.isFingerPrintSensorAvailable() = isMarshmallowPlus() && Reprint.isHardwarePresent()

fun Context.getLatestMediaId(uri: Uri = MediaStore.Files.getContentUri("external")): Long {
@@ -138,7 +136,6 @@ fun Context.getLatestMediaByDateId(uri: Uri = MediaStore.Files.getContentUri("ex
}

// some helper functions were taken from https://github.com/iPaulPro/aFileChooser/blob/master/aFileChooser/src/com/ipaulpro/afilechooser/utils/FileUtils.java
@SuppressLint("NewApi")
fun Context.getRealPathFromURI(uri: Uri): String? {
    if (uri.scheme == "file") {
        return uri.path
+1 −2
Original line number Diff line number Diff line
package com.simplemobiletools.commons.extensions

import android.media.ExifInterface
import java.io.IOException

fun ExifInterface.copyTo(destination: ExifInterface) {
    val attributes = arrayOf(
@@ -38,6 +37,6 @@ fun ExifInterface.copyTo(destination: ExifInterface) {

    try {
        destination.saveAttributes()
    } catch (ignored: IOException) {
    } catch (ignored: Exception) {
    }
}
Loading