From 513995f0d457e829b8504085ee7dc36b18b5ac64 Mon Sep 17 00:00:00 2001 From: Guillaume HUSTA Date: Wed, 3 Jan 2024 17:56:10 +0100 Subject: [PATCH] refactor: Use Observable.doOnTerminate() (from rxjava3) --- .../java/fr/husta/android/dockersearch/MainActivity.java | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/fr/husta/android/dockersearch/MainActivity.java b/app/src/main/java/fr/husta/android/dockersearch/MainActivity.java index 77d1929..feb4981 100644 --- a/app/src/main/java/fr/husta/android/dockersearch/MainActivity.java +++ b/app/src/main/java/fr/husta/android/dockersearch/MainActivity.java @@ -272,7 +272,8 @@ public boolean onQueryTextSubmit(String query) Disposable disposable = dockerRegistryClient.searchImagesAsync(query) .subscribeOn(Schedulers.io()) .observeOn(AndroidSchedulers.mainThread()) - .doOnSubscribe(data -> progressBar.show()) + .doOnSubscribe(disp1 -> progressBar.show()) + .doOnTerminate(() -> progressBar.hide()) .subscribe(data -> { Log.d(TAG, "searchImagesAsync.onResponse: returned " + data.getResults().size() + " out of " + data.getNumResults()); data.getResults().sort(new DefaultImageSearchComparator()); @@ -291,10 +292,8 @@ public boolean onQueryTextSubmit(String query) }, throwable -> { Log.e(TAG, throwable.getMessage(), throwable); - progressBar.hide(); Toast.makeText(MainActivity.this, getString(R.string.msg_error, throwable.getMessage()), Toast.LENGTH_LONG).show(); - }, - () -> progressBar.hide()); + }); disposables.add(disposable); // fermer le clavier de saisie