Skip to content

Commit

Permalink
chat: handle null exception (fixes #2510) (#2511)
Browse files Browse the repository at this point in the history
Co-authored-by: dogi <[email protected]>
  • Loading branch information
Okuro3499 and dogi authored Sep 19, 2023
1 parent e26b096 commit 957fafd
Show file tree
Hide file tree
Showing 8 changed files with 27 additions and 14 deletions.
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ android {
applicationId "org.ole.planet.myplanet"
minSdkVersion 21
targetSdkVersion 34
versionCode 1044
versionName "0.10.44"
versionCode 1045
versionName "0.10.45"
ndkVersion '21.3.6528147'
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
vectorDrawables.useSupportLibrary = true
Expand Down
31 changes: 19 additions & 12 deletions app/src/main/java/org/ole/planet/myplanet/ui/chat/ChatActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import okhttp3.MediaType
import okhttp3.RequestBody
import org.ole.planet.myplanet.R
import org.ole.planet.myplanet.databinding.ActivityChatBinding
import org.ole.planet.myplanet.datamanager.ApiClient
import org.ole.planet.myplanet.datamanager.ApiInterface
Expand Down Expand Up @@ -102,23 +103,29 @@ class ChatActivity : AppCompatActivity() {
call.enqueue(object : Callback<ChatModel> {
override fun onResponse(call: Call<ChatModel>, response: Response<ChatModel>) {
val responseBody = response.body()
if (responseBody != null && responseBody.status == "Success") {
val chatModel = response.body()
val history: ArrayList<History> = chatModel?.history ?: ArrayList()

val lastItem = history.lastOrNull()
if (lastItem != null) {
if (lastItem.response != null) {
val responseBody = lastItem.response
val chatResponse = response.body()?.chat
if (chatResponse != null) {
mAdapter.addResponse(chatResponse)
if (responseBody != null) {
if (responseBody.status == "Success") {
val chatModel = response.body()
val history: ArrayList<History> = chatModel?.history ?: ArrayList()

val lastItem = history.lastOrNull()
if (lastItem != null) {
if (lastItem.response != null) {
val responseBody = lastItem.response
val chatResponse = response.body()?.chat
if (chatResponse != null) {
mAdapter.addResponse(chatResponse)
}
}
}
} else {
activityChatBinding.textGchatIndicator.visibility = View.VISIBLE
activityChatBinding.textGchatIndicator.text = "${response.body()!!.message}"
}
} else {
activityChatBinding.textGchatIndicator.visibility = View.VISIBLE
activityChatBinding.textGchatIndicator.text = "${response.body()!!.message}"
activityChatBinding.textGchatIndicator.text =
getString(R.string.request_failed_please_retry)
}

activityChatBinding.buttonGchatSend.isEnabled = true
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values-ar/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -941,5 +941,6 @@
<string name="kindly_give_a_rating">يرجى التقييم</string>
<string name="must_start_with_letter_or_number">يجب أن تبدأ بحرف أو رقم</string>
<string name="only_letters_numbers_and_are_allowed">يُسمح فقط بالحروف والأرقام و "_" و "." و "-"</string>
<string name="request_failed_please_retry">الطلب فشل، يرجى إعادة المحاولة</string>

</resources>
1 change: 1 addition & 0 deletions app/src/main/res/values-es/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -946,5 +946,6 @@
<string name="kindly_give_a_rating">Por favor, dé una calificación</string>
<string name="must_start_with_letter_or_number">Debe comenzar con una letra o número</string>
<string name="only_letters_numbers_and_are_allowed">Solo se permiten letras, números, "_" , ".", y "-"</string>
<string name="request_failed_please_retry">La solicitud ha fallado, por favor inténtelo de nuevo</string>

</resources>
1 change: 1 addition & 0 deletions app/src/main/res/values-fr/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -946,5 +946,6 @@
<string name="kindly_give_a_rating">Veuillez donner une note</string>
<string name="must_start_with_letter_or_number">Doit commencer par une lettre ou un chiffre</string>
<string name="only_letters_numbers_and_are_allowed">Seules les lettres, les chiffres, "_" , ".", et "-" sont autorisés</string>
<string name="request_failed_please_retry">La demande a échoué, veuillez réessayer</string>

</resources>
1 change: 1 addition & 0 deletions app/src/main/res/values-ne/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -946,5 +946,6 @@
<string name="kindly_give_a_rating">कृपया मूल्याङ्कन दिनुहोस्</string>
<string name="must_start_with_letter_or_number">पात्र वा नम्बरसँग सुरु गर्नु पर्दछ</string>
<string name="only_letters_numbers_and_are_allowed">केवल अक्षर, नम्बर, "_" , ".", र "-" पाएको छ</string>
<string name="request_failed_please_retry">अनुरोध असफल भयो, कृपया पुन: प्रयास गर्नुहोस्</string>

</resources>
1 change: 1 addition & 0 deletions app/src/main/res/values-so/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -935,5 +935,6 @@
<string name="kindly_give_a_rating">si naxariis leh u bixi rating</string>
<string name="must_start_with_letter_or_number">Waa in la bilaabo lambarka ama tirada</string>
<string name="only_letters_numbers_and_are_allowed">Waxaad ka ogolaan kartaa lambarka, tirada, "_", ".", iyo "-"</string>
<string name="request_failed_please_retry">Codka lama yimaado, fadlan dib ugu ciyaar</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 @@ -1036,5 +1036,6 @@
<string name="must_start_with_letter_or_number">Must start with letter or number</string>
<string name="only_letters_numbers_and_are_allowed">Only letters, numbers and "_" , ".", "-" are allowed</string>
<string name="config_not_available" translatable="false">Config not available.</string>
<string name="request_failed_please_retry">Request failed, please retry</string>

</resources>

0 comments on commit 957fafd

Please sign in to comment.