diff --git a/app/src/main/kotlin/at/connyduck/pixelcat/components/timeline/detail/DetailActivity.kt b/app/src/main/kotlin/at/connyduck/pixelcat/components/timeline/detail/DetailActivity.kt
index 46ca725..ed4a98f 100644
--- a/app/src/main/kotlin/at/connyduck/pixelcat/components/timeline/detail/DetailActivity.kt
+++ b/app/src/main/kotlin/at/connyduck/pixelcat/components/timeline/detail/DetailActivity.kt
@@ -9,6 +9,8 @@ import androidx.recyclerview.widget.ConcatAdapter
import at.connyduck.pixelcat.R
import at.connyduck.pixelcat.components.general.BaseActivity
import at.connyduck.pixelcat.components.timeline.TimeLineActionListener
+import at.connyduck.pixelcat.components.util.Error
+import at.connyduck.pixelcat.components.util.Loading
import at.connyduck.pixelcat.components.util.Success
import at.connyduck.pixelcat.components.util.extension.getDisplayWidthInPx
import at.connyduck.pixelcat.components.util.extension.hide
@@ -54,6 +56,10 @@ class DetailActivity: BaseActivity(), TimeLineActionListener {
viewModel.reload(false)
}
+ binding.detailStatus.setOnRetryListener {
+ viewModel.reload(true)
+ }
+
viewModel.setStatusId(intent.getStringExtra(EXTRA_STATUS_ID)!!)
val displayWidth = getDisplayWidthInPx()
@@ -64,11 +70,27 @@ class DetailActivity: BaseActivity(), TimeLineActionListener {
binding.detailRecyclerView.adapter = ConcatAdapter(statusAdapter, repliesAdapter)
viewModel.currentStatus.observe(this, Observer {
- if(it is Success) {
- binding.detailProgress.hide()
- binding.detailSwipeRefresh.isRefreshing = false
- binding.detailRecyclerView.show()
- statusAdapter.submitList(listOf(it.data))
+ when(it) {
+ is Success -> {
+ binding.detailSwipeRefresh.show()
+ binding.detailStatus.hide()
+ binding.detailProgress.hide()
+ binding.detailSwipeRefresh.isRefreshing = false
+ binding.detailRecyclerView.show()
+ statusAdapter.submitList(listOf(it.data))
+ }
+ is Loading -> {
+ binding.detailSwipeRefresh.hide()
+ binding.detailStatus.hide()
+ binding.detailProgress.show()
+ }
+ is Error -> {
+ binding.detailSwipeRefresh.hide()
+ binding.detailStatus.show()
+ binding.detailProgress.hide()
+ binding.detailStatus.setOnRetryListener { }
+ binding.detailStatus.showGeneralError()
+ }
}
})
diff --git a/app/src/main/kotlin/at/connyduck/pixelcat/components/view/StatusView.kt b/app/src/main/kotlin/at/connyduck/pixelcat/components/view/StatusView.kt
new file mode 100644
index 0000000..ed9d8ea
--- /dev/null
+++ b/app/src/main/kotlin/at/connyduck/pixelcat/components/view/StatusView.kt
@@ -0,0 +1,60 @@
+/*
+ * Copyright (C) 2020 Conny Duck
+ *
+ * This file is part of Pixelcat.
+ *
+ * Pixelcat is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * Pixelcat is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
+
+package at.connyduck.pixelcat.components.view
+
+import android.content.Context
+import android.util.AttributeSet
+import android.view.Gravity
+import android.view.LayoutInflater
+import android.view.View
+import android.widget.LinearLayout
+import at.connyduck.pixelcat.R
+import at.connyduck.pixelcat.components.util.extension.getColorForAttr
+import at.connyduck.pixelcat.databinding.ViewStatusBinding
+
+class StatusView @JvmOverloads constructor(
+ context: Context,
+ attrs: AttributeSet? = null,
+ defStyleAttr: Int = 0
+) : LinearLayout(context, attrs, defStyleAttr) {
+
+ val binding: ViewStatusBinding
+
+ init {
+ binding = ViewStatusBinding.inflate(LayoutInflater.from(context), this)
+ gravity = Gravity.CENTER
+ setBackgroundColor(context.getColorForAttr(R.attr.colorSurface))
+ orientation = VERTICAL
+ }
+
+ fun setOnRetryListener(listener: (View) -> Unit) {
+ binding.statusButton.setOnClickListener(listener)
+ }
+
+ fun showGeneralError() {
+ binding.statusMessage.setText(R.string.status_general_error)
+ binding.statusMessage.setCompoundDrawablesWithIntrinsicBounds(0, R.drawable.ic_alert_triangle, 0, 0)
+ }
+
+ fun showNetworkError() {
+ binding.statusMessage.setText(R.string.status_network_error)
+ binding.statusMessage.setCompoundDrawablesWithIntrinsicBounds(0, R.drawable.ic_wifi_off, 0, 0)
+ }
+}
\ No newline at end of file
diff --git a/app/src/main/res/drawable/ic_alert_triangle.xml b/app/src/main/res/drawable/ic_alert_triangle.xml
new file mode 100644
index 0000000..ac29b98
--- /dev/null
+++ b/app/src/main/res/drawable/ic_alert_triangle.xml
@@ -0,0 +1,14 @@
+
+
+
+
+
diff --git a/app/src/main/res/drawable/ic_wifi_off.xml b/app/src/main/res/drawable/ic_wifi_off.xml
new file mode 100644
index 0000000..720b3ae
--- /dev/null
+++ b/app/src/main/res/drawable/ic_wifi_off.xml
@@ -0,0 +1,30 @@
+
+
+
+
+
+
+
+
+
diff --git a/app/src/main/res/layout/activity_detail.xml b/app/src/main/res/layout/activity_detail.xml
index a61b003..138f0e8 100644
--- a/app/src/main/res/layout/activity_detail.xml
+++ b/app/src/main/res/layout/activity_detail.xml
@@ -1,46 +1,57 @@
+ xmlns:app="http://schemas.android.com/apk/res-auto"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent"
+ android:background="@drawable/pixelcat_gradient">
+ android:id="@+id/detailAppbar"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content">
+ android:id="@+id/detailToolbar"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ app:layout_scrollFlags="scroll|enterAlways"
+ app:navigationIcon="@drawable/ic_cat_small"
+ app:title="@string/app_name"
+ app:titleTextAppearance="@style/TextAppearanceToolbar"
+ app:titleTextColor="?attr/colorPrimary" />
+ android:id="@+id/detailSwipeRefresh"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent"
+ android:background="?android:attr/windowBackground"
+ app:layout_behavior="@string/appbar_scrolling_view_behavior">
+ android:id="@+id/detailRecyclerView"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent"
+ app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager" />
-
+
+
+
+
+
+
\ No newline at end of file
diff --git a/app/src/main/res/layout/view_status.xml b/app/src/main/res/layout/view_status.xml
new file mode 100644
index 0000000..a18a348
--- /dev/null
+++ b/app/src/main/res/layout/view_status.xml
@@ -0,0 +1,28 @@
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml
index c942c7a..ea0e978 100644
--- a/app/src/main/res/values/strings.xml
+++ b/app/src/main/res/values/strings.xml
@@ -76,4 +76,8 @@
Sensitive media
Pixelcat is free and open-source software. It is licensed under the GNU General Public License Version 3.
+ An unexpected error occurred
+ Failed to connect. Please check your internet connection-
+
+