diff --git a/lib/main.dart b/lib/main.dart index 443b1a55..f31e048c 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -1,4 +1,3 @@ -import 'package:flutter/foundation.dart'; import 'package:flutter/material.dart'; import 'package:ice_live_viewer/pages/home.dart'; import 'package:ice_live_viewer/pages/newhome.dart'; diff --git a/lib/pages/settings.dart b/lib/pages/settings.dart index a911bdf7..871c463a 100644 --- a/lib/pages/settings.dart +++ b/lib/pages/settings.dart @@ -24,10 +24,10 @@ class SettingsPage extends StatelessWidget { title: 'General', ), ListTile( - title: const Text('Settings'), + title: const Text('Under Construction'), subtitle: const Text('This page is still not complete'), leading: const Icon( - Icons.warning_amber_rounded, + Icons.construction_rounded, size: 32, ), onTap: () {}, @@ -41,9 +41,18 @@ class SettingsPage extends StatelessWidget { ), onTap: () { Provider.of(context, listen: false) - .showThemeDialog(context); + .showThemeSelectorDialog(context); }, ), + ListTile( + title: const Text('Change Language'), + subtitle: const Text('Change the language of the app'), + leading: const Icon( + Icons.translate, + size: 32, + ), + onTap: () {}, + ), const SwitchTile( title: 'Use custom resolution for Huya', subtitle: @@ -60,7 +69,7 @@ class SettingsPage extends StatelessWidget { title: 'Experimental', ), const SwitchTile( - title: '[Only Windows] Use Native Player', + title: '[Only Windows|Not complete] Use Native Player', subtitle: 'This setup only uses Win32 APIs & no texture, intermediate buffers or copying of pixel buffers.', settingKey: 'use_native_player', diff --git a/lib/provider/themeprovider.dart b/lib/provider/themeprovider.dart index 10242d23..525b92a1 100644 --- a/lib/provider/themeprovider.dart +++ b/lib/provider/themeprovider.dart @@ -1,18 +1,11 @@ import 'package:flutter/material.dart'; +import 'package:ice_live_viewer/utils/prefs_helper.dart'; class AppThemeProvider extends ChangeNotifier { - AppTheme() { - changeThemeColor(0); + AppThemeProvider() { + changeThemeColor(PrefsHelper.getThemeColorPrefIndex()); } - int _themeModeIndex = 0; - int get themeModeIndex => _themeModeIndex; - int _themeColorIndex = 4; - int get themeColorIndex => _themeColorIndex; - String _themeColorName = ''; - - get themeColor => themeColors.values.toList()[_themeColorIndex]; - static Map themeModes = { "system": ThemeMode.system, "on": ThemeMode.dark, @@ -20,53 +13,58 @@ class AppThemeProvider extends ChangeNotifier { }; static Map themeColors = { - "indigo": Colors.indigo, - "violet": Colors.deepPurple, - "grass": Colors.lightGreen, - "teal": Colors.teal, - "seafoam": const Color.fromARGB(255, 112, 193, 207), + "Crimson": const Color.fromARGB(255, 220, 20, 60), + "Orange": Colors.orange, + "Chrome": const Color.fromARGB(255, 230, 184, 0), + "Grass": Colors.lightGreen, + "Teal": Colors.teal, + "Sea Foam": const Color.fromARGB(255, 112, 193, 207), + "Blue": Colors.blue, + "Indigo": Colors.indigo, + "Violet": Colors.deepPurple, + "Orchid": const Color.fromARGB(255, 218, 112, 214), }; - void setThemeModeIndex(int index) { - _themeModeIndex = index; - notifyListeners(); - } - - void setThemeColorIndex(int index) { - _themeColorIndex = index; - notifyListeners(); - } - + late Color _themeColor; + late String _themeColorName; + get themeColor => _themeColor; + get themeColorName => _themeColorName; void changeThemeColor(int index) { + _themeColor = AppThemeProvider.themeColors.values.toList()[index]; _themeColorName = AppThemeProvider.themeColors.keys.toList()[index]; notifyListeners(); + PrefsHelper.setThemeColorPrefIndex(index); } - List _createThemeWidget(BuildContext context) { - List widgets = []; + List _createThemeSelectorWidget(BuildContext context) { + List themeSelectorWidgets = []; for (var item in AppThemeProvider.themeColors.keys) { - widgets.add(RadioListTile( + themeSelectorWidgets.add(RadioListTile( groupValue: item, value: _themeColorName, title: Text(item, style: TextStyle(color: AppThemeProvider.themeColors[item])), onChanged: (value) { - setThemeColorIndex( + changeThemeColor( AppThemeProvider.themeColors.keys.toList().indexOf(item)); - Navigator.of(context).pop(); + //Navigator.of(context).pop(); }, )); } - return widgets; + return themeSelectorWidgets; } - void showThemeDialog(BuildContext context) { + void showThemeSelectorDialog(BuildContext context) { showDialog( context: context, builder: (BuildContext context) { return SimpleDialog( - title: const Text('切换主题'), - children: _createThemeWidget(context), + title: Text( + 'Change Theme', + style: + TextStyle(color: AppThemeProvider.themeColors[_themeColorName]), + ), + children: _createThemeSelectorWidget(context), ); }, ); diff --git a/lib/utils/http/huyaparser.dart b/lib/utils/http/huyaparser.dart index 79f1c84e..937807ed 100644 --- a/lib/utils/http/huyaparser.dart +++ b/lib/utils/http/huyaparser.dart @@ -67,7 +67,6 @@ Future> getLiveInfo(String url) async { } else { int lUid = roomInfo['profileInfo']['uid']; String cover = roomInfo['liveData']['screenshot']; - //TODO fix cover 403 Map streamDict = roomInfo['stream']['flv']; List multiLine = streamDict['multiLine']; List rateArray = streamDict['rateArray']; diff --git a/lib/utils/init/ioinit.dart b/lib/utils/init/ioinit.dart index 4565b92f..01fa14ee 100644 --- a/lib/utils/init/ioinit.dart +++ b/lib/utils/init/ioinit.dart @@ -3,17 +3,19 @@ import 'package:dart_vlc/dart_vlc.dart'; import 'dart:io'; import 'package:ice_live_viewer/main.dart'; import 'package:ice_live_viewer/provider/themeprovider.dart'; +import 'package:ice_live_viewer/utils/prefs_helper.dart'; import 'package:provider/provider.dart'; +import 'package:shared_preferences/shared_preferences.dart'; -void init() { +void init() async { if (Platform.isWindows) { DartVLC.initialize(useFlutterNativeView: false); - runApp(MultiProvider(providers: [ - ChangeNotifierProvider(create: (_) => AppThemeProvider()), - ], child: const MyApp())); - } else { - runApp(MultiProvider(providers: [ - ChangeNotifierProvider(create: (_) => AppThemeProvider()), - ], child: const MyApp())); } + PrefsHelper.prefs = await SharedPreferences.getInstance(); + runApp(MultiProvider(providers: [ + ChangeNotifierProvider( + create: (_) => AppThemeProvider(), + lazy: false, + ), + ], child: const MyApp())); } diff --git a/lib/utils/prefs_helper.dart b/lib/utils/prefs_helper.dart new file mode 100644 index 00000000..2ecbf2fb --- /dev/null +++ b/lib/utils/prefs_helper.dart @@ -0,0 +1,15 @@ +import 'package:shared_preferences/shared_preferences.dart'; + +///This is the new class for the shared preferences. +///And the old storage.dart will be deprecated. +class PrefsHelper { + static late SharedPreferences prefs; + + static int getThemeColorPrefIndex() { + return prefs.getInt('theme_color') ?? 0; + } + + static void setThemeColorPrefIndex(int pref) async { + prefs.setInt('theme_color', pref); + } +} diff --git a/lib/utils/storage.dart b/lib/utils/storage.dart index 887eb00a..6ac12958 100644 --- a/lib/utils/storage.dart +++ b/lib/utils/storage.dart @@ -1,6 +1,6 @@ import 'package:flutter/material.dart'; import 'package:shared_preferences/shared_preferences.dart'; -//import 'dart:convert'; +//TODO deprecated this util file and use the new one. //create a function to get all the data and store every value into a map Future> getAllData() async { diff --git a/lib/utils/theme.dart b/lib/utils/theme.dart index 258462c9..5119406e 100644 --- a/lib/utils/theme.dart +++ b/lib/utils/theme.dart @@ -7,10 +7,12 @@ class MyTheme { get lightThemeData => ThemeData.from( colorScheme: ColorScheme.fromSeed( - seedColor: primaryColor, - brightness: Brightness.light, - primary: primaryColor, - secondary: primaryColor), + seedColor: primaryColor, + brightness: Brightness.light, + primary: primaryColor, + secondary: primaryColor, + background: Colors.grey[50], + ), useMaterial3: true, textTheme: TextTheme( headline1: TextStyle(