Init repo

This commit is contained in:
PartyDonut 2024-09-15 14:12:28 +02:00
commit 764b6034e3
566 changed files with 212335 additions and 0 deletions

View file

@ -0,0 +1,140 @@
import 'dart:convert';
import 'package:collection/collection.dart';
import 'package:flutter/widgets.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:screen_brightness/screen_brightness.dart';
import 'package:fladder/providers/shared_provider.dart';
import 'package:fladder/util/debouncer.dart';
enum ReadDirection {
leftToRight,
rightToLeft;
String toMap() => name;
static ReadDirection fromMap(String? map) {
return ReadDirection.values.firstWhereOrNull((element) => element.name == map) ?? ReadDirection.leftToRight;
}
}
enum InitZoomState {
contained,
covered;
String toMap() => name;
static InitZoomState fromMap(String? map) {
return InitZoomState.values.firstWhereOrNull((element) => element.name == map) ?? InitZoomState.contained;
}
}
enum GestureCache {
contained,
covered;
String toMap() => name;
static InitZoomState fromMap(String? map) {
return InitZoomState.values.firstWhereOrNull((element) => element.name == map) ?? InitZoomState.contained;
}
}
class BookViewerSettingsModel {
final double? screenBrightness;
final ReadDirection readDirection;
final InitZoomState initZoomState;
final bool cachePageZoom;
final bool keepPageZoom;
final bool disableScrollOnZoom;
BookViewerSettingsModel({
this.screenBrightness,
this.readDirection = ReadDirection.leftToRight,
this.initZoomState = InitZoomState.contained,
this.cachePageZoom = false,
this.keepPageZoom = true,
this.disableScrollOnZoom = false,
});
BookViewerSettingsModel copyWith({
ValueGetter<double?>? screenBrightness,
ReadDirection? readDirection,
InitZoomState? initZoomState,
bool? cachePageZoom,
bool? keepPageZoom,
bool? disableScrollOnZoom,
}) {
return BookViewerSettingsModel(
screenBrightness: screenBrightness != null ? screenBrightness.call() : this.screenBrightness,
readDirection: readDirection ?? this.readDirection,
initZoomState: initZoomState ?? this.initZoomState,
cachePageZoom: cachePageZoom ?? this.cachePageZoom,
keepPageZoom: keepPageZoom ?? this.keepPageZoom,
disableScrollOnZoom: disableScrollOnZoom ?? this.disableScrollOnZoom,
);
}
Map<String, dynamic> toMap() {
return {
'screenBrightness': screenBrightness,
'readDirection': readDirection.toMap(),
'initZoomState': initZoomState.toMap(),
'cachePageZoom': cachePageZoom,
'keepPageZoom': keepPageZoom,
'disableScrollOnZoom': disableScrollOnZoom,
};
}
factory BookViewerSettingsModel.fromMap(Map<String, dynamic> map) {
return BookViewerSettingsModel(
screenBrightness: map['screenBrightness']?.toDouble(),
readDirection: ReadDirection.fromMap(map['readDirection']),
initZoomState: InitZoomState.fromMap(map['initZoomState']),
cachePageZoom: map['cachePageZoom'] ?? false,
keepPageZoom: map['keepPageZoom'] ?? true,
disableScrollOnZoom: map['disableScrollOnZoom'] ?? false,
);
}
String toJson() => json.encode(toMap());
factory BookViewerSettingsModel.fromJson(String source) => BookViewerSettingsModel.fromMap(json.decode(source));
}
final bookViewerSettingsProvider = StateNotifierProvider<BookViewerSettingsNotifier, BookViewerSettingsModel>((ref) {
return BookViewerSettingsNotifier(ref);
});
class BookViewerSettingsNotifier extends StateNotifier<BookViewerSettingsModel> {
BookViewerSettingsNotifier(this.ref) : super(BookViewerSettingsModel());
final Ref ref;
final Debouncer _debouncer = Debouncer(const Duration(seconds: 1));
@override
set state(BookViewerSettingsModel value) {
_debouncer.run(() => ref.read(sharedUtilityProvider).bookViewSettings = value);
super.state = value;
}
void setScreenBrightness(double? value) async {
state = state.copyWith(
screenBrightness: () => value,
);
if (state.screenBrightness != null) {
ScreenBrightness().setScreenBrightness(state.screenBrightness!);
} else {
ScreenBrightness().resetScreenBrightness();
}
}
setSavedBrightness() {
if (state.screenBrightness != null) {
ScreenBrightness().setScreenBrightness(state.screenBrightness!);
}
}
void update(BookViewerSettingsModel Function(BookViewerSettingsModel state) outgoing) => state = outgoing(state);
}

View file

@ -0,0 +1,54 @@
import 'package:fladder/models/settings/client_settings_model.dart';
import 'package:fladder/providers/shared_provider.dart';
import 'package:fladder/util/custom_color_themes.dart';
import 'package:fladder/util/debouncer.dart';
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
final clientSettingsProvider = StateNotifierProvider<ClientSettingsNotifier, ClientSettingsModel>((ref) {
return ClientSettingsNotifier(ref);
});
class ClientSettingsNotifier extends StateNotifier<ClientSettingsModel> {
ClientSettingsNotifier(this.ref) : super(ClientSettingsModel());
final Ref ref;
final Debouncer _debouncer = Debouncer(const Duration(seconds: 1));
@override
set state(ClientSettingsModel value) {
super.state = value;
_debouncer.run(() => ref.read(sharedUtilityProvider).clientSettings = state);
}
void setWindowPosition(Offset windowPosition) =>
state = state.copyWith(position: Vector2.fromPosition(windowPosition));
void setWindowSize(Size windowSize) => state = state.copyWith(size: Vector2.fromSize(windowSize));
void setThemeMode(ThemeMode? themeMode) {
if (themeMode == null) return;
state = state.copyWith(themeMode: themeMode);
}
void setThemeColor(ColorThemes? themeColor) => state = state.copyWith(themeColor: themeColor);
void setAmoledBlack(bool? value) => state = state.copyWith(amoledBlack: value ?? false);
void setBlurPlaceholders(bool value) => state = state.copyWith(blurPlaceHolders: value);
void setTimeOut(Duration? duration) => state = state.copyWith(timeOut: duration);
void setBlurEpisodes(bool value) => state = state.copyWith(blurUpcomingEpisodes: value);
void setMediaKeys(bool value) => state = state.copyWith(enableMediaKeys: value);
void setPosterSize(double value) => state = state.copyWith(posterSize: value.clamp(0.5, 1.5));
void addPosterSize(double value) => state = state.copyWith(posterSize: (state.posterSize + value).clamp(0.5, 1.5));
void setSyncPath(String? path) => state = state.copyWith(syncPath: path);
void update(Function(ClientSettingsModel current) value) => state = value(state);
}

View file

@ -0,0 +1,21 @@
import 'package:fladder/models/settings/home_settings_model.dart';
import 'package:fladder/providers/shared_provider.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
final homeSettingsProvider = StateNotifierProvider<HomeSettingsNotifier, HomeSettingsModel>((ref) {
return HomeSettingsNotifier(ref);
});
class HomeSettingsNotifier extends StateNotifier<HomeSettingsModel> {
HomeSettingsNotifier(this.ref) : super(HomeSettingsModel());
final Ref ref;
@override
set state(HomeSettingsModel value) {
super.state = value;
ref.read(sharedUtilityProvider).homeSettings = value;
}
update(HomeSettingsModel Function(HomeSettingsModel currentState) value) => state = value(state);
}

View file

@ -0,0 +1,82 @@
import 'dart:convert';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:fladder/providers/shared_provider.dart';
class PhotoViewSettingsModel {
final bool repeat;
final bool mute;
final bool autoPlay;
final bool theaterMode;
final Duration timer;
PhotoViewSettingsModel({
this.repeat = true,
this.mute = false,
this.autoPlay = false,
this.theaterMode = false,
this.timer = const Duration(seconds: 15),
});
PhotoViewSettingsModel copyWith({
bool? repeat,
bool? mute,
bool? autoPlay,
bool? theaterMode,
Duration? timer,
}) {
return PhotoViewSettingsModel(
repeat: repeat ?? this.repeat,
mute: mute ?? this.mute,
autoPlay: autoPlay ?? this.autoPlay,
theaterMode: theaterMode ?? this.theaterMode,
timer: timer ?? this.timer,
);
}
Map<String, dynamic> toMap() {
return {
'repeat': repeat,
'mute': mute,
'autoPlay': autoPlay,
'theaterMode': theaterMode,
'timer': timer.inMilliseconds,
};
}
factory PhotoViewSettingsModel.fromMap(Map<String, dynamic> map) {
return PhotoViewSettingsModel(
repeat: map['repeat'] ?? false,
mute: map['mute'] ?? false,
autoPlay: map['autoPlay'] ?? false,
theaterMode: map['theaterMode'] ?? false,
timer: map['timer'] != null ? Duration(milliseconds: map['timer'] as int) : const Duration(seconds: 15),
);
}
String toJson() => json.encode(toMap());
factory PhotoViewSettingsModel.fromJson(String source) => PhotoViewSettingsModel.fromMap(json.decode(source));
}
final photoViewSettingsProvider = StateNotifierProvider<PhotoViewSettingsNotifier, PhotoViewSettingsModel>((ref) {
return PhotoViewSettingsNotifier(ref);
});
final testProviderProvider = StateProvider<int>((ref) {
return 0;
});
class PhotoViewSettingsNotifier extends StateNotifier<PhotoViewSettingsModel> {
PhotoViewSettingsNotifier(this.ref) : super(PhotoViewSettingsModel());
final Ref ref;
@override
set state(PhotoViewSettingsModel value) {
super.state = value;
ref.read(sharedUtilityProvider).photoViewSettings = value;
}
PhotoViewSettingsModel update(PhotoViewSettingsModel Function(PhotoViewSettingsModel state) cb) => state = cb(state);
}

View file

@ -0,0 +1,40 @@
import 'dart:ui';
import 'package:fladder/models/settings/subtitle_settings_model.dart';
import 'package:fladder/providers/shared_provider.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
final subtitleSettingsProvider = StateNotifierProvider<SubtitleSettingsNotifier, SubtitleSettingsModel>((ref) {
return SubtitleSettingsNotifier(ref);
});
class SubtitleSettingsNotifier extends StateNotifier<SubtitleSettingsModel> {
SubtitleSettingsNotifier(this.ref) : super(const SubtitleSettingsModel());
final Ref ref;
@override
set state(SubtitleSettingsModel value) {
super.state = value;
ref.read(sharedUtilityProvider).subtitleSettings = value;
}
void setFontSize(double value) => state = state.copyWith(fontSize: value);
void setVerticalOffset(double value) => state = state.copyWith(verticalOffset: value);
void setSubColor(Color color) => state = state.copyWith(color: color);
void setOutlineColor(Color e) => state = state.copyWith(outlineColor: e);
setOutlineThickness(double value) => state = state.copyWith(outlineSize: value);
void resetSettings({SubtitleSettingsModel? value}) => state = value ?? const SubtitleSettingsModel();
void setFontWeight(FontWeight? value) => state = state.copyWith(fontWeight: value);
setBackGroundOpacity(double value) =>
state = state.copyWith(backGroundColor: state.backGroundColor.withOpacity(value));
setShadowIntensity(double value) => state = state.copyWith(shadow: value);
}

View file

@ -0,0 +1,57 @@
import 'package:fladder/models/settings/video_player_settings.dart';
import 'package:fladder/providers/shared_provider.dart';
import 'package:fladder/providers/video_player_provider.dart';
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:screen_brightness/screen_brightness.dart';
final videoPlayerSettingsProvider =
StateNotifierProvider<VideoPlayerSettingsProviderNotifier, VideoPlayerSettingsModel>((ref) {
return VideoPlayerSettingsProviderNotifier(ref);
});
class VideoPlayerSettingsProviderNotifier extends StateNotifier<VideoPlayerSettingsModel> {
VideoPlayerSettingsProviderNotifier(this.ref) : super(const VideoPlayerSettingsModel());
final Ref ref;
@override
set state(VideoPlayerSettingsModel value) {
final oldState = super.state;
super.state = value;
ref.read(sharedUtilityProvider).videoPlayerSettings = value;
if (!oldState.playerSame(value)) {
ref.read(videoPlayerProvider.notifier).init();
}
}
void setScreenBrightness(double? value) async {
state = state.copyWith(
screenBrightness: () => value,
);
if (state.screenBrightness != null) {
ScreenBrightness().setScreenBrightness(state.screenBrightness!);
} else {
ScreenBrightness().resetScreenBrightness();
}
}
setSavedBrightness() {
if (state.screenBrightness != null) {
ScreenBrightness().setScreenBrightness(state.screenBrightness!);
}
}
void setFillScreen(bool? value, {BuildContext? context}) {
state = state.copyWith(fillScreen: value);
}
void setHardwareAccel(bool? value) => state = state.copyWith(hardwareAccel: value);
void setUseLibass(bool? value) => state = state.copyWith(useLibass: value);
void setFitType(BoxFit? value) => state = state.copyWith(videoFit: value);
void setVolume(double value) => state = state.copyWith(internalVolume: value);
void steppedVolume(int i) => state = state.copyWith(internalVolume: (state.volume + i).clamp(0, 100));
}