Skip to content

Commit

Permalink
Disable disk writes strict mode check as vibration triggers it
Browse files Browse the repository at this point in the history
  • Loading branch information
rubengees committed Oct 8, 2018
1 parent 26fae74 commit 5353ec1
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 57 deletions.
1 change: 1 addition & 0 deletions src/main/kotlin/me/proxer/app/MainApplication.kt
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,7 @@ class MainApplication : Application() {
if (BuildConfig.DEBUG) {
val threadPolicy = StrictModeCompat.ThreadPolicy.Builder()
.detectAll()
.permitDiskWrites()
.permitDiskReads()
.penaltyDeath()
.penaltyLog()
Expand Down
56 changes: 22 additions & 34 deletions src/main/kotlin/me/proxer/app/util/data/StorageHelper.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import com.orhanobut.hawk.Converter
import com.orhanobut.hawk.DataInfo
import com.orhanobut.hawk.Hawk
import me.proxer.app.auth.LocalUser
import me.proxer.app.util.extension.permitDisk
import org.koin.standalone.KoinComponent
import timber.log.Timber
import java.util.Date
Expand Down Expand Up @@ -35,22 +34,18 @@ class StorageHelper(context: Context, jsonParser: HawkMoshiParser) : KoinCompone
}

init {
permitDisk {
initHawk(context, jsonParser)
initHawk(context, jsonParser)

migrateUser(context, jsonParser)
migratePreferences(context)
}
migrateUser(context, jsonParser)
migratePreferences(context)
}

var user: LocalUser?
get() = Hawk.get(USER)
set(value) {
permitDisk {
when (value) {
null -> Hawk.delete(USER)
else -> Hawk.put(USER, value)
}
when (value) {
null -> Hawk.delete(USER)
else -> Hawk.put(USER, value)
}
}

Expand All @@ -60,25 +55,25 @@ class StorageHelper(context: Context, jsonParser: HawkMoshiParser) : KoinCompone
var isTwoFactorAuthenticationEnabled: Boolean
get() = Hawk.get(TWO_FACTOR_AUTHENTICATION, false)
set(value) {
permitDisk { Hawk.put(TWO_FACTOR_AUTHENTICATION, value) }
Hawk.put(TWO_FACTOR_AUTHENTICATION, value)
}

var lastNewsDate: Date
get() = Date(Hawk.get(LAST_NEWS_DATE, 0L))
set(value) {
permitDisk { Hawk.put(LAST_NEWS_DATE, value.time) }
Hawk.put(LAST_NEWS_DATE, value.time)
}

var lastNotificationsDate: Date
get() = Date(Hawk.get(LAST_NOTIFICATIONS_DATE, 0L))
set(value) {
permitDisk { Hawk.put(LAST_NOTIFICATIONS_DATE, value.time) }
Hawk.put(LAST_NOTIFICATIONS_DATE, value.time)
}

var lastChatMessageDate: Date
get() = Date(Hawk.get(LAST_CHAT_MESSAGE_DATE, 0L))
set(value) {
permitDisk { Hawk.put(LAST_CHAT_MESSAGE_DATE, value.time) }
Hawk.put(LAST_CHAT_MESSAGE_DATE, value.time)
}

val chatInterval: Long
Expand All @@ -87,19 +82,19 @@ class StorageHelper(context: Context, jsonParser: HawkMoshiParser) : KoinCompone
var areConferencesSynchronized: Boolean
get() = Hawk.get(CONFERENCES_SYNCHRONIZED, false)
set(value) {
permitDisk { Hawk.put(CONFERENCES_SYNCHRONIZED, value) }
Hawk.put(CONFERENCES_SYNCHRONIZED, value)
}

var lastTagUpdateDate: Date
get() = Date(Hawk.get(LAST_TAG_UPDATE_DATE, 0L))
set(value) {
permitDisk { Hawk.put(LAST_TAG_UPDATE_DATE, value.time) }
Hawk.put(LAST_TAG_UPDATE_DATE, value.time)
}

var launches: Int
get() = Hawk.get(LAUNCHES, 0)
private set(value) {
permitDisk { Hawk.put(LAUNCHES, value) }
Hawk.put(LAUNCHES, value)
}

var hasRated: Boolean
Expand All @@ -108,27 +103,23 @@ class StorageHelper(context: Context, jsonParser: HawkMoshiParser) : KoinCompone
Hawk.put(RATED, value)
}

fun incrementChatInterval() = permitDisk {
Hawk.get(CHAT_INTERVAL, DEFAULT_CHAT_INTERVAL).let {
if (it < MAX_CHAT_INTERVAL) {
Hawk.put(CHAT_INTERVAL, (it * 1.5f).toLong())
}
fun incrementChatInterval() = Hawk.get(CHAT_INTERVAL, DEFAULT_CHAT_INTERVAL).let {
if (it < MAX_CHAT_INTERVAL) {
Hawk.put(CHAT_INTERVAL, (it * 1.5f).toLong())
}
}

fun incrementLaunches() = permitDisk {
Hawk.get(LAUNCHES, 0).let {
Hawk.put(LAUNCHES, it + 1)
}
fun incrementLaunches() = Hawk.get(LAUNCHES, 0).let {
Hawk.put(LAUNCHES, it + 1)
}

fun resetChatInterval() = permitDisk { Hawk.put(CHAT_INTERVAL, DEFAULT_CHAT_INTERVAL) }
fun resetChatInterval() = Hawk.put(CHAT_INTERVAL, DEFAULT_CHAT_INTERVAL)

fun putMessageDraft(id: String, draft: String) = permitDisk { Hawk.put("$MESSAGE_DRAFT_PREFIX$id", draft) }
fun putMessageDraft(id: String, draft: String) = Hawk.put("$MESSAGE_DRAFT_PREFIX$id", draft)

fun getMessageDraft(id: String): String? = Hawk.get("$MESSAGE_DRAFT_PREFIX$id")

fun deleteMessageDraft(id: String) = permitDisk { Hawk.delete("$MESSAGE_DRAFT_PREFIX$id") }
fun deleteMessageDraft(id: String) = Hawk.delete("$MESSAGE_DRAFT_PREFIX$id")

private fun initHawk(context: Context, jsonParser: HawkMoshiParser) {
if (!Hawk.isBuilt()) {
Expand Down Expand Up @@ -191,10 +182,7 @@ class StorageHelper(context: Context, jsonParser: HawkMoshiParser) : KoinCompone

@Suppress("UNCHECKED_CAST")
override fun <T : Any?> fromString(value: String, dataInfo: DataInfo?): T {
return jsonParser.fromJson<MigrationLocalUser>(
value,
MigrationLocalUser::class.java
) as T
return jsonParser.fromJson<MigrationLocalUser>(value, MigrationLocalUser::class.java) as T
}
}
}

This file was deleted.

0 comments on commit 5353ec1

Please sign in to comment.