Skip to content

Commit 0c609bd

Browse files
Add confirm dialog for translation source language (#517)
* add confirmation dialog to download translation data * add DataDownloadViewModel for centralized download state management * navigate to translation setting on clicking Change language * remove unused import directive * use dynamic source language from context for download confirm dialog * add confirm dialog in select translation language screen * Standardize spacing of all docstrings - WIP will check punctuation/capitalization * trigger download state from select language screen * fix navigation to download screen * Further updates of comments in the project * Move file to facilitate rebase * move DataDownloadScreen --------- Co-authored-by: Andrew Tavis McAllister <andrew.t.mcallister@gmail.com>
1 parent aacabd6 commit 0c609bd

41 files changed

Lines changed: 756 additions & 171 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

app/src/main/java/be/scri/App.kt

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import androidx.compose.runtime.getValue
2121
import androidx.compose.runtime.rememberCoroutineScope
2222
import androidx.compose.ui.Modifier
2323
import androidx.compose.ui.unit.dp
24+
import androidx.lifecycle.viewmodel.compose.viewModel
2425
import androidx.navigation.NavHostController
2526
import androidx.navigation.compose.NavHost
2627
import androidx.navigation.compose.composable
@@ -30,14 +31,15 @@ import be.scri.navigation.Screen
3031
import be.scri.ui.common.appcomponents.HintDialog
3132
import be.scri.ui.common.bottombar.ScribeBottomBar
3233
import be.scri.ui.screens.DefaultCurrencySymbolScreen
33-
import be.scri.ui.screens.DownloadDataScreen
3434
import be.scri.ui.screens.InstallationScreen
3535
import be.scri.ui.screens.LanguageSettingsScreen
3636
import be.scri.ui.screens.PrivacyPolicyScreen
3737
import be.scri.ui.screens.SelectTranslationSourceLanguageScreen
3838
import be.scri.ui.screens.ThirdPartyScreen
3939
import be.scri.ui.screens.WikimediaScreen
4040
import be.scri.ui.screens.about.AboutScreen
41+
import be.scri.ui.screens.download.DataDownloadViewModel
42+
import be.scri.ui.screens.download.DownloadDataScreen
4143
import be.scri.ui.screens.settings.SettingsScreen
4244
import be.scri.ui.theme.ScribeTheme
4345
import kotlinx.coroutines.CoroutineScope
@@ -60,7 +62,8 @@ import kotlinx.coroutines.launch
6062
* @param isDarkTheme Flag to indicate if dark theme is enabled.
6163
* @param modifier Optional layout modifier for UI customization.
6264
*/
63-
@SuppressLint("ComposeModifierMissing")
65+
@Suppress("LongParameterList")
66+
@SuppressLint("ComposeModifierMissing", "LongParameterList")
6467
@Composable
6568
fun ScribeApp(
6669
pagerState: PagerState,
@@ -72,9 +75,12 @@ fun ScribeApp(
7275
context: Context,
7376
isDarkTheme: Boolean,
7477
modifier: Modifier = Modifier,
78+
downloadViewModel: DataDownloadViewModel = viewModel(),
7579
) {
7680
val coroutineScope = rememberCoroutineScope()
7781
val navBackStackEntry by navController.currentBackStackEntryAsState()
82+
val downloadStates = downloadViewModel.downloadStates
83+
val onDownloadAction = downloadViewModel::handleDownloadAction
7884

7985
ScribeTheme(
8086
useDarkTheme = isDarkTheme,
@@ -199,6 +205,13 @@ fun ScribeApp(
199205
onBackNavigation = {
200206
navController.popBackStack()
201207
},
208+
onNavigateToTranslation = { language ->
209+
navController.navigate(
210+
"translation_language_detail/$language",
211+
)
212+
},
213+
downloadStates = downloadStates,
214+
onDownloadAction = onDownloadAction,
202215
modifier = Modifier.padding(innerPadding),
203216
)
204217
}
@@ -229,6 +242,10 @@ fun ScribeApp(
229242
onBackNavigation = {
230243
navController.popBackStack()
231244
},
245+
onNavigateToDownloadData = {
246+
navController.popBackStack()
247+
},
248+
onDownloadAction = onDownloadAction,
232249
modifier = Modifier.padding(innerPadding),
233250
currentLanguage = language,
234251
)

app/src/main/java/be/scri/extensions/CommonsContext.kt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,15 @@ import be.scri.helpers.PREFS_KEY
99
/**
1010
* Retrieves the shared preferences using the predefined PREFS_KEY.
1111
*
12-
* @receiver Context used to access shared preferences
13-
* @return SharedPreferences instance
12+
* @receiver Context used to access shared preferences.
13+
* @return SharedPreferences instance.
1414
*/
1515
fun Context.getSharedPrefs() = getSharedPreferences(PREFS_KEY, Context.MODE_PRIVATE)
1616

1717
/**
1818
* Provides an instance of BaseConfig associated with the context.
1919
*
20-
* @receiver Context used to create BaseConfig instance
21-
* @return BaseConfig instance
20+
* @receiver Context used to create BaseConfig instance.
21+
* @return BaseConfig instance.
2222
*/
2323
val Context.baseConfig: BaseConfig get() = BaseConfig.newInstance(this)

app/src/main/java/be/scri/extensions/ContextStyling.kt

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ import be.scri.helpers.DARK_GREY
1313
/**
1414
* Retrieves the appropriate text color based on the user's theme settings.
1515
*
16-
* @receiver Context used to access resources and configuration
17-
* @return Int representing the text color
16+
* @receiver Context used to access resources and configuration.
17+
* @return Int representing the text color.
1818
*/
1919
fun Context.getProperTextColor() =
2020
if (baseConfig.isUsingSystemTheme) {
@@ -26,8 +26,8 @@ fun Context.getProperTextColor() =
2626
/**
2727
* Retrieves the appropriate key color based on the user's theme settings.
2828
*
29-
* @receiver Context used to access resources and configuration
30-
* @return Int representing the key color
29+
* @receiver Context used to access resources and configuration.
30+
* @return Int representing the key color.
3131
*/
3232

3333
fun Context.getProperKeyColor() =
@@ -40,8 +40,8 @@ fun Context.getProperKeyColor() =
4040
/**
4141
* Retrieves the appropriate background color based on the user's theme settings.
4242
*
43-
* @receiver Context used to access resources and configuration
44-
* @return Int representing the background color
43+
* @receiver Context used to access resources and configuration.
44+
* @return Int representing the background color.
4545
*/
4646
fun Context.getProperBackgroundColor() =
4747
if (baseConfig.isUsingSystemTheme) {
@@ -53,8 +53,8 @@ fun Context.getProperBackgroundColor() =
5353
/**
5454
* Retrieves the appropriate primary color based on the user's theme settings.
5555
*
56-
* @receiver Context used to access resources and configuration
57-
* @return Int representing the primary color
56+
* @receiver Context used to access resources and configuration.
57+
* @return Int representing the primary color.
5858
*/
5959
fun Context.getProperPrimaryColor() =
6060
when {
@@ -66,8 +66,8 @@ fun Context.getProperPrimaryColor() =
6666
/**
6767
* Determines if the current theme is black and white.
6868
*
69-
* @receiver Context used to access configuration
70-
* @return Boolean indicating if the theme is black and white
69+
* @receiver Context used to access configuration.
70+
* @return Boolean indicating if the theme is black and white.
7171
*/
7272
fun Context.isBlackAndWhiteTheme() =
7373
baseConfig.textColor == Color.WHITE &&
@@ -77,8 +77,8 @@ fun Context.isBlackAndWhiteTheme() =
7777
/**
7878
* Determines if the current theme is white.
7979
*
80-
* @receiver Context used to access configuration
81-
* @return Boolean indicating if the theme is white
80+
* @receiver Context used to access configuration.
81+
* @return Boolean indicating if the theme is white.
8282
*/
8383

8484
fun Context.isWhiteTheme() =
@@ -89,7 +89,7 @@ fun Context.isWhiteTheme() =
8989
/**
9090
* Determines if the system is using a dark theme.
9191
*
92-
* @receiver Context used to access configuration
93-
* @return Boolean indicating if the system is using a dark theme
92+
* @receiver Context used to access configuration.
93+
* @return Boolean indicating if the system is using a dark theme.
9494
*/
9595
fun Context.isUsingSystemDarkTheme() = resources.configuration.uiMode and Configuration.UI_MODE_NIGHT_YES != 0

app/src/main/java/be/scri/extensions/Drawable.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import android.graphics.drawable.Drawable
99
* Applies a color filter to the drawable using the specified color.
1010
*
1111
* @param color The color to apply using the SRC_IN mode.
12+
*
1213
* @return The mutated [Drawable] with the color filter applied.
1314
*/
1415
fun Drawable.applyColorFilter(color: Int) = mutate().setColorFilter(color, PorterDuff.Mode.SRC_IN)

app/src/main/java/be/scri/extensions/Int.kt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ fun Int.getContrastColor(): Int {
3434
*
3535
* @receiver Int The color to adjust.
3636
* @param factor Float The factor to multiply the alpha by (0f = fully transparent, 1f = original alpha).
37+
*
3738
* @return Int The color with modified alpha.
3839
*/
3940
fun Int.adjustAlpha(factor: Float): Int {
@@ -62,6 +63,7 @@ private const val FACTOR_DIVIDER = 100
6263
*
6364
* @receiver Int The original color.
6465
* @param factor Int The factor to darken the color by (default is 8).
66+
*
6567
* @return Int The darkened color.
6668
*/
6769

@@ -87,6 +89,7 @@ fun Int.darkenColor(factor: Int = DEFAULT_DARKEN_FACTOR): Int {
8789
*
8890
* @receiver Int The original color.
8991
* @param factor Int The factor to lighten the color by (default is 8).
92+
*
9093
* @return Int The lightened color.
9194
*/
9295

@@ -113,6 +116,7 @@ private const val LIGHTNESS_THRESHOLD = 0.5f
113116
* Converts a color from HSL to HSV.
114117
*
115118
* @param hsl FloatArray The color in HSL format.
119+
*
116120
* @return FloatArray The converted color in HSV format.
117121
*/
118122
private fun hsl2hsv(hsl: FloatArray): FloatArray {
@@ -127,6 +131,7 @@ private fun hsl2hsv(hsl: FloatArray): FloatArray {
127131
* Converts a color from HSV to HSL.
128132
*
129133
* @param hsv FloatArray The color in HSV format.
134+
*
130135
* @return FloatArray The converted color in HSL format.
131136
*/
132137

app/src/main/java/be/scri/helpers/AlphanumericComparator.kt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ class AlphanumericComparator {
1616
*
1717
* @param string1 The first string to compare.
1818
* @param string2 The second string to compare.
19+
*
1920
* @return A negative integer if `string1` comes before `string2`,
2021
* a positive integer if `string1` comes after `string2`,
2122
* and zero if they are equal.
@@ -67,6 +68,7 @@ class AlphanumericComparator {
6768
* @param string The input string.
6869
* @param length The total length of the string.
6970
* @param marker The current position in the string from where extraction starts.
71+
*
7072
* @return A substring representing a numeric or alphabetic chunk.
7173
*/
7274
private fun getChunk(
@@ -105,7 +107,8 @@ class AlphanumericComparator {
105107
* Checks if the given character is a numeric digit.
106108
*
107109
* @param ch The character to check.
108-
* @return `true` if the character is a digit (0-9), `false` otherwise.
110+
*
111+
* @return true if the character is a digit (0-9), false otherwise.
109112
*/
110113
private fun isDigit(ch: Char) = ch in '0'..'9'
111114
}

app/src/main/java/be/scri/helpers/AnnotationTextUtils.kt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@ import be.scri.helpers.LanguageMappingConstants.prepAnnotationConversionDict
1717
object AnnotationTextUtils {
1818
/**
1919
* Maps a case annotation string (e.g., "genitive case") to a displayable text and color.
20+
*
2021
* @param nounType The case annotation string.
22+
*
2123
* @return A pair containing the color resource ID and the display text.
2224
*/
2325
fun handleTextForCaseAnnotation(
@@ -40,7 +42,9 @@ object AnnotationTextUtils {
4042

4143
/**
4244
* Maps a noun type string (e.g., "masculine") to a displayable text and color.
45+
*
4346
* @param nounType The noun type or gender string.
47+
*
4448
* @return A pair containing the color resource ID and the display text.
4549
*/
4650
fun handleColorAndTextForNounType(
@@ -62,8 +66,10 @@ object AnnotationTextUtils {
6266

6367
/**
6468
* Processes a noun gender abbreviation for display, converting it based on language-specific conventions.
69+
*
6570
* @param language The current keyboard language.
6671
* @param text The gender abbreviation (e.g., "M", "F", "N").
72+
*
6773
* @return The language-specific display text (e.g., "М" for Russian masculine).
6874
*/
6975
fun processValueForNouns(
@@ -73,8 +79,10 @@ object AnnotationTextUtils {
7379

7480
/**
7581
* Processes a preposition case abbreviation for display, converting it based on language-specific conventions.
82+
*
7683
* @param language The current keyboard language.
7784
* @param text The case abbreviation (e.g., "Acc", "Dat").
85+
*
7886
* @return The language-specific display text (e.g., "Akk" for German accusative).
7987
*/
8088
fun processValuesForPreposition(

app/src/main/java/be/scri/helpers/BaseConfig.kt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,8 @@ import be.scri.extensions.getSharedPrefs
88

99
/**
1010
* A configuration helper class for managing app settings.
11-
* <p>
1211
* This class provides access to various UI-related preferences such as colors, language settings,
1312
* and theme preferences. Preferences are stored using `SharedPreferences`.
14-
* </p>
1513
*
1614
* @param context The application context used to retrieve resources and shared preferences.
1715
*/
@@ -28,6 +26,7 @@ open class BaseConfig(
2826
* Creates a new instance of `BaseConfig`.
2927
*
3028
* @param context The application context.
29+
*
3130
* @return A new instance of `BaseConfig`.
3231
*/
3332
fun newInstance(context: Context) = BaseConfig(context)

app/src/main/java/be/scri/helpers/DatabaseFileManager.kt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import java.io.IOException
1212
/**
1313
* Manages access to all SQLite database files.
1414
* Ensures DB files are copied from assets and provides read-only connections.
15+
*
1516
* @param context The application context.
1617
*/
1718
class DatabaseFileManager(
@@ -31,6 +32,7 @@ class DatabaseFileManager(
3132
* It handles copying the database from assets if it doesn't exist locally.
3233
*
3334
* @param language The language code (e.g., "DE", "FR") used to determine the database filename.
35+
*
3436
* @return An open, read-only [SQLiteDatabase] instance, or `null` on failure.
3537
*/
3638
fun getLanguageDatabase(language: String): SQLiteDatabase? {
@@ -56,6 +58,7 @@ class DatabaseFileManager(
5658
* @param dbName The filename of the database (e.g., "ENLanguageData.sqlite").
5759
* @param assetPath The path to the database file within the app's assets folder
5860
* (e.g., "data/ENLanguageData.sqlite").
61+
*
5962
* @return An open, read-only [SQLiteDatabase], or `null` if copying or opening fails.
6063
*/
6164
private fun getDatabase(
@@ -85,7 +88,8 @@ class DatabaseFileManager(
8588
*
8689
* @param dbFile The destination [File] in the app's database directory.
8790
* @param assetPath The path to the source file within the assets folder.
88-
* @return `true` if the copy was successful, `false` otherwise.
91+
*
92+
* @return true if the copy was successful, false otherwise.
8993
*/
9094
private fun copyDatabaseFromAssets(
9195
dbFile: File,

app/src/main/java/be/scri/helpers/DatabaseManagers.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ class DatabaseManagers(
4141
* It delegates the loading and parsing logic to the [ContractDataLoader].
4242
*
4343
* @param language The language code (e.g., "DE", "FR") for which to load the contract.
44+
*
4445
* @return A [DataContract] object containing the language's structural metadata, or `null`
4546
* if not found or on error.
4647
*/

0 commit comments

Comments
 (0)