Question regarding `Flow` collection, `RecyclerView`s and MVVM. For a simple list to be displayed in...
m

Mark

about 5 years ago
Question regarding
Flow
collection, `RecyclerView`s and MVVM. For a simple list to be displayed in a
RecyclerView
, the
ViewModel
exposes a
Flow
of
List<Item>
which is collected in the
Fragment
which in turn sets the items on a `RecyclerView`’s adapter (and calls
notifyDataSetChanged()
). I believe this is standard procedure. However, suppose I want to ‘decorate’ certain items in
List<Item>
(think of making a specific DB call for an item ID to obtain a
Flow
specific to that item). Where to collect such Flows? 1.
ViewModel
- hide this complexity from the fragment/adapter, so that
List<DecoratedItem>
contains an immutable snapshot of the data with the ‘decoration’ already applied 2.
Fragment
-
Item
could expose a ‘decoration’
Flow
which is collected in the
Fragment
. With this level of granularity, the fragment would be better able to call the relevant
notifyItemChanged()
function 3.
RecyclerView.Adapter
- when binding the item we can start collecting the ‘decoration’ flow for that item. This fits well, because there is no point collecting that when the item is not bound. My notes: (1) Seems like the more correct, since it keeps non-UI logic out of the fragment/adapter, but then we have a potentially long list with some update caused by an item that’s long been scrolled past, and applying
DiffUtil
etc (2) I’m not particularly convinced by this approach, but I’ve included it because it’s where collection already occurs (3) Seems neat because we are only collecting items that are currently bound Maybe it depends on how active these ‘decoration’ flows are? Low activity would mean the concerns of (1) are not such a big deal. Any thoughts, please?
Hello, any ideas why `detekt` and `detektMain` give me different violations in one source file for ...
s

Stanislav Kral

over 1 year ago
Hello, any ideas why
detekt
and
detektMain
give me different violations in one source file for a multimodule project?
topnax@topnax-ryzen:<workdir>$ ./gradlew detekt

> Task :core-service:detekt FAILED
<workdir>/core-service/src/main/kotlin/cz/ayeto/backend/CoreApplication.kt:14:33: In most cases using a spread operator causes a full copy of the array to be created before calling a method. This may result in a performance penalty. [SpreadOperator]


FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':core-service:detekt'.
> Analysis failed with 1 weighted issues.

* Try:
> Run with --stacktrace option to get the stack trace.
> Run with --info or --debug option to get more log output.
> Run with --scan to get full insights.
> Get more help at <https://help.gradle.org>.

BUILD FAILED in 1s
1 actionable task: 1 executed
topnax@topnax-ryzen:<workdir>$ ./gradlew detektMain

> Task :core-service:detektMain FAILED
<workdir>/core-service/src/main/kotlin/cz/ayeto/backend/CoreApplication.kt:14:33: Used in this way a spread operator causes a full copy of the array to be created before calling a method. This may result in a performance penalty. [SpreadOperator]
<workdir>/core-service/src/main/kotlin/cz/ayeto/backend/CoreApplication.kt:11:5: Calling !! on a nullable type will throw a NullPointerException at runtime in case the value is null. It should be avoided. [UnsafeCallOnNullableType]
<workdir>/core-service/src/main/kotlin/cz/ayeto/backend/CoreApplication.kt:18:13: Calling !! on a nullable type will throw a NullPointerException at runtime in case the value is null. It should be avoided. [UnsafeCallOnNullableType]


FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':core-service:detektMain'.
> Analysis failed with 3 weighted issues.

* Try:
> Run with --stacktrace option to get the stack trace.
> Run with --info or --debug option to get more log output.
> Run with --scan to get full insights.
> Get more help at <https://help.gradle.org>.

BUILD FAILED in 1s
6 actionable tasks: 4 executed, 2 up-to-date
Root buildscript:
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
import io.gitlab.arturbosch.detekt.Detekt

plugins {
	val kotlinVersion = "1.9.22"

	id("org.jlleitschuh.gradle.ktlint") version "12.1.0"
    id("io.gitlab.arturbosch.detekt") version "1.23.5"

	kotlin("jvm") version kotlinVersion apply true
}

allprojects {
    apply(plugin = "io.gitlab.arturbosch.detekt")

    detekt {
        buildUponDefaultConfig = true
    }

    tasks.withType<Detekt>().configureEach {
        buildUponDefaultConfig = true
        reports {
            html.required = true
            // disabled until GitLab adds SARIF support
            // sarif.required = true
        }
    }

	repositories {
		mavenLocal()
		mavenCentral()
	}
}

subprojects {
	apply {
     ...
Any help would be appreciated. Thanks
After upgrading the compose bom to 2023.08.00 (so compose 1.5 stable) i have this error: ```Executio...
j

Jakub Syty

over 2 years ago
After upgrading the compose bom to 2023.08.00 (so compose 1.5 stable) i have this error:
Execution failed for task ':app:checkDebugAarMetadata'.
> A failure occurred while executing com.android.build.gradle.internal.tasks.CheckAarMetadataWorkAction
   > 2 issues were found when checking AAR metadata:
     
       1.  Dependency 'androidx.emoji2:emoji2-views-helper:1.4.0' requires libraries and applications that
           depend on it to compile against version 34 or later of the
           Android APIs.
     
           :app is currently compiled against android-33.
     
           Also, the maximum recommended compile SDK version for Android Gradle
           plugin 8.1.0 is 33.
     
           Recommended action: Update this project's version of the Android Gradle
           plugin to one that supports 34, then update this project to use
           compileSdk of at least 34.
     
           Note that updating a library or application's compileSdk (which
           allows newer APIs to be used) can be done separately from updating
           targetSdk (which opts the app in to new runtime behavior) and
           minSdk (which determines which devices the app can be installed
           on).
     
       2.  Dependency 'androidx.emoji2:emoji2:1.4.0' requires libraries and applications that
           depend on it to compile against version 34 or later of the
           Android APIs.
     
           :app is currently compiled against android-33.
     
           Also, the maximum recommended compile SDK version for Android Gradle
           plugin 8.1.0 is 33.
     
           Recommended action: Update this project's version of the Android Gradle
           plugin to one that supports 34, then update this project to use
           compileSdk of at least 34.
     
           Note that updating a library or application's compileSdk (which
           allows newer APIs to be used) can be done separately from updating
           targetSdk (which opts the app in to new runtime behavior) and
           minSdk (which determines which devices the app can be installed
           on).
I do not use the emoji dependency anywhere (explicitly). I feel like stable compose shouldn't force me to use beta SDK platform through transient dependency. Anybody else came across that?
plus1 1