From cfb43c34ac40e739a33826b9fde7315f2f43499d Mon Sep 17 00:00:00 2001 From: Ivan Kupalov Date: Thu, 31 Jan 2019 18:31:15 +0100 Subject: [PATCH] Fix empty state for account media, fix tablets (#1018) --- .../tusky/fragment/AccountMediaFragment.kt | 34 +++++++++++++++---- .../res/layout-sw640dp/fragment_timeline.xml | 16 +++++---- 2 files changed, 36 insertions(+), 14 deletions(-) diff --git a/app/src/main/java/com/keylesspalace/tusky/fragment/AccountMediaFragment.kt b/app/src/main/java/com/keylesspalace/tusky/fragment/AccountMediaFragment.kt index 37028e9f..10625853 100644 --- a/app/src/main/java/com/keylesspalace/tusky/fragment/AccountMediaFragment.kt +++ b/app/src/main/java/com/keylesspalace/tusky/fragment/AccountMediaFragment.kt @@ -15,7 +15,6 @@ package com.keylesspalace.tusky.fragment -import android.content.Context import android.graphics.Color import android.os.Bundle import android.util.Log @@ -35,7 +34,8 @@ import com.keylesspalace.tusky.entity.Attachment import com.keylesspalace.tusky.entity.Status import com.keylesspalace.tusky.network.MastodonApi 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.viewdata.AttachmentViewData import com.squareup.picasso.Picasso @@ -43,6 +43,7 @@ import kotlinx.android.synthetic.main.fragment_timeline.* import retrofit2.Call import retrofit2.Callback import retrofit2.Response +import java.io.IOException import java.util.* import javax.inject.Inject @@ -80,9 +81,19 @@ class AccountMediaFragment : BaseFragment(), Injectable { private val callback = object : Callback> { override fun onFailure(call: Call>?, t: Throwable?) { fetchingStatus = FetchingStatus.NOT_FETCHING - if(isAdded) { + if (isAdded) { swipe_refresh_layout.isRefreshing = false 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) @@ -90,7 +101,7 @@ class AccountMediaFragment : BaseFragment(), Injectable { override fun onResponse(call: Call>, response: Response>) { fetchingStatus = FetchingStatus.NOT_FETCHING - if(isAdded) { + if (isAdded) { swipe_refresh_layout.isRefreshing = false progress_bar.visibility = View.GONE @@ -103,7 +114,11 @@ class AccountMediaFragment : BaseFragment(), Injectable { result.addAll(AttachmentViewData.list(status)) } 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> { override fun onFailure(call: Call>?, t: Throwable?) { fetchingStatus = FetchingStatus.NOT_FETCHING + Log.d(TAG, "Failed to fetch account media", t) } @@ -156,6 +172,7 @@ class AccountMediaFragment : BaseFragment(), Injectable { val accountId = arguments?.getString(ACCOUNT_ID_ARG) swipe_refresh_layout.setOnRefreshListener { + statusView.hide() if (fetchingStatus != FetchingStatus.NOT_FETCHING) return@setOnRefreshListener currentCall = if (statuses.isEmpty()) { fetchingStatus = FetchingStatus.INITIAL_FETCHING @@ -170,7 +187,7 @@ class AccountMediaFragment : BaseFragment(), Injectable { swipe_refresh_layout.setColorSchemeResources(R.color.tusky_blue) 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() { @@ -202,6 +219,9 @@ class AccountMediaFragment : BaseFragment(), Injectable { } private fun doInitialLoadingIfNeeded() { + if (isAdded) { + statusView.hide() + } val accountId = arguments?.getString(ACCOUNT_ID_ARG) if (fetchingStatus == FetchingStatus.NOT_FETCHING && statuses.isEmpty()) { fetchingStatus = FetchingStatus.INITIAL_FETCHING @@ -239,7 +259,7 @@ class AccountMediaFragment : BaseFragment(), Injectable { NOT_FETCHING, INITIAL_FETCHING, FETCHING_BOTTOM, REFRESHING } - inner class MediaGridAdapter: + inner class MediaGridAdapter : RecyclerView.Adapter() { var baseItemColor = Color.BLACK diff --git a/app/src/main/res/layout-sw640dp/fragment_timeline.xml b/app/src/main/res/layout-sw640dp/fragment_timeline.xml index 43b82f3a..ef5743af 100644 --- a/app/src/main/res/layout-sw640dp/fragment_timeline.xml +++ b/app/src/main/res/layout-sw640dp/fragment_timeline.xml @@ -1,6 +1,7 @@ @@ -32,17 +33,18 @@ app:layout_constraintRight_toRightOf="parent" app:layout_constraintTop_toTopOf="parent" /> - + app:layout_constraintTop_toTopOf="parent" + tools:src="@drawable/elephant_error" + tools:visibility="visible" /> \ No newline at end of file