From 7d9edf1b33fe30b6ad7fc34d48bb38bd4cd9b78f Mon Sep 17 00:00:00 2001 From: Konrad Pozniak Date: Thu, 25 Jul 2019 12:17:52 +0200 Subject: [PATCH] fix crash in FiltersActivity (#1409) --- .../java/com/keylesspalace/tusky/FiltersActivity.kt | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/com/keylesspalace/tusky/FiltersActivity.kt b/app/src/main/java/com/keylesspalace/tusky/FiltersActivity.kt index a030e657..02186b07 100644 --- a/app/src/main/java/com/keylesspalace/tusky/FiltersActivity.kt +++ b/app/src/main/java/com/keylesspalace/tusky/FiltersActivity.kt @@ -85,9 +85,14 @@ class FiltersActivity: BaseActivity() { private fun createFilter(phrase: String, wholeWord: Boolean) { api.createFilter(phrase, listOf(context), false, wholeWord, "").enqueue(object: Callback { override fun onResponse(call: Call, response: Response) { - filters.add(response.body()!!) - refreshFilterDisplay() - eventHub.dispatch(PreferenceChangedEvent(context)) + val filterResponse = response.body() + if(response.isSuccessful && filterResponse != null) { + filters.add(filterResponse) + refreshFilterDisplay() + eventHub.dispatch(PreferenceChangedEvent(context)) + } else { + Toast.makeText(this@FiltersActivity, "Error creating filter '$phrase'", Toast.LENGTH_SHORT).show() + } } override fun onFailure(call: Call, t: Throwable) {