Kickback

Additional

Language
Java
Version
N/A
Created
Dec 10, 2017
Updated
Dec 11, 2017
Owner
skydoves
Contributor
skydoves
1
Activity
Badge
Generate
Download
Source code
APK file

Advertisement

Kickback


This Java & Android library helps to manage static data more structurally using annotation processor.

Including in your project

build.gradle

dependencies {
    compile 'com.github.skydoves:kickback:1.0.2'
    annotationProcessor 'com.github.skydoves:kickback-processor:1.0.2'
    kapt 'com.github.skydoves:kickback-processor:1.0.2' // for kotlin project
}

Usage

Create an abstract class with @KickbackBox annotation.
@KickbackBox annotation means integration management class about static objects.

@KickbackBox(name = "Profile")
public abstract class UserProfile {
    final int visits = 1;

    @KickbackElement(name = "name")
    final String userName = "skydoves";

    @Weak
    @KickbackElement(name = "password")
    final int userPassword = 1234;

    @Weak
    @KickbackElement(name = "secondPassword")
    final int userSecondPassword = 12345;

    @Soft
    @KickbackElement(name = "dog")
    Dog userDog;

    @Soft
    UserPrivates userPrivates;
}

@KickbackElement annotation decides name tag of a variable.
If not annotated, the default name of the variable will be field name.
@Weak and @Soft annotation make an instance of a field to weak or soft reference.

After builds your project, Kickback_(box name) class will be auto-generated by Kickback like below.

public class Kickback_Profile implements LifecycleObserver {
  private static Integer kickback_Visits = 1;

  private static String kickback_Name = "skydoves";

  private static WeakReference<? extends Integer> kickback_Password = new WeakReference(1234);
  
  public static void setVisits(Integer visits) {
    kickback_Visits = visits;
  }

  public static void setName(String name) {
    kickback_Name = name;
  }

  public static void setPassword(Integer password) {
    kickback_Password = new WeakReference(password);
  }
  // -- skiped --

Then we can put, take out or free at memory into our new generated box class.

Kickback_Profile.setName("Kickback");
Kickback_Profile.getName();
Kickback_Profile.freeName();

In Android project, we can set LifecycleObserver and get LifecycleObserver from box class.
Using by these methods, we can more prevent our project from OOM.

kickback_profile.setLifecycleObserver(LifecycleOwner lifecycleOwner)
kickback_profile.getLifecycleObserver()

License

Copyright 2017 skydoves

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.