diff --git a/app/src/main/java/io/legado/app/lib/theme/prefs/IconListPreference.kt b/app/src/main/java/io/legado/app/lib/theme/prefs/IconListPreference.kt deleted file mode 100644 index d78849b3e..000000000 --- a/app/src/main/java/io/legado/app/lib/theme/prefs/IconListPreference.kt +++ /dev/null @@ -1,96 +0,0 @@ -package io.legado.app.lib.theme.prefs - -import android.annotation.SuppressLint -import android.app.Activity -import android.app.AlertDialog.Builder -import android.content.Context -import android.graphics.drawable.Drawable -import android.preference.ListPreference -import android.util.AttributeSet -import android.view.View -import android.view.ViewGroup -import android.widget.ArrayAdapter -import android.widget.CheckedTextView -import android.widget.ImageView -import android.widget.ListAdapter -import io.legado.app.R -import java.util.* - - -class IconListPreference(context: Context, attrs: AttributeSet) : ListPreference(context, attrs) { - - private val mEntryDrawables = ArrayList() - - init { - - val a = context.theme.obtainStyledAttributes(attrs, R.styleable.IconListPreference, 0, 0) - - val drawables: Array - - try { - drawables = a.getTextArray(R.styleable.IconListPreference_icons) - } finally { - a.recycle() - } - - for (drawable in drawables) { - val resId = context.resources.getIdentifier(drawable.toString(), "mipmap", context.packageName) - - @Suppress("DEPRECATION") - val d = context.resources.getDrawable(resId) - - mEntryDrawables.add(d) - } - - widgetLayoutResource = R.layout.view_icon - } - - protected fun createListAdapter(): ListAdapter { - val selectedValue = value - val selectedIndex = findIndexOfValue(selectedValue) - return AppArrayAdapter(context, R.layout.item_icon_preference, entries, mEntryDrawables, selectedIndex) - } - - override fun onBindView(view: View) { - super.onBindView(view) - - val selectedValue = value - val selectedIndex = findIndexOfValue(selectedValue) - - val drawable = mEntryDrawables[selectedIndex] - - (view.findViewById(R.id.preview) as ImageView).setImageDrawable(drawable) - } - - override fun onPrepareDialogBuilder(builder: Builder) { - builder.setAdapter(createListAdapter(), this) - super.onPrepareDialogBuilder(builder) - } - - inner class AppArrayAdapter( - context: Context, textViewResourceId: Int, - objects: Array, imageDrawables: List, - selectedIndex: Int - ) : ArrayAdapter(context, textViewResourceId, objects) { - private var mImageDrawables: List? = null - private var mSelectedIndex = 0 - - init { - mSelectedIndex = selectedIndex - mImageDrawables = imageDrawables - } - - @SuppressLint("ViewHolder") - override fun getView(position: Int, convertView: View?, parent: ViewGroup): View { - val inflater = (context as Activity).layoutInflater - val view = inflater.inflate(R.layout.item_icon_preference, parent, false) - val textView = view.findViewById(R.id.label) as CheckedTextView - textView.text = getItem(position) - textView.isChecked = position == mSelectedIndex - - val imageView = view.findViewById(R.id.icon) as ImageView - imageView.setImageDrawable(mImageDrawables!![position]) - return view - } - } -} diff --git a/app/src/main/res/xml/pref_config.xml b/app/src/main/res/xml/pref_config.xml index b6656a907..043eb7cbc 100644 --- a/app/src/main/res/xml/pref_config.xml +++ b/app/src/main/res/xml/pref_config.xml @@ -17,4 +17,11 @@ app:iconSpaceReserved="false" /> + + \ No newline at end of file diff --git a/app/src/main/res/xml/pref_config_read.xml b/app/src/main/res/xml/pref_config_read.xml index 9b52e4753..06ddce418 100644 --- a/app/src/main/res/xml/pref_config_read.xml +++ b/app/src/main/res/xml/pref_config_read.xml @@ -8,5 +8,10 @@ android:key="hideStatusBar" app:iconSpaceReserved="false" /> + \ No newline at end of file