feat: 优化代码

pull/97/head
kunfei 5 years ago
parent 382b2b1811
commit 4079f2c247
  1. 1
      app/src/main/AndroidManifest.xml
  2. 9
      app/src/main/java/io/legado/app/ui/widget/prefs/ColorPreference.kt
  3. 47
      app/src/main/java/io/legado/app/ui/widget/prefs/IconListPreference.kt
  4. 4
      app/src/main/java/io/legado/app/ui/widget/prefs/NameListPreference.kt
  5. 71
      app/src/main/res/drawable-v24/ic_launcher_1.xml
  6. 5
      app/src/main/res/mipmap-anydpi-v26/ic_launcher_1.xml
  7. 2
      app/src/main/res/xml/pref_config_read.xml
  8. 12
      app/src/main/res/xml/pref_config_theme.xml
  9. 2
      app/src/main/res/xml/pref_main.xml

@ -41,6 +41,7 @@
<!--图标1-->
<activity
android:name=".ui.welcome.Icon1Activity"
android:icon="@mipmap/ic_launcher_1"
android:enabled="false">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

@ -1,4 +1,4 @@
package io.legado.app.lib.theme.prefs
package io.legado.app.ui.widget.prefs
import android.content.Context
import android.content.ContextWrapper
@ -15,7 +15,7 @@ import androidx.preference.PreferenceViewHolder
import com.jaredrummler.android.colorpicker.*
import io.legado.app.lib.theme.ATH
class ATEColorPreference(context: Context, attrs: AttributeSet) : Preference(context, attrs),
class ColorPreference(context: Context, attrs: AttributeSet) : Preference(context, attrs),
ColorPickerDialogListener {
private val sizeNormal = 0
@ -86,7 +86,7 @@ class ATEColorPreference(context: Context, attrs: AttributeSet) : Preference(con
}
}
fun getActivity(): FragmentActivity {
private fun getActivity(): FragmentActivity {
val context = context
if (context is FragmentActivity) {
return context
@ -397,7 +397,8 @@ class ATEColorPreference(context: Context, attrs: AttributeSet) : Preference(con
* @see .show
*/
fun create(): ColorPickerDialog {
val dialog = ColorPickerDialogCompat()
val dialog =
ColorPickerDialogCompat()
val args = Bundle()
args.putInt(ARG_ID, dialogId)
args.putInt(ARG_TYPE, dialogType)

@ -0,0 +1,47 @@
package io.legado.app.ui.widget.prefs
import android.content.Context
import android.graphics.drawable.Drawable
import android.util.AttributeSet
import android.widget.ImageView
import androidx.preference.ListPreference
import androidx.preference.PreferenceViewHolder
import io.legado.app.R
class IconListPreference(context: Context, attrs: AttributeSet) : ListPreference(context, attrs) {
private val mEntryDrawables = arrayListOf<Drawable>()
init {
widgetLayoutResource = R.layout.view_icon
val a = context.theme.obtainStyledAttributes(attrs, R.styleable.IconListPreference, 0, 0)
val drawables: Array<CharSequence>
drawables = try {
a.getTextArray(R.styleable.IconListPreference_icons)
} finally {
a.recycle()
}
for (drawable in drawables) {
val resId = context.resources
.getIdentifier(drawable.toString(), "mipmap", context.packageName)
val d = context.resources.getDrawable(resId)
mEntryDrawables.add(d)
}
}
override fun onBindViewHolder(holder: PreferenceViewHolder?) {
super.onBindViewHolder(holder)
holder?.itemView?.findViewById<ImageView>(R.id.preview)?.let {
val selectedIndex = findIndexOfValue(value)
val drawable = mEntryDrawables[selectedIndex]
it.setImageDrawable(drawable)
}
}
}

@ -1,4 +1,4 @@
package io.legado.app.lib.theme.prefs
package io.legado.app.ui.widget.prefs
import android.content.Context
import android.util.AttributeSet
@ -8,7 +8,7 @@ import androidx.preference.PreferenceViewHolder
import io.legado.app.R
class ATEListPreference(context: Context, attrs: AttributeSet) : ListPreference(context, attrs) {
class NameListPreference(context: Context, attrs: AttributeSet) : ListPreference(context, attrs) {
init {
widgetLayoutResource = R.layout.item_text

@ -0,0 +1,71 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="108dp"
android:height="108dp"
android:viewportWidth="108"
android:viewportHeight="108">
<path
android:pathData="M33.17,64.5l0,-21l42,-0l0,21z"
android:strokeWidth="0.5"
android:fillColor="#fff"
android:strokeColor="#000" />
<path
android:pathData="M70.1,59.05a1.5,2 0,1 0,3 0a1.5,2 0,1 0,-3 0z"
android:fillColor="#ed1c24" />
<path
android:pathData="M29.17,66l0,-24l4,-0l0,24z"
android:strokeWidth="0.5"
android:fillColor="#fff"
android:strokeColor="#000" />
<path
android:pathData="M29.17,40l0,-3l4,-0l0,3z"
android:strokeWidth="0.5"
android:fillColor="#fff"
android:strokeColor="#000" />
<path
android:pathData="M30.17,42l0,-2l2,-0l0,2z"
android:strokeWidth="0.5"
android:fillColor="#fff"
android:strokeColor="#000" />
<path
android:pathData="M29.17,71l0,-3l4,-0l0,3z"
android:strokeWidth="0.5"
android:fillColor="#fff"
android:strokeColor="#000" />
<path
android:pathData="M30.17,68l0,-2l2,-0l0,2z"
android:strokeWidth="0.5"
android:fillColor="#fff"
android:strokeColor="#000" />
<path
android:pathData="M75.17,66l0,-24l4,-0l0,24z"
android:strokeWidth="0.5"
android:fillColor="#fff"
android:strokeColor="#000" />
<path
android:pathData="M75.17,40l0,-3l4,-0l0,3z"
android:strokeWidth="0.5"
android:fillColor="#fff"
android:strokeColor="#000" />
<path
android:pathData="M76.17,42l0,-2l2,-0l0,2z"
android:strokeWidth="0.5"
android:fillColor="#fff"
android:strokeColor="#000" />
<path
android:pathData="M75.17,71l0,-3l4,-0l0,3z"
android:strokeWidth="0.5"
android:fillColor="#fff"
android:strokeColor="#000" />
<path
android:pathData="M76.17,68l0,-2l2,-0l0,2z"
android:strokeWidth="0.5"
android:fillColor="#fff"
android:strokeColor="#000" />
<path
android:pathData="M43.28,50.3l-0.05,8.43a3.26,3.26 0,0 1,-0.88 1.8c-0.14,0 -0.24,0 -0.27,-0.11l0.05,-4 0.06,-5.69 -0.06,-1.58 1.26,0.43c0.11,0 0.13,0.11 0.06,0.22ZM48.48,54.57c0.07,0 0.07,0.09 0,0.16l-0.17,0.33L48,56.65c-0.07,0.29 0,0.45 0.22,0.49A2.93,2.93 0,0 0,49.35 57c0.26,0 0.46,-0.24 0.6,-0.71a0.15,0.15 0,0 1,0.11 0s0.06,0 0.06,0.11c-0.08,0.43 0,0.69 0.16,0.76 0.4,0.47 0.27,0.82 -0.38,1a3.77,3.77 0,0 1,-1.7 0.11c-0.65,-0.18 -1,-0.77 -0.93,-1.75l0.06,-1.37v-1h-1.1l0.77,0.33c0.07,0 0.07,0.09 0,0.16l-0.16,0.22a12.29,12.29 0,0 1,-3.5 4.37c-0.11,0 -0.13,0 -0.06,-0.11a12.28,12.28 0,0 0,2.63 -5h-0.44a2.06,2.06 0,0 1,-0.66 0.87c-0.18,0.11 -0.29,0.09 -0.33,-0.05l0.06,-1.53v-0.77q0,-0.27 -0.06,-0.87v-0.5s0,-0.05 0.11,-0.05l0.93,0.49 1.81,-0.05A10.57,10.57 0,0 0,48 49.27l1.2,0.38c0.07,0 0.07,0.11 0,0.22l-0.6,0.65 -1.09,1.21h0.87l0.49,-0.61 1.1,0.61c0.07,0 0.07,0 0,0.11l-0.28,0.43 0,1.64 0.11,0.17c0,0.07 0,0.11 -0.06,0.11L47.66,54.19ZM43.55,47.3a0.51,0.51 0,0 1,0.17 0.05c1.2,0.4 1.78,0.73 1.75,1s-0.17,0.63 -0.6,1c-0.26,0.1 -0.42,0 -0.49,-0.17a5,5 0,0 0,-0.93 -1.8C43.41,47.3 43.45,47.26 43.55,47.3ZM45.25,49.59c0.91,0.41 1.38,0.77 1.42,1.1a0.91,0.91 0,0 1,-0.55 0.76c-0.21,0 -0.34,0 -0.38,-0.22a2,2 0,0 0,-0.54 -1.53C45.16,49.59 45.18,49.56 45.25,49.59ZM45.47,52.05v1.86l3,0L48.47,52ZM48.09,48.94a11.7,11.7 0,0 0,-1.69 0.11L46,48.72l4.76,-0.17 0.6,-0.65 1,0.71h0s0,0.09 0,0.16l-0.38,0.61L52,54.84l0.11,3a2.72,2.72 0,0 1,-1.69 2.57,0.43 0.43,0 0,1 -0.17,0.06s0,-0.1 0,-0.17a1.53,1.53 0,0 0,-0.55 -1.15,0.16 0.16,0 0,1 0,-0.11 0,0 0,0 1,0 0c0.77,0 1.12,-0.15 1,-0.55l-0.05,-9.62Z"
android:fillColor="#002747" />
<path
android:pathData="M59.8,56.59c0.11,0 0.12,0 0.05,0.11l-1.91,2a14.53,14.53 0,0 0,-1 1c0,0.07 -0.09,0.07 -0.17,0l-0.82,-0.82c-0.11,-0.07 -0.12,-0.13 0,-0.16 0.51,-0.26 0.89,-0.44 1.15,-0.55L57,52 56,52a4.29,4.29 0,0 0,-1.09 0.11l-0.49,-0.44 2.35,-0.05 0.6,-0.71 1.09,0.65c0.08,0 0.08,0.09 0,0.17l-0.27,0.38 -0.38,5.58ZM56.08,47.59a3.72,3.72 0,0 1,1.86 1.15,1.21 1.21,0 0,1 -0.6,1.15c-0.26,0.11 -0.44,0.06 -0.55,-0.16a4,4 0,0 0,-0.82 -2C55.93,47.62 56,47.59 56.08,47.62ZM62.64,51.86 L64.12,52.35c0.11,0 0.12,0.13 0,0.28L63.9,53l-0.17,1.8a5.14,5.14 0,0 1,-0.16 0.88l2.24,-0.06 0.77,-0.87 1.09,1c0.07,0.08 0.06,0.11 0,0.11l-4.1,0.17q-0.39,3.16 -7.17,4.7c-0.11,0 -0.16,0 -0.16,0a0.17,0.17 0,0 1,0.11 -0.17c3.75,-1 5.78,-2.51 6.07,-4.48l-1.64,0.11a7.49,7.49 0,0 0,-1.26 0.11,1.12 1.12,0 0,1 -0.27,0l-0.33,-0.44 3.55,-0.11a3.5,3.5 0,0 0,0.11 -0.82l0.11,-1.09a10.52,10.52 0,0 0,0 -1.59ZM61.44,49.67a13.84,13.84 0,0 0,-1.42 0.17l-0.44,-0.44 2.68,0L62.26,49c0,-0.73 0,-1.29 -0.06,-1.69l1.48,0.38c0.07,0 0.11,0 0.11,0a0.17,0.17 0,0 1,-0.06 0.22,1.21 1.21,0 0,0 -0.21,0.82l-0.06,0.55 1.42,0 0.66,-0.66 0.87,0.77 0.06,0.1a0.15,0.15 0,0 1,-0.11 0.06l-2.9,0.11v1.64l2.19,-0.06 0.55,-0.6 1.31,1.15a0.18,0.18 0,0 1,0.11 0.17,0.63 0.63,0 0,1 -0.17,0.1 3.64,3.64 0,0 0,-2.07 0.88c-0.11,0 -0.15,0 -0.11,-0.11l0.38,-1.26 -4.54,0.11 -0.49,0.06c-0.59,0.07 -1,0.12 -1.15,0.16L59,51.45l3.23,-0.11L62.23,49.7ZM59.52,53.5c1.13,0.29 1.73,0.58 1.81,0.88a0.91,0.91 0,0 1,-0.33 0.87c-0.22,0.18 -0.38,0.15 -0.49,-0.11a5.37,5.37 0,0 0,-1 -1.47C59.4,53.59 59.41,53.53 59.52,53.53ZM60.34,52.02c1,0.22 1.5,0.44 1.54,0.66a1,1 0,0 1,-0.28 0.82c-0.22,0.15 -0.36,0.11 -0.44,-0.11a2.31,2.31 0,0 0,-0.82 -1.26C60.23,52.13 60.23,52.09 60.34,52.05ZM63.46,57.02a7.17,7.17 0,0 1,3.06 1.53q0.23,0.44 -0.27,1.26c-0.15,0.15 -0.26,0.22 -0.33,0.22s-0.16,-0.09 -0.27,-0.27a7.39,7.39 0,0 0,-2.24 -2.63S63.39,57.07 63.46,57Z"
android:fillColor="#002747" />
</vector>

@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android">
<background android:drawable="@drawable/ic_launcher_background" />
<foreground android:drawable="@drawable/ic_launcher_1" />
</adaptive-icon>

@ -2,7 +2,7 @@
<androidx.preference.PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<io.legado.app.lib.theme.prefs.ATEListPreference
<io.legado.app.ui.widget.prefs.NameListPreference
android:key="keep_light"
android:defaultValue="0"
android:entryValues="@array/screen_time_out_value"

@ -26,7 +26,7 @@
android:title="白天"
app:iconSpaceReserved="false">
<io.legado.app.lib.theme.prefs.ATEColorPreference
<io.legado.app.ui.widget.prefs.ColorPreference
android:defaultValue="@color/md_light_blue_600"
android:key="colorPrimary"
android:summary="白天,主色调"
@ -34,7 +34,7 @@
app:cpv_dialogType="preset"
app:iconSpaceReserved="false" />
<io.legado.app.lib.theme.prefs.ATEColorPreference
<io.legado.app.ui.widget.prefs.ColorPreference
android:defaultValue="@color/md_pink_800"
android:key="colorAccent"
android:summary="白天,强调色"
@ -42,7 +42,7 @@
app:cpv_dialogType="preset"
app:iconSpaceReserved="false" />
<io.legado.app.lib.theme.prefs.ATEColorPreference
<io.legado.app.ui.widget.prefs.ColorPreference
android:defaultValue="@color/md_grey_100"
android:key="colorBackground"
android:summary="白天,背景色"
@ -56,7 +56,7 @@
android:title="夜间"
app:iconSpaceReserved="false">
<io.legado.app.lib.theme.prefs.ATEColorPreference
<io.legado.app.ui.widget.prefs.ColorPreference
android:defaultValue="@color/md_grey_900"
android:key="colorPrimaryNight"
android:summary="夜间,主色调"
@ -64,7 +64,7 @@
app:cpv_dialogType="preset"
app:iconSpaceReserved="false" />
<io.legado.app.lib.theme.prefs.ATEColorPreference
<io.legado.app.ui.widget.prefs.ColorPreference
android:defaultValue="@color/md_deep_orange_800"
android:key="colorAccentNight"
android:summary="夜间,强调色"
@ -72,7 +72,7 @@
app:cpv_dialogType="preset"
app:iconSpaceReserved="false" />
<io.legado.app.lib.theme.prefs.ATEColorPreference
<io.legado.app.ui.widget.prefs.ColorPreference
android:defaultValue="@color/md_black_1000"
android:key="colorBackgroundNight"
android:summary="夜间,背景色"

@ -12,7 +12,7 @@
android:title="@string/replace_purify"
app:iconSpaceReserved="false" />
<io.legado.app.lib.theme.prefs.ATEListPreference
<io.legado.app.ui.widget.prefs.NameListPreference
android:defaultValue="0"
android:entries="@array/theme_mode"
android:entryValues="@array/theme_mode_v"

Loading…
Cancel
Save