forked from hardcoresushi/DroidFS
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-core:$exoplayer_version"
|
||||||
implementation "com.google.android.exoplayer:exoplayer-ui:$exoplayer_version"
|
implementation "com.google.android.exoplayer:exoplayer-ui:$exoplayer_version"
|
||||||
|
|
||||||
def camerax_version = "1.1.0-alpha01"
|
def camerax_v1 = "1.1.0-alpha03"
|
||||||
implementation "androidx.camera:camera-camera2:$camerax_version"
|
implementation "androidx.camera:camera-camera2:$camerax_v1"
|
||||||
implementation "androidx.camera:camera-lifecycle:$camerax_version"
|
implementation "androidx.camera:camera-lifecycle:$camerax_v1"
|
||||||
implementation "androidx.camera:camera-view:1.0.0-alpha21"
|
def camerax_v2 = "1.0.0-alpha23"
|
||||||
implementation "androidx.camera:camera-extensions:1.0.0-alpha21"
|
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() {
|
open class BaseExplorerActivity : BaseActivity() {
|
||||||
private lateinit var sortOrderEntries: Array<String>
|
private lateinit var sortOrderEntries: Array<String>
|
||||||
private lateinit var sortOrderValues: Array<String>
|
private lateinit var sortOrderValues: Array<String>
|
||||||
|
private var foldersFirst = true
|
||||||
private var currentSortOrderIndex = 0
|
private var currentSortOrderIndex = 0
|
||||||
protected lateinit var gocryptfsVolume: GocryptfsVolume
|
protected lateinit var gocryptfsVolume: GocryptfsVolume
|
||||||
private lateinit var volumeName: String
|
private lateinit var volumeName: String
|
||||||
@ -70,6 +71,7 @@ open class BaseExplorerActivity : BaseActivity() {
|
|||||||
gocryptfsVolume = GocryptfsVolume(sessionID)
|
gocryptfsVolume = GocryptfsVolume(sessionID)
|
||||||
sortOrderEntries = resources.getStringArray(R.array.sort_orders_entries)
|
sortOrderEntries = resources.getStringArray(R.array.sort_orders_entries)
|
||||||
sortOrderValues = resources.getStringArray(R.array.sort_orders_values)
|
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"))
|
currentSortOrderIndex = resources.getStringArray(R.array.sort_orders_values).indexOf(sharedPrefs.getString(ConstValues.sort_order_key, "name"))
|
||||||
init()
|
init()
|
||||||
setSupportActionBar(toolbar)
|
setSupportActionBar(toolbar)
|
||||||
@ -188,7 +190,7 @@ open class BaseExplorerActivity : BaseActivity() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun sortExplorerElements() {
|
private fun sortExplorerElements() {
|
||||||
ExplorerElement.sortBy(sortOrderValues[currentSortOrderIndex], explorerElements)
|
ExplorerElement.sortBy(sortOrderValues[currentSortOrderIndex], foldersFirst, explorerElements)
|
||||||
val sharedPrefsEditor = sharedPrefs.edit()
|
val sharedPrefsEditor = sharedPrefs.edit()
|
||||||
sharedPrefsEditor.putString(ConstValues.sort_order_key, sortOrderValues[currentSortOrderIndex])
|
sharedPrefsEditor.putString(ConstValues.sort_order_key, sortOrderValues[currentSortOrderIndex])
|
||||||
sharedPrefsEditor.apply()
|
sharedPrefsEditor.apply()
|
||||||
@ -249,11 +251,11 @@ open class BaseExplorerActivity : BaseActivity() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun createFolder(folder_name: String){
|
private fun createFolder(folderName: String){
|
||||||
if (folder_name.isEmpty()) {
|
if (folderName.isEmpty()) {
|
||||||
Toast.makeText(this, R.string.error_filename_empty, Toast.LENGTH_SHORT).show()
|
Toast.makeText(this, R.string.error_filename_empty, Toast.LENGTH_SHORT).show()
|
||||||
} else {
|
} else {
|
||||||
if (!gocryptfsVolume.mkdir(PathUtils.pathJoin(currentDirectoryPath, folder_name))) {
|
if (!gocryptfsVolume.mkdir(PathUtils.pathJoin(currentDirectoryPath, folderName))) {
|
||||||
ColoredAlertDialogBuilder(this)
|
ColoredAlertDialogBuilder(this)
|
||||||
.setTitle(R.string.error)
|
.setTitle(R.string.error)
|
||||||
.setMessage(R.string.error_mkdir)
|
.setMessage(R.string.error_mkdir)
|
||||||
|
@ -3,8 +3,8 @@ package sushi.hardcore.droidfs.explorers
|
|||||||
import sushi.hardcore.droidfs.util.PathUtils
|
import sushi.hardcore.droidfs.util.PathUtils
|
||||||
import java.util.*
|
import java.util.*
|
||||||
|
|
||||||
class ExplorerElement(val name: String, val elementType: Short, var size: Long, val mtime: Long, val parentPath: String) {
|
class ExplorerElement(val name: String, val elementType: Short, var size: Long, mTime: Long, val parentPath: String) {
|
||||||
val mTime = Date((mtime * 1000).toString().toLong())
|
val mTime = Date((mTime * 1000).toString().toLong())
|
||||||
val fullPath: String = PathUtils.pathJoin(parentPath, name)
|
val fullPath: String = PathUtils.pathJoin(parentPath, name)
|
||||||
|
|
||||||
val isDirectory: Boolean
|
val isDirectory: Boolean
|
||||||
@ -17,25 +17,53 @@ class ExplorerElement(val name: String, val elementType: Short, var size: Long,
|
|||||||
get() = elementType.toInt() == 1
|
get() = elementType.toInt() == 1
|
||||||
|
|
||||||
companion object {
|
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) {
|
when (sortOrder) {
|
||||||
"name" -> {
|
"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" -> {
|
"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" -> {
|
"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" -> {
|
"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" -> {
|
"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" -> {
|
"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
|
protected lateinit var filePath: String
|
||||||
private var isFinishingIntentionally = false
|
private var isFinishingIntentionally = false
|
||||||
private var usf_keep_open = false
|
private var usf_keep_open = false
|
||||||
|
private var foldersFirst = true
|
||||||
private var wasMapped = false
|
private var wasMapped = false
|
||||||
protected val mappedPlaylist = mutableListOf<ExplorerElement>()
|
protected val mappedPlaylist = mutableListOf<ExplorerElement>()
|
||||||
protected var currentPlaylistIndex = -1
|
protected var currentPlaylistIndex = -1
|
||||||
@ -26,6 +27,7 @@ abstract class FileViewerActivity: BaseActivity() {
|
|||||||
val sessionID = intent.getIntExtra("sessionID", -1)
|
val sessionID = intent.getIntExtra("sessionID", -1)
|
||||||
gocryptfsVolume = GocryptfsVolume(sessionID)
|
gocryptfsVolume = GocryptfsVolume(sessionID)
|
||||||
usf_keep_open = sharedPrefs.getBoolean("usf_keep_open", false)
|
usf_keep_open = sharedPrefs.getBoolean("usf_keep_open", false)
|
||||||
|
foldersFirst = sharedPrefs.getBoolean("folders_first", true)
|
||||||
hideSystemUi()
|
hideSystemUi()
|
||||||
viewFile()
|
viewFile()
|
||||||
}
|
}
|
||||||
@ -108,7 +110,7 @@ abstract class FileViewerActivity: BaseActivity() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
val sortOrder = intent.getStringExtra("sortOrder") ?: "name"
|
val sortOrder = intent.getStringExtra("sortOrder") ?: "name"
|
||||||
ExplorerElement.sortBy(sortOrder, mappedPlaylist)
|
ExplorerElement.sortBy(sortOrder, foldersFirst, mappedPlaylist)
|
||||||
//find current index
|
//find current index
|
||||||
for ((i, e) in mappedPlaylist.withIndex()){
|
for ((i, e) in mappedPlaylist.withIndex()){
|
||||||
if (filePath == e.fullPath){
|
if (filePath == e.fullPath){
|
||||||
|
@ -190,4 +190,6 @@
|
|||||||
<string name="file_op_export_msg">Exporting files…</string>
|
<string name="file_op_export_msg">Exporting files…</string>
|
||||||
<string name="file_op_move_msg">Moving files…</string>
|
<string name="file_op_move_msg">Moving files…</string>
|
||||||
<string name="file_op_wiping_msg">Wiping 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>
|
</resources>
|
||||||
|
@ -28,6 +28,13 @@
|
|||||||
android:title="@string/settings_title_sort_order"
|
android:title="@string/settings_title_sort_order"
|
||||||
android:icon="@drawable/icon_sort"/>
|
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>
|
||||||
|
|
||||||
<PreferenceCategory android:title="@string/unsafe_features">
|
<PreferenceCategory android:title="@string/unsafe_features">
|
||||||
|
@ -6,7 +6,7 @@ buildscript {
|
|||||||
jcenter()
|
jcenter()
|
||||||
}
|
}
|
||||||
dependencies {
|
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"
|
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user