From 06a902f30c0f117563ac93b8c55652d68fbb49c3 Mon Sep 17 00:00:00 2001 From: ART_F Date: Sat, 22 Jun 2019 17:03:45 +0200 Subject: [PATCH 1/5] Fix eternal loading progress #719 --- .../main/java/io/plaidapp/ui/HomeActivity.kt | 38 +++++++++++++------ app/src/main/res/layout/activity_home.xml | 8 ++++ app/src/main/res/values/strings.xml | 1 + .../plaidapp/core/ui/filter/FilterAdapter.kt | 12 +++++- .../ui/recyclerview/InfiniteScrollListener.kt | 6 ++- .../io/plaidapp/search/ui/SearchActivity.kt | 2 + 6 files changed, 52 insertions(+), 15 deletions(-) diff --git a/app/src/main/java/io/plaidapp/ui/HomeActivity.kt b/app/src/main/java/io/plaidapp/ui/HomeActivity.kt index b4da3dfa5..56ba824a2 100644 --- a/app/src/main/java/io/plaidapp/ui/HomeActivity.kt +++ b/app/src/main/java/io/plaidapp/ui/HomeActivity.kt @@ -118,9 +118,16 @@ class HomeActivity : AppCompatActivity() { private val noFiltersEmptyText by lazy { val view = findViewById(R.id.stub_no_filters).inflate() as TextView - // create the no filters empty text + noDataEmptyText(R.string.no_filters_selected, view) + } + + private val noDataEmptyText by lazy { + val view = findViewById(R.id.stub_no_data).inflate() as TextView + noDataEmptyText(R.string.no_data, view) + } - val emptyText = getText(R.string.no_filters_selected) as SpannedString + private fun HomeActivity.noDataEmptyText(stringId: Int, view: TextView): TextView { + val emptyText = getText(stringId) as SpannedString val ssb = SpannableStringBuilder(emptyText) val annotations = emptyText.getSpans(0, emptyText.length, Annotation::class.java) @@ -151,7 +158,7 @@ class HomeActivity : AppCompatActivity() { } } - with(view) { + return with(view) { text = ssb setOnClickListener { drawer.openDrawer(GravityCompat.END) @@ -292,6 +299,10 @@ class HomeActivity : AppCompatActivity() { val uiModel = viewModel.feedProgress.value return uiModel?.isLoading ?: false } + + override fun onStopLoading() { + checkEmptyState() + } } val shotPreloadSizeProvider = ViewPreloadSizeProvider() @@ -523,22 +534,25 @@ class HomeActivity : AppCompatActivity() { // if grid is empty check whether we're loading or if no filters are selected if (sourcesRepository.getActiveSourcesCount() > 0 && connectivityChecker != null) { connectivityChecker?.connectedStatus?.value?.let { - loading.visibility = View.VISIBLE - setNoFiltersEmptyTextVisibility(View.GONE) + if (filtersAdapter.getEnabledFilterCount() > 0) { + setEmptyStateVisibility(View.GONE, View.VISIBLE, View.GONE) + } else { + setEmptyStateVisibility(View.VISIBLE, View.GONE, View.GONE) + } } } else { - loading.visibility = View.GONE - setNoFiltersEmptyTextVisibility(View.VISIBLE) + setEmptyStateVisibility(View.GONE, View.GONE, View.VISIBLE) } toolbar.translationZ = 0f } else { - loading.visibility = View.GONE - setNoFiltersEmptyTextVisibility(View.GONE) + setEmptyStateVisibility(View.GONE, View.GONE, View.GONE) } } - private fun setNoFiltersEmptyTextVisibility(visibility: Int) { - noFiltersEmptyText.visibility = visibility + private fun setEmptyStateVisibility(progressBar: Int, noData: Int, noFilter: Int) { + loading.visibility = progressBar + noDataEmptyText.visibility = noData + noFiltersEmptyText.visibility = noFilter } @Suppress("DEPRECATION") @@ -636,7 +650,7 @@ class HomeActivity : AppCompatActivity() { TransitionManager.beginDelayedTransition(drawer) noConnection.visibility = View.GONE - loading.visibility = View.VISIBLE + checkEmptyState() viewModel.loadData() } diff --git a/app/src/main/res/layout/activity_home.xml b/app/src/main/res/layout/activity_home.xml index 64401dc83..62c8ab471 100644 --- a/app/src/main/res/layout/activity_home.xml +++ b/app/src/main/res/layout/activity_home.xml @@ -61,6 +61,14 @@ android:indeterminateTint="?android:colorAccent" android:indeterminateTintMode="src_in" /> + + Add Edit No filters selected, press the filter button above ()\nor swipe from the right + No data, problem with server, press the filter button above ()\nor swipe from the right Search Dribbble & Designer News diff --git a/core/src/main/java/io/plaidapp/core/ui/filter/FilterAdapter.kt b/core/src/main/java/io/plaidapp/core/ui/filter/FilterAdapter.kt index b0273d83f..147d05f7b 100644 --- a/core/src/main/java/io/plaidapp/core/ui/filter/FilterAdapter.kt +++ b/core/src/main/java/io/plaidapp/core/ui/filter/FilterAdapter.kt @@ -65,8 +65,8 @@ class FilterAdapter : ListAdapter(sourceUiModel override fun onCreateViewHolder(viewGroup: ViewGroup, viewType: Int): FilterViewHolder { val holder = FilterViewHolder( - LayoutInflater.from(viewGroup.context) - .inflate(R.layout.filter_item, viewGroup, false) + LayoutInflater.from(viewGroup.context) + .inflate(R.layout.filter_item, viewGroup, false) ) holder.itemView.setOnClickListener { val position = holder.adapterPosition @@ -109,4 +109,12 @@ class FilterAdapter : ListAdapter(sourceUiModel val uiModel = getItem(position) uiModel.onSourceDismissed(uiModel) } + + fun getEnabledFilterCount(): Int { + var count = 0 + currentList.map { + if (it.active) count = count.inc() + } + return count + } } diff --git a/core/src/main/java/io/plaidapp/core/ui/recyclerview/InfiniteScrollListener.kt b/core/src/main/java/io/plaidapp/core/ui/recyclerview/InfiniteScrollListener.kt index d3ca05875..ec84e292f 100644 --- a/core/src/main/java/io/plaidapp/core/ui/recyclerview/InfiniteScrollListener.kt +++ b/core/src/main/java/io/plaidapp/core/ui/recyclerview/InfiniteScrollListener.kt @@ -37,13 +37,17 @@ abstract class InfiniteScrollListener( val totalItemCount = layoutManager.itemCount val firstVisibleItem = layoutManager.findFirstVisibleItemPosition() - if (totalItemCount - visibleItemCount <= firstVisibleItem + VISIBLE_THRESHOLD) { + if (totalItemCount - visibleItemCount <= firstVisibleItem + VISIBLE_THRESHOLD && totalItemCount > 0) { recyclerView.post(loadMoreRunnable) + } else { + onStopLoading() } } abstract fun onLoadMore() + abstract fun onStopLoading() + abstract fun isDataLoading(): Boolean companion object { diff --git a/search/src/main/java/io/plaidapp/search/ui/SearchActivity.kt b/search/src/main/java/io/plaidapp/search/ui/SearchActivity.kt index 71d43af6d..60f1ed759 100644 --- a/search/src/main/java/io/plaidapp/search/ui/SearchActivity.kt +++ b/search/src/main/java/io/plaidapp/search/ui/SearchActivity.kt @@ -169,6 +169,8 @@ class SearchActivity : AppCompatActivity() { override fun isDataLoading(): Boolean { return viewModel.searchProgress.value?.isLoading ?: false } + + override fun onStopLoading() {} }) setHasFixedSize(true) From c4c98a2da1193ec9ed7ca4f64b5eecc2844a9114 Mon Sep 17 00:00:00 2001 From: ART_F Date: Sun, 23 Jun 2019 17:28:47 +0200 Subject: [PATCH 2/5] Fix eternal loading progress in Search #697 --- .../main/java/io/plaidapp/search/domain/LoadSearchDataUseCase.kt | 1 + 1 file changed, 1 insertion(+) diff --git a/search/src/main/java/io/plaidapp/search/domain/LoadSearchDataUseCase.kt b/search/src/main/java/io/plaidapp/search/domain/LoadSearchDataUseCase.kt index 0ca49c491..7f5bbb65b 100644 --- a/search/src/main/java/io/plaidapp/search/domain/LoadSearchDataUseCase.kt +++ b/search/src/main/java/io/plaidapp/search/domain/LoadSearchDataUseCase.kt @@ -57,6 +57,7 @@ class LoadSearchDataUseCase( }) } } + if (_searchResult.value == null) _searchResult.postValue(emptyList()) deferredJobs.awaitAll() } } From ee407d7e1d89b343f30264d58cf9d92ebdff038d Mon Sep 17 00:00:00 2001 From: ART_F Date: Mon, 30 Dec 2019 21:57:49 +0100 Subject: [PATCH 3/5] Refactor: text & CTA shown if there is an error --- .../main/java/io/plaidapp/ui/HomeActivity.kt | 18 +++++------ app/src/main/res/layout/activity_home.xml | 4 +-- app/src/main/res/layout/no_data.xml | 30 +++++++++++++++++++ app/src/main/res/values/strings.xml | 3 +- 4 files changed, 43 insertions(+), 12 deletions(-) create mode 100644 app/src/main/res/layout/no_data.xml diff --git a/app/src/main/java/io/plaidapp/ui/HomeActivity.kt b/app/src/main/java/io/plaidapp/ui/HomeActivity.kt index 56ba824a2..b8600dc55 100644 --- a/app/src/main/java/io/plaidapp/ui/HomeActivity.kt +++ b/app/src/main/java/io/plaidapp/ui/HomeActivity.kt @@ -38,9 +38,11 @@ import android.view.View import android.view.ViewGroup import android.view.ViewStub import android.view.WindowInsets +import android.widget.Button import android.widget.CheckBox import android.widget.FrameLayout import android.widget.ImageView +import android.widget.LinearLayout import android.widget.ProgressBar import android.widget.TextView import android.widget.Toast @@ -118,15 +120,15 @@ class HomeActivity : AppCompatActivity() { private val noFiltersEmptyText by lazy { val view = findViewById(R.id.stub_no_filters).inflate() as TextView - noDataEmptyText(R.string.no_filters_selected, view) + noFiltersEmptyText(R.string.no_filters_selected, view) } - private val noDataEmptyText by lazy { - val view = findViewById(R.id.stub_no_data).inflate() as TextView - noDataEmptyText(R.string.no_data, view) + private val noDataView by lazy { + val view = findViewById(R.id.stub_no_data).inflate() as LinearLayout + view.apply { findViewById