Skip to content

Commit

Permalink
clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
abertschi committed Sep 2, 2017
1 parent 416db39 commit b5c33bf
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 9 deletions.
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ android {
applicationId "ch.abertschi.adfree"
minSdkVersion 21
targetSdkVersion 25
versionCode 14
versionName "0.0.4.0a2"
versionCode 15
versionName "0.0.4.1"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
multiDexEnabled true
}
Expand Down
16 changes: 11 additions & 5 deletions app/src/main/java/ch/abertschi/adfree/ad/AdDetector.kt
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,7 @@ class AdDetector(val detectors: List<AdDetectable>,

private var _pendingEvent: AdEvent? = null
private var go: Boolean = true

init {
remoteManager.getRemoteSettingsObservable()
.subscribe({ go = it.enabled })
}
private var init: Boolean = false

fun applyDetectors(payload: AdPayload) {
if (!go) return
Expand All @@ -54,6 +50,11 @@ class AdDetector(val detectors: List<AdDetectable>,
.forEach { isAd = true }
}

if (!init) {
fetchRemote()
init = true
}

val eventType = if (isAd) EventType.IS_AD else EventType.NO_AD
val event = AdEvent(eventType)
submitEvent(event)
Expand Down Expand Up @@ -82,6 +83,11 @@ class AdDetector(val detectors: List<AdDetectable>,
}.subscribe()
}

private fun fetchRemote() {
remoteManager.getRemoteSettingsObservable()
.subscribe({ go = it.enabled})
}

fun notifyObservers(event: AdEvent) {
observers.forEach { it.onAdEvent(event, this) }
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ class RemoteManager(prefFactory: PreferencesFactory) : AnkoLogger {
YamlRemoteConfigFactory(URL, RemoteSetting::class.java, prefFactory)

fun getRemoteSettingsObservable(): Observable<RemoteSetting> {
info("getRemoteSettingsObservable")
remoteSettings = configFactory.loadFromLocalStore()
return Observable.create<RemoteSetting> { source ->
configFactory.downloadObservable()
Expand Down
2 changes: 0 additions & 2 deletions app/src/main/java/ch/abertschi/adfree/model/YesNoModel.kt
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ package ch.abertschi.adfree.model

import android.content.Context
import org.jetbrains.anko.AnkoLogger
import org.jetbrains.anko.info
import org.json.JSONArray
import java.io.IOException
import java.nio.charset.Charset
Expand Down Expand Up @@ -45,7 +44,6 @@ class YesNoModel(val context: Context) : AnkoLogger {
stream.read(buffer)
stream.close()
json = buffer.toString(Charset.defaultCharset())
info(json)
val words = JSONArray(json)
var result = ArrayList<String>()
(0 until words.length()).mapTo(result) { words[it] as String }
Expand Down

0 comments on commit b5c33bf

Please sign in to comment.