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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix eternal loading progress #719 #697 #814

Open
wants to merge 6 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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 29 additions & 15 deletions app/src/main/java/io/plaidapp/ui/HomeActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,10 @@ import android.view.View
import android.view.ViewGroup
import android.view.ViewStub
import android.view.WindowInsets
import android.widget.Button
import android.widget.FrameLayout
import android.widget.ImageView
import android.widget.LinearLayout
import android.widget.ProgressBar
import android.widget.TextView
import android.widget.Toast
Expand Down Expand Up @@ -118,9 +120,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
noFiltersEmptyText(R.string.no_filters_selected, view)
}

private val noDataView by lazy {
val view = findViewById<ViewStub>(R.id.stub_no_data).inflate() as LinearLayout
view.apply { findViewById<Button>(R.id.retryButton).setOnClickListener { viewModel.loadData() } }
}

val emptyText = getText(R.string.no_filters_selected) as SpannedString
private fun HomeActivity.noFiltersEmptyText(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,11 +160,9 @@ class HomeActivity : AppCompatActivity() {
}
}

with(view) {
return with(view) {
text = ssb
setOnClickListener {
drawer.openDrawer(GravityCompat.END)
}
setOnClickListener { drawer.openDrawer(GravityCompat.END) }
view
}
}
Expand Down Expand Up @@ -293,6 +300,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 @@ -528,22 +539,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)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@QArtur99 Please consider creating extension function for view i.e fun View.visible() = visibility == View.VISIBLE and fun View.gone() = visibility == View.GONE this will be more readable.
Thanks

} 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) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@QArtur99 Please use default value for params. this will avoid setEmptyStateVisibility(View.GONE, View.GONE, View.GONE) it will become a simple call setEmptyStateVisibility() and as most of the params value is View.GONE we will not have to pass that again.
Thanks

loading.visibility = progressBar
noDataView.visibility = noData
noFiltersEmptyText.visibility = noFilter
}

@Suppress("DEPRECATION")
Expand Down Expand Up @@ -641,7 +655,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
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,14 @@
android:indeterminateTint="?android:colorAccent"
android:indeterminateTintMode="src_in" />

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

<ViewStub
android:id="@+id/stub_no_filters"
android:layout_width="wrap_content"
Expand Down
30 changes: 30 additions & 0 deletions app/src/main/res/layout/no_data.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/noDataContainer"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:elevation="1dp"
android:orientation="vertical">

<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:padding="@dimen/padding_normal"
android:text="@string/no_data"
android:textColor="@color/text_primary_light"
android:textSize="15sp"
tools:text="@string/no_data" />

<Button
android:id="@+id/retryButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:foreground="?attr/selectableItemBackground"
android:text="@string/retry"
android:textAllCaps="false"
android:textSize="15sp" />

</LinearLayout>
2 changes: 2 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,10 @@
<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">Error loading data</string>

<!--searchable label-->
<string name="search_hint">Search Dribbble &amp; Designer News</string>
<string name="retry">Retry</string>

</resources>
12 changes: 10 additions & 2 deletions core/src/main/java/io/plaidapp/core/ui/filter/FilterAdapter.kt
Original file line number Diff line number Diff line change
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
}
}
Original file line number Diff line number Diff line change
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

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ class LoadSearchDataUseCase(
deferredJobs.add(async { it.loadMore() })
}
}
if (_searchResult.value == null) _searchResult.postValue(emptyList())
deferredJobs.awaitAll()
}

Expand Down
2 changes: 2 additions & 0 deletions search/src/main/java/io/plaidapp/search/ui/SearchActivity.kt
Original file line number Diff line number Diff line change
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