Skip to content

Commit

Permalink
Decouple CacheHandler from Main Activity
Browse files Browse the repository at this point in the history
  • Loading branch information
unbiaseduser-github committed Oct 19, 2022
1 parent fb8d528 commit dc978b9
Showing 1 changed file with 3 additions and 2 deletions.
@@ -1,5 +1,6 @@
package com.sixtyninefourtwenty.imdefinitelysober.internal

import android.content.Context
import androidx.appcompat.app.AppCompatActivity
import com.sixtyninefourtwenty.imdefinitelysober.Addiction
import com.sixtyninefourtwenty.imdefinitelysober.activities.Main
Expand All @@ -9,7 +10,7 @@ import java.io.ObjectOutputStream
import java.util.zip.DeflaterOutputStream
import java.util.zip.InflaterInputStream

class CacheHandler(private val activity: Main) {
class CacheHandler(private val context: Context) {
fun readCache(input: InputStream): ArrayList<Addiction> {
val result = ArrayList<Addiction>()
val cache = input.readBytes()
Expand Down Expand Up @@ -37,7 +38,7 @@ class CacheHandler(private val activity: Main) {
Main.addictions.forEach {
output.add(it.toCacheable())
}
activity.openFileOutput("Sobriety.cache", AppCompatActivity.MODE_PRIVATE).use { fos ->
context.openFileOutput("Sobriety.cache", AppCompatActivity.MODE_PRIVATE).use { fos ->
DeflaterOutputStream(fos, true).use { dos ->
ObjectOutputStream(dos).use {
it.writeObject(output)
Expand Down

0 comments on commit dc978b9

Please sign in to comment.