Skip to content

Commit

Permalink
Merge pull request #18 from KiARC/dev
Browse files Browse the repository at this point in the history
Small Patches
  • Loading branch information
KiARC authored Mar 30, 2022
2 parents 1129ac0 + ee74e6a commit 988fa7e
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 17 deletions.
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ android {
applicationId "com.katiearose.sobriety"
minSdk 30
targetSdk 30
versionCode 8
versionName "v4.0.0"
versionCode 9
versionName "v4.0.1"
setProperty("archivesBaseName", "Sobriety $versionName")
}

Expand Down
29 changes: 14 additions & 15 deletions app/src/main/java/com/katiearose/sobriety/Main.kt
Original file line number Diff line number Diff line change
Expand Up @@ -190,27 +190,26 @@ class Main : AppCompatActivity() {
createNewCard(addiction)
}
} catch (e: ClassCastException) {
readCache(cache.inputStream())
readLegacyCache(cache.inputStream())
}
}

@Deprecated(
"For old caches before the implementation of the Addiction class.",
ReplaceWith("readCache(FileInputStream)"),
DeprecationLevel.WARNING
)
private fun readLegacyCache(input: InputStream) {
val a = HashMap<String, Pair<Instant, CircularBuffer<Long>>>()
InflaterInputStream(input).use { iis ->
ObjectInputStream(iis).use {
for (i in it.readObject() as HashMap<String, Pair<Instant, CircularBuffer<Long>>>) {
a[i.key] = i.value
try {
val a = HashMap<String, Pair<Instant, CircularBuffer<Long>>>()
InflaterInputStream(input).use { iis ->
ObjectInputStream(iis).use {
for (i in it.readObject() as HashMap<String, Pair<Instant, CircularBuffer<Long>>>) {
a[i.key] = i.value
}
}
}
}
for (ad in a) {
val addiction = Addiction(ad.key, ad.value.first)
createNewCard(addiction)
for (ad in a) {
val addiction = Addiction(ad.key, ad.value.first)
createNewCard(addiction)
}
} catch (e: Exception) {
//Do nothing, i.e. if the cache is older than the previous version just ignore it, supporting every previous version would take more code than it's worth.
}
}

Expand Down
3 changes: 3 additions & 0 deletions fastlane/metadata/android/en-US/changelogs/9.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Bug fixes
- App no longer crashes when reading old caches
- Caches older than the v3.x.x format are ignored

0 comments on commit 988fa7e

Please sign in to comment.