From bc89370a3da7096806ef3d91edaea2bd5ba41a78 Mon Sep 17 00:00:00 2001 From: sb-dor Date: Fri, 16 Aug 2024 07:44:33 +0500 Subject: [PATCH] still dealing with ui --- ...legram_storage_file_picker_data_model.dart | 7 +- .../entities/telegram_file_folder_enums.dart | 6 + .../telegram_file_picker_state_model.dart | 8 +- .../bloc/telegram_file_picker_events.dart | 3 +- .../telegram_browse_app_folder_screen.dart | 15 ++- .../telegram_browse_folder_data_screen.dart | 13 +- .../telegram_files_picker_screen.dart | 118 +++++++++++++----- 7 files changed, 130 insertions(+), 40 deletions(-) create mode 100644 lib/features/telegram_file_picker_feature/domain/entities/telegram_file_folder_enums.dart diff --git a/lib/features/telegram_file_picker_feature/data/models/data_models/telegram_storage_file_picker_data_model.dart b/lib/features/telegram_file_picker_feature/data/models/data_models/telegram_storage_file_picker_data_model.dart index e68f66e..603d00f 100644 --- a/lib/features/telegram_file_picker_feature/data/models/data_models/telegram_storage_file_picker_data_model.dart +++ b/lib/features/telegram_file_picker_feature/data/models/data_models/telegram_storage_file_picker_data_model.dart @@ -1,6 +1,7 @@ import 'package:flutter/material.dart'; import 'package:yahay/core/app_routing/app_router.dart'; import 'package:yahay/core/utils/global_context/global_context.dart'; +import 'package:yahay/features/telegram_file_picker_feature/domain/entities/telegram_file_folder_enums.dart'; import 'package:yahay/features/telegram_file_picker_feature/domain/usecases/sheet_opener/telegram_app_folder_sheet_opener.dart'; import 'package:yahay/features/telegram_file_picker_feature/view/bloc/telegram_file_picker_bloc.dart'; import 'package:yahay/features/telegram_file_picker_feature/view/bloc/telegram_file_picker_events.dart'; @@ -47,7 +48,8 @@ class TelegramStorageFilePickerDataModel { title: "Yahay", content: "Browse the app's folder", onTap: () async { - _telegramBloc.events.add(const SelectScreenForFilesPickerScreenEvent(1)); + _telegramBloc.events.add(const SelectScreenForFilesPickerScreenEvent( + TelegramFileFolderEnum.browseTheAppsFolder)); }, ), TelegramStorageFilePickerDataModel( @@ -60,7 +62,8 @@ class TelegramStorageFilePickerDataModel { title: "Gallery", content: "To send images without compression", onTap: () { - _telegramBloc.events.add(const SelectScreenForFilesPickerScreenEvent(2)); + _telegramBloc.events.add(const SelectScreenForFilesPickerScreenEvent( + TelegramFileFolderEnum.browseTheGalleryFolder)); }, ), ]; diff --git a/lib/features/telegram_file_picker_feature/domain/entities/telegram_file_folder_enums.dart b/lib/features/telegram_file_picker_feature/domain/entities/telegram_file_folder_enums.dart new file mode 100644 index 0000000..a5f9a80 --- /dev/null +++ b/lib/features/telegram_file_picker_feature/domain/entities/telegram_file_folder_enums.dart @@ -0,0 +1,6 @@ +enum TelegramFileFolderEnum { + recentDownloadsScreen, + browseTheAppsFolder, + browseTheFolder, + browseTheGalleryFolder, +} \ No newline at end of file diff --git a/lib/features/telegram_file_picker_feature/view/bloc/state_model/telegram_file_picker_state_model.dart b/lib/features/telegram_file_picker_feature/view/bloc/state_model/telegram_file_picker_state_model.dart index 4a98ca3..cb26863 100644 --- a/lib/features/telegram_file_picker_feature/view/bloc/state_model/telegram_file_picker_state_model.dart +++ b/lib/features/telegram_file_picker_feature/view/bloc/state_model/telegram_file_picker_state_model.dart @@ -6,6 +6,7 @@ import 'package:path/path.dart'; import 'package:yahay/core/global_usages/constants/constants.dart'; import 'package:yahay/core/utils/global_context/global_context.dart'; import 'package:yahay/features/telegram_file_picker_feature/data/models/telegram_file_image_model.dart'; +import 'package:yahay/features/telegram_file_picker_feature/domain/entities/telegram_file_folder_enums.dart'; import 'package:yahay/features/telegram_file_picker_feature/domain/entities/telegram_file_image_entity.dart'; import 'package:yahay/features/telegram_file_picker_feature/domain/entities/telegram_file_image_with_compressed_and_original_path_entity.dart'; import 'package:yahay/features/telegram_file_picker_feature/view/bloc/telegram_file_picker_state.dart'; @@ -67,11 +68,12 @@ class TelegramFilePickerStateModel { Timer? get openButtonSectionTimer => _openButtonSectionTimer; - int _filePickerScreenSelectedScreen = 0; + TelegramFileFolderEnum _filePickerScreenSelectedScreen = + TelegramFileFolderEnum.recentDownloadsScreen; - int get filePickerScreenSelectedScreen => _filePickerScreenSelectedScreen; + TelegramFileFolderEnum get filePickerScreenSelectedScreen => _filePickerScreenSelectedScreen; - void selectScreen(int screen) { + void selectScreen(TelegramFileFolderEnum screen) { _filePickerScreenSelectedScreen = screen; } diff --git a/lib/features/telegram_file_picker_feature/view/bloc/telegram_file_picker_events.dart b/lib/features/telegram_file_picker_feature/view/bloc/telegram_file_picker_events.dart index 26969de..0fe3ddd 100644 --- a/lib/features/telegram_file_picker_feature/view/bloc/telegram_file_picker_events.dart +++ b/lib/features/telegram_file_picker_feature/view/bloc/telegram_file_picker_events.dart @@ -1,5 +1,6 @@ import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; +import 'package:yahay/features/telegram_file_picker_feature/domain/entities/telegram_file_folder_enums.dart'; import 'package:yahay/features/telegram_file_picker_feature/domain/entities/telegram_file_image_entity.dart'; import 'package:yahay/features/telegram_file_picker_feature/domain/entities/telegram_file_image_with_compressed_and_original_path_entity.dart'; @@ -98,7 +99,7 @@ final class BrowseInternalStorageAndSelectFilesEvent extends TelegramFilePickerE } final class SelectScreenForFilesPickerScreenEvent extends TelegramFilePickerEvents { - final int screen; + final TelegramFileFolderEnum screen; const SelectScreenForFilesPickerScreenEvent(this.screen); } diff --git a/lib/features/telegram_file_picker_feature/view/pages/screens/telegram_app_folder_screen/telegram_browse_app_folder_screen.dart b/lib/features/telegram_file_picker_feature/view/pages/screens/telegram_app_folder_screen/telegram_browse_app_folder_screen.dart index 0d2975e..500148c 100644 --- a/lib/features/telegram_file_picker_feature/view/pages/screens/telegram_app_folder_screen/telegram_browse_app_folder_screen.dart +++ b/lib/features/telegram_file_picker_feature/view/pages/screens/telegram_app_folder_screen/telegram_browse_app_folder_screen.dart @@ -1,4 +1,5 @@ import 'package:flutter/material.dart'; +import 'package:yahay/features/telegram_file_picker_feature/domain/entities/telegram_file_folder_enums.dart'; import 'package:yahay/features/telegram_file_picker_feature/mixins/folder_creator/folder_creator.dart'; import 'package:yahay/features/telegram_file_picker_feature/view/bloc/telegram_file_picker_bloc.dart'; import 'package:yahay/features/telegram_file_picker_feature/view/bloc/telegram_file_picker_events.dart'; @@ -33,7 +34,8 @@ class _TelegramBrowseAppFolderScreenState extends State createState() => _TelegramBrowseFolderDataScreenState(); @@ -29,9 +36,7 @@ class _TelegramBrowseFolderDataScreenState extends State { void initState() { super.initState(); _telegramFilePickerBloc = widget.telegramFilePickerBloc; - final currentStateModel = _telegramFilePickerBloc.states.value.telegramFilePickerStateModel; + // final currentStateModel = _telegramFilePickerBloc.states.value.telegramFilePickerStateModel; widget.parentScrollController.addListener(() { if (widget.parentScrollController.offset == widget.parentScrollController.position.maxScrollExtent && @@ -84,18 +85,21 @@ class _TelegramFilesPickerScreenState extends State { controller: widget.parentScrollController, children: [ Visibility( - visible: state.telegramFilePickerStateModel.filePickerScreenSelectedScreen == 0, + visible: state.telegramFilePickerStateModel.filePickerScreenSelectedScreen == + TelegramFileFolderEnum.recentDownloadsScreen, maintainAnimation: true, maintainState: true, child: AnimatedSlide( curve: Curves.fastOutSlowIn, duration: const Duration(milliseconds: 300), - offset: state.telegramFilePickerStateModel.filePickerScreenSelectedScreen == 0 + offset: state.telegramFilePickerStateModel.filePickerScreenSelectedScreen == + TelegramFileFolderEnum.recentDownloadsScreen ? Offset.zero : const Offset(1, 0), child: AnimatedOpacity( opacity: - state.telegramFilePickerStateModel.filePickerScreenSelectedScreen == 0 + state.telegramFilePickerStateModel.filePickerScreenSelectedScreen == + TelegramFileFolderEnum.recentDownloadsScreen ? 1 : 0, duration: const Duration(seconds: 1), @@ -113,29 +117,33 @@ class _TelegramFilesPickerScreenState extends State { ), ), ), + // apps folder Visibility( maintainAnimation: true, maintainState: true, - visible: state.telegramFilePickerStateModel.filePickerScreenSelectedScreen == 1, + visible: state.telegramFilePickerStateModel.filePickerScreenSelectedScreen == + TelegramFileFolderEnum.browseTheAppsFolder, child: PopScope( - canPop: state.telegramFilePickerStateModel.filePickerScreenSelectedScreen == 1 + canPop: state.telegramFilePickerStateModel.filePickerScreenSelectedScreen == + TelegramFileFolderEnum.browseTheAppsFolder ? false : true, onPopInvokedWithResult: (v, r) { - _telegramFilePickerBloc.events - .add(const SelectScreenForFilesPickerScreenEvent(0)); + _telegramFilePickerBloc.events.add( + const SelectScreenForFilesPickerScreenEvent( + TelegramFileFolderEnum.recentDownloadsScreen)); }, child: AnimatedSlide( curve: Curves.fastOutSlowIn, duration: const Duration(milliseconds: 300), - offset: - state.telegramFilePickerStateModel.filePickerScreenSelectedScreen == 1 - ? Offset.zero - : const Offset(1, 0), + offset: state.telegramFilePickerStateModel.filePickerScreenSelectedScreen == + TelegramFileFolderEnum.browseTheAppsFolder + ? Offset.zero + : const Offset(1, 0), child: AnimatedOpacity( opacity: state.telegramFilePickerStateModel.filePickerScreenSelectedScreen == - 1 + TelegramFileFolderEnum.browseTheAppsFolder ? 1 : 0, duration: const Duration(seconds: 1), @@ -143,34 +151,88 @@ class _TelegramFilesPickerScreenState extends State { ), ), ), + Visibility( child: PopScope( - canPop: state.telegramFilePickerStateModel.filePickerScreenSelectedScreen == 2 + canPop: state.telegramFilePickerStateModel.filePickerScreenSelectedScreen == + TelegramFileFolderEnum.browseTheFolder ? false : true, onPopInvokedWithResult: (v, r) { - _telegramFilePickerBloc.events - .add(const SelectScreenForFilesPickerScreenEvent(0)); + _telegramFilePickerBloc.events.add( + const SelectScreenForFilesPickerScreenEvent( + TelegramFileFolderEnum.browseTheAppsFolder, + ), + ); }, child: AnimatedSlide( curve: Curves.fastOutSlowIn, duration: const Duration(milliseconds: 300), - offset: - state.telegramFilePickerStateModel.filePickerScreenSelectedScreen == 2 - ? Offset.zero - : const Offset(1, 0), + offset: state.telegramFilePickerStateModel.filePickerScreenSelectedScreen == + TelegramFileFolderEnum.browseTheFolder + ? Offset.zero + : const Offset(1, 0), child: AnimatedOpacity( - opacity: - state.telegramFilePickerStateModel.filePickerScreenSelectedScreen == - 2 - ? 1 - : 0, - duration: const Duration(seconds: 1), - child: const TelegramBrowseFolderDataScreen()), + opacity: + state.telegramFilePickerStateModel.filePickerScreenSelectedScreen == + TelegramFileFolderEnum.browseTheFolder + ? 1 + : 0, + duration: const Duration(seconds: 1), + child: TelegramBrowseFolderDataScreen( + onBackFolder: () { + _telegramFilePickerBloc.events.add( + const SelectScreenForFilesPickerScreenEvent( + TelegramFileFolderEnum.browseTheAppsFolder, + ), + ); + }, + ), + ), + ), + ), + ), + + // gallery folder data + Visibility( + child: PopScope( + canPop: state.telegramFilePickerStateModel.filePickerScreenSelectedScreen == + TelegramFileFolderEnum.browseTheGalleryFolder + ? false + : true, + onPopInvokedWithResult: (v, r) { + _telegramFilePickerBloc.events.add( + const SelectScreenForFilesPickerScreenEvent( + TelegramFileFolderEnum.recentDownloadsScreen)); + }, + child: AnimatedSlide( + curve: Curves.fastOutSlowIn, + duration: const Duration(milliseconds: 300), + offset: state.telegramFilePickerStateModel.filePickerScreenSelectedScreen == + TelegramFileFolderEnum.browseTheGalleryFolder + ? Offset.zero + : const Offset(1, 0), + child: AnimatedOpacity( + opacity: + state.telegramFilePickerStateModel.filePickerScreenSelectedScreen == + TelegramFileFolderEnum.browseTheGalleryFolder + ? 1 + : 0, + duration: const Duration(seconds: 1), + child: TelegramBrowseFolderDataScreen( + onBackFolder: () { + _telegramFilePickerBloc.events.add( + const SelectScreenForFilesPickerScreenEvent( + TelegramFileFolderEnum.recentDownloadsScreen, + ), + ); + }, + ), + ), ), ), ), - ], //TelegramBrowseFolderDataScreen + ], ); } },