From 1ae013d2b321df3757c6336467688cc9bd95d2eb Mon Sep 17 00:00:00 2001 From: Arin Modi Date: Tue, 26 Apr 2022 01:18:43 +0530 Subject: [PATCH] =?UTF-8?q?Fixed=20#4906=20:=20Peer=20review:=20"thank=20t?= =?UTF-8?q?he=20contributor"=20should=20show=20snackb=E2=80=A6=20(#4914)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Fixed #4906 : Peer review: "thank the contributor" should show snackbar instead of notification * changes the snackbar to toast * added the tests * minor changes * minor changes - 2 --- .../nrw/commons/review/ReviewController.java | 28 +++++++++++-------- .../commons/review/ReviewControllerTest.kt | 15 ++++++++++ 2 files changed, 31 insertions(+), 12 deletions(-) diff --git a/app/src/main/java/fr/free/nrw/commons/review/ReviewController.java b/app/src/main/java/fr/free/nrw/commons/review/ReviewController.java index d7bb36031..1efef7aa8 100644 --- a/app/src/main/java/fr/free/nrw/commons/review/ReviewController.java +++ b/app/src/main/java/fr/free/nrw/commons/review/ReviewController.java @@ -156,21 +156,25 @@ public class ReviewController { .subscribeOn(Schedulers.io()) .observeOn(AndroidSchedulers.mainThread()) .subscribe((result) -> { - String message; - String title; - if (result) { - title = context.getString(R.string.send_thank_success_title); - message = context.getString(R.string.send_thank_success_message, media.getDisplayTitle()); - } else { - title = context.getString(R.string.send_thank_failure_title); - message = context.getString(R.string.send_thank_failure_message, media.getDisplayTitle()); - } - - showNotification(title, message); - + displayThanksToast(context,result); }, Timber::e); } + @SuppressLint("StringFormatInvalid") + private void displayThanksToast(final Context context, final boolean result){ + final String message; + final String title; + if (result) { + title = context.getString(R.string.send_thank_success_title); + message = context.getString(R.string.send_thank_success_message, media.getDisplayTitle()); + } else { + title = context.getString(R.string.send_thank_failure_title); + message = context.getString(R.string.send_thank_failure_message, media.getDisplayTitle()); + } + + ViewUtil.showShortToast(context,message); + } + private void showNotification(String title, String message) { notificationBuilder.setDefaults(NotificationCompat.DEFAULT_ALL) .setContentTitle(title) diff --git a/app/src/test/kotlin/fr/free/nrw/commons/review/ReviewControllerTest.kt b/app/src/test/kotlin/fr/free/nrw/commons/review/ReviewControllerTest.kt index 9c89eaeeb..684ad15fd 100644 --- a/app/src/test/kotlin/fr/free/nrw/commons/review/ReviewControllerTest.kt +++ b/app/src/test/kotlin/fr/free/nrw/commons/review/ReviewControllerTest.kt @@ -144,8 +144,23 @@ class ReviewControllerTest { R.string.send_thank_toast, media.displayTitle ) ) + + val method: Method = ReviewController::class.java.getDeclaredMethod( + "displayThanksToast", Context::class.java, Boolean::class.java + ) + + method.isAccessible = true + method.invoke(controller,context,true) + + assertEquals( + ShadowToast.getTextOfLatestToast().toString(), + context.getString( + R.string.send_thank_success_message, media.displayTitle + ) + ) } + @Test fun testSendThanksCaseNull() { shadowOf(Looper.getMainLooper()).idle()