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> */ </T> */
private fun <T> determineActivePlugin(pluginsInCategory: ArrayList<PluginBase>, private fun <T> determineActivePlugin(pluginsInCategory: ArrayList<PluginBase>,
pluginType: PluginType): T? { pluginType: PluginType): T? {
@Suppress("UNCHECKED_CAST")
val activePlugin = getTheOneEnabledInArray(pluginsInCategory, pluginType) as T? val activePlugin = getTheOneEnabledInArray(pluginsInCategory, pluginType) as T?
if (activePlugin != null) { if (activePlugin != null) {
setFragmentVisiblities((activePlugin as PluginBase).name, pluginsInCategory, pluginType) setFragmentVisiblities((activePlugin as PluginBase).name, pluginsInCategory, pluginType)

View file

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

View file

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

View file

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

View file

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

View file

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