mirror of
https://github.com/Droid-Deck/DroidDeck.git
synced 2026-12-04 03:55:44 +00:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
796e31fbda |
No files matched your search
@@ -83,7 +83,7 @@ object EpicLibrary {
|
||||
thirdPartyManagedApp = o.optString("thirdPartyManagedApp", ""),
|
||||
)
|
||||
}
|
||||
return tidy(games)
|
||||
return tidy(games.filterNot { it.title == it.appName && it.appName.matches(Regex("[0-9a-fA-F]{32}")) })
|
||||
}
|
||||
|
||||
private fun tidy(games: List<EpicGame>): List<EpicGame> =
|
||||
@@ -131,7 +131,7 @@ object EpicLibrary {
|
||||
appName = appName,
|
||||
namespace = record.optString("namespace"),
|
||||
catalogItemId = record.optString("catalogItemId"),
|
||||
title = pick("title", before?.title?.takeIf { it != appName } ?: appName),
|
||||
title = d.optString("title", "").takeIf { it.isNotBlank() } ?: before?.title?.takeIf { it != appName } ?: appName,
|
||||
artCover = pick("tall", before?.artCover.orEmpty()),
|
||||
artSquare = pick("wide", before?.artSquare.orEmpty()),
|
||||
developer = pick("developer", before?.developer.orEmpty()),
|
||||
@@ -152,6 +152,10 @@ object EpicLibrary {
|
||||
return tidy(if (base.isEmpty()) games else base)
|
||||
}
|
||||
|
||||
internal fun hasCatalogTitle(details: JSONObject?, before: EpicGame?): Boolean =
|
||||
details?.optString("title", "")?.isNotBlank() == true ||
|
||||
(before != null && before.title.isNotBlank() && before.title != before.appName)
|
||||
|
||||
fun sync(context: Context, force: Boolean, status: (String) -> Unit): SyncResult {
|
||||
if (!running.compareAndSet(false, true)) return SyncResult.Busy
|
||||
try {
|
||||
@@ -182,7 +186,8 @@ object EpicLibrary {
|
||||
val record = records.optJSONObject(i) ?: continue
|
||||
if (i % 5 == 0) status(app.getString(R.string.stores_sync_details, i, total))
|
||||
val details = EpicApiClient.catalogDetails(token, record.optString("namespace"), record.optString("catalogItemId"))
|
||||
games += gameFrom(record, details, before[record.optString("appName")])
|
||||
val previous = before[record.optString("appName")]
|
||||
if (hasCatalogTitle(details, previous)) games += gameFrom(record, details, previous)
|
||||
}
|
||||
val shown = visible(games)
|
||||
prefs.edit().putString(KEY_CACHE, toCacheJson(shown)).putLong(KEY_SYNCED_AT, System.currentTimeMillis()).apply()
|
||||
|
||||
@@ -92,6 +92,22 @@ class EpicLibraryTest {
|
||||
assertEquals(listOf("dlc"), EpicLibrary.visible(listOf(dlc)).map { it.appName })
|
||||
}
|
||||
|
||||
@Test fun untitledRecordsAreNotListedAndKnownTitlesSurviveLookupFailures() {
|
||||
val id = "370325fee5104176a6e5321234567890"
|
||||
val record = JSONObject().put("appName", id)
|
||||
val base = EpicLibrary.gameFrom(record, JSONObject().put("title", "Game"), null)
|
||||
val dlc = EpicLibrary.gameFrom(JSONObject().put("appName", "dlc"), JSONObject().put("title", "Add-on").put("dlc", true), null)
|
||||
assertFalse(EpicLibrary.hasCatalogTitle(null, null))
|
||||
assertFalse(EpicLibrary.hasCatalogTitle(JSONObject().put("title", " "), null))
|
||||
assertFalse(EpicLibrary.hasCatalogTitle(null, EpicLibrary.gameFrom(record, null, null)))
|
||||
assertTrue(EpicLibrary.hasCatalogTitle(null, base))
|
||||
assertTrue(EpicLibrary.hasCatalogTitle(JSONObject().put("title", "Game"), null))
|
||||
assertEquals(listOf(base), EpicLibrary.visible(listOf(base, dlc)))
|
||||
val cached = JSONArray().put(JSONObject().put("appName", id).put("title", id))
|
||||
.put(JSONObject().put("appName", "named").put("title", "Named Game"))
|
||||
assertEquals(listOf("named"), EpicLibrary.fromCacheJson(cached.toString()).map { it.appName })
|
||||
}
|
||||
|
||||
@Test fun syncedGamesKeepCachedValuesWhenDetailsAreMissing() {
|
||||
val record = JSONObject().put("appName", "Fig").put("namespace", "ns").put("catalogItemId", "cat")
|
||||
val before = EpicGame("Fig", "ns", "cat", "Cached Title", artCover = "c", version = "v1", installSize = 7L)
|
||||
|
||||
Reference in new issue
Block a user