44
44
import fr .free .nrw .commons .MediaDataExtractor ;
45
45
import fr .free .nrw .commons .R ;
46
46
import fr .free .nrw .commons .Utils ;
47
+ import fr .free .nrw .commons .auth .AccountUtil ;
47
48
import fr .free .nrw .commons .category .CategoryDetailsActivity ;
48
49
import fr .free .nrw .commons .contributions .ContributionsFragment ;
49
50
import fr .free .nrw .commons .delete .DeleteHelper ;
@@ -367,6 +368,7 @@ public void onCopyWikicodeClicked(){
367
368
368
369
@ OnClick (R .id .nominateDeletion )
369
370
public void onDeleteButtonClicked (){
371
+ if (AccountUtil .getUserName (getContext ()).equals (media .getCreator ())){
370
372
final ArrayAdapter <String > languageAdapter = new ArrayAdapter <>(getActivity (),
371
373
R .layout .simple_spinner_dropdown_list , reasonList );
372
374
final Spinner spinner = new Spinner (getActivity ());
@@ -384,19 +386,19 @@ public void onDeleteButtonClicked(){
384
386
if (isDeleted ) {
385
387
dialog .getButton (AlertDialog .BUTTON_POSITIVE ).setEnabled (false );
386
388
}
389
+ }
387
390
//Reviewer correct me if i have misunderstood something over here
388
391
//But how does this if (delete.getVisibility() == View.VISIBLE) {
389
392
// enableDeleteButton(true); makes sense ?
393
+ else {
390
394
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?" );
392
396
final EditText input = new EditText (getActivity ());
393
397
alert .setView (input );
394
398
input .requestFocus ();
395
399
alert .setPositiveButton (R .string .ok , (dialog1 , whichButton ) -> {
396
400
String reason = input .getText ().toString ();
397
-
398
- deleteHelper .makeDeletion (getContext (), media , reason );
399
- enableDeleteButton (false );
401
+ onDeleteClickeddialogtext (reason );
400
402
});
401
403
alert .setNegativeButton (R .string .cancel , (dialog12 , whichButton ) -> {
402
404
});
@@ -427,6 +429,7 @@ public void onTextChanged(CharSequence s, int start, int before, int count) {
427
429
d .show ();
428
430
d .getButton (AlertDialog .BUTTON_POSITIVE ).setEnabled (false );
429
431
}
432
+ }
430
433
431
434
@ SuppressLint ("CheckResult" )
432
435
private void onDeleteClicked (Spinner spinner ) {
@@ -445,6 +448,22 @@ private void onDeleteClicked(Spinner spinner) {
445
448
446
449
}
447
450
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
+
448
467
@ OnClick (R .id .seeMore )
449
468
public void onSeeMoreClicked (){
450
469
if (nominatedForDeletion .getVisibility () == VISIBLE && getActivity () != null ) {
0 commit comments