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

Fixes #5531 Circular Progress bar keeps on moving when nomination for deletion is successful. #5610

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1227,12 +1227,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 @@ -1244,12 +1239,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);
}

public void onSeeMoreClicked(){
Expand Down Expand Up @@ -1281,6 +1271,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) {
binding.mediaDetailCategoryContainer.removeAllViews();
for (String category : categories) {
Expand Down
Loading