All Projects → AlexeyPanchenko → stater

AlexeyPanchenko / stater

Licence: Apache-2.0 license
Android library for easy save data to bundle in Activity/Fragment.

Programming Languages

kotlin
9241 projects
java
68154 projects - #9 most used programming language

Projects that are alternatives of or similar to stater

sentry-android-gradle-plugin
Gradle plugin for Sentry Android. Upload proguard, debug files, and more.
Stars: ✭ 67 (+458.33%)
Mutual labels:  gradle-plugin
kotlin-plugin-generated
A Kotlin compiler plugin that annotates Kotlin-generated methods for improved coverage reports
Stars: ✭ 33 (+175%)
Mutual labels:  gradle-plugin
DataBindingCompat
A Gradle plugin that makes databinding work well with appcompat
Stars: ✭ 13 (+8.33%)
Mutual labels:  gradle-plugin
native-build-tools
Native-image plugins for various build tools
Stars: ✭ 168 (+1300%)
Mutual labels:  gradle-plugin
kosogor
Defaults and simplified Kotlins-DSL interfaces for Gradle
Stars: ✭ 18 (+50%)
Mutual labels:  gradle-plugin
gradle-jnlp-plugin
Gradle plugin to generate jnlp files, sign jars etc. for being able to start an application with Java Webstart
Stars: ✭ 19 (+58.33%)
Mutual labels:  gradle-plugin
laboratory
Feature flags for multi-module Kotlin Android projects
Stars: ✭ 71 (+491.67%)
Mutual labels:  gradle-plugin
javacard-gradle-plugin
🔑 Gradle plugin for JavaCard development
Stars: ✭ 24 (+100%)
Mutual labels:  gradle-plugin
fabric-loom
Gradle build system plugin used to automate the setup of a minecraft mod development environment.
Stars: ✭ 150 (+1150%)
Mutual labels:  gradle-plugin
fat-aar
The fat-aar plugin that can be used under android plugin 3.0.1 and gradle wrapper 4.4.
Stars: ✭ 32 (+166.67%)
Mutual labels:  gradle-plugin
parcl
Gradle plugin for bundling your Java application for distribution on Windows, Mac and Linux
Stars: ✭ 52 (+333.33%)
Mutual labels:  gradle-plugin
FirebaseTestLab-Android
No description or website provided.
Stars: ✭ 50 (+316.67%)
Mutual labels:  gradle-plugin
kt2ts-gradle-plugin
Generate TypeScript from Kotlin (or any jvm language) by annotations
Stars: ✭ 15 (+25%)
Mutual labels:  gradle-plugin
extra-java-module-info
A Gradle 6.4+ plugin to use legacy Java libraries as Java Modules in a modular Java project
Stars: ✭ 39 (+225%)
Mutual labels:  gradle-plugin
ank
ΛNK: Compile time docs verification and evaluation for Kotlin and Java (Temporarily moved to Arrow-kt)
Stars: ✭ 52 (+333.33%)
Mutual labels:  gradle-plugin
androidNativeBundle
a gradle plugin that support publish c/c++ headers to 'aar' and depend those 'aar'
Stars: ✭ 60 (+400%)
Mutual labels:  gradle-plugin
groocss
GrooCSS - code CSS in Groovy
Stars: ✭ 24 (+100%)
Mutual labels:  gradle-plugin
VanillaGradle
A toolchain for Minecraft: Java Edition that builds a workspace to interact with the game using the official mappings provided to the public by Mojang Studios.
Stars: ✭ 61 (+408.33%)
Mutual labels:  gradle-plugin
Shot
Screenshot testing library for Android
Stars: ✭ 951 (+7825%)
Mutual labels:  gradle-plugin
sonar-scanner-gradle
SonarQube Scanner for Gradle
Stars: ✭ 132 (+1000%)
Mutual labels:  gradle-plugin

Stater

Build status Download-plugin

Lightweight library to save state in your Activity/Fragment. Stater also fine works with Kotlin code as it uses bytecode transformation.

Download

In root build.gradle file:

buildscript {
    ext.stater_version = '1.2'
    repositories {
        jcenter()
    }
    dependencies {
        ...
        classpath "ru.alexpanchenko:stater-plugin:$stater_version"
    }
}

allprojects {
    repositories {
        jcenter()
    }
}

In your app build.gradle file add plugin:

apply plugin: 'com.android.application'
...
apply plugin: 'stater-plugin'

Usage

Activity

import ru.alexpanchenko.stater.State;

public class MainActivity extends AppCompatActivity {
  @State
  private int yourVar = 0;
  
  @State
  private Bundle bundleVar;
}

Fragment

import ru.alexpanchenko.stater.State;

public class MainFragment extends Fragment {
  @State
  private int yourVar = 0;
  
  @State
  private Bundle bundleVar;
}

It's all!

If you need to save custom fields just add a setting in your build.gradle file:

apply plugin: 'stater-plugin'

android {
  ...
}

stater {
  customSerializerEnabled = true
}

And then use:

import ru.alexpanchenko.stater.State;

public class MainActivity extends AppCompatActivity {
  @State
  private CustomClass customClass;
  // or
  @State
  private List<CustomClass> customClassList;
  // or
  @State
  private Container<CustomClass> customClassContainer;
}

Supported types

Supported Types
boolean/Boolean/boolean[ ]/Boolean[ ]
byte/Byte/byte[ ]/Byte[ ]
char/Character/char[ ]/Character[ ]
short/Short/short[ ]/Short[ ]
int/Integer/int[ ]/Integer[ ] List/ArrayList<Integer>
float/Float/float[ ]/Float[ ]
long/Long/long[ ]/Long[ ]
double/Double/double[ ]/Double[ ]
String/String[ ] List/ArrayList<String>
CharSequence/CharSequence[ ] List/ArrayList<CharSequence>
Serializable
Parcelable/Parcelable[ ] List/ArrayList<Parcelable>
Bundle
IBinder
Custom types (optional)

How it works

Stater plugin transform classes that inherit Activity/Fragment in compile time (see transformClassesWithStaterTransformFor... task). It save state in onSaveInstanceState and restore it in onCreate.

protected void onCreate(@Nullable Bundle savedInstanceState) {
    if (savedInstanceState != null) {
      this.yourVar = savedInstanceState.getInt("your/class/path_yourVar");
      this.bundleVar = savedInstanceState.bundleVar("your/class/path_bundleVar");
    }
    super.onCreate(savedInstanceState);
}

protected void onSaveInstanceState(@NonNull Bundle outState) {
    outState.putInt("your/class/path_yourVar", this.yourVar);
    outState.putBundle("your/class/path_bundleVar", this.bundleVar);
    super.onSaveInstanceState(outState);
}

Transformed classes you can find in build/intermediates/transforms/StaterTransform/yourPackage.

License

Copyright 2019 Alexey Panchenko

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

   http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].