TF-4075 Change attachments location

(cherry picked from commit ab23dac45d9dcf7c5e057f8e16974b3ed8205771)
This commit is contained in:
dab246
2025-10-06 19:17:25 +07:00
committed by Dat H. Pham
parent 993b05fbc2
commit 6bbebd8e67
31 changed files with 540 additions and 486 deletions
@@ -1,60 +1,8 @@
class SupportedPreviewFileTypes {
static const imageMimeTypes = [
'image/bmp',
'image/jpeg',
'image/gif',
'image/webp',
'image/png',
'image/svg+xml',
'image/x-icon',
'image/tiff',
'image/heif',
'image/avif'
];
static const textMimeTypes = [
'text/plain',
'text/markdown',
];
static const jsonMimeTypes = [
'application/json',
];
static const docMimeTypes = [
'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
'application/vnd.oasis.opendocument.text',
'application/vnd.oasis.opendocument.text-template',
'application/vnd.oasis.opendocument.text-web',
'application/vnd.oasis.opendocument.text-master',
'application/msword',
'application/vnd.ms-works'];
static const rtfMimeTypes = ['application/rtf'];
static const xlsMimeTypes = [
'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
'application/vnd.oasis.opendocument.spreadsheet',
'application/vnd.oasis.opendocument.spreadsheet-template',
'application/vnd.oasis.opendocument.chart',
'application/vnd.oasis.opendocument.formula',
'application/vnd.ms-excel'];
static const pptMimeTypes = [
'application/vnd.openxmlformats-officedocument.presentationml.presentation',
'application/vnd.oasis.opendocument.presentation',
'application/vnd.oasis.opendocument.presentation-template',
'application/vnd.ms-powerpoint'];
static const zipMimeTypes = [
'application/zip',
'application/x-tar',
'application/x-gtar',
'application/x-gzip',
'application/x-compressed',
'application/x-zip-compressed',
'application/java-archive'];
static const iOSSupportedTypes = {
'text/plain' : 'public.plain-text',
'text/html' : 'public.html',
@@ -83,50 +31,4 @@ class SupportedPreviewFileTypes {
'application/vnd.openxmlformats-officedocument.presentationml.presentation' : 'com.microsoft.powerpoint.ppt',
'application/pdf' : 'com.adobe.pdf',
};
static const androidSupportedTypes = [
'image/bmp',
'image/jpeg',
'image/gif',
'image/png',
'text/plain',
'text/html',
'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
'application/vnd.openxmlformats-officedocument.presentationml.presentation',
'application/msword',
'application/vnd.ms-excel',
'application/vnd.ms-powerpoint',
'application/vnd.ms-outlook',
'application/vnd.ms-works',
'application/vnd.mpohun.certificate',
'application/vnd.android.package-archive',
'application/octet-stream',
'application/x-tar',
'application/x-gtar',
'application/x-gzip',
'application/x-javascript',
'application/x-compressed',
'application/x-zip-compressed',
'application/java-archive',
'application/pdf',
'application/rtf',
'audio/x-mpegurl',
'video/x-m4v',
'video/x-ms-asf',
'video/x-msvideo',
'audio/x-mpeg',
'audio/mp4a-latm',
'video/vnd.mpegurl',
'video/quicktime',
'video/mp4',
'video/3gpp',
'video/mpeg',
'audio/mpeg',
'audio/ogg',
'audio/x-pn-realaudio',
'audio/x-wav',
'audio/x-ms-wma',
'audio/x-ms-wmv',
];
}
@@ -1,49 +1,18 @@
import 'package:core/data/constants/constant.dart';
import 'package:core/domain/preview/document_uti.dart';
import 'package:core/domain/preview/supported_preview_file_types.dart';
import 'package:core/presentation/extensions/string_extension.dart';
import 'package:core/presentation/model/file_category.dart';
import 'package:core/presentation/resources/image_paths.dart';
import 'package:http_parser/http_parser.dart';
extension MediaTypeExtension on MediaType {
bool isAndroidSupportedPreview() => SupportedPreviewFileTypes.androidSupportedTypes.contains(mimeType);
bool isIOSSupportedPreview() => SupportedPreviewFileTypes.iOSSupportedTypes.containsKey(mimeType);
bool isImageFile() => SupportedPreviewFileTypes.imageMimeTypes.contains(mimeType);
bool isDocFile() => SupportedPreviewFileTypes.docMimeTypes.contains(mimeType);
bool isPowerPointFile() => SupportedPreviewFileTypes.pptMimeTypes.contains(mimeType);
bool isExcelFile() => SupportedPreviewFileTypes.xlsMimeTypes.contains(mimeType);
bool isZipFile() => SupportedPreviewFileTypes.zipMimeTypes.contains(mimeType);
bool isRtfFile() => SupportedPreviewFileTypes.rtfMimeTypes.contains(mimeType);
bool isTextFile() => SupportedPreviewFileTypes.textMimeTypes.contains(mimeType);
bool isJsonFile() => SupportedPreviewFileTypes.jsonMimeTypes.contains(mimeType);
DocumentUti getDocumentUti() => DocumentUti(SupportedPreviewFileTypes.iOSSupportedTypes[mimeType]);
String getIcon(ImagePaths imagePaths, {String? fileName}) {
if (isPDFFile(fileName: fileName) == true || isRtfFile()) {
return imagePaths.icFilePdf;
} else if (isDocFile()) {
return imagePaths.icFileDocx;
} else if (isExcelFile()) {
return imagePaths.icFileXlsx;
} else if (isPowerPointFile()) {
return imagePaths.icFilePptx;
} else if (isZipFile()) {
return imagePaths.icFileZip;
} else if (isImageSupportedPreview(fileName: fileName)) {
return imagePaths.icFilePng;
} else {
return imagePaths.icFileEPup;
}
final category = getFileCategory(fileName: fileName);
return category.getIconPath(imagePaths);
}
bool isPDFFile({required String? fileName}) =>
@@ -58,10 +27,132 @@ extension MediaTypeExtension on MediaType {
(mimeType == Constant.octetStreamMimeType &&
fileName?.endsWith(Constant.htmlExtension) == true);
bool isImageSupportedPreview({required String? fileName}) =>
isImageFile() ||
(mimeType == Constant.octetStreamMimeType &&
fileName != null &&
SupportedPreviewFileTypes.imageMimeTypes
.contains(fileName.imageMimeType));
FileCategory getFileCategory({String? fileName}) {
String? ext;
if (fileName != null && fileName.contains('.')) {
ext = fileName.split('.').last.toLowerCase();
}
switch (ext) {
case 'pdf':
return FileCategory.pdf;
case 'doc':
case 'docx':
case 'rtf':
return FileCategory.document;
case 'odt':
return FileCategory.documentODT;
case 'xls':
case 'xlsx':
case 'csv':
case 'tsv':
return FileCategory.spreadsheet;
case 'ods':
return FileCategory.spreadsheetODS;
case 'ppt':
case 'pptx':
return FileCategory.presentation;
case 'odp':
return FileCategory.presentationODP;
case 'jpg':
case 'jpeg':
case 'png':
case 'gif':
case 'bmp':
case 'svg':
case 'webp':
case 'heic':
case 'heif':
case 'avif':
case 'tiff':
return FileCategory.image;
case 'mp3':
case 'wav':
case 'ogg':
case 'm4a':
case 'aac':
case 'flac':
return FileCategory.audio;
case 'mp4':
case 'mov':
case 'avi':
case 'mkv':
case 'webm':
case 'wmv':
return FileCategory.video;
case 'zip':
case 'rar':
case '7z':
case 'tar':
case 'gz':
case 'bz2':
return FileCategory.archive;
case 'txt':
case 'md':
case 'log':
return FileCategory.text;
case 'js':
case 'ts':
case 'json':
case 'html':
case 'css':
case 'xml':
case 'java':
case 'kt':
case 'dart':
case 'py':
case 'c':
case 'cpp':
case 'h':
case 'cs':
case 'swift':
case 'go':
case 'rb':
case 'php':
case 'sh':
case 'yml':
case 'yaml':
return FileCategory.code;
case 'apk':
case 'ipa':
case 'exe':
case 'dmg':
return FileCategory.other;
}
final lowerType = mimeType.toLowerCase();
if (lowerType == 'application/pdf') return FileCategory.pdf;
if (lowerType.startsWith('image/')) return FileCategory.image;
if (lowerType.startsWith('audio/')) return FileCategory.audio;
if (lowerType.startsWith('video/')) return FileCategory.video;
if (lowerType.startsWith('text/')) return FileCategory.text;
if (lowerType.contains('zip') || lowerType.contains('compressed')) {
return FileCategory.archive;
}
if (lowerType.contains('msword') ||
lowerType.contains('wordprocessingml')) {
return FileCategory.document;
}
if (lowerType.contains('spreadsheetml') ||
lowerType.contains('excel') ||
lowerType.contains('csv')) {
return FileCategory.spreadsheet;
}
if (lowerType.contains('presentationml') ||
lowerType.contains('powerpoint')) {
return FileCategory.presentation;
}
if (lowerType == 'application/octet-stream') {
return FileCategory.other;
}
return FileCategory.other;
}
}
@@ -0,0 +1,51 @@
import 'package:core/presentation/resources/image_paths.dart';
enum FileCategory {
pdf,
document,
documentODT,
spreadsheet,
spreadsheetODS,
presentation,
presentationODP,
image,
video,
audio,
archive,
text,
code,
other;
String getIconPath(ImagePaths imagePaths) {
switch (this) {
case FileCategory.pdf:
return imagePaths.icFilePdf;
case FileCategory.document:
return imagePaths.icFileDoc;
case FileCategory.documentODT:
return imagePaths.icFileODT;
case FileCategory.spreadsheet:
return imagePaths.icFileExcel;
case FileCategory.spreadsheetODS:
return imagePaths.icFileODS;
case FileCategory.presentation:
return imagePaths.icFilePowerPoint;
case FileCategory.presentationODP:
return imagePaths.icFileODP;
case FileCategory.image:
return imagePaths.icFileImage;
case FileCategory.video:
return imagePaths.icFileVideo;
case FileCategory.audio:
return imagePaths.icFileAudio;
case FileCategory.archive:
return imagePaths.icFileZip;
case FileCategory.text:
return imagePaths.icFileText;
case FileCategory.code:
return imagePaths.icFileCode;
case FileCategory.other:
return imagePaths.icFileDefault;
}
}
}
@@ -101,13 +101,20 @@ class ImagePaths {
String get icSelectedSB => _getImagePath('ic_selected_sb.svg');
String get icUserSB => _getImagePath('ic_user_sb.svg');
String get icComposeWeb => _getImagePath('ic_compose_web.svg');
String get icFileDocx => _getImagePath('ic_file_docx.svg');
String get icFileDoc => _getImagePath('ic_file_doc.svg');
String get icFileZip => _getImagePath('ic_file_zip.svg');
String get icFileXlsx => _getImagePath('ic_file_xlsx.svg');
String get icFilePng => _getImagePath('ic_file_png.svg');
String get icFileExcel => _getImagePath('ic_file_excel.svg');
String get icFileImage => _getImagePath('ic_file_image.svg');
String get icFilePdf => _getImagePath('ic_file_pdf.svg');
String get icFilePptx => _getImagePath('ic_file_pptx.svg');
String get icFileEPup => _getImagePath('ic_file_epup.svg');
String get icFilePowerPoint => _getImagePath('ic_file_power_point.svg');
String get icFileDefault => _getImagePath('ic_file_default.svg');
String get icFileAudio => _getImagePath('ic_file_audio.svg');
String get icFileCode => _getImagePath('ic_file_code.svg');
String get icFileODP => _getImagePath('ic_file_odp.svg');
String get icFileODS => _getImagePath('ic_file_ods.svg');
String get icFileODT => _getImagePath('ic_file_odt.svg');
String get icFileText => _getImagePath('ic_file_text.svg');
String get icFileVideo => _getImagePath('ic_file_video.svg');
String get icLanguage => _getImagePath('ic_language.svg');
String get icChecked => _getImagePath('ic_checked.svg');
String get icStyleBold => _getImagePath('ic_style_bold.svg');