Stateful is a Kotlin library which makes Android application development faster and easier.

Overview

Maven Central

Stateful

Stateful is a Kotlin library which makes Android application development faster and easier. It helps you delete all the boilerplate code for saving instance state and lets you forget about saving and restoring your fragment's/activity's state.

Download

Gradle:

implementation 'com.picsart:stateful:1.2.1'

Using Stateful

The most activities look like the following example.

class MySuperCoolActivity : Activity() {
    private var importantNumber: Int = 3
    private var importantNullableNumber: Int? = null
    private var importantFlag: Boolean = false
    ///and many other super important properties


    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        if (savedInstanceState != null) {
            importantNumber = savedInstanceState.getInt("important property key")
            importantFlag = savedInstanceState.getBoolean("important flag key")
            if (savedInstanceState.containsKey("important nullable property key")) {
                importantNullableNumber = savedInstanceState.getInt("important nullable property key")            
            }
            //....
        }
        //some important logic...
    }

    override fun onSaveInstanceState(outState: Bundle) {
        super.onSaveInstanceState(outState)
        outState.putInt("important property key", importantNumber)
        outState.putBoolean("important flag key", importantFlag)
        importantNullableNumber?.let {
            outState.putInt("important nullable property key", it)
        }
        //....
    }

    //some more code..
}

What if I say that you can remove all boilerplate code for saving state with the help of stateful?

class MySuperCoolActivity : Activity(), Stateful by state() {
    private var importantNumber: Int by statefulProperty(3)
    private var importantNullableNumber: Int? by statefulNullableProperty<Int>(null)
    private var importantFlag: Boolean by statefulProperty(false)
    ///and many more super important properties


    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        restore(savedInstanceState)
        //some important logic...
    }

    override fun onSaveInstanceState(outState: Bundle) {
        super.onSaveInstanceState(outState)
        save(outState)
    }

    //some more code..
}

The default implementation is using property names as a key to put them in the bundle. If you want to implement your own logic for a key generation you can extend Stateful interface and use your own implementation.

You might also like...
Kotlin Multiplatform is an SDK for cross-platform mobile development, which enables teams to use the same business logic in both Android and iOS client applications.
Kotlin Multiplatform is an SDK for cross-platform mobile development, which enables teams to use the same business logic in both Android and iOS client applications.

Kotlin Multiplatform is an SDK for cross-platform mobile development, which enables teams to use the same business logic in both Android and iOS client applications.

A collection of small utility functions to make it easier to deal with some otherwise nullable APIs on Android.

requireKTX requireKTX is a collection of small utility functions to make it easier to deal with some otherwise nullable APIs on Android, using the sam

It is far easier to design a class to be thread-safe than to retrofit it for thread safety later
It is far easier to design a class to be thread-safe than to retrofit it for thread safety later

"It is far easier to design a class to be thread-safe than to retrofit it for thread safety later." (Brian Goetz - Java concurrency: Publisher: Addiso

Android Clean Architecture in Rorty is a sample project that presents modern, approach to Android application development using Kotlin and latest tech-stack.
Android Clean Architecture in Rorty is a sample project that presents modern, approach to Android application development using Kotlin and latest tech-stack.

Android Clean Architecture in Rorty is a sample project that presents modern, approach to Android application development using Kotlin and latest tech-stack.

📒 NotyKT is a complete 💎Kotlin-stack (Backend + Android) 📱 application built to demonstrate the use of Modern development tools with best practices implementation🦸.
📒 NotyKT is a complete 💎Kotlin-stack (Backend + Android) 📱 application built to demonstrate the use of Modern development tools with best practices implementation🦸.

NotyKT 🖊️ NotyKT is the complete Kotlin-stack note taking 🖊️ application 📱 built to demonstrate a use of Kotlin programming language in server-side

Rick-and-morty-app - Android mobile application development with clean architecture
Rick-and-morty-app - Android mobile application development with clean architecture

Android - Rick And Morty App MVVM architecture Dependency Injection (Dagger) Ret

Lightweight compiler plugin intended for Kotlin/JVM library development and symbol visibility control.

Restrikt A Kotlin/JVM compiler plugin to restrict symbols access, from external project sources. This plugin offers two ways to hide symbols: An autom

Pleasant Android application development
Pleasant Android application development

⚠️ Anko is deprecated. Please see this page for more information. Anko is a Kotlin library which makes Android application development faster and easi

CleanArchitecture is a sample project that presents a modern, 2021 approach to Android application development.
CleanArchitecture is a sample project that presents a modern, 2021 approach to Android application development.

CleanArchitecture is a sample project that presents a modern, 2021 approach to Android application development. The goal of the pro

Releases(1.2.1)
Owner
PicsArt
PicsArt
A set of extension properties on Int, Long, Double, and Duration, that makes it easier to work with Kotlin Duration

Kotlin Duration Extensions Gradle Groovy repositories { mavenCentral() } implementation 'com.eygraber:kotlin-duration-extensions:1.0.1' Kotlin rep

Eliezer Graber 8 Nov 8, 2022
Use Flink's Stateful Functions as a control-plane technology for operating a streaming-platform

statefun-ops Use ?? Flink Stateful Functions as a control-plane technology for operating a streaming-platform based on Apache Kafka. Walkthrough Ensur

Dylan Meissner 8 Oct 1, 2022
An open source GitHub Android client app, faster and concise.

An open-source GitHub Android client app, faster and concise.

30度的射线 4.1k Dec 26, 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
Kstr is a set of helpful methods library for Kotlin intended for make the developer life easier.

Kstr is a set of helpful methods library for Kotlin intended for make the developer life easier. Kstr uses the powerful feature of extension func

Rafael Acioly 0 Nov 3, 2021
Android Library to make SharedPreferences usage easier.

KotlinPreferences Kotlin Android Library, that makes preference usage simple and fun. KotlinPreferences now have a brother. With KotlinPreferences, yo

Marcin Moskała 50 Nov 6, 2022
A fragment binding library - the easier, efficient way.

Byda allprojects { repositories { ... maven { url 'https://jitpack.io' } } } dependencies { implementation 'com.github.Codzure:B

null 3 May 27, 2021
A React Native library making file access easier for developers as first class citizens, without the tears

React Native File Gateway A React Native library making file access easier for developers as first class citizens, without the tears. ⚠️ NOTE: This li

Jimmy Wei 4 Sep 11, 2021
Elixir is a library designed to make minecraft login easier.

Elixir Elixir is a library designed to make minecraft login easier. Usage We have a maven repo for this project. repositories { maven { url = "htt

null 4 Aug 11, 2022
API-Request - Android app that makes API Request

API-Request Android project using Retrofit and Ktor for Http Requests, built wit

Thales 2 Mar 26, 2022