Skip to content

Commit 1fd748f

Browse files
authored
solved crashing problem in nomination button (commons-app#3522)
solved crashing problem in nomination button solved crashing problem in nomination button
1 parent 34a016d commit 1fd748f

File tree

1 file changed

+61
-55
lines changed

1 file changed

+61
-55
lines changed

app/src/main/java/fr/free/nrw/commons/media/MediaDetailFragment.java

+61-55
Original file line numberDiff line numberDiff line change
@@ -348,69 +348,75 @@ public void onCopyWikicodeClicked(){
348348

349349
@OnClick(R.id.nominateDeletion)
350350
public void onDeleteButtonClicked(){
351-
if(AccountUtil.getUserName(getContext()).equals(media.getCreator())){
352-
final ArrayAdapter<String> languageAdapter = new ArrayAdapter<>(getActivity(),
353-
R.layout.simple_spinner_dropdown_list, reasonList);
354-
final Spinner spinner = new Spinner(getActivity());
355-
spinner.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT));
356-
spinner.setAdapter(languageAdapter);
357-
spinner.setGravity(17);
358-
359-
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
360-
builder.setView(spinner);
361-
builder.setTitle(R.string.nominate_delete)
362-
.setPositiveButton(R.string.about_translate_proceed, (dialog, which) -> onDeleteClicked(spinner));
363-
builder.setNegativeButton(R.string.about_translate_cancel, (dialog, which) -> dialog.dismiss());
364-
AlertDialog dialog = builder.create();
365-
dialog.show();
366-
if(isDeleted) {
367-
dialog.getButton(AlertDialog.BUTTON_POSITIVE).setEnabled(false);
368-
}
369-
}
370-
//Reviewer correct me if i have misunderstood something over here
371-
//But how does this if (delete.getVisibility() == View.VISIBLE) {
372-
// enableDeleteButton(true); makes sense ?
373-
else{
374-
AlertDialog.Builder alert = new AlertDialog.Builder(getActivity());
375-
alert.setMessage(getString(R.string.dialog_box_text_nomination,media.getDisplayTitle()));
376-
final EditText input = new EditText(getActivity());
377-
alert.setView(input);
378-
input.requestFocus();
379-
alert.setPositiveButton(R.string.ok, (dialog1, whichButton) -> {
380-
String reason = input.getText().toString();
381-
onDeleteClickeddialogtext(reason);
382-
});
383-
alert.setNegativeButton(R.string.cancel, (dialog12, whichButton) -> {
384-
});
385-
AlertDialog d = alert.create();
386-
input.addTextChangedListener(new TextWatcher() {
387-
private void handleText() {
388-
final Button okButton = d.getButton(AlertDialog.BUTTON_POSITIVE);
389-
if (input.getText().length() == 0) {
390-
okButton.setEnabled(false);
391-
} else {
392-
okButton.setEnabled(true);
351+
if (AccountUtil.getUserName(getContext()) != null && AccountUtil.getUserName(getContext()).equals(media.getCreator())) {
352+
final ArrayAdapter<String> languageAdapter = new ArrayAdapter<>(getActivity(),
353+
R.layout.simple_spinner_dropdown_list, reasonList);
354+
final Spinner spinner = new Spinner(getActivity());
355+
spinner.setLayoutParams(
356+
new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT,
357+
LinearLayout.LayoutParams.WRAP_CONTENT));
358+
spinner.setAdapter(languageAdapter);
359+
spinner.setGravity(17);
360+
361+
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
362+
builder.setView(spinner);
363+
builder.setTitle(R.string.nominate_delete)
364+
.setPositiveButton(R.string.about_translate_proceed,
365+
(dialog, which) -> onDeleteClicked(spinner));
366+
builder.setNegativeButton(R.string.about_translate_cancel,
367+
(dialog, which) -> dialog.dismiss());
368+
AlertDialog dialog = builder.create();
369+
dialog.show();
370+
if (isDeleted) {
371+
dialog.getButton(AlertDialog.BUTTON_POSITIVE).setEnabled(false);
393372
}
394373
}
374+
//Reviewer correct me if i have misunderstood something over here
375+
//But how does this if (delete.getVisibility() == View.VISIBLE) {
376+
// enableDeleteButton(true); makes sense ?
377+
else {
378+
AlertDialog.Builder alert = new AlertDialog.Builder(getActivity());
379+
alert.setMessage(
380+
getString(R.string.dialog_box_text_nomination, media.getDisplayTitle()));
381+
final EditText input = new EditText(getActivity());
382+
alert.setView(input);
383+
input.requestFocus();
384+
alert.setPositiveButton(R.string.ok, (dialog1, whichButton) -> {
385+
String reason = input.getText().toString();
386+
onDeleteClickeddialogtext(reason);
387+
});
388+
alert.setNegativeButton(R.string.cancel, (dialog12, whichButton) -> {
389+
});
390+
AlertDialog d = alert.create();
391+
input.addTextChangedListener(new TextWatcher() {
392+
private void handleText() {
393+
final Button okButton = d.getButton(AlertDialog.BUTTON_POSITIVE);
394+
if (input.getText().length() == 0) {
395+
okButton.setEnabled(false);
396+
} else {
397+
okButton.setEnabled(true);
398+
}
399+
}
395400

396-
@Override
397-
public void afterTextChanged(Editable arg0) {
398-
handleText();
399-
}
401+
@Override
402+
public void afterTextChanged(Editable arg0) {
403+
handleText();
404+
}
400405

401-
@Override
402-
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
403-
}
406+
@Override
407+
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
408+
}
404409

405-
@Override
406-
public void onTextChanged(CharSequence s, int start, int before, int count) {
410+
@Override
411+
public void onTextChanged(CharSequence s, int start, int before, int count) {
412+
}
413+
});
414+
d.show();
415+
d.getButton(AlertDialog.BUTTON_POSITIVE).setEnabled(false);
407416
}
408-
});
409-
d.show();
410-
d.getButton(AlertDialog.BUTTON_POSITIVE).setEnabled(false);
411-
}
412417
}
413418

419+
414420
@SuppressLint("CheckResult")
415421
private void onDeleteClicked(Spinner spinner) {
416422
String reason = spinner.getSelectedItem().toString();

0 commit comments

Comments
 (0)