@@ -1300,12 +1300,7 @@ private void onDeleteClicked(Spinner spinner) {
1300
1300
resultSingle
1301
1301
.subscribeOn (Schedulers .io ())
1302
1302
.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 );
1309
1304
}
1310
1305
1311
1306
@ SuppressLint ("CheckResult" )
@@ -1317,12 +1312,7 @@ private void onDeleteClickeddialogtext(String reason) {
1317
1312
resultSingletext
1318
1313
.subscribeOn (Schedulers .io ())
1319
1314
.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 );
1326
1316
}
1327
1317
1328
1318
@ OnClick (R .id .seeMore )
@@ -1356,6 +1346,47 @@ private void enableProgressBar() {
1356
1346
isDeleted = true ;
1357
1347
}
1358
1348
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
+
1359
1390
private void rebuildCatList (List <String > categories ) {
1360
1391
categoryContainer .removeAllViews ();
1361
1392
for (String category : categories ) {
0 commit comments