show toolbar icons in toolbar key dialog

This commit is contained in:
Helium314 2024-04-06 12:22:14 +02:00
parent 52f567ff9e
commit 4ee01527a2
4 changed files with 35 additions and 5 deletions

View file

@ -1,8 +1,11 @@
package helium314.keyboard.latin.utils
import android.content.Context
import android.graphics.drawable.Drawable
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.ImageView
import android.widget.Switch
import android.widget.TextView
import androidx.annotation.StringRes
@ -51,7 +54,13 @@ fun infoDialog(context: Context, message: String) {
* Items are semicolon-separated, see e.g. [POPUP_KEYS_LABEL_DEFAULT] for an example.
*/
// this should probably be a class
fun reorderDialog(context: Context, key: String, defaultSetting: String, @StringRes dialogTitleId: Int) {
fun reorderDialog(
context: Context,
key: String,
defaultSetting: String,
@StringRes dialogTitleId: Int,
getIcon: (String) -> Drawable? = { null }
) {
val prefs = DeviceProtectedUtils.getSharedPreferences(context)
val orderedItems = prefs.getString(key, defaultSetting)!!.split(";").mapTo(ArrayList()) {
val both = it.split(",")
@ -85,6 +94,11 @@ fun reorderDialog(context: Context, key: String, defaultSetting: String, @String
val pos = orderedItems.indexOfFirst { it.first == text }
orderedItems[pos] = text to isChecked
}
val icon = getIcon(text)
viewHolder.itemView.findViewById<ImageView>(R.id.reorder_item_icon)?.let {
it.visibility = if (icon == null) View.GONE else View.VISIBLE
it.setImageDrawable(icon)
}
}
}
rv.adapter = adapter