Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[TEST] Combine TokenOIDC box with Account box in hive database #2998

Open
wants to merge 2 commits into
base: sprint_25_flutter_3_22_2
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions core/lib/data/network/download/download_client.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@ class DownloadClient {

Future<ResponseBody> downloadFile(
String url,
String basicAuth,
String authenticationHeader,
CancelToken? cancelToken,
) async {
final headerParam = _dioClient.getHeaders();
headerParam[HttpHeaders.authorizationHeader] = basicAuth;
headerParam[HttpHeaders.authorizationHeader] = authenticationHeader;
headerParam[HttpHeaders.acceptHeader] = DioClient.jmapHeader;

final responseBody = await _dioClient.get(
Expand Down
4 changes: 2 additions & 2 deletions core/lib/data/network/download/download_manager.dart
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,14 @@ class DownloadManager {
String downloadUrl,
Future<Directory> directoryToSave,
String filename,
String basicAuth,
String authenticationHeader,
{CancelToken? cancelToken}
) async {
final streamController = StreamController<DownloadedResponse>();

try {
await Future.wait([
_downloadClient.downloadFile(downloadUrl, basicAuth, cancelToken),
_downloadClient.downloadFile(downloadUrl, authenticationHeader, cancelToken),
directoryToSave
]).then((values) {
final response = (values[0] as ResponseBody);
Expand Down
21 changes: 21 additions & 0 deletions core/lib/domain/exceptions/file_exception.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import 'package:equatable/equatable.dart';

abstract class FileException with EquatableMixin implements Exception {
final String message;

FileException(this.message);

@override
String toString() => message;

@override
List<Object> get props => [message];
}

class NotFoundFileInFolderException extends FileException {
NotFoundFileInFolderException() : super('No files found in the folder');
}

class UserCancelShareFileException extends FileException {
UserCancelShareFileException() : super('User cancel share file');
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,14 @@ class CupertinoLoadingWidget extends StatelessWidget {
final double? size;
final EdgeInsetsGeometry? padding;
final bool isCenter;
final Color? progressColor;

const CupertinoLoadingWidget({
super.key,
this.size,
this.padding,
this.isCenter = true,
this.progressColor,
});

@override
Expand All @@ -21,8 +23,8 @@ class CupertinoLoadingWidget extends StatelessWidget {
child: SizedBox(
width: size ?? CupertinoLoadingWidgetStyles.size,
height: size ?? CupertinoLoadingWidgetStyles.size,
child: const CupertinoActivityIndicator(
color: CupertinoLoadingWidgetStyles.progressColor
child: CupertinoActivityIndicator(
color: progressColor ?? CupertinoLoadingWidgetStyles.progressColor
)
)
)
Expand All @@ -31,8 +33,8 @@ class CupertinoLoadingWidget extends StatelessWidget {
child: SizedBox(
width: size ?? CupertinoLoadingWidgetStyles.size,
height: size ?? CupertinoLoadingWidgetStyles.size,
child: const CupertinoActivityIndicator(
color: CupertinoLoadingWidgetStyles.progressColor
child: CupertinoActivityIndicator(
color: progressColor ?? CupertinoLoadingWidgetStyles.progressColor
)
),
);
Expand Down
12 changes: 9 additions & 3 deletions core/lib/utils/app_logger.dart
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import 'dart:async';

import 'package:core/utils/log_tracking.dart';
import 'package:core/utils/platform_info.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';

final logHistory = _Dispatcher('');

void log(String? value, {Level level = Level.info}) {
if (!kDebugMode) return;
Future<void> log(String? value, {Level level = Level.info}) async {
if (!kDebugMode && !LogTracking().enableTraceLog) return;

String logsStr = value ?? '';
logHistory.value = '$logsStr\n${logHistory.value}';
Expand Down Expand Up @@ -41,11 +42,16 @@ void log(String? value, {Level level = Level.info}) {
break;
}
}

// ignore: avoid_print
print('[TwakeMail] $logsStr');

if (LogTracking().enableTraceLog) {
await LogTracking().addLog(message: logsStr);
}
}

void logError(String? value) => log(value, level: Level.error);
Future<void> logError(String? value) => log(value, level: Level.error);

// Take from: https://flutter.dev/docs/testing/errors
void initLogger(VoidCallback runApp) {
Expand Down
59 changes: 59 additions & 0 deletions core/lib/utils/file_utils.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import 'dart:convert';
import 'dart:io';

import 'package:core/domain/exceptions/download_file_exception.dart';
import 'package:core/domain/exceptions/file_exception.dart';
import 'package:core/utils/app_logger.dart';
import 'package:core/utils/platform_info.dart';
import 'package:flutter/services.dart';
Expand Down Expand Up @@ -68,6 +69,18 @@ class FileUtils {
}
}

Future<void> deleteFileByFolderName({required String nameFile, String? folderPath}) async {
final internalStorageDirPath = await _getInternalStorageDirPath(
nameFile: nameFile,
folderPath: folderPath);

final file = File(internalStorageDirPath);

if (await file.exists()) {
await file.delete();
}
}

Future<String> getContentFromFile({
required String nameFile,
String? folderPath,
Expand Down Expand Up @@ -115,10 +128,56 @@ class FileUtils {
}
}

static Future<void> removeFolderPath(String path) async {
final dir = Directory(path);
if (await dir.exists()) {
await dir.delete(recursive: true);
}
}

Future<String> convertImageAssetToBase64(String assetImage) async {
ByteData bytes = await rootBundle.load(assetImage);
final buffer = bytes.buffer;
final base64Data = base64Encode(Uint8List.view(buffer));
return base64Data;
}

static Future<String> getExternalDocumentPath({String? folderPath}) async {
Directory directory = Directory('');
if (Platform.isAndroid) {
if (folderPath?.isNotEmpty == true) {
directory = Directory('/storage/emulated/0/Download/$folderPath');
} else {
directory = Directory('/storage/emulated/0/Download');
}
} else {
directory = await getApplicationDocumentsDirectory();
if (folderPath?.isNotEmpty == true) {
directory = Directory('${directory.absolute.path}/$folderPath');
}
}

final exPath = directory.path;
await Directory(exPath).create(recursive: true);
return exPath;
}

static Future<String> copyInternalFilesToDownloadExternal(List<String> listFilePaths) async {
final externalPath = await getExternalDocumentPath();

List<String> externalListPaths = [];
for (var filePath in listFilePaths) {
final file = File(filePath);
final fileName = filePath.substring(filePath.lastIndexOf('/') + 1);
final externalFile = File('$externalPath/$fileName');
await externalFile.writeAsBytes(file.readAsBytesSync());
externalListPaths.add(externalFile.path);
}

if (externalListPaths.isNotEmpty) {
return externalPath;
} else {
throw NotFoundFileInFolderException();
}
}
}
Loading
Loading