Skip to content

Commit 1ae013d

Browse files
authored
Fixed commons-app#4906 : Peer review: "thank the contributor" should show snackb… (commons-app#4914)
* Fixed commons-app#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
1 parent 11bc72c commit 1ae013d

File tree

2 files changed

+30
-11
lines changed

2 files changed

+30
-11
lines changed

app/src/main/java/fr/free/nrw/commons/review/ReviewController.java

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -156,19 +156,23 @@ void sendThanks(@NonNull Activity activity) {
156156
.subscribeOn(Schedulers.io())
157157
.observeOn(AndroidSchedulers.mainThread())
158158
.subscribe((result) -> {
159-
String message;
160-
String title;
161-
if (result) {
162-
title = context.getString(R.string.send_thank_success_title);
163-
message = context.getString(R.string.send_thank_success_message, media.getDisplayTitle());
164-
} else {
165-
title = context.getString(R.string.send_thank_failure_title);
166-
message = context.getString(R.string.send_thank_failure_message, media.getDisplayTitle());
167-
}
159+
displayThanksToast(context,result);
160+
}, Timber::e);
161+
}
168162

169-
showNotification(title, message);
163+
@SuppressLint("StringFormatInvalid")
164+
private void displayThanksToast(final Context context, final boolean result){
165+
final String message;
166+
final String title;
167+
if (result) {
168+
title = context.getString(R.string.send_thank_success_title);
169+
message = context.getString(R.string.send_thank_success_message, media.getDisplayTitle());
170+
} else {
171+
title = context.getString(R.string.send_thank_failure_title);
172+
message = context.getString(R.string.send_thank_failure_message, media.getDisplayTitle());
173+
}
170174

171-
}, Timber::e);
175+
ViewUtil.showShortToast(context,message);
172176
}
173177

174178
private void showNotification(String title, String message) {

app/src/test/kotlin/fr/free/nrw/commons/review/ReviewControllerTest.kt

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,8 +144,23 @@ class ReviewControllerTest {
144144
R.string.send_thank_toast, media.displayTitle
145145
)
146146
)
147+
148+
val method: Method = ReviewController::class.java.getDeclaredMethod(
149+
"displayThanksToast", Context::class.java, Boolean::class.java
150+
)
151+
152+
method.isAccessible = true
153+
method.invoke(controller,context,true)
154+
155+
assertEquals(
156+
ShadowToast.getTextOfLatestToast().toString(),
157+
context.getString(
158+
R.string.send_thank_success_message, media.displayTitle
159+
)
160+
)
147161
}
148162

163+
149164
@Test
150165
fun testSendThanksCaseNull() {
151166
shadowOf(Looper.getMainLooper()).idle()

0 commit comments

Comments
 (0)