Skip to content

Unofficial YouTube Music / Spotify Premium client for Android, built in Liquid Glass. Audio effects, Spotify Connect, listening history, 8 languages. Rust core on librespot.

Fix the YouTube Music home and sign-in, and show who is signed in properly

Lelonio2793d5e10597
diff --git a/app/src/main/java/dev/lelonio/square/SquareApplication.kt b/app/src/main/java/dev/lelonio/square/SquareApplication.kt
index 0f5bd63..66031be 100644
--- a/app/src/main/java/dev/lelonio/square/SquareApplication.kt
+++ b/app/src/main/java/dev/lelonio/square/SquareApplication.kt
@@ -35,6 +35,8 @@ class SquareApplication : Application(), ImageLoaderFactory {
// First, so a crash anywhere below is written down; see Report.
dev.lelonio.square.diagnostics.Report.install(this)
// Temporary, dev builds only; see WidevineProbe.
+ // YouTube's language and country, before anything asks it for a page.
+ language.applyToYouTube()
dev.lelonio.square.diagnostics.WidevineProbe.register(this)
// The vendored InnerTube module logs through Timber, and with nothing
// planted every one of those lines went nowhere — which is why a
diff --git a/app/src/main/java/dev/lelonio/square/backend/youtube/YouTubeAccount.kt b/app/src/main/java/dev/lelonio/square/backend/youtube/YouTubeAccount.kt
index a3c2bfc..d626549 100644
--- a/app/src/main/java/dev/lelonio/square/backend/youtube/YouTubeAccount.kt
+++ b/app/src/main/java/dev/lelonio/square/backend/youtube/YouTubeAccount.kt
@@ -159,7 +159,10 @@ class YouTubeAccount(context: Context) {
.putString(KEY_VISITOR_DATA, visitorData)
.putString(KEY_DATA_SYNC_ID, dataSyncId)
.putString(KEY_NAME, name)
- .apply()
+ // Written before this returns: a sign-in is the one thing worth
+ // waiting for the disk over, and an asynchronous write was lost
+ // when the app stopped straight after it.
+ .commit()
_accountName.value = name
applyToInnerTube()
}
diff --git a/app/src/main/java/dev/lelonio/square/backend/youtube/YouTubeLoginScreen.kt b/app/src/main/java/dev/lelonio/square/backend/youtube/YouTubeLoginScreen.kt
index c0a9f74..8cec58b 100644
--- a/app/src/main/java/dev/lelonio/square/backend/youtube/YouTubeLoginScreen.kt
+++ b/app/src/main/java/dev/lelonio/square/backend/youtube/YouTubeLoginScreen.kt
@@ -5,8 +5,32 @@ import android.webkit.CookieManager
import android.webkit.WebView
import android.webkit.WebViewClient
import androidx.activity.compose.BackHandler
+import androidx.compose.foundation.background
+import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.fillMaxSize
+import androidx.compose.foundation.layout.fillMaxWidth
+import androidx.compose.foundation.layout.height
+import androidx.compose.foundation.layout.padding
+import androidx.compose.foundation.layout.size
+import androidx.compose.foundation.layout.systemBarsPadding
+import androidx.compose.foundation.shape.CircleShape
+import androidx.compose.foundation.shape.RoundedCornerShape
+import androidx.compose.material3.Icon
+import androidx.compose.material3.MaterialTheme
+import androidx.compose.material3.Text
+import androidx.compose.ui.draw.clip
+import androidx.compose.ui.graphics.graphicsLayer
+import androidx.compose.ui.res.stringResource
+import androidx.compose.ui.text.font.FontWeight
+import androidx.compose.ui.unit.dp
+import com.adamglin.PhosphorIcons
+import com.adamglin.phosphoricons.Fill
+import com.adamglin.phosphoricons.Regular
+import com.adamglin.phosphoricons.fill.LockSimple
+import com.adamglin.phosphoricons.regular.ShieldCheck
+import com.adamglin.phosphoricons.regular.X
+import dev.lelonio.square.R
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
@@ -40,7 +64,21 @@ import kotlinx.coroutines.launch
fun YouTubeLoginScreen(account: YouTubeAccount, onDone: () -> Unit) {
val scope = rememberCoroutineScope()
var completing by remember { mutableStateOf(false) }
- var webView: WebView? = null
+ // Remembered: a plain local was lost every time the page redrew, and the
+ // progress bar redraws it many times a second.
+ val webViewHolder = remember { arrayOfNulls<WebView>(1) }
+ // Every way out goes through here: the page lets go of the focus first.
+ // Taken away while focused, it sent Android looking for the next thing to
+ // focus in a screen still being composed, and the app stopped.
+ val close: () -> Unit = {
+ webViewHolder[0]?.apply {
+ clearFocus()
+ isFocusable = false
+ }
+ onDone()
+ }
+ var progress by remember { mutableStateOf(0) }
+ var host by remember { mutableStateOf("accounts.google.com") }
val context = androidx.compose.ui.platform.LocalContext.current
@@ -54,7 +92,7 @@ fun YouTubeLoginScreen(account: YouTubeAccount, onDone: () -> Unit) {
val cookie = CookieManager.getInstance().getCookie(MUSIC_URL).orEmpty()
// Backing out before signing in is an ordinary outcome, not a failure.
if (cookie.isBlank()) {
- onDone()
+ close()
return
}
@@ -66,9 +104,15 @@ fun YouTubeLoginScreen(account: YouTubeAccount, onDone: () -> Unit) {
YouTube.dataSyncId = dataSyncId
fun keep(name: String) {
- webView?.apply {
+ webViewHolder[0]?.apply {
stopLoading()
clearHistory()
+ // Let go of the focus before the page goes: taken away
+ // while focused, it sent Android looking for the next
+ // thing to focus in a screen still being composed, and the
+ // app stopped right as the sign-in finished.
+ clearFocus()
+ isFocusable = false
}
account.save(
cookie = cookie,
@@ -76,7 +120,7 @@ fun YouTubeLoginScreen(account: YouTubeAccount, onDone: () -> Unit) {
dataSyncId = dataSyncId,
name = name,
)
- onDone()
+ close()
}
// The session is only worth keeping if it can actually read the
@@ -114,55 +158,207 @@ fun YouTubeLoginScreen(account: YouTubeAccount, onDone: () -> Unit) {
context.getString(dev.lelonio.square.R.string.youtube_sign_in_failed),
android.widget.Toast.LENGTH_LONG,
).show()
- onDone()
+ close()
}
}
}
- Box(Modifier.fillMaxSize()) {
- AndroidView(
- modifier = Modifier.fillMaxSize(),
- factory = { context ->
- WebView(context).apply {
- webViewClient = object : WebViewClient() {
- override fun onPageFinished(view: WebView, url: String?) {
- // Landing back on music.youtube.com with a cookie is
- // what "signed in" looks like: Google's flow can take
- // any number of pages — password, 2FA, account
- // picker — and this is the one state that means it
- // finished.
- val signedIn = url?.contains("music.youtube.com") == true &&
- CookieManager.getInstance().getCookie(MUSIC_URL)
- .orEmpty().isNotBlank()
- if (!signedIn || completing) return
- // The page's ids first, then the check. Read
- // through a bridge and checked straight after,
- // the check always went before the page had
- // answered, with both of them empty.
- view.evaluateJavascript(
- "(function(){try{var c=window.yt.config_;" +
- "return [c.VISITOR_DATA||'',c.DATASYNC_ID||''];}catch(e){return ['',''];}})()",
- ) { result ->
- val ids = runCatching { org.json.JSONArray(result) }.getOrNull()
- complete(
- visitorData = ids?.optString(0).orEmpty(),
- // Two ids separated by `||`; the first is
- // this account's.
- dataSyncId = ids?.optString(1).orEmpty().substringBefore("||"),
- )
+ // Google's own page, inside the app's: a header that says what it is and
+ // where it is, the page on a card under it, and a word on what is kept.
+ // The page has to stay Google's and stay visible as Google's — a password
+ // typed into anything else is the thing never to ask for.
+ val ink = androidx.compose.ui.graphics.Color.White
+ androidx.compose.foundation.layout.Column(
+ Modifier
+ .fillMaxSize()
+ .systemBarsPadding(),
+ ) {
+ androidx.compose.foundation.layout.Row(
+ Modifier
+ .fillMaxWidth()
+ .padding(start = 16.dp, end = 20.dp, top = 8.dp, bottom = 12.dp),
+ verticalAlignment = androidx.compose.ui.Alignment.CenterVertically,
+ ) {
+ Box(
+ Modifier
+ .size(44.dp)
+ .clip(CircleShape)
+ .background(ink.copy(alpha = 0.12f))
+ .clickable {
+ webViewHolder[0]?.stopLoading()
+ close()
+ },
+ contentAlignment = androidx.compose.ui.Alignment.Center,
+ ) {
+ Icon(
+ PhosphorIcons.Regular.X,
+ contentDescription = stringResource(R.string.close),
+ tint = ink,
+ modifier = Modifier.size(20.dp),
+ )
+ }
+ androidx.compose.foundation.layout.Column(Modifier.padding(start = 14.dp)) {
+ Text(
+ stringResource(R.string.youtube_sign_in),
+ style = MaterialTheme.typography.titleMedium,
+ fontWeight = FontWeight.SemiBold,
+ color = ink,
+ )
+ androidx.compose.foundation.layout.Row(verticalAlignment = androidx.compose.ui.Alignment.CenterVertically) {
+ Icon(
+ PhosphorIcons.Fill.LockSimple,
+ contentDescription = null,
+ tint = ink.copy(alpha = 0.6f),
+ modifier = Modifier.size(12.dp),
+ )
+ Text(
+ host,
+ style = MaterialTheme.typography.bodySmall,
+ color = ink.copy(alpha = 0.6f),
+ maxLines = 1,
+ modifier = Modifier.padding(start = 4.dp),
+ )
+ }
+ }
+ }
+
+ // How far the page has got, on a hairline under the header.
+ val shown by androidx.compose.animation.core.animateFloatAsState(
+ targetValue = progress / 100f,
+ label = "loginProgress",
+ )
+ val barAlpha by androidx.compose.animation.core.animateFloatAsState(
+ targetValue = if (progress in 1..99) 1f else 0f,
+ label = "loginProgressAlpha",
+ )
+ Box(
+ Modifier
+ .fillMaxWidth()
+ .height(2.dp)
+ .padding(horizontal = 16.dp)
+ .graphicsLayer { alpha = barAlpha },
+ ) {
+ Box(
+ Modifier
+ .fillMaxWidth(shown.coerceIn(0f, 1f))
+ .height(2.dp)
+ .clip(RoundedCornerShape(1.dp))
+ .background(ink.copy(alpha = 0.85f)),
+ )
+ }
+
+ Box(
+ Modifier
+ .weight(1f)
+ .fillMaxWidth()
+ .padding(start = 12.dp, end = 12.dp, top = 10.dp)
+ .clip(RoundedCornerShape(28.dp))
+ .background(androidx.compose.ui.graphics.Color.White),
+ ) {
+ AndroidView(
+ modifier = Modifier.fillMaxSize(),
+ factory = { context ->
+ WebView(context).apply {
+ webViewClient = object : WebViewClient() {
+ override fun onPageStarted(view: WebView, url: String?, favicon: android.graphics.Bitmap?) {
+ url?.let { android.net.Uri.parse(it).host }?.let { host = it }
+ }
+
+ override fun onPageFinished(view: WebView, url: String?) {
+ // Landing back on music.youtube.com with a cookie is
+ // what "signed in" looks like: Google's flow can take
+ // any number of pages — password, 2FA, account
+ // picker — and this is the one state that means it
+ // finished.
+ val signedIn = url?.contains("music.youtube.com") == true &&
+ CookieManager.getInstance().getCookie(MUSIC_URL)
+ .orEmpty().isNotBlank()
+ if (!signedIn || completing) return
+ // The page's ids first, then the check. Read
+ // through a bridge and checked straight after,
+ // the check always went before the page had
+ // answered, with both of them empty.
+ view.evaluateJavascript(
+ "(function(){try{var c=window.yt.config_;" +
+ "return [c.VISITOR_DATA||'',c.DATASYNC_ID||''];}catch(e){return ['',''];}})()",
+ ) { result ->
+ val ids = runCatching { org.json.JSONArray(result) }.getOrNull()
+ complete(
+ visitorData = ids?.optString(0).orEmpty(),
+ // Two ids separated by `||`; the first is
+ // this account's.
+ dataSyncId = ids?.optString(1).orEmpty().substringBefore("||"),
+ )
+ }
+ }
+ }
+ webChromeClient = object : android.webkit.WebChromeClient() {
+ override fun onProgressChanged(view: WebView, newProgress: Int) {
+ progress = newProgress
}
}
+ settings.javaScriptEnabled = true
+ webViewHolder[0] = this
+ loadUrl(SIGN_IN_URL)
+ }
+ },
+ )
+ // The account being checked, once Google has let it in: a moment
+ // with nothing to press, said rather than left to look stuck.
+ androidx.compose.animation.AnimatedVisibility(
+ visible = completing,
+ enter = androidx.compose.animation.fadeIn(),
+ exit = androidx.compose.animation.fadeOut(),
+ modifier = Modifier.fillMaxSize(),
+ ) {
+ Box(
+ Modifier
+ .fillMaxSize()
+ .background(androidx.compose.ui.graphics.Color(0xFF101012).copy(alpha = 0.88f)),
+ contentAlignment = androidx.compose.ui.Alignment.Center,
+ ) {
+ androidx.compose.foundation.layout.Column(
+ horizontalAlignment = androidx.compose.ui.Alignment.CenterHorizontally,
+ ) {
+ androidx.compose.material3.CircularProgressIndicator(
+ color = ink,
+ strokeWidth = 2.dp,
+ modifier = Modifier.size(32.dp),
+ )
+ Text(
+ stringResource(R.string.youtube_signing_in),
+ style = MaterialTheme.typography.bodyMedium,
+ color = ink,
+ modifier = Modifier.padding(top = 14.dp),
+ )
}
- settings.javaScriptEnabled = true
- webView = this
- loadUrl(SIGN_IN_URL)
}
- },
- )
+ }
+ }
+
+ androidx.compose.foundation.layout.Row(
+ Modifier
+ .fillMaxWidth()
+ .padding(horizontal = 24.dp, vertical = 14.dp),
+ verticalAlignment = androidx.compose.ui.Alignment.CenterVertically,
+ ) {
+ Icon(
+ PhosphorIcons.Regular.ShieldCheck,
+ contentDescription = null,
+ tint = ink.copy(alpha = 0.6f),
+ modifier = Modifier.size(16.dp),
+ )
+ Text(
+ stringResource(R.string.youtube_sign_in_private),
+ style = MaterialTheme.typography.bodySmall,
+ color = ink.copy(alpha = 0.6f),
+ modifier = Modifier.padding(start = 8.dp),
+ )
+ }
}
BackHandler {
- val view = webView
+ val view = webViewHolder[0]
// Google's flow is several pages deep, so back should walk it rather
// than abandoning a sign-in halfway through.
if (view?.canGoBack() == true) view.goBack() else complete()
diff --git a/app/src/main/java/dev/lelonio/square/data/LanguageStore.kt b/app/src/main/java/dev/lelonio/square/data/LanguageStore.kt
index a645b9c..78d4866 100644
--- a/app/src/main/java/dev/lelonio/square/data/LanguageStore.kt
+++ b/app/src/main/java/dev/lelonio/square/data/LanguageStore.kt
@@ -49,6 +49,7 @@ class LanguageStore(context: Context) {
_tag.value = tag
prefs.edit().putString(KEY_LANGUAGE, tag).apply()
tellEngine()
+ applyToYouTube()
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
val manager = app.getSystemService(android.app.LocaleManager::class.java)
manager?.applicationLocales =
@@ -79,6 +80,25 @@ class LanguageStore(context: Context) {
}.start()
}
+ /**
+ * Tells YouTube Music the language to answer in and the country to answer
+ * for, separately.
+ *
+ * Its module read both from the default locale, and an app set to English
+ * has a default locale with a language and no country: the country went
+ * out empty, YouTube answered every page with 400 "invalid argument", and
+ * the home was blank. The country is the phone's own, whatever language the
+ * app is read in; the network's where the phone names none.
+ */
+ fun applyToYouTube() {
+ val country = systemLocale().country.takeIf { it.length == 2 }
+ ?: app.getSystemService(android.telephony.TelephonyManager::class.java)
+ ?.networkCountryIso?.uppercase()?.takeIf { it.length == 2 }
+ ?: "US"
+ com.metrolist.innertube.YouTube.locale =
+ com.metrolist.innertube.models.YouTubeLocale(gl = country, hl = language())
+ }
+
/**
* The same context, reading in the chosen language.
*
diff --git a/app/src/main/java/dev/lelonio/square/playback/websdk/WebSdkActivity.kt b/app/src/main/java/dev/lelonio/square/playback/websdk/WebSdkActivity.kt
index d0b6154..950e3d2 100644
--- a/app/src/main/java/dev/lelonio/square/playback/websdk/WebSdkActivity.kt
+++ b/app/src/main/java/dev/lelonio/square/playback/websdk/WebSdkActivity.kt
@@ -167,11 +167,14 @@ class WebSdkActivity : ComponentActivity() {
} else {
val uriHandler = LocalUriHandler.current
val clipboard = LocalClipboardManager.current
+ val context = androidx.compose.ui.platform.LocalContext.current
CardButton(
title = stringResource(R.string.onboarding_open_dashboard),
detail = DASHBOARD_URL.removePrefix("https://"),
icon = PhosphorIcons.Regular.ArrowUpRight,
- onClick = { uriHandler.openUri(DASHBOARD_URL) },
+ onClick = {
+ dev.lelonio.square.ui.onboarding.openOrCopy(uriHandler, clipboard, context, DASHBOARD_URL)
+ },
modifier = Modifier.padding(top = 18.dp),
)
Text(stringResource(R.string.web_sdk_redirect), style = MaterialTheme.typography.bodyMedium,
diff --git a/app/src/main/java/dev/lelonio/square/ui/components/ProfilePicture.kt b/app/src/main/java/dev/lelonio/square/ui/components/ProfilePicture.kt
new file mode 100644
index 0000000..e63c746
--- /dev/null
+++ b/app/src/main/java/dev/lelonio/square/ui/components/ProfilePicture.kt
@@ -0,0 +1,97 @@
+package dev.lelonio.square.ui.components
+
+import androidx.compose.foundation.background
+import androidx.compose.foundation.layout.Box
+import androidx.compose.foundation.layout.fillMaxSize
+import androidx.compose.foundation.shape.CircleShape
+import androidx.compose.material3.Icon
+import androidx.compose.material3.Text
+import androidx.compose.runtime.Composable
+import androidx.compose.ui.Alignment
+import androidx.compose.ui.Modifier
+import androidx.compose.ui.draw.clip
+import androidx.compose.ui.graphics.Brush
+import androidx.compose.ui.text.TextStyle
+import androidx.compose.ui.text.font.FontWeight
+import androidx.compose.ui.unit.Dp
+import androidx.compose.ui.unit.dp
+import com.adamglin.PhosphorIcons
+import com.adamglin.phosphoricons.Fill
+import com.adamglin.phosphoricons.fill.User
+import dev.lelonio.square.ui.theme.Ink
+
+/**
+ * A person's picture, round: the account's own where it has one.
+ *
+ * Without one it is not a cover. The generated cover a playlist falls back to
+ * is a large letter laid out for a square, and cut into a circle it showed half
+ * of one. A name gets its initials, whole and centred; no name, which is
+ * nobody signed in, gets the outline of a person.
+ */
+@Composable
+fun ProfilePicture(
+ url: String?,
+ name: String?,
+ /**
+ * How big it is drawn, for the corner and the initials. Passed rather than
+ * measured: measuring meant composing late, and a late composition is what
+ * the focus search went looking in when the sign-in page closed — the app
+ * stopped with Compose's "pending composition has not been applied".
+ */
+ size: Dp,
+ modifier: Modifier = Modifier,
+ decodeSize: Dp = 0.dp,
+) {
+ if (url != null) {
+ Artwork(
+ url = url,
+ title = name.orEmpty(),
+ modifier = modifier,
+ corner = size / 2,
+ decodeSize = decodeSize,
+ )
+ return
+ }
+ Box(
+ modifier
+ .clip(CircleShape)
+ .background(
+ Brush.linearGradient(listOf(Ink.copy(alpha = 0.16f), Ink.copy(alpha = 0.07f))),
+ ),
+ contentAlignment = Alignment.Center,
+ ) {
+ val initials = initialsOf(name)
+ if (initials.isEmpty()) {
+ Icon(
+ PhosphorIcons.Fill.User,
+ contentDescription = null,
+ tint = Ink.copy(alpha = 0.55f),
+ modifier = Modifier.fillMaxSize(0.5f),
+ )
+ } else {
+ val side = size
+ Box(Modifier.fillMaxSize(), contentAlignment = Alignment.Center) {
+ Text(
+ initials,
+ style = TextStyle(
+ fontSize = with(androidx.compose.ui.platform.LocalDensity.current) {
+ (side * if (initials.length > 1) 0.36f else 0.42f).toSp()
+ },
+ fontWeight = FontWeight.SemiBold,
+ color = Ink.copy(alpha = 0.8f),
+ ),
+ maxLines = 1,
+ )
+ }
+ }
+ }
+}
+
+/** Up to two initials: the first and last words' first letters. */
+private fun initialsOf(name: String?): String {
+ val words = name.orEmpty().trim().split(Regex("\\s+")).filter { it.isNotEmpty() }
+ if (words.isEmpty()) return ""
+ val first = words.first().first()
+ val last = words.drop(1).lastOrNull()?.first()
+ return listOfNotNull(first, last).joinToString("") { it.uppercase() }
+}
diff --git a/app/src/main/java/dev/lelonio/square/ui/home/HomeScreen.kt b/app/src/main/java/dev/lelonio/square/ui/home/HomeScreen.kt
index d2f7412..86b2ccf 100644
--- a/app/src/main/java/dev/lelonio/square/ui/home/HomeScreen.kt
+++ b/app/src/main/java/dev/lelonio/square/ui/home/HomeScreen.kt
@@ -185,7 +185,11 @@ fun HomeScreen(
contentPadding = contentPadding,
home = youtubeHome,
recent = recent,
- accountName = (state as? MainViewModel.UiState.Ready)?.displayName.orEmpty(),
+ // Nobody's name while signed out: the library's answer outlived a
+ // sign-out, and the header went on naming an account the app was
+ // no longer in.
+ accountName = (state as? MainViewModel.UiState.Ready)?.displayName.orEmpty()
+ .takeIf { youtubeSignedIn }.orEmpty(),
backdrop = backdrop,
onPlayRecent = onPlayRecent,
onPlayTrending = onPlayTrending,
@@ -759,9 +763,10 @@ private fun Header(
FriendFaces(friends, onOpenFriends)
}
- Artwork(
+ dev.lelonio.square.ui.components.ProfilePicture(
url = avatarUrl,
- title = name,
+ name = name,
+ size = 46.dp,
modifier = Modifier
.padding(start = 14.dp)
// Measured from the scroll rather than sized in
@@ -774,7 +779,6 @@ private fun Header(
.clip(CircleShape)
.pressable(onOpenSettings, pressedScale = 0.90f)
.softShadow(CircleShape, elevation = 10.dp),
- corner = 23.dp,
decodeSize = 46.dp,
)
}
diff --git a/app/src/main/java/dev/lelonio/square/ui/onboarding/OnboardingScreen.kt b/app/src/main/java/dev/lelonio/square/ui/onboarding/OnboardingScreen.kt
index 805a1e9..a18a438 100644
--- a/app/src/main/java/dev/lelonio/square/ui/onboarding/OnboardingScreen.kt
+++ b/app/src/main/java/dev/lelonio/square/ui/onboarding/OnboardingScreen.kt
@@ -195,6 +195,7 @@ private fun LogIn(
private fun Dashboard(redirectUri: String) {
val uriHandler = LocalUriHandler.current
val clipboard = LocalClipboardManager.current
+ val context = androidx.compose.ui.platform.LocalContext.current
StepHeader(stringResource(R.string.onboarding_key_title), stepOf(2))
ProseText(stringResource(R.string.onboarding_key_intro))
@@ -203,7 +204,7 @@ private fun Dashboard(redirectUri: String) {
title = stringResource(R.string.onboarding_open_dashboard),
detail = DASHBOARD_URL.removePrefix("https://"),
icon = PhosphorIcons.Regular.ArrowUpRight,
- onClick = { uriHandler.openUri(DASHBOARD_URL) },
+ onClick = { openOrCopy(uriHandler, clipboard, context, DASHBOARD_URL) },
modifier = Modifier.padding(top = 18.dp),
)
@@ -348,3 +349,25 @@ private fun LanguageChips(language: String, onLanguage: (String) -> Unit) {
}
private const val DASHBOARD_URL = "https://developer.spotify.com/dashboard"
+
+/**
+ * Opens [url] in the browser, or copies it and says so when nothing will open
+ * it. A phone with no browser set to answer, or one whose launcher refuses a
+ * link from an app, left the button doing nothing at all, with no way to the
+ * page the setup depends on.
+ */
+internal fun openOrCopy(
+ uriHandler: androidx.compose.ui.platform.UriHandler,
+ clipboard: androidx.compose.ui.platform.ClipboardManager,
+ context: android.content.Context,
+ url: String,
+) {
+ val opened = runCatching { uriHandler.openUri(url) }.isSuccess
+ if (opened) return
+ clipboard.setText(androidx.compose.ui.text.AnnotatedString(url))
+ android.widget.Toast.makeText(
+ context,
+ context.getString(dev.lelonio.square.R.string.link_copied_open_browser),
+ android.widget.Toast.LENGTH_LONG,
+ ).show()
+}
diff --git a/app/src/main/java/dev/lelonio/square/ui/settings/SettingsScreen.kt b/app/src/main/java/dev/lelonio/square/ui/settings/SettingsScreen.kt
index 60143cb..18d18c6 100644
--- a/app/src/main/java/dev/lelonio/square/ui/settings/SettingsScreen.kt
+++ b/app/src/main/java/dev/lelonio/square/ui/settings/SettingsScreen.kt
@@ -308,14 +308,21 @@ fun SettingsScreen(
item("top") { heading(shown) }
if (shown == null) item("pages") {
+ // On YouTube Music, the Google account says who this is. The
+ // library's own answer outlived a sign-out: the card went on
+ // showing a name, a picture and a count of playlists for an account
+ // the app was no longer signed in to.
+ val youtubeName by app.youtubeAccount.accountName.collectAsStateWithLifecycle()
+ val activeBackend by app.preferences.backend.collectAsStateWithLifecycle()
+ val signedOutOfYouTube = activeBackend == BackendId.YOUTUBE_MUSIC && youtubeName == null
SettingsIndex(
- name = ready?.displayName,
- note = if (ready != null) {
- stringResource(R.string.playlist_count, ready.playlists.size)
- } else {
- stringResource(R.string.log_in_to_resume)
+ name = ready?.displayName?.takeUnless { signedOutOfYouTube },
+ note = when {
+ signedOutOfYouTube -> stringResource(R.string.youtube_sign_in)
+ ready != null -> stringResource(R.string.playlist_count, ready.playlists.size)
+ else -> stringResource(R.string.log_in_to_resume)
},
- avatarUrl = ready?.avatarUrl,
+ avatarUrl = ready?.avatarUrl?.takeUnless { signedOutOfYouTube },
) { goTo(it) }
}
@@ -330,13 +337,13 @@ fun SettingsScreen(
horizontalAlignment = Alignment.CenterHorizontally,
verticalArrangement = Arrangement.spacedBy(10.dp),
) {
- Artwork(
+ dev.lelonio.square.ui.components.ProfilePicture(
url = ready?.avatarUrl,
- title = ready?.displayName.orEmpty(),
+ name = ready?.displayName,
+ size = 96.dp,
modifier = Modifier
.size(96.dp)
.softShadow(CircleShape, elevation = 16.dp),
- corner = 48.dp,
decodeSize = 96.dp,
)
Text(
@@ -999,13 +1006,13 @@ private fun SettingsIndex(
.padding(16.dp),
verticalAlignment = Alignment.CenterVertically,
) {
- Artwork(
+ dev.lelonio.square.ui.components.ProfilePicture(
url = avatarUrl,
- title = name.orEmpty(),
+ name = name,
+ size = 56.dp,
modifier = Modifier
.size(56.dp)
.softShadow(CircleShape, elevation = 10.dp),
- corner = 28.dp,
decodeSize = 56.dp,
)
Column(
diff --git a/app/src/main/res/values-de/strings.xml b/app/src/main/res/values-de/strings.xml
index f494237..4eb25bf 100644
--- a/app/src/main/res/values-de/strings.xml
+++ b/app/src/main/res/values-de/strings.xml
@@ -602,4 +602,7 @@
<string name="spotify_dj_starting">Der DJ macht sich bereit…</string>
<string name="spotify_dj_failed">Der DJ ist gerade nicht verfügbar. Versuch es später noch einmal.</string>
<string name="spotify_dj_talking">spricht</string>
+ <string name="link_copied_open_browser">Der Browser ließ sich nicht öffnen. Der Link ist kopiert: füge ihn dort ein.</string>
+ <string name="youtube_signing_in">Anmeldung läuft…</string>
+ <string name="youtube_sign_in_private">Dein Passwort geht nur an Google. Square behält die Sitzung, die Google zurückgibt.</string>
</resources>
diff --git a/app/src/main/res/values-es/strings.xml b/app/src/main/res/values-es/strings.xml
index 0825ae1..7aaee48 100644
--- a/app/src/main/res/values-es/strings.xml
+++ b/app/src/main/res/values-es/strings.xml
@@ -608,4 +608,7 @@
<string name="spotify_dj_starting">El DJ se está preparando…</string>
<string name="spotify_dj_failed">El DJ no está disponible ahora. Inténtalo más tarde.</string>
<string name="spotify_dj_talking">está hablando</string>
+ <string name="link_copied_open_browser">No se pudo abrir el navegador. El enlace está copiado: pégalo allí.</string>
+ <string name="youtube_signing_in">Iniciando sesión…</string>
+ <string name="youtube_sign_in_private">Tu contraseña va solo a Google. Square guarda la sesión que Google devuelve.</string>
</resources>
diff --git a/app/src/main/res/values-fr/strings.xml b/app/src/main/res/values-fr/strings.xml
index baf48d3..6c90b65 100644
--- a/app/src/main/res/values-fr/strings.xml
+++ b/app/src/main/res/values-fr/strings.xml
@@ -602,4 +602,7 @@
<string name="spotify_dj_starting">Le DJ se prépare…</string>
<string name="spotify_dj_failed">Le DJ n\'est pas disponible pour le moment. Réessayez plus tard.</string>
<string name="spotify_dj_talking">parle</string>
+ <string name="link_copied_open_browser">Impossible d\'ouvrir le navigateur. Le lien est copié : collez-le dedans.</string>
+ <string name="youtube_signing_in">Connexion en cours…</string>
+ <string name="youtube_sign_in_private">Votre mot de passe va uniquement à Google. Square garde la session que Google renvoie.</string>
</resources>
diff --git a/app/src/main/res/values-hi/strings.xml b/app/src/main/res/values-hi/strings.xml
index fe15427..3062f50 100644
--- a/app/src/main/res/values-hi/strings.xml
+++ b/app/src/main/res/values-hi/strings.xml
@@ -617,4 +617,7 @@
<string name="spotify_dj_starting">DJ तैयार हो रहा है…</string>
<string name="spotify_dj_failed">DJ अभी उपलब्ध नहीं है। बाद में फिर कोशिश करें।</string>
<string name="spotify_dj_talking">बोल रहा है</string>
+ <string name="link_copied_open_browser">ब्राउज़र नहीं खुल सका। लिंक कॉपी हो गया है: उसे वहाँ पेस्ट करें।</string>
+ <string name="youtube_signing_in">साइन इन हो रहा है…</string>
+ <string name="youtube_sign_in_private">आपका पासवर्ड सिर्फ़ Google को जाता है। Square वही सेशन रखता है जो Google लौटाता है।</string>
</resources>
diff --git a/app/src/main/res/values-it/strings.xml b/app/src/main/res/values-it/strings.xml
index 4cdbd96..f4a1b78 100644
--- a/app/src/main/res/values-it/strings.xml
+++ b/app/src/main/res/values-it/strings.xml
@@ -639,4 +639,7 @@
<string name="spotify_dj_starting">Il DJ si sta preparando…</string>
<string name="spotify_dj_failed">Il DJ non è disponibile ora. Riprova più tardi.</string>
<string name="spotify_dj_talking">sta parlando</string>
+ <string name="link_copied_open_browser">Impossibile aprire il browser. Il link è copiato: incollalo lì.</string>
+ <string name="youtube_signing_in">Accesso in corso…</string>
+ <string name="youtube_sign_in_private">La password va solo a Google. Square conserva la sessione che Google restituisce.</string>
</resources>
diff --git a/app/src/main/res/values-ja/strings.xml b/app/src/main/res/values-ja/strings.xml
index 50cdcfb..0725757 100644
--- a/app/src/main/res/values-ja/strings.xml
+++ b/app/src/main/res/values-ja/strings.xml
@@ -658,5 +658,8 @@
<string name="spotify_dj_starting">DJ を準備しています…</string>
<string name="spotify_dj_failed">DJ は現在利用できません。しばらくしてからもう一度お試しください。</string>
<string name="spotify_dj_talking">話しています</string>
+ <string name="link_copied_open_browser">ブラウザを開けませんでした。リンクをコピーしたので、ブラウザに貼り付けてください。</string>
+ <string name="youtube_signing_in">ログインしています…</string>
+ <string name="youtube_sign_in_private">パスワードは Google にのみ送られます。Square は Google から返されたセッションだけを保存します。</string>
</resources>
diff --git a/app/src/main/res/values-ko/strings.xml b/app/src/main/res/values-ko/strings.xml
index 1a9a7a4..11034e9 100644
--- a/app/src/main/res/values-ko/strings.xml
+++ b/app/src/main/res/values-ko/strings.xml
@@ -626,4 +626,7 @@
<string name="spotify_dj_starting">DJ가 준비 중입니다…</string>
<string name="spotify_dj_failed">지금은 DJ를 사용할 수 없습니다. 나중에 다시 시도하세요.</string>
<string name="spotify_dj_talking">이야기 중</string>
+ <string name="link_copied_open_browser">브라우저를 열 수 없습니다. 링크가 복사되었으니 브라우저에 붙여넣으세요.</string>
+ <string name="youtube_signing_in">로그인 중…</string>
+ <string name="youtube_sign_in_private">비밀번호는 Google에만 전달됩니다. Square는 Google이 돌려주는 세션만 보관합니다.</string>
</resources>
diff --git a/app/src/main/res/values-pt/strings.xml b/app/src/main/res/values-pt/strings.xml
index 74f7cf2..b52e0a2 100644
--- a/app/src/main/res/values-pt/strings.xml
+++ b/app/src/main/res/values-pt/strings.xml
@@ -602,4 +602,7 @@
<string name="spotify_dj_starting">O DJ está se preparando…</string>
<string name="spotify_dj_failed">O DJ não está disponível agora. Tente mais tarde.</string>
<string name="spotify_dj_talking">está falando</string>
+ <string name="link_copied_open_browser">Não foi possível abrir o navegador. O link foi copiado: cole-o lá.</string>
+ <string name="youtube_signing_in">Entrando…</string>
+ <string name="youtube_sign_in_private">Sua senha vai só para o Google. O Square guarda a sessão que o Google devolve.</string>
</resources>
diff --git a/app/src/main/res/values-ru/strings.xml b/app/src/main/res/values-ru/strings.xml
index 8770aec..5f98c30 100644
--- a/app/src/main/res/values-ru/strings.xml
+++ b/app/src/main/res/values-ru/strings.xml
@@ -631,4 +631,7 @@
<string name="spotify_dj_starting">DJ готовится…</string>
<string name="spotify_dj_failed">DJ сейчас недоступен. Попробуйте позже.</string>
<string name="spotify_dj_talking">говорит</string>
+ <string name="link_copied_open_browser">Не удалось открыть браузер. Ссылка скопирована: вставьте её туда.</string>
+ <string name="youtube_signing_in">Выполняется вход…</string>
+ <string name="youtube_sign_in_private">Пароль получает только Google. Square хранит сессию, которую возвращает Google.</string>
</resources>
diff --git a/app/src/main/res/values-tr/strings.xml b/app/src/main/res/values-tr/strings.xml
index 38a1e01..2447bd8 100644
--- a/app/src/main/res/values-tr/strings.xml
+++ b/app/src/main/res/values-tr/strings.xml
@@ -615,4 +615,7 @@
<string name="spotify_dj_starting">DJ hazırlanıyor…</string>
<string name="spotify_dj_failed">DJ şu anda kullanılamıyor. Daha sonra tekrar dene.</string>
<string name="spotify_dj_talking">konuşuyor</string>
+ <string name="link_copied_open_browser">Tarayıcı açılamadı. Bağlantı kopyalandı: oraya yapıştır.</string>
+ <string name="youtube_signing_in">Giriş yapılıyor…</string>
+ <string name="youtube_sign_in_private">Şifren yalnızca Google\'a gider. Square, Google\'ın verdiği oturumu saklar.</string>
</resources>
diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml
index c889987..b8ac84d 100644
--- a/app/src/main/res/values/strings.xml
+++ b/app/src/main/res/values/strings.xml
@@ -667,4 +667,7 @@
<string name="spotify_dj_starting">The DJ is getting ready…</string>
<string name="spotify_dj_failed">The DJ isn\'t available right now. Try again later.</string>
<string name="spotify_dj_talking">is talking</string>
+ <string name="link_copied_open_browser">Couldn\'t open the browser. The link is copied: paste it there.</string>
+ <string name="youtube_signing_in">Signing in…</string>
+ <string name="youtube_sign_in_private">Your password goes only to Google. Square keeps the session Google gives back.</string>
</resources>