@@ -94,6 +94,7 @@ public class MediaDetailFragment extends CommonsDaggerSupportFragment implements
94
94
private int index ;
95
95
private boolean isDeleted = false ;
96
96
private boolean isWikipediaButtonDisplayed ;
97
+ private Callback callback ;
97
98
98
99
99
100
public static MediaDetailFragment forMedia (int index , boolean editable , boolean isCategoryImage , boolean isWikipediaButtonDisplayed ) {
@@ -195,6 +196,8 @@ public static MediaDetailFragment forMedia(int index, boolean editable, boolean
195
196
TextView existingCategories ;
196
197
@ BindView (R .id .no_results_found )
197
198
TextView noResultsFound ;
199
+ @ BindView (R .id .progressBarDeletion )
200
+ ProgressBar progressBarDeletion ;
198
201
199
202
private ArrayList <String > categoryNames = new ArrayList <>();
200
203
private String categorySearchQuery ;
@@ -228,6 +231,8 @@ public static MediaDetailFragment forMedia(int index, boolean editable, boolean
228
231
*/
229
232
private int minimumHeightOfMetadata = 200 ;
230
233
234
+ final static String NOMINATING_FOR_DELETION_MEDIA = "Nominating for deletion %s" ;
235
+
231
236
@ Override
232
237
public void onSaveInstanceState (Bundle outState ) {
233
238
super .onSaveInstanceState (outState );
@@ -305,6 +310,14 @@ public void run() {
305
310
return view ;
306
311
}
307
312
313
+ @ Override
314
+ public void onAttach (final Context context ) {
315
+ super .onAttach (context );
316
+ if (getParentFragment () != null ) {
317
+ callback = (Callback ) getParentFragment ();
318
+ }
319
+ }
320
+
308
321
@ OnClick (R .id .mediaDetailImageViewSpacer )
309
322
public void launchZoomActivity (View view ) {
310
323
if (media .getImageUrl () != null ) {
@@ -339,6 +352,12 @@ public void onResume() {
339
352
media = getArguments ().getParcelable ("media" );
340
353
}
341
354
355
+ media = detailProvider .getMediaAtPosition (index );
356
+
357
+ if (media != null && applicationKvStore .getBoolean (String .format (NOMINATING_FOR_DELETION_MEDIA , media .getImageUrl ()), false )) {
358
+ enableProgressBar ();
359
+ }
360
+
342
361
scrollView .getViewTreeObserver ().addOnGlobalLayoutListener (
343
362
new OnGlobalLayoutListener () {
344
363
@ Override
@@ -348,7 +367,9 @@ public void onGlobalLayout() {
348
367
}
349
368
scrollView .getViewTreeObserver ().removeOnGlobalLayoutListener (this );
350
369
oldWidthOfImageView = scrollView .getWidth ();
351
- displayMediaDetails ();
370
+ if (media != null ) {
371
+ displayMediaDetails ();
372
+ }
352
373
}
353
374
}
354
375
);
@@ -431,6 +452,10 @@ private void onDiscussionLoaded(String discussion) {
431
452
432
453
private void onDeletionPageExists (Boolean deletionPageExists ) {
433
454
if (deletionPageExists ){
455
+ if (applicationKvStore .getBoolean (String .format (NOMINATING_FOR_DELETION_MEDIA , media .getImageUrl ()), false )) {
456
+ applicationKvStore .remove (String .format (NOMINATING_FOR_DELETION_MEDIA , media .getImageUrl ()));
457
+ progressBarDeletion .setVisibility (GONE );
458
+ }
434
459
delete .setVisibility (GONE );
435
460
nominatedForDeletion .setVisibility (VISIBLE );
436
461
} else if (!isCategoryImage ) {
@@ -804,7 +829,7 @@ public void onDeleteButtonClicked(){
804
829
input .addTextChangedListener (new TextWatcher () {
805
830
private void handleText () {
806
831
final Button okButton = d .getButton (AlertDialog .BUTTON_POSITIVE );
807
- if (input .getText ().length () == 0 ) {
832
+ if (input .getText ().length () == 0 || isDeleted ) {
808
833
okButton .setEnabled (false );
809
834
} else {
810
835
okButton .setEnabled (true );
@@ -831,35 +856,37 @@ public void onTextChanged(CharSequence s, int start, int before, int count) {
831
856
832
857
@ SuppressLint ("CheckResult" )
833
858
private void onDeleteClicked (Spinner spinner ) {
859
+ applicationKvStore .putBoolean (String .format (NOMINATING_FOR_DELETION_MEDIA , media .getImageUrl ()), true );
860
+ enableProgressBar ();
834
861
String reason = spinner .getSelectedItem ().toString ();
835
862
Single <Boolean > resultSingle = reasonBuilder .getReason (media , reason )
836
863
.flatMap (reasonString -> deleteHelper .makeDeletion (getContext (), media , reason ));
837
- compositeDisposable .add (resultSingle
838
- .subscribeOn (Schedulers .io ())
839
- .observeOn (AndroidSchedulers .mainThread ())
840
- .subscribe (s -> {
841
- if (getActivity () != null ) {
842
- isDeleted = true ;
843
- enableDeleteButton (false );
844
- }
845
- }));
846
-
864
+ resultSingle
865
+ .subscribeOn (Schedulers .io ())
866
+ .observeOn (AndroidSchedulers .mainThread ())
867
+ .subscribe (s -> {
868
+ if (applicationKvStore .getBoolean (String .format (NOMINATING_FOR_DELETION_MEDIA , media .getImageUrl ()), false )) {
869
+ applicationKvStore .remove (String .format (NOMINATING_FOR_DELETION_MEDIA , media .getImageUrl ()));
870
+ callback .nominatingForDeletion (index );
871
+ }
872
+ });
847
873
}
848
874
849
875
@ SuppressLint ("CheckResult" )
850
876
private void onDeleteClickeddialogtext (String reason ) {
877
+ applicationKvStore .putBoolean (String .format (NOMINATING_FOR_DELETION_MEDIA , media .getImageUrl ()), true );
878
+ enableProgressBar ();
851
879
Single <Boolean > resultSingletext = reasonBuilder .getReason (media , reason )
852
880
.flatMap (reasonString -> deleteHelper .makeDeletion (getContext (), media , reason ));
853
- compositeDisposable .add (resultSingletext
854
- .subscribeOn (Schedulers .io ())
855
- .observeOn (AndroidSchedulers .mainThread ())
856
- .subscribe (s -> {
857
- if (getActivity () != null ) {
858
- isDeleted = true ;
859
- enableDeleteButton (false );
860
- }
861
- }));
862
-
881
+ resultSingletext
882
+ .subscribeOn (Schedulers .io ())
883
+ .observeOn (AndroidSchedulers .mainThread ())
884
+ .subscribe (s -> {
885
+ if (applicationKvStore .getBoolean (String .format (NOMINATING_FOR_DELETION_MEDIA , media .getImageUrl ()), false )) {
886
+ applicationKvStore .remove (String .format (NOMINATING_FOR_DELETION_MEDIA , media .getImageUrl ()));
887
+ callback .nominatingForDeletion (index );
888
+ }
889
+ });
863
890
}
864
891
865
892
@ OnClick (R .id .seeMore )
@@ -869,13 +896,13 @@ public void onSeeMoreClicked(){
869
896
}
870
897
}
871
898
872
- private void enableDeleteButton ( boolean visibility ) {
873
- delete . setEnabled ( visibility );
874
- if ( visibility ) {
875
- delete . setTextColor ( getResources (). getColor ( R . color . primaryTextColor ));
876
- } else {
877
- delete .setTextColor ( getResources (). getColor ( R . color . deleteButtonLight ) );
878
- }
899
+ /**
900
+ * Enable Progress Bar and Update delete button text.
901
+ */
902
+ private void enableProgressBar () {
903
+ progressBarDeletion . setVisibility ( VISIBLE );
904
+ delete .setText ( "Nominating for Deletion" );
905
+ isDeleted = true ;
879
906
}
880
907
881
908
private void rebuildCatList (List <String > categories ) {
@@ -1005,4 +1032,8 @@ public boolean updateCategoryDisplay(List<String> categories) {
1005
1032
return true ;
1006
1033
}
1007
1034
}
1035
+
1036
+ public interface Callback {
1037
+ void nominatingForDeletion (int index );
1038
+ }
1008
1039
}
0 commit comments