Browse Source

Add logo header in more section

arkon 5 years ago
parent
commit
90ce89193d

+ 20 - 1
app/src/main/java/eu/kanade/tachiyomi/ui/more/MoreController.kt

@@ -1,14 +1,19 @@
 package eu.kanade.tachiyomi.ui.more
 
+import android.content.Context
+import android.util.AttributeSet
+import androidx.preference.Preference
 import androidx.preference.PreferenceScreen
 import eu.kanade.tachiyomi.R
 import eu.kanade.tachiyomi.data.preference.PreferenceKeys as Keys
+import eu.kanade.tachiyomi.ui.base.controller.NoToolbarElevationController
 import eu.kanade.tachiyomi.ui.base.controller.RootController
 import eu.kanade.tachiyomi.ui.base.controller.withFadeTransaction
 import eu.kanade.tachiyomi.ui.download.DownloadController
 import eu.kanade.tachiyomi.ui.migration.MigrationController
 import eu.kanade.tachiyomi.ui.setting.SettingsController
 import eu.kanade.tachiyomi.ui.setting.SettingsMainController
+import eu.kanade.tachiyomi.util.preference.add
 import eu.kanade.tachiyomi.util.preference.iconRes
 import eu.kanade.tachiyomi.util.preference.iconTint
 import eu.kanade.tachiyomi.util.preference.onClick
@@ -21,13 +26,18 @@ import eu.kanade.tachiyomi.util.system.getResourceColor
 import eu.kanade.tachiyomi.util.system.openInBrowser
 import uy.kohesive.injekt.api.get
 
-class MoreController : SettingsController(), RootController {
+class MoreController :
+    SettingsController(),
+    RootController,
+    NoToolbarElevationController {
 
     override fun setupPreferenceScreen(screen: PreferenceScreen) = with(screen) {
         titleRes = R.string.label_more
 
         val tintColor = context.getResourceColor(R.attr.colorAccent)
 
+        add(MoreHeaderPreference(context))
+
         switchPreference {
             key = Keys.downloadedOnly
             titleRes = R.string.label_downloaded_only
@@ -83,6 +93,15 @@ class MoreController : SettingsController(), RootController {
         }
     }
 
+    private class MoreHeaderPreference @JvmOverloads constructor(context: Context, attrs: AttributeSet? = null) :
+        Preference(context, attrs) {
+
+        init {
+            layoutResource = R.layout.pref_more_header
+            isSelectable = false
+        }
+    }
+
     companion object {
         private const val URL_HELP = "https://tachiyomi.org/help/"
     }

+ 7 - 0
app/src/main/java/eu/kanade/tachiyomi/util/preference/PreferenceDSL.kt

@@ -72,6 +72,13 @@ fun initDialog(dialogPreference: DialogPreference) {
     }
 }
 
+inline fun <P : Preference> PreferenceGroup.add(p: P): P {
+    return p.apply {
+        this.isIconSpaceReserved = false
+        addPreference(this)
+    }
+}
+
 inline fun <P : Preference> PreferenceGroup.initThenAdd(p: P, block: P.() -> Unit): P {
     return p.apply {
         block()

+ 17 - 0
app/src/main/res/layout/pref_more_header.xml

@@ -0,0 +1,17 @@
+<?xml version="1.0" encoding="utf-8"?>
+<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
+    xmlns:app="http://schemas.android.com/apk/res-auto"
+    android:layout_width="match_parent"
+    android:layout_height="wrap_content"
+    android:background="?attr/colorPrimary"
+    android:elevation="2dp"
+    android:padding="48dp">
+
+    <ImageView
+        android:layout_width="72dp"
+        android:layout_height="72dp"
+        android:layout_gravity="center"
+        app:srcCompat="@drawable/ic_tachi"
+        app:tint="?attr/colorOnPrimary" />
+
+</FrameLayout>