Rx module

This commit is contained in:
Milos Kozak 2022-11-06 12:28:35 +01:00
parent b4edb71e27
commit 4643b12414
983 changed files with 3228 additions and 2264 deletions

View file

@ -0,0 +1,35 @@
apply plugin: 'com.android.library'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-kapt'
apply plugin: 'kotlin-allopen'
apply plugin: 'com.hiya.jacoco-android'
apply plugin: 'kotlinx-serialization'
apply from: "${project.rootDir}/core/android_dependencies.gradle"
apply from: "${project.rootDir}/core/android_module_dependencies.gradle"
apply from: "${project.rootDir}/core/test_dependencies.gradle"
apply from: "${project.rootDir}/core/jacoco_global.gradle"
android {
namespace 'info.nightscout.rx'
defaultConfig {
minSdkVersion 23 // for wear
}
}
dependencies {
api "com.google.dagger:dagger:$dagger_version"
api "com.google.dagger:dagger-android:$dagger_version"
//Logger
api 'org.slf4j:slf4j-api:1.7.36' // 2.0.x breaks logging. Code change needed
api 'com.github.tony19:logback-android:2.0.0'
//RxBus
api "io.reactivex.rxjava3:rxjava:$rxjava_version"
api "io.reactivex.rxjava3:rxkotlin:$rxkotlin_version"
api "io.reactivex.rxjava3:rxandroid:$rxandroid_version"
api "org.jetbrains.kotlinx:kotlinx-serialization-json:1.4.1"
api "org.apache.commons:commons-lang3:$commonslang3_version"
}

View file

@ -0,0 +1,15 @@
package info.nightscout.rx.annotations
/**
* This is the actual annotation that makes the class open. Don't use it directly, only through [RxOpenForTesting]
* which has a NOOP replacement in production.
*/
@Target(AnnotationTarget.ANNOTATION_CLASS)
annotation class RxOpenClass
/**
* Annotate a class with [RxOpenForTesting] if it should be extendable for testing.
*/
@RxOpenClass
@Target(AnnotationTarget.CLASS)
annotation class RxOpenForTesting

View file

@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest>
</manifest>

View file

@ -1,4 +1,4 @@
package info.nightscout.androidaps.utils.rx
package info.nightscout.rx
import io.reactivex.rxjava3.android.schedulers.AndroidSchedulers
import io.reactivex.rxjava3.core.Scheduler

View file

@ -1,16 +1,16 @@
package info.nightscout.androidaps.plugins.bus
package info.nightscout.rx.bus
import info.nightscout.androidaps.annotations.OpenForTesting
import info.nightscout.androidaps.events.Event
import info.nightscout.shared.logging.AAPSLogger
import info.nightscout.shared.logging.LTag
import info.nightscout.androidaps.utils.rx.AapsSchedulers
import info.nightscout.rx.AapsSchedulers
import info.nightscout.rx.annotations.RxOpenForTesting
import info.nightscout.rx.events.Event
import info.nightscout.rx.logging.AAPSLogger
import info.nightscout.rx.logging.LTag
import io.reactivex.rxjava3.core.Observable
import io.reactivex.rxjava3.subjects.PublishSubject
import javax.inject.Inject
import javax.inject.Singleton
@OpenForTesting
@RxOpenForTesting
@Singleton
class RxBus @Inject constructor(
val aapsSchedulers: AapsSchedulers,
@ -26,7 +26,7 @@ class RxBus @Inject constructor(
// Listen should return an Observable and not the publisher
// Using ofType we filter only events that match that class type
fun <T: Any> toObservable(eventType: Class<T>): Observable<T> =
fun <T : Any> toObservable(eventType: Class<T>): Observable<T> =
publisher
.subscribeOn(aapsSchedulers.io)
.ofType(eventType)

View file

@ -0,0 +1,25 @@
package info.nightscout.rx.di
import dagger.Module
import dagger.Provides
import info.nightscout.rx.AapsSchedulers
import info.nightscout.rx.DefaultAapsSchedulers
import info.nightscout.rx.interfaces.L
import info.nightscout.rx.logging.AAPSLogger
import info.nightscout.rx.logging.AAPSLoggerProduction
import javax.inject.Singleton
@Module(
includes = [
]
)
open class RxModule {
@Provides
@Singleton
internal fun provideSchedulers(): AapsSchedulers = DefaultAapsSchedulers()
@Provides
@Singleton
fun provideAAPSLogger(l: L): AAPSLogger = AAPSLoggerProduction(l)
}

View file

@ -1,4 +1,4 @@
package info.nightscout.androidaps.events
package info.nightscout.rx.events
import org.apache.commons.lang3.builder.ReflectionToStringBuilder
import org.apache.commons.lang3.builder.ToStringStyle

View file

@ -0,0 +1,3 @@
package info.nightscout.rx.events
class EventAcceptOpenLoopChange : Event()

View file

@ -0,0 +1,3 @@
package info.nightscout.rx.events
class EventAppExit : Event()

View file

@ -0,0 +1,3 @@
package info.nightscout.rx.events
class EventAppInitialized : Event()

View file

@ -1,3 +1,3 @@
package info.nightscout.androidaps.events
package info.nightscout.rx.events
class EventAutosensCalculationFinished(val cause: Event?) : EventLoop()

View file

@ -1,4 +1,4 @@
package info.nightscout.androidaps.events
package info.nightscout.rx.events
class EventBTChange(val state: Change, val deviceName: String?, val deviceAddress: String? = null) : Event() {

View file

@ -1,3 +1,3 @@
package info.nightscout.androidaps.events
package info.nightscout.rx.events
class EventChargingState(val isCharging: Boolean, val batterLevel: Int) : Event()

View file

@ -0,0 +1,3 @@
package info.nightscout.rx.events
class EventConfigBuilderChange : Event()

View file

@ -0,0 +1,3 @@
package info.nightscout.rx.events
class EventCustomActionsChanged : Event()

View file

@ -1,3 +1,3 @@
package info.nightscout.androidaps.events
package info.nightscout.rx.events
class EventCustomCalculationFinished : Event()

View file

@ -1,3 +1,3 @@
package info.nightscout.androidaps.events
package info.nightscout.rx.events
class EventDanaRSyncStatus(var message: String) : Event()

View file

@ -0,0 +1,3 @@
package info.nightscout.rx.events
class EventExtendedBolusChange : EventLoop()

View file

@ -0,0 +1,3 @@
package info.nightscout.rx.events
class EventFoodDatabaseChanged : Event()

View file

@ -0,0 +1,3 @@
package info.nightscout.rx.events
class EventInitializationChanged : Event()

View file

@ -0,0 +1,3 @@
package info.nightscout.rx.events
class EventLocalProfileChanged : Event()

View file

@ -1,4 +1,4 @@
package info.nightscout.androidaps.events
package info.nightscout.rx.events
/** Supeclass for all events concerned with input or output into or from the LoopPlugin. */
abstract class EventLoop : Event()

View file

@ -0,0 +1,5 @@
package info.nightscout.rx.events
import info.nightscout.rx.weardata.EventData
class EventMobileToWear(val payload: EventData) : Event()

View file

@ -0,0 +1,3 @@
package info.nightscout.rx.events
class EventNSClientRestart : Event()

View file

@ -1,4 +1,4 @@
package info.nightscout.androidaps.events
package info.nightscout.rx.events
class EventNetworkChange(
var mobileConnected: Boolean = false,

View file

@ -1,3 +1,3 @@
package info.nightscout.androidaps.events
package info.nightscout.rx.events
class EventNtpStatus(val status: String, val percent: Int) : Event()

View file

@ -0,0 +1,3 @@
package info.nightscout.rx.events
class EventOfflineChange : Event()

View file

@ -0,0 +1,3 @@
package info.nightscout.rx.events
class EventProfileStoreChanged : Event()

View file

@ -1,3 +1,3 @@
package info.nightscout.androidaps.events
package info.nightscout.rx.events
class EventProfileSwitchChanged : Event()

View file

@ -1,3 +1,3 @@
package info.nightscout.androidaps.events
package info.nightscout.rx.events
class EventRebuildTabs constructor(var recreate: Boolean = false) : Event()

View file

@ -1,3 +1,3 @@
package info.nightscout.androidaps.events
package info.nightscout.rx.events
class EventRefreshOverview(var from: String, val now : Boolean = false) : Event()

View file

@ -1,3 +1,3 @@
package info.nightscout.androidaps.events
package info.nightscout.rx.events
class EventScale(val hours: Int) : Event()

View file

@ -0,0 +1,3 @@
package info.nightscout.rx.events
class EventTempBasalChange : EventLoop()

View file

@ -0,0 +1,3 @@
package info.nightscout.rx.events
class EventTempTargetChange : Event()

View file

@ -0,0 +1,3 @@
package info.nightscout.rx.events
class EventThemeSwitch : Event()

View file

@ -0,0 +1,3 @@
package info.nightscout.rx.events
class EventTherapyEventChange : Event()

View file

@ -0,0 +1,3 @@
package info.nightscout.rx.events
class EventTreatmentChange : EventLoop()

View file

@ -0,0 +1,4 @@
package info.nightscout.rx.events
/** Base class for events to update the UI, mostly a specific tab. */
abstract class EventUpdateGui : Event()

View file

@ -0,0 +1,5 @@
package info.nightscout.rx.events
import info.nightscout.rx.weardata.EventData
class EventWearToMobile(val payload: EventData) : Event()

View file

@ -0,0 +1,7 @@
package info.nightscout.rx.interfaces
interface L {
fun resetToDefaults()
fun findByName(name: String): LogElement
fun getLogElements(): List<LogElement>
}

View file

@ -0,0 +1,11 @@
package info.nightscout.rx.interfaces
interface LogElement {
var name: String
var defaultValue: Boolean
var enabled: Boolean
fun enable(enabled: Boolean)
fun resetToDefault()
}

View file

@ -1,4 +1,4 @@
package info.nightscout.shared.logging
package info.nightscout.rx.logging
/**
* Created by adrian on 2019-12-27.

View file

@ -1,5 +1,6 @@
package info.nightscout.shared.logging
package info.nightscout.rx.logging
import info.nightscout.rx.interfaces.L
import org.slf4j.LoggerFactory
/**

View file

@ -1,4 +1,4 @@
package info.nightscout.shared.logging
package info.nightscout.rx.logging
/**
* Created by adrian on 2019-12-27.

View file

@ -1,4 +1,4 @@
package info.nightscout.shared.logging
package info.nightscout.rx.logging
import android.os.Bundle

View file

@ -1,4 +1,4 @@
package info.nightscout.shared.logging
package info.nightscout.rx.logging
enum class LTag(val tag: String, val defaultValue : Boolean = true, val requiresRestart: Boolean = false) {
CORE("CORE"),

View file

@ -1,9 +1,9 @@
package info.nightscout.shared.weardata
package info.nightscout.rx.weardata
import info.nightscout.androidaps.events.Event
import info.nightscout.rx.events.Event
import kotlinx.serialization.Serializable
import kotlinx.serialization.json.Json
import java.util.*
import java.util.Objects
@Serializable
sealed class EventData : Event() {

View file

@ -0,0 +1,8 @@
package info.nightscout.rx.annotations
/**
* Annotate a class with [DbOpenForTesting] if it should be extendable for testing.
* In production the class remains final.
*/
@Target(AnnotationTarget.CLASS)
annotation class RxOpenForTesting

View file

@ -0,0 +1 @@
/build

View file

@ -0,0 +1,24 @@
apply plugin: 'com.android.library'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-kapt'
apply plugin: 'kotlin-allopen'
apply plugin: 'com.hiya.jacoco-android'
apply plugin: 'kotlinx-serialization'
apply from: "${project.rootDir}/core/android_dependencies.gradle"
apply from: "${project.rootDir}/core/android_module_dependencies.gradle"
//apply from: "${project.rootDir}/core/test_dependencies.gradle"
//apply from: "${project.rootDir}/core/jacoco_global.gradle"
android {
namespace 'info.nightscout.shared.impl'
defaultConfig {
minSdkVersion 23 // for wear
}
}
dependencies {
implementation project(':app-wear-shared:rx')
implementation project(':app-wear-shared:shared')
}

View file

@ -0,0 +1,21 @@
# Add project specific ProGuard rules here.
# You can control the set of applied configuration files using the
# proguardFiles setting in build.gradle.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html
# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
#}
# Uncomment this to preserve the line number information for
# debugging stack traces.
#-keepattributes SourceFile,LineNumberTable
# If you keep the line number information, uncomment this to
# hide the original source file name.
#-renamesourcefileattribute SourceFile

View file

@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest>
</manifest>

View file

@ -0,0 +1,19 @@
package info.nightscout.rx.di
import dagger.Module
import dagger.Provides
import info.nightcout.shared.impl.logging.LImpl
import info.nightscout.rx.interfaces.L
import info.nightscout.shared.sharedPreferences.SP
import javax.inject.Singleton
@Module(
includes = [
]
)
open class SharedImplModule {
@Provides
@Singleton
fun provideL(sp: SP): L = LImpl(sp)
}

View file

@ -1,43 +1,46 @@
package info.nightscout.shared.logging
package info.nightcout.shared.impl.logging
import info.nightscout.rx.interfaces.L
import info.nightscout.rx.interfaces.LogElement
import info.nightscout.rx.logging.LTag
import info.nightscout.shared.sharedPreferences.SP
import java.util.*
import javax.inject.Inject
import javax.inject.Singleton
@Singleton
class L @Inject constructor(
class LImpl @Inject constructor(
private val sp: SP
) {
) : L {
private var logElements: MutableList<LogElement> = ArrayList()
init {
LTag.values().forEach { logElements.add(LogElement(it, sp)) }
LTag.values().forEach { logElements.add(LogElementImpl(it, sp)) }
}
fun findByName(name: String): LogElement {
override fun findByName(name: String): LogElement {
for (element in logElements) {
if (element.name == name) return element
}
return LogElement(false, sp)
return LogElementImpl(false, sp)
}
fun getLogElements(): List<LogElement> {
override fun getLogElements(): List<LogElement> {
return logElements
}
fun resetToDefaults() {
override fun resetToDefaults() {
for (element in logElements) {
element.resetToDefault()
}
}
class LogElement {
class LogElementImpl : LogElement {
var sp: SP
var name: String
var defaultValue: Boolean
var enabled: Boolean
override var name: String
override var defaultValue: Boolean
override var enabled: Boolean
private var requiresRestart = false
internal constructor(tag: LTag, sp: SP) {
@ -57,12 +60,12 @@ class L @Inject constructor(
private fun getSPName(): String = "log_$name"
fun enable(enabled: Boolean) {
override fun enable(enabled: Boolean) {
this.enabled = enabled
sp.putBoolean(getSPName(), enabled)
}
fun resetToDefault() {
override fun resetToDefault() {
enable(defaultValue)
}
}

1
app-wear-shared/shared/.gitignore vendored Normal file
View file

@ -0,0 +1 @@
/build

View file

@ -0,0 +1,21 @@
# Add project specific ProGuard rules here.
# You can control the set of applied configuration files using the
# proguardFiles setting in build.gradle.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html
# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
#}
# Uncomment this to preserve the line number information for
# debugging stack traces.
#-keepattributes SourceFile,LineNumberTable
# If you keep the line number information, uncomment this to
# hide the original source file name.
#-renamesourcefileattribute SourceFile

View file

@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest>
</manifest>

View file

@ -5,7 +5,15 @@ import android.content.res.AssetFileDescriptor
import android.graphics.Bitmap
import android.graphics.drawable.Drawable
import android.util.DisplayMetrics
import androidx.annotation.*
import androidx.annotation.ArrayRes
import androidx.annotation.AttrRes
import androidx.annotation.BoolRes
import androidx.annotation.ColorInt
import androidx.annotation.ColorRes
import androidx.annotation.DrawableRes
import androidx.annotation.PluralsRes
import androidx.annotation.RawRes
import androidx.annotation.StringRes
interface ResourceHelper {
fun updateContext(ctx: Context?)

View file

@ -20,7 +20,12 @@ import java.text.SimpleDateFormat
import java.time.Instant
import java.time.ZoneId
import java.time.ZoneOffset
import java.util.*
import java.util.Calendar
import java.util.Date
import java.util.EnumSet
import java.util.GregorianCalendar
import java.util.Locale
import java.util.TimeZone
import java.util.concurrent.TimeUnit
import java.util.regex.Pattern
import java.util.stream.Collectors

View file

@ -4,22 +4,17 @@ import android.content.Context
import androidx.preference.PreferenceManager
import dagger.Module
import dagger.Provides
import info.nightscout.shared.logging.AAPSLogger
import info.nightscout.shared.logging.AAPSLoggerProduction
import info.nightscout.shared.logging.L
import info.nightscout.shared.sharedPreferences.SP
import info.nightscout.shared.sharedPreferences.SPImplementation
import javax.inject.Singleton
@Module(includes = [
])
@Module(
includes = [
]
)
open class SharedModule {
@Provides
@Singleton
fun provideSharedPreferences(context: Context): SP = SPImplementation(PreferenceManager.getDefaultSharedPreferences(context), context)
@Provides
@Singleton
fun provideAAPSLogger(l: L): AAPSLogger = AAPSLoggerProduction(l)
}

Some files were not shown because too many files have changed in this diff Show more