forked from nextcloud/android
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Need more kotlin in the codebase and these were simple enough Signed-off-by: Álvaro Brey Vilas <[email protected]>
- Loading branch information
1 parent
7baa0f8
commit 96c55a6
Showing
9 changed files
with
336 additions
and
417 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
DO NOT TOUCH; GENERATED BY DRONE | ||
<span class="mdl-layout-title">Lint Report: 102 warnings</span> | ||
<span class="mdl-layout-title">Lint Report: 103 warnings</span> |
107 changes: 0 additions & 107 deletions
107
src/main/java/com/owncloud/android/utils/FileSortOrder.java
This file was deleted.
Oops, something went wrong.
109 changes: 109 additions & 0 deletions
109
src/main/java/com/owncloud/android/utils/FileSortOrder.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
/* | ||
* Nextcloud Android client application | ||
* | ||
* @author Sven R. Kunze | ||
* Copyright (C) 2017 Sven R. Kunze | ||
* Copyright (C) 2022 Álvaro Brey Vilas | ||
* | ||
* This program is free software; you can redistribute it and/or | ||
* modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE | ||
* License as published by the Free Software Foundation; either | ||
* version 3 of the License, or any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU AFFERO GENERAL PUBLIC LICENSE for more details. | ||
* | ||
* You should have received a copy of the GNU Affero General Public | ||
* License along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
package com.owncloud.android.utils | ||
|
||
import com.owncloud.android.datamodel.OCFile | ||
import com.owncloud.android.lib.resources.trashbin.model.TrashbinFile | ||
import java.io.File | ||
import java.util.Collections | ||
|
||
/** | ||
* Sort order | ||
*/ | ||
open class FileSortOrder(@JvmField var name: String, var isAscending: Boolean) { | ||
|
||
val sortMultiplier: Int | ||
get() = if (isAscending) 1 else -1 | ||
|
||
@Suppress("EnumNaming") // already saved in user preferences -.-' | ||
enum class Type { | ||
trashBinView, localFileListView | ||
} | ||
|
||
companion object { | ||
const val sort_a_to_z_id = "sort_a_to_z" | ||
const val sort_z_to_a_id = "sort_z_to_a" | ||
const val sort_old_to_new_id = "sort_old_to_new" | ||
const val sort_new_to_old_id = "sort_new_to_old" | ||
const val sort_small_to_big_id = "sort_small_to_big" | ||
const val sort_big_to_small_id = "sort_big_to_small" | ||
|
||
@JvmField | ||
val sort_a_to_z: FileSortOrder = FileSortOrderByName(sort_a_to_z_id, true) | ||
|
||
@JvmField | ||
val sort_z_to_a: FileSortOrder = FileSortOrderByName(sort_z_to_a_id, false) | ||
|
||
@JvmField | ||
val sort_old_to_new: FileSortOrder = FileSortOrderByDate(sort_old_to_new_id, true) | ||
|
||
@JvmField | ||
val sort_new_to_old: FileSortOrder = FileSortOrderByDate(sort_new_to_old_id, false) | ||
|
||
@JvmField | ||
val sort_small_to_big: FileSortOrder = FileSortOrderBySize(sort_small_to_big_id, true) | ||
|
||
@JvmField | ||
val sort_big_to_small: FileSortOrder = FileSortOrderBySize(sort_big_to_small_id, false) | ||
|
||
@JvmField | ||
val sortOrders: Map<String, FileSortOrder> = Collections.unmodifiableMap( | ||
mapOf( | ||
sort_a_to_z.name to sort_a_to_z, | ||
sort_z_to_a.name to sort_z_to_a, | ||
sort_old_to_new.name to sort_old_to_new, | ||
sort_new_to_old.name to sort_new_to_old, | ||
sort_small_to_big.name to sort_small_to_big, | ||
sort_big_to_small.name to sort_big_to_small | ||
) | ||
) | ||
|
||
/** | ||
* Sorts list by Favourites. | ||
* | ||
* @param files files to sort | ||
*/ | ||
@JvmStatic | ||
fun sortCloudFilesByFavourite(files: MutableList<OCFile>): List<OCFile> { | ||
files.sortWith { o1: OCFile, o2: OCFile -> | ||
when { | ||
o1.isFavorite && o2.isFavorite -> 0 | ||
o1.isFavorite -> -1 | ||
o2.isFavorite -> 1 | ||
else -> 0 | ||
} | ||
} | ||
return files | ||
} | ||
} | ||
|
||
open fun sortCloudFiles(files: MutableList<OCFile>): List<OCFile> { | ||
return sortCloudFilesByFavourite(files) | ||
} | ||
|
||
open fun sortLocalFiles(files: MutableList<File>): List<File> { | ||
return files | ||
} | ||
|
||
open fun sortTrashbinFiles(files: MutableList<TrashbinFile>): List<TrashbinFile> { | ||
return files | ||
} | ||
} |
82 changes: 0 additions & 82 deletions
82
src/main/java/com/owncloud/android/utils/FileSortOrderByDate.java
This file was deleted.
Oops, something went wrong.
69 changes: 69 additions & 0 deletions
69
src/main/java/com/owncloud/android/utils/FileSortOrderByDate.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
/* | ||
* Nextcloud Android client application | ||
* | ||
* @author Sven R. Kunze | ||
* Copyright (C) 2017 Sven R. Kunze | ||
* Copyright (C) 2022 Álvaro Brey Vilas | ||
* | ||
* This program is free software; you can redistribute it and/or | ||
* modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE | ||
* License as published by the Free Software Foundation; either | ||
* version 3 of the License, or any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU AFFERO GENERAL PUBLIC LICENSE for more details. | ||
* | ||
* You should have received a copy of the GNU Affero General Public | ||
* License along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
package com.owncloud.android.utils | ||
|
||
import com.owncloud.android.datamodel.OCFile | ||
import com.owncloud.android.lib.resources.trashbin.model.TrashbinFile | ||
import java.io.File | ||
|
||
/** | ||
* Created by srkunze on 28.08.17. | ||
*/ | ||
class FileSortOrderByDate(name: String, ascending: Boolean) : FileSortOrder(name, ascending) { | ||
/** | ||
* Sorts list by Date. | ||
* | ||
* @param files list of files to sort | ||
*/ | ||
override fun sortCloudFiles(files: MutableList<OCFile>): List<OCFile> { | ||
val multiplier = if (isAscending) 1 else -1 | ||
files.sortWith { o1: OCFile, o2: OCFile -> | ||
multiplier * o1.modificationTimestamp.compareTo(o2.modificationTimestamp) | ||
} | ||
return super.sortCloudFiles(files) | ||
} | ||
|
||
/** | ||
* Sorts list by Date. | ||
* | ||
* @param files list of files to sort | ||
*/ | ||
override fun sortTrashbinFiles(files: MutableList<TrashbinFile>): List<TrashbinFile> { | ||
val multiplier = if (isAscending) 1 else -1 | ||
files.sortWith { o1: TrashbinFile, o2: TrashbinFile -> | ||
multiplier * o1.deletionTimestamp.compareTo(o2.deletionTimestamp) | ||
} | ||
return super.sortTrashbinFiles(files) | ||
} | ||
|
||
/** | ||
* Sorts list by Date. | ||
* | ||
* @param files list of files to sort | ||
*/ | ||
override fun sortLocalFiles(files: MutableList<File>): List<File> { | ||
val multiplier = if (isAscending) 1 else -1 | ||
files.sortWith { o1: File, o2: File -> | ||
multiplier * o1.lastModified().compareTo(o2.lastModified()) | ||
} | ||
return files | ||
} | ||
} |
Oops, something went wrong.