Android: Sort game list by date of title.txt

The title played last comes first.
This commit is contained in:
kichikuou
2020-02-10 18:41:23 +09:00
parent 936e524670
commit 3e4f0d6c48
@@ -60,7 +60,7 @@ class Launcher private constructor(private val rootDir: File) {
}
}
data class Entry(val path: File, val title: String)
data class Entry(val path: File, val title: String, val timestamp: Long)
val games = arrayListOf<Entry>()
val titles: List<String>
get() = games.map(Entry::title)
@@ -109,6 +109,7 @@ class Launcher private constructor(private val rootDir: File) {
private fun updateGameList() {
var saveDirFound = false
games.clear()
for (path in rootDir.listFiles()) {
if (!path.isDirectory)
continue
@@ -117,13 +118,15 @@ class Launcher private constructor(private val rootDir: File) {
continue
}
try {
val title = File(path, TITLE_FILE).readText()
games.add(Entry(path, title))
val titleFile = File(path, TITLE_FILE)
val title = titleFile.readText()
games.add(Entry(path, title, titleFile.lastModified()))
} catch (e: IOException) {
// Incomplete game installation. Delete it.
path.deleteRecursively()
}
}
games.sortByDescending(Entry::timestamp)
if (!saveDirFound) {
saveDir.mkdir()
}