Compare commits

..
11 changed files with 1015 additions and 842 deletions

No files matched your search

File diff suppressed because it is too large. Load diff
+21 -2
View File
@@ -87,15 +87,34 @@ export default function AppLayout() {
<Stack.Screen
name="settings"
options={{
headerShown: Platform.OS === "android",
// iOS gets a native header with a close button; Android
// draws its own title bar in the screen.
headerShown: Platform.OS === "ios",
title: "Settings",
headerLargeTitle: false,
headerTransparent: false,
headerShadowVisible: false,
headerStyle: { backgroundColor: "#000" },
// Matches the inline title size of Apple Music's settings.
headerTitleStyle: { fontSize: 20, fontWeight: "700" },
presentation:
Platform.OS === "ios" ? "modal" : "fullScreenModal",
animation: "slide_from_bottom",
gestureEnabled: true,
gestureDirection: "vertical",
}}
/>
>
{/* Stack.Toolbar forces the header on, so keep it iOS-only. */}
{Platform.OS === "ios" ? (
<Stack.Toolbar placement="right">
<Stack.Toolbar.Button
icon="xmark"
accessibilityLabel="Close settings"
onPress={() => router.back()}
/>
</Stack.Toolbar>
) : null}
</Stack.Screen>
<Stack.Screen
name="create-account"
options={{
+1 -16
View File
@@ -1,16 +1 @@
import { Platform } from "react-native"
import { SafeAreaView } from "react-native-safe-area-context"
import SettingsScreen from "./(tabs)/home/settings"
export default function Settings() {
if (Platform.OS !== "android") return <SettingsScreen />
return (
<SafeAreaView
edges={["bottom", "left", "right"]}
style={{ flex: 1, backgroundColor: "#000" }}
>
<SettingsScreen />
</SafeAreaView>
)
}
export { default } from "./(tabs)/home/settings"
+32
View File
@@ -0,0 +1,32 @@
import { Button, Host } from "@expo/ui/swift-ui"
import {
buttonBorderShape,
buttonStyle,
controlSize,
labelStyle,
} from "@expo/ui/swift-ui/modifiers"
/** A native SwiftUI glass "+" button, matching the iOS header close button. */
export function AddButton({
label,
onPress,
}: {
label: string
onPress: () => void
}) {
return (
<Host matchContents>
<Button
label={label}
systemImage="plus"
onPress={onPress}
modifiers={[
labelStyle("iconOnly"),
buttonStyle("glass"),
buttonBorderShape("circle"),
controlSize("large"),
]}
/>
</Host>
)
}
+26
View File
@@ -0,0 +1,26 @@
import { Ionicons } from "@expo/vector-icons"
import { Pressable } from "react-native"
import { useThemeColors } from "@/lib/theme"
/** A plain "+" icon button. iOS uses a native SwiftUI button instead. */
export function AddButton({
label,
onPress,
}: {
label: string
onPress: () => void
}) {
const colors = useThemeColors()
return (
<Pressable
accessibilityRole="button"
accessibilityLabel={label}
hitSlop={8}
onPress={onPress}
style={({ pressed }) => ({ opacity: pressed ? 0.6 : 1 })}
>
<Ionicons name="add" size={32} color={colors.foreground} />
</Pressable>
)
}
+15 -1
View File
@@ -1,4 +1,7 @@
import { useAndroidTabPalette } from "@/contexts/android-tab-theme"
import {
useAndroidTabPalette,
useAndroidTabHasArtworkPalette,
} from "@/contexts/android-tab-theme"
import { Ionicons } from "@expo/vector-icons"
import { NativeTabs } from "expo-router/native-tabs"
import { useRouter } from "expo-router"
@@ -163,10 +166,20 @@ function MiniPlayerContent({
function MiniPlayerChrome({ children }: { children: React.ReactNode }) {
const palette = useAndroidTabPalette()
const hasArtworkPalette = useAndroidTabHasArtworkPalette()
return (
<View style={[styles.androidBar, { backgroundColor: palette.background }]}>
{children}
{hasArtworkPalette ? (
<View
style={[
styles.separator,
styles.topBorder,
{ backgroundColor: palette.secondaryForeground },
]}
/>
) : null}
<View
style={[
styles.separator,
@@ -254,6 +267,7 @@ const styles = StyleSheet.create({
height: 1,
zIndex: 1,
},
topBorder: { top: 0 },
bottomBorder: { bottom: 0 },
content: {
flexDirection: "row",
+28 -37
View File
@@ -34,7 +34,6 @@ import {
writeRememberedDownloadQuality,
} from "@/lib/downloads"
import { loadPlaybackSongs } from "@/lib/playback-files"
import { downloadQualitySupported } from "@/lib/playback-capabilities"
import type { ServerConfig } from "@/lib/server-config"
import { showError } from "@/lib/toast"
import { useThemeColors } from "@/lib/theme"
@@ -239,44 +238,36 @@ function DownloadQualityPopup({
>
{pending?.target.title}
</Text>
{pending?.response.options
.filter((option) => downloadQualitySupported(option.quality))
.map((option) => (
<Pressable
key={option.quality}
accessibilityRole="button"
style={[styles.row, { borderBottomColor: colors.border }]}
onPress={() => onPick(option.quality, remember)}
>
<View style={styles.rowText}>
{option.quality === "lossless" ||
option.quality === "atmos" ? (
<AudioFormatBadge
format={option.quality}
color={colors.foreground}
backgroundColor={colors.card}
/>
) : (
<Text
style={[styles.label, { color: colors.foreground }]}
>
{DOWNLOAD_QUALITY_LABELS[option.quality]}
</Text>
)}
<Text
style={{ color: colors.mutedForeground, fontSize: 12 }}
>
{optionDetail(option, songCount)}
{pending?.response.options.map((option) => (
<Pressable
key={option.quality}
accessibilityRole="button"
style={[styles.row, { borderBottomColor: colors.border }]}
onPress={() => onPick(option.quality, remember)}
>
<View style={styles.rowText}>
{option.quality === "lossless" ||
option.quality === "atmos" ? (
<AudioFormatBadge
format={option.quality}
color={colors.foreground}
backgroundColor={colors.card}
/>
) : (
<Text style={[styles.label, { color: colors.foreground }]}>
{DOWNLOAD_QUALITY_LABELS[option.quality]}
</Text>
</View>
<Text
style={[styles.size, { color: colors.mutedForeground }]}
>
{option.estimated ? "~" : ""}
{formatBytes(option.bytes)}
)}
<Text style={{ color: colors.mutedForeground, fontSize: 12 }}>
{optionDetail(option, songCount)}
</Text>
</Pressable>
))}
</View>
<Text style={[styles.size, { color: colors.mutedForeground }]}>
{option.estimated ? "~" : ""}
{formatBytes(option.bytes)}
</Text>
</Pressable>
))}
<View style={styles.rememberRow}>
<Text style={{ color: colors.foreground, fontSize: 15 }}>
Remember my choice
+1 -3
View File
@@ -16,7 +16,6 @@ import {
type DownloadQuality,
} from "@otunes/convex/download-quality"
import { getAuthCookieHeader } from "@/lib/auth-cookies"
import { downloadQualitySupported } from "@/lib/playback-capabilities"
import type { ServerConfig } from "@/lib/server-config"
const REMEMBERED_QUALITY_KEY = "otunes.download-quality"
@@ -299,10 +298,9 @@ export function downloadedCoverUri(url: string) {
export async function readRememberedDownloadQuality() {
try {
const quality = parseDownloadQuality(
return parseDownloadQuality(
await AsyncStorage.getItem(REMEMBERED_QUALITY_KEY)
)
return quality && downloadQualitySupported(quality) ? quality : undefined
} catch {
return undefined
}
-15
View File
@@ -1,10 +1,5 @@
import { Platform } from "react-native"
import {
DOWNLOAD_QUALITIES,
type DownloadQuality,
} from "@otunes/convex/download-quality"
// Android Dolby decoder reports do not reliably indicate working Atmos playback.
export const dolbyAtmosSupported = Platform.OS === "ios"
@@ -12,13 +7,3 @@ export const dolbyAtmosSupported = Platform.OS === "ios"
export function atmosEnabled(user: { preferAtmos?: boolean }) {
return dolbyAtmosSupported && (user.preferAtmos ?? false)
}
/** Whether this device may download in a quality. Android cannot download Atmos. */
export function downloadQualitySupported(quality: DownloadQuality) {
return quality !== "atmos" || dolbyAtmosSupported
}
/** Download qualities this device offers, lowest first. */
export const deviceDownloadQualities = DOWNLOAD_QUALITIES.filter(
downloadQualitySupported
)
+3 -4
View File
@@ -39,10 +39,9 @@ const ASK_EVERY_TIME = "ask"
/** Shades of the text color, darkest for the smallest files. */
const QUALITY_OPACITY: Record<DownloadQuality, number> = {
low: 0.2,
medium: 0.35,
high: 0.5,
lossless: 0.75,
medium: 0.25,
high: 0.45,
lossless: 0.7,
atmos: 1,
}
+3 -10
View File
@@ -2,7 +2,6 @@ import type { PlaybackSource, PlaybackStreamPlan } from "./playback-stream"
/** Qualities a listener can pick when downloading, lowest first. */
export const DOWNLOAD_QUALITIES = [
"low",
"medium",
"high",
"lossless",
@@ -12,7 +11,6 @@ export const DOWNLOAD_QUALITIES = [
export type DownloadQuality = (typeof DOWNLOAD_QUALITIES)[number]
export const DOWNLOAD_QUALITY_LABELS: Record<DownloadQuality, string> = {
low: "Low",
medium: "Medium",
high: "High",
lossless: "Lossless",
@@ -20,14 +18,12 @@ export const DOWNLOAD_QUALITY_LABELS: Record<DownloadQuality, string> = {
}
export const DOWNLOAD_QUALITY_DETAILS: Record<DownloadQuality, string> = {
low: "AAC 64 kbps",
medium: "AAC 128 kbps",
high: "AAC 256 kbps",
lossless: "ALAC or FLAC",
atmos: "Spatial audio",
}
const LOW_KBPS = 64
const MEDIUM_KBPS = 128
const HIGH_KBPS = 256
@@ -58,14 +54,13 @@ function highPlan(files: Record<string, unknown>): DownloadPlan {
/**
* Picks the file for one song. Lossless and Dolby Atmos fall back to High when
* the song lacks them, and Low and Medium are always transcoded.
* the song lacks them, and Medium is always transcoded.
*/
export function downloadPlan(
files: Record<string, unknown>,
quality: DownloadQuality
): DownloadPlan {
switch (quality) {
case "low":
case "medium":
return {
quality,
@@ -75,7 +70,7 @@ export function downloadPlan(
: "normal" in files
? "normal"
: "atmos",
kbps: quality === "low" ? LOW_KBPS : MEDIUM_KBPS,
kbps: MEDIUM_KBPS,
}
case "high":
return highPlan(files)
@@ -89,7 +84,7 @@ export function downloadPlan(
/**
* The download quality holding the same audio a stream plan plays, so a
* download can stand in for streaming.
* download can stand in for streaming. Low has no download equivalent.
*/
export function streamDownloadQuality(
plan: PlaybackStreamPlan
@@ -100,7 +95,6 @@ export function streamDownloadQuality(
}
if (plan.kbps === HIGH_KBPS) return "high"
if (plan.kbps === MEDIUM_KBPS) return "medium"
if (plan.kbps === LOW_KBPS) return "low"
return undefined
}
@@ -135,7 +129,6 @@ export function downloadOptions(
).length
if (
fallbackCount === songs.length &&
quality !== "low" &&
quality !== "medium" &&
quality !== "high"
) {