diff --git a/app/build.gradle b/app/build.gradle index d1cc99e..72d2980 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -106,6 +106,9 @@ dependencies { implementation "com.google.dagger:hilt-android:2.44.2" kapt "com.google.dagger:hilt-compiler:2.44.2" + // Shimmer + implementation 'com.facebook.shimmer:shimmer:0.5.0' + // Test testImplementation 'junit:junit:4.13.2' androidTestImplementation 'androidx.test.ext:junit:1.1.5' diff --git a/app/src/main/java/com/talent/animescrap/ui/fragments/AnimeFragment.kt b/app/src/main/java/com/talent/animescrap/ui/fragments/AnimeFragment.kt index 8c0d5ae..d6a4a99 100644 --- a/app/src/main/java/com/talent/animescrap/ui/fragments/AnimeFragment.kt +++ b/app/src/main/java/com/talent/animescrap/ui/fragments/AnimeFragment.kt @@ -22,6 +22,8 @@ import androidx.navigation.fragment.findNavController import androidx.navigation.fragment.navArgs import androidx.preference.PreferenceManager import coil.load +import com.facebook.shimmer.Shimmer +import com.facebook.shimmer.ShimmerDrawable import com.google.android.material.bottomsheet.BottomSheetBehavior import com.google.android.material.bottomsheet.BottomSheetDialog import com.talent.animescrap.R @@ -58,6 +60,14 @@ class AnimeFragment : Fragment() { private lateinit var epList: MutableList private lateinit var epType: String private lateinit var epIndex: String + private val shimmer = + Shimmer.AlphaHighlightBuilder()// The attributes for a ShimmerDrawable is set by this builder + .setDuration(1200) // how long the shimmering animation takes to do one full sweep + .setBaseAlpha(0.6f) //the alpha of the underlying children + .setHighlightAlpha(0.9f) // the shimmer alpha amount + .setDirection(Shimmer.Direction.LEFT_TO_RIGHT) + .setAutoStart(true) + .build() override fun onCreateView( inflater: LayoutInflater, container: ViewGroup?, @@ -129,10 +139,16 @@ class AnimeFragment : Fragment() { // load background image. binding.backgroundImage.load(animeDetails.animeCover) { + placeholder(ShimmerDrawable().apply { + setShimmer(shimmer) + }) error(R.drawable.ic_broken_image) } // load cover image. binding.coverAnime.load(animeDetails.animeCover) { + placeholder(ShimmerDrawable().apply { + setShimmer(shimmer) + }) error(R.drawable.ic_broken_image) } binding.errorCard?.visibility = View.GONE diff --git a/app/src/main/java/com/talent/animescrap/viewbindings/Bindings.kt b/app/src/main/java/com/talent/animescrap/viewbindings/Bindings.kt index c20ec23..d3aab2b 100644 --- a/app/src/main/java/com/talent/animescrap/viewbindings/Bindings.kt +++ b/app/src/main/java/com/talent/animescrap/viewbindings/Bindings.kt @@ -5,22 +5,27 @@ import android.widget.ImageView import android.widget.ProgressBar import androidx.databinding.BindingAdapter import coil.load +import com.facebook.shimmer.Shimmer +import com.facebook.shimmer.ShimmerDrawable import com.talent.animescrap.R - +private val shimmer = + Shimmer.AlphaHighlightBuilder()// The attributes for a ShimmerDrawable is set by this builder + .setDuration(1200) // how long the shimmering animation takes to do one full sweep + .setBaseAlpha(0.6f) //the alpha of the underlying children + .setHighlightAlpha(0.9f) // the shimmer alpha amount + .setDirection(Shimmer.Direction.LEFT_TO_RIGHT) + .setAutoStart(true) + .build() /* A function that is called when the `image` attribute is used in the layout. */ -@BindingAdapter("image", "loaderId") -fun ImageView.setImage(url: String?, progressBar: ProgressBar) { +@BindingAdapter("image") +fun ImageView.setImage(url: String?) { if (!url.isNullOrEmpty()) load(url) { + placeholder(ShimmerDrawable().apply { + setShimmer(shimmer) + }) error(R.drawable.ic_broken_image) - listener( - onSuccess = { _, _ -> - progressBar.visibility = View.GONE - }, onError = { _, _ -> - progressBar.visibility = View.GONE - } - ) build() } } \ No newline at end of file diff --git a/app/src/main/res/layout-land-television/fragment_anime.xml b/app/src/main/res/layout-land-television/fragment_anime.xml index 133aa8a..41ce3f9 100644 --- a/app/src/main/res/layout-land-television/fragment_anime.xml +++ b/app/src/main/res/layout-land-television/fragment_anime.xml @@ -30,6 +30,7 @@ android:layout_height="300dp" android:adjustViewBounds="true" android:scaleType="centerCrop" + android:background="@color/shimmerColor" tools:ignore="ContentDescription" /> diff --git a/app/src/main/res/layout-land/fragment_anime.xml b/app/src/main/res/layout-land/fragment_anime.xml index 46ae002..367c7bb 100644 --- a/app/src/main/res/layout-land/fragment_anime.xml +++ b/app/src/main/res/layout-land/fragment_anime.xml @@ -30,6 +30,7 @@ android:layout_height="60dp" android:adjustViewBounds="true" android:scaleType="centerCrop" + android:background="@color/shimmerColor" tools:ignore="ContentDescription" /> diff --git a/app/src/main/res/layout-land/portrait_cover_cardview_item.xml b/app/src/main/res/layout-land/portrait_cover_cardview_item.xml index c536f5a..7ec418d 100644 --- a/app/src/main/res/layout-land/portrait_cover_cardview_item.xml +++ b/app/src/main/res/layout-land/portrait_cover_cardview_item.xml @@ -46,21 +46,12 @@ - - diff --git a/app/src/main/res/layout/fragment_anime.xml b/app/src/main/res/layout/fragment_anime.xml index 32059a3..739202a 100644 --- a/app/src/main/res/layout/fragment_anime.xml +++ b/app/src/main/res/layout/fragment_anime.xml @@ -29,6 +29,7 @@ android:layout_width="match_parent" android:layout_height="180dp" android:adjustViewBounds="true" + android:background="@color/shimmerColor" android:scaleType="centerCrop" tools:ignore="ContentDescription" /> @@ -55,7 +56,7 @@ android:id="@+id/coverAnime" android:layout_width="match_parent" android:layout_height="match_parent" - android:background="@color/white" + android:background="@color/shimmerColor" android:contentDescription="@string/cover_of_anime" android:scaleType="centerCrop" android:transitionName="pageImageT" /> diff --git a/app/src/main/res/layout/landscape_cover_cardview_item.xml b/app/src/main/res/layout/landscape_cover_cardview_item.xml index 8a11571..dab6367 100644 --- a/app/src/main/res/layout/landscape_cover_cardview_item.xml +++ b/app/src/main/res/layout/landscape_cover_cardview_item.xml @@ -46,21 +46,12 @@ - - diff --git a/app/src/main/res/layout/portrait_cover_cardview_item.xml b/app/src/main/res/layout/portrait_cover_cardview_item.xml index b285b4d..a06ff21 100644 --- a/app/src/main/res/layout/portrait_cover_cardview_item.xml +++ b/app/src/main/res/layout/portrait_cover_cardview_item.xml @@ -46,20 +46,12 @@ - diff --git a/app/src/main/res/values-night/colors.xml b/app/src/main/res/values-night/colors.xml new file mode 100644 index 0000000..0c9b00b --- /dev/null +++ b/app/src/main/res/values-night/colors.xml @@ -0,0 +1,4 @@ + + + #5C5050 + \ No newline at end of file diff --git a/app/src/main/res/values/colors.xml b/app/src/main/res/values/colors.xml index 568580e..06b9be4 100644 --- a/app/src/main/res/values/colors.xml +++ b/app/src/main/res/values/colors.xml @@ -8,6 +8,7 @@ #FF000000 #FFFFFFFF #FFFFFFFF + #FFFFFFFF