|
|
@ -1,33 +1,17 @@ |
|
|
|
package io.legado.app.ui.widget.prefs |
|
|
|
package io.legado.app.ui.widget.prefs |
|
|
|
|
|
|
|
|
|
|
|
import android.content.Context |
|
|
|
import android.content.Context |
|
|
|
import android.content.ContextWrapper |
|
|
|
|
|
|
|
import android.content.res.TypedArray |
|
|
|
|
|
|
|
import android.graphics.Color |
|
|
|
|
|
|
|
import android.graphics.drawable.Drawable |
|
|
|
import android.graphics.drawable.Drawable |
|
|
|
import android.media.Image |
|
|
|
|
|
|
|
import android.os.Bundle |
|
|
|
|
|
|
|
import android.util.AttributeSet |
|
|
|
import android.util.AttributeSet |
|
|
|
import android.view.LayoutInflater |
|
|
|
import android.view.LayoutInflater |
|
|
|
import android.view.View |
|
|
|
import android.view.View |
|
|
|
import android.view.ViewGroup |
|
|
|
|
|
|
|
import android.widget.FrameLayout |
|
|
|
import android.widget.FrameLayout |
|
|
|
import android.widget.ImageView |
|
|
|
import android.widget.ImageView |
|
|
|
import android.widget.TextView |
|
|
|
import android.widget.TextView |
|
|
|
import androidx.annotation.ColorInt |
|
|
|
|
|
|
|
import androidx.annotation.StringRes |
|
|
|
|
|
|
|
import androidx.appcompat.app.AlertDialog |
|
|
|
|
|
|
|
import androidx.appcompat.widget.SwitchCompat |
|
|
|
|
|
|
|
import androidx.core.view.isVisible |
|
|
|
import androidx.core.view.isVisible |
|
|
|
import androidx.core.view.updateLayoutParams |
|
|
|
|
|
|
|
import androidx.fragment.app.FragmentActivity |
|
|
|
|
|
|
|
import androidx.preference.Preference |
|
|
|
|
|
|
|
import androidx.preference.PreferenceViewHolder |
|
|
|
import androidx.preference.PreferenceViewHolder |
|
|
|
import com.jaredrummler.android.colorpicker.* |
|
|
|
|
|
|
|
import io.legado.app.lib.theme.ATH |
|
|
|
|
|
|
|
import io.legado.app.R |
|
|
|
import io.legado.app.R |
|
|
|
import io.legado.app.lib.theme.accentColor |
|
|
|
import io.legado.app.lib.theme.accentColor |
|
|
|
import org.jetbrains.anko.imageBitmap |
|
|
|
|
|
|
|
import org.jetbrains.anko.layoutInflater |
|
|
|
import org.jetbrains.anko.layoutInflater |
|
|
|
import kotlin.math.roundToInt |
|
|
|
import kotlin.math.roundToInt |
|
|
|
|
|
|
|
|
|
|
@ -44,21 +28,21 @@ class Preference(context: Context, attrs: AttributeSet) : androidx.preference.Pr |
|
|
|
weightWidth: Int = 0, weightHeight: Int = 0): T? { |
|
|
|
weightWidth: Int = 0, weightHeight: Int = 0): T? { |
|
|
|
if (it == null) return null |
|
|
|
if (it == null) return null |
|
|
|
val view = it.findViewById(R.id.preference_title) |
|
|
|
val view = it.findViewById(R.id.preference_title) |
|
|
|
if (view is TextView) { // && !view.isInEditMode |
|
|
|
if (view is TextView) { |
|
|
|
view.text = title |
|
|
|
view.text = title |
|
|
|
view.isVisible = title != null && title.isNotEmpty() |
|
|
|
view.isVisible = title != null && title.isNotEmpty() |
|
|
|
|
|
|
|
|
|
|
|
val tv_summary = it.findViewById(R.id.preference_desc) |
|
|
|
val tvSummary = it.findViewById(R.id.preference_desc) |
|
|
|
if(tv_summary is TextView) { |
|
|
|
if (tvSummary is TextView) { |
|
|
|
tv_summary.text = summary |
|
|
|
tvSummary.text = summary |
|
|
|
tv_summary.isVisible = summary != null && summary.isNotEmpty() |
|
|
|
tvSummary.isVisible = summary != null && summary.isNotEmpty() |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
val _icon = it.findViewById(R.id.preference_icon) |
|
|
|
val iconView = it.findViewById(R.id.preference_icon) |
|
|
|
if (_icon is ImageView) { |
|
|
|
if (iconView is ImageView) { |
|
|
|
_icon.isVisible = icon != null && icon.isVisible |
|
|
|
iconView.isVisible = icon != null && icon.isVisible |
|
|
|
_icon.setImageDrawable(icon) |
|
|
|
iconView.setImageDrawable(icon) |
|
|
|
_icon.setColorFilter(context.accentColor) |
|
|
|
iconView.setColorFilter(context.accentColor) |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -72,7 +56,7 @@ class Preference(context: Context, attrs: AttributeSet) : androidx.preference.Pr |
|
|
|
lay.removeAllViews() |
|
|
|
lay.removeAllViews() |
|
|
|
lay.addView(childView) |
|
|
|
lay.addView(childView) |
|
|
|
lay.isVisible = true |
|
|
|
lay.isVisible = true |
|
|
|
v = lay.findViewById<T>(viewId) |
|
|
|
v = lay.findViewById(viewId) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (weightWidth > 0 || weightHeight > 0) { |
|
|
|
if (weightWidth > 0 || weightHeight > 0) { |
|
|
@ -94,8 +78,8 @@ class Preference(context: Context, attrs: AttributeSet) : androidx.preference.Pr |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
override fun onBindViewHolder(holder: PreferenceViewHolder?) { |
|
|
|
override fun onBindViewHolder(holder: PreferenceViewHolder?) { |
|
|
|
super.onBindViewHolder(holder) |
|
|
|
|
|
|
|
bindView<View>(context, holder, icon, title, summary, null, null) |
|
|
|
bindView<View>(context, holder, icon, title, summary, null, null) |
|
|
|
|
|
|
|
super.onBindViewHolder(holder) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|