Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions app/src/main/assets/emoji.json

Large diffs are not rendered by default.

143 changes: 143 additions & 0 deletions app/src/main/assets/symbol_shortcodes.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,143 @@
{
"euro": "€",
"pound": "£",
"yen": "¥",
"cent": "¢",
"rupee": "₹",
"dollar": "$",
"percent": "%",
"pct": "%",
"permille": "‰",
"amp": "&",
"ampersand": "&",
"at": "@",
"hash": "#",
"hashtag": "#",
"caret": "^",
"tilde": "~",
"backslash": "\\",
"slash": "/",
"pipe": "|",
"underscore": "_",
"grave": "`",
"apostrophe": "'",
"comma": ",",
"period": ".",
"semicolon": ";",
"colon": ":",
"exclamation": "!",
"question": "?",
"lparen": "(",
"rparen": ")",
"lbrace": "{",
"rbrace": "}",
"lbracket": "[",
"rbracket": "]",
"less": "<",
"greater": ">",
"equal": "=",
"plus": "+",
"minus": "-",
"asterisk": "*",
"times": "×",
"multiply": "×",
"divide": "÷",
"division": "÷",
"plusminus": "±",
"pm": "±",
"infinity": "∞",
"inf": "∞",
"approximately": "≈",
"approx": "≈",
"notequal": "≠",
"neq": "≠",
"lessequal": "≤",
"leq": "≤",
"greaterequal": "≥",
"geq": "≥",
"sum": "∑",
"product": "∏",
"integral": "∫",
"sqrt": "√",
"cuberoot": "∛",
"fourthroot": "∜",
"bullet": "•",
"middot": "·",
"ellipsis": "…",
"dots": "…",
"section": "§",
"paragraph": "¶",
"dagger": "†",
"doubledagger": "‡",
"degree": "°",
"deg": "°",
"micro": "µ",
"alpha": "α",
"beta": "β",
"gamma": "γ",
"delta": "δ",
"epsilon": "ε",
"theta": "θ",
"lambda": "λ",
"mu": "μ",
"sigma": "σ",
"omega": "ω",
"pi": "π",
"tau": "τ",
"phi": "φ",
"arrow": "→",
"rightarrow": "→",
"leftarrow": "←",
"uparrow": "↑",
"downarrow": "↓",
"leftrightarrow": "↔",
"doublearrow": "⇒",
"implies": "⇒",
"star": "★",
"blackstar": "★",
"whitestar": "☆",
"heart": "♥",
"blackheart": "♥",
"whiteheart": "♡",
"spade": "♠",
"club": "♣",
"diamond": "♦",
"check": "✓",
"checkmark": "✓",
"cross": "✗",
"xmark": "✗",
"music": "♪",
"note": "♪",
"notes": "♫",
"sun": "☀",
"cloud": "☁",
"umbrella": "☂",
"snowflake": "❄",
"telephone": "☎",
"phone": "☎",
"mail": "✉",
"email": "✉",
"pencil": "✎",
"scissors": "✂",
"airplane": "✈",
"warning": "⚠",
"peace": "☮",
"yin": "☯",
"yinyang": "☯",
"fraction14": "¼",
"quarter": "¼",
"fraction12": "½",
"half": "½",
"fraction34": "¾",
"super2": "²",
"squared": "²",
"super3": "³",
"cubed": "³",
"laquo": "«",
"raquo": "»",
"ldquo": ",\n \"rdquo\": ",
"lsquo": "'",
"rsquo": "'",
"mdash": "—",
"ndash": "–"
}
80 changes: 80 additions & 0 deletions app/src/main/java/it/palsoftware/pastiera/SettingsManager.kt
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,11 @@ object SettingsManager {
private const val KEY_AUTO_CORRECT_ENABLED = "auto_correct_enabled"
private const val KEY_AUTO_CORRECT_ENABLED_LANGUAGES = "auto_correct_enabled_languages"
private const val KEY_SUGGESTIONS_ENABLED = "suggestions_enabled"
private const val KEY_SNIPPETS_ENABLED = "snippets_enabled"
private const val KEY_SNIPPETS_TRIGGER = "snippets_trigger"
private const val KEY_SNIPPETS = "snippets"
private const val KEY_EMOJI_SHORTCODE_ENABLED = "emoji_shortcode_enabled"
private const val KEY_SYMBOL_SHORTCODE_ENABLED = "symbol_shortcode_enabled"
private const val KEY_ACCENT_MATCHING_ENABLED = "accent_matching_enabled"
private const val KEY_AUTO_REPLACE_ON_SPACE_ENTER = "auto_replace_on_space_enter"
private const val KEY_MAX_AUTO_REPLACE_DISTANCE = "max_auto_replace_distance"
Expand Down Expand Up @@ -279,6 +284,10 @@ object SettingsManager {
private const val DEFAULT_LAYOUT_AWARE_CTRL_SHORTCUTS = false
private const val DEFAULT_AUTO_CORRECT_ENABLED = true
private const val DEFAULT_SUGGESTIONS_ENABLED = true
private const val DEFAULT_SNIPPETS_ENABLED = true
private const val DEFAULT_SNIPPETS_TRIGGER = "!"
private const val DEFAULT_EMOJI_SHORTCODE_ENABLED = true
private const val DEFAULT_SYMBOL_SHORTCODE_ENABLED = true
private const val DEFAULT_ACCENT_MATCHING_ENABLED = true
private const val DEFAULT_AUTO_REPLACE_ON_SPACE_ENTER = false
private const val DEFAULT_MAX_AUTO_REPLACE_DISTANCE = 1
Expand Down Expand Up @@ -2531,6 +2540,77 @@ object SettingsManager {
.apply()
}

fun getSnippetsEnabled(context: Context): Boolean {
return getPreferences(context).getBoolean(KEY_SNIPPETS_ENABLED, DEFAULT_SNIPPETS_ENABLED)
}

fun setSnippetsEnabled(context: Context, enabled: Boolean) {
getPreferences(context).edit()
.putBoolean(KEY_SNIPPETS_ENABLED, enabled)
.apply()
}

fun getSnippetsTrigger(context: Context): String {
val stored = getPreferences(context).getString(KEY_SNIPPETS_TRIGGER, DEFAULT_SNIPPETS_TRIGGER).orEmpty()
return stored.take(1).ifEmpty { DEFAULT_SNIPPETS_TRIGGER }
}

fun setSnippetsTrigger(context: Context, trigger: String) {
val normalized = trigger.trim().take(1).ifEmpty { DEFAULT_SNIPPETS_TRIGGER }
getPreferences(context).edit()
.putString(KEY_SNIPPETS_TRIGGER, normalized)
.apply()
}

fun getSnippets(context: Context): LinkedHashMap<String, String> {
val jsonString = getPreferences(context).getString(KEY_SNIPPETS, null) ?: return linkedMapOf()
return try {
val jsonObject = JSONObject(jsonString)
val snippets = linkedMapOf<String, String>()
jsonObject.keys().forEach { key ->
snippets[key] = jsonObject.getString(key)
}
snippets
} catch (e: Exception) {
Log.e(TAG, "Error loading snippets", e)
linkedMapOf()
}
}

fun saveSnippets(context: Context, snippets: Map<String, String>) {
try {
val jsonObject = JSONObject()
snippets.forEach { (shortcut, value) ->
jsonObject.put(shortcut.lowercase(), value)
}
getPreferences(context).edit()
.putString(KEY_SNIPPETS, jsonObject.toString())
.apply()
} catch (e: Exception) {
Log.e(TAG, "Error saving snippets", e)
}
}

fun getEmojiShortcodeEnabled(context: Context): Boolean {
return getPreferences(context).getBoolean(KEY_EMOJI_SHORTCODE_ENABLED, DEFAULT_EMOJI_SHORTCODE_ENABLED)
}

fun setEmojiShortcodeEnabled(context: Context, enabled: Boolean) {
getPreferences(context).edit()
.putBoolean(KEY_EMOJI_SHORTCODE_ENABLED, enabled)
.apply()
}

fun getSymbolShortcodeEnabled(context: Context): Boolean {
return getPreferences(context).getBoolean(KEY_SYMBOL_SHORTCODE_ENABLED, DEFAULT_SYMBOL_SHORTCODE_ENABLED)
}

fun setSymbolShortcodeEnabled(context: Context, enabled: Boolean) {
getPreferences(context).edit()
.putBoolean(KEY_SYMBOL_SHORTCODE_ENABLED, enabled)
.apply()
}

/**
* Returns whether accent matching should be applied to suggestions and auto-replace.
*/
Expand Down
Loading