add links to discussin sections to load dialogs for laoyuts and colors

and gather links in a single place
This commit is contained in:
Helium314 2025-02-25 20:24:24 +01:00
parent 6212f44283
commit 3c9d1c8795
8 changed files with 58 additions and 25 deletions

View file

@ -0,0 +1,13 @@
package helium314.keyboard.latin.common
object Links {
const val DICTIONARY_URL = "https://codeberg.org/Helium314/aosp-dictionaries"
const val DICTIONARY_DOWNLOAD_SUFFIX = "/src/branch/main/"
const val DICTIONARY_NORMAL_SUFFIX = "dictionaries/"
const val DICTIONARY_EXPERIMENTAL_SUFFIX = "dictionaries_experimental/"
const val GITHUB = "https://github.com/Helium314/HeliBoard"
const val LICENSE = "$GITHUB/blob/main/LICENSE-GPL-3"
const val LAYOUT_FORMAT_URL = "$GITHUB/blob/main/layouts.md"
const val CUSTOM_LAYOUTS = "$GITHUB/discussions/categories/custom-layout"
const val CUSTOM_COLORS = "$GITHUB/discussions/categories/custom-colors"
}

View file

@ -22,6 +22,8 @@ import helium314.keyboard.dictionarypack.DictionaryPackConstants
import helium314.keyboard.keyboard.KeyboardLayoutSet import helium314.keyboard.keyboard.KeyboardLayoutSet
import helium314.keyboard.keyboard.KeyboardSwitcher import helium314.keyboard.keyboard.KeyboardSwitcher
import helium314.keyboard.latin.R import helium314.keyboard.latin.R
import helium314.keyboard.latin.common.Links.DICTIONARY_URL
import helium314.keyboard.latin.common.Links.LAYOUT_FORMAT_URL
import helium314.keyboard.latin.common.LocaleUtils import helium314.keyboard.latin.common.LocaleUtils
import helium314.keyboard.latin.common.LocaleUtils.constructLocale import helium314.keyboard.latin.common.LocaleUtils.constructLocale
import helium314.keyboard.latin.databinding.LanguageListItemBinding import helium314.keyboard.latin.databinding.LanguageListItemBinding
@ -425,4 +427,3 @@ private fun getAvailableSecondaryLocales(context: Context, mainLocale: Locale, a
return locales return locales
} }
private const val LAYOUT_FORMAT_URL = "https://github.com/Helium314/HeliBoard/blob/main/layouts.md"

View file

@ -16,6 +16,7 @@ import androidx.compose.ui.text.buildAnnotatedString
import androidx.core.content.edit import androidx.core.content.edit
import helium314.keyboard.compat.locale import helium314.keyboard.compat.locale
import helium314.keyboard.latin.R import helium314.keyboard.latin.R
import helium314.keyboard.latin.common.Links
import helium314.keyboard.latin.common.LocaleUtils import helium314.keyboard.latin.common.LocaleUtils
import helium314.keyboard.latin.common.LocaleUtils.constructLocale import helium314.keyboard.latin.common.LocaleUtils.constructLocale
import helium314.keyboard.latin.settings.Defaults import helium314.keyboard.latin.settings.Defaults
@ -50,8 +51,8 @@ fun showMissingDictionaryDialog(context: Context, locale: Locale) {
if (prefs.getBoolean(Settings.PREF_DONT_SHOW_MISSING_DICTIONARY_DIALOG, Defaults.PREF_DONT_SHOW_MISSING_DICTIONARY_DIALOG) if (prefs.getBoolean(Settings.PREF_DONT_SHOW_MISSING_DICTIONARY_DIALOG, Defaults.PREF_DONT_SHOW_MISSING_DICTIONARY_DIALOG)
|| locale.toString() == SubtypeLocaleUtils.NO_LANGUAGE) || locale.toString() == SubtypeLocaleUtils.NO_LANGUAGE)
return return
val repositoryLink = "<a href='$DICTIONARY_URL'>" + context.getString(R.string.dictionary_link_text) + "</a>" val repositoryLink = "<a href='${Links.DICTIONARY_URL}'>" + context.getString(R.string.dictionary_link_text) + "</a>"
val dictionaryLink = "<a href='$DICTIONARY_URL/src/branch/main/dictionaries/main_$locale.dict'>" + context.getString( val dictionaryLink = "<a href='${Links.DICTIONARY_URL}/src/branch/main/dictionaries/main_$locale.dict'>" + context.getString(
R.string.dictionary_link_text) + "</a>" R.string.dictionary_link_text) + "</a>"
val startMessage = context.getString( // todo: now with the available dicts csv, is the full text still necessary? val startMessage = context.getString( // todo: now with the available dicts csv, is the full text still necessary?
R.string.no_dictionary_message, R.string.no_dictionary_message,
@ -88,8 +89,8 @@ fun createDictionaryTextHtml(message: String, locale: Locale, context: Context):
val rawDictString = "$type: ${dictLocale.getDisplayName(context.resources.configuration.locale())}" val rawDictString = "$type: ${dictLocale.getDisplayName(context.resources.configuration.locale())}"
val dictString = if (experimental.isEmpty()) rawDictString val dictString = if (experimental.isEmpty()) rawDictString
else context.getString(R.string.available_dictionary_experimental, rawDictString) else context.getString(R.string.available_dictionary_experimental, rawDictString)
val dictBaseUrl = DICTIONARY_URL + DICTIONARY_DOWNLOAD_SUFFIX + val dictBaseUrl = Links.DICTIONARY_URL + Links.DICTIONARY_DOWNLOAD_SUFFIX +
if (experimental.isEmpty()) DICTIONARY_NORMAL_SUFFIX else DICTIONARY_EXPERIMENTAL_SUFFIX if (experimental.isEmpty()) Links.DICTIONARY_NORMAL_SUFFIX else Links.DICTIONARY_EXPERIMENTAL_SUFFIX
val dictLink = dictBaseUrl + type + "_" + localeString.lowercase() + ".dict" val dictLink = dictBaseUrl + type + "_" + localeString.lowercase() + ".dict"
val fullText = "<li><a href='$dictLink'>$dictString</a></li>" val fullText = "<li><a href='$dictLink'>$dictString</a></li>"
knownDicts.add(fullText) knownDicts.add(fullText)
@ -109,7 +110,7 @@ fun createDictionaryTextHtml(message: String, locale: Locale, context: Context):
fun MissingDictionaryDialog(onDismissRequest: () -> Unit, locale: Locale) { fun MissingDictionaryDialog(onDismissRequest: () -> Unit, locale: Locale) {
val prefs = LocalContext.current.prefs() val prefs = LocalContext.current.prefs()
val availableDicts = createDictionaryTextAnnotated(locale) val availableDicts = createDictionaryTextAnnotated(locale)
val dictLink = "$DICTIONARY_URL/src/branch/main/dictionaries/main_$locale.dict" val dictLink = "${Links.DICTIONARY_URL}/src/branch/main/dictionaries/main_$locale.dict"
val message = stringResource(R.string.no_dictionary_message, "§repl1§", locale.toString(), "§repl2§") val message = stringResource(R.string.no_dictionary_message, "§repl1§", locale.toString(), "§repl2§")
.replace("<br>", "\n") // compose doesn't understand html... // todo: modify the string? .replace("<br>", "\n") // compose doesn't understand html... // todo: modify the string?
@ -120,7 +121,7 @@ fun MissingDictionaryDialog(onDismissRequest: () -> Unit, locale: Locale) {
val annotatedString = buildAnnotatedString { val annotatedString = buildAnnotatedString {
append(part1) append(part1)
appendLink(stringResource(R.string.dictionary_link_text), DICTIONARY_URL) appendLink(stringResource(R.string.dictionary_link_text), Links.DICTIONARY_URL)
append(part2) append(part2)
appendLink(stringResource(R.string.dictionary_link_text), dictLink) appendLink(stringResource(R.string.dictionary_link_text), dictLink)
append(part3) append(part3)
@ -158,8 +159,8 @@ fun createDictionaryTextAnnotated(locale: Locale): AnnotatedString {
val rawDictString = "$type: ${dictLocale.getDisplayName(context.resources.configuration.locale())}" val rawDictString = "$type: ${dictLocale.getDisplayName(context.resources.configuration.locale())}"
val dictString = if (experimental.isEmpty()) rawDictString val dictString = if (experimental.isEmpty()) rawDictString
else context.getString(R.string.available_dictionary_experimental, rawDictString) else context.getString(R.string.available_dictionary_experimental, rawDictString)
val dictBaseUrl = DICTIONARY_URL + DICTIONARY_DOWNLOAD_SUFFIX + val dictBaseUrl = Links.DICTIONARY_URL + Links.DICTIONARY_DOWNLOAD_SUFFIX +
if (experimental.isEmpty()) DICTIONARY_NORMAL_SUFFIX else DICTIONARY_EXPERIMENTAL_SUFFIX if (experimental.isEmpty()) Links.DICTIONARY_NORMAL_SUFFIX else Links.DICTIONARY_EXPERIMENTAL_SUFFIX
val dictLink = dictBaseUrl + type + "_" + localeString.lowercase() + ".dict" val dictLink = dictBaseUrl + type + "_" + localeString.lowercase() + ".dict"
knownDicts.add(dictString to dictLink) knownDicts.add(dictString to dictLink)
} }
@ -195,8 +196,3 @@ fun cleanUnusedMainDicts(context: Context) {
private fun hasAnythingOtherThanExtractedMainDictionary(dir: File) = private fun hasAnythingOtherThanExtractedMainDictionary(dir: File) =
dir.listFiles()?.any { it.name != DictionaryInfoUtils.getExtractedMainDictFilename() } != false dir.listFiles()?.any { it.name != DictionaryInfoUtils.getExtractedMainDictFilename() } != false
const val DICTIONARY_URL = "https://codeberg.org/Helium314/aosp-dictionaries"
const val DICTIONARY_DOWNLOAD_SUFFIX = "/src/branch/main/"
const val DICTIONARY_NORMAL_SUFFIX = "dictionaries/"
const val DICTIONARY_EXPERIMENTAL_SUFFIX = "dictionaries_experimental/"

View file

@ -33,6 +33,7 @@ import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.LocalContext import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.res.painterResource import androidx.compose.ui.res.painterResource
import androidx.compose.ui.res.stringResource import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.buildAnnotatedString
import androidx.compose.ui.text.input.TextFieldValue import androidx.compose.ui.text.input.TextFieldValue
import androidx.compose.ui.tooling.preview.Preview import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.dp
@ -40,9 +41,11 @@ import helium314.keyboard.keyboard.ColorSetting
import helium314.keyboard.keyboard.KeyboardTheme import helium314.keyboard.keyboard.KeyboardTheme
import helium314.keyboard.latin.R import helium314.keyboard.latin.R
import helium314.keyboard.latin.common.ColorType import helium314.keyboard.latin.common.ColorType
import helium314.keyboard.latin.common.Links
import helium314.keyboard.latin.common.decodeBase36 import helium314.keyboard.latin.common.decodeBase36
import helium314.keyboard.latin.settings.Settings import helium314.keyboard.latin.settings.Settings
import helium314.keyboard.latin.utils.Log import helium314.keyboard.latin.utils.Log
import helium314.keyboard.latin.utils.appendLink
import helium314.keyboard.latin.utils.getActivity import helium314.keyboard.latin.utils.getActivity
import helium314.keyboard.latin.utils.getStringResourceOrName import helium314.keyboard.latin.utils.getStringResourceOrName
import helium314.keyboard.latin.utils.prefs import helium314.keyboard.latin.utils.prefs
@ -132,6 +135,15 @@ fun ColorThemePickerDialog(
ConfirmationDialog( ConfirmationDialog(
onDismissRequest = { showLoadDialog = false }, onDismissRequest = { showLoadDialog = false },
title = { Text(stringResource(R.string.load)) }, title = { Text(stringResource(R.string.load)) },
content = {
val text = stringResource(R.string.get_colors_message)
val annotated = buildAnnotatedString {
append(text.substringBefore("%s"))
appendLink(stringResource(R.string.discussion_section_link), Links.CUSTOM_COLORS)
append(text.substringAfter("%s"))
}
Text(annotated)
},
onConfirmed = { onConfirmed = {
val intent = Intent(Intent.ACTION_OPEN_DOCUMENT) val intent = Intent(Intent.ACTION_OPEN_DOCUMENT)
.addCategory(Intent.CATEGORY_OPENABLE) .addCategory(Intent.CATEGORY_OPENABLE)

View file

@ -45,6 +45,7 @@ import helium314.keyboard.keyboard.internal.keyboard_parser.morePopupKeysResId
import helium314.keyboard.latin.R import helium314.keyboard.latin.R
import helium314.keyboard.latin.common.Constants.Separators import helium314.keyboard.latin.common.Constants.Separators
import helium314.keyboard.latin.common.Constants.Subtype.ExtraValue import helium314.keyboard.latin.common.Constants.Subtype.ExtraValue
import helium314.keyboard.latin.common.Links
import helium314.keyboard.latin.common.LocaleUtils.constructLocale import helium314.keyboard.latin.common.LocaleUtils.constructLocale
import helium314.keyboard.latin.common.LocaleUtils.localizedDisplayName import helium314.keyboard.latin.common.LocaleUtils.localizedDisplayName
import helium314.keyboard.latin.settings.Defaults import helium314.keyboard.latin.settings.Defaults
@ -380,10 +381,15 @@ private fun MainLayoutRow(
// layoutString contains "%s" since we didn't supply a formatArg // layoutString contains "%s" since we didn't supply a formatArg
val layoutString = stringResource(R.string.message_add_custom_layout) val layoutString = stringResource(R.string.message_add_custom_layout)
val linkText = stringResource(R.string.dictionary_link_text) val linkText = stringResource(R.string.dictionary_link_text)
val discussionSectionText = stringResource(R.string.get_layouts_message)
val annotated = buildAnnotatedString { val annotated = buildAnnotatedString {
append(layoutString.substringBefore("%s")) append(layoutString.substringBefore("%s"))
appendLink(linkText, LAYOUT_FORMAT_URL) appendLink(linkText, Links.LAYOUT_FORMAT_URL)
append(layoutString.substringAfter("%s")) append(layoutString.substringAfter("%s"))
appendLine()
append(discussionSectionText.substringBefore("%s"))
appendLink(stringResource(R.string.discussion_section_link), Links.CUSTOM_LAYOUTS)
append(discussionSectionText.substringAfter("%s"))
} }
ConfirmationDialog( ConfirmationDialog(
@ -460,5 +466,3 @@ fun <T>DropDownField(
private fun getAvailableSecondaryLocales(context: Context, mainLocale: Locale): List<Locale> = private fun getAvailableSecondaryLocales(context: Context, mainLocale: Locale): List<Locale> =
getDictionaryLocales(context).filter { it != mainLocale && it.script() == mainLocale.script() } getDictionaryLocales(context).filter { it != mainLocale && it.script() == mainLocale.script() }
private const val LAYOUT_FORMAT_URL = "https://github.com/Helium314/HeliBoard/blob/main/layouts.md"

View file

@ -24,6 +24,7 @@ import androidx.compose.ui.tooling.preview.Preview
import androidx.core.net.toUri import androidx.core.net.toUri
import helium314.keyboard.latin.BuildConfig import helium314.keyboard.latin.BuildConfig
import helium314.keyboard.latin.R import helium314.keyboard.latin.R
import helium314.keyboard.latin.common.Links
import helium314.keyboard.latin.settings.DebugSettings import helium314.keyboard.latin.settings.DebugSettings
import helium314.keyboard.latin.settings.Defaults import helium314.keyboard.latin.settings.Defaults
import helium314.keyboard.latin.utils.Log import helium314.keyboard.latin.utils.Log
@ -93,7 +94,7 @@ fun createAboutSettings(context: Context) = listOf(
description = it.description, description = it.description,
onClick = { onClick = {
val intent = Intent() val intent = Intent()
intent.data = "https://github.com/Helium314/HeliBoard/blob/main/LICENSE-GPL-3".toUri() intent.data = Links.LICENSE.toUri()
intent.action = Intent.ACTION_VIEW intent.action = Intent.ACTION_VIEW
ctx.startActivity(intent) ctx.startActivity(intent)
}, },
@ -131,7 +132,7 @@ fun createAboutSettings(context: Context) = listOf(
description = it.description, description = it.description,
onClick = { onClick = {
val intent = Intent() val intent = Intent()
intent.data = "https://github.com/Helium314/HeliBoard".toUri() intent.data = Links.GITHUB.toUri()
intent.action = Intent.ACTION_VIEW intent.action = Intent.ACTION_VIEW
ctx.startActivity(intent) ctx.startActivity(intent)
}, },

View file

@ -20,12 +20,12 @@ import androidx.compose.ui.text.buildAnnotatedString
import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.dp
import helium314.keyboard.latin.Dictionary import helium314.keyboard.latin.Dictionary
import helium314.keyboard.latin.R import helium314.keyboard.latin.R
import helium314.keyboard.latin.common.Links
import helium314.keyboard.latin.common.LocaleUtils import helium314.keyboard.latin.common.LocaleUtils
import helium314.keyboard.latin.common.LocaleUtils.constructLocale import helium314.keyboard.latin.common.LocaleUtils.constructLocale
import helium314.keyboard.latin.common.LocaleUtils.localizedDisplayName import helium314.keyboard.latin.common.LocaleUtils.localizedDisplayName
import helium314.keyboard.latin.common.splitOnWhitespace import helium314.keyboard.latin.common.splitOnWhitespace
import helium314.keyboard.latin.settings.USER_DICTIONARY_SUFFIX import helium314.keyboard.latin.settings.USER_DICTIONARY_SUFFIX
import helium314.keyboard.latin.utils.DICTIONARY_URL
import helium314.keyboard.latin.utils.DictionaryInfoUtils import helium314.keyboard.latin.utils.DictionaryInfoUtils
import helium314.keyboard.latin.utils.SubtypeLocaleUtils import helium314.keyboard.latin.utils.SubtypeLocaleUtils
import helium314.keyboard.latin.utils.SubtypeSettings import helium314.keyboard.latin.utils.SubtypeSettings
@ -102,7 +102,7 @@ fun DictionaryScreen(
val addDictString = stringResource(R.string.add_dictionary) val addDictString = stringResource(R.string.add_dictionary)
val annotated = buildAnnotatedString { val annotated = buildAnnotatedString {
append(addDictString.substringBefore("%s")) append(addDictString.substringBefore("%s"))
appendLink(stringResource(R.string.dictionary_link_text), DICTIONARY_URL) appendLink(stringResource(R.string.dictionary_link_text), Links.DICTIONARY_URL)
append(addDictString.substringAfter("%s")) append(addDictString.substringAfter("%s"))
} }
Text(annotated) Text(annotated)

View file

@ -517,7 +517,7 @@ disposition rather than other common dispositions for Latin languages. [CHAR LIM
<string name="keyboard_layout_set">Layout</string> <string name="keyboard_layout_set">Layout</string>
<!-- Button text and title for adding a custom layout --> <!-- Button text and title for adding a custom layout -->
<string name="button_title_add_custom_layout">Add custom layout</string> <string name="button_title_add_custom_layout">Add custom layout</string>
<!-- Message text for adding a custom layout, interpreted as HTML --> <!-- Message text for adding a custom layout -->
<string name="message_add_custom_layout">Select a file in a compatible format. Information about the formats is available %s.</string> <string name="message_add_custom_layout">Select a file in a compatible format. Information about the formats is available %s.</string>
<!-- Button text for loading a custom layout, image or theme file --> <!-- Button text for loading a custom layout, image or theme file -->
<string name="button_load_custom">Load file</string> <string name="button_load_custom">Load file</string>
@ -688,11 +688,11 @@ New dictionary:
You can download dictionaries %1$s, or check whether a dictionary for \"%2$s\" can be downloaded directly %3$s."</string> You can download dictionaries %1$s, or check whether a dictionary for \"%2$s\" can be downloaded directly %3$s."</string>
<!-- Button to never show the no_dictionary_message when enabling a language that has no dictionary --> <!-- Button to never show the no_dictionary_message when enabling a language that has no dictionary -->
<string name="no_dictionary_dont_show_again_button">"Don't show again"</string> <string name="no_dictionary_dont_show_again_button">"Don't show again"</string>
<!-- Message for the user dictionary selection dialog, %s will be replaced by dictionary_link_text. This string will be interpreted as HTML --> <!-- Message for the user dictionary selection dialog, %s will be replaced by dictionary_link_text. -->
<string name="add_dictionary">"Select a dictionary to add. Dictionaries in .dict format can be downloaded %s."</string> <string name="add_dictionary">"Select a dictionary to add. Dictionaries in .dict format can be downloaded %s."</string>
<!-- Title of the link to the download page inserted into messages (add_dictionary and no_dictionary_message) --> <!-- Title of the link to the download page inserted into several messages -->
<string name="dictionary_link_text">"here"</string> <string name="dictionary_link_text">"here"</string>
<!-- Title of an item in the list of available dictionaries when the dictionary is experimental. This string will be interpreted as HTML --> <!-- Title of an item in the list of available dictionaries when the dictionary is experimental. -->
<string name="available_dictionary_experimental">"%s (experimental)"</string> <string name="available_dictionary_experimental">"%s (experimental)"</string>
<!-- Text shown when dictionary file could not be read --> <!-- Text shown when dictionary file could not be read -->
<string name="dictionary_file_error">"Error: Selected file is not a valid dictionary file"</string> <string name="dictionary_file_error">"Error: Selected file is not a valid dictionary file"</string>
@ -841,6 +841,12 @@ New dictionary:
<string name="select_color_accent">Accent</string> <string name="select_color_accent">Accent</string>
<!-- Selection: gesture color. --> <!-- Selection: gesture color. -->
<string name="select_color_gesture">Gesture input</string> <string name="select_color_gesture">Gesture input</string>
<!-- Message displayed when clicking "load" button in color theme picker. "%s" will be replaced by discussion_section_link -->
<string name="get_colors_message">"You can find and share colors in the %s."</string>
<!-- Message displayed when clicking add button for layouts. "%s" will be replaced by discussion_section_link -->
<string name="get_layouts_message">"You can find and share layouts in the %s."</string>
<!-- Text to be used in get_colors_message and get_layouts_message -->
<string name="discussion_section_link">"discussion section"</string>
<!-- Settings screen title for about [CHAR LIMIT=33]--> <!-- Settings screen title for about [CHAR LIMIT=33]-->
<string name="settings_screen_about">About</string> <string name="settings_screen_about">About</string>
<!-- version for about screen--> <!-- version for about screen-->