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

Commit e19e0814 authored by tibbi's avatar tibbi
Browse files

add a getBubbleText helper function to FileDirItem model

parent 8462cddd
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -7,7 +7,7 @@ buildscript {
        propMinSdkVersion = 16
        propTargetSdkVersion = propCompileSdkVersion
        propVersionCode = 1
        propVersionName = '3.2.1'
        propVersionName = '3.2.2'
        kotlin_version = '1.2.0'
        support_libs = '27.0.2'
    }
+12 −3
Original line number Diff line number Diff line
package com.simplemobiletools.commons.models

import com.simplemobiletools.commons.extensions.formatDate
import com.simplemobiletools.commons.extensions.formatSize
import com.simplemobiletools.commons.helpers.SORT_BY_DATE_MODIFIED
import com.simplemobiletools.commons.helpers.SORT_BY_NAME
import com.simplemobiletools.commons.helpers.SORT_BY_SIZE
@@ -36,9 +38,7 @@ data class FileDirItem(val path: String, val name: String, val isDirectory: Bool
                    }
                }
                else -> {
                    val extension = if (isDirectory) name else path.substringAfterLast('.', "")
                    val otherExtension = if (other.isDirectory) other.name else other.path.substringAfterLast('.', "")
                    result = extension.toLowerCase().compareTo(otherExtension.toLowerCase())
                    result = getExtension().toLowerCase().compareTo(other.getExtension().toLowerCase())
                }
            }

@@ -48,4 +48,13 @@ data class FileDirItem(val path: String, val name: String, val isDirectory: Bool
            result
        }
    }

    fun getExtension() = if (isDirectory) name else path.substringAfterLast('.', "")

    fun getBubbleText() = when {
        sorting and SORT_BY_NAME != 0 -> name
        sorting and SORT_BY_SIZE != 0 -> size.formatSize()
        sorting and SORT_BY_DATE_MODIFIED != 0 -> File(path).lastModified().formatDate()
        else -> getExtension().toLowerCase()
    }
}