Преглед изворни кода

Specified image placeholder color for dark theme

Vadik Sirekanyan пре 7 година
родитељ
комит
09de91d66a

+ 2 - 2
app/src/main/java/me/vadik/knigopis/adapters/BooksAdapter.kt

@@ -102,14 +102,14 @@ class BooksAdapter(
                         .load(coverUrl)
                         .apply(
                             RequestOptions.centerCropTransform()
-                                .placeholder(R.color.image_placeholder_color)
+                                .placeholder(R.drawable.rectangle_placeholder_background)
                         )
                         .transition(DrawableTransitionOptions.withCrossFade())
                         .into(this)
                 }, {
                     logError("cannot load thumbnail", it)
                     Glide.with(context)
-                        .load(R.color.image_placeholder_color)
+                        .load(R.drawable.rectangle_placeholder_background)
                         .transition(DrawableTransitionOptions.withCrossFade())
                         .into(this)
                 })

+ 1 - 1
app/src/main/res/drawable/oval_placeholder_background.xml

@@ -1,5 +1,5 @@
 <?xml version="1.0" encoding="utf-8"?>
 <shape xmlns:android="http://schemas.android.com/apk/res/android"
     android:shape="oval">
-    <solid android:color="@color/image_placeholder_color" />
+    <solid android:color="?attr/image_placeholder_color" />
 </shape>

+ 5 - 0
app/src/main/res/drawable/rectangle_placeholder_background.xml

@@ -0,0 +1,5 @@
+<?xml version="1.0" encoding="utf-8"?>
+<shape xmlns:android="http://schemas.android.com/apk/res/android"
+    android:shape="rectangle">
+    <solid android:color="?attr/image_placeholder_color" />
+</shape>

+ 1 - 1
app/src/main/res/layout/book.xml

@@ -23,7 +23,7 @@
         android:layout_height="40dp"
         android:layout_gravity="center_vertical"
         android:layout_marginStart="16dp"
-        android:background="@color/image_placeholder_color"
+        android:background="@drawable/rectangle_placeholder_background"
         tools:ignore="ContentDescription" />
 
     <LinearLayout

+ 1 - 1
app/src/main/res/layout/note.xml

@@ -9,7 +9,7 @@
     <ImageView
         android:layout_width="40dp"
         android:layout_height="40dp"
-        android:background="@color/image_placeholder_color"
+        android:background="@drawable/rectangle_placeholder_background"
         tools:ignore="ContentDescription" />
 
     <LinearLayout

+ 1 - 1
app/src/main/res/layout/user_book.xml

@@ -11,7 +11,7 @@
         android:layout_width="40dp"
         android:layout_height="40dp"
         android:layout_marginStart="16dp"
-        android:background="@color/image_placeholder_color"
+        android:background="@drawable/rectangle_placeholder_background"
         tools:ignore="ContentDescription" />
 
     <LinearLayout

+ 4 - 0
app/src/main/res/values/attrs.xml

@@ -0,0 +1,4 @@
+<?xml version="1.0" encoding="utf-8"?>
+<resources>
+    <attr name="image_placeholder_color" format="reference|color" />
+</resources>

+ 2 - 1
app/src/main/res/values/colors.xml

@@ -14,6 +14,7 @@
     <color name="black_20">#33000000</color>
     <color name="black_54">#8A000000</color>
     <color name="black_87">#DE000000</color>
-    <color name="image_placeholder_color">@color/colorPrimary50</color>
+    <color name="image_placeholder_color_light">@color/colorPrimary50</color>
+    <color name="image_placeholder_color_dark">@color/colorPrimaryLight</color>
     <color name="ic_launcher_background">#512DA8</color>
 </resources>

+ 2 - 0
app/src/main/res/values/styles.xml

@@ -6,6 +6,7 @@
         <item name="colorAccent">@color/colorAccent</item>
         <item name="android:windowBackground">@color/colorPrimary</item>
         <item name="android:listDivider">@drawable/recycler_view_divider</item>
+        <item name="image_placeholder_color">@color/image_placeholder_color_light</item>
     </style>
 
     <style name="DarkAppTheme" parent="Theme.AppCompat.NoActionBar">
@@ -14,6 +15,7 @@
         <item name="colorAccent">@color/colorAccent</item>
         <item name="android:windowBackground">@color/colorPrimary</item>
         <item name="android:listDivider">@drawable/recycler_view_divider</item>
+        <item name="image_placeholder_color">@color/image_placeholder_color_dark</item>
     </style>
 
     <style name="DevTheme" parent="AppTheme">