feat: Add new app announcement

This commit is contained in:
Myzel394 2024-04-26 14:36:10 +02:00
parent 84da393e0d
commit fe73d7dfbb
No known key found for this signature in database
GPG Key ID: DEC4AAB876F73185
10 changed files with 51 additions and 0 deletions

View File

@ -322,6 +322,9 @@ Maybe this can be labeled better? Let me know. It should be something that can d
<string name="settings_view_source_code">View source code</string> <string name="settings_view_source_code">View source code</string>
<string name="time_zone_add_title">Add time zone</string> <string name="time_zone_add_title">Add time zone</string>
<string name="settings_numberhub_newApp">Unitto is now NumberHub!</string>
<string name="settings_numberhub_newApp_message">Unitto has been discontinued. You\'re one of the first users to try NumberHub! Please spread the word and share the app with your friends. Thank you for your support!</string>
<!-- https://s3.eu-west-1.amazonaws.com/po-pub/i/UCrz06kaEYxCGAE73ZLl9EtX.png --> <!-- https://s3.eu-west-1.amazonaws.com/po-pub/i/UCrz06kaEYxCGAE73ZLl9EtX.png -->
<string name="time_zone_no_results_button">Read the article</string> <string name="time_zone_no_results_button">Read the article</string>

View File

@ -99,4 +99,6 @@ interface UserPreferencesRepository {
suspend fun updateAdditionalButtons(enabled: Boolean) suspend fun updateAdditionalButtons(enabled: Boolean)
suspend fun updateInverseMode(enabled: Boolean) suspend fun updateInverseMode(enabled: Boolean)
suspend fun updateHasSeenNewAppAnnouncement(value: Boolean)
} }

View File

@ -21,4 +21,5 @@ package app.myzel394.numberhub.data.model.userprefs
interface GeneralPreferences { interface GeneralPreferences {
val lastReadChangelog: String val lastReadChangelog: String
val enableVibrations: Boolean val enableVibrations: Boolean
val hasSeenNewAppAnnouncement: Boolean
} }

View File

@ -77,6 +77,10 @@ internal fun Preferences.getRadianMode(): Boolean {
return this[PrefsKeys.RADIAN_MODE] ?: true return this[PrefsKeys.RADIAN_MODE] ?: true
} }
internal fun Preferences.getHasSeenNewAppAnnouncement(): Boolean {
return this[PrefsKeys.HAS_SEEN_NEW_APP_ANNOUNCEMENT] ?: false
}
internal fun Preferences.getFormatterSymbols(): FormatterSymbols { internal fun Preferences.getFormatterSymbols(): FormatterSymbols {
val grouping = this[PrefsKeys.FORMATTER_GROUPING] val grouping = this[PrefsKeys.FORMATTER_GROUPING]
val fractional = this[PrefsKeys.FORMATTER_FRACTIONAL] val fractional = this[PrefsKeys.FORMATTER_FRACTIONAL]

View File

@ -50,6 +50,7 @@ data class AppPreferencesImpl(
data class GeneralPreferencesImpl( data class GeneralPreferencesImpl(
override val lastReadChangelog: String, override val lastReadChangelog: String,
override val enableVibrations: Boolean, override val enableVibrations: Boolean,
override val hasSeenNewAppAnnouncement: Boolean,
) : GeneralPreferences ) : GeneralPreferences
data class CalculatorPreferencesImpl( data class CalculatorPreferencesImpl(

View File

@ -37,6 +37,7 @@ object PrefsKeys {
val ENABLE_VIBRATIONS = booleanPreferencesKey("ENABLE_VIBRATIONS_PREF_KEY") val ENABLE_VIBRATIONS = booleanPreferencesKey("ENABLE_VIBRATIONS_PREF_KEY")
val MIDDLE_ZERO = booleanPreferencesKey("MIDDLE_ZERO_PREF_KEY") val MIDDLE_ZERO = booleanPreferencesKey("MIDDLE_ZERO_PREF_KEY")
val AC_BUTTON = booleanPreferencesKey("AC_BUTTON_PREF_KEY") val AC_BUTTON = booleanPreferencesKey("AC_BUTTON_PREF_KEY")
val HAS_SEEN_NEW_APP_ANNOUNCEMENT = booleanPreferencesKey("HAS_SEEN_NEW_APP_ANNOUNCEMENT_PREF_KEY")
// val RPN_MODE = booleanPreferencesKey("RPN_MODE_PREF_KEY") // val RPN_MODE = booleanPreferencesKey("RPN_MODE_PREF_KEY")
// FORMATTER // FORMATTER

View File

@ -70,6 +70,7 @@ class UserPreferencesRepositoryImpl @Inject constructor(
GeneralPreferencesImpl( GeneralPreferencesImpl(
lastReadChangelog = preferences.getLastReadChangelog(), lastReadChangelog = preferences.getLastReadChangelog(),
enableVibrations = preferences.getEnableVibrations(), enableVibrations = preferences.getEnableVibrations(),
hasSeenNewAppAnnouncement = preferences.getHasSeenNewAppAnnouncement(),
) )
} }
@ -325,4 +326,10 @@ class UserPreferencesRepositoryImpl @Inject constructor(
preferences[PrefsKeys.INVERSE_MODE] = enabled preferences[PrefsKeys.INVERSE_MODE] = enabled
} }
} }
override suspend fun updateHasSeenNewAppAnnouncement(value: Boolean) {
dataStore.edit { preferences ->
preferences[PrefsKeys.HAS_SEEN_NEW_APP_ANNOUNCEMENT] = value
}
}
} }

View File

@ -50,6 +50,7 @@ import androidx.compose.material.icons.filled.RateReview
import androidx.compose.material.icons.filled.SwapHoriz import androidx.compose.material.icons.filled.SwapHoriz
import androidx.compose.material.icons.filled.Vibration import androidx.compose.material.icons.filled.Vibration
import androidx.compose.material.icons.filled._123 import androidx.compose.material.icons.filled._123
import androidx.compose.material.icons.outlined.CheckCircle
import androidx.compose.material.icons.outlined.NewReleases import androidx.compose.material.icons.outlined.NewReleases
import androidx.compose.material3.CircularProgressIndicator import androidx.compose.material3.CircularProgressIndicator
import androidx.compose.material3.DropdownMenu import androidx.compose.material3.DropdownMenu
@ -119,6 +120,7 @@ internal fun SettingsRoute(
uiState = uiState, uiState = uiState,
openDrawer = openDrawer, openDrawer = openDrawer,
navControllerAction = navControllerAction, navControllerAction = navControllerAction,
onHasSeenNewAppAnnouncement = viewModel::updateHasSeenNewAppAnnouncement,
updateLastReadChangelog = viewModel::updateLastReadChangelog, updateLastReadChangelog = viewModel::updateLastReadChangelog,
updateVibrations = viewModel::updateVibrations, updateVibrations = viewModel::updateVibrations,
clearCache = viewModel::clearCache, clearCache = viewModel::clearCache,
@ -135,6 +137,7 @@ private fun SettingsScreen(
navControllerAction: (String) -> Unit, navControllerAction: (String) -> Unit,
updateLastReadChangelog: (String) -> Unit, updateLastReadChangelog: (String) -> Unit,
updateVibrations: (Boolean) -> Unit, updateVibrations: (Boolean) -> Unit,
onHasSeenNewAppAnnouncement: (Boolean) -> Unit,
clearCache: () -> Unit, clearCache: () -> Unit,
backup: (Context, Uri) -> Unit, backup: (Context, Uri) -> Unit,
restore: (Context, Uri) -> Unit, restore: (Context, Uri) -> Unit,
@ -197,6 +200,25 @@ private fun SettingsScreen(
.verticalScroll(rememberScrollState()) .verticalScroll(rememberScrollState())
.padding(padding), .padding(padding),
) { ) {
AnimatedVisibility(
visible = !uiState.hasSeenNewAppAnnouncement,
enter = expandVertically() + fadeIn(),
exit = shrinkVertically() + fadeOut(),
) {
val title = stringResource(R.string.settings_numberhub_newApp)
AnnoyingBox(
modifier = Modifier
.padding(16.dp, 8.dp)
.fillMaxWidth(),
imageVector = Icons.Outlined.CheckCircle,
imageVectorContentDescription = title,
title = title,
support = stringResource(R.string.settings_numberhub_newApp_message),
) {
//onHasSeenNewAppAnnouncement(true)
}
}
AnimatedVisibility( AnimatedVisibility(
visible = uiState.showUpdateChangelog, visible = uiState.showUpdateChangelog,
enter = expandVertically() + fadeIn(), enter = expandVertically() + fadeIn(),
@ -339,6 +361,7 @@ private fun PreviewSettingsScreen() {
cacheSize = 2, cacheSize = 2,
backupInProgress = false, backupInProgress = false,
showUpdateChangelog = true, showUpdateChangelog = true,
hasSeenNewAppAnnouncement = false,
), ),
) )
} }
@ -347,6 +370,9 @@ private fun PreviewSettingsScreen() {
uiState = uiState, uiState = uiState,
openDrawer = {}, openDrawer = {},
navControllerAction = {}, navControllerAction = {},
onHasSeenNewAppAnnouncement = {
uiState = uiState.copy(hasSeenNewAppAnnouncement = true)
},
updateLastReadChangelog = { updateLastReadChangelog = {
uiState = uiState.copy(showUpdateChangelog = false) uiState = uiState.copy(showUpdateChangelog = false)
}, },

View File

@ -26,5 +26,6 @@ internal sealed class SettingsUIState {
val cacheSize: Int, val cacheSize: Int,
val backupInProgress: Boolean, val backupInProgress: Boolean,
val showUpdateChangelog: Boolean, val showUpdateChangelog: Boolean,
val hasSeenNewAppAnnouncement: Boolean,
) : SettingsUIState() ) : SettingsUIState()
} }

View File

@ -62,6 +62,7 @@ internal class SettingsViewModel @Inject constructor(
cacheSize = cacheSize, cacheSize = cacheSize,
backupInProgress = backupInProgress, backupInProgress = backupInProgress,
showUpdateChangelog = prefs.lastReadChangelog != BuildConfig.VERSION_CODE, showUpdateChangelog = prefs.lastReadChangelog != BuildConfig.VERSION_CODE,
hasSeenNewAppAnnouncement = prefs.hasSeenNewAppAnnouncement,
) )
} }
.stateIn(viewModelScope, SettingsUIState.Loading) .stateIn(viewModelScope, SettingsUIState.Loading)
@ -100,6 +101,10 @@ internal class SettingsViewModel @Inject constructor(
} }
} }
fun updateHasSeenNewAppAnnouncement(value: Boolean) = viewModelScope.launch {
userPrefsRepository.updateHasSeenNewAppAnnouncement(value)
}
/** /**
* @see UserPreferencesRepository.updateLastReadChangelog * @see UserPreferencesRepository.updateLastReadChangelog
*/ */