Skip to content

Commit c298657

Browse files
committed
Fix : Circular ProgressBar stops after Nomination of Deletion
1 parent 28ea111 commit c298657

File tree

1 file changed

+43
-12
lines changed

1 file changed

+43
-12
lines changed

app/src/main/java/fr/free/nrw/commons/media/MediaDetailFragment.java

Lines changed: 43 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1300,12 +1300,7 @@ private void onDeleteClicked(Spinner spinner) {
13001300
resultSingle
13011301
.subscribeOn(Schedulers.io())
13021302
.observeOn(AndroidSchedulers.mainThread())
1303-
.subscribe(s -> {
1304-
if(applicationKvStore.getBoolean(String.format(NOMINATING_FOR_DELETION_MEDIA, media.getImageUrl()), false)) {
1305-
applicationKvStore.remove(String.format(NOMINATING_FOR_DELETION_MEDIA, media.getImageUrl()));
1306-
callback.nominatingForDeletion(index);
1307-
}
1308-
});
1303+
.subscribe(this::handleDeletionResult, this::handleDeletionError);
13091304
}
13101305

13111306
@SuppressLint("CheckResult")
@@ -1317,12 +1312,7 @@ private void onDeleteClickeddialogtext(String reason) {
13171312
resultSingletext
13181313
.subscribeOn(Schedulers.io())
13191314
.observeOn(AndroidSchedulers.mainThread())
1320-
.subscribe(s -> {
1321-
if(applicationKvStore.getBoolean(String.format(NOMINATING_FOR_DELETION_MEDIA, media.getImageUrl()), false)) {
1322-
applicationKvStore.remove(String.format(NOMINATING_FOR_DELETION_MEDIA, media.getImageUrl()));
1323-
callback.nominatingForDeletion(index);
1324-
}
1325-
});
1315+
.subscribe(this::handleDeletionResult, this::handleDeletionError);
13261316
}
13271317

13281318
@OnClick(R.id.seeMore)
@@ -1356,6 +1346,47 @@ private void enableProgressBar() {
13561346
isDeleted = true;
13571347
}
13581348

1349+
/**
1350+
* Disables Progress Bar and Update delete button text.
1351+
*/
1352+
private void disableProgressBar() {
1353+
if (getActivity() == null) {
1354+
return; // Prevent NullPointerException when fragment is not attached to activity
1355+
}
1356+
getActivity().runOnUiThread(() -> {
1357+
if (progressBarDeletion != null) {
1358+
progressBarDeletion.setVisibility(GONE);
1359+
}
1360+
});
1361+
}
1362+
1363+
private void handleDeletionResult(final boolean success) {
1364+
if (success) {
1365+
Timber.d("Nominated for Deletion : Success");
1366+
delete.setText("Nominated for Deletion");
1367+
ViewUtil.showLongSnackbar(requireView(),
1368+
"Nominating for deletion : Success");
1369+
disableProgressBar();
1370+
checkAndClearDeletionFlag();
1371+
} else {
1372+
disableProgressBar();
1373+
}
1374+
}
1375+
1376+
private void handleDeletionError(final Throwable throwable) {
1377+
// Log error or show error message to the user
1378+
Timber.e(throwable.getLocalizedMessage());
1379+
disableProgressBar();
1380+
checkAndClearDeletionFlag();
1381+
}
1382+
1383+
private void checkAndClearDeletionFlag() {
1384+
if (applicationKvStore.getBoolean(String.format(NOMINATING_FOR_DELETION_MEDIA, media.getImageUrl()), false)) {
1385+
applicationKvStore.remove(String.format(NOMINATING_FOR_DELETION_MEDIA, media.getImageUrl()));
1386+
callback.nominatingForDeletion(index); // Notify that nomination for deletion has proceeded
1387+
}
1388+
}
1389+
13591390
private void rebuildCatList(List<String> categories) {
13601391
categoryContainer.removeAllViews();
13611392
for (String category : categories) {

0 commit comments

Comments
 (0)