-
Notifications
You must be signed in to change notification settings - Fork 3.2k
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
base: main
Are you sure you want to change the base?
Changes from all commits
06a902f
c4c98a2
ee407d7
900c4e6
46d2601
42aac8b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
|
@@ -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) | ||
|
||
|
@@ -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 | ||
} | ||
} | ||
|
@@ -293,6 +300,10 @@ class HomeActivity : AppCompatActivity() { | |
val uiModel = viewModel.feedProgress.value | ||
return uiModel?.isLoading ?: false | ||
} | ||
|
||
override fun onStopLoading() { | ||
checkEmptyState() | ||
} | ||
} | ||
|
||
val shotPreloadSizeProvider = ViewPreloadSizeProvider<Shot>() | ||
|
@@ -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) | ||
} 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) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @QArtur99 Please use default value for params. this will avoid |
||
loading.visibility = progressBar | ||
noDataView.visibility = noData | ||
noFiltersEmptyText.visibility = noFilter | ||
} | ||
|
||
@Suppress("DEPRECATION") | ||
|
@@ -641,7 +655,7 @@ class HomeActivity : AppCompatActivity() { | |
|
||
TransitionManager.beginDelayedTransition(drawer) | ||
noConnection.visibility = View.GONE | ||
loading.visibility = View.VISIBLE | ||
checkEmptyState() | ||
viewModel.loadData() | ||
} | ||
|
||
|
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> |
This file was deleted.
There was a problem hiding this comment.
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
andfun View.gone() = visibility == View.GONE
this will be more readable.Thanks