Отображение AlertDialog в представлении после наблюдения завершаемого - PullRequest
1 голос
/ 27 июня 2019

Я хочу отобразить AlertDialog в моем View, показывающем, что результат был успешным,

private void actionUpdateProfesional() {
    btnSave.setOnClickListener(view -> {
        alertDialog = new AlertDialog.Builder(this)
                .setTitle("Wait!")
                .setMessage("Are you sure you want update your data?")
                .setPositiveButton("YES", (dialogInterface, i) -> presenter.updateProfile())
                .setNegativeButton("NO", null)
                .create();
        alertDialog.show();
    });
}

после того, как мой Completable был выполнен на моем докладчике:

@Override
public void updateProfile() {
    Disposable d = updateInfoInteractor
            .build(new ProfileUpdateInfoInteractor.Param(view.getPhone(), view.getLocation(), view.getDescription()))
            .observeOn(schedulers.main())
            .subscribeWith(new DisposableCompletableObserver() {
                @Override
                public void onComplete() {
                    Timber.d("Profile edited");
                }

                @Override
                public void onError(Throwable e) {
                    Timber.d("Error at edit profile");
                }
            });
}

Ответы [ 3 ]

1 голос
/ 27 июня 2019

Вы должны вызывать метод actionUpdateProfesional() вашего представления из метода onComplete.

Возможно, вам потребуется добавить actionUpdateProfesional() к интерфейсу просмотра, на который вы ссылаетесь в докладчике.

Было бы что-то вроде этого:

@Override
public void updateProfile() {
    Disposable d = updateInfoInteractor
            .build(new ProfileUpdateInfoInteractor.Param(view.getPhone(), view.getLocation(), view.getDescription()))
            .observeOn(schedulers.main())
            .subscribeWith(new DisposableCompletableObserver() {
                @Override
                public void onComplete() {
                    Timber.d("Profile edited");
                    if (view != null) {
                        view.actionUpdateProfesional()
                    }
                }

                @Override
                public void onError(Throwable e) {
                    Timber.d("Error at edit profile");
                }
            });
}
1 голос
/ 27 июня 2019

Но если вы хотите решить эту проблему с помощью MVP Architecture, вам нужно создать новый метод в интерфейсе View.Потому что докладчик не выполняет логику пользовательского интерфейса, иначе ваша архитектура будет повреждена.

public interface MyObjectView {
    void resultSuccess(int status);
}


MyObjectView myView

Public MyPresenterConstructor(MyObjectView myView){
    this.myView = myView;
}


@Override
    public void updateProfile() {
        Disposable d = updateInfoInteractor
                .build(new ProfileUpdateInfoInteractor.Param(view.getPhone(), view.getLocation(), view.getDescription()))
                .observeOn(schedulers.main())
                .subscribeWith(new DisposableCompletableObserver() {
                    @Override
                    public void onComplete() {
                        Timber.d("Profile edited");

                        // Show alert dialog here!
            myView.resultSuccess(200)   // Okee

                    }

                    @Override
                    public void onError(Throwable e) {
                        Timber.d("Error at edit profile");
                    }
                });
    }

Тогда не забудьте реализовать интерфейс View в вашем Activity (UI).затем позвоните в свой alertDialog.

public class MainActivity extend AppCompatActivity implement MyObjectView{

…….

@Override
Public void resultSuccess(int code){

// call your dialog here

}

…..

}
0 голосов
/ 27 июня 2019

Вы на самом деле не задавали вопрос, поэтому я предполагаю, что вам интересно, как отобразить диалоговое окно с предупреждением о завершенном событии.Вы можете сделать это, просто создав его снова в функции onComplete().

@Override
public void updateProfile() {
    Disposable d = updateInfoInteractor
            .build(new ProfileUpdateInfoInteractor.Param(view.getPhone(), view.getLocation(), view.getDescription()))
            .observeOn(schedulers.main())
            .subscribeWith(new DisposableCompletableObserver() {
                @Override
                public void onComplete() {
                    Timber.d("Profile edited");

                    // Show alert dialog here!
                    alertDialog = new AlertDialog.Builder(this)
                        .setTitle("Wait!")
                        .setMessage("Are you sure you want update your data?")
                        .setPositiveButton("YES", (dialogInterface, i) -> 
                            presenter.updateProfile())
                        .setNegativeButton("NO", null)
                        .create();
                    alertDialog.show();
                }

                @Override
                public void onError(Throwable e) {
                    Timber.d("Error at edit profile");
                }
            });
}

Надеюсь, это поможет!

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...