mirror of
https://github.com/Helium314/HeliBoard.git
synced 2025-05-25 11:22:20 +00:00
show toolbar icons in toolbar key dialog
This commit is contained in:
parent
52f567ff9e
commit
4ee01527a2
4 changed files with 35 additions and 5 deletions
|
@ -60,15 +60,18 @@ public final class PreferencesSettingsFragment extends SubScreenFragment {
|
|||
setLocalizedNumberRowVisibility();
|
||||
findPreference(Settings.PREF_POPUP_KEYS_LABELS_ORDER).setVisible(getSharedPreferences().getBoolean(Settings.PREF_SHOW_HINTS, false));
|
||||
findPreference(Settings.PREF_POPUP_KEYS_ORDER).setOnPreferenceClickListener((pref) -> {
|
||||
DialogUtilsKt.reorderDialog(requireContext(), Settings.PREF_POPUP_KEYS_ORDER, PopupKeysUtilsKt.POPUP_KEYS_ORDER_DEFAULT, R.string.popup_order);
|
||||
DialogUtilsKt.reorderDialog(requireContext(), Settings.PREF_POPUP_KEYS_ORDER,
|
||||
PopupKeysUtilsKt.POPUP_KEYS_ORDER_DEFAULT, R.string.popup_order, (x) -> null);
|
||||
return true;
|
||||
});
|
||||
findPreference(Settings.PREF_POPUP_KEYS_LABELS_ORDER).setOnPreferenceClickListener((pref) -> {
|
||||
DialogUtilsKt.reorderDialog(requireContext(), Settings.PREF_POPUP_KEYS_LABELS_ORDER, PopupKeysUtilsKt.POPUP_KEYS_LABEL_DEFAULT, R.string.hint_source);
|
||||
DialogUtilsKt.reorderDialog(requireContext(), Settings.PREF_POPUP_KEYS_LABELS_ORDER,
|
||||
PopupKeysUtilsKt.POPUP_KEYS_LABEL_DEFAULT, R.string.hint_source, (x) -> null);
|
||||
return true;
|
||||
});
|
||||
findPreference(Settings.PREF_TOOLBAR_KEYS).setOnPreferenceClickListener((pref) -> {
|
||||
DialogUtilsKt.reorderDialog(requireContext(), Settings.PREF_TOOLBAR_KEYS, ToolbarUtilsKt.getDefaultToolbarPref(), R.string.toolbar_keys);
|
||||
DialogUtilsKt.reorderDialog(requireContext(), Settings.PREF_TOOLBAR_KEYS, ToolbarUtilsKt.getDefaultToolbarPref(),
|
||||
R.string.toolbar_keys, (name) -> ToolbarUtilsKt.getToolbarIconByName(name, requireContext()));
|
||||
return true;
|
||||
});
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -4,9 +4,12 @@ package helium314.keyboard.latin.utils
|
|||
import android.content.Context
|
||||
import android.content.SharedPreferences
|
||||
import android.content.res.TypedArray
|
||||
import android.graphics.drawable.Drawable
|
||||
import android.widget.ImageButton
|
||||
import android.widget.ImageView
|
||||
import androidx.appcompat.view.ContextThemeWrapper
|
||||
import androidx.core.content.edit
|
||||
import helium314.keyboard.keyboard.KeyboardTheme
|
||||
import helium314.keyboard.keyboard.internal.keyboard_parser.floris.KeyCode
|
||||
import helium314.keyboard.latin.R
|
||||
import helium314.keyboard.latin.settings.Settings
|
||||
|
@ -76,6 +79,15 @@ private fun getStyleableIconId(key: ToolbarKey) = when (key) {
|
|||
SELECT_WORD -> R.styleable.Keyboard_iconSelectWord
|
||||
}
|
||||
|
||||
fun getToolbarIconByName(name: String, context: Context): Drawable? {
|
||||
val key = entries.firstOrNull { it.name == name } ?: return null
|
||||
val themeContext = ContextThemeWrapper(context, KeyboardTheme.getKeyboardTheme(context).mStyleId)
|
||||
val attrs = themeContext.obtainStyledAttributes(null, R.styleable.Keyboard)
|
||||
val icon = attrs.getDrawable(getStyleableIconId(key))?.mutate()
|
||||
attrs.recycle()
|
||||
return icon
|
||||
}
|
||||
|
||||
// names need to be aligned with resources strings (using lowercase of key.name)
|
||||
enum class ToolbarKey {
|
||||
VOICE, CLIPBOARD, UNDO, REDO, SETTINGS, SELECT_ALL, SELECT_WORD, COPY, ONE_HANDED, LEFT, RIGHT, UP, DOWN,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue