Skip to content

Commit

Permalink
3rdlibrary: add shimmer loading on get products #34
Browse files Browse the repository at this point in the history
  • Loading branch information
reskimulud committed Aug 20, 2022
1 parent 2512767 commit 2c54f80
Show file tree
Hide file tree
Showing 6 changed files with 158 additions and 1 deletion.
3 changes: 2 additions & 1 deletion .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions commonui/src/main/res/values/themes.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
<color name="colorTextSecondary">#636363</color>
<color name="colorPrimaryVariant">#1C1C1C</color>

<!-- Soft grey -->
<color name="colorSoftGrey">#888888</color>

<style name="Theme.Eshop" parent="Theme.MaterialComponents.DayNight.NoActionBar">
<!-- Primary brand color. -->
<item name="colorPrimary">@color/colorPrimary</item>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ class ProductsFragment: Fragment() {
val categoryId = it.first
val search = it.second

isShowProgressBar(true)
if (categoryId.isNotEmpty() || search.isNotEmpty()) {
Timber.d("collect - categoryId: $categoryId")
if (categoryId.isNotEmpty() || categoryId != "all") {
Expand All @@ -181,6 +182,7 @@ class ProductsFragment: Fragment() {
productViewModel.getProducts(categoryId, search).collect {
Timber.d("Products: $it")
listProductAdapter.submitData(it)
isShowProgressBar(false)
}
}
}
Expand All @@ -196,14 +198,28 @@ class ProductsFragment: Fragment() {
findNavController().navigate(request)
}

isShowProgressBar(true)
getProducts()

binding.rvProducts.adapter = listProductAdapter
}

override fun onResume() {
super.onResume()
isShowProgressBar(true)
}

override fun onDestroyView() {
super.onDestroyView()
_binding = null
listProductAdapter.submitData(lifecycle, PagingData.empty())
}

private fun isShowProgressBar(state: Boolean) {
if (state) {
binding.progressBar.visibility = View.VISIBLE
} else {
binding.progressBar.visibility = View.GONE
}
}
}
55 changes: 55 additions & 0 deletions product/src/main/res/layout/fragment_products.xml
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,61 @@

</androidx.recyclerview.widget.RecyclerView>

<com.facebook.shimmer.ShimmerFrameLayout
android:id="@+id/progress_bar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:visibility="gone"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/tv_products"
app:shimmer_auto_start="true">

<GridLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:columnCount="2">

<include
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_gravity="fill"
android:layout_rowWeight="1"
android:layout_columnWeight="1"
android:layout_margin="8dp"
layout="@layout/item_product_placeholder" />

<include
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_gravity="fill"
android:layout_rowWeight="1"
android:layout_columnWeight="1"
android:layout_margin="8dp"
layout="@layout/item_product_placeholder" />

<include
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_gravity="fill"
android:layout_rowWeight="1"
android:layout_columnWeight="1"
android:layout_margin="8dp"
layout="@layout/item_product_placeholder" />
<include
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_gravity="fill"
android:layout_rowWeight="1"
android:layout_columnWeight="1"
android:layout_margin="8dp"
layout="@layout/item_product_placeholder" />


</GridLayout>

</com.facebook.shimmer.ShimmerFrameLayout>

</androidx.constraintlayout.widget.ConstraintLayout>

</androidx.core.widget.NestedScrollView>
Expand Down
81 changes: 81 additions & 0 deletions product/src/main/res/layout/item_product_placeholder.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools">

<com.google.android.material.card.MaterialCardView
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">

<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent">

<View
android:id="@+id/iv_image"
android:layout_width="0dp"
android:layout_height="120dp"
android:layout_marginStart="16dp"
android:layout_marginTop="16dp"
android:layout_marginEnd="16dp"
android:background="@color/colorSoftGrey"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />

<View
android:id="@+id/tv_title"
android:layout_width="0dp"
android:layout_height="12dp"
android:layout_marginStart="16dp"
android:layout_marginTop="16dp"
android:layout_marginEnd="16dp"
android:background="@color/colorTextSecondary"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/iv_image" />

<View
android:id="@+id/tv_price"
android:layout_width="50dp"
android:layout_height="12dp"
android:layout_marginStart="16dp"
android:layout_marginTop="8dp"
android:layout_marginBottom="16dp"
android:background="@color/colorTextSecondary"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/tv_title" />

<View
android:id="@+id/tv_rating"
android:layout_width="32dp"
android:layout_height="12dp"
android:background="@color/colorTextSecondary"
app:layout_constraintBottom_toBottomOf="@+id/rb_rating"
app:layout_constraintEnd_toStartOf="@+id/rb_rating"
app:layout_constraintTop_toTopOf="@+id/rb_rating" />

<RatingBar
android:id="@+id/rb_rating"
style="?android:attr/ratingBarStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="16dp"
android:numStars="1"
android:progressTint="@color/colorTextSecondary"
app:layout_constraintBottom_toBottomOf="@+id/tv_price"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="@+id/tv_price"
tools:rating="1" />

</androidx.constraintlayout.widget.ConstraintLayout>

</com.google.android.material.card.MaterialCardView>

</androidx.constraintlayout.widget.ConstraintLayout>
1 change: 1 addition & 0 deletions ui_dependencies.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,5 @@ dependencies {
// other 3rd-party library
implementation 'com.github.bumptech.glide:glide:4.13.1'
implementation "com.airbnb.android:lottie:5.2.0"
implementation "com.facebook.shimmer:shimmer:0.5.0"
}

0 comments on commit 2c54f80

Please sign in to comment.