Skip to content
This repository has been archived by the owner on Jun 27, 2020. It is now read-only.

Commit

Permalink
Display error message, when there were a handle changes
Browse files Browse the repository at this point in the history
  • Loading branch information
Evgenii Kanivets committed Jan 10, 2019
1 parent 421c6a9 commit 1e1cc80
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ class CwApp : Application() {
}


fun showError() {
Toast.makeText(applicationContext, getString(R.string.no_internet_connection), Toast.LENGTH_SHORT).show()
fun showError(message: String = getString(R.string.no_internet_connection)) {
Toast.makeText(applicationContext, message, Toast.LENGTH_SHORT).show()
}

companion object {
Expand Down
16 changes: 11 additions & 5 deletions app/src/main/java/com/bogdan/codeforceswatcher/util/UserLoader.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.bogdan.codeforceswatcher.util

import com.bogdan.codeforceswatcher.CwApp
import com.bogdan.codeforceswatcher.R
import com.bogdan.codeforceswatcher.model.RatingChangeResponse
import com.bogdan.codeforceswatcher.model.User
import com.bogdan.codeforceswatcher.model.UserResponse
Expand All @@ -17,6 +18,7 @@ object UserLoader {
override fun onResponse(call: Call<UserResponse>, response: Response<UserResponse>) {
if (response.body() == null) {
userLoaded(mutableListOf())
CwApp.app.showError(CwApp.app.getString(R.string.failed_to_fetch_users))
} else {
val userList = response.body()?.result
if (userList != null) {
Expand All @@ -34,9 +36,11 @@ object UserLoader {
})
}

private fun loadRatingUpdates(roomUserList: List<User>,
userList: List<User>,
userLoaded: (MutableList<Pair<String, Int>>) -> Unit) {
private fun loadRatingUpdates(
roomUserList: List<User>,
userList: List<User>,
userLoaded: (MutableList<Pair<String, Int>>) -> Unit
) {
val result: MutableList<Pair<String, Int>> = mutableListOf()
val countDownLatch = CountDownLatch(userList.size)

Expand All @@ -54,8 +58,10 @@ object UserLoader {
countDownLatch.countDown()
} else {
ratingCall.enqueue(object : Callback<RatingChangeResponse> {
override fun onResponse(call: Call<RatingChangeResponse>,
response: Response<RatingChangeResponse>) {
override fun onResponse(
call: Call<RatingChangeResponse>,
response: Response<RatingChangeResponse>
) {
if (response.isSuccessful) {
val ratingChanges = response.body()?.result
val ratingChange = ratingChanges?.lastOrNull()
Expand Down
2 changes: 2 additions & 0 deletions app/src/main/res/values-ru-rRU/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@
<string name="no_rating_update">Нет обновления рейтинга</string>
<string name="none">Нет</string>
<string name="no_internet_connection">Нет соединения с интернетом</string>
<string name="rating_changes">Изменения рейтинга</string>
<string name="ratings_have_been_updated">Рейтинги обновлены</string>
<string name="ratings_update">Обновление рейтинга</string>
<string name="user_already_added">Пользователь уже добавлен</string>
<string name="failed_to_fetch_users">Не получилось обновить пользователей! Проверьте хэндлы…</string>
</resources>
2 changes: 2 additions & 0 deletions app/src/main/res/values-uk-rUA/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@
<string name="no_rating_update">Немає оновлення рейтингу</string>
<string name="none">Немає</string>
<string name="no_internet_connection">Немає зв\'язку з Інтернетом</string>
<string name="rating_changes">Змiни рейтингу</string>
<string name="ratings_have_been_updated">Рейтинги оновлені</string>
<string name="ratings_update">Оновлення рейтингу</string>
<string name="user_already_added">Користувача вже додано</string>
<string name="failed_to_fetch_users">Не вдалося оновити користувачiв! Перевiрте хендли…</string>
</resources>
1 change: 1 addition & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,5 @@
<string name="ratings_have_been_updated">Ratings have been updated</string>
<string name="ratings_update">Rating updates</string>
<string name="user_already_added">User already added</string>
<string name="failed_to_fetch_users">Failed to fetch users! Check handles…</string>
</resources>

0 comments on commit 1e1cc80

Please sign in to comment.