From af49f40d0b1783312bb5973ce9756316dc0a5adc Mon Sep 17 00:00:00 2001 From: kichikuou Date: Tue, 11 Feb 2020 09:49:01 +0900 Subject: [PATCH] Android: Sort game list by date of title.txt The title played last comes first. --- .../main/java/io/github/kichikuou/xsystem35/Launcher.kt | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/android/app/src/main/java/io/github/kichikuou/xsystem35/Launcher.kt b/android/app/src/main/java/io/github/kichikuou/xsystem35/Launcher.kt index 85ab795..22256a4 100644 --- a/android/app/src/main/java/io/github/kichikuou/xsystem35/Launcher.kt +++ b/android/app/src/main/java/io/github/kichikuou/xsystem35/Launcher.kt @@ -61,7 +61,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() val titles: List get() = games.map(Entry::title) @@ -108,6 +108,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 @@ -116,13 +117,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) { File(rootDir, SAVE_DIR).mkdir() }