replace deprecated calls

This commit is contained in:
Milos Kozak 2020-03-29 23:52:24 +02:00
parent f25e871a91
commit d1ee12fafc
6 changed files with 21 additions and 39 deletions

View file

@ -190,6 +190,7 @@ class PluginStore @Inject constructor(
</T> */
private fun <T> determineActivePlugin(pluginsInCategory: ArrayList<PluginBase>,
pluginType: PluginType): T? {
@Suppress("UNCHECKED_CAST")
val activePlugin = getTheOneEnabledInArray(pluginsInCategory, pluginType) as T?
if (activePlugin != null) {
setFragmentVisiblities((activePlugin as PluginBase).name, pluginsInCategory, pluginType)

View file

@ -50,7 +50,8 @@ class TidepoolPlugin @Inject constructor(
private val fabricPrivacy: FabricPrivacy,
private val tidepoolUploader: TidepoolUploader,
private val uploadChunk: UploadChunk,
private val sp: SP
private val sp: SP,
private val rateLimit: RateLimit
) : PluginBase(PluginDescription()
.mainType(PluginType.GENERAL)
.pluginName(R.string.tidepool)
@ -103,7 +104,7 @@ class TidepoolPlugin @Inject constructor(
if (isEnabled(PluginType.GENERAL)
&& (!sp.getBoolean(R.string.key_tidepool_only_while_charging, false) || ChargingStateReceiver.isCharging())
&& (!sp.getBoolean(R.string.key_tidepool_only_while_unmetered, false) || NetworkChangeReceiver.isWifiConnected())
&& RateLimit.rateLimit("tidepool-new-data-upload", T.mins(4).secs().toInt()))
&& rateLimit.rateLimit("tidepool-new-data-upload", T.mins(4).secs().toInt()))
doUpload()
}, {
fabricPrivacy.logException(it)

View file

@ -1,32 +1,22 @@
package info.nightscout.androidaps.plugins.general.tidepool.comm
import info.nightscout.androidaps.logging.L
import info.nightscout.androidaps.logging.StacktraceLoggerWrapper
import info.nightscout.androidaps.logging.AAPSLogger
import info.nightscout.androidaps.logging.LTag
import okhttp3.Interceptor
import okhttp3.Response
import okio.Buffer
import org.slf4j.LoggerFactory
import java.io.IOException
class InfoInterceptor(tag: String) : Interceptor {
private val log = StacktraceLoggerWrapper.getLogger(L.TIDEPOOL)
private var tag = "interceptor"
init {
this.tag = tag
}
class InfoInterceptor(val tag: String = "interceptor", val aapsLogger: AAPSLogger) : Interceptor {
@Throws(IOException::class)
override fun intercept(chain: Interceptor.Chain): Response {
val request = chain.request()
request.body?.let {
if (L.isEnabled(L.TIDEPOOL)) {
log.debug("Interceptor Body size: " + it.contentLength())
val requestBuffer = Buffer()
it.writeTo(requestBuffer)
log.debug("Interceptor Body: " + requestBuffer.readUtf8())
}
aapsLogger.debug(LTag.TIDEPOOL, "Interceptor Body size: " + it.contentLength())
val requestBuffer = Buffer()
it.writeTo(requestBuffer)
aapsLogger.debug(LTag.TIDEPOOL, "Interceptor Body: " + requestBuffer.readUtf8())
}
return chain.proceed(request)
}

View file

@ -68,7 +68,7 @@ class TidepoolUploader @Inject constructor(
val client = OkHttpClient.Builder()
.addInterceptor(httpLoggingInterceptor)
.addInterceptor(InfoInterceptor(TidepoolUploader::class.java.name))
.addInterceptor(InfoInterceptor(TidepoolUploader::class.java.name, aapsLogger))
.build()
retrofit = Retrofit.Builder()

View file

@ -1,23 +1,13 @@
package info.nightscout.androidaps.plugins.general.tidepool.events
import info.nightscout.androidaps.events.Event
import info.nightscout.androidaps.logging.L
import info.nightscout.androidaps.logging.StacktraceLoggerWrapper
import info.nightscout.androidaps.utils.DateUtil
import org.slf4j.LoggerFactory
import java.text.SimpleDateFormat
import java.util.*
class EventTidepoolStatus(val status: String) : Event() {
private val log = StacktraceLoggerWrapper.getLogger(L.TIDEPOOL)
var date: Long = DateUtil.now()
init {
if (L.isEnabled(L.TIDEPOOL))
log.debug("New status: $status")
}
private var timeFormat = SimpleDateFormat("HH:mm:ss", Locale.getDefault())
fun toPreparedHtml(): StringBuilder {
@ -29,5 +19,4 @@ class EventTidepoolStatus(val status: String) : Event() {
stringBuilder.append("<br>")
return stringBuilder
}
}

View file

@ -1,26 +1,27 @@
package info.nightscout.androidaps.plugins.general.tidepool.utils
import info.nightscout.androidaps.logging.L
import info.nightscout.androidaps.logging.StacktraceLoggerWrapper
import info.nightscout.androidaps.logging.AAPSLogger
import info.nightscout.androidaps.logging.LTag
import info.nightscout.androidaps.utils.DateUtil
import info.nightscout.androidaps.utils.T
import org.slf4j.LoggerFactory
import java.util.*
import javax.inject.Inject
import javax.inject.Singleton
object RateLimit {
@Singleton
class RateLimit @Inject constructor(
val aapsLogger: AAPSLogger
) {
private val rateLimits = HashMap<String, Long>()
private val log = StacktraceLoggerWrapper.getLogger(L.TIDEPOOL)
// return true if below rate limit
@Synchronized
fun rateLimit(name: String, seconds: Int): Boolean {
// check if over limit
rateLimits[name]?.let {
if (DateUtil.now() - it < T.secs(seconds.toLong()).msecs()) {
if (L.isEnabled(L.TIDEPOOL))
log.debug("$name rate limited: $seconds seconds")
aapsLogger.debug(LTag.TIDEPOOL, "$name rate limited: $seconds seconds")
return false
}
}