import React from 'react'; import { ScrollView, StyleSheet, Switch, View, TextInput, Pressable } from 'react-native'; import { useColorScheme } from 'react-native'; import { ThemedText } from '@/components/themed-text'; import { ThemedView } from '@/components/themed-view'; import { Collapsible } from '@/components/ui/collapsible'; import { SYNC_INTERVALS, SyncInterval, NotificationPreferences, ReadingPreferences } from '@/types/feed'; import { AccountSettings } from '@/types/global'; import { useTheme } from '@/hooks/use-theme'; import { useSettingsStore } from '@/stores/settings-store'; export default function SettingsScreen() { const colorScheme = useColorScheme(); const theme = useTheme(); const { syncInterval, setSyncInterval, theme: themeSetting, setTheme, notificationPreferences, setNotificationPreferences, readingPreferences, setReadingPreferences, accountSettings, setAccountSettings, } = useSettingsStore(); // Sync interval handler const handleSyncIntervalChange = (value: number) => { const interval = SYNC_INTERVALS.find((i) => i.value === value); if (interval) { setSyncInterval(interval); } }; // Notification handlers const handleNotificationToggle = (key: keyof NotificationPreferences, value: boolean) => { setNotificationPreferences({ [key]: value }); }; // Reading preference handlers const handleReadingToggle = (key: keyof ReadingPreferences, value: boolean) => { setReadingPreferences({ [key]: value }); }; const handleFontSizeChange = (size: ReadingPreferences['fontSize']) => { setReadingPreferences({ fontSize: size }); }; const handleLineHeightChange = (height: ReadingPreferences['lineHeight']) => { setReadingPreferences({ lineHeight: height }); }; // Theme handler const handleThemeChange = (theme: 'light' | 'dark' | 'system') => { setTheme(theme); }; // Account settings handlers const handleAccountSettingChange = (key: keyof AccountSettings, value: string | boolean) => { setAccountSettings({ [key]: value }); }; return ( {/* Sync Settings */} Sync Settings Choose how often your feeds should be updated. {SYNC_INTERVALS.map((interval) => ( handleSyncIntervalChange(interval.value)} style={({ pressed }) => [ styles.intervalItem, { backgroundColor: syncInterval.value === interval.value ? theme.backgroundSelected : theme.backgroundElement, opacity: pressed ? 0.7 : 1, }, ]} > {interval.label} {syncInterval.value === interval.value && ( )} ))} {/* Theme */} Theme Choose your preferred appearance. handleThemeChange('light')} style={({ pressed }) => [ styles.themeButton, { opacity: pressed ? 0.7 : 1 }, ]} > Light handleThemeChange('dark')} style={({ pressed }) => [ styles.themeButton, { opacity: pressed ? 0.7 : 1 }, ]} > Dark handleThemeChange('system')} style={({ pressed }) => [ styles.themeButton, { opacity: pressed ? 0.7 : 1 }, ]} > System ⚠️ Note Changing theme will apply on app restart. {/* Notifications */} Notifications Manage how you receive notifications. New Articles handleNotificationToggle('newArticles', value)} trackColor={{ false: theme.textSecondary, true: theme.text }} thumbColor="white" /> Episode Releases handleNotificationToggle('episodeReleases', value)} trackColor={{ false: theme.textSecondary, true: theme.text }} thumbColor="white" /> Custom Alerts handleNotificationToggle('customAlerts', value)} trackColor={{ false: theme.textSecondary, true: theme.text }} thumbColor="white" /> Sound handleNotificationToggle('sound', value)} trackColor={{ false: theme.textSecondary, true: theme.text }} thumbColor="white" /> Vibration handleNotificationToggle('vibration', value)} trackColor={{ false: theme.textSecondary, true: theme.text }} thumbColor="white" /> {/* Reading Preferences */} Reading Preferences Customize your reading experience. Font Size {(['small', 'medium', 'large', 'xlarge'] as ReadingPreferences['fontSize'][]).map((size) => ( handleFontSizeChange(size)} style={({ pressed }) => [ styles.fontSizeButton, { backgroundColor: readingPreferences.fontSize === size ? theme.backgroundSelected : theme.backgroundElement, opacity: pressed ? 0.7 : 1, }, ]} > {size === 'small' ? 'A' : size === 'medium' ? 'B' : size === 'large' ? 'C' : 'D'} ))} Line Height {(['normal', 'relaxed', 'loose'] as ReadingPreferences['lineHeight'][]).map((height) => ( handleLineHeightChange(height)} style={({ pressed }) => [ styles.lineHeightButton, { backgroundColor: readingPreferences.lineHeight === height ? theme.backgroundSelected : theme.backgroundElement, opacity: pressed ? 0.7 : 1, }, ]} > {height.charAt(0).toUpperCase() + height.slice(1)} ))} Show Reading Time handleReadingToggle('showReadingTime', value)} trackColor={{ false: theme.textSecondary, true: theme.text }} thumbColor="white" /> Show Author handleReadingToggle('showAuthor', value)} trackColor={{ false: theme.textSecondary, true: theme.text }} thumbColor="white" /> Show Date handleReadingToggle('showDate', value)} trackColor={{ false: theme.textSecondary, true: theme.text }} thumbColor="white" /> {/* Account Settings */} Account Settings Manage your account preferences. Email handleAccountSettingChange('email', text)} keyboardType="email-address" autoCapitalize="none" /> Privacy Level {(['public', 'private', 'anonymous'] as AccountSettings['privacy'][]).map((privacy) => ( handleAccountSettingChange('privacy', privacy)} style={({ pressed }) => [ styles.privacyButton, { backgroundColor: accountSettings.privacy === privacy ? theme.backgroundSelected : theme.backgroundElement, opacity: pressed ? 0.7 : 1, }, ]} > {privacy.charAt(0).toUpperCase() + privacy.slice(1)} ))} Language handleAccountSettingChange('language', text)} /> Timezone handleAccountSettingChange('timezone', text)} /> Notifications Enabled handleAccountSettingChange('notificationsEnabled', value)} trackColor={{ false: theme.textSecondary, true: theme.text }} thumbColor="white" /> ); } const styles = StyleSheet.create({ container: { flex: 1, }, scrollView: { flex: 1, }, scrollContent: { paddingBottom: 24, }, section: { marginBottom: 24, paddingHorizontal: 16, }, sectionTitle: { marginBottom: 4, }, sectionDescription: { marginBottom: 16, }, intervalContainer: { gap: 8, }, intervalItem: { flexDirection: 'row', alignItems: 'center', justifyContent: 'space-between', padding: 16, borderRadius: 12, gap: 12, }, intervalLabel: { fontSize: 14, }, checkmark: { width: 20, height: 20, borderRadius: 10, justifyContent: 'center', alignItems: 'center', }, checkmarkCircle: { width: 12, height: 12, borderRadius: 6, backgroundColor: '#4CAF50', }, themeContainer: { flexDirection: 'row', justifyContent: 'space-around', alignItems: 'center', marginBottom: 16, }, themeButton: { alignItems: 'center', gap: 4, }, themeCircle: { width: 40, height: 40, borderRadius: 20, }, themeLabel: { fontSize: 12, }, warningBox: { padding: 12, borderRadius: 8, marginBottom: 16, }, warningTitle: { marginBottom: 4, }, warningText: {}, prefGroup: { marginBottom: 8, }, prefHeader: { flexDirection: 'row', alignItems: 'center', justifyContent: 'space-between', }, prefTitle: { fontSize: 14, }, fontSizeSelector: { flexDirection: 'row', gap: 8, }, fontSizeButton: { padding: 12, borderRadius: 8, minWidth: 44, alignItems: 'center', justifyContent: 'center', }, fontSizeLabel: { fontWeight: 'bold', }, lineHeightSelector: { flexDirection: 'row', gap: 8, }, lineHeightButton: { flex: 1, padding: 12, borderRadius: 8, alignItems: 'center', }, lineHeightLabel: { fontSize: 12, textAlign: 'center', }, input: { borderRadius: 8, padding: 12, fontSize: 14, marginTop: 4, }, privacySelector: { flexDirection: 'row', gap: 8, marginTop: 4, }, privacyButton: { flex: 1, padding: 12, borderRadius: 8, alignItems: 'center', }, privacyLabel: { fontSize: 14, textAlign: 'center', }, });