RetrofitLifecycle

Introduction: Manage retrofit call's lifecycle with proxy class which generated by annotation
More: Author   ReportBugs   
Tags:

RetrofitLifecycle manage retrofit call's lifecycle with proxy class which generated by annotation.

Usage

Add it in your root build.gradle at the end of repositories:

allprojects {
    repositories {
        ...
        maven { url 'https://jitpack.io' }
    }
}

Add the dependency

dependencies {
    compile 'com.github.luckyandyzhang.RetrofitLifecycle:retrofit-lifecycle:1.0.1'
    annotationProcessor 'com.github.luckyandyzhang.RetrofitLifecycle:retrofit-lifecycle-compiler:1.0.1'
}

Use @RetrofitInterface on retrofit interface:

@RetrofitInterface
public interface GankAPI {
    @GET("data/Android/10/1")
    Call<ResponseBody> getGankList();
}

Get proxy class and use it:

GankAPI gankAPI = new Retrofit.Builder()
        .addConverterFactory(GsonConverterFactory.create())
        .baseUrl("http://gank.io/api/")
        .build()
        .create(GankAPI.class);
//get proxy class
GankAPI gankAPIProxy = RetrofitLifecycle.getProxyInterface(GankAPI.class, gankAPI);
//use proxy class to reqeust
gankAPIProxy.getGankList().enqueue(new Callback<ResponseBody>() {
    @Override
    public void onResponse(Call<ResponseBody> call, Response<ResponseBody> response) {

    }

    @Override
    public void onFailure(Call<ResponseBody> call, Throwable t) {

    }
});
//cancel all calls
RetrofitLifecycle.cancelAll(gankAPIProxy);

For additional information see sample module :)

License

Copyright 2017 Andy

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.
Apps
About Me
GitHub: Trinea
Facebook: Dev Tools