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

New version 0.0.85 #224

Merged
merged 3 commits into from
Oct 30, 2023
Merged
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: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 0.0.85

- [DSVideoMessageBubble] Added a progressive loading

## 0.0.84

- [DSImageMessageBubble] Improved the performance of the image bubble
Expand Down
4 changes: 4 additions & 0 deletions analysis_options.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
include: package:flutter_lints/flutter.yaml

linter:
rules:
- prefer_relative_imports

# Additional information about this file can be found at
# https://dart.dev/guides/language/analysis-options
10 changes: 4 additions & 6 deletions lib/src/controllers/chat/ds_image_message_bubble.controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@ import 'dart:async';
import 'dart:convert';
import 'dart:io';

import 'package:blip_ds/src/utils/ds_directory_formatter.util.dart';
import 'package:crypto/crypto.dart';
import 'package:get/get.dart';
import 'package:path/path.dart' as path_utils;

import '../../services/ds_auth.service.dart';
import '../../services/ds_file.service.dart';
import '../../utils/ds_directory_formatter.util.dart';

class DSImageMessageBubbleController extends GetxController {
final maximumProgress = RxInt(0);
Expand Down Expand Up @@ -49,14 +50,11 @@ class DSImageMessageBubbleController extends GetxController {
return;
}

final fileName = fullPath.split('/').last;
final path = fullPath.substring(0, fullPath.lastIndexOf('/'));

try {
final savedFilePath = await DSFileService.download(
url,
fileName,
path: path,
path_utils.basename(fullPath),
path: path_utils.dirname(fullPath),
onReceiveProgress: _onReceiveProgress,
httpHeaders: shouldAuthenticate ? DSAuthService.httpHeaders : null,
);
Expand Down
39 changes: 19 additions & 20 deletions lib/src/controllers/chat/ds_video_message_bubble.controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,22 @@ import 'dart:io';

import 'package:crypto/crypto.dart';
import 'package:ffmpeg_kit_flutter_full_gpl/ffmpeg_kit.dart';
import 'package:ffmpeg_kit_flutter_full_gpl/return_code.dart';
import 'package:file_sizes/file_sizes.dart';
import 'package:get/get.dart';
import 'package:path/path.dart' as path_utils;

import '../../models/ds_toast_props.model.dart';
import '../../services/ds_file.service.dart';
import '../../services/ds_toast.service.dart';
import '../../utils/ds_directory_formatter.util.dart';
import '../../widgets/chat/video/ds_video_error.dialog.dart';

class DSVideoMessageBubbleController {
final String url;
final int mediaSize;
final Map<String, String?>? httpHeaders;
final String type;
final maximumProgress = RxInt(0);
final downloadProgress = RxInt(0);

DSVideoMessageBubbleController({
required this.url,
Expand Down Expand Up @@ -90,28 +91,17 @@ class DSVideoMessageBubbleController {
if (!await outputFile.exists()) {
final inputFilePath = await DSFileService.download(
url,
fileName,
path_utils.basename(fullPath),
path: path_utils.dirname(fullPath),
onReceiveProgress: (current, max) {
downloadProgress.value = current;
maximumProgress.value = max;
},
httpHeaders: httpHeaders,
);

final session = await FFmpegKit.execute(
'-hide_banner -y -i "$inputFilePath" "${outputFile.path}"');

File(inputFilePath!).delete();

final returnCode = await session.getReturnCode();

if (!ReturnCode.isSuccess(returnCode)) {
hasError.value = true;
await DSVideoErrorDialog.show(
filename: fileName,
url: url,
httpHeaders: httpHeaders,
);
}
_generateThumbnail(inputFilePath!);
}

_generateThumbnail(outputFile.path);
} catch (_) {
hasError.value = true;

Expand All @@ -136,4 +126,13 @@ class DSVideoMessageBubbleController {

thumbnail.value = thumbnailPath;
}

String getDownloadProgress() {
String getSize(int value) => FileSize.getSize(
value,
precision: PrecisionValue.One,
);

return '${getSize(downloadProgress.value)} / ${getSize(maximumProgress.value)}';
}
}
47 changes: 31 additions & 16 deletions lib/src/widgets/chat/video/ds_video_message_bubble.widget.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ import '../../../models/ds_message_bubble_style.model.dart';
import '../../../services/ds_auth.service.dart';
import '../../../themes/colors/ds_colors.theme.dart';
import '../../../themes/icons/ds_icons.dart';
import '../../animations/ds_fading_circle_loading.widget.dart';
import '../../buttons/ds_button.widget.dart';
import '../../texts/ds_caption_small_text.widget.dart';
import '../ds_message_bubble.widget.dart';
import '../ds_show_more_text.widget.dart';
import 'ds_video_body.widget.dart';
Expand Down Expand Up @@ -135,21 +135,8 @@ class _DSVideoMessageBubbleState extends State<DSVideoMessageBubble>
size: 80.0,
color: DSColors.neutralDarkRooftop,
)
: (_controller.isDownloading.value ||
_controller.isLoadingThumbnail.value)
? Center(
child: Container(
height: 50.0,
decoration: BoxDecoration(
shape: BoxShape.circle,
color: foregroundColor,
),
child: DSFadingCircleLoading(
color: backgroundLoadingColor,
size: 45.0,
),
),
)
: _controller.isDownloading.value
? _buildDownloadProgress(foregroundColor)
: _controller.thumbnail.isEmpty
? Center(
child: SizedBox(
Expand Down Expand Up @@ -204,4 +191,32 @@ class _DSVideoMessageBubbleState extends State<DSVideoMessageBubble>
),
);
}

Widget _buildDownloadProgress(final Color foregroundColor) {
final double percent = _controller.maximumProgress.value > 0
? _controller.downloadProgress.value / _controller.maximumProgress.value
: 0;

return AnimatedOpacity(
opacity: _controller.maximumProgress.value > 0 ? 1 : 0,
duration: const Duration(milliseconds: 250),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Padding(
padding: const EdgeInsets.all(8.0),
child: CircularProgressIndicator(
color: foregroundColor,
backgroundColor: Colors.grey,
value: percent,
),
),
DSCaptionSmallText(
_controller.getDownloadProgress(),
color: foregroundColor,
)
],
),
);
}
}
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: blip_ds
description: Blip Design System for Flutter.
version: 0.0.84
version: 0.0.85
homepage: https://github.com/takenet/blip-ds-flutter#readme
repository: https://github.com/takenet/blip-ds-flutter

Expand Down