This commit is contained in:
		
							
								
								
									
										110
									
								
								lib/controller/media_controller.dart
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										110
									
								
								lib/controller/media_controller.dart
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,110 @@
 | 
			
		||||
import 'package:encrypt_shared_preferences/provider.dart';
 | 
			
		||||
import 'package:f0ckapp/utils/animatedtransition.dart';
 | 
			
		||||
import 'package:get/get.dart';
 | 
			
		||||
 | 
			
		||||
import 'package:f0ckapp/service/media_service.dart';
 | 
			
		||||
import 'package:f0ckapp/models/media_item.dart';
 | 
			
		||||
 | 
			
		||||
class MediaController extends GetxController {
 | 
			
		||||
  final EncryptedSharedPreferencesAsync storage =
 | 
			
		||||
      EncryptedSharedPreferencesAsync.getInstance();
 | 
			
		||||
 | 
			
		||||
  final RxList<MediaItem> mediaItems = <MediaItem>[].obs;
 | 
			
		||||
  final RxBool isLoading = false.obs;
 | 
			
		||||
  final RxString errorMessage = ''.obs;
 | 
			
		||||
  final MediaService _mediaService = MediaService();
 | 
			
		||||
 | 
			
		||||
  RxnString tag = RxnString();
 | 
			
		||||
  RxInt type = 0.obs;
 | 
			
		||||
  RxInt mode = 0.obs;
 | 
			
		||||
  RxBool random = false.obs;
 | 
			
		||||
  late RxBool muted = false.obs;
 | 
			
		||||
  late RxInt crossAxisCount = 0.obs;
 | 
			
		||||
  late RxBool drawerSwipeEnabled = true.obs;
 | 
			
		||||
  final Rx<PageTransition> transitionType = PageTransition.opacity.obs;
 | 
			
		||||
 | 
			
		||||
  @override
 | 
			
		||||
  void onInit() async {
 | 
			
		||||
    super.onInit();
 | 
			
		||||
    await loadSettings();
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  Future<void> loadSettings() async {
 | 
			
		||||
    muted.value = await storage.getBoolean('muted') ?? false;
 | 
			
		||||
    crossAxisCount.value = await storage.getInt('crossAxisCount') ?? 0;
 | 
			
		||||
    drawerSwipeEnabled.value =
 | 
			
		||||
        await storage.getBoolean('drawerSwipeEnabled') ?? true;
 | 
			
		||||
    transitionType.value =
 | 
			
		||||
        PageTransition.values[await storage.getInt('transitionType') ?? 0];
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  Future<void> saveSettings() async {
 | 
			
		||||
    await storage.setBoolean('muted', muted.value);
 | 
			
		||||
    await storage.setInt('crossAxisCount', crossAxisCount.value);
 | 
			
		||||
    await storage.setBoolean('drawerSwipeEnabled', drawerSwipeEnabled.value);
 | 
			
		||||
    await storage.setInt('transitionType', transitionType.value.index);
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  Future<void> setTag(String? newTag) async {
 | 
			
		||||
    tag.value = newTag;
 | 
			
		||||
    await loadMediaItems();
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  Future<void> setType(int newType) async {
 | 
			
		||||
    type.value = newType;
 | 
			
		||||
    await loadMediaItems();
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  Future<void> setMode(int newMode) async {
 | 
			
		||||
    mode.value = newMode;
 | 
			
		||||
    await loadMediaItems();
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  Future<void> toggleRandom() async {
 | 
			
		||||
    random.value = !random.value;
 | 
			
		||||
    await loadMediaItems();
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  Future<void> toggleMuted() async {
 | 
			
		||||
    muted.value = !muted.value;
 | 
			
		||||
    await saveSettings();
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  Future<void> setCrossAxisCount(int newCrossAxisCount) async {
 | 
			
		||||
    crossAxisCount.value = newCrossAxisCount;
 | 
			
		||||
    await saveSettings();
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  Future<void> setDrawerSwipeEnabled(bool newValue) async {
 | 
			
		||||
    drawerSwipeEnabled.value = newValue;
 | 
			
		||||
    await saveSettings();
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  Future<void> setTransitionType(PageTransition newType) async {
 | 
			
		||||
    transitionType.value = newType;
 | 
			
		||||
    await saveSettings();
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  Future<void> loadMediaItems({int? older, bool append = false}) async {
 | 
			
		||||
    if (isLoading.value) return;
 | 
			
		||||
    try {
 | 
			
		||||
      isLoading.value = true;
 | 
			
		||||
      final List<MediaItem> items = await _mediaService.fetchMediaItems(
 | 
			
		||||
        type: type.value,
 | 
			
		||||
        mode: mode.value,
 | 
			
		||||
        random: random.value ? 1 : 0,
 | 
			
		||||
        tag: tag.value,
 | 
			
		||||
        older: older,
 | 
			
		||||
      );
 | 
			
		||||
 | 
			
		||||
      append ? mediaItems.addAll(items) : mediaItems.assignAll(items);
 | 
			
		||||
      
 | 
			
		||||
      errorMessage.value = '';
 | 
			
		||||
    } catch (e) {
 | 
			
		||||
      errorMessage.value = 'Fehler beim Laden der Daten: ${e.toString()}';
 | 
			
		||||
      Get.snackbar('Error', e.toString());
 | 
			
		||||
    } finally {
 | 
			
		||||
      isLoading.value = false;
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										289
									
								
								lib/controller/theme_controller.dart
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										289
									
								
								lib/controller/theme_controller.dart
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,289 @@
 | 
			
		||||
import 'package:flutter/material.dart';
 | 
			
		||||
 | 
			
		||||
import 'package:get/get.dart';
 | 
			
		||||
import 'package:encrypt_shared_preferences/provider.dart';
 | 
			
		||||
 | 
			
		||||
final ThemeData f0ckTheme = ThemeData(
 | 
			
		||||
  brightness: Brightness.dark,
 | 
			
		||||
  primaryColor: const Color(0xFF9FFF00),
 | 
			
		||||
  scaffoldBackgroundColor: const Color(0xFF000000),
 | 
			
		||||
  colorScheme: const ColorScheme.dark(
 | 
			
		||||
    primary: Color(0xFF9FFF00),
 | 
			
		||||
    secondary: Color(0xFF262626),
 | 
			
		||||
    surface: Color(0xFF232323),
 | 
			
		||||
    onPrimary: Color(0xFF000000),
 | 
			
		||||
    onSecondary: Colors.white,
 | 
			
		||||
    onSurface: Colors.white,
 | 
			
		||||
  ),
 | 
			
		||||
  appBarTheme: const AppBarTheme(
 | 
			
		||||
    backgroundColor: Color(0xFF2B2B2B),
 | 
			
		||||
    foregroundColor: Color(0xFF9FFF00),
 | 
			
		||||
    elevation: 2,
 | 
			
		||||
  ),
 | 
			
		||||
  textTheme: const TextTheme(
 | 
			
		||||
    bodyLarge: TextStyle(color: Colors.white),
 | 
			
		||||
    bodyMedium: TextStyle(color: Colors.white),
 | 
			
		||||
  ),
 | 
			
		||||
  elevatedButtonTheme: ElevatedButtonThemeData(
 | 
			
		||||
    style: ElevatedButton.styleFrom(
 | 
			
		||||
      foregroundColor: const Color(0xFF000000),
 | 
			
		||||
      backgroundColor: const Color(0xFF9FFF00),
 | 
			
		||||
    ),
 | 
			
		||||
  ),
 | 
			
		||||
  scrollbarTheme: ScrollbarThemeData(
 | 
			
		||||
    thumbColor: WidgetStateProperty.all<Color>(const Color(0xFF2B2B2B)),
 | 
			
		||||
    trackColor: WidgetStateProperty.all<Color>(const Color(0xFF424242)),
 | 
			
		||||
  ),
 | 
			
		||||
);
 | 
			
		||||
 | 
			
		||||
final ThemeData p1nkTheme = ThemeData(
 | 
			
		||||
  brightness: Brightness.dark,
 | 
			
		||||
  primaryColor: const Color(0xFF171717),
 | 
			
		||||
  scaffoldBackgroundColor: const Color(0xFF171717),
 | 
			
		||||
  appBarTheme: const AppBarTheme(
 | 
			
		||||
    color: Color(0xFF2B2B2B),
 | 
			
		||||
    foregroundColor: Color(0xFFFF00D0),
 | 
			
		||||
    elevation: 2,
 | 
			
		||||
  ),
 | 
			
		||||
  textTheme: const TextTheme(
 | 
			
		||||
    bodyLarge: TextStyle(color: Color(0xFFFFFFFF)),
 | 
			
		||||
    bodyMedium: TextStyle(color: Color(0xFFFFFFFF)),
 | 
			
		||||
    titleLarge: TextStyle(color: Color(0xFFFFFFFF)),
 | 
			
		||||
  ),
 | 
			
		||||
  elevatedButtonTheme: ElevatedButtonThemeData(
 | 
			
		||||
    style: ElevatedButton.styleFrom(
 | 
			
		||||
      foregroundColor: const Color(0xFF000000),
 | 
			
		||||
      backgroundColor: const Color(0xFFFF00D0),
 | 
			
		||||
    ),
 | 
			
		||||
  ),
 | 
			
		||||
  progressIndicatorTheme: const ProgressIndicatorThemeData(
 | 
			
		||||
    color: Color(0xFFFF00D0),
 | 
			
		||||
  ),
 | 
			
		||||
  scrollbarTheme: ScrollbarThemeData(
 | 
			
		||||
    thumbColor: WidgetStateProperty.all(const Color(0xFF2B2B2B)),
 | 
			
		||||
    trackColor: WidgetStateProperty.all(const Color(0xFF424242)),
 | 
			
		||||
  ),
 | 
			
		||||
  colorScheme: const ColorScheme.dark(
 | 
			
		||||
    primary: Color(0xFF171717),
 | 
			
		||||
    secondary: Color(0xFFFF00D0),
 | 
			
		||||
    surface: Color(0xFF171717),
 | 
			
		||||
    onPrimary: Color(0xFFFFFFFF),
 | 
			
		||||
    onSecondary: Color(0xFF000000),
 | 
			
		||||
    onSurface: Color(0xFFFFFFFF),
 | 
			
		||||
    error: Color(0xFFA72828),
 | 
			
		||||
  ),
 | 
			
		||||
);
 | 
			
		||||
 | 
			
		||||
final ThemeData paperTheme = ThemeData(
 | 
			
		||||
  brightness: Brightness.light,
 | 
			
		||||
  primaryColor: const Color(0xFF000000),
 | 
			
		||||
  scaffoldBackgroundColor: const Color(0xFFFFFFFF),
 | 
			
		||||
  colorScheme: const ColorScheme.light(
 | 
			
		||||
    primary: Color(0xFF000000),
 | 
			
		||||
    secondary: Color(0xFF262626),
 | 
			
		||||
    surface: Color(0xFFFFFFFF),
 | 
			
		||||
    onPrimary: Colors.white,
 | 
			
		||||
    onSecondary: Colors.white,
 | 
			
		||||
    onSurface: Color(0xFF000000),
 | 
			
		||||
  ),
 | 
			
		||||
  appBarTheme: const AppBarTheme(
 | 
			
		||||
    backgroundColor: Color(0xFFFFFFFF),
 | 
			
		||||
    foregroundColor: Color(0xFF000000),
 | 
			
		||||
    elevation: 0,
 | 
			
		||||
  ),
 | 
			
		||||
  textTheme: const TextTheme(
 | 
			
		||||
    bodyLarge: TextStyle(color: Color(0xFF000000)),
 | 
			
		||||
    bodyMedium: TextStyle(color: Color(0xFF000000)),
 | 
			
		||||
  ),
 | 
			
		||||
  elevatedButtonTheme: ElevatedButtonThemeData(
 | 
			
		||||
    style: ElevatedButton.styleFrom(
 | 
			
		||||
      foregroundColor: const Color(0xFFFFFFFF),
 | 
			
		||||
      backgroundColor: const Color(0xFF000000),
 | 
			
		||||
    ),
 | 
			
		||||
  ),
 | 
			
		||||
);
 | 
			
		||||
 | 
			
		||||
final ThemeData orangeTheme = ThemeData(
 | 
			
		||||
  brightness: Brightness.dark,
 | 
			
		||||
  primaryColor: const Color(0xFFFF6F00),
 | 
			
		||||
  scaffoldBackgroundColor: const Color(0xFF171717),
 | 
			
		||||
  colorScheme: const ColorScheme.dark(
 | 
			
		||||
    primary: Color(0xFFFF6F00),
 | 
			
		||||
    secondary: Color(0xFF262626),
 | 
			
		||||
    surface: Color(0xFF232323),
 | 
			
		||||
    onPrimary: Colors.white,
 | 
			
		||||
    onSecondary: Colors.white,
 | 
			
		||||
    onSurface: Colors.white,
 | 
			
		||||
  ),
 | 
			
		||||
  appBarTheme: const AppBarTheme(
 | 
			
		||||
    backgroundColor: Color(0xFF2B2B2B),
 | 
			
		||||
    foregroundColor: Color(0xFFFF6F00),
 | 
			
		||||
    elevation: 2,
 | 
			
		||||
  ),
 | 
			
		||||
  textTheme: const TextTheme(
 | 
			
		||||
    bodyLarge: TextStyle(color: Colors.white),
 | 
			
		||||
    bodyMedium: TextStyle(color: Colors.white),
 | 
			
		||||
  ),
 | 
			
		||||
  elevatedButtonTheme: ElevatedButtonThemeData(
 | 
			
		||||
    style: ElevatedButton.styleFrom(
 | 
			
		||||
      foregroundColor: Colors.white,
 | 
			
		||||
      backgroundColor: const Color(0xFFFF6F00),
 | 
			
		||||
    ),
 | 
			
		||||
  ),
 | 
			
		||||
  scrollbarTheme: ScrollbarThemeData(
 | 
			
		||||
    thumbColor: WidgetStateProperty.all<Color>(const Color(0xFF2B2B2B)),
 | 
			
		||||
    trackColor: WidgetStateProperty.all<Color>(const Color(0xFF424242)),
 | 
			
		||||
  ),
 | 
			
		||||
);
 | 
			
		||||
 | 
			
		||||
final ThemeData amoledTheme = ThemeData(
 | 
			
		||||
  brightness: Brightness.dark,
 | 
			
		||||
  primaryColor: const Color(0xFFFFFFFF),
 | 
			
		||||
  scaffoldBackgroundColor: const Color(0xFF000000),
 | 
			
		||||
  canvasColor: const Color(0xFF000000),
 | 
			
		||||
  cardColor: const Color(0xFF000000),
 | 
			
		||||
  colorScheme: const ColorScheme.dark(
 | 
			
		||||
    primary: Color(0xFFFFFFFF),
 | 
			
		||||
    secondary: Color(0xFF1F1F1F),
 | 
			
		||||
    surface: Color(0xFF000000),
 | 
			
		||||
    onPrimary: Color(0xFF000000),
 | 
			
		||||
    onSecondary: Colors.white,
 | 
			
		||||
    onSurface: Colors.white,
 | 
			
		||||
  ),
 | 
			
		||||
  appBarTheme: const AppBarTheme(
 | 
			
		||||
    backgroundColor: Color(0xFF000000),
 | 
			
		||||
    foregroundColor: Colors.white,
 | 
			
		||||
    elevation: 2,
 | 
			
		||||
  ),
 | 
			
		||||
  textTheme: const TextTheme(
 | 
			
		||||
    bodyLarge: TextStyle(color: Colors.white),
 | 
			
		||||
    bodyMedium: TextStyle(color: Colors.white),
 | 
			
		||||
  ),
 | 
			
		||||
  elevatedButtonTheme: ElevatedButtonThemeData(
 | 
			
		||||
    style: ElevatedButton.styleFrom(
 | 
			
		||||
      foregroundColor: Colors.black,
 | 
			
		||||
      backgroundColor: const Color(0xFFFFFFFF),
 | 
			
		||||
    ),
 | 
			
		||||
  ),
 | 
			
		||||
  scrollbarTheme: ScrollbarThemeData(
 | 
			
		||||
    thumbColor: WidgetStateProperty.all<Color>(const Color(0xFF1D1C1C)),
 | 
			
		||||
    trackColor: WidgetStateProperty.all<Color>(const Color(0xFF000000)),
 | 
			
		||||
  ),
 | 
			
		||||
);
 | 
			
		||||
 | 
			
		||||
final ThemeData f0ck95Theme = ThemeData(
 | 
			
		||||
  brightness: Brightness.light,
 | 
			
		||||
  primaryColor: const Color(0xFFC0C0C0),
 | 
			
		||||
  scaffoldBackgroundColor: const Color(0xFF008080),
 | 
			
		||||
  colorScheme: const ColorScheme.light(
 | 
			
		||||
    primary: Color(0xFFC0C0C0),
 | 
			
		||||
    secondary: Color(0xFF808080),
 | 
			
		||||
    surface: Color(0xFFC0C0C0),
 | 
			
		||||
    onPrimary: Colors.black,
 | 
			
		||||
    onSecondary: Colors.white,
 | 
			
		||||
  ),
 | 
			
		||||
  appBarTheme: AppBarTheme(
 | 
			
		||||
    backgroundColor: const Color(0xFFE0E0E0),
 | 
			
		||||
    foregroundColor: Colors.black,
 | 
			
		||||
    elevation: 4,
 | 
			
		||||
    centerTitle: true,
 | 
			
		||||
  ),
 | 
			
		||||
  textTheme: const TextTheme(
 | 
			
		||||
    bodyLarge: TextStyle(color: Colors.black),
 | 
			
		||||
    bodyMedium: TextStyle(color: Colors.black),
 | 
			
		||||
  ),
 | 
			
		||||
  elevatedButtonTheme: ElevatedButtonThemeData(
 | 
			
		||||
    style: ElevatedButton.styleFrom(
 | 
			
		||||
      foregroundColor: Colors.white,
 | 
			
		||||
      backgroundColor: Colors.black,
 | 
			
		||||
    ),
 | 
			
		||||
  ),
 | 
			
		||||
  scrollbarTheme: ScrollbarThemeData(
 | 
			
		||||
    thumbColor: WidgetStateProperty.all<Color>(const Color(0xFF2B2B2B)),
 | 
			
		||||
    trackColor: WidgetStateProperty.all<Color>(const Color(0xFF424242)),
 | 
			
		||||
  ),
 | 
			
		||||
);
 | 
			
		||||
 | 
			
		||||
final ThemeData f0ck95dTheme = ThemeData(
 | 
			
		||||
  brightness: Brightness.dark,
 | 
			
		||||
  primaryColor: const Color(0xFFFFFFFF),
 | 
			
		||||
  scaffoldBackgroundColor: const Color(0xFF0E0F0F),
 | 
			
		||||
  colorScheme: const ColorScheme.dark(
 | 
			
		||||
    primary: Color(0xFFFFFFFF),
 | 
			
		||||
    secondary: Color(0xFFC0C0C0),
 | 
			
		||||
    surface: Color(0xFF333131),
 | 
			
		||||
    onPrimary: Colors.black,
 | 
			
		||||
    onSecondary: Colors.white,
 | 
			
		||||
  ),
 | 
			
		||||
  appBarTheme: const AppBarTheme(
 | 
			
		||||
    backgroundColor: Color(0xFF0B0A0A),
 | 
			
		||||
    foregroundColor: Colors.white,
 | 
			
		||||
    elevation: 2,
 | 
			
		||||
  ),
 | 
			
		||||
  textTheme: const TextTheme(
 | 
			
		||||
    bodyLarge: TextStyle(color: Colors.white),
 | 
			
		||||
    bodyMedium: TextStyle(color: Colors.white),
 | 
			
		||||
  ),
 | 
			
		||||
  elevatedButtonTheme: ElevatedButtonThemeData(
 | 
			
		||||
    style: ElevatedButton.styleFrom(
 | 
			
		||||
      foregroundColor: Colors.black,
 | 
			
		||||
      backgroundColor: Colors.white,
 | 
			
		||||
    ),
 | 
			
		||||
  ),
 | 
			
		||||
  scrollbarTheme: ScrollbarThemeData(
 | 
			
		||||
    thumbColor: WidgetStateProperty.all<Color>(const Color(0xFF2B2B2B)),
 | 
			
		||||
    trackColor: WidgetStateProperty.all<Color>(const Color(0xFF424242)),
 | 
			
		||||
  ),
 | 
			
		||||
);
 | 
			
		||||
 | 
			
		||||
class ThemeController extends GetxController {
 | 
			
		||||
  final EncryptedSharedPreferencesAsync storage =
 | 
			
		||||
      EncryptedSharedPreferencesAsync.getInstance();
 | 
			
		||||
 | 
			
		||||
  final Rx<ThemeData> currentTheme = f0ckTheme.obs;
 | 
			
		||||
 | 
			
		||||
  final Map<String, ThemeData> themeMap = {
 | 
			
		||||
    'f0ck': f0ckTheme,
 | 
			
		||||
    'P1nk': p1nkTheme,
 | 
			
		||||
    'Orange': orangeTheme,
 | 
			
		||||
    'Amoled': amoledTheme,
 | 
			
		||||
    'Paper': paperTheme,
 | 
			
		||||
    'f0ck95': f0ck95Theme,
 | 
			
		||||
    'f0ck95d': f0ck95dTheme,
 | 
			
		||||
  };
 | 
			
		||||
 | 
			
		||||
  @override
 | 
			
		||||
  void onInit() {
 | 
			
		||||
    super.onInit();
 | 
			
		||||
    _loadTheme();
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  Future<void> _loadTheme() async {
 | 
			
		||||
    try {
 | 
			
		||||
      final String? savedThemeName = await storage.getString('theme');
 | 
			
		||||
      if (savedThemeName != null && themeMap.containsKey(savedThemeName)) {
 | 
			
		||||
        currentTheme.value = themeMap[savedThemeName]!;
 | 
			
		||||
        Get.changeTheme(currentTheme.value);
 | 
			
		||||
      }
 | 
			
		||||
    } catch (error) {
 | 
			
		||||
      Get.snackbar('', 'Fehler beim Laden des Themes: $error');
 | 
			
		||||
      currentTheme.value = f0ckTheme;
 | 
			
		||||
      Get.changeTheme(f0ckTheme);
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  Future<void> updateTheme(String themeName) async {
 | 
			
		||||
    try {
 | 
			
		||||
      await storage.setString('theme', themeName);
 | 
			
		||||
      if (themeMap.containsKey(themeName)) {
 | 
			
		||||
        currentTheme.value = themeMap[themeName]!;
 | 
			
		||||
        Get.changeTheme(currentTheme.value);
 | 
			
		||||
      } else {
 | 
			
		||||
        currentTheme.value = f0ckTheme;
 | 
			
		||||
        Get.changeTheme(f0ckTheme);
 | 
			
		||||
      }
 | 
			
		||||
    } catch (error) {
 | 
			
		||||
      Get.snackbar('', 'Fehler beim Aktualisieren des Themes: $error');
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
		Reference in New Issue
	
	Block a user