Skip to content

Commit

Permalink
🔖 Bump to version 2.2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
istornz committed Dec 2, 2024
1 parent b256c39 commit 2295f24
Show file tree
Hide file tree
Showing 11 changed files with 60 additions and 22 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 2.2.0
* ✨ Added a new method `createOrUpdateActivity()`, you can use it to create or update by passing an activity ID (thanks to @Clon1998 👍).
* ⬆️ Upgrade dependencies.

## 2.1.0
* ✨ You can now send generic files instead of just pictures.

Expand Down
18 changes: 9 additions & 9 deletions example/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -98,10 +98,10 @@ packages:
dependency: "direct dev"
description:
name: flutter_lints
sha256: "3f41d009ba7172d5ff9be5f6e6e6abb4300e263aab8866d2a0842ed2a70f8f0c"
sha256: "5398f14efa795ffb7a33e9b6a08798b26a180edac4ad7db3f231e40f82ce11e1"
url: "https://pub.dev"
source: hosted
version: "4.0.0"
version: "5.0.0"
flutter_test:
dependency: "direct dev"
description: flutter
Expand All @@ -111,10 +111,10 @@ packages:
dependency: transitive
description:
name: image
sha256: "2237616a36c0d69aef7549ab439b833fb7f9fb9fc861af2cc9ac3eedddd69ca8"
sha256: f31d52537dc417fdcde36088fdf11d191026fd5e4fae742491ebd40e5a8bea7d
url: "https://pub.dev"
source: hosted
version: "4.2.0"
version: "4.3.0"
leak_tracker:
dependency: transitive
description:
Expand Down Expand Up @@ -143,17 +143,17 @@ packages:
dependency: transitive
description:
name: lints
sha256: "976c774dd944a42e83e2467f4cc670daef7eed6295b10b36ae8c85bcbf828235"
sha256: "3315600f3fb3b135be672bf4a178c55f274bebe368325ae18462c89ac1e3b413"
url: "https://pub.dev"
source: hosted
version: "4.0.0"
version: "5.0.0"
live_activities:
dependency: "direct main"
description:
path: ".."
relative: true
source: path
version: "2.0.1"
version: "2.2.0"
matcher:
dependency: transitive
description:
Expand Down Expand Up @@ -190,10 +190,10 @@ packages:
dependency: transitive
description:
name: path_provider
sha256: fec0d61223fba3154d87759e3cc27fe2c8dc498f6386c6d6fc80d1afdd1bf378
sha256: "50c5dd5b6e1aaf6fb3a78b33f6aa3afca52bf903a8a5298f53101fdaee55bbcd"
url: "https://pub.dev"
source: hosted
version: "2.1.4"
version: "2.1.5"
path_provider_android:
dependency: transitive
description:
Expand Down
2 changes: 1 addition & 1 deletion example/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ dev_dependencies:
# activated in the `analysis_options.yaml` file located at the root of your
# package. See that file for information about deactivating specific lint
# rules and activating additional ones.
flutter_lints: ^4.0.0
flutter_lints: ^5.0.0

# For information on the generic Dart part of this file, see the
# following page: https://dart.dev/tools/pub/pubspec
Expand Down
10 changes: 6 additions & 4 deletions lib/live_activities.dart
Original file line number Diff line number Diff line change
Expand Up @@ -54,16 +54,18 @@ class LiveActivities {
.updateActivity(activityId, data, alertConfig);
}

Future createOrUpdateActivity(String customId, Map<String, dynamic> data, {
Future createOrUpdateActivity(
String customId,
Map<String, dynamic> data, {
bool removeWhenAppIsKilled = false,
Duration? staleIn,
}) async {
await _appGroupsFileService.sendFilesToAppGroups(data);
return LiveActivitiesPlatform.instance
.createOrUpdateActivity(customId, data, removeWhenAppIsKilled: removeWhenAppIsKilled, staleIn: staleIn);
return LiveActivitiesPlatform.instance.createOrUpdateActivity(
customId, data,
removeWhenAppIsKilled: removeWhenAppIsKilled, staleIn: staleIn);
}


/// End an iOS 16.1+ live activity.
/// You can get an activity id by calling [createActivity].
Future endActivity(String activityId) {
Expand Down
7 changes: 5 additions & 2 deletions lib/live_activities_method_channel.dart
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,16 @@ class MethodChannelLiveActivities extends LiveActivitiesPlatform {
'alertConfig': alertConfig?.toMap()
});
}

@override
Future createOrUpdateActivity(String customId, Map<String, dynamic> data, {
Future createOrUpdateActivity(
String customId,
Map<String, dynamic> data, {
bool removeWhenAppIsKilled = false,
Duration? staleIn,
}) async {
final staleInMinutes =
(staleIn?.inMinutes ?? 0) >= 1 ? staleIn?.inMinutes : null;
(staleIn?.inMinutes ?? 0) >= 1 ? staleIn?.inMinutes : null;
return methodChannel.invokeMethod('createOrUpdateActivity', {
'customId': customId,
'data': data,
Expand Down
7 changes: 5 additions & 2 deletions lib/live_activities_platform_interface.dart
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,14 @@ abstract class LiveActivitiesPlatform extends PlatformInterface {
throw UnimplementedError('updateActivity() has not been implemented.');
}

Future createOrUpdateActivity(String customId, Map<String, dynamic> data, {
Future createOrUpdateActivity(
String customId,
Map<String, dynamic> data, {
bool removeWhenAppIsKilled = false,
Duration? staleIn,
}) {
throw UnimplementedError('createOrUpdateActivity() has not been implemented.');
throw UnimplementedError(
'createOrUpdateActivity() has not been implemented.');
}

Future endActivity(String activityId) {
Expand Down
15 changes: 15 additions & 0 deletions lib/models/activity_update.dart
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
import 'package:flutter/cupertino.dart';
import 'package:live_activities/models/live_activity_state.dart';

/// Abstract class to represent an activity update
abstract class ActivityUpdate {
/// The id of the activity
ActivityUpdate({required this.activityId});

/// The id of the activity
final String activityId;

/// Factory to create an activity update from a map
factory ActivityUpdate.fromMap(Map<String, dynamic> map) {
final status = LiveActivityState.values.byName(map['status']);
final activityId = map['activityId'] as String;
Expand All @@ -23,13 +27,15 @@ abstract class ActivityUpdate {
}
}

/// Map the activity update to a specific type
TResult map<TResult extends Object?>({
required TResult Function(ActiveActivityUpdate value) active,
required TResult Function(EndedActivityUpdate value) ended,
required TResult Function(StaleActivityUpdate value) stale,
required TResult Function(UnknownActivityUpdate value) unknown,
});

/// Map the activity update to a specific type or return null
TResult? mapOrNull<TResult extends Object?>({
TResult Function(ActiveActivityUpdate value)? active,
TResult Function(EndedActivityUpdate value)? ended,
Expand All @@ -43,13 +49,16 @@ abstract class ActivityUpdate {
}
}

/// Class to represent an active activity update
class ActiveActivityUpdate extends ActivityUpdate {
/// Constructor for an active activity update
@visibleForTesting
ActiveActivityUpdate({
required super.activityId,
required this.activityToken,
});

/// The token of the activity
final String activityToken;

@override
Expand Down Expand Up @@ -78,7 +87,9 @@ class ActiveActivityUpdate extends ActivityUpdate {
}
}

/// Class to represent an ended activity update
class EndedActivityUpdate extends ActivityUpdate {
/// Constructor for an ended activity update
@visibleForTesting
EndedActivityUpdate({required super.activityId});

Expand All @@ -103,7 +114,9 @@ class EndedActivityUpdate extends ActivityUpdate {
}
}

/// Class to represent a stale activity update
class StaleActivityUpdate extends ActivityUpdate {
/// Constructor for a stale activity update
@visibleForTesting
StaleActivityUpdate({required super.activityId});

Expand All @@ -128,7 +141,9 @@ class StaleActivityUpdate extends ActivityUpdate {
}
}

/// Class to represent an unknown activity update
class UnknownActivityUpdate extends ActivityUpdate {
/// Constructor for an unknown activity update
@visibleForTesting
UnknownActivityUpdate({required super.activityId});

Expand Down
6 changes: 6 additions & 0 deletions lib/services/app_groups_file_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,22 @@ import 'package:live_activities/models/live_activity_file.dart';
import 'package:live_activities/services/image_file_service.dart';
import 'package:path_provider/path_provider.dart';

/// Folder name to store files in the app groups directory
const kFileFolderName = 'LiveActivitiesFiles';

/// Service to handle all processes to files that are sent to the app groups
class AppGroupsFileService {
final _imageService = ImageFileService();

String? _appGroupId;
final List<String> _assetsCopiedInAppGroups = [];

/// Initialize the service with the app group id
init({required String appGroupId}) {
_appGroupId = appGroupId;
}

/// Send files to the app groups directory
Future sendFilesToAppGroups(Map<String, dynamic> data) async {
if (_appGroupId == null) {
throw Exception('appGroupId is null. Please call init() first.');
Expand Down Expand Up @@ -54,11 +58,13 @@ class AppGroupsFileService {
}
}

/// Remove all files from the app group directory
Future<void> removeAllFiles() async {
final laFilesDir = await _liveActivitiesFilesDirectory();
laFilesDir.deleteSync(recursive: true);
}

/// Remove all files that were copied to the app groups in this session
Future<void> removeFilesSession() async {
for (String filePath in _assetsCopiedInAppGroups) {
final file = File(filePath);
Expand Down
2 changes: 2 additions & 0 deletions lib/services/image_file_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ import 'dart:ui';

import 'package:image/image.dart' as img;

/// Service to handle all processes to image files
class ImageFileService {
/// Resize the image to a specific factor
Future resizeImage(File file, num resizeFactor) async {
final bytes = file.readAsBytesSync();
final buffer = await ImmutableBuffer.fromUint8List(bytes);
Expand Down
6 changes: 3 additions & 3 deletions pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: live_activities
description: A Flutter plugin to use iOS 16.1+ Live Activities & iPhone 14 Pro Dynamic Island features
version: 2.1.0
version: 2.2.0
homepage: https://dimitridessus.fr/
repository: https://github.com/istornz/live_activities

Expand All @@ -25,8 +25,8 @@ dependencies:
sdk: flutter
plugin_platform_interface: ^2.1.8
flutter_app_group_directory: ^1.0.2+2
path_provider: ^2.1.4
image: ^4.2.0
path_provider: ^2.1.5
image: ^4.3.0

dev_dependencies:
flutter_test:
Expand Down
5 changes: 4 additions & 1 deletion test/live_activities_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,11 @@ class MockLiveActivitiesPlatform
Future<Map<String, LiveActivityState>> getAllActivities() {
return Future.value({'ACTIVITY_ID': LiveActivityState.active});
}

@override
Future createOrUpdateActivity(String customId, Map<String, dynamic> data, {
Future createOrUpdateActivity(
String customId,
Map<String, dynamic> data, {
bool removeWhenAppIsKilled = false,
Duration? staleIn,
}) {
Expand Down

0 comments on commit 2295f24

Please sign in to comment.