mirror of
https://github.com/commons-app/apps-android-commons.git
synced 2025-10-27 12:53:55 +01:00
* Fixed - #4844 : [Bug]: In peer review, deletion proposal is sent even if no reason is chosen * Minor Changes * Minor Fixes * added required changes * added required changes - 1 * Added Test For OK Button * Minor Fixes
This commit is contained in:
parent
16266975d8
commit
c626f97fb9
2 changed files with 56 additions and 12 deletions
|
|
@ -5,6 +5,7 @@ import static fr.free.nrw.commons.notification.NotificationHelper.NOTIFICATION_D
|
||||||
import android.annotation.SuppressLint;
|
import android.annotation.SuppressLint;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import static fr.free.nrw.commons.utils.LangCodeUtils.getLocalizedResources;
|
import static fr.free.nrw.commons.utils.LangCodeUtils.getLocalizedResources;
|
||||||
|
import android.content.DialogInterface;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
import androidx.appcompat.app.AlertDialog;
|
import androidx.appcompat.app.AlertDialog;
|
||||||
|
|
@ -39,6 +40,8 @@ public class DeleteHelper {
|
||||||
private final PageEditClient pageEditClient;
|
private final PageEditClient pageEditClient;
|
||||||
private final ViewUtilWrapper viewUtil;
|
private final ViewUtilWrapper viewUtil;
|
||||||
private final String username;
|
private final String username;
|
||||||
|
private AlertDialog d;
|
||||||
|
private DialogInterface.OnMultiChoiceClickListener listener;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
public DeleteHelper(NotificationHelper notificationHelper,
|
public DeleteHelper(NotificationHelper notificationHelper,
|
||||||
|
|
@ -176,12 +179,17 @@ public class DeleteHelper {
|
||||||
reasonListEnglish[2] = getLocalizedResources(context, Locale.ENGLISH).getString(R.string.delete_helper_ask_reason_copyright_logo);
|
reasonListEnglish[2] = getLocalizedResources(context, Locale.ENGLISH).getString(R.string.delete_helper_ask_reason_copyright_logo);
|
||||||
}
|
}
|
||||||
|
|
||||||
alert.setMultiChoiceItems(reasonList, checkedItems, (dialogInterface, position, isChecked) -> {
|
alert.setMultiChoiceItems(reasonList, checkedItems, listener = (dialogInterface, position, isChecked) -> {
|
||||||
|
|
||||||
if (isChecked) {
|
if (isChecked) {
|
||||||
mUserReason.add(position);
|
mUserReason.add(position);
|
||||||
} else {
|
} else {
|
||||||
mUserReason.remove((Integer.valueOf(position)));
|
mUserReason.remove((Integer.valueOf(position)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// disable the OK button if no reason selected
|
||||||
|
((AlertDialog) dialogInterface).getButton(AlertDialog.BUTTON_POSITIVE).setEnabled(
|
||||||
|
!mUserReason.isEmpty());
|
||||||
});
|
});
|
||||||
|
|
||||||
alert.setPositiveButton(context.getString(R.string.ok), (dialogInterface, i) -> {
|
alert.setPositiveButton(context.getString(R.string.ok), (dialogInterface, i) -> {
|
||||||
|
|
@ -200,20 +208,39 @@ public class DeleteHelper {
|
||||||
String finalReason = reason;
|
String finalReason = reason;
|
||||||
|
|
||||||
Single.defer((Callable<SingleSource<Boolean>>) () ->
|
Single.defer((Callable<SingleSource<Boolean>>) () ->
|
||||||
makeDeletion(context, media, finalReason))
|
makeDeletion(context, media, finalReason))
|
||||||
.subscribeOn(Schedulers.io())
|
.subscribeOn(Schedulers.io())
|
||||||
.observeOn(AndroidSchedulers.mainThread())
|
.observeOn(AndroidSchedulers.mainThread())
|
||||||
.subscribe(aBoolean -> {
|
.subscribe(aBoolean -> {
|
||||||
if (aBoolean) {
|
if (aBoolean) {
|
||||||
reviewCallback.onSuccess();
|
reviewCallback.onSuccess();
|
||||||
} else {
|
} else {
|
||||||
reviewCallback.onFailure();
|
reviewCallback.onFailure();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
alert.setNegativeButton(context.getString(R.string.cancel), (dialog, which) -> reviewCallback.onFailure());
|
alert.setNegativeButton(context.getString(R.string.cancel), (dialog, which) -> reviewCallback.onFailure());
|
||||||
AlertDialog d = alert.create();
|
d = alert.create();
|
||||||
d.show();
|
d.show();
|
||||||
|
|
||||||
|
// disable the OK button by default
|
||||||
|
d.getButton(AlertDialog.BUTTON_POSITIVE).setEnabled(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* returns the instance of shown AlertDialog,
|
||||||
|
* used for taking reference during unit test
|
||||||
|
* */
|
||||||
|
public AlertDialog getDialog(){
|
||||||
|
return d;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* returns the instance of shown DialogInterface.OnMultiChoiceClickListener,
|
||||||
|
* used for taking reference during unit test
|
||||||
|
* */
|
||||||
|
public DialogInterface.OnMultiChoiceClickListener getListener(){
|
||||||
|
return listener;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,6 @@
|
||||||
package fr.free.nrw.commons.delete
|
package fr.free.nrw.commons.delete
|
||||||
|
|
||||||
|
import android.app.AlertDialog
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import com.nhaarman.mockitokotlin2.eq
|
import com.nhaarman.mockitokotlin2.eq
|
||||||
import com.nhaarman.mockitokotlin2.mock
|
import com.nhaarman.mockitokotlin2.mock
|
||||||
|
|
@ -15,6 +16,7 @@ import io.reactivex.Observable
|
||||||
import io.reactivex.Single
|
import io.reactivex.Single
|
||||||
import org.junit.Assert.assertNotNull
|
import org.junit.Assert.assertNotNull
|
||||||
import org.junit.Assert.assertTrue
|
import org.junit.Assert.assertTrue
|
||||||
|
import org.junit.Assert.assertEquals
|
||||||
import org.junit.Before
|
import org.junit.Before
|
||||||
import org.junit.Test
|
import org.junit.Test
|
||||||
import org.junit.runner.RunWith
|
import org.junit.runner.RunWith
|
||||||
|
|
@ -142,6 +144,21 @@ class DeleteHelperTest {
|
||||||
deleteHelper.askReasonAndExecute(media, mContext, "My Question", ReviewController.DeleteReason.COPYRIGHT_VIOLATION, callback);
|
deleteHelper.askReasonAndExecute(media, mContext, "My Question", ReviewController.DeleteReason.COPYRIGHT_VIOLATION, callback);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun alertDialogPositiveButtonDisableTest() {
|
||||||
|
val mContext = RuntimeEnvironment.getApplication().applicationContext
|
||||||
|
deleteHelper.askReasonAndExecute(media, mContext, "My Question", ReviewController.DeleteReason.COPYRIGHT_VIOLATION, callback);
|
||||||
|
assertEquals(false, deleteHelper.dialog.getButton(AlertDialog.BUTTON_POSITIVE).isEnabled)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun alertDialogPositiveButtonEnableTest() {
|
||||||
|
val mContext = RuntimeEnvironment.getApplication().applicationContext
|
||||||
|
deleteHelper.askReasonAndExecute(media, mContext, "My Question", ReviewController.DeleteReason.COPYRIGHT_VIOLATION, callback);
|
||||||
|
deleteHelper.listener.onClick(deleteHelper.dialog,1,true);
|
||||||
|
assertEquals(true, deleteHelper.dialog.getButton(AlertDialog.BUTTON_POSITIVE).isEnabled)
|
||||||
|
}
|
||||||
|
|
||||||
@Test(expected = RuntimeException::class)
|
@Test(expected = RuntimeException::class)
|
||||||
fun makeDeletionForEmptyCreatorName() {
|
fun makeDeletionForEmptyCreatorName() {
|
||||||
whenever(pageEditClient.prependEdit(ArgumentMatchers.anyString(), ArgumentMatchers.anyString(), ArgumentMatchers.anyString()))
|
whenever(pageEditClient.prependEdit(ArgumentMatchers.anyString(), ArgumentMatchers.anyString(), ArgumentMatchers.anyString()))
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue