Fixed #4906 : Peer review: "thank the contributor" should show snackb… (#4914)

* 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
This commit is contained in:
Arin Modi 2022-04-26 01:18:43 +05:30 committed by GitHub
parent 11bc72c514
commit 1ae013d2b3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 31 additions and 12 deletions

View file

@ -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)

View file

@ -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()