Skip to content

Commit

Permalink
added send button - appears only when user select files, 2) changes s…
Browse files Browse the repository at this point in the history
…ome ui in light mode, 3) added some animation in selection folder files
  • Loading branch information
sb-dor committed Aug 18, 2024
1 parent 6dfe224 commit 111ed72
Show file tree
Hide file tree
Showing 19 changed files with 450 additions and 150 deletions.
2 changes: 2 additions & 0 deletions android/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.ACCESS_MEDIA_LOCATION"/>
<uses-permission android:name="android.permission.READ_MEDIA_IMAGES" />
<uses-permission android:name="android.permission.READ_MEDIA_VIDEO" />


<uses-permission
Expand Down
2 changes: 1 addition & 1 deletion lib/core/app_settings/app_theme/app_theme_bloc.dart
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class AppThemeBloc {
factory AppThemeBloc() {
final eventBehavior = BehaviorSubject<AppThemeEvents>();

_currentState = AppColorsScheme.dark;
_currentState = AppColorsScheme.light;

final themeData = eventBehavior.map<ThemeData>((appThemeDataEvent) {
ThemeData theme = _appThemeChangerEvent(appThemeDataEvent as AppThemeChangerEvent);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
import 'package:camera/camera.dart';
import 'package:collection/collection.dart';
import 'package:flutter/material.dart';
/// [for future usege only]

/// [for future usage only]
class CameraHelperService {
late List<CameraDescription> _cameras;
Expand All @@ -14,8 +15,6 @@ class CameraHelperService {

// init this one in main func
Future<void> initCameras() async {
final list = await availableCameras();
debugPrint("all camera list settings list: ${list.length}");
_cameras = await availableCameras();
}

Expand Down
36 changes: 19 additions & 17 deletions lib/core/utils/permissions/permissions_service.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import 'package:device_info_plus/device_info_plus.dart';
import 'package:flutter/foundation.dart';
import 'package:permission_handler/permission_handler.dart';

Expand All @@ -7,28 +8,29 @@ class PermissionsService {
}

Future<bool> manageExternalStoragePermission() async {
var checkPermissionForManagingExternalStorage = await Permission.manageExternalStorage.status;

debugPrint("check external: $checkPermissionForManagingExternalStorage");

if (checkPermissionForManagingExternalStorage != PermissionStatus.granted) {
await Permission.manageExternalStorage.request();
bool permission = await Permission.manageExternalStorage.request().isGranted;
if (!permission) {
await openAppSettings();
permission = await Permission.manageExternalStorage.request().isGranted;
}

checkPermissionForManagingExternalStorage = await Permission.manageExternalStorage.status;

return checkPermissionForManagingExternalStorage == PermissionStatus.granted;
return permission;
}

Future<bool> storagePermission() async {
final checkPermissionForStorage = await Permission.storage.status;
Future<bool> storagePermission({bool checkOnceAgain = false}) async {
final deviceInfo = await DeviceInfoPlugin().androidInfo;
bool permission = false;

if (checkPermissionForStorage != PermissionStatus.granted) {
final permissionForStorage = await Permission.storage.request();
if (deviceInfo.version.sdkInt > 32) {
permission = await Permission.photos.request().isGranted;
} else {
permission = await Permission.storage.request().isGranted;
}

debugPrint("permission for managing storage denied $permissionForStorage");
return permissionForStorage != PermissionStatus.granted;
if (!permission && !checkOnceAgain) {
await openAppSettings();
permission = await storagePermission(checkOnceAgain: true);
}
return false;

return permission;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -63,15 +63,15 @@ class TelegramStorageFilePickerDataModel {
title: "Gallery",
content: "To send images without compression",
onTap: () async {
final dir = await FolderCreator.getApplicationDirStatic();
// init here for folder data
_telegramBloc.events.add(
SetSpecificFolderPathInOrderToGetDataFromThereEvent(dir?.path),
const SelectScreenForFilesPickerScreenEvent(
TelegramFileFolderEnum.browseTheGalleryFolder,
),
);

_telegramBloc.events.add(
const SelectScreenForFilesPickerScreenEvent(
TelegramFileFolderEnum.browseTheGalleryFolder,
const GetSpecificFolderDataEvent(
getGalleryData: true,
),
);
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,17 @@ import 'package:yahay/features/telegram_file_picker_feature/domain/entities/tele
import 'package:yahay/features/telegram_file_picker_feature/domain/repo/telegram_file_picker_repo.dart';
import 'package:yahay/features/telegram_file_picker_feature/mixins/app_storage_file_mixin/app_storage_file_mixin.dart';
import 'package:yahay/features/telegram_file_picker_feature/mixins/recent_file_mixin/downloads_path_files.dart';
import 'package:yahay/features/telegram_file_picker_feature/mixins/recent_file_mixin/recent_file_mixin.dart';
import 'package:yahay/features/telegram_file_picker_feature/mixins/recent_file_mixin/recent_galley_file_mixin.dart';

class TelegramFilePickerRepoImpl
with RecentFileMixin, DownloadsPathFiles, AppStorageFileMixin
with RecentGalleyFileMixin, DownloadsPathFiles, AppStorageFileMixin
implements TelegramFilePickerRepo {
@override
Stream<TelegramPathFolderFileModel?> getRecentImagesAndVideos() =>
getAllImagesAndVideos();
Stream<TelegramPathFolderFileModel?> getRecentImagesAndVideos({RecentFilesOptions? options}) =>
getAllImagesAndVideos(options: options);

@override
Stream<TelegramPathFolderFileModel?> getRecentFiles() =>
downloadsPathFilesData();
Stream<TelegramPathFolderFileModel?> getRecentFiles() => downloadsPathFilesData();

@override
Stream<TelegramPathFolderFileModel?> getSpecificFolderData(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import 'package:yahay/features/telegram_file_picker_feature/domain/entities/telegram_path_folder_file.dart';
import 'package:yahay/features/telegram_file_picker_feature/mixins/recent_file_mixin/recent_galley_file_mixin.dart';

// means that other classes can't "extend" it
// classes only can "implement"
abstract interface class TelegramFilePickerRepo {
// for getting recent files -> images and videos
Stream<TelegramPathFolderFile?> getRecentImagesAndVideos();
Stream<TelegramPathFolderFile?> getRecentImagesAndVideos({RecentFilesOptions? options});

// for getting all download's path files here
Stream<TelegramPathFolderFile?> getRecentFiles();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,11 @@ class FilePickerUseCase {
FilePickerUseCase(this._filePickerRepo);

// for getting recent files -> images and videos
Stream<TelegramPathFolderFile?> getRecentImagesAndVideos() async* {
yield* _filePickerRepo.getRecentImagesAndVideos();
}
Stream<TelegramPathFolderFile?> getRecentImagesAndVideos() =>
_filePickerRepo.getRecentImagesAndVideos();

// for getting all download's path files here
Stream<TelegramPathFolderFile?> downloadsPathFilesData() async* {
yield* _filePickerRepo.getRecentFiles();
}
Stream<TelegramPathFolderFile?> downloadsPathFilesData() => _filePickerRepo.getRecentFiles();

//
// for getting specific app folder data, does not matter what
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,35 +14,28 @@ import 'package:yahay/features/telegram_file_picker_feature/data/models/telegram
import 'package:yahay/features/telegram_file_picker_feature/domain/entities/telegram_file_image_asset_entity.dart';
import 'package:yahay/injections/injections.dart';

mixin class RecentFileMixin {
mixin class RecentGalleyFileMixin {
final _permissions = snoopy<PermissionsService>();

// final _context = snoopy<GlobalContext>().globalContext.currentContext!;

// final _reusableFunctions = snoopy<ReusableGlobalFunctions>();

Stream<TelegramPathFolderFileModel?> getAllImagesAndVideos() async* {
Stream<TelegramPathFolderFileModel?> getAllImagesAndVideos({
RecentFilesOptions? options,
}) async* {
try {
final externalStoragePermission = await _permissions.manageExternalStoragePermission();

final storagePermission = await _permissions.storagePermission();

debugPrint("storage $storagePermission | external: ${externalStoragePermission}");
debugPrint("storage $storagePermission | external: $externalStoragePermission");

if (!externalStoragePermission || !storagePermission) return;

var images = await PhotoManager.getAssetListRange(
start: 0,
end: 100,
);

List<TelegramFileImageAssetEntity> toEncodeList = [];

for (final image in images) {
final file = await image.file;
if (file == null) continue;
toEncodeList.add(TelegramFileImageAssetEntity(file.absolute.path));
}
List<TelegramFileImageAssetEntity> toEncodeList = await _RecentFilesHelper(
options: options,
).getAssets();

final ReceivePort receivePort = ReceivePort();

Expand Down Expand Up @@ -154,3 +147,76 @@ mixin class RecentFileMixin {
// return fileFromCompressedImage;
// }
}

class RecentFilesOptions {
final bool getAll;
final int? start;
final int? end;

RecentFilesOptions({this.getAll = false, this.start, this.end});
}

abstract interface class _RecentFilesHelper {
Future<List<TelegramFileImageAssetEntity>> getAssets();

factory _RecentFilesHelper({
RecentFilesOptions? options,
}) {
switch (options?.getAll) {
case null:
case false:
return _GetRangedAssetFiles(
start: options?.start,
end: options?.end,
);
case true:
return _GetAllAssetFiles();
}
}
}

class _GetRangedAssetFiles implements _RecentFilesHelper {
final int? start;
final int? end;

_GetRangedAssetFiles({this.start, this.end});

@override
Future<List<TelegramFileImageAssetEntity>> getAssets() async {
var images = await PhotoManager.getAssetListRange(
start: start ?? 0,
end: end ?? 100,
);

List<TelegramFileImageAssetEntity> list = [];

for (final image in images) {
final file = await image.file;
if (file == null) continue;
list.add(TelegramFileImageAssetEntity(file.absolute.path));
}
return list;
}
}

class _GetAllAssetFiles implements _RecentFilesHelper {
@override
Future<List<TelegramFileImageAssetEntity>> getAssets() async {
var images = await PhotoManager.getAssetPathList();
List<TelegramFileImageAssetEntity> list = [];
for (final assetPath in images) {
// Fetch all assets in the album
final assets = await assetPath.getAssetListPaged(
page: 0, // Start with the first page
size: await assetPath.assetCountAsync, // Fetch all assets in one go
);

for (final asset in assets) {
final file = await asset.file;
if (file == null) continue;
list.add(TelegramFileImageAssetEntity(file.absolute.path));
}
}
return list;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ 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_asset_entity.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_path_folder_file.dart';
import 'package:yahay/features/telegram_file_picker_feature/view/bloc/telegram_file_picker_state.dart';
Expand Down Expand Up @@ -56,6 +57,10 @@ class TelegramFilePickerStateModel {
_specificFolderFilesPagination,
);

UnmodifiableListView<TelegramFileImageEntity> get specificFolderFilesAll => UnmodifiableListView(
_specificFolderFilesAll,
);

List<TelegramFileImageEntity?> get clonedPickedFiles =>
_pickedFiles.map((e) => TelegramFileImageModel.fromEntity(e)).toList();

Expand Down Expand Up @@ -152,6 +157,10 @@ class TelegramFilePickerStateModel {
}
}

void addAllToFolderDataList(List<TelegramFileImageEntity> list) {
_specificFolderFilesPagination.addAll(list);
}

void addToPagination(List<TelegramFileImageEntity> list) => _galleryPathPagination.addAll(list);

void addToRecentFilesPagination(List<TelegramFileImageEntity> list) =>
Expand Down Expand Up @@ -194,6 +203,8 @@ class TelegramFilePickerStateModel {
bool isFileInsidePickedFiles(TelegramFileImageEntity? value) =>
_pickedFiles.any((el) => el.uuid == value?.uuid);

void clearPickedFiles() => _pickedFiles.clear();

String? getFileBaseName(File? file) {
try {
return basename(file!.path);
Expand Down
Loading

0 comments on commit 111ed72

Please sign in to comment.