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

Commit fc3c4167 authored by tibbi's avatar tibbi
Browse files

add a helper function for checking if a path represents a directory

parent 0a0c5156
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -6,7 +6,7 @@ buildscript {
        propMinSdkVersion = 16
        propTargetSdkVersion = propCompileSdkVersion
        propVersionCode = 1
        propVersionName = '3.11.45'
        propVersionName = '3.11.46'
        kotlin_version = '1.2.21'
        support_libs = '27.0.2'
    }
+10 −2
Original line number Diff line number Diff line
@@ -2,9 +2,8 @@ package com.simplemobiletools.commons.extensions

import android.content.Context
import android.media.ExifInterface
import com.simplemobiletools.commons.R.string.name
import com.simplemobiletools.commons.R.string.path
import com.simplemobiletools.commons.helpers.OTG_PATH
import java.io.File
import java.text.SimpleDateFormat
import java.util.*

@@ -51,6 +50,7 @@ fun String.isDng() = endsWith(".dng", true)

// fast extension checks, not guaranteed to be accurate
fun String.isVideoFast() = videoExtensions.any { endsWith(it, true) }

fun String.isImageFast() = photoExtensions.any { endsWith(it, true) }
fun String.isAudioFast() = audioExtensions.any { endsWith(it, true) }

@@ -126,6 +126,14 @@ fun String.getGenericMimeType(): String {

fun String.getParentPath() = substring(0, length - getFilenameFromPath().length)

fun String.getIsDirectory(context: Context): Boolean {
    return if (context.isPathOnOTG(this)) {
        context.getSomeDocumentFile(this)?.isDirectory ?: false
    } else {
        File(this).isDirectory
    }
}

fun String.getMimeTypeFromPath(): String {
    val typesMap = HashMap<String, String>().apply {
        put("323", "text/h323")