From 74b378886c3d4ffaf902acf6ecafc5f93bb8fc3a Mon Sep 17 00:00:00 2001 From: Bojan Date: Fri, 24 Dec 2021 13:34:21 +0100 Subject: [PATCH] * Update Kotlin to 1.6.10. * Update Gradle wrapper to 7.3.3. * Update AndroidX dependencies. * Fix collecting flows on lifecycle. * Fix core JVM static method calls with Kotlin 1.6.x. * Fix missing event parameters in session list. * Fix large event parameters in detail view. * Fix large event parameters for in app notification. * Add exhaustive branches in generated code. --- .idea/misc.xml | 1 + CHANGELOG.md | 14 ++++++ README.md | 12 ++--- config.gradle | 4 +- .../main/kotlin/com/infinum/collar/Collar.kt | 6 +++ gradle/libs.versions.toml | 45 ++++++++--------- gradle/wrapper/gradle-wrapper.properties | 2 +- ktlint.gradle | 2 +- .../processor/specs/AnalyticsEventsSpec.kt | 1 + .../collar/processor/specs/ScreenNameSpec.kt | 1 + .../processor/specs/UserPropertiesSpec.kt | 1 + sample/build.gradle | 2 +- .../infinum/collar/sample/MainActivity.java | 48 ++++++++++++++++++- .../infinum/collar/sample/AnalyticsEvent.kt | 48 ++++++++++++++++++- ui/build.gradle | 2 +- .../dialogs/CollarDetailDialog.kt | 21 +++++++- .../inapp/snackbar/CollarSnackbarView.kt | 2 + .../presentation/shared/base/BaseActivity.kt | 3 +- .../base/BaseBottomSheetDialogFragment.kt | 3 +- .../ui/presentation/shared/base/BaseView.kt | 32 ++++++++----- .../presentation/shared/base/BaseViewModel.kt | 4 +- .../shared/delegates/ViewBindingDelegate.kt | 20 +++++--- .../viewholders/shared/CollarViewHolder.kt | 2 +- .../main/res/layout/collar_dialog_detail.xml | 22 ++++++--- .../main/res/layout/collar_view_snackbar.xml | 1 + 25 files changed, 229 insertions(+), 70 deletions(-) diff --git a/.idea/misc.xml b/.idea/misc.xml index 03d7bea9..fd2c2e93 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -13,6 +13,7 @@ + diff --git a/CHANGELOG.md b/CHANGELOG.md index e0386dcd..74ee29ac 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,20 @@ Change Log ========== +## Version 1.3.2 + +_2021-12-24_ + +* Update Kotlin to 1.6.10. +* Update Gradle wrapper to 7.3.3. +* Update AndroidX dependencies. +* Fix collecting flows on lifecycle. +* Fix core JVM static method calls with Kotlin 1.6.x. +* Fix missing event parameters in session list. +* Fix large event parameters in detail view. +* Fix large event parameters for in app notification. +* Add exhaustive branches in generated code. + ## Version 1.3.1 _2021-09-27_ diff --git a/README.md b/README.md index 6c428938..60551e93 100644 --- a/README.md +++ b/README.md @@ -31,7 +31,7 @@ buildscript { mavenCentral() } dependencies { - classpath "com.infinum.collar:collar-plugin:1.3.1" + classpath "com.infinum.collar:collar-plugin:1.3.2" } } ``` @@ -42,7 +42,7 @@ buildscript { mavenCentral() } dependencies { - classpath("com.infinum.collar:collar-plugin:1.3.1") + classpath("com.infinum.collar:collar-plugin:1.3.2") } } ``` @@ -259,13 +259,13 @@ You can search, filter and clear all sent analytics. In your app `build.gradle` or `build.gradle.kts` add: **Groovy** ```gradle -debugImplementation "com.infinum.collar:collar-ui:1.3.1" -releaseImplementation "com.infinum.collar:collar-ui-no-op:1.3.1" +debugImplementation "com.infinum.collar:collar-ui:1.3.2" +releaseImplementation "com.infinum.collar:collar-ui-no-op:1.3.2" ``` **KotlinDSL** ```kotlin -debugImplementation("com.infinum.collar:collar-ui:1.3.1") -releaseImplementation("com.infinum.collar:collar-ui-no-op:1.3.1") +debugImplementation("com.infinum.collar:collar-ui:1.3.2") +releaseImplementation("com.infinum.collar:collar-ui-no-op:1.3.2") ``` In order to start tracking with UI you must use _LiveCollector_ as in this example: diff --git a/config.gradle b/config.gradle index 2f2cc298..326e467c 100644 --- a/config.gradle +++ b/config.gradle @@ -7,7 +7,7 @@ ext { ] releaseConfig = [ "group" : "com.infinum.collar", - "version" : "1.3.1", - "versionCode": 1 * 100 * 100 + 3 * 100 + 1 + "version" : "1.3.2", + "versionCode": 1 * 100 * 100 + 3 * 100 + 2 ] } \ No newline at end of file diff --git a/core/src/main/kotlin/com/infinum/collar/Collar.kt b/core/src/main/kotlin/com/infinum/collar/Collar.kt index bc7a27f8..12c7893d 100644 --- a/core/src/main/kotlin/com/infinum/collar/Collar.kt +++ b/core/src/main/kotlin/com/infinum/collar/Collar.kt @@ -34,6 +34,7 @@ public object Collar { * * @param screenName value. */ + @JvmStatic public fun trackScreen(screenName: String): Unit = collector?.onScreen( Screen( @@ -46,6 +47,7 @@ public object Collar { * * @param screen wrapper class. */ + @JvmStatic public fun trackScreen(screen: Screen): Unit = collector?.onScreen(screen) ?: Unit @@ -55,6 +57,7 @@ public object Collar { * @param eventName value. * @param params value. */ + @JvmStatic public fun trackEvent(eventName: String, params: Bundle): Unit = collector?.onEvent( Event( @@ -68,6 +71,7 @@ public object Collar { * * @param event wrapper class. */ + @JvmStatic public fun trackEvent(event: Event): Unit = collector?.onEvent(event) ?: Unit @@ -78,6 +82,7 @@ public object Collar { * @param name value. * @param value value. */ + @JvmStatic public fun trackProperty(name: String, value: String?): Unit = collector?.onProperty( Property( @@ -91,6 +96,7 @@ public object Collar { * * @param property wrapper class. */ + @JvmStatic public fun trackProperty(property: Property): Unit = collector?.onProperty(property) ?: Unit } diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index c4f44f8e..f5050cf1 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -1,28 +1,29 @@ [versions] -collar = "1.3.1" -gradle = "7.0.2" -lint = "30.0.2" -kotlin = "1.5.31" -coroutines = "1.5.2" -serialization = "1.3.0" -poet = "1.10.1" -annotations = "22.0.0" -core = "1.6.0" -appcompat = "1.3.1" -activity = "1.3.1" -fragment = "1.3.6" -lifecycle = "2.3.1" +collar = "1.3.2" +gradle = "7.0.4" +lint = "30.0.4" +kotlin = "1.6.10" +coroutines = "1.6.0" +serialization = "1.3.1" +poet = "1.10.2" +annotations = "23.0.0" +core = "1.7.0" +appcompat = "1.4.0" +activity = "1.4.0" +fragment = "1.4.0" +lifecycle = "2.4.0" recyclerview = "1.2.1" -room = "2.4.0-alpha04" +room = "2.4.0" startup = "1.1.0" dynamicanimation = "1.0.0" design = "1.4.0" -koin = "3.1.2" -timber = "5.0.0" -detekt = "1.18.1" -ktlint = "10.2.0" -cpd = "3.1" -dokka = "1.5.30" +koin = "3.1.4" +timber = "5.0.1" +detekt = "1.18.0" +ktlintplugin = "10.2.0" +ktlint = "0.43.1" +cpd = "3.2" +dokka = "1.6.0" [libraries] libraryannotations = { module = "com.infinum.collar:collar-annotations", version.ref = "collar" } @@ -55,7 +56,7 @@ androidx-activity = { module = "androidx.activity:activity-ktx", version.ref = " androidx-fragment = { module = "androidx.fragment:fragment-ktx", version.ref = "fragment" } androidx-lifecycle-viewmodel = { module = "androidx.lifecycle:lifecycle-viewmodel-ktx", version.ref = "lifecycle" } androidx-lifecycle-livedata = { module = "androidx.lifecycle:lifecycle-livedata-ktx", version.ref = "lifecycle" } -androidx-lifecycle-runtime = { module = "androidx.lifecycle:lifecycle-runtime", version.ref = "lifecycle" } +androidx-lifecycle-runtime = { module = "androidx.lifecycle:lifecycle-runtime-ktx", version.ref = "lifecycle" } androidx-recyclerview = { module = "androidx.recyclerview:recyclerview", version.ref = "recyclerview" } androidx-dynamicanimation = { module = "androidx.dynamicanimation:dynamicanimation", version.ref = "dynamicanimation" } androidx-startup = { module = "androidx.startup:startup-runtime", version.ref = "startup" } @@ -75,7 +76,7 @@ timber = { module = "com.jakewharton.timber:timber", version.ref = "timber" } detekt-gradle = { module = "io.gitlab.arturbosch.detekt:detekt-gradle-plugin", version.ref = "detekt" } detekt-formatting = { module = "io.gitlab.arturbosch.detekt:detekt-formatting", version.ref = "detekt" } -ktlint = { module = "org.jlleitschuh.gradle:ktlint-gradle", version.ref = "ktlint" } +ktlint = { module = "org.jlleitschuh.gradle:ktlint-gradle", version.ref = "ktlintplugin" } cpd = { module = "de.aaschmid:gradle-cpd-plugin", version.ref = "cpd" } diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index ffed3a25..2e6e5897 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,5 +1,5 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-7.2-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-7.3.3-bin.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/ktlint.gradle b/ktlint.gradle index 197e683f..9424250a 100644 --- a/ktlint.gradle +++ b/ktlint.gradle @@ -1,7 +1,7 @@ apply plugin: "org.jlleitschuh.gradle.ktlint" ktlint { - version = "0.42.1" + version = libs.versions.ktlint.get() debug = false android = true } \ No newline at end of file diff --git a/processor/src/main/kotlin/com/infinum/collar/processor/specs/AnalyticsEventsSpec.kt b/processor/src/main/kotlin/com/infinum/collar/processor/specs/AnalyticsEventsSpec.kt index 3da4c233..845e7e9c 100644 --- a/processor/src/main/kotlin/com/infinum/collar/processor/specs/AnalyticsEventsSpec.kt +++ b/processor/src/main/kotlin/com/infinum/collar/processor/specs/AnalyticsEventsSpec.kt @@ -56,6 +56,7 @@ internal class AnalyticsEventsSpec( unindent() addStatement(STATEMENT_EVENT_CLASS_END) } + addStatement("else -> Unit") } .build() diff --git a/processor/src/main/kotlin/com/infinum/collar/processor/specs/ScreenNameSpec.kt b/processor/src/main/kotlin/com/infinum/collar/processor/specs/ScreenNameSpec.kt index 6a95fc04..c323ad46 100644 --- a/processor/src/main/kotlin/com/infinum/collar/processor/specs/ScreenNameSpec.kt +++ b/processor/src/main/kotlin/com/infinum/collar/processor/specs/ScreenNameSpec.kt @@ -53,6 +53,7 @@ internal class ScreenNameSpec( holders.forEach { addStatement(this, it) } + addStatement("else -> Unit") } .build() diff --git a/processor/src/main/kotlin/com/infinum/collar/processor/specs/UserPropertiesSpec.kt b/processor/src/main/kotlin/com/infinum/collar/processor/specs/UserPropertiesSpec.kt index edd9b6df..c2724d13 100644 --- a/processor/src/main/kotlin/com/infinum/collar/processor/specs/UserPropertiesSpec.kt +++ b/processor/src/main/kotlin/com/infinum/collar/processor/specs/UserPropertiesSpec.kt @@ -44,6 +44,7 @@ internal class UserPropertiesSpec( it.propertyParameterNames.single() ) } + addStatement("else -> Unit") } .build() } diff --git a/sample/build.gradle b/sample/build.gradle index 4b3637e3..d360d974 100644 --- a/sample/build.gradle +++ b/sample/build.gradle @@ -52,7 +52,7 @@ android { javaCompileOptions { annotationProcessorOptions { argument "events_count", "100" - argument "event_parameters_count", "17" + argument "event_parameters_count", "60" argument "event_name_length", "20" argument "reserved_prefixes", "ga_,fb_" } diff --git a/sample/src/main/java/com/infinum/collar/sample/MainActivity.java b/sample/src/main/java/com/infinum/collar/sample/MainActivity.java index 89140d5c..87488241 100644 --- a/sample/src/main/java/com/infinum/collar/sample/MainActivity.java +++ b/sample/src/main/java/com/infinum/collar/sample/MainActivity.java @@ -52,7 +52,53 @@ public void onClick(View v) { 18, 2L, Short.MAX_VALUE, - buildBundle() + buildBundle(), + "awesome", + true, + Byte.MAX_VALUE, + Character.MAX_VALUE, + 7.11, + 31.5f, + 18, + 2L, + Short.MAX_VALUE, + "awesome", + true, + Byte.MAX_VALUE, + Character.MAX_VALUE, + 7.11, + 31.5f, + 18, + 2L, + Short.MAX_VALUE, + "awesome", + true, + Byte.MAX_VALUE, + Character.MAX_VALUE, + 7.11, + 31.5f, + 18, + 2L, + Short.MAX_VALUE, + buildBundle(), + "awesome", + true, + Byte.MAX_VALUE, + Character.MAX_VALUE, + 7.11, + 31.5f, + 18, + 2L, + Short.MAX_VALUE, + "awesome", + true, + Byte.MAX_VALUE, + Character.MAX_VALUE, + 7.11, + 31.5f, + 18, + 2L, + Short.MAX_VALUE )); } } diff --git a/sample/src/main/kotlin/com/infinum/collar/sample/AnalyticsEvent.kt b/sample/src/main/kotlin/com/infinum/collar/sample/AnalyticsEvent.kt index 8a7ca3dc..644b812b 100644 --- a/sample/src/main/kotlin/com/infinum/collar/sample/AnalyticsEvent.kt +++ b/sample/src/main/kotlin/com/infinum/collar/sample/AnalyticsEvent.kt @@ -19,7 +19,53 @@ sealed class AnalyticsEvent { val myInt: Int, val myLong: Long, val myShort: Short, - val myBundle: Bundle + val myBundle: Bundle, + val myOtherString: String, + val myOtherBoolean: Boolean, + val myOtherByte: Byte, + val myOtherChar: Char, + val myOtherDouble: Double, + val myOtherFloat: Float, + val myOtherInt: Int, + val myOtherLong: Long, + val myOtherShort: Short, + val myBrandString: String, + val myBrandBoolean: Boolean, + val myBrandByte: Byte, + val myBrandChar: Char, + val myBrandDouble: Double, + val myBrandFloat: Float, + val myBrandInt: Int, + val myBrandLong: Long, + val myBrandShort: Short, + val myString2: String, + val myBoolean2: Boolean, + val myByte2: Byte, + val myChar2: Char, + val myDouble2: Double, + val myFloat2: Float, + val myInt2: Int, + val myLong2: Long, + val myShort2: Short, + val myBundle2: Bundle, + val myOtherString2: String, + val myOtherBoolean2: Boolean, + val myOtherByte2: Byte, + val myOtherChar2: Char, + val myOtherDouble2: Double, + val myOtherFloat2: Float, + val myOtherInt2: Int, + val myOtherLong2: Long, + val myOtherShort2: Short, + val myBrandString2: String, + val myBrandBoolean2: Boolean, + val myBrandByte2: Byte, + val myBrandChar2: Char, + val myBrandDouble2: Double, + val myBrandFloat2: Float, + val myBrandInt2: Int, + val myBrandLong2: Long, + val myBrandShort2: Short ) : AnalyticsEvent() data class Event2( diff --git a/ui/build.gradle b/ui/build.gradle index ec8267ad..22140743 100644 --- a/ui/build.gradle +++ b/ui/build.gradle @@ -1,7 +1,7 @@ plugins { id "com.android.library" id "kotlin-android" - id "com.google.devtools.ksp" version "1.5.31-1.0.0" + id "com.google.devtools.ksp" version "1.6.10-1.0.2" } android { diff --git a/ui/src/main/kotlin/com/infinum/collar/ui/presentation/dialogs/CollarDetailDialog.kt b/ui/src/main/kotlin/com/infinum/collar/ui/presentation/dialogs/CollarDetailDialog.kt index bf4d5d4f..01b058ab 100644 --- a/ui/src/main/kotlin/com/infinum/collar/ui/presentation/dialogs/CollarDetailDialog.kt +++ b/ui/src/main/kotlin/com/infinum/collar/ui/presentation/dialogs/CollarDetailDialog.kt @@ -5,6 +5,7 @@ import android.view.View import androidx.core.app.ShareCompat import androidx.core.view.isGone import androidx.core.view.isVisible +import androidx.core.widget.NestedScrollView import com.infinum.collar.ui.R import com.infinum.collar.ui.data.models.local.CollarEntity import com.infinum.collar.ui.data.models.local.EntityType @@ -62,11 +63,13 @@ internal class CollarDetailDialog : BaseBottomSheetDialogFragment(R.la } } - @Suppress("ComplexMethod") + @Suppress("ComplexMethod", "LongMethod") override fun onViewCreated(view: View, savedInstanceState: Bundle?) { super.onViewCreated(view, savedInstanceState) with(binding) { + appBarLayout.isLiftOnScroll = true + appBarLayout.isLifted = false toolbar.setNavigationOnClickListener { dismiss() } @@ -119,6 +122,22 @@ internal class CollarDetailDialog : BaseBottomSheetDialogFragment(R.la } } } + contentView.setOnScrollChangeListener( + NestedScrollView.OnScrollChangeListener { v, _, scrollY, _, oldScrollY -> + if (scrollY > oldScrollY) { + appBarLayout.isLifted = true + } + if (scrollY < oldScrollY) { + appBarLayout.isLifted = true + } + if (scrollY == 0) { + appBarLayout.isLifted = false + } + if (scrollY == v.measuredHeight - v.getChildAt(0).measuredHeight) { + appBarLayout.isLifted = true + } + } + ) } } diff --git a/ui/src/main/kotlin/com/infinum/collar/ui/presentation/notifications/inapp/snackbar/CollarSnackbarView.kt b/ui/src/main/kotlin/com/infinum/collar/ui/presentation/notifications/inapp/snackbar/CollarSnackbarView.kt index 6e4133bc..5fa5b0f2 100644 --- a/ui/src/main/kotlin/com/infinum/collar/ui/presentation/notifications/inapp/snackbar/CollarSnackbarView.kt +++ b/ui/src/main/kotlin/com/infinum/collar/ui/presentation/notifications/inapp/snackbar/CollarSnackbarView.kt @@ -5,6 +5,7 @@ import android.content.res.ColorStateList import android.graphics.PorterDuff import android.graphics.PorterDuffColorFilter import android.os.Build +import android.text.method.ScrollingMovementMethod import android.util.AttributeSet import android.view.LayoutInflater import android.widget.FrameLayout @@ -26,6 +27,7 @@ internal class CollarSnackbarView @JvmOverloads constructor( this, true ).apply { + this.valueView.movementMethod = ScrollingMovementMethod() this.root.setOnClickListener { CollarUi.show() } } diff --git a/ui/src/main/kotlin/com/infinum/collar/ui/presentation/shared/base/BaseActivity.kt b/ui/src/main/kotlin/com/infinum/collar/ui/presentation/shared/base/BaseActivity.kt index 35757b08..4f7108d7 100644 --- a/ui/src/main/kotlin/com/infinum/collar/ui/presentation/shared/base/BaseActivity.kt +++ b/ui/src/main/kotlin/com/infinum/collar/ui/presentation/shared/base/BaseActivity.kt @@ -3,7 +3,6 @@ package com.infinum.collar.ui.presentation.shared.base import android.os.Bundle import androidx.annotation.RestrictTo import androidx.appcompat.app.AppCompatActivity -import androidx.lifecycle.lifecycleScope import androidx.viewbinding.ViewBinding import com.infinum.collar.ui.di.LibraryKoinComponent @@ -17,6 +16,6 @@ internal abstract class BaseActivity : AppCompatActivity(), BaseVi setContentView(binding.root) - collectFlows(lifecycleScope) + collectFlows(this) } } diff --git a/ui/src/main/kotlin/com/infinum/collar/ui/presentation/shared/base/BaseBottomSheetDialogFragment.kt b/ui/src/main/kotlin/com/infinum/collar/ui/presentation/shared/base/BaseBottomSheetDialogFragment.kt index 012f4a23..d075fec3 100644 --- a/ui/src/main/kotlin/com/infinum/collar/ui/presentation/shared/base/BaseBottomSheetDialogFragment.kt +++ b/ui/src/main/kotlin/com/infinum/collar/ui/presentation/shared/base/BaseBottomSheetDialogFragment.kt @@ -10,7 +10,6 @@ import android.view.WindowManager import androidx.annotation.CallSuper import androidx.annotation.LayoutRes import androidx.annotation.RestrictTo -import androidx.lifecycle.lifecycleScope import androidx.viewbinding.ViewBinding import com.google.android.material.bottomsheet.BottomSheetDialogFragment import com.infinum.collar.ui.R @@ -40,6 +39,6 @@ internal abstract class BaseBottomSheetDialogFragment( @CallSuper override fun onViewCreated(view: View, savedInstanceState: Bundle?) { - collectFlows(viewLifecycleOwner.lifecycleScope) + collectFlows(viewLifecycleOwner) } } diff --git a/ui/src/main/kotlin/com/infinum/collar/ui/presentation/shared/base/BaseView.kt b/ui/src/main/kotlin/com/infinum/collar/ui/presentation/shared/base/BaseView.kt index 460bcb28..fe64790e 100644 --- a/ui/src/main/kotlin/com/infinum/collar/ui/presentation/shared/base/BaseView.kt +++ b/ui/src/main/kotlin/com/infinum/collar/ui/presentation/shared/base/BaseView.kt @@ -1,7 +1,11 @@ package com.infinum.collar.ui.presentation.shared.base -import androidx.lifecycle.LifecycleCoroutineScope +import androidx.lifecycle.Lifecycle +import androidx.lifecycle.LifecycleOwner +import androidx.lifecycle.lifecycleScope +import androidx.lifecycle.repeatOnLifecycle import kotlinx.coroutines.flow.collectLatest +import kotlinx.coroutines.launch internal interface BaseView { @@ -13,20 +17,22 @@ internal interface BaseView { fun onError(error: Throwable) {} - fun collectFlows(lifecycleCoroutineScope: LifecycleCoroutineScope) { - lifecycleCoroutineScope.launchWhenStarted { - viewModel?.stateFlow?.collectLatest { state -> - state?.let { onState(it) } + fun collectFlows(owner: LifecycleOwner) { + with(owner) { + lifecycleScope.launch { + lifecycle.repeatOnLifecycle(Lifecycle.State.STARTED) { + viewModel?.stateFlow?.collectLatest { state -> state?.let { onState(it) } } + } } - } - lifecycleCoroutineScope.launchWhenStarted { - viewModel?.eventFlow?.collectLatest { - onEvent(it) + lifecycleScope.launch { + lifecycle.repeatOnLifecycle(Lifecycle.State.STARTED) { + viewModel?.eventFlow?.collectLatest { event -> event?.let { onEvent(it) } } + } } - } - lifecycleCoroutineScope.launchWhenStarted { - viewModel?.errorFlow?.collectLatest { throwable -> - throwable?.let { onError(it) } + lifecycleScope.launch { + lifecycle.repeatOnLifecycle(Lifecycle.State.STARTED) { + viewModel?.errorFlow?.collectLatest { throwable -> throwable?.let { onError(it) } } + } } } } diff --git a/ui/src/main/kotlin/com/infinum/collar/ui/presentation/shared/base/BaseViewModel.kt b/ui/src/main/kotlin/com/infinum/collar/ui/presentation/shared/base/BaseViewModel.kt index 38e14885..d7cf1d8b 100644 --- a/ui/src/main/kotlin/com/infinum/collar/ui/presentation/shared/base/BaseViewModel.kt +++ b/ui/src/main/kotlin/com/infinum/collar/ui/presentation/shared/base/BaseViewModel.kt @@ -27,11 +27,11 @@ internal abstract class BaseViewModel : ViewModel(), LibraryKoinCo private var mainDispatchers = Dispatchers.Main private val mutableStateFlow: MutableStateFlow = MutableStateFlow(null) - private val mutableEventFlow: MutableSharedFlow = MutableSharedFlow(replay = 1) + private val mutableEventFlow: MutableSharedFlow = MutableSharedFlow(replay = 1) private val mutableErrorFlow: MutableStateFlow = MutableStateFlow(null) val stateFlow: StateFlow get() = mutableStateFlow.asStateFlow() - val eventFlow: SharedFlow get() = mutableEventFlow.asSharedFlow() + val eventFlow: SharedFlow get() = mutableEventFlow.asSharedFlow() val errorFlow: StateFlow get() = mutableErrorFlow.asStateFlow() protected open val errorHandler = CoroutineExceptionHandler { _, throwable -> diff --git a/ui/src/main/kotlin/com/infinum/collar/ui/presentation/shared/delegates/ViewBindingDelegate.kt b/ui/src/main/kotlin/com/infinum/collar/ui/presentation/shared/delegates/ViewBindingDelegate.kt index e423f493..98d13465 100644 --- a/ui/src/main/kotlin/com/infinum/collar/ui/presentation/shared/delegates/ViewBindingDelegate.kt +++ b/ui/src/main/kotlin/com/infinum/collar/ui/presentation/shared/delegates/ViewBindingDelegate.kt @@ -7,10 +7,12 @@ import androidx.fragment.app.Fragment import androidx.lifecycle.Lifecycle import androidx.lifecycle.asFlow import androidx.lifecycle.lifecycleScope +import androidx.lifecycle.repeatOnLifecycle import androidx.viewbinding.ViewBinding import kotlin.properties.ReadOnlyProperty import kotlin.reflect.KProperty import kotlinx.coroutines.flow.collectLatest +import kotlinx.coroutines.launch internal class ViewBindingDelegate( private val fragment: Fragment, @@ -20,14 +22,18 @@ internal class ViewBindingDelegate( private var binding: T? = null init { - fragment.lifecycleScope.launchWhenCreated { - fragment.viewLifecycleOwnerLiveData - .asFlow() - .collectLatest { - if (it == null) { - binding = null - } + with(fragment) { + lifecycleScope.launch { + lifecycle.repeatOnLifecycle(Lifecycle.State.CREATED) { + viewLifecycleOwnerLiveData + .asFlow() + .collectLatest { + if (it == null) { + binding = null + } + } } + } } } diff --git a/ui/src/main/kotlin/com/infinum/collar/ui/presentation/viewholders/shared/CollarViewHolder.kt b/ui/src/main/kotlin/com/infinum/collar/ui/presentation/viewholders/shared/CollarViewHolder.kt index c87e3d07..6bf5eb96 100644 --- a/ui/src/main/kotlin/com/infinum/collar/ui/presentation/viewholders/shared/CollarViewHolder.kt +++ b/ui/src/main/kotlin/com/infinum/collar/ui/presentation/viewholders/shared/CollarViewHolder.kt @@ -52,7 +52,7 @@ internal abstract class CollarViewHolder( } timeView.text = Date(entity.timestamp).presentationItemFormat nameView.text = entity.name - valueView?.text = entity.value + valueView?.text = entity.value ?: entity.parameters rootView.setOnClickListener { onClick(entity) } } diff --git a/ui/src/main/res/layout/collar_dialog_detail.xml b/ui/src/main/res/layout/collar_dialog_detail.xml index ecc66097..f76c2845 100644 --- a/ui/src/main/res/layout/collar_dialog_detail.xml +++ b/ui/src/main/res/layout/collar_dialog_detail.xml @@ -6,15 +6,25 @@ android:layout_height="wrap_content" android:orientation="vertical"> - + android:layout_height="wrap_content" + android:background="?colorSurface" + app:liftOnScroll="true"> + + + + diff --git a/ui/src/main/res/layout/collar_view_snackbar.xml b/ui/src/main/res/layout/collar_view_snackbar.xml index 6b1566fb..b57fa1b4 100644 --- a/ui/src/main/res/layout/collar_view_snackbar.xml +++ b/ui/src/main/res/layout/collar_view_snackbar.xml @@ -43,6 +43,7 @@ style="@style/TextAppearance.MaterialComponents.Body2" android:layout_width="match_parent" android:layout_height="wrap_content" + android:scrollbars="vertical" android:textColor="@android:color/white" tools:text="test_property_value\ntest_property_value\ntest_property_value\ntest_property_value" />