Field cleaning and destroying for java objects that delete references to and dispose/close object which uses annotation processing to generate boilerplate code for you.
class ExampleActivity extends Activity {
@Chopp
Object object = new Object();
@Chopp(value = SubscriptionChopperable.class, level = 20)
Subscription subscription = Subscriptions.empty();
@Chopp(SubscriptionChopperable.class)
CompositeSubscription compositeSubscription = new CompositeSubscription();
@Chopp(value = ButterKnifeUnbindChopperable.class, level = 100)
Unbinder unbinder;
@Chopp(value = RealmChopperable.class, level = 50)
Realm realm;
@Chopp(ChainChopperable.class)
ChainField chainField = new ChainField();
@Chopp({DisposableChopperable.class /*, SomeOtherChopperable.class */})
DisposeElement disposeField = new DisposeElement();
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
initActivity();
}
@Override
protected void onPause() {
super.onPause();
Chopper.chopp(this, 20);
}
@Override
protected void onStop() {
super.onStop();
Chopper.chopp(this, 50);
}
@Override
protected void onDestroy() {
Chopper.chopp(this, 100);
super.onDestroy();
}
}Use annotation to make variable chopperable
@Choppdependencies {
compile 'com.github.levelapp.Chopper:chopperannotation:1.0.2'
annotationProcessor 'com.github.levelapp.Chopper:chopperprocessor:1.0.2'
}
allprojects {
repositories {
maven { url "https://jitpack.io" }
}
} @Chopp(BroadcastReceiverChopperable.class)
@Chopp(RecyclerViewChopperable.class) compile 'com.github.levelapp.Chopper:chopperandroid:1.0.2'- ButterKnife
@Chopp(ButterKnifeChopperable.class) compile 'com.github.levelapp.Chopper:chopperbutterknife:1.0.2'- RxJava
@Chopp(SubscriptionChopperable.class) compile 'com.github.levelapp.Chopper:chopperrxjava:1.0.2'- RxJava2
@Chopp(SubscriptionChopperable.class) compile 'com.github.levelapp.Chopper:chopperrxjava2:1.0.2'- Realm
@Chopp(RealmChopperable.class)
@Chopp(RealmObjectChangeListenerChopperable.class)
@Chopp(RealmResultChangeListenerChopperable.class) compile 'com.github.levelapp.Chopper:chopperrealm:1.0.2'With BetterProguardProcessor
Call init() before first call Chopper, e.g. in Application.
With BetterProguardProcessor all classes can be fully minified.
BetterProguardFactoryImpl will be created after first success build.
Chopper.init(new BetterProguardFactoryImpl());Without BetterProguardProcessor
#Chopper
-dontwarn com.levelapp.chopper.**
-keep class com.levelapp.chopper.** { *; }
-keep class **$$Chopperable { *; }
-keepclasseswithmembernames class * {
@com.levelapp.annotation.* <fields>;
}
-keepnames class * { @com.levelapp.annotation.annotations.Chopp *;}
Create own Chopperable implementation to destroy object in right way
public class DisposableChopperable implements Chopperable<Disposable, Object> {
@Override
public void chopp(Disposable target, Object enclosed, int level) {
if (target != null){
target.dispose();
}
}
}With ChainChopperable Chopper create DESTROY chain.
Look at sample for better understanding
Copyright 2016 Rafał Dziuryk
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.