Skip to content

Commit 1b6c847

Browse files
author
Mihai-Cristian Condrea
committed
refactor: Improved error handling, updated copyright, and enhanced code clarity
Significantly improved error handling and user experience: - Enhanced the app's error handling mechanism with informative error dialogs for a better user experience. - Updated the copyright string in the project files. - Enhanced code clarity by adding explicit type annotations and cleaning up unnecessary lint suppressions. - Updated the changelog to document the new feature and related improvements.
1 parent a7dee8b commit 1b6c847

File tree

11 files changed

+127
-124
lines changed

11 files changed

+127
-124
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
# Version 1.1.3:
2+
3+
- **Minor**: Enhanced the app's error handling mechanism for a better user experience.
4+
15
# Version 1.1.2:
26

37
- **Minor**: Updated the app to support the latest changes in the API.

app/build.gradle.kts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ android {
1919
applicationId = "com.d4rk.androidtutorials"
2020
minSdk = 23
2121
targetSdk = 35
22-
versionCode = 105
23-
versionName = "1.1.2"
22+
versionCode = 106
23+
versionName = "1.1.3"
2424
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
2525
resourceConfigurations += listOf(
2626
"en" ,

app/src/main/kotlin/com/d4rk/androidtutorials/ui/screens/settings/about/AboutSettingsComposable.kt

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -34,29 +34,28 @@ fun AboutSettingsComposable(activity : AboutSettingsActivity) {
3434
val changelogHtmlString = htmlData.value.first
3535
val eulaHtmlString = htmlData.value.second
3636

37-
TopAppBarScaffoldWithBackButton(
38-
title = stringResource(id = R.string.about) ,
39-
onBackClicked = { activity.finish() }) { paddingValues ->
40-
Box(modifier = Modifier.padding(paddingValues)) {
37+
TopAppBarScaffoldWithBackButton(title = stringResource(id = R.string.about) ,
38+
onBackClicked = { activity.finish() }) { paddingValues ->
39+
Box(modifier = Modifier.padding(paddingValues = paddingValues)) {
4140
LazyColumn(
4241
modifier = Modifier.fillMaxHeight()
4342
) {
44-
item(key = "app_info_category") {
43+
item {
4544
PreferenceCategoryItem(title = stringResource(id = R.string.app_info))
4645
}
47-
item(key = "app_name") {
46+
item {
4847
PreferenceItem(
4948
title = stringResource(id = R.string.app_name) ,
5049
summary = stringResource(id = R.string.copyright) ,
5150
)
5251
}
53-
item(key = "app_build_version") {
52+
item {
5453
PreferenceItem(
5554
title = stringResource(id = R.string.app_build_version) ,
5655
summary = "${BuildConfig.VERSION_NAME} (${BuildConfig.VERSION_CODE})"
5756
)
5857
}
59-
item(key = "oss_licenses") {
58+
item {
6059
PreferenceItem(title = stringResource(R.string.oss_license_title) ,
6160
summary = stringResource(id = R.string.summary_preference_settings_oss) ,
6261
onClick = {
@@ -67,10 +66,10 @@ fun AboutSettingsComposable(activity : AboutSettingsActivity) {
6766
)
6867
})
6968
}
70-
item(key = "device_info_category") {
69+
item {
7170
PreferenceCategoryItem(title = stringResource(id = R.string.device_info))
7271
}
73-
item(key = "device_info") {
72+
item {
7473
val version : String = stringResource(
7574
id = R.string.app_build ,
7675
"${stringResource(id = R.string.manufacturer)} ${Build.MANUFACTURER}" ,
@@ -89,11 +88,12 @@ fun AboutSettingsComposable(activity : AboutSettingsActivity) {
8988
label = "Device Info" ,
9089
text = version ,
9190
onShowSnackbar = {
92-
showSnackbar = true
93-
})
91+
showSnackbar = true
92+
})
9493
})
9594
}
9695
}
96+
9797
Snackbar(message = stringResource(id = R.string.snack_device_info_copied) ,
9898
showSnackbar = showSnackbar ,
9999
onDismiss = { showSnackbar = false })

app/src/main/kotlin/com/d4rk/androidtutorials/ui/screens/settings/display/DisplaySettingsComposable.kt

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ import com.d4rk.androidtutorials.ui.components.navigation.TopAppBarScaffoldWithB
3535
import com.d4rk.androidtutorials.ui.screens.settings.display.theme.ThemeSettingsActivity
3636
import com.d4rk.androidtutorials.utils.helpers.IntentsHelper
3737
import kotlinx.coroutines.CoroutineScope
38-
import kotlinx.coroutines.Dispatchers
3938
import kotlinx.coroutines.launch
4039

4140
@Composable
@@ -57,15 +56,15 @@ fun DisplaySettingsComposable(activity : DisplaySettingsActivity) {
5756

5857

5958
val isDynamicColors : State<Boolean> = dataStore.dynamicColors.collectAsState(initial = true)
60-
val scope : CoroutineScope = rememberCoroutineScope()
59+
val coroutineScope : CoroutineScope = rememberCoroutineScope()
6160

6261
TopAppBarScaffoldWithBackButton(
6362
title = stringResource(id = R.string.display) ,
6463
onBackClicked = { activity.finish() }) { paddingValues ->
6564
LazyColumn(
6665
modifier = Modifier
6766
.fillMaxHeight()
68-
.padding(paddingValues) ,
67+
.padding(paddingValues = paddingValues) ,
6968
) {
7069
item {
7170
PreferenceCategoryItem(title = stringResource(id = R.string.appearance))
@@ -76,14 +75,14 @@ fun DisplaySettingsComposable(activity : DisplaySettingsActivity) {
7675
switchState.value = isChecked
7776
} ,
7877
onSwitchClick = { isChecked ->
79-
scope.launch(Dispatchers.IO) {
78+
coroutineScope.launch {
8079
if (isChecked) {
81-
dataStore.saveThemeMode(darkModeString)
80+
dataStore.saveThemeMode(mode = darkModeString)
8281
dataStore.themeModeState.value =
8382
darkModeString
8483
}
8584
else {
86-
dataStore.saveThemeMode(lightModeString)
85+
dataStore.saveThemeMode(mode = lightModeString)
8786
dataStore.themeModeState.value =
8887
lightModeString
8988
}
@@ -101,8 +100,8 @@ fun DisplaySettingsComposable(activity : DisplaySettingsActivity) {
101100
summary = stringResource(id = R.string.summary_preference_settings_dynamic_colors) ,
102101
checked = isDynamicColors.value ,
103102
) { isChecked ->
104-
CoroutineScope(Dispatchers.IO).launch {
105-
dataStore.saveDynamicColors(isChecked)
103+
coroutineScope.launch {
104+
dataStore.saveDynamicColors(isChecked = isChecked)
106105
}
107106
}
108107
}
@@ -114,8 +113,8 @@ fun DisplaySettingsComposable(activity : DisplaySettingsActivity) {
114113
summary = stringResource(id = R.string.summary_preference_settings_bounce_buttons) ,
115114
checked = bouncyButtons ,
116115
) { isChecked ->
117-
CoroutineScope(Dispatchers.IO).launch {
118-
dataStore.saveBouncyButtons(isChecked)
116+
coroutineScope.launch {
117+
dataStore.saveBouncyButtons(isChecked = isChecked)
119118
}
120119
}
121120
}
@@ -129,8 +128,8 @@ fun DisplaySettingsComposable(activity : DisplaySettingsActivity) {
129128
SelectStartupScreenAlertDialog(dataStore = dataStore ,
130129
onDismiss = { showStartupDialog = false } ,
131130
onStartupSelected = { selectedStartup ->
132-
scope.launch {
133-
dataStore.saveStartupPage(selectedStartup)
131+
coroutineScope.launch {
132+
dataStore.saveStartupPage(startupPage = selectedStartup)
134133
}
135134
})
136135
}

app/src/main/kotlin/com/d4rk/androidtutorials/ui/screens/settings/display/theme/ThemeSettingsComposable.kt

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package com.d4rk.androidtutorials.ui.screens.settings.display.theme
22

3-
import android.content.Context
43
import androidx.compose.foundation.layout.Box
54
import androidx.compose.foundation.layout.Column
65
import androidx.compose.foundation.layout.Row
@@ -22,7 +21,6 @@ import androidx.compose.runtime.collectAsState
2221
import androidx.compose.runtime.rememberCoroutineScope
2322
import androidx.compose.ui.Alignment
2423
import androidx.compose.ui.Modifier
25-
import androidx.compose.ui.platform.LocalContext
2624
import androidx.compose.ui.res.stringResource
2725
import androidx.compose.ui.unit.dp
2826
import com.d4rk.androidtutorials.R
@@ -32,14 +30,12 @@ import com.d4rk.androidtutorials.ui.components.preferences.SwitchCardComposable
3230
import com.d4rk.androidtutorials.ui.components.modifiers.bounceClick
3331
import com.d4rk.androidtutorials.ui.components.navigation.TopAppBarScaffoldWithBackButton
3432
import kotlinx.coroutines.CoroutineScope
35-
import kotlinx.coroutines.Dispatchers
3633
import kotlinx.coroutines.launch
3734

3835
@Composable
3936
fun ThemeSettingsComposable(activity : ThemeSettingsActivity) {
40-
val context : Context = LocalContext.current
4137
val dataStore : DataStore = AppCoreManager.dataStore
42-
val scope : CoroutineScope = rememberCoroutineScope()
38+
val coroutineScope : CoroutineScope = rememberCoroutineScope()
4339
val themeMode : String = dataStore.themeMode.collectAsState(initial = "follow_system").value
4440
val isAmoledMode : State<Boolean> = dataStore.amoledMode.collectAsState(initial = false)
4541

@@ -48,22 +44,21 @@ fun ThemeSettingsComposable(activity : ThemeSettingsActivity) {
4844
stringResource(id = R.string.dark_mode) ,
4945
stringResource(id = R.string.light_mode) ,
5046
)
51-
TopAppBarScaffoldWithBackButton(
52-
title = stringResource(id = R.string.dark_theme) ,
53-
onBackClicked = { activity.finish() }) { paddingValues ->
47+
TopAppBarScaffoldWithBackButton(title = stringResource(id = R.string.dark_theme) ,
48+
onBackClicked = { activity.finish() }) { paddingValues ->
5449
Box(modifier = Modifier.fillMaxSize()) {
5550
LazyColumn(
5651
modifier = Modifier
5752
.fillMaxSize()
58-
.padding(paddingValues) ,
53+
.padding(paddingValues = paddingValues) ,
5954
) {
6055
item {
6156
SwitchCardComposable(
6257
title = stringResource(id = R.string.amoled_mode) ,
6358
switchState = isAmoledMode
6459
) { isChecked ->
65-
scope.launch(Dispatchers.IO) {
66-
dataStore.saveAmoledMode(isChecked)
60+
coroutineScope.launch {
61+
dataStore.saveAmoledMode(isChecked = isChecked)
6762
}
6863
}
6964
}
@@ -81,8 +76,8 @@ fun ThemeSettingsComposable(activity : ThemeSettingsActivity) {
8176
RadioButton(modifier = Modifier.bounceClick() ,
8277
selected = (text == themeMode) ,
8378
onClick = {
84-
scope.launch(Dispatchers.IO) {
85-
dataStore.saveThemeMode(text)
79+
coroutineScope.launch {
80+
dataStore.saveThemeMode(mode = text)
8681
dataStore.themeModeState.value = text
8782
}
8883
})
@@ -99,10 +94,10 @@ fun ThemeSettingsComposable(activity : ThemeSettingsActivity) {
9994
Column(
10095
modifier = Modifier
10196
.fillMaxWidth()
102-
.padding(24.dp)
97+
.padding(all = 24.dp)
10398
) {
10499
Icon(imageVector = Icons.Outlined.Info , contentDescription = null)
105-
Spacer(modifier = Modifier.height(24.dp))
100+
Spacer(modifier = Modifier.height(height = 24.dp))
106101
Text(text = stringResource(id = R.string.summary_dark_theme))
107102
}
108103
}

app/src/main/kotlin/com/d4rk/androidtutorials/ui/screens/settings/privacy/PrivacySettingsComposable.kt

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -20,59 +20,61 @@ import com.d4rk.androidtutorials.utils.helpers.IntentsHelper
2020
@Composable
2121
fun PrivacySettingsComposable(activity : PrivacySettingsActivity) {
2222
val context : Context = LocalContext.current
23-
TopAppBarScaffoldWithBackButton(
24-
title = stringResource(id = R.string.security_and_privacy) ,
25-
onBackClicked = { activity.finish() }) { paddingValues ->
23+
TopAppBarScaffoldWithBackButton(title = stringResource(id = R.string.security_and_privacy) ,
24+
onBackClicked = { activity.finish() }) { paddingValues ->
2625
LazyColumn(
2726
modifier = Modifier
2827
.fillMaxHeight()
29-
.padding(paddingValues) ,
28+
.padding(paddingValues = paddingValues) ,
3029
) {
3130
item {
3231
PreferenceCategoryItem(title = stringResource(id = R.string.privacy))
3332
PreferenceItem(title = stringResource(id = R.string.privacy_policy) ,
3433
summary = stringResource(id = R.string.summary_preference_settings_privacy_policy) ,
3534
onClick = {
3635
IntentsHelper.openUrl(
37-
context ,
36+
context = context ,
3837
url = "https://sites.google.com/view/d4rk7355608/more/apps/privacy-policy"
3938
)
4039
})
4140
PreferenceItem(title = stringResource(id = R.string.terms_of_service) ,
4241
summary = stringResource(id = R.string.summary_preference_settings_terms_of_service) ,
4342
onClick = {
4443
IntentsHelper.openUrl(
45-
context ,
44+
context = context ,
4645
url = "https://sites.google.com/view/d4rk7355608/more/apps/terms-of-service"
4746
)
4847
})
4948
PreferenceItem(title = stringResource(id = R.string.code_of_conduct) ,
5049
summary = stringResource(id = R.string.summary_preference_settings_code_of_conduct) ,
5150
onClick = {
5251
IntentsHelper.openUrl(
53-
context ,
52+
context = context ,
5453
url = "https://sites.google.com/view/d4rk7355608/more/code-of-conduct"
5554
)
5655
})
5756
PreferenceItem(title = stringResource(id = R.string.permissions) ,
5857
summary = stringResource(id = R.string.summary_preference_settings_permissions) ,
5958
onClick = {
6059
IntentsHelper.openActivity(
61-
context , PermissionsSettingsActivity::class.java
60+
context = context ,
61+
activityClass = PermissionsSettingsActivity::class.java
6262
)
6363
})
6464
PreferenceItem(title = stringResource(id = R.string.ads) ,
6565
summary = stringResource(id = R.string.summary_preference_settings_ads) ,
6666
onClick = {
6767
IntentsHelper.openActivity(
68-
context , AdsSettingsActivity::class.java
68+
context = context ,
69+
activityClass = AdsSettingsActivity::class.java
6970
)
7071
})
7172
PreferenceItem(title = stringResource(id = R.string.usage_and_diagnostics) ,
7273
summary = stringResource(id = R.string.summary_preference_settings_usage_and_diagnostics) ,
7374
onClick = {
7475
IntentsHelper.openActivity(
75-
context , UsageAndDiagnosticsActivity::class.java
76+
context = context ,
77+
activityClass = UsageAndDiagnosticsActivity::class.java
7678
)
7779
})
7880
}
@@ -82,15 +84,16 @@ fun PrivacySettingsComposable(activity : PrivacySettingsActivity) {
8284
summary = stringResource(id = R.string.summary_preference_settings_legal_notices) ,
8385
onClick = {
8486
IntentsHelper.openUrl(
85-
context ,
87+
context = context ,
8688
url = "https://sites.google.com/view/d4rk7355608/more/apps/legal-notices"
8789
)
8890
})
8991
PreferenceItem(title = stringResource(id = R.string.license) ,
9092
summary = stringResource(id = R.string.summary_preference_settings_license) ,
9193
onClick = {
9294
IntentsHelper.openUrl(
93-
context , url = "https://www.gnu.org/licenses/gpl-3.0"
95+
context = context ,
96+
url = "https://www.gnu.org/licenses/gpl-3.0"
9497
)
9598
})
9699
}

0 commit comments

Comments
 (0)