From 47fba525e68a1e137b1643ca8c61fdd6a21c5111 Mon Sep 17 00:00:00 2001 From: Angelo Cordero Date: Sat, 11 Feb 2023 04:25:59 +0800 Subject: [PATCH] code cleanup --- lib/core/constants.dart | 49 +++++--- lib/core/file_utils.dart | 46 ++++---- lib/core/helper_functions.dart | 21 ++-- lib/core/providers_declaration.dart | 19 ++-- lib/media_center/media_center_providers.dart | 23 ++-- .../notifiers/bibles_notifier.dart | 51 --------- .../media_center_bibles_notifier.dart | 43 +++++++ .../media_center_photos_notifier.dart | 18 +-- ...edia_center_playlist_preview_notifier.dart | 13 +-- .../media_center_playlists_notifier.dart | 34 ++---- .../media_center_songs_notifier.dart | 34 ++++++ .../media_center_videos_notifier.dart | 18 +-- .../notifiers/songs_notifier.dart | 47 -------- .../tabs/media_center_bibles_tab.dart | 23 +--- .../tabs/media_center_photos_tab.dart | 4 +- .../tabs/media_center_playlists_tab.dart | 16 +-- .../tabs/media_center_songs_tab.dart | 4 +- .../tabs/media_center_videos_tab.dart | 6 +- .../widgets/playlist_preview_panel.dart | 2 +- lib/models/playlist_model.dart | 4 +- lib/notifiers/scripture_notifier.dart | 19 ++-- lib/notifiers/slides_notifier.dart | 106 ++++++------------ lib/projection_layers/media_layer.dart | 57 ---------- lib/projection_layers/slide_layer.dart | 97 ---------------- .../playlist_media_expansion_tile.dart | 16 ++- .../playlist_verses_expansion_tile.dart | 2 +- lib/widgets/projection_slide_widget.dart | 14 +-- lib/windows/projection_window.dart | 2 +- 28 files changed, 289 insertions(+), 499 deletions(-) delete mode 100644 lib/media_center/notifiers/bibles_notifier.dart create mode 100644 lib/media_center/notifiers/media_center_bibles_notifier.dart create mode 100644 lib/media_center/notifiers/media_center_songs_notifier.dart delete mode 100644 lib/media_center/notifiers/songs_notifier.dart delete mode 100644 lib/projection_layers/media_layer.dart delete mode 100644 lib/projection_layers/slide_layer.dart diff --git a/lib/core/constants.dart b/lib/core/constants.dart index 65cb2c9..e3c4b20 100644 --- a/lib/core/constants.dart +++ b/lib/core/constants.dart @@ -1,6 +1,6 @@ -import 'dart:ui'; - -import 'package:path/path.dart' as p; +import 'package:flutter/material.dart'; +import 'package:google_fonts/google_fonts.dart'; +import 'package:path/path.dart'; import 'package:path_provider/path_provider.dart'; import 'package:tuple/tuple.dart'; @@ -28,6 +28,25 @@ enum SlideType { song, } +TextStyle songSlideTextStyle = const TextStyle( + fontFamily: 'LemonMilk', + fontSize: 80, + color: Colors.white, +); + +TextStyle verseSlideTextStyle = const TextStyle( + fontFamily: 'SegoeUI', + fontSize: 80, + color: Colors.white, +); + +TextStyle refTextStyle = GoogleFonts.raleway( + textStyle: const TextStyle( + fontSize: 50, + color: Colors.white, + ), +); + List videoFileExtensions = ['mp4', 'mov']; List photoFileExtensions = ['jpg', 'jpeg', 'png']; List bibleFileExtenstion = ['cpsb']; @@ -39,43 +58,47 @@ Future appDirectory() async { } Future biblesDirectory() async { - return p.join(await appDirectory(), 'bibles'); + return join(await appDirectory(), 'bibles'); } Future songsDirectory() async { - return p.join(await mediaDirectory(), 'songs'); + return join(await mediaDirectory(), 'songs'); } Future mediaDirectory() async { - return p.join(await appDirectory(), 'media'); + return join(await appDirectory(), 'media'); } Future settingsFile() async { - return p.join(await settingsDir(),'settings.json'); + return join(await settingsDir(), 'settings.json'); } Future settingsDir() async { - return p.join(await appDirectory(), 'settings'); + return join(await appDirectory(), 'settings'); } Future photosDirectory() async { - return p.join(await mediaDirectory(), 'photos'); + return join(await mediaDirectory(), 'photos'); } Future photoThumbnailsDirectory() async { - return p.join(await photosDirectory(), 'thumbnails'); + return join(await photosDirectory(), 'thumbnails'); +} + +Future videoThumbnailsDirectory() async { + return join(await videosDirectory(), 'thumbnails'); } Future videosDirectory() async { - return p.join(await mediaDirectory(), 'videos'); + return join(await mediaDirectory(), 'videos'); } Future playlistsDirectory() async { - return p.join(await mediaDirectory(), 'playlists'); + return join(await mediaDirectory(), 'playlists'); } Future getPlaylistPath(String fileName) async { - return p.join(await playlistsDirectory(), fileName); + return join(await playlistsDirectory(), fileName); } List superscriptMap = [ diff --git a/lib/core/file_utils.dart b/lib/core/file_utils.dart index f20130d..6d24850 100644 --- a/lib/core/file_utils.dart +++ b/lib/core/file_utils.dart @@ -2,21 +2,19 @@ import 'dart:convert'; import 'dart:io'; import 'package:file_picker/file_picker.dart'; -import 'package:freecps/core/bible_parser.dart'; import 'package:image_compression/image_compression.dart'; -import 'package:nanoid/nanoid.dart'; -import 'package:path/path.dart' as p; import 'package:path/path.dart'; import '../models/playlist_model.dart'; import '../models/song_model.dart'; -import 'constants.dart' as constants; +import 'bible_parser.dart'; import 'constants.dart'; +import 'helper_functions.dart'; class FileUtils { static initializeDirectories() async { - Directory('${await photosDirectory()}/thumbnails').create(recursive: true); - Directory('${await videosDirectory()}/thumbnails').create(recursive: true); + Directory(await photoThumbnailsDirectory()).create(recursive: true); + Directory(await videoThumbnailsDirectory()).create(recursive: true); Directory(await songsDirectory()).create(recursive: false); Directory(await playlistsDirectory()).create(recursive: false); Directory(await biblesDirectory()).create(recursive: false); @@ -25,14 +23,14 @@ class FileUtils { } static Future importPhotos(List files) async { - String dir = await constants.photosDirectory(); + String dir = await photosDirectory(); for (File file in files) { - String filePath = p.join(dir, basename(file.path)); + String filePath = join(dir, basename(file.path)); await file.copy(filePath); - String thumbnailPath = p.join(dir, 'thumbnails', basename(file.path)); + String thumbnailPath = join(dir, 'thumbnails', basename(file.path)); final output = compress( ImageFileConfiguration( @@ -53,30 +51,30 @@ class FileUtils { //! TODO: make thumbnails static void importVideos(List files) async { - String dir = await constants.videosDirectory(); + String dir = await videosDirectory(); for (File file in files) { - String filePath = p.join(dir, basename(file.path)); + String filePath = join(dir, basename(file.path)); await file.copy(filePath); } } static void importSongs(List files) async { - String dir = await constants.songsDirectory(); + String dir = await songsDirectory(); for (File file in files) { - String filePath = p.join(dir, basename(file.path)); + String filePath = join(dir, basename(file.path)); await file.copy(filePath); } } static void importPlaylist(List files) async { - String dir = await constants.playlistsDirectory(); + String dir = await playlistsDirectory(); for (File file in files) { - String filePath = p.join(dir, basename(file.path)); + String filePath = join(dir, basename(file.path)); await file.copy(filePath); } @@ -93,13 +91,19 @@ class FileUtils { } static getVideoFilePath(String fileName) async { - String dir = await constants.videosDirectory(); + String dir = await videosDirectory(); - return p.join(dir, fileName); + return join(dir, fileName); + } + + static getPhotoFilePath(String fileName) async { + String dir = await photosDirectory(); + + return join(dir, fileName); } static Future getPlaylistPath(String fileName) async { - return p.join(await playlistsDirectory(), fileName); + return join(await playlistsDirectory(), fileName); } static void savePlaylist(Playlist playlist) async { @@ -112,7 +116,7 @@ class FileUtils { } } - static void addMediaToPlaylist(Set media, Playlist playlist) async { + static void addMediaToPlaylist(Set media, Playlist playlist) { Set list = {...playlist.media, ...media}; savePlaylist(playlist.copyWith(media: list.toList())); @@ -123,9 +127,9 @@ class FileUtils { } static void addNewPlaylist() async { - String fileName = '${customAlphabet(customIdAlphabet, 30)}.cpss'; + String fileName = '$generateRandomID.cpss'; - File(p.join(await playlistsDirectory(), fileName)).writeAsStringSync(Playlist.addNew(fileName).toJson()); + File(join(await playlistsDirectory(), fileName)).writeAsStringSync(Playlist.addNew(fileName).toJson()); } static void saveSettings(Map settings) async { diff --git a/lib/core/helper_functions.dart b/lib/core/helper_functions.dart index 823802f..83a2a15 100644 --- a/lib/core/helper_functions.dart +++ b/lib/core/helper_functions.dart @@ -1,32 +1,31 @@ import 'package:flutter/painting.dart'; +import 'package:nanoid/nanoid.dart'; import '../models/scripture_reference_model.dart'; +import 'constants.dart'; -String scriptureRefToRefString(ScriptureReference ref) { +String scriptureRefToString(ScriptureReference ref) { return '${ref.translation} ${ref.book} ${ref.chapter}:${ref.verse!.verseString}'; } +String generateRandomID() { + return customAlphabet(customIdAlphabet, 30); +} + //TODO refactor int maxCharacters( String text, TextStyle style, ) { - final TextPainter heightPainter = TextPainter( - text: TextSpan(text: text, style: style), - maxLines: 1, - textDirection: TextDirection.ltr, - )..layout(minWidth: 0, maxWidth: double.infinity); - - final TextPainter widthPainter = TextPainter( + final TextPainter sizePainter = TextPainter( // M as text because it probably is the widest text: TextSpan(text: 'M', style: style), maxLines: 1, textDirection: TextDirection.ltr, )..layout(minWidth: 0, maxWidth: double.infinity); - double height = heightPainter.height; double paddingSize = 30; - int maxLines = (1080 - (2 * paddingSize) - 100) ~/ height; + int maxLines = (1080 - (2 * paddingSize) - 100) ~/ sizePainter.height; final TextPainter textPainter = TextPainter( text: TextSpan( @@ -37,5 +36,5 @@ int maxCharacters( textDirection: TextDirection.ltr, )..layout(minWidth: 0, maxWidth: 1920 - 30 - 30); - return ((textPainter.width ~/ widthPainter.width) * maxLines) - 5; + return ((textPainter.width ~/ sizePainter.width) * maxLines) - 5; } diff --git a/lib/core/providers_declaration.dart b/lib/core/providers_declaration.dart index b4891c2..f242387 100644 --- a/lib/core/providers_declaration.dart +++ b/lib/core/providers_declaration.dart @@ -22,7 +22,7 @@ final ctrlKeyNotifier = StateProvider((ref) { }); final scriptureProvider = StateNotifierProvider((ref) { - return ScriptureNotifier(ref); + return ScriptureNotifier(ref, ref.read(directoriesProvider)['biblesDir']!); }); final biblesDirectoryProvider = StateProvider((ref) { @@ -45,14 +45,19 @@ final verseListControllerProvider = StateNotifierProvider((ref) { - return PlaylistNotifier(ref); + // return ref.watch(initProvider).maybeMap( + // data: (data) { + return PlaylistNotifier(ref); + // }, + // orElse: () { + // return PlaylistNotifier(null); + // }, + // ); }); -final slidePanelTitleProvider = StateProvider( - (ref) { - return ''; - }, -); +final slidePanelTitleProvider = StateProvider((ref) { + return ''; +}); final settingsProvider = StateNotifierProvider>((ref) { String file = ref.watch(directoriesProvider)['settingsFile']!; diff --git a/lib/media_center/media_center_providers.dart b/lib/media_center/media_center_providers.dart index c959972..5b00052 100644 --- a/lib/media_center/media_center_providers.dart +++ b/lib/media_center/media_center_providers.dart @@ -3,37 +3,38 @@ import 'dart:io'; import 'package:flutter/widgets.dart'; import 'package:flutter_riverpod/flutter_riverpod.dart'; -import '../core/constants.dart'; import '../core/providers_declaration.dart'; import '../models/playlist_model.dart'; import '../models/song_model.dart'; -import 'notifiers/bibles_notifier.dart'; +import 'notifiers/media_center_bibles_notifier.dart'; import 'notifiers/media_center_photos_notifier.dart'; import 'notifiers/media_center_playlist_preview_notifier.dart'; import 'notifiers/media_center_playlists_notifier.dart'; import 'notifiers/media_center_videos_notifier.dart'; -import 'notifiers/songs_notifier.dart'; +import 'notifiers/media_center_songs_notifier.dart'; //TODO make these async final photosProvider = StateNotifierProvider.autoDispose>((ref) { - return MediaCenterPhotosNotifier(photoThumbnailsDirectory()); + return MediaCenterPhotosNotifier(ref.watch(directoriesProvider)['photoThumbnailsDir']!); }); final videosProvider = StateNotifierProvider.autoDispose>((ref) { - return MediaCenterVideosNotifier(videosDirectory()); + return MediaCenterVideosNotifier(ref.watch(directoriesProvider)['videosDir']!); }); final playlistsProvider = StateNotifierProvider.autoDispose>((ref) { - return MediaCenterPlaylistsNotifier(playlistsDirectory(), songsDirectory()); + Map dirs = ref.watch(directoriesProvider); + + return MediaCenterPlaylistsNotifier(dirs['playlistDir']!, dirs['songsDir']!); }); -final songsProvider = StateNotifierProvider.autoDispose>((ref) { - return SongsNotifier(songsDirectory()); +final songsProvider = StateNotifierProvider.autoDispose>((ref) { + return MediaCenterSongsNotifier(ref.watch(directoriesProvider)['songsDir']!); }); -final biblesProvider = StateNotifierProvider.autoDispose>((ref) { - return BiblesNotifier(biblesDirectory()); +final biblesProvider = StateNotifierProvider.autoDispose>((ref) { + return MediaCenterBiblesNotifier(ref.watch(directoriesProvider)['biblesDir']!); }); final mediaCenterCtrlKeyNotifier = StateProvider.autoDispose((ref) { @@ -76,7 +77,7 @@ final previewedPlaylistProvider = StateProvider.autoDispose((ref) { final playlistPreviewProvider = StateNotifierProvider.autoDispose((ref) { dynamic selected = ref.watch(playlistPreviewSelectedObjectProvider); - return MediaCenterPlaylistPreviewNotifier(selected); + return MediaCenterPlaylistPreviewNotifier(args: selected, photosDir: ref.watch(directoriesProvider)['photosDir']!); }); final playlistPreviewSelectedObjectProvider = StateProvider.autoDispose((ref) { diff --git a/lib/media_center/notifiers/bibles_notifier.dart b/lib/media_center/notifiers/bibles_notifier.dart deleted file mode 100644 index 2be7cb9..0000000 --- a/lib/media_center/notifiers/bibles_notifier.dart +++ /dev/null @@ -1,51 +0,0 @@ -import 'dart:convert'; -import 'dart:io'; - -import 'package:flutter_riverpod/flutter_riverpod.dart'; -import 'package:path/path.dart'; -import 'package:tuple/tuple.dart'; - -typedef BibleData = Tuple2; - -class BiblesNotifier extends StateNotifier> { - BiblesNotifier(this.path) : super([]) { - _fetch(); - _listen(); - } - - Future path; - - _fetch() async { - state = Directory(await path).listSync(recursive: false).whereType().map( - (Directory dir) { - String name = basenameWithoutExtension(dir.path); - - String translationName = jsonDecode(File(join(dir.path, '$name.metadata.json')).readAsStringSync())['translationName']; - - return BibleData(name, translationName); - }, - ).toList(); - } - - _listen() async { - Directory(await path).watch().listen( - (event) async { - if (!mounted) return; - - try { - state = Directory(await path).listSync(recursive: false).whereType().map( - (Directory dir) { - String name = basenameWithoutExtension(dir.path); - - String translationName = jsonDecode(File(join(dir.path, '$name.metadata.json')).readAsStringSync())['translationName']; - - return BibleData(name, translationName); - }, - ).toList(); - } catch (e) { - // - } - }, - ); - } -} diff --git a/lib/media_center/notifiers/media_center_bibles_notifier.dart b/lib/media_center/notifiers/media_center_bibles_notifier.dart new file mode 100644 index 0000000..97e83b5 --- /dev/null +++ b/lib/media_center/notifiers/media_center_bibles_notifier.dart @@ -0,0 +1,43 @@ +import 'dart:convert'; +import 'dart:io'; + +import 'package:flutter_riverpod/flutter_riverpod.dart'; +import 'package:path/path.dart'; +import 'package:tuple/tuple.dart'; + +typedef BibleData = Tuple2; + +class MediaCenterBiblesNotifier extends StateNotifier> { + MediaCenterBiblesNotifier(this.path) : super([]) { + _setState(); + _listen(); + } + + String path; + + _listen() { + Directory(path).watch().listen( + (event) { + if (!mounted) return; + + try { + _setState(); + } catch (e) { + // + } + }, + ); + } + + void _setState() { + state = Directory(path).listSync(recursive: false).whereType().map( + (Directory dir) { + String name = basenameWithoutExtension(dir.path); + + String translationName = jsonDecode(File(join(dir.path, '$name.metadata.json')).readAsStringSync())['translationName']; + + return BibleData(name, translationName); + }, + ).toList(); + } +} diff --git a/lib/media_center/notifiers/media_center_photos_notifier.dart b/lib/media_center/notifiers/media_center_photos_notifier.dart index d37b31a..d4a9eee 100644 --- a/lib/media_center/notifiers/media_center_photos_notifier.dart +++ b/lib/media_center/notifiers/media_center_photos_notifier.dart @@ -4,25 +4,25 @@ import 'package:flutter_riverpod/flutter_riverpod.dart'; class MediaCenterPhotosNotifier extends StateNotifier> { MediaCenterPhotosNotifier(this.path) : super([]) { - _fetch(); + _setState(); _listen(); } - Future path; + String path; - _fetch() async { - state = Directory(await path).listSync(recursive: false).whereType().toList(); - } - - _listen() async { - Directory(await path).watch().listen((event) async { + _listen() { + Directory(path).watch().listen((event) { if (!mounted) return; try { - state = Directory(await path).listSync(recursive: false).whereType().toList(); + _setState(); } catch (e) { // } }); } + + void _setState() { + state = Directory(path).listSync(recursive: false).whereType().toList(); + } } diff --git a/lib/media_center/notifiers/media_center_playlist_preview_notifier.dart b/lib/media_center/notifiers/media_center_playlist_preview_notifier.dart index 88412a0..6f0c051 100644 --- a/lib/media_center/notifiers/media_center_playlist_preview_notifier.dart +++ b/lib/media_center/notifiers/media_center_playlist_preview_notifier.dart @@ -11,10 +11,12 @@ import '../../models/saved_verse_slides.dart'; import '../../models/song_model.dart'; class MediaCenterPlaylistPreviewNotifier extends StateNotifier { - MediaCenterPlaylistPreviewNotifier(dynamic args) : super(Container()) { + MediaCenterPlaylistPreviewNotifier({required dynamic args, required this.photosDir}) : super(Container()) { _preview(args); } + String photosDir; + void _preview(dynamic args) { if (args is Song) { _previewSong(args); @@ -22,16 +24,13 @@ class MediaCenterPlaylistPreviewNotifier extends StateNotifier { _previewVerses(args); } else if (args is String) { _previewMedia(args); - } else { - state = Container(); } } - void _previewMedia(String args) async { + void _previewMedia(String args) { for (var e in photoFileExtensions) { if (args.toLowerCase().contains(e)) { - String filePath = join(await photosDirectory(), args); - + String filePath = join(photosDir, args); state = Image.file(File(filePath)); return; } @@ -55,7 +54,7 @@ class MediaCenterPlaylistPreviewNotifier extends StateNotifier { void _previewVerses(SavedVerseSlides args) { state = ListView( children: [ - Text(scriptureRefToRefString(args.scriptureRef)), + Text(scriptureRefToString(args.scriptureRef)), const Divider( height: 30, ), diff --git a/lib/media_center/notifiers/media_center_playlists_notifier.dart b/lib/media_center/notifiers/media_center_playlists_notifier.dart index 88c55ae..212903a 100644 --- a/lib/media_center/notifiers/media_center_playlists_notifier.dart +++ b/lib/media_center/notifiers/media_center_playlists_notifier.dart @@ -6,46 +6,30 @@ import '../../models/playlist_model.dart'; class MediaCenterPlaylistsNotifier extends StateNotifier> { MediaCenterPlaylistsNotifier(this.playlistPath, this.songsPath) : super([]) { - init(); - } - - Future playlistPath; - Future songsPath; - - init() { - _fetch(); + _setState(); _listen(); } - void _fetch() async { - String path = await songsPath; - - try { - await setState(path); - } catch (e) { - // - } - } - - void _listen() async { - String path = await songsPath; + String playlistPath; + String songsPath; - Directory(await playlistPath).watch().listen((FileSystemEvent event) async { + void _listen() { + Directory(playlistPath).watch().listen((FileSystemEvent event) async { if (!mounted) return; if (event is FileSystemModifyEvent) return; try { - await setState(path); + _setState(); } catch (e) { // } }); } - Future setState(String path) async { - state = Directory(await playlistPath).listSync(recursive: false).whereType().toList().map((file) { - return Playlist.fromJson(file.readAsStringSync(), path); + void _setState() { + state = Directory(playlistPath).listSync(recursive: false).whereType().toList().map((file) { + return Playlist.fromJson(file.readAsStringSync(), songsPath); }).toList(); state.sort((a, b) => a.title.compareTo(b.title)); diff --git a/lib/media_center/notifiers/media_center_songs_notifier.dart b/lib/media_center/notifiers/media_center_songs_notifier.dart new file mode 100644 index 0000000..59952a8 --- /dev/null +++ b/lib/media_center/notifiers/media_center_songs_notifier.dart @@ -0,0 +1,34 @@ +import 'dart:io'; + +import 'package:flutter_riverpod/flutter_riverpod.dart'; + +import '../../models/song_model.dart'; + +class MediaCenterSongsNotifier extends StateNotifier> { + MediaCenterSongsNotifier(this.path) : super([]) { + _setState(); + _listen(); + } + + String path; + + void _listen() { + Directory(path).watch().listen((event) { + if (!mounted) return; + + try { + _setState(); + } catch (e) { + // + } + }); + } + + void _setState() { + state = Directory(path).listSync(recursive: false).whereType().map((file) { + return Song.fromJson(file.readAsStringSync()); + }).toList(); + + state.sort((a, b) => a.title.compareTo(b.title)); + } +} diff --git a/lib/media_center/notifiers/media_center_videos_notifier.dart b/lib/media_center/notifiers/media_center_videos_notifier.dart index 8c00d93..28b5e40 100644 --- a/lib/media_center/notifiers/media_center_videos_notifier.dart +++ b/lib/media_center/notifiers/media_center_videos_notifier.dart @@ -4,25 +4,25 @@ import 'package:flutter_riverpod/flutter_riverpod.dart'; class MediaCenterVideosNotifier extends StateNotifier> { MediaCenterVideosNotifier(this.path) : super([]) { - _fetch(); + _setState(); _listen(); } - Future path; + String path; - _fetch() async { - state = Directory(await path).listSync(recursive: false).whereType().toList(); - } - - _listen() async { - Directory(await path).watch().listen((event) async { + _listen() { + Directory(path).watch().listen((event) { if (!mounted) return; try { - state = Directory(await path).listSync(recursive: false).whereType().toList(); + _setState(); } catch (e) { // } }); } + + void _setState() { + state = Directory(path).listSync(recursive: false).whereType().toList(); + } } diff --git a/lib/media_center/notifiers/songs_notifier.dart b/lib/media_center/notifiers/songs_notifier.dart deleted file mode 100644 index 8b90a5e..0000000 --- a/lib/media_center/notifiers/songs_notifier.dart +++ /dev/null @@ -1,47 +0,0 @@ -import 'dart:io'; - -import 'package:flutter_riverpod/flutter_riverpod.dart'; - -import '../../models/song_model.dart'; - -class SongsNotifier extends StateNotifier> { - SongsNotifier(this.path) : super([]) { - _fetch(); - _listen(); - } - - Future path; - - _fetch() async { - state = Directory(await path).listSync(recursive: false).whereType().map( - (file) { - return Song.fromJson( - file.readAsStringSync(), - ); - }, - ).toList(); - state.sort((a, b) => a.title.compareTo(b.title)); - } - - _listen() async { - Directory(await path).watch().listen( - (event) async { - if (!mounted) return; - - try { - state = Directory(await path).listSync(recursive: false).whereType().map( - (file) { - return Song.fromJson( - file.readAsStringSync(), - ); - }, - ).toList(); - - state.sort((a, b) => a.title.compareTo(b.title)); - } catch (e) { -// - } - }, - ); - } -} diff --git a/lib/media_center/tabs/media_center_bibles_tab.dart b/lib/media_center/tabs/media_center_bibles_tab.dart index d84de19..eb1d897 100644 --- a/lib/media_center/tabs/media_center_bibles_tab.dart +++ b/lib/media_center/tabs/media_center_bibles_tab.dart @@ -2,7 +2,7 @@ import 'package:file_picker/file_picker.dart'; import 'package:flutter/material.dart'; import 'package:flutter_riverpod/flutter_riverpod.dart'; import 'package:freecps/core/constants.dart'; -import 'package:freecps/media_center/notifiers/bibles_notifier.dart'; +import 'package:freecps/media_center/notifiers/media_center_bibles_notifier.dart'; import '../../core/file_utils.dart'; import '../media_center_providers.dart'; @@ -31,25 +31,10 @@ class MediaCenterBiblesTab extends ConsumerWidget { mainAxisExtent: 200, ), itemBuilder: (context, index) { - // String selectedFileName = ref.watch(selectedPlaylistProvider); BibleData bible = bibles[index]; - - return GestureDetector( - onTap: () { - //ref.read(selectedPlaylistProvider.notifier).state = playlist.fileName; - }, - child: Card( - // shape: playlist.fileName == selectedFileName - // ? const RoundedRectangleBorder( - // side: BorderSide( - // color: Color(0xff1e66f5), - // width: 1.5, - // ), - // ) - // : null, - child: Center( - child: Text(bible.item2), - ), + return Card( + child: Center( + child: Text(bible.item2), ), ); }, diff --git a/lib/media_center/tabs/media_center_photos_tab.dart b/lib/media_center/tabs/media_center_photos_tab.dart index c347ef2..6fa2f0a 100644 --- a/lib/media_center/tabs/media_center_photos_tab.dart +++ b/lib/media_center/tabs/media_center_photos_tab.dart @@ -5,7 +5,7 @@ import 'package:flutter/material.dart'; import 'package:flutter_riverpod/flutter_riverpod.dart'; import 'package:path/path.dart'; -import '../../core/constants.dart' as constants; +import '../../core/constants.dart'; import '../../core/file_utils.dart'; import '../../core/providers_declaration.dart'; import '../media_center_providers.dart'; @@ -84,7 +84,7 @@ class MediaCenterPhotosTab extends ConsumerWidget { FilePickerResult? result = await FilePicker.platform.pickFiles( allowMultiple: true, type: FileType.custom, - allowedExtensions: constants.photoFileExtensions, + allowedExtensions: photoFileExtensions, ); if (result == null) return; diff --git a/lib/media_center/tabs/media_center_playlists_tab.dart b/lib/media_center/tabs/media_center_playlists_tab.dart index b326f0f..199e30a 100644 --- a/lib/media_center/tabs/media_center_playlists_tab.dart +++ b/lib/media_center/tabs/media_center_playlists_tab.dart @@ -2,7 +2,7 @@ import 'package:file_picker/file_picker.dart'; import 'package:flutter/material.dart'; import 'package:flutter_riverpod/flutter_riverpod.dart'; -import '../../core/constants.dart' as constants; +import '../../core/constants.dart'; import '../../core/file_utils.dart'; import '../../core/providers_declaration.dart'; import '../../models/playlist_model.dart'; @@ -102,15 +102,15 @@ class MediaCenterPlaylistsTab extends ConsumerWidget { ), ElevatedButton( onPressed: () async { - FilePickerResult? result = await FilePicker.platform.pickFiles( - allowMultiple: true, - type: FileType.custom, - allowedExtensions: constants.playlistFileExtension, - ); + FilePickerResult? result = await FilePicker.platform.pickFiles( + allowMultiple: true, + type: FileType.custom, + allowedExtensions: playlistFileExtension, + ); - if (result == null) return; + if (result == null) return; - FileUtils.importPlaylist(FileUtils.filePickerResultToFile(result)); + FileUtils.importPlaylist(FileUtils.filePickerResultToFile(result)); }, child: const Text('Import'), ), diff --git a/lib/media_center/tabs/media_center_songs_tab.dart b/lib/media_center/tabs/media_center_songs_tab.dart index b4cabdc..2dc8289 100644 --- a/lib/media_center/tabs/media_center_songs_tab.dart +++ b/lib/media_center/tabs/media_center_songs_tab.dart @@ -2,7 +2,7 @@ import 'package:file_picker/file_picker.dart'; import 'package:flutter/material.dart'; import 'package:flutter_riverpod/flutter_riverpod.dart'; -import '../../core/constants.dart' as constants; +import '../../core/constants.dart'; import '../../core/file_utils.dart'; import '../../core/providers_declaration.dart'; import '../../models/song_model.dart'; @@ -86,7 +86,7 @@ class MediaCenterSongsTab extends ConsumerWidget { FilePickerResult? result = await FilePicker.platform.pickFiles( allowMultiple: true, type: FileType.custom, - allowedExtensions: constants.songFileExtension, + allowedExtensions: songFileExtension, ); if (result == null) return; diff --git a/lib/media_center/tabs/media_center_videos_tab.dart b/lib/media_center/tabs/media_center_videos_tab.dart index bcdeeb0..d5af00f 100644 --- a/lib/media_center/tabs/media_center_videos_tab.dart +++ b/lib/media_center/tabs/media_center_videos_tab.dart @@ -5,7 +5,7 @@ import 'package:flutter/material.dart'; import 'package:flutter_riverpod/flutter_riverpod.dart'; import 'package:path/path.dart'; -import '../../core/constants.dart' as constants; +import '../../core/constants.dart'; import '../../core/file_utils.dart'; import '../../core/providers_declaration.dart'; import '../media_center_providers.dart'; @@ -70,7 +70,7 @@ class MediaCenterVideosTab extends ConsumerWidget { mainAxisAlignment: MainAxisAlignment.end, children: [ ElevatedButton( - onPressed: () async { + onPressed: () { FileUtils.addMediaToPlaylist(selectedVideos, ref.read(activePlaylistProvider)); }, child: const Text('Add To Playlist'), @@ -83,7 +83,7 @@ class MediaCenterVideosTab extends ConsumerWidget { FilePickerResult? result = await FilePicker.platform.pickFiles( allowMultiple: true, type: FileType.custom, - allowedExtensions: constants.videoFileExtensions, + allowedExtensions: videoFileExtensions, ); if (result == null) return; diff --git a/lib/media_center/widgets/playlist_preview_panel.dart b/lib/media_center/widgets/playlist_preview_panel.dart index ba8222a..0f95517 100644 --- a/lib/media_center/widgets/playlist_preview_panel.dart +++ b/lib/media_center/widgets/playlist_preview_panel.dart @@ -76,7 +76,7 @@ class PlaylistPreviewPanel extends ConsumerWidget { }, selected: selected is SavedVerseSlides && selected == e, title: Text( - scriptureRefToRefString(e.scriptureRef), + scriptureRefToString(e.scriptureRef), ), ), ), diff --git a/lib/models/playlist_model.dart b/lib/models/playlist_model.dart index ded484e..0f0dd18 100644 --- a/lib/models/playlist_model.dart +++ b/lib/models/playlist_model.dart @@ -2,7 +2,7 @@ import 'dart:convert'; import 'dart:io'; import 'package:flutter/foundation.dart'; -import 'package:path/path.dart' as p; +import 'package:path/path.dart'; import 'saved_verse_slides.dart'; import 'song_model.dart'; @@ -46,7 +46,7 @@ class Playlist { (fileName) { try { return Song.fromJson( - File(p.join(songsDir, fileName)).readAsStringSync(), + File(join(songsDir, fileName)).readAsStringSync(), ); } catch (e) { return Song.error(); diff --git a/lib/notifiers/scripture_notifier.dart b/lib/notifiers/scripture_notifier.dart index ee31a5b..7c732ee 100644 --- a/lib/notifiers/scripture_notifier.dart +++ b/lib/notifiers/scripture_notifier.dart @@ -2,7 +2,6 @@ import 'dart:convert'; import 'dart:io'; import 'package:flutter_riverpod/flutter_riverpod.dart'; -import 'package:freecps/core/constants.dart'; import 'package:path/path.dart'; import '../models/scripture_model.dart'; @@ -12,13 +11,13 @@ import '../models/verse_reference_model.dart'; /// Notifier that holds all data of the selected scripture class ScriptureNotifier extends StateNotifier { - ScriptureNotifier(this.ref) : super(const Scripture(scriptureRef: ScriptureReference())) { + ScriptureNotifier(this.ref, this.biblesDirectory) : super(const Scripture(scriptureRef: ScriptureReference())) { _init(); } StateNotifierProviderRef ref; - String _biblesDirectory = ''; + String biblesDirectory; final Set _availableBibles = {}; List>? _bookData; Set? _books; @@ -115,16 +114,14 @@ class ScriptureNotifier extends StateNotifier { return state.verses ?? []; } - void _init() async { - _biblesDirectory = await biblesDirectory(); - + void _init() { _setAvailableBibles(); } void _setAvailableBibles() { _availableBibles.clear(); - List bibleFileEntities = Directory(_biblesDirectory).listSync(); + List bibleFileEntities = Directory(biblesDirectory).listSync(); if (bibleFileEntities.isNotEmpty) { for (var element in bibleFileEntities) { @@ -138,11 +135,11 @@ class ScriptureNotifier extends StateNotifier { translationRef = _availableBibles.first; } - File(_biblesDirectory).watch().listen((event) { + File(biblesDirectory).watch().listen((event) { try { _availableBibles.clear(); - List bibleFileEntities = Directory(_biblesDirectory).listSync().whereType().toList(); + List bibleFileEntities = Directory(biblesDirectory).listSync().whereType().toList(); if (bibleFileEntities.isNotEmpty) { for (var element in bibleFileEntities) { @@ -162,7 +159,7 @@ class ScriptureNotifier extends StateNotifier { void _setTranslationData() { if (state.scriptureRef.translation == null) return; - String path = '$_biblesDirectory/${state.scriptureRef.translation}/${state.scriptureRef.translation}.metadata.json'; + String path = '$biblesDirectory/${state.scriptureRef.translation}/${state.scriptureRef.translation}.metadata.json'; _translationData = jsonDecode(File(path).readAsStringSync()); @@ -176,7 +173,7 @@ class ScriptureNotifier extends StateNotifier { String book = state.scriptureRef.book != null ? state.scriptureRef.book.toString() : _books!.first; - String bookPath = '$_biblesDirectory/${state.scriptureRef.translation}/books/${state.scriptureRef.translation}.$book.json'; + String bookPath = '$biblesDirectory/${state.scriptureRef.translation}/books/${state.scriptureRef.translation}.$book.json'; _bookData = List>.from(jsonDecode(File(bookPath).readAsStringSync())['chapters']); } diff --git a/lib/notifiers/slides_notifier.dart b/lib/notifiers/slides_notifier.dart index 34fbe55..b3c3553 100644 --- a/lib/notifiers/slides_notifier.dart +++ b/lib/notifiers/slides_notifier.dart @@ -41,7 +41,7 @@ class SlidesNotifier extends StateNotifier> { generateSavedVerseSlides(SavedVerseSlides slides) { state = slides.verseSlides; - _setSlidesPanelTitle(scriptureRefToRefString(slides.scriptureRef)); + _setSlidesPanelTitle(scriptureRefToString(slides.scriptureRef)); } generateScriptureSlides({ @@ -51,20 +51,14 @@ class SlidesNotifier extends StateNotifier> { int? endVerse = scripture.scriptureRef.verse!.verseRange.item2; _scriptureReference = scripture.scriptureRef; - _setSlidesPanelTitle(scriptureRefToRefString(scripture.scriptureRef)); + _setSlidesPanelTitle(scriptureRefToString(scripture.scriptureRef)); - bool breakOnNewVerse = _ref.read(settingsProvider.select((value) => value['break_on_new_verse'])) == 'true' ? true : false; - - if (endVerse != null) { - if (breakOnNewVerse == false) { - stitchVerses(scripture, startVerse, endVerse); - return; - } - _setMultipleScriptureSlides(scripture, startVerse, endVerse); + if (endVerse == null) { + _setSingleVerseScriptureSlide(scripture, startVerse); return; } - _setSingleScriptureSlide(scripture, startVerse); + _setMultipleVerseScriptureSlides(scripture, startVerse, endVerse); } void saveScriptureSlideToPlaylist(Playlist playlist) { @@ -77,36 +71,33 @@ class SlidesNotifier extends StateNotifier> { FileUtils.savePlaylist(playlist.copyWith(verses: playlistVerses)); } - void _setMultipleScriptureSlides(Scripture scripture, int startVerse, int endVerse) { + bool _breakOnNewVerse() { + return _ref.read(settingsProvider.select((value) => value['break_on_new_verse'])) == 'true' ? true : false; + } + + void _setMultipleVerseScriptureSlides(Scripture scripture, int startVerse, int endVerse) { + if (!_breakOnNewVerse()) { + _stitchVerses(scripture, startVerse, endVerse); + return; + } + List temp = []; - scripture.verses! - .getRange( - startVerse - 1, - endVerse, - ) - .forEach( + scripture.verses!.getRange(startVerse - 1, endVerse).forEach( (verse) { String text = _getTextWithSuperscript(verse.num, verse.text); - - int maxChars = maxCharacters( - text, - const TextStyle( - fontFamily: 'LemonMilk', - fontSize: 80, - color: Colors.white, - ), - ); + int maxChars = maxCharacters(text, songSlideTextStyle); if (text.length > maxChars) { - splitSlides(text, maxChars, scripture); + + _splitSlides(text, maxChars, scripture); + temp.addAll(_splitSlides(text, maxChars, scripture)); - temp.addAll(splitSlides(text, maxChars, scripture)); } else { temp.add( Slide( text: text, - reference: _scriptureRefToString(scripture.scriptureRef), + reference: scriptureRefToString(scripture.scriptureRef), slideType: SlideType.scripture, ), ); @@ -117,34 +108,25 @@ class SlidesNotifier extends StateNotifier> { state = temp; } - void _setSingleScriptureSlide(Scripture scripture, int startVerse) { + void _setSingleVerseScriptureSlide(Scripture scripture, int startVerse) { Verse verse = scripture.verses![startVerse - 1]; - String text = _getTextWithSuperscript(verse.num, verse.text).trim(); - - int maxChars = maxCharacters( - text, - const TextStyle( - fontFamily: 'LemonMilk', - fontSize: 80, - color: Colors.white, - ), - ); + int maxChars = maxCharacters(text, songSlideTextStyle); if (text.length > maxChars) { - state = splitSlides(text, maxChars, scripture); + state = _splitSlides(text, maxChars, scripture); } else { state = [ Slide( text: text, - reference: _scriptureRefToString(scripture.scriptureRef), + reference: scriptureRefToString(scripture.scriptureRef), slideType: SlideType.scripture, ), ]; } } - List splitSlides(String text, int maxChars, Scripture scripture) { + List _splitSlides(String text, int maxChars, Scripture scripture) { int slideCount = text.length ~/ maxChars; int charsPerSlide = text.length ~/ slideCount; @@ -170,7 +152,7 @@ class SlidesNotifier extends StateNotifier> { temp.add( Slide( text: slideText, - reference: _scriptureRefToString(scripture.scriptureRef), + reference: scriptureRefToString(scripture.scriptureRef), slideType: SlideType.scripture, ), ); @@ -195,46 +177,28 @@ class SlidesNotifier extends StateNotifier> { } } - String _scriptureRefToString(ScriptureReference ref) { - return '${ref.translation} ${ref.book} ${ref.chapter}:${ref.verse!.verseString}'; - } void _setSlidesPanelTitle(String title) { _ref.read(slidePanelTitleProvider.notifier).state = title; } - void stitchVerses(Scripture scripture, int startVerse, int endVerse) { + void _stitchVerses(Scripture scripture, int startVerse, int endVerse) { String passage = ''; - scripture.verses! - .getRange( - startVerse - 1, - endVerse, - ) - .forEach( - (verse) { - String text = _getTextWithSuperscript(verse.num, verse.text); + scripture.verses!.getRange(startVerse - 1, endVerse).forEach((verse) { + String text = _getTextWithSuperscript(verse.num, verse.text); + passage = '$passage $text'; + }); - passage = '$passage $text'; - }, - ); - - int maxChars = maxCharacters( - passage, - const TextStyle( - fontFamily: 'LemonMilk', - fontSize: 80, - color: Colors.white, - ), - ); + int maxChars = maxCharacters(passage, songSlideTextStyle); if (passage.length > maxChars) { - state = splitSlides(passage, maxChars, scripture); + state = _splitSlides(passage, maxChars, scripture); } else { state = [ Slide( text: passage, - reference: _scriptureRefToString(scripture.scriptureRef), + reference: scriptureRefToString(scripture.scriptureRef), slideType: SlideType.scripture, ), ]; diff --git a/lib/projection_layers/media_layer.dart b/lib/projection_layers/media_layer.dart deleted file mode 100644 index 09c4786..0000000 --- a/lib/projection_layers/media_layer.dart +++ /dev/null @@ -1,57 +0,0 @@ -// ignore_for_file: deprecated_member_use_from_same_package - -import 'dart:io'; - -import 'package:dart_vlc/dart_vlc.dart'; -import 'package:desktop_multi_window/desktop_multi_window.dart'; -import 'package:flutter/material.dart'; -import 'package:window_manager/window_manager.dart'; -import '../core/constants.dart' as constants; - -@Deprecated('not working') -class MediaLayer extends StatefulWidget { - const MediaLayer({super.key}); - - @override - State createState() => _MediaLayerState(); -} - -class _MediaLayerState extends State { - late final Player player; - - @override - Widget build(BuildContext context) { - return Video( - player: player, - fit: BoxFit.cover, - showControls: false, - ); - } - - @override - void dispose() { - player.dispose(); - super.dispose(); - windowManager.close(); - } - - @override - void initState() { - super.initState(); - player = Player(id: 1); - player.setPlaylistMode(PlaylistMode.loop); - - DesktopMultiWindow.setMethodHandler((call, _) async { - if (call.method == 'setBackground') { - player.open(Media.file(File(call.arguments))); - } - - if (call.method == 'clearBackground') { - player.open(Media.file(File(constants.blackBackgroundFilePath))); - } - if (call.method == 'close') { - dispose(); - } - }); - } -} diff --git a/lib/projection_layers/slide_layer.dart b/lib/projection_layers/slide_layer.dart deleted file mode 100644 index 5725d95..0000000 --- a/lib/projection_layers/slide_layer.dart +++ /dev/null @@ -1,97 +0,0 @@ -// ignore_for_file: deprecated_member_use_from_same_package - -import 'package:desktop_multi_window/desktop_multi_window.dart'; -import 'package:flutter/material.dart'; -// import 'package:window_manager/window_manager.dart'; - - -@Deprecated('not working') -class SlideLayer extends StatefulWidget { - const SlideLayer({super.key}); - - @override - State createState() => _SlideLayerState(); -} - -class _SlideLayerState extends State { - Widget first = Container(color: Colors.transparent,); - Widget second = Container(color: Colors.transparent,); - - bool showingFirst = false; - - @override - void initState() { - DesktopMultiWindow.setMethodHandler((call, _) async { - if (call.method == 'verseSlide') { - setState(() { - if (showingFirst) { - second = Container( - color: Colors.transparent.withOpacity(0.5), - height: 1080, - width: 1920, - child: Center( - child: Text( - call.arguments.toString(), - textAlign: TextAlign.center, - style: const TextStyle( - fontSize: 80, - fontWeight: FontWeight.bold, - color: Colors.white, - ), - ), - ), - ); - } else { - first = Container( - color: Colors.transparent.withOpacity(0.5), - height: 1080, - width: 1920, - child: Center( - child: Text( - call.arguments.toString(), - textAlign: TextAlign.center, - style: const TextStyle( - fontSize: 80, - fontWeight: FontWeight.bold, - color: Colors.white, - ), - ), - ), - ); - } - - showingFirst = !showingFirst; - }); - } - - if (call.method == 'close') { - dispose(); - } - }); - - super.initState(); - } - - @override - Widget build(BuildContext context) { - return Container( - color: Colors.transparent, - height: 1080, - width: 1920, - child: AnimatedCrossFade( - alignment: Alignment.center, - firstChild: first, - secondChild: second, - crossFadeState: showingFirst ? CrossFadeState.showFirst : CrossFadeState.showSecond, - duration: const Duration(milliseconds: 300), - sizeCurve: Curves.linear, - ), - ); - } - - @override - void dispose() { - //windowManager.close(); - super.dispose(); - } -} diff --git a/lib/widgets/playlist_media_expansion_tile.dart b/lib/widgets/playlist_media_expansion_tile.dart index 40d17d8..a4f308f 100644 --- a/lib/widgets/playlist_media_expansion_tile.dart +++ b/lib/widgets/playlist_media_expansion_tile.dart @@ -1,6 +1,7 @@ import 'package:flutter/material.dart'; import 'package:flutter_riverpod/flutter_riverpod.dart'; +import '../core/constants.dart'; import '../core/file_utils.dart'; import '../core/projection_utils.dart'; import '../core/providers_declaration.dart'; @@ -22,7 +23,20 @@ class PlaylistMediaExpansionTile extends ConsumerWidget { return GestureDetector( onTap: () async { try { - String filePath = await FileUtils.getVideoFilePath(media); + String filePath = ''; + + for (var element in videoFileExtensions) { + if (media.toLowerCase().contains(element)) { + filePath = await FileUtils.getVideoFilePath(media); + } + } + + for (var element in photoFileExtensions) { + if (media.toLowerCase().contains(element)) { + filePath = await FileUtils.getPhotoFilePath(media); + } + } + bool isLive = ref.read(liveProvider); await ProjectionUtils.setBackground(filePath, isLive); } catch (e) { diff --git a/lib/widgets/playlist_verses_expansion_tile.dart b/lib/widgets/playlist_verses_expansion_tile.dart index 916d926..cb55650 100644 --- a/lib/widgets/playlist_verses_expansion_tile.dart +++ b/lib/widgets/playlist_verses_expansion_tile.dart @@ -19,7 +19,7 @@ class PlaylistVersesExpansionTile extends ConsumerWidget { children: [ ...playlist.verses.map( (SavedVerseSlides savedVerseSlides) { - String displayString = scriptureRefToRefString(savedVerseSlides.scriptureRef); + String displayString = scriptureRefToString(savedVerseSlides.scriptureRef); return GestureDetector( onTap: () async { diff --git a/lib/widgets/projection_slide_widget.dart b/lib/widgets/projection_slide_widget.dart index 4fe4a04..ce86b88 100644 --- a/lib/widgets/projection_slide_widget.dart +++ b/lib/widgets/projection_slide_widget.dart @@ -1,5 +1,4 @@ import 'package:flutter/material.dart'; -import 'package:google_fonts/google_fonts.dart'; import '../core/constants.dart'; @@ -29,11 +28,7 @@ class ProjectionTextWidget extends StatelessWidget { softWrap: true, textAlign: TextAlign.center, overflow: TextOverflow.fade, - style: const TextStyle( - fontFamily: 'LemonMilk', - fontSize: 80, - color: Colors.white, - ), + style: songSlideTextStyle ) : Text( text, @@ -55,12 +50,7 @@ class ProjectionTextWidget extends StatelessWidget { children: [ Text( reference, - style: GoogleFonts.raleway( - textStyle: const TextStyle( - fontSize: 50, - color: Colors.white, - ), - ), + style: refTextStyle ), const SizedBox( width: 50, diff --git a/lib/windows/projection_window.dart b/lib/windows/projection_window.dart index 8ba73ec..27cc027 100644 --- a/lib/windows/projection_window.dart +++ b/lib/windows/projection_window.dart @@ -31,7 +31,7 @@ class _ProjectionWindowState extends State { child: Stack( children: [ ColorFiltered( - colorFilter: const ColorFilter.mode(Colors.black38, BlendMode.darken), + colorFilter: const ColorFilter.mode(Colors.black45, BlendMode.darken), child: Video( player: player, fit: BoxFit.cover,