Case insensitive sort & Folders first option
This commit is contained in:
parent
0eb515c938
commit
f119ccf477
@ -60,9 +60,10 @@ dependencies {
|
||||
implementation "com.google.android.exoplayer:exoplayer-core:$exoplayer_version"
|
||||
implementation "com.google.android.exoplayer:exoplayer-ui:$exoplayer_version"
|
||||
|
||||
def camerax_version = "1.1.0-alpha01"
|
||||
implementation "androidx.camera:camera-camera2:$camerax_version"
|
||||
implementation "androidx.camera:camera-lifecycle:$camerax_version"
|
||||
implementation "androidx.camera:camera-view:1.0.0-alpha21"
|
||||
implementation "androidx.camera:camera-extensions:1.0.0-alpha21"
|
||||
def camerax_v1 = "1.1.0-alpha03"
|
||||
implementation "androidx.camera:camera-camera2:$camerax_v1"
|
||||
implementation "androidx.camera:camera-lifecycle:$camerax_v1"
|
||||
def camerax_v2 = "1.0.0-alpha23"
|
||||
implementation "androidx.camera:camera-view:$camerax_v2"
|
||||
implementation "androidx.camera:camera-extensions:$camerax_v2"
|
||||
}
|
||||
|
@ -45,6 +45,7 @@ import sushi.hardcore.droidfs.widgets.ColoredAlertDialogBuilder
|
||||
open class BaseExplorerActivity : BaseActivity() {
|
||||
private lateinit var sortOrderEntries: Array<String>
|
||||
private lateinit var sortOrderValues: Array<String>
|
||||
private var foldersFirst = true
|
||||
private var currentSortOrderIndex = 0
|
||||
protected lateinit var gocryptfsVolume: GocryptfsVolume
|
||||
private lateinit var volumeName: String
|
||||
@ -70,6 +71,7 @@ open class BaseExplorerActivity : BaseActivity() {
|
||||
gocryptfsVolume = GocryptfsVolume(sessionID)
|
||||
sortOrderEntries = resources.getStringArray(R.array.sort_orders_entries)
|
||||
sortOrderValues = resources.getStringArray(R.array.sort_orders_values)
|
||||
foldersFirst = sharedPrefs.getBoolean("folders_first", true)
|
||||
currentSortOrderIndex = resources.getStringArray(R.array.sort_orders_values).indexOf(sharedPrefs.getString(ConstValues.sort_order_key, "name"))
|
||||
init()
|
||||
setSupportActionBar(toolbar)
|
||||
@ -188,7 +190,7 @@ open class BaseExplorerActivity : BaseActivity() {
|
||||
}
|
||||
|
||||
private fun sortExplorerElements() {
|
||||
ExplorerElement.sortBy(sortOrderValues[currentSortOrderIndex], explorerElements)
|
||||
ExplorerElement.sortBy(sortOrderValues[currentSortOrderIndex], foldersFirst, explorerElements)
|
||||
val sharedPrefsEditor = sharedPrefs.edit()
|
||||
sharedPrefsEditor.putString(ConstValues.sort_order_key, sortOrderValues[currentSortOrderIndex])
|
||||
sharedPrefsEditor.apply()
|
||||
@ -249,11 +251,11 @@ open class BaseExplorerActivity : BaseActivity() {
|
||||
}
|
||||
}
|
||||
|
||||
private fun createFolder(folder_name: String){
|
||||
if (folder_name.isEmpty()) {
|
||||
private fun createFolder(folderName: String){
|
||||
if (folderName.isEmpty()) {
|
||||
Toast.makeText(this, R.string.error_filename_empty, Toast.LENGTH_SHORT).show()
|
||||
} else {
|
||||
if (!gocryptfsVolume.mkdir(PathUtils.pathJoin(currentDirectoryPath, folder_name))) {
|
||||
if (!gocryptfsVolume.mkdir(PathUtils.pathJoin(currentDirectoryPath, folderName))) {
|
||||
ColoredAlertDialogBuilder(this)
|
||||
.setTitle(R.string.error)
|
||||
.setMessage(R.string.error_mkdir)
|
||||
|
@ -3,8 +3,8 @@ package sushi.hardcore.droidfs.explorers
|
||||
import sushi.hardcore.droidfs.util.PathUtils
|
||||
import java.util.*
|
||||
|
||||
class ExplorerElement(val name: String, val elementType: Short, var size: Long, val mtime: Long, val parentPath: String) {
|
||||
val mTime = Date((mtime * 1000).toString().toLong())
|
||||
class ExplorerElement(val name: String, val elementType: Short, var size: Long, mTime: Long, val parentPath: String) {
|
||||
val mTime = Date((mTime * 1000).toString().toLong())
|
||||
val fullPath: String = PathUtils.pathJoin(parentPath, name)
|
||||
|
||||
val isDirectory: Boolean
|
||||
@ -17,25 +17,53 @@ class ExplorerElement(val name: String, val elementType: Short, var size: Long,
|
||||
get() = elementType.toInt() == 1
|
||||
|
||||
companion object {
|
||||
fun sortBy(sortOrder: String, explorerElements: MutableList<ExplorerElement>) {
|
||||
private fun foldersFirst(a: ExplorerElement, b: ExplorerElement, default: () -> Int): Int {
|
||||
return if (a.isDirectory && b.isRegularFile) {
|
||||
-1
|
||||
} else if (b.isDirectory && a.isRegularFile) {
|
||||
1
|
||||
} else {
|
||||
default()
|
||||
}
|
||||
}
|
||||
private fun doSort(a: ExplorerElement, b: ExplorerElement, foldersFirst: Boolean, sorter: () -> Int): Int {
|
||||
return if (foldersFirst) {
|
||||
foldersFirst(a, b, sorter)
|
||||
} else {
|
||||
sorter()
|
||||
}
|
||||
}
|
||||
fun sortBy(sortOrder: String, foldersFirst: Boolean, explorerElements: MutableList<ExplorerElement>) {
|
||||
when (sortOrder) {
|
||||
"name" -> {
|
||||
explorerElements.sortWith(Comparator { o1, o2 -> o1.fullPath.compareTo(o2.fullPath) })
|
||||
explorerElements.sortWith { a, b ->
|
||||
doSort(a, b, foldersFirst) { a.fullPath.compareTo(b.fullPath, true) }
|
||||
}
|
||||
}
|
||||
"size" -> {
|
||||
explorerElements.sortWith(Comparator { o1, o2 -> (o1.size - o2.size).toInt() })
|
||||
explorerElements.sortWith { a, b ->
|
||||
doSort(a, b, foldersFirst) { (a.size - b.size).toInt() }
|
||||
}
|
||||
}
|
||||
"date" -> {
|
||||
explorerElements.sortWith(Comparator { o1, o2 -> o1.mTime.compareTo(o2.mTime) })
|
||||
explorerElements.sortWith { a, b ->
|
||||
doSort(a, b, foldersFirst) { a.mTime.compareTo(b.mTime) }
|
||||
}
|
||||
}
|
||||
"name_desc" -> {
|
||||
explorerElements.sortWith(Comparator { o1, o2 -> o2.fullPath.compareTo(o1.fullPath) })
|
||||
explorerElements.sortWith { a, b ->
|
||||
doSort(a, b, foldersFirst) { b.fullPath.compareTo(a.fullPath, true) }
|
||||
}
|
||||
}
|
||||
"size_desc" -> {
|
||||
explorerElements.sortWith(Comparator { o1, o2 -> (o2.size - o1.size).toInt() })
|
||||
explorerElements.sortWith { a, b ->
|
||||
doSort(a, b, foldersFirst) { (b.size - a.size).toInt() }
|
||||
}
|
||||
}
|
||||
"date_desc" -> {
|
||||
explorerElements.sortWith(Comparator { o1, o2 -> o2.mTime.compareTo(o1.mTime) })
|
||||
explorerElements.sortWith { a, b ->
|
||||
doSort(a, b, foldersFirst) { b.mTime.compareTo(a.mTime) }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -16,6 +16,7 @@ abstract class FileViewerActivity: BaseActivity() {
|
||||
protected lateinit var filePath: String
|
||||
private var isFinishingIntentionally = false
|
||||
private var usf_keep_open = false
|
||||
private var foldersFirst = true
|
||||
private var wasMapped = false
|
||||
protected val mappedPlaylist = mutableListOf<ExplorerElement>()
|
||||
protected var currentPlaylistIndex = -1
|
||||
@ -26,6 +27,7 @@ abstract class FileViewerActivity: BaseActivity() {
|
||||
val sessionID = intent.getIntExtra("sessionID", -1)
|
||||
gocryptfsVolume = GocryptfsVolume(sessionID)
|
||||
usf_keep_open = sharedPrefs.getBoolean("usf_keep_open", false)
|
||||
foldersFirst = sharedPrefs.getBoolean("folders_first", true)
|
||||
hideSystemUi()
|
||||
viewFile()
|
||||
}
|
||||
@ -108,7 +110,7 @@ abstract class FileViewerActivity: BaseActivity() {
|
||||
}
|
||||
}
|
||||
val sortOrder = intent.getStringExtra("sortOrder") ?: "name"
|
||||
ExplorerElement.sortBy(sortOrder, mappedPlaylist)
|
||||
ExplorerElement.sortBy(sortOrder, foldersFirst, mappedPlaylist)
|
||||
//find current index
|
||||
for ((i, e) in mappedPlaylist.withIndex()){
|
||||
if (filePath == e.fullPath){
|
||||
|
@ -190,4 +190,6 @@
|
||||
<string name="file_op_export_msg">Exporting files…</string>
|
||||
<string name="file_op_move_msg">Moving files…</string>
|
||||
<string name="file_op_wiping_msg">Wiping files…</string>
|
||||
<string name="folders_first">Folders first</string>
|
||||
<string name="folders_first_summary">Show folders at the beginning of the list</string>
|
||||
</resources>
|
||||
|
@ -28,6 +28,13 @@
|
||||
android:title="@string/settings_title_sort_order"
|
||||
android:icon="@drawable/icon_sort"/>
|
||||
|
||||
<SwitchPreferenceCompat
|
||||
android:defaultValue="true"
|
||||
app:icon="@drawable/icon_folder"
|
||||
android:key="folders_first"
|
||||
android:title="@string/folders_first"
|
||||
android:summary="@string/folders_first_summary"/>
|
||||
|
||||
</PreferenceCategory>
|
||||
|
||||
<PreferenceCategory android:title="@string/unsafe_features">
|
||||
|
@ -6,7 +6,7 @@ buildscript {
|
||||
jcenter()
|
||||
}
|
||||
dependencies {
|
||||
classpath 'com.android.tools.build:gradle:4.1.2'
|
||||
classpath 'com.android.tools.build:gradle:4.1.3'
|
||||
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user