mirror of
https://github.com/IllusionMan1212/lyrics-grabbr.git
synced 2026-10-24 02:12:27 +00:00
show a one-time notice related to whitelisting apps
This commit is contained in:
@@ -116,6 +116,7 @@ class MainActivity : AppCompatActivity() {
|
||||
navController.navigate(Routes.Lyrics.route)
|
||||
},
|
||||
lyricsViewModel = lyricsViewModel,
|
||||
settingsViewModel = settingsViewModel,
|
||||
goBack = { finish() },
|
||||
lastNotification = lastNotification,
|
||||
)
|
||||
|
||||
+9
@@ -18,6 +18,7 @@ data class SettingsPreferences(
|
||||
val appTheme: Int = Theme.SYSTEM.ordinal,
|
||||
val whitelist: Set<String> = emptySet(),
|
||||
val keepScreenOn: Boolean = false,
|
||||
val whitelistPromptSeen: Boolean = false,
|
||||
)
|
||||
|
||||
class SettingsPreferencesRepository(
|
||||
@@ -27,6 +28,7 @@ class SettingsPreferencesRepository(
|
||||
private val APP_THEME = intPreferencesKey("app_theme")
|
||||
private val WHITELIST = stringSetPreferencesKey("apps_whitelist")
|
||||
private val KEEP_SCREEN_ON = booleanPreferencesKey("keep_screen_on")
|
||||
private val WHITELIST_PROMPT_SEEN = booleanPreferencesKey("whitelist_prompt_seen")
|
||||
}
|
||||
|
||||
val preferences = dataStore.data.map { mapSettingsPreferences(it) }
|
||||
@@ -55,11 +57,18 @@ class SettingsPreferencesRepository(
|
||||
}
|
||||
}
|
||||
|
||||
suspend fun discardWhitelistPrompt() {
|
||||
dataStore.edit { prefs ->
|
||||
prefs[WHITELIST_PROMPT_SEEN] = true
|
||||
}
|
||||
}
|
||||
|
||||
private fun mapSettingsPreferences(prefs: Preferences): SettingsPreferences {
|
||||
return SettingsPreferences(
|
||||
prefs[APP_THEME] ?: Theme.SYSTEM.ordinal,
|
||||
prefs[WHITELIST] ?: emptySet(),
|
||||
prefs[KEEP_SCREEN_ON] ?: false,
|
||||
prefs[WHITELIST_PROMPT_SEEN] ?: false,
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -87,6 +87,7 @@ import coil.compose.AsyncImage
|
||||
import com.illusionman1212.lyricsgrabbr.ui.components.forwardingPainter
|
||||
import com.illusionman1212.lyricsgrabbr.utils.annotatedStringResource
|
||||
import com.illusionman1212.lyricsgrabbr.viewmodels.LyricsViewModel
|
||||
import com.illusionman1212.lyricsgrabbr.viewmodels.SettingsViewModel
|
||||
import kotlinx.coroutines.launch
|
||||
|
||||
|
||||
@@ -100,6 +101,7 @@ fun HomePage(
|
||||
factory = HomeViewModel.Factory,
|
||||
),
|
||||
lyricsViewModel: LyricsViewModel,
|
||||
settingsViewModel: SettingsViewModel,
|
||||
lastNotification: MutableStateFlow<NotificationEvent?>
|
||||
) {
|
||||
val context = LocalContext.current
|
||||
@@ -115,6 +117,7 @@ fun HomePage(
|
||||
var songUri by remember { mutableStateOf(Uri.EMPTY) }
|
||||
var showBottomSheet by remember { mutableStateOf(false) }
|
||||
var listeningPermission = homeViewModel.getListeningPermission()
|
||||
val settingsState by settingsViewModel.uiState.collectAsStateWithLifecycle()
|
||||
var notificationPermission by remember { mutableStateOf(
|
||||
ActivityCompat.checkSelfPermission(context, POST_NOTIFICATIONS) == PERMISSION_GRANTED
|
||||
) }
|
||||
@@ -237,6 +240,30 @@ fun HomePage(
|
||||
modifier = Modifier.padding(bottom = 16.dp)
|
||||
)
|
||||
}
|
||||
} else if (!settingsState.whitelistPromptSeen) {
|
||||
LGAlertDialog(
|
||||
properties = DialogProperties(
|
||||
dismissOnBackPress = true,
|
||||
dismissOnClickOutside = true,
|
||||
),
|
||||
onDismiss = { settingsViewModel.discardWhitelistPrompt() },
|
||||
title = stringResource(id = R.string.whitelist_apps),
|
||||
buttons = {
|
||||
TextButton(
|
||||
onClick = {
|
||||
settingsViewModel.discardWhitelistPrompt()
|
||||
}
|
||||
) {
|
||||
Text(stringResource(id = R.string.understood))
|
||||
}
|
||||
}
|
||||
) {
|
||||
Text(
|
||||
text = stringResource(R.string.whitelist_prompt_desc),
|
||||
style = MaterialTheme.typography.bodyMedium,
|
||||
modifier = Modifier.padding(bottom = 16.dp)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
Column(
|
||||
@@ -248,7 +275,11 @@ fun HomePage(
|
||||
verticalArrangement = Arrangement.spacedBy(16.dp),
|
||||
horizontalAlignment = Alignment.CenterHorizontally,
|
||||
) {
|
||||
Text( text = stringResource(id = R.string.no_supported_player), style = MaterialTheme.typography.headlineSmall )
|
||||
Text(
|
||||
text = stringResource(id = R.string.no_supported_player),
|
||||
style = MaterialTheme.typography.headlineSmall,
|
||||
textAlign = TextAlign.Center,
|
||||
)
|
||||
if (!notificationPermission) {
|
||||
Text(
|
||||
text = stringResource(id = R.string.notification_post_permission_not_granted).uppercase(),
|
||||
|
||||
@@ -31,6 +31,7 @@ data class SettingsState(
|
||||
val applications: Map<String, AppInfo> = emptyMap(),
|
||||
val whitelistSearchQuery: String = "",
|
||||
val keepScreenOn: Boolean = false,
|
||||
val whitelistPromptSeen: Boolean = true,
|
||||
)
|
||||
|
||||
class SettingsViewModel(private val settingsPrefsRepo: SettingsPreferencesRepository, context: Context): ViewModel() {
|
||||
@@ -48,6 +49,12 @@ class SettingsViewModel(private val settingsPrefsRepo: SettingsPreferencesReposi
|
||||
}
|
||||
}
|
||||
|
||||
fun discardWhitelistPrompt() {
|
||||
viewModelScope.launch(Dispatchers.IO) {
|
||||
settingsPrefsRepo.discardWhitelistPrompt()
|
||||
}
|
||||
}
|
||||
|
||||
fun toggleKeepScreenOn() {
|
||||
viewModelScope.launch(Dispatchers.IO) {
|
||||
settingsPrefsRepo.toggleKeepScreenOn()
|
||||
@@ -157,6 +164,7 @@ class SettingsViewModel(private val settingsPrefsRepo: SettingsPreferencesReposi
|
||||
state.copy(
|
||||
appTheme = it.appTheme,
|
||||
keepScreenOn = it.keepScreenOn,
|
||||
whitelistPromptSeen = it.whitelistPromptSeen,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -26,6 +26,8 @@
|
||||
<string name="notification_post_permission_desc">يتطلب هذا التطبيق أذونات الإشعارات لبدء خدمة مقدمة بغرض الاستماع إلى إشعارات الموسيقى، ولا يمكن أن يعمل بدونها.</string>
|
||||
<string name="notification_post_permission_not_granted">لم يتم منح إذن الإشعارات، لن يعمل التطبيق بشكل صحيح</string>
|
||||
<string name="grant_permission">منح الإذن</string>
|
||||
<string name="understood">مفهوم</string>
|
||||
<string name="whitelist_prompt_desc">يعمل التطبيق على أساس القائمة البيضاء. وهذا يمنحك التحكم في التطبيقات التي سنستمع إليها ويقلل أيضًا من التشويش على التطبيق.\nيمكنك التحكم في القائمة البيضاء من الإعدادات</string>
|
||||
|
||||
<!-- Settings -->
|
||||
<string name="settings">الإعدادات</string>
|
||||
|
||||
@@ -25,6 +25,8 @@
|
||||
<string name="notification_post_permission_desc">LyricsGrabbr requires notification permissions to start a foreground service for the purpose of listening to music notifications, and cannot function without it.</string>
|
||||
<string name="notification_post_permission_not_granted">Notification permission is not granted, the app will not function properly</string>
|
||||
<string name="grant_permission">Grant Permission</string>
|
||||
<string name="understood">Understood</string>
|
||||
<string name="whitelist_prompt_desc">The application operates on a whitelist basis. This gives you control over which apps we\'ll listen to and also reduces noise for the application.\nYou may control the whitelist from the settings.</string>
|
||||
|
||||
<!-- Settings -->
|
||||
<string name="settings">Settings</string>
|
||||
|
||||
Reference in New Issue
Block a user