4444import fr .free .nrw .commons .MediaDataExtractor ;
4545import fr .free .nrw .commons .R ;
4646import fr .free .nrw .commons .Utils ;
47+ import fr .free .nrw .commons .auth .AccountUtil ;
4748import fr .free .nrw .commons .category .CategoryDetailsActivity ;
4849import fr .free .nrw .commons .contributions .ContributionsFragment ;
4950import fr .free .nrw .commons .delete .DeleteHelper ;
@@ -367,6 +368,7 @@ public void onCopyWikicodeClicked(){
367368
368369 @ OnClick (R .id .nominateDeletion )
369370 public void onDeleteButtonClicked (){
371+ if (AccountUtil .getUserName (getContext ()).equals (media .getCreator ())){
370372 final ArrayAdapter <String > languageAdapter = new ArrayAdapter <>(getActivity (),
371373 R .layout .simple_spinner_dropdown_list , reasonList );
372374 final Spinner spinner = new Spinner (getActivity ());
@@ -384,19 +386,19 @@ public void onDeleteButtonClicked(){
384386 if (isDeleted ) {
385387 dialog .getButton (AlertDialog .BUTTON_POSITIVE ).setEnabled (false );
386388 }
389+ }
387390 //Reviewer correct me if i have misunderstood something over here
388391 //But how does this if (delete.getVisibility() == View.VISIBLE) {
389392 // enableDeleteButton(true); makes sense ?
393+ else {
390394 AlertDialog .Builder alert = new AlertDialog .Builder (getActivity ());
391- alert .setMessage ("Why should this fileckathon-2018 be deleted?" );
395+ alert .setMessage ("Why should " + media . getDisplayTitle () + " be deleted?" );
392396 final EditText input = new EditText (getActivity ());
393397 alert .setView (input );
394398 input .requestFocus ();
395399 alert .setPositiveButton (R .string .ok , (dialog1 , whichButton ) -> {
396400 String reason = input .getText ().toString ();
397-
398- deleteHelper .makeDeletion (getContext (), media , reason );
399- enableDeleteButton (false );
401+ onDeleteClickeddialogtext (reason );
400402 });
401403 alert .setNegativeButton (R .string .cancel , (dialog12 , whichButton ) -> {
402404 });
@@ -427,6 +429,7 @@ public void onTextChanged(CharSequence s, int start, int before, int count) {
427429 d .show ();
428430 d .getButton (AlertDialog .BUTTON_POSITIVE ).setEnabled (false );
429431 }
432+ }
430433
431434 @ SuppressLint ("CheckResult" )
432435 private void onDeleteClicked (Spinner spinner ) {
@@ -445,6 +448,22 @@ private void onDeleteClicked(Spinner spinner) {
445448
446449 }
447450
451+ @ SuppressLint ("CheckResult" )
452+ private void onDeleteClickeddialogtext (String reason ) {
453+ Single <Boolean > resultSingletext = reasonBuilder .getReason (media , reason )
454+ .flatMap (reasonString -> deleteHelper .makeDeletion (getContext (), media , reason ));
455+ compositeDisposable .add (resultSingletext
456+ .subscribeOn (Schedulers .io ())
457+ .observeOn (AndroidSchedulers .mainThread ())
458+ .subscribe (s -> {
459+ if (getActivity () != null ) {
460+ isDeleted = true ;
461+ enableDeleteButton (false );
462+ }
463+ }));
464+
465+ }
466+
448467 @ OnClick (R .id .seeMore )
449468 public void onSeeMoreClicked (){
450469 if (nominatedForDeletion .getVisibility () == VISIBLE && getActivity () != null ) {
0 commit comments