error handling in FiltersActivity (#1180)
This commit is contained in:
parent
dd02af9911
commit
4facdc9b68
2 changed files with 55 additions and 9 deletions
|
@ -2,6 +2,7 @@ package com.keylesspalace.tusky
|
||||||
|
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import android.view.MenuItem
|
import android.view.MenuItem
|
||||||
|
import android.view.View
|
||||||
import android.widget.AdapterView
|
import android.widget.AdapterView
|
||||||
import android.widget.ArrayAdapter
|
import android.widget.ArrayAdapter
|
||||||
import android.widget.Toast
|
import android.widget.Toast
|
||||||
|
@ -10,6 +11,8 @@ import com.keylesspalace.tusky.appstore.EventHub
|
||||||
import com.keylesspalace.tusky.appstore.PreferenceChangedEvent
|
import com.keylesspalace.tusky.appstore.PreferenceChangedEvent
|
||||||
import com.keylesspalace.tusky.entity.Filter
|
import com.keylesspalace.tusky.entity.Filter
|
||||||
import com.keylesspalace.tusky.network.MastodonApi
|
import com.keylesspalace.tusky.network.MastodonApi
|
||||||
|
import com.keylesspalace.tusky.util.hide
|
||||||
|
import com.keylesspalace.tusky.util.show
|
||||||
import kotlinx.android.synthetic.main.activity_filters.*
|
import kotlinx.android.synthetic.main.activity_filters.*
|
||||||
import kotlinx.android.synthetic.main.dialog_filter.*
|
import kotlinx.android.synthetic.main.dialog_filter.*
|
||||||
import kotlinx.android.synthetic.main.toolbar_basic.*
|
import kotlinx.android.synthetic.main.toolbar_basic.*
|
||||||
|
@ -17,6 +20,7 @@ import okhttp3.ResponseBody
|
||||||
import retrofit2.Call
|
import retrofit2.Call
|
||||||
import retrofit2.Callback
|
import retrofit2.Callback
|
||||||
import retrofit2.Response
|
import retrofit2.Response
|
||||||
|
import java.io.IOException
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
|
|
||||||
class FiltersActivity: BaseActivity() {
|
class FiltersActivity: BaseActivity() {
|
||||||
|
@ -132,24 +136,55 @@ class FiltersActivity: BaseActivity() {
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun loadFilters() {
|
private fun loadFilters() {
|
||||||
|
|
||||||
|
filterMessageView.hide()
|
||||||
|
filtersView.hide()
|
||||||
|
addFilterButton.hide()
|
||||||
|
filterProgressBar.show()
|
||||||
|
|
||||||
api.filters.enqueue(object : Callback<List<Filter>> {
|
api.filters.enqueue(object : Callback<List<Filter>> {
|
||||||
override fun onResponse(call: Call<List<Filter>>, response: Response<List<Filter>>) {
|
override fun onResponse(call: Call<List<Filter>>, response: Response<List<Filter>>) {
|
||||||
filters = response.body()!!.filter { filter -> filter.context.contains(context) }.toMutableList()
|
val filterResponse = response.body()
|
||||||
refreshFilterDisplay()
|
if(response.isSuccessful && filterResponse != null) {
|
||||||
|
|
||||||
|
filters = filterResponse.filter { filter -> filter.context.contains(context) }.toMutableList()
|
||||||
|
refreshFilterDisplay()
|
||||||
|
|
||||||
|
filtersView.show()
|
||||||
|
addFilterButton.show()
|
||||||
|
filterProgressBar.hide()
|
||||||
|
} else {
|
||||||
|
filterProgressBar.hide()
|
||||||
|
filterMessageView.show()
|
||||||
|
filterMessageView.setup(R.drawable.elephant_error,
|
||||||
|
R.string.error_generic, this@FiltersActivity::reload)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onFailure(call: Call<List<Filter>>, t: Throwable) {
|
override fun onFailure(call: Call<List<Filter>>, t: Throwable) {
|
||||||
// Anything?
|
filterProgressBar.hide()
|
||||||
|
filterMessageView.show()
|
||||||
|
if (t is IOException) {
|
||||||
|
filterMessageView.setup(R.drawable.elephant_offline,
|
||||||
|
R.string.error_network, this@FiltersActivity::reload)
|
||||||
|
} else {
|
||||||
|
filterMessageView.setup(R.drawable.elephant_error,
|
||||||
|
R.string.error_generic, this@FiltersActivity::reload)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun reload(v: View) {
|
||||||
|
loadFilters()
|
||||||
|
}
|
||||||
|
|
||||||
override fun onCreate(savedInstanceState: Bundle?) {
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
super.onCreate(savedInstanceState)
|
super.onCreate(savedInstanceState)
|
||||||
|
|
||||||
setContentView(R.layout.activity_filters)
|
setContentView(R.layout.activity_filters)
|
||||||
setupToolbarBackArrow()
|
setupToolbarBackArrow()
|
||||||
filter_floating_add.setOnClickListener {
|
addFilterButton.setOnClickListener {
|
||||||
showAddFilterDialog()
|
showAddFilterDialog()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<androidx.coordinatorlayout.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
<androidx.coordinatorlayout.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
xmlns:tools="http://schemas.android.com/tools"
|
|
||||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||||
|
xmlns:tools="http://schemas.android.com/tools"
|
||||||
android:id="@+id/activityFilters"
|
android:id="@+id/activityFilters"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
|
@ -15,16 +15,27 @@
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
app:layout_behavior="@string/appbar_scrolling_view_behavior" />
|
app:layout_behavior="@string/appbar_scrolling_view_behavior" />
|
||||||
|
|
||||||
|
<com.keylesspalace.tusky.view.BackgroundMessageView
|
||||||
|
android:id="@+id/filterMessageView"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_gravity="center" />
|
||||||
|
|
||||||
|
<ProgressBar
|
||||||
|
android:id="@+id/filterProgressBar"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_gravity="center" />
|
||||||
|
|
||||||
<com.google.android.material.floatingactionbutton.FloatingActionButton
|
<com.google.android.material.floatingactionbutton.FloatingActionButton
|
||||||
android:id="@+id/filter_floating_add"
|
android:id="@+id/addFilterButton"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_margin="16dp"
|
android:layout_margin="16dp"
|
||||||
android:contentDescription="@string/filter_addition_dialog_title"
|
android:contentDescription="@string/filter_addition_dialog_title"
|
||||||
app:layout_anchor="@id/filtersView"
|
|
||||||
app:layout_anchorGravity="bottom|end"
|
|
||||||
android:src="@drawable/ic_plus_24dp"
|
android:src="@drawable/ic_plus_24dp"
|
||||||
/>
|
app:layout_anchor="@id/filtersView"
|
||||||
|
app:layout_anchorGravity="bottom|end" />
|
||||||
|
|
||||||
|
|
||||||
</androidx.coordinatorlayout.widget.CoordinatorLayout>
|
</androidx.coordinatorlayout.widget.CoordinatorLayout>
|
Loading…
Reference in a new issue