Skip to content

Async UI implementation #81

@sciage

Description

@sciage

Currently I have successfully implemented MVP architecture in my android app but When I am loading data inside my fragment, the UI hangs till the loading finishes. When Loading finishes, and data is loaded inside fragment, then only I can interact with click on different buttons.

This is my network api call

public Single<List<PostsModel>> getFacebookFriendsFeed(String id_user_name, String user_id, String facebookId, String page) { return Rx2AndroidNetworking.get(ApiEndPoint.GET_POST_DATA) // .addHeaders(mApiHeader.getProtectedApiHeader()) .addQueryParameter("id_user_name", id_user_name) .addQueryParameter("user_id", user_id) .addQueryParameter("facebookId", facebookId) .addQueryParameter("page", page) .build() .getObjectListSingle(PostsModel.class) .subscribeOn(Schedulers.io()) .observeOn(AndroidSchedulers.mainThread()); }

This is my presenter implementation of the API

`@Override
public void getFacebookPostsOnline(String id_user_name, String user_id, String facebookId, String page) {

  //  getMvpView().showLoading();

    getCompositeDisposable().add(getDataManager()
            .getFacebookFriendsFeed(id_user_name, user_id, facebookId, page)
            .subscribeOn(getSchedulerProvider().io())
            .observeOn(getSchedulerProvider().ui())
            .subscribe(new Consumer<List<PostsModel>>() {
                @Override
                public void accept(List<PostsModel> response) throws Exception {

                    getMvpView().getFacebookPosts(response);
                    // todo add data and loop to get all friends list
               /*     getDataManager().updateUserInfo(

                            response.info.getId(),
                            response.info.getUser_token(),
                            DataManager.LoggedInMode.LOGGED_IN_MODE_SERVER
                    );
                    */


                    if (!isViewAttached()) {
                        return;
                    }

                 //   getMvpView().hideLoading();
                  //  getMvpView().openMainActivity();

                }
            }, new Consumer<Throwable>() {
                @Override
                public void accept(Throwable throwable) throws Exception {

                    if (!isViewAttached()) {
                        return;
                    }

                    getMvpView().hideLoading();

                    // handle the login error here
                    if (throwable instanceof ANError) {
                        ANError anError = (ANError) throwable;
                        handleApiError(anError);
                    }
                }
            }));
}`

Please let me know where I am going wrong in making the UI more async. and do you need any more details about my code.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions