Fix empty state for account media, fix tablets (#1018)
This commit is contained in:
parent
6b7ca5d184
commit
87364edd98
|
@ -15,7 +15,6 @@
|
||||||
|
|
||||||
package com.keylesspalace.tusky.fragment
|
package com.keylesspalace.tusky.fragment
|
||||||
|
|
||||||
import android.content.Context
|
|
||||||
import android.graphics.Color
|
import android.graphics.Color
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import android.util.Log
|
import android.util.Log
|
||||||
|
@ -35,7 +34,8 @@ import com.keylesspalace.tusky.entity.Attachment
|
||||||
import com.keylesspalace.tusky.entity.Status
|
import com.keylesspalace.tusky.entity.Status
|
||||||
import com.keylesspalace.tusky.network.MastodonApi
|
import com.keylesspalace.tusky.network.MastodonApi
|
||||||
import com.keylesspalace.tusky.util.ThemeUtils
|
import com.keylesspalace.tusky.util.ThemeUtils
|
||||||
import com.keylesspalace.tusky.util.visible
|
import com.keylesspalace.tusky.util.hide
|
||||||
|
import com.keylesspalace.tusky.util.show
|
||||||
import com.keylesspalace.tusky.view.SquareImageView
|
import com.keylesspalace.tusky.view.SquareImageView
|
||||||
import com.keylesspalace.tusky.viewdata.AttachmentViewData
|
import com.keylesspalace.tusky.viewdata.AttachmentViewData
|
||||||
import com.squareup.picasso.Picasso
|
import com.squareup.picasso.Picasso
|
||||||
|
@ -43,6 +43,7 @@ import kotlinx.android.synthetic.main.fragment_timeline.*
|
||||||
import retrofit2.Call
|
import retrofit2.Call
|
||||||
import retrofit2.Callback
|
import retrofit2.Callback
|
||||||
import retrofit2.Response
|
import retrofit2.Response
|
||||||
|
import java.io.IOException
|
||||||
import java.util.*
|
import java.util.*
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
|
|
||||||
|
@ -80,9 +81,19 @@ class AccountMediaFragment : BaseFragment(), Injectable {
|
||||||
private val callback = object : Callback<List<Status>> {
|
private val callback = object : Callback<List<Status>> {
|
||||||
override fun onFailure(call: Call<List<Status>>?, t: Throwable?) {
|
override fun onFailure(call: Call<List<Status>>?, t: Throwable?) {
|
||||||
fetchingStatus = FetchingStatus.NOT_FETCHING
|
fetchingStatus = FetchingStatus.NOT_FETCHING
|
||||||
if(isAdded) {
|
if (isAdded) {
|
||||||
swipe_refresh_layout.isRefreshing = false
|
swipe_refresh_layout.isRefreshing = false
|
||||||
progress_bar.visibility = View.GONE
|
progress_bar.visibility = View.GONE
|
||||||
|
statusView.show()
|
||||||
|
if (t is IOException) {
|
||||||
|
statusView.setup(R.drawable.elephant_offline, R.string.error_network) {
|
||||||
|
doInitialLoadingIfNeeded()
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
statusView.setup(R.drawable.elephant_error, R.string.error_generic) {
|
||||||
|
doInitialLoadingIfNeeded()
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Log.d(TAG, "Failed to fetch account media", t)
|
Log.d(TAG, "Failed to fetch account media", t)
|
||||||
|
@ -90,7 +101,7 @@ class AccountMediaFragment : BaseFragment(), Injectable {
|
||||||
|
|
||||||
override fun onResponse(call: Call<List<Status>>, response: Response<List<Status>>) {
|
override fun onResponse(call: Call<List<Status>>, response: Response<List<Status>>) {
|
||||||
fetchingStatus = FetchingStatus.NOT_FETCHING
|
fetchingStatus = FetchingStatus.NOT_FETCHING
|
||||||
if(isAdded) {
|
if (isAdded) {
|
||||||
swipe_refresh_layout.isRefreshing = false
|
swipe_refresh_layout.isRefreshing = false
|
||||||
progress_bar.visibility = View.GONE
|
progress_bar.visibility = View.GONE
|
||||||
|
|
||||||
|
@ -103,7 +114,11 @@ class AccountMediaFragment : BaseFragment(), Injectable {
|
||||||
result.addAll(AttachmentViewData.list(status))
|
result.addAll(AttachmentViewData.list(status))
|
||||||
}
|
}
|
||||||
adapter.addTop(result)
|
adapter.addTop(result)
|
||||||
nothing_message.visible(statuses.isEmpty())
|
if (statuses.isEmpty()) {
|
||||||
|
statusView.show()
|
||||||
|
statusView.setup(R.drawable.elephant_friend_empty, R.string.message_empty,
|
||||||
|
null)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -112,6 +127,7 @@ class AccountMediaFragment : BaseFragment(), Injectable {
|
||||||
private val bottomCallback = object : Callback<List<Status>> {
|
private val bottomCallback = object : Callback<List<Status>> {
|
||||||
override fun onFailure(call: Call<List<Status>>?, t: Throwable?) {
|
override fun onFailure(call: Call<List<Status>>?, t: Throwable?) {
|
||||||
fetchingStatus = FetchingStatus.NOT_FETCHING
|
fetchingStatus = FetchingStatus.NOT_FETCHING
|
||||||
|
|
||||||
Log.d(TAG, "Failed to fetch account media", t)
|
Log.d(TAG, "Failed to fetch account media", t)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -156,6 +172,7 @@ class AccountMediaFragment : BaseFragment(), Injectable {
|
||||||
val accountId = arguments?.getString(ACCOUNT_ID_ARG)
|
val accountId = arguments?.getString(ACCOUNT_ID_ARG)
|
||||||
|
|
||||||
swipe_refresh_layout.setOnRefreshListener {
|
swipe_refresh_layout.setOnRefreshListener {
|
||||||
|
statusView.hide()
|
||||||
if (fetchingStatus != FetchingStatus.NOT_FETCHING) return@setOnRefreshListener
|
if (fetchingStatus != FetchingStatus.NOT_FETCHING) return@setOnRefreshListener
|
||||||
currentCall = if (statuses.isEmpty()) {
|
currentCall = if (statuses.isEmpty()) {
|
||||||
fetchingStatus = FetchingStatus.INITIAL_FETCHING
|
fetchingStatus = FetchingStatus.INITIAL_FETCHING
|
||||||
|
@ -170,7 +187,7 @@ class AccountMediaFragment : BaseFragment(), Injectable {
|
||||||
swipe_refresh_layout.setColorSchemeResources(R.color.tusky_blue)
|
swipe_refresh_layout.setColorSchemeResources(R.color.tusky_blue)
|
||||||
swipe_refresh_layout.setProgressBackgroundColorSchemeColor(ThemeUtils.getColor(context, android.R.attr.colorBackground))
|
swipe_refresh_layout.setProgressBackgroundColorSchemeColor(ThemeUtils.getColor(context, android.R.attr.colorBackground))
|
||||||
|
|
||||||
nothing_message.visibility = View.GONE
|
statusView.visibility = View.GONE
|
||||||
|
|
||||||
recycler_view.addOnScrollListener(object : RecyclerView.OnScrollListener() {
|
recycler_view.addOnScrollListener(object : RecyclerView.OnScrollListener() {
|
||||||
|
|
||||||
|
@ -202,6 +219,9 @@ class AccountMediaFragment : BaseFragment(), Injectable {
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun doInitialLoadingIfNeeded() {
|
private fun doInitialLoadingIfNeeded() {
|
||||||
|
if (isAdded) {
|
||||||
|
statusView.hide()
|
||||||
|
}
|
||||||
val accountId = arguments?.getString(ACCOUNT_ID_ARG)
|
val accountId = arguments?.getString(ACCOUNT_ID_ARG)
|
||||||
if (fetchingStatus == FetchingStatus.NOT_FETCHING && statuses.isEmpty()) {
|
if (fetchingStatus == FetchingStatus.NOT_FETCHING && statuses.isEmpty()) {
|
||||||
fetchingStatus = FetchingStatus.INITIAL_FETCHING
|
fetchingStatus = FetchingStatus.INITIAL_FETCHING
|
||||||
|
@ -239,7 +259,7 @@ class AccountMediaFragment : BaseFragment(), Injectable {
|
||||||
NOT_FETCHING, INITIAL_FETCHING, FETCHING_BOTTOM, REFRESHING
|
NOT_FETCHING, INITIAL_FETCHING, FETCHING_BOTTOM, REFRESHING
|
||||||
}
|
}
|
||||||
|
|
||||||
inner class MediaGridAdapter:
|
inner class MediaGridAdapter :
|
||||||
RecyclerView.Adapter<MediaGridAdapter.MediaViewHolder>() {
|
RecyclerView.Adapter<MediaGridAdapter.MediaViewHolder>() {
|
||||||
|
|
||||||
var baseItemColor = Color.BLACK
|
var baseItemColor = Color.BLACK
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
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:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
android:background="?attr/tab_page_margin_drawable">
|
android:background="?attr/tab_page_margin_drawable">
|
||||||
|
@ -32,17 +33,18 @@
|
||||||
app:layout_constraintRight_toRightOf="parent"
|
app:layout_constraintRight_toRightOf="parent"
|
||||||
app:layout_constraintTop_toTopOf="parent" />
|
app:layout_constraintTop_toTopOf="parent" />
|
||||||
|
|
||||||
<TextView
|
|
||||||
android:id="@+id/nothing_message"
|
<com.keylesspalace.tusky.view.BackgroundMessageView
|
||||||
|
android:id="@+id/statusView"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:drawablePadding="32dp"
|
android:src="@android:color/transparent"
|
||||||
android:text="@string/footer_empty"
|
android:visibility="gone"
|
||||||
android:textAlignment="center"
|
|
||||||
android:textSize="?attr/status_text_medium"
|
|
||||||
app:layout_constraintBottom_toBottomOf="parent"
|
app:layout_constraintBottom_toBottomOf="parent"
|
||||||
app:layout_constraintLeft_toLeftOf="parent"
|
app:layout_constraintLeft_toLeftOf="parent"
|
||||||
app:layout_constraintRight_toRightOf="parent"
|
app:layout_constraintRight_toRightOf="parent"
|
||||||
app:layout_constraintTop_toTopOf="parent" />
|
app:layout_constraintTop_toTopOf="parent"
|
||||||
|
tools:src="@drawable/elephant_error"
|
||||||
|
tools:visibility="visible" />
|
||||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||||
</FrameLayout>
|
</FrameLayout>
|
Loading…
Reference in a new issue