Skip to content

Latest commit

 

History

History
65 lines (52 loc) · 1.52 KB

adal-network.md

File metadata and controls

65 lines (52 loc) · 1.52 KB

adal-network

Android library that offers an retrofit callback with centralized error handling

Download

Gradle:

dependencies {
  implementation 'com.massivedisaster.adal:adal-network:0.1.20'
}

Usage

public class FragmentNetworkRequest extends AbstractRequestFragment {

    private RecyclerView mRclItems;
    private AdapterPost mAdapterPost;   

    @Override
    protected void doOnCreated() {
        mRclItems.setLayoutManager(new LinearLayoutManager(getContext()));

        mAdapterPost = new AdapterPost();
        mAdapterPost.setOnLoadMoreListener(new OnLoadMoreListener() {
            @Override
            public void onLoadMore() {
                request();
            }
        });
        mRclItems.setAdapter(mAdapterPost);

        request();
    }

    private void request() {

        // Show the general loading if the adapter is empty
        if (mAdapterPost.isEmpty()) {
            showLoading();
        }

        addRequest((APIRequests.getPosts(new APIRequestCallback<ResponseList<Post>>(getContext()) {
            @Override
            public void onSuccess(ResponseList<Post> posts) {
                mAdapterPost.addAll(posts);
            }

            @Override
            public void onError(APIError error, boolean isServerError) {
                showError(error.getMessage());
            }
        })));
    }
}

Contributing

CONTRIBUTING

License

MIT LICENSE