Skip to content

Commit

Permalink
feat: language selector, closes #228
Browse files Browse the repository at this point in the history
credits DanielSevillano
  • Loading branch information
Malopieds committed Aug 23, 2024
1 parent b8e958e commit e360e89
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
package com.malopieds.innertune.ui.screens.settings

import android.content.ActivityNotFoundException
import android.content.Intent
import android.net.Uri
import android.os.Build
import android.provider.Settings
import android.widget.Toast
import androidx.compose.animation.AnimatedVisibility
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Spacer
Expand All @@ -17,6 +23,7 @@ import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.remember
import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.res.stringResource
import androidx.navigation.NavController
Expand Down Expand Up @@ -60,6 +67,7 @@ fun ContentSettings(
navController: NavController,
scrollBehavior: TopAppBarScrollBehavior,
) {
val context = LocalContext.current
val accountName by rememberPreference(AccountNameKey, "")
val accountEmail by rememberPreference(AccountEmailKey, "")
val accountChannelHandle by rememberPreference(AccountChannelHandleKey, "")
Expand Down Expand Up @@ -98,6 +106,7 @@ fun ContentSettings(
icon = { Icon(painterResource(R.drawable.person), null) },
onClick = { navController.navigate("login") },
)

ListPreference(
title = { Text(stringResource(R.string.content_language)) },
icon = { Icon(painterResource(R.drawable.language), null) },
Expand All @@ -123,6 +132,23 @@ fun ContentSettings(
onValueSelected = onContentCountryChange,
)

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
PreferenceEntry(
title = { Text(stringResource(R.string.app_language)) },
description = stringResource(R.string.configure_app_language),
icon = { Icon(painterResource(R.drawable.language), null) },
onClick = {
try {
context.startActivity(
Intent(Settings.ACTION_APPLICATION_SETTINGS, Uri.parse("package:${context.packageName}")),
)
} catch (e: ActivityNotFoundException) {
Toast.makeText(context, R.string.intent_app_language_not_found, Toast.LENGTH_LONG).show()
}
},
)
}

SwitchPreference(
title = { Text(stringResource(R.string.hide_explicit)) },
icon = { Icon(painterResource(R.drawable.explicit), null) },
Expand Down
3 changes: 3 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,9 @@
<string name="set_quick_picks">Set Quick Picks</string>
<string name="last_song_listened">Based on last song listened</string>
<string name="restart_to_take_effect">Restart to take effect</string>
<string name="app_language">App language</string>
<string name="configure_app_language">Configure app languages</string>
<string name="intent_app_language_not_found">Couldn\'t find app language settings, please configure them manually</string>

<string name="player_and_audio">Player and audio</string>
<string name="audio_quality">Audio quality</string>
Expand Down

0 comments on commit e360e89

Please sign in to comment.