2026-03-19 16:34:56 +08:00
|
|
|
import React from 'react';
|
2026-03-20 14:06:52 +08:00
|
|
|
import { View, Text, TouchableOpacity, StyleSheet, ActivityIndicator } from 'react-native';
|
2026-03-19 16:34:56 +08:00
|
|
|
import { SafeAreaView } from 'react-native-safe-area-context';
|
|
|
|
|
import { useRouter } from 'expo-router';
|
|
|
|
|
import { Ionicons } from '@expo/vector-icons';
|
|
|
|
|
import { useAuthStore } from '../store/authStore';
|
|
|
|
|
import { useSettingsStore } from '../store/settingsStore';
|
2026-03-24 21:04:10 +08:00
|
|
|
import { useTheme } from '../utils/theme';
|
2026-03-20 14:06:52 +08:00
|
|
|
import { useCheckUpdate } from '../hooks/useCheckUpdate';
|
2026-03-19 16:34:56 +08:00
|
|
|
|
|
|
|
|
export default function SettingsScreen() {
|
|
|
|
|
const router = useRouter();
|
|
|
|
|
const { isLoggedIn, logout } = useAuthStore();
|
2026-03-24 21:04:10 +08:00
|
|
|
const { darkMode, setDarkMode, trafficSaving, setTrafficSaving } = useSettingsStore();
|
|
|
|
|
const theme = useTheme();
|
2026-03-20 14:06:52 +08:00
|
|
|
const { currentVersion, isChecking, downloadProgress, checkUpdate } = useCheckUpdate();
|
2026-03-19 16:34:56 +08:00
|
|
|
|
|
|
|
|
const handleLogout = async () => {
|
|
|
|
|
await logout();
|
|
|
|
|
router.back();
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
return (
|
2026-03-24 21:04:10 +08:00
|
|
|
<SafeAreaView style={[styles.safe, { backgroundColor: theme.bg }]}>
|
|
|
|
|
<View style={[styles.topBar, { backgroundColor: theme.card, borderBottomColor: theme.border }]}>
|
2026-03-19 16:34:56 +08:00
|
|
|
<TouchableOpacity onPress={() => router.back()} style={styles.backBtn}>
|
2026-03-24 21:04:10 +08:00
|
|
|
<Ionicons name="chevron-back" size={24} color={theme.text} />
|
2026-03-19 16:34:56 +08:00
|
|
|
</TouchableOpacity>
|
2026-03-24 21:04:10 +08:00
|
|
|
<Text style={[styles.topTitle, { color: theme.text }]}>设置</Text>
|
2026-03-19 16:34:56 +08:00
|
|
|
<View style={styles.spacer} />
|
|
|
|
|
</View>
|
|
|
|
|
|
2026-03-24 21:04:10 +08:00
|
|
|
<View style={[styles.section, { backgroundColor: theme.card, borderColor: theme.border }]}>
|
|
|
|
|
<Text style={[styles.sectionLabel, { color: theme.textSub }]}>版本信息</Text>
|
2026-03-20 14:06:52 +08:00
|
|
|
<View style={styles.versionRow}>
|
2026-03-24 21:04:10 +08:00
|
|
|
<Text style={[styles.versionLabel, { color: theme.text }]}>当前版本</Text>
|
|
|
|
|
<Text style={[styles.versionValue, { color: theme.textSub }]}>v{currentVersion}</Text>
|
2026-03-20 14:06:52 +08:00
|
|
|
</View>
|
|
|
|
|
</View>
|
|
|
|
|
|
2026-03-24 21:04:10 +08:00
|
|
|
<View style={[styles.section, { backgroundColor: theme.card, borderColor: theme.border }]}>
|
|
|
|
|
<Text style={[styles.sectionLabel, { color: theme.textSub }]}>更新</Text>
|
2026-03-20 14:06:52 +08:00
|
|
|
<TouchableOpacity
|
|
|
|
|
style={styles.updateBtn}
|
|
|
|
|
onPress={checkUpdate}
|
|
|
|
|
activeOpacity={0.7}
|
|
|
|
|
disabled={isChecking || downloadProgress !== null}
|
|
|
|
|
>
|
|
|
|
|
{isChecking ? (
|
|
|
|
|
<>
|
|
|
|
|
<ActivityIndicator size="small" color="#00AEEC" style={{ marginRight: 8 }} />
|
|
|
|
|
<Text style={styles.updateBtnText}>检查中...</Text>
|
|
|
|
|
</>
|
|
|
|
|
) : downloadProgress !== null ? (
|
|
|
|
|
<Text style={styles.updateBtnText}>下载中 {downloadProgress}%</Text>
|
|
|
|
|
) : (
|
|
|
|
|
<Text style={styles.updateBtnText}>检查更新</Text>
|
|
|
|
|
)}
|
|
|
|
|
</TouchableOpacity>
|
|
|
|
|
</View>
|
|
|
|
|
|
2026-03-24 21:04:10 +08:00
|
|
|
<View style={[styles.section, { backgroundColor: theme.card, borderColor: theme.border }]}>
|
|
|
|
|
<Text style={[styles.sectionLabel, { color: theme.textSub }]}>外观</Text>
|
2026-03-19 16:34:56 +08:00
|
|
|
<View style={styles.optionRow}>
|
|
|
|
|
<TouchableOpacity
|
2026-03-24 21:04:10 +08:00
|
|
|
style={[styles.option, !darkMode && styles.optionActive]}
|
|
|
|
|
onPress={() => setDarkMode(false)}
|
2026-03-19 16:34:56 +08:00
|
|
|
activeOpacity={0.7}
|
|
|
|
|
>
|
2026-03-24 21:04:10 +08:00
|
|
|
<Text style={[styles.optionText, !darkMode && styles.optionTextActive]}>浅色</Text>
|
2026-03-19 16:34:56 +08:00
|
|
|
</TouchableOpacity>
|
|
|
|
|
<TouchableOpacity
|
2026-03-24 21:04:10 +08:00
|
|
|
style={[styles.option, darkMode && styles.optionActive]}
|
|
|
|
|
onPress={() => setDarkMode(true)}
|
2026-03-19 16:34:56 +08:00
|
|
|
activeOpacity={0.7}
|
|
|
|
|
>
|
2026-03-24 21:04:10 +08:00
|
|
|
<Text style={[styles.optionText, darkMode && styles.optionTextActive]}>深色</Text>
|
2026-03-19 16:34:56 +08:00
|
|
|
</TouchableOpacity>
|
|
|
|
|
</View>
|
|
|
|
|
</View>
|
|
|
|
|
|
2026-03-24 21:04:10 +08:00
|
|
|
<View style={[styles.section, { backgroundColor: theme.card, borderColor: theme.border }]}>
|
|
|
|
|
<Text style={[styles.sectionLabel, { color: theme.textSub }]}>流量</Text>
|
|
|
|
|
<View style={styles.optionRow}>
|
|
|
|
|
<TouchableOpacity
|
|
|
|
|
style={[styles.option, !trafficSaving && styles.optionActive]}
|
|
|
|
|
onPress={() => setTrafficSaving(false)}
|
|
|
|
|
activeOpacity={0.7}
|
|
|
|
|
>
|
|
|
|
|
<Text style={[styles.optionText, !trafficSaving && styles.optionTextActive]}>标准</Text>
|
|
|
|
|
</TouchableOpacity>
|
|
|
|
|
<TouchableOpacity
|
|
|
|
|
style={[styles.option, trafficSaving && styles.optionActive]}
|
|
|
|
|
onPress={() => setTrafficSaving(true)}
|
|
|
|
|
activeOpacity={0.7}
|
|
|
|
|
>
|
|
|
|
|
<Text style={[styles.optionText, trafficSaving && styles.optionTextActive]}>节流</Text>
|
|
|
|
|
</TouchableOpacity>
|
|
|
|
|
</View>
|
|
|
|
|
{trafficSaving && (
|
|
|
|
|
<Text style={[styles.hint, { color: theme.textSub }]}>
|
|
|
|
|
封面低画质 · 首页视频不自动播放 · 视频默认 360p
|
|
|
|
|
</Text>
|
|
|
|
|
)}
|
|
|
|
|
</View>
|
|
|
|
|
|
2026-03-19 16:34:56 +08:00
|
|
|
{isLoggedIn && (
|
|
|
|
|
<TouchableOpacity style={styles.logoutBtn} onPress={handleLogout} activeOpacity={0.8}>
|
|
|
|
|
<Text style={styles.logoutText}>退出登录</Text>
|
|
|
|
|
</TouchableOpacity>
|
|
|
|
|
)}
|
|
|
|
|
</SafeAreaView>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const styles = StyleSheet.create({
|
2026-03-24 21:04:10 +08:00
|
|
|
safe: { flex: 1 },
|
2026-03-19 16:34:56 +08:00
|
|
|
topBar: {
|
|
|
|
|
flexDirection: 'row',
|
|
|
|
|
alignItems: 'center',
|
|
|
|
|
paddingHorizontal: 8,
|
|
|
|
|
paddingVertical: 8,
|
|
|
|
|
borderBottomWidth: StyleSheet.hairlineWidth,
|
|
|
|
|
},
|
|
|
|
|
backBtn: { padding: 4, width: 32 },
|
|
|
|
|
spacer: { width: 32 },
|
|
|
|
|
topTitle: {
|
|
|
|
|
flex: 1,
|
|
|
|
|
fontSize: 16,
|
|
|
|
|
fontWeight: '600',
|
|
|
|
|
textAlign: 'center',
|
|
|
|
|
},
|
|
|
|
|
section: {
|
|
|
|
|
marginTop: 16,
|
|
|
|
|
paddingHorizontal: 16,
|
|
|
|
|
paddingVertical: 14,
|
|
|
|
|
borderTopWidth: StyleSheet.hairlineWidth,
|
|
|
|
|
borderBottomWidth: StyleSheet.hairlineWidth,
|
|
|
|
|
},
|
2026-03-24 21:04:10 +08:00
|
|
|
sectionLabel: { fontSize: 13, marginBottom: 10 },
|
2026-03-19 16:34:56 +08:00
|
|
|
optionRow: { flexDirection: 'row', gap: 10 },
|
|
|
|
|
option: {
|
2026-03-25 12:03:28 +08:00
|
|
|
paddingHorizontal: 10,
|
|
|
|
|
paddingVertical: 2,
|
|
|
|
|
borderRadius: 16,
|
|
|
|
|
backgroundColor: '#f0f0f0',
|
2026-03-19 16:34:56 +08:00
|
|
|
},
|
2026-03-25 12:03:28 +08:00
|
|
|
optionActive: { backgroundColor: '#00AEEC' },
|
|
|
|
|
optionText: { fontSize: 13, color: '#333', fontWeight: '500' },
|
|
|
|
|
optionTextActive: { color: '#fff', fontWeight: '600' },
|
2026-03-24 21:04:10 +08:00
|
|
|
hint: { fontSize: 12, marginTop: 8 },
|
2026-03-20 14:06:52 +08:00
|
|
|
versionRow: {
|
|
|
|
|
flexDirection: 'row',
|
|
|
|
|
justifyContent: 'space-between',
|
|
|
|
|
alignItems: 'center',
|
|
|
|
|
},
|
2026-03-24 21:04:10 +08:00
|
|
|
versionLabel: { fontSize: 14 },
|
|
|
|
|
versionValue: { fontSize: 14 },
|
2026-03-20 14:06:52 +08:00
|
|
|
updateBtn: {
|
|
|
|
|
flexDirection: 'row',
|
|
|
|
|
alignItems: 'center',
|
|
|
|
|
paddingVertical: 6,
|
|
|
|
|
},
|
|
|
|
|
updateBtnText: { fontSize: 14, color: '#00AEEC', fontWeight: '600' },
|
2026-03-19 16:34:56 +08:00
|
|
|
logoutBtn: {
|
|
|
|
|
margin: 24,
|
|
|
|
|
paddingVertical: 12,
|
|
|
|
|
borderRadius: 8,
|
|
|
|
|
borderWidth: 1,
|
|
|
|
|
borderColor: '#ff4757',
|
|
|
|
|
alignItems: 'center',
|
|
|
|
|
},
|
|
|
|
|
logoutText: { fontSize: 15, color: '#ff4757', fontWeight: '600' },
|
|
|
|
|
});
|