Add status to beans in Compose, Fields in beans can be directly used as the MutableState

Overview

Buff

Add status to beans in Jetpack(jb) Compose, Fields in beans can be directly used as the MutableState<T>

⚠️ Non mainstream warning:This item violates 'Unique trusted data source' and 'FP',If the content on this page causes your discomfort,please press Ctrl+W

us English | cn 简体中文

ability

  1. Convert some fields in beans to MutableState<T> that can be used directly

Capability to be achieved

see this

How to use

Step 1.Root dir, build.gradle.kts add:

buildscript {
    repositories {
        maven("https://jitpack.io")//this
        ...
    }
}

allprojects {
    repositories {
        maven("https://jitpack.io")//this
        ...
    }
}

Step 2.Your app dir, build.gradle.kts add:

version =

plugins {
    ...
    id("com.google.devtools.ksp") version "1.7.10-1.0.6"//this, The left 1.7.10 corresponds to your the Kotlin version,more version: https://github.com/google/ksp/releases
}

dependencies {
    ...
    implementation("com.github.ltttttttttttt:Buff:$version")//this, such as 0.0.3
    ksp("com.github.ltttttttttttt:Buff:$version")//this, such as 0.0.3
}

Step 3.Use BUff

Add the @Buff to your bean, call the addBuff() transform to the new Any, The attribute (such as name) not in the constructor will be automatically converted to MutableState<T>

@Buff
class BuffBean(
    val id: Int? = null,
) {
    var name: String? = null
}

Example(reference UseBuff.kt):

val buffBean = BuffBean(0)
val bean = buffBean.addBuff()//Transform to the BuffBeanWithBuff
bean.name//The name's getter and setter have the effect of MutableState<T>
bean.removeBuff()//Fallback to BuffBean(optional)

Step 4.Add ksp dir to the srcDir

Your app dir, build.gradle.kts add:

//If your project is the android, and the productFlavors is not set
android {
    buildTypes {
        release {
            kotlin {
                sourceSets.main {
                    kotlin.srcDir("build/generated/ksp/release/kotlin")
                }
            }
        }
        debug {
            kotlin {
                sourceSets.main {
                    kotlin.srcDir("build/generated/ksp/debug/kotlin")
                }
            }
        }
    }
    kotlin {
        sourceSets.test {
            kotlin.srcDir("build/generated/ksp/test/kotlin")
        }
    }
}

//If your project is the android, and the productFlavors is set
applicationVariants.all {
    outputs.all {
        val flavorAndBuildTypeName = name
        kotlin {
            sourceSets.main {
                kotlin.srcDir(
                    "build/generated/ksp/${
                        flavorAndBuildTypeName.split("-").let {
                            it.first() + it.last()[0].toUpperCase() + it.last().substring(1)
                        }
                    }/kotlin"
                )
            }
        }
    }
}
kotlin {
    sourceSets.test {
        kotlin.srcDir("build/generated/ksp/test/kotlin")
    }
}

//If your project is the jvm or more
kotlin {
    sourceSets.main {
        kotlin.srcDir("build/generated/ksp/main/kotlin")
    }
    sourceSets.test {
        kotlin.srcDir("build/generated/ksp/test/kotlin")
    }
}

Step 5.Config

Serialize of this project uses kotlinx-serialization by default, To modify, Your app dir, build.gradle.kts add:

ksp {
    //Set the Annotation of the class, Usually as follows
    arg("classSerializeAnnotationWithBuff", "//Not have")
    //Set the Annotation of the field to transient, Usually as follows
    arg("fieldSerializeTransientAnnotationWithBuff", "@kotlin.jvm.Transient")
}

Add custom code, reference [KspOptions.handlerCustomCode], Your app dir, build.gradle.kts add:

ksp {
    arg("customInClassWithBuff", "//Class end")//in class
    arg("customInFileWithBuff", "//File end")//in file
}
You might also like...
Recycler-coroutines - RecyclerView Auto Add Data Using Coroutines

Sample RecyclerView Auto Add With Coroutine Colaborator Very open to anyone, I'l

This lib implements the most common CoroutineScopes used in Android apps.

AndroidCoroutineScopes Starting from 0.26.0 release we should define a scope for new coroutines (docs). To avoid this boilerplate code I've created th

Most used extension methods for Kotlin

Extensify Most used extension methods for Kotlin Download Step 1. Add the JitPack repository to your build file allprojects { repositories {

Klimatic is an android app built using Kotlin. It try to showcase all the latest technologies used in android.
Klimatic is an android app built using Kotlin. It try to showcase all the latest technologies used in android.

Klimatic Klimatic is an android app built using Kotlin. It try to showcase all the latest technologies used in android. Built using Android Architectu

Various experimental proposals and extensions to Javalin 4.x used in Reposilite 3.x

Javalin RFCs Various experimental extensions to Javalin 4.x used in Reposilite 3.x. Provides basic support for Kotlin coroutines and async routes with

This is a Kotlin multiplatform template project used to generate and deploy a natively compiled AWS lambda function using the custom runtime.
This is a Kotlin multiplatform template project used to generate and deploy a natively compiled AWS lambda function using the custom runtime.

Overview This is a Kotlin multiplatform template project used to generate and deploy a natively compiled AWS Lambda function using a custom runtime. U

Theia - A Kotlin program used to analyze and discover backdoors in Minecraft Java 1.12.2 forge mods

Theia A Kotlin program used to analyse and discover backdoors in Minecraft Java

Kotools Types - a lightweight library that provides commonly used types for Kotlin

Kotools Types is a lightweight library that provides commonly used types for Kotlin

An android lib that provides most commonly used utility function

Awesome-Utility An android lib that provides most commonly used utility function. It can help Android developers with supporting common utility functi

Releases(0.0.5)
Owner
lt
kotlin yyds
lt
Bego Chat is chat application in Kotlin and Firebase with the following features: last seen , user status like typing ,online and last seen with MVVM pattern and clean architecture

Compose ChatApp(Bego Chat) Bego Chat is Compose chat application in Kotlin and Firebase with the following features: sending all file types and abilit

Ahmed EL Bagory 5 Dec 20, 2022
Arc Layout is a view group with which you can add a arc-shaped container in your layout.

ArcLayout Arc Layout is a view group with which you can add a arc-shaped container in your layout. Two main variables are the direction and the curvat

Ali Rezaiyan 32 Aug 17, 2022
A simple demo that shows how WebWorkers can be used in Kotlin/JS

Web Workers in KotlinJS This repo demonstrates how to set up a Web Worker in Kotlin/JS. It is a very simple demo that creates a new worker that sends

Ethan Davidson 7 Dec 15, 2022
Add Wheel Date - Time Picker in Android Jetpack Compose.

WheelPickerCompose Add Wheel Date - Time Picker in Android Jetpack Compose. Usage Picker Usage WheelDateTimePicker { snappedDateTime -> } WheelDatePic

Emir Demirli 81 Dec 30, 2022
💡🚀⭐️ A generalized adapter for RecyclerView on Android which makes it easy to add heterogeneous items to a list

Mystique is a Kotlin library for Android’s RecyclerView which allows you to create homogeneous and heterogeneous lists effortlessly using an universal

Rahul Chowdhury 48 Oct 3, 2022
A FDPClient fork , It aims to add more modules.

LightClient A FDPClient fork , It aims to add more modules. You can download development version at Github-Actions , Release at Release Only running o

Ad973_ 3 Aug 26, 2021
A kotlin library of extension functions that add smalltalk style methods to objects.

KtTalk A kotlin library of extension functions that add smalltalk style methods to objects. Motivation Smalltalk is a pure OO language in which everyt

null 11 Oct 16, 2021
A simple e-market application that allows users to view the store details and products, add products to the basket, and place an order.

E-Market Application Features : Store details & products screen Fetch the store detail from an endpoint and display this upper part of the screen. Fet

Amit Kumar guha 2 Jun 27, 2022
Muhammad Bilal 0 Jan 6, 2022