Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Async UI implementation #81

Open
sciage opened this issue Dec 22, 2018 · 0 comments
Open

Async UI implementation #81

sciage opened this issue Dec 22, 2018 · 0 comments

Comments

@sciage
Copy link

sciage commented Dec 22, 2018

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant