Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix eternal loading progress #719 #697 #738

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
38 changes: 26 additions & 12 deletions app/src/main/java/io/plaidapp/ui/HomeActivity.kt
Expand Up @@ -118,9 +118,16 @@ class HomeActivity : AppCompatActivity() {

private val noFiltersEmptyText by lazy {
val view = findViewById<ViewStub>(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<ViewStub>(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)

Expand Down Expand Up @@ -151,7 +158,7 @@ class HomeActivity : AppCompatActivity() {
}
}

with(view) {
return with(view) {
text = ssb
setOnClickListener {
drawer.openDrawer(GravityCompat.END)
Expand Down Expand Up @@ -292,6 +299,10 @@ class HomeActivity : AppCompatActivity() {
val uiModel = viewModel.feedProgress.value
return uiModel?.isLoading ?: false
}

override fun onStopLoading() {
checkEmptyState()
}
}

val shotPreloadSizeProvider = ViewPreloadSizeProvider<Shot>()
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -636,7 +650,7 @@ class HomeActivity : AppCompatActivity() {

TransitionManager.beginDelayedTransition(drawer)
noConnection.visibility = View.GONE
loading.visibility = View.VISIBLE
checkEmptyState()
viewModel.loadData()
}

Expand Down
8 changes: 8 additions & 0 deletions app/src/main/res/layout/activity_home.xml
Expand Up @@ -61,6 +61,14 @@
android:indeterminateTint="?android:colorAccent"
android:indeterminateTintMode="src_in" />

<ViewStub
android:id="@+id/stub_no_data"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_margin="@dimen/spacing_huge"
android:layout="@layout/no_filters" />

<ViewStub
android:id="@+id/stub_no_filters"
android:layout_width="wrap_content"
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values/strings.xml
Expand Up @@ -35,6 +35,7 @@
<string name="add">Add</string>
<string name="edit">Edit</string>
<string name="no_filters_selected">No filters selected, press the filter button above (<annotation src="@drawable/ic_filter_small">&#2228;</annotation>)\n<i><annotation foregroundColor="@color/text_secondary_light">or swipe from the&#160;right</annotation></i></string>
<string name="no_data">No data, problem with server, press the filter button above (<annotation src="@drawable/ic_filter_small">&#2228;</annotation>)\n<i><annotation foregroundColor="@color/text_secondary_light">or swipe from the&#160;right</annotation></i></string>

<!--searchable label-->
<string name="search_hint">Search Dribbble &amp; Designer News</string>
Expand Down
12 changes: 10 additions & 2 deletions core/src/main/java/io/plaidapp/core/ui/filter/FilterAdapter.kt
Expand Up @@ -65,8 +65,8 @@ class FilterAdapter : ListAdapter<SourceUiModel, FilterViewHolder>(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
Expand Down Expand Up @@ -109,4 +109,12 @@ class FilterAdapter : ListAdapter<SourceUiModel, FilterViewHolder>(sourceUiModel
val uiModel = getItem(position)
uiModel.onSourceDismissed(uiModel)
}

fun getEnabledFilterCount(): Int {
var count = 0
currentList.map {
if (it.active) count = count.inc()
}
return count
}
}
Expand Up @@ -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 {
Expand Down
Expand Up @@ -57,6 +57,7 @@ class LoadSearchDataUseCase(
})
}
}
if (_searchResult.value == null) _searchResult.postValue(emptyList())
deferredJobs.awaitAll()
}
}
2 changes: 2 additions & 0 deletions search/src/main/java/io/plaidapp/search/ui/SearchActivity.kt
Expand Up @@ -169,6 +169,8 @@ class SearchActivity : AppCompatActivity() {
override fun isDataLoading(): Boolean {
return viewModel.searchProgress.value?.isLoading ?: false
}

override fun onStopLoading() {}
})
setHasFixedSize(true)

Expand Down