Skip to content

Commit

Permalink
Fix : Circular ProgressBar stops after Nomination of Deletion
Browse files Browse the repository at this point in the history
  • Loading branch information
neeldoshii committed Mar 6, 2024
1 parent 28ea111 commit c298657
Showing 1 changed file with 43 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1300,12 +1300,7 @@ private void onDeleteClicked(Spinner spinner) {
resultSingle
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(s -> {
if(applicationKvStore.getBoolean(String.format(NOMINATING_FOR_DELETION_MEDIA, media.getImageUrl()), false)) {
applicationKvStore.remove(String.format(NOMINATING_FOR_DELETION_MEDIA, media.getImageUrl()));
callback.nominatingForDeletion(index);
}
});
.subscribe(this::handleDeletionResult, this::handleDeletionError);
}

@SuppressLint("CheckResult")
Expand All @@ -1317,12 +1312,7 @@ private void onDeleteClickeddialogtext(String reason) {
resultSingletext
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(s -> {
if(applicationKvStore.getBoolean(String.format(NOMINATING_FOR_DELETION_MEDIA, media.getImageUrl()), false)) {
applicationKvStore.remove(String.format(NOMINATING_FOR_DELETION_MEDIA, media.getImageUrl()));
callback.nominatingForDeletion(index);
}
});
.subscribe(this::handleDeletionResult, this::handleDeletionError);
}

@OnClick(R.id.seeMore)
Expand Down Expand Up @@ -1356,6 +1346,47 @@ private void enableProgressBar() {
isDeleted = true;
}

/**
* Disables Progress Bar and Update delete button text.
*/
private void disableProgressBar() {
if (getActivity() == null) {
return; // Prevent NullPointerException when fragment is not attached to activity
}
getActivity().runOnUiThread(() -> {
if (progressBarDeletion != null) {
progressBarDeletion.setVisibility(GONE);
}
});
}

private void handleDeletionResult(final boolean success) {
if (success) {
Timber.d("Nominated for Deletion : Success");
delete.setText("Nominated for Deletion");
ViewUtil.showLongSnackbar(requireView(),
"Nominating for deletion : Success");
disableProgressBar();
checkAndClearDeletionFlag();
} else {
disableProgressBar();
}
}

private void handleDeletionError(final Throwable throwable) {
// Log error or show error message to the user
Timber.e(throwable.getLocalizedMessage());
disableProgressBar();
checkAndClearDeletionFlag();
}

private void checkAndClearDeletionFlag() {
if (applicationKvStore.getBoolean(String.format(NOMINATING_FOR_DELETION_MEDIA, media.getImageUrl()), false)) {
applicationKvStore.remove(String.format(NOMINATING_FOR_DELETION_MEDIA, media.getImageUrl()));
callback.nominatingForDeletion(index); // Notify that nomination for deletion has proceeded
}
}

private void rebuildCatList(List<String> categories) {
categoryContainer.removeAllViews();
for (String category : categories) {
Expand Down

0 comments on commit c298657

Please sign in to comment.