current_backup_asset_info_box.dart 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276
  1. import 'package:easy_localization/easy_localization.dart';
  2. import 'package:flutter/foundation.dart';
  3. import 'package:flutter/material.dart';
  4. import 'package:flutter_hooks/flutter_hooks.dart';
  5. import 'package:hooks_riverpod/hooks_riverpod.dart';
  6. import 'package:immich_mobile/extensions/build_context_extensions.dart';
  7. import 'package:immich_mobile/modules/backup/models/backup_state.model.dart';
  8. import 'package:immich_mobile/modules/backup/providers/backup.provider.dart';
  9. import 'package:immich_mobile/modules/backup/providers/error_backup_list.provider.dart';
  10. import 'package:immich_mobile/modules/backup/providers/manual_upload.provider.dart';
  11. import 'package:immich_mobile/routing/router.dart';
  12. import 'package:photo_manager/photo_manager.dart';
  13. class CurrentUploadingAssetInfoBox extends HookConsumerWidget {
  14. const CurrentUploadingAssetInfoBox({super.key});
  15. @override
  16. Widget build(BuildContext context, WidgetRef ref) {
  17. var isManualUpload = ref.watch(backupProvider).backupProgress ==
  18. BackUpProgressEnum.manualInProgress;
  19. var asset = !isManualUpload
  20. ? ref.watch(backupProvider).currentUploadAsset
  21. : ref.watch(manualUploadProvider).currentUploadAsset;
  22. var uploadProgress = !isManualUpload
  23. ? ref.watch(backupProvider).progressInPercentage
  24. : ref.watch(manualUploadProvider).progressInPercentage;
  25. var iCloudDownloadProgress =
  26. ref.watch(backupProvider).iCloudDownloadProgress;
  27. final isShowThumbnail = useState(false);
  28. String getAssetCreationDate() {
  29. return DateFormat.yMMMMd().format(
  30. DateTime.parse(
  31. asset.fileCreatedAt.toString(),
  32. ).toLocal(),
  33. );
  34. }
  35. Widget buildErrorChip() {
  36. return ActionChip(
  37. avatar: Icon(
  38. Icons.info,
  39. color: Colors.red[400],
  40. ),
  41. elevation: 1,
  42. visualDensity: VisualDensity.compact,
  43. label: Text(
  44. "backup_controller_page_failed",
  45. style: TextStyle(
  46. color: Colors.red[400],
  47. fontWeight: FontWeight.bold,
  48. fontSize: 11,
  49. ),
  50. ).tr(
  51. args: [ref.watch(errorBackupListProvider).length.toString()],
  52. ),
  53. backgroundColor: Colors.white,
  54. onPressed: () {
  55. context.autoPush(const FailedBackupStatusRoute());
  56. },
  57. );
  58. }
  59. Widget buildAssetInfoTable() {
  60. return Table(
  61. border: TableBorder.all(
  62. color: context.themeData.primaryColorLight,
  63. width: 1,
  64. ),
  65. children: [
  66. TableRow(
  67. decoration: const BoxDecoration(
  68. // color: Colors.grey[100],
  69. ),
  70. children: [
  71. TableCell(
  72. verticalAlignment: TableCellVerticalAlignment.middle,
  73. child: Padding(
  74. padding: const EdgeInsets.all(6.0),
  75. child: const Text(
  76. 'backup_controller_page_filename',
  77. style: TextStyle(
  78. fontWeight: FontWeight.bold,
  79. fontSize: 10.0,
  80. ),
  81. ).tr(
  82. args: [asset.fileName, asset.fileType.toLowerCase()],
  83. ),
  84. ),
  85. ),
  86. ],
  87. ),
  88. TableRow(
  89. decoration: const BoxDecoration(
  90. // color: Colors.grey[200],
  91. ),
  92. children: [
  93. TableCell(
  94. verticalAlignment: TableCellVerticalAlignment.middle,
  95. child: Padding(
  96. padding: const EdgeInsets.all(6.0),
  97. child: const Text(
  98. "backup_controller_page_created",
  99. style: TextStyle(
  100. fontWeight: FontWeight.bold,
  101. fontSize: 10.0,
  102. ),
  103. ).tr(
  104. args: [getAssetCreationDate()],
  105. ),
  106. ),
  107. ),
  108. ],
  109. ),
  110. TableRow(
  111. decoration: const BoxDecoration(
  112. // color: Colors.grey[100],
  113. ),
  114. children: [
  115. TableCell(
  116. child: Padding(
  117. padding: const EdgeInsets.all(6.0),
  118. child: const Text(
  119. "backup_controller_page_id",
  120. style: TextStyle(
  121. fontWeight: FontWeight.bold,
  122. fontSize: 10.0,
  123. ),
  124. ).tr(args: [asset.id]),
  125. ),
  126. ),
  127. ],
  128. ),
  129. ],
  130. );
  131. }
  132. buildAssetThumbnail() async {
  133. var assetEntity = await AssetEntity.fromId(asset.id);
  134. if (assetEntity != null) {
  135. return assetEntity.thumbnailDataWithSize(
  136. const ThumbnailSize(500, 500),
  137. quality: 100,
  138. );
  139. }
  140. }
  141. buildiCloudDownloadProgerssBar() {
  142. if (asset.iCloudAsset != null && asset.iCloudAsset!) {
  143. return Padding(
  144. padding: const EdgeInsets.only(top: 8.0),
  145. child: Row(
  146. children: [
  147. SizedBox(
  148. width: 110,
  149. child: Text(
  150. "iCloud Download",
  151. style: context.textTheme.labelSmall,
  152. ),
  153. ),
  154. Expanded(
  155. child: LinearProgressIndicator(
  156. minHeight: 10.0,
  157. value: uploadProgress / 100.0,
  158. backgroundColor: Colors.grey,
  159. color: context.primaryColor,
  160. ),
  161. ),
  162. Text(
  163. " ${iCloudDownloadProgress.toStringAsFixed(0)}%",
  164. style: const TextStyle(fontSize: 12),
  165. ),
  166. ],
  167. ),
  168. );
  169. }
  170. return const SizedBox();
  171. }
  172. buildUploadProgressBar() {
  173. return Padding(
  174. padding: const EdgeInsets.only(top: 8.0),
  175. child: Row(
  176. children: [
  177. if (asset.iCloudAsset != null && asset.iCloudAsset!)
  178. SizedBox(
  179. width: 110,
  180. child: Text(
  181. "Immich Upload",
  182. style: context.textTheme.labelSmall,
  183. ),
  184. ),
  185. Expanded(
  186. child: LinearProgressIndicator(
  187. minHeight: 10.0,
  188. value: uploadProgress / 100.0,
  189. backgroundColor: Colors.grey,
  190. color: context.primaryColor,
  191. ),
  192. ),
  193. Text(
  194. " ${uploadProgress.toStringAsFixed(0)}%",
  195. style: const TextStyle(fontSize: 12),
  196. ),
  197. ],
  198. ),
  199. );
  200. }
  201. return FutureBuilder<Uint8List?>(
  202. future: buildAssetThumbnail(),
  203. builder: (context, thumbnail) => ListTile(
  204. isThreeLine: true,
  205. leading: AnimatedCrossFade(
  206. alignment: Alignment.centerLeft,
  207. firstChild: GestureDetector(
  208. onTap: () => isShowThumbnail.value = false,
  209. child: thumbnail.hasData
  210. ? ClipRRect(
  211. borderRadius: BorderRadius.circular(5),
  212. child: Image.memory(
  213. thumbnail.data!,
  214. fit: BoxFit.cover,
  215. width: 50,
  216. height: 50,
  217. ),
  218. )
  219. : const SizedBox(
  220. width: 50,
  221. height: 50,
  222. child: Padding(
  223. padding: EdgeInsets.all(8.0),
  224. child: CircularProgressIndicator.adaptive(
  225. strokeWidth: 1,
  226. ),
  227. ),
  228. ),
  229. ),
  230. secondChild: GestureDetector(
  231. onTap: () => isShowThumbnail.value = true,
  232. child: Icon(
  233. Icons.image_outlined,
  234. color: context.primaryColor,
  235. size: 30,
  236. ),
  237. ),
  238. crossFadeState: isShowThumbnail.value
  239. ? CrossFadeState.showFirst
  240. : CrossFadeState.showSecond,
  241. duration: const Duration(milliseconds: 200),
  242. ),
  243. title: Row(
  244. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  245. children: [
  246. Text(
  247. "backup_controller_page_uploading_file_info",
  248. style: context.textTheme.titleSmall,
  249. ).tr(),
  250. if (ref.watch(errorBackupListProvider).isNotEmpty) buildErrorChip(),
  251. ],
  252. ),
  253. subtitle: Column(
  254. children: [
  255. buildiCloudDownloadProgerssBar(),
  256. buildUploadProgressBar(),
  257. Padding(
  258. padding: const EdgeInsets.only(top: 8.0),
  259. child: buildAssetInfoTable(),
  260. ),
  261. ],
  262. ),
  263. ),
  264. );
  265. }
  266. }