Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,8 @@ private boolean delete(Media media, String reason) {
mwApi.appendEdit(editToken, logPageString + "\n",
"Commons:Deletion_requests/" + date, summary);
mwApi.appendEdit(editToken, userPageString + "\n",
"User_Talk:" + sessionManager.getCurrentAccount().name, summary);
"User_Talk:" + media.getCreator(), summary);

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good :-)

} catch (Exception e) {
Timber.e(e);
return false;
Expand Down
121 changes: 69 additions & 52 deletions app/src/main/java/fr/free/nrw/commons/media/MediaDetailFragment.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
import fr.free.nrw.commons.MediaDataExtractor;
import fr.free.nrw.commons.R;
import fr.free.nrw.commons.Utils;
import fr.free.nrw.commons.auth.AccountUtil;
import fr.free.nrw.commons.category.CategoryDetailsActivity;
import fr.free.nrw.commons.contributions.ContributionsFragment;
import fr.free.nrw.commons.delete.DeleteHelper;
Expand Down Expand Up @@ -366,66 +367,68 @@ public void onCopyWikicodeClicked(){
}

@OnClick(R.id.nominateDeletion)
public void onDeleteButtonClicked(){
final ArrayAdapter<String> languageAdapter = new ArrayAdapter<>(getActivity(),
R.layout.simple_spinner_dropdown_list, reasonList);
final Spinner spinner = new Spinner(getActivity());
spinner.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT));
spinner.setAdapter(languageAdapter);
spinner.setGravity(17);

AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
builder.setView(spinner);
builder.setTitle(R.string.nominate_delete)
.setPositiveButton(R.string.about_translate_proceed, (dialog, which) -> onDeleteClicked(spinner));
builder.setNegativeButton(R.string.about_translate_cancel, (dialog, which) -> dialog.dismiss());
AlertDialog dialog = builder.create();
dialog.show();
if(isDeleted) {
dialog.getButton(AlertDialog.BUTTON_POSITIVE).setEnabled(false);
public void onDeleteButtonClicked() {
if (media.getCreator().equals(AccountUtil.getUserName(getContext()))) {
final ArrayAdapter<String> languageAdapter = new ArrayAdapter<>(getActivity(),
R.layout.simple_spinner_dropdown_list, reasonList);
final Spinner spinner = new Spinner(getActivity());
spinner.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT));
spinner.setAdapter(languageAdapter);
spinner.setGravity(17);

AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
builder.setView(spinner);
builder.setTitle(R.string.nominate_delete)
.setPositiveButton(R.string.about_translate_proceed, (dialog, which) -> onDeleteClicked(spinner));
builder.setNegativeButton(R.string.about_translate_cancel, (dialog, which) -> dialog.dismiss());
AlertDialog dialog = builder.create();
dialog.show();
if (isDeleted) {
dialog.getButton(AlertDialog.BUTTON_POSITIVE).setEnabled(false);
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems that you have reformatted the code? That makes it difficult to see what has actually changed. Better send a first pull request with only the real changes, and then optionally later a second pull request with only the reformatting. Thanks! :-)

}
//Reviewer correct me if i have misunderstood something over here
//But how does this if (delete.getVisibility() == View.VISIBLE) {
// enableDeleteButton(true); makes sense ?
AlertDialog.Builder alert = new AlertDialog.Builder(getActivity());
alert.setMessage("Why should this fileckathon-2018 be deleted?");
final EditText input = new EditText(getActivity());
alert.setView(input);
input.requestFocus();
alert.setPositiveButton(R.string.ok, (dialog1, whichButton) -> {
String reason = input.getText().toString();

deleteHelper.makeDeletion(getContext(), media, reason);
enableDeleteButton(false);
});
alert.setNegativeButton(R.string.cancel, (dialog12, whichButton) -> {
});
AlertDialog d = alert.create();
input.addTextChangedListener(new TextWatcher() {
private void handleText() {
final Button okButton = d.getButton(AlertDialog.BUTTON_POSITIVE);
if (input.getText().length() == 0) {
okButton.setEnabled(false);
} else {
okButton.setEnabled(true);
else {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same thing @nicolas-raoul pointed happened here too. Indentation of several lines are changed. Reviewers click "files changed" tab on your pull request page and see changed lines. When you made additional changes it is hard to understand for us what will be inserted into our code base if we merge this changes. Even if your additional changes are beneficial for code quality etc. please send them in separate pull request. We should be seeing only relevant lines changed under a single pull request.

AlertDialog.Builder alert = new AlertDialog.Builder(getActivity());
alert.setMessage("Why should "+ media.getDisplayTitle() +" be deleted?");
final EditText input = new EditText(getActivity());
alert.setView(input);
input.requestFocus();
alert.setPositiveButton(R.string.ok, (dialog1, whichButton) -> {
String reason = input.getText().toString();
onDeleteClickedOthers(reason);
});
alert.setNegativeButton(R.string.cancel, (dialog12, whichButton) -> {
});
AlertDialog d = alert.create();
input.addTextChangedListener(new TextWatcher() {
private void handleText() {
final Button okButton = d.getButton(AlertDialog.BUTTON_POSITIVE);
if (input.getText().length() == 0) {
okButton.setEnabled(false);
} else {
okButton.setEnabled(true);
}
}
}

@Override
public void afterTextChanged(Editable arg0) {
handleText();
}
@Override
public void afterTextChanged(Editable arg0) {
handleText();
}

@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
}
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
}

@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
}
});
d.show();
d.getButton(AlertDialog.BUTTON_POSITIVE).setEnabled(false);
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
}
});
d.show();
d.getButton(AlertDialog.BUTTON_POSITIVE).setEnabled(false);
}
}

@SuppressLint("CheckResult")
Expand All @@ -443,6 +446,20 @@ private void onDeleteClicked(Spinner spinner) {
}
}));

}
private void onDeleteClickedOthers(String reason){
Single<Boolean> resultSingles = reasonBuilder.getReason(media, reason)
.flatMap(reasonString -> deleteHelper.makeDeletion(getContext(), media, reason));
compositeDisposable.add(resultSingles
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(s -> {
if (getActivity() != null) {
isDeleted = true;
enableDeleteButton(false);
}
}));

}

@OnClick(R.id.seeMore)
Expand Down