Skip to content

Commit

Permalink
🔀 Merge pull request #92 from SnapDrive/main
Browse files Browse the repository at this point in the history
Updated dependencies
  • Loading branch information
istornz authored Oct 11, 2024
2 parents 2e88e6e + 0343036 commit a210d7f
Show file tree
Hide file tree
Showing 4 changed files with 129 additions and 16 deletions.
63 changes: 52 additions & 11 deletions example/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,20 @@ packages:
app_group_directory:
dependency: transitive
description:
name: app_group_directory
sha256: ad89800fd55133b46e1f6940ac6b974562f7fb6394c662c0f4422b90167f2416
path: "."
ref: HEAD
resolved-ref: "6612fedceab9e75859dbfb0a54365ef812925c6b"
url: "https://github.com/nhathuynh2803/app_group_directory"
source: git
version: "2.0.0"
archive:
dependency: transitive
description:
name: archive
sha256: cb6a278ef2dbb298455e1a713bda08524a175630ec643a242c399c932a0a1f7d
url: "https://pub.dev"
source: hosted
version: "2.0.0"
version: "3.6.1"
async:
dependency: transitive
description:
Expand Down Expand Up @@ -49,6 +58,14 @@ packages:
url: "https://pub.dev"
source: hosted
version: "1.18.0"
crypto:
dependency: transitive
description:
name: crypto
sha256: ec30d999af904f33454ba22ed9a86162b35e52b44ac4807d1d93c288041d7d27
url: "https://pub.dev"
source: hosted
version: "3.0.5"
cupertino_icons:
dependency: "direct main"
description:
Expand Down Expand Up @@ -86,19 +103,19 @@ packages:
url: "https://pub.dev"
source: hosted
version: "4.0.0"
flutter_native_image:
dependency: transitive
description:
name: flutter_native_image
sha256: "0ff23d6222064259df8f85ea56925627ea1ec8658814672c5b6c23fc9174c65e"
url: "https://pub.dev"
source: hosted
version: "0.0.6+1"
flutter_test:
dependency: "direct dev"
description: flutter
source: sdk
version: "0.0.0"
image:
dependency: transitive
description:
name: image
sha256: "2237616a36c0d69aef7549ab439b833fb7f9fb9fc861af2cc9ac3eedddd69ca8"
url: "https://pub.dev"
source: hosted
version: "4.2.0"
leak_tracker:
dependency: transitive
description:
Expand Down Expand Up @@ -218,6 +235,14 @@ packages:
url: "https://pub.dev"
source: hosted
version: "2.3.0"
petitparser:
dependency: transitive
description:
name: petitparser
sha256: c15605cd28af66339f8eb6fbe0e541bfe2d1b72d5825efc6598f3e0a31b9ad27
url: "https://pub.dev"
source: hosted
version: "6.0.2"
platform:
dependency: transitive
description:
Expand Down Expand Up @@ -287,6 +312,14 @@ packages:
url: "https://pub.dev"
source: hosted
version: "0.7.2"
typed_data:
dependency: transitive
description:
name: typed_data
sha256: facc8d6582f16042dd49f2463ff1bd6e2c9ef9f3d5da3d9b087e244a7b564b3c
url: "https://pub.dev"
source: hosted
version: "1.3.2"
vector_math:
dependency: transitive
description:
Expand All @@ -311,6 +344,14 @@ packages:
url: "https://pub.dev"
source: hosted
version: "1.0.4"
xml:
dependency: transitive
description:
name: xml
sha256: b015a8ad1c488f66851d762d3090a21c600e479dc75e68328c52774040cf9226
url: "https://pub.dev"
source: hosted
version: "6.5.0"
sdks:
dart: ">=3.4.0 <4.0.0"
flutter: ">=3.22.0"
43 changes: 43 additions & 0 deletions ios/Classes/SwiftLiveActivitiesPlugin.swift
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,50 @@ public class SwiftLiveActivitiesPlugin: NSObject, FlutterPlugin, FlutterStreamHa
urlSchemeChannel.setStreamHandler(instance)
activityStatusChannel.setStreamHandler(instance)
registrar.addApplicationDelegate(instance)

print("LiveActivitiesPlugin is registered TEST123")
if #available(iOS 17.2, *) {
Task {
for await data in Activity<LiveActivitiesAppAttributes>.pushToStartTokenUpdates {
let token = data.map {String(format: "%02x", $0)}.joined()
print("Activity PushToStart Token: \(token)")
//send this token to your notification server

// PushToken über den Flutter Channel senden
channel.invokeMethod("onPushTokenReceived", arguments: token)
}

for await activity in Activity<LiveActivitiesAppAttributes>.activityUpdates {
// Upon finding one, listen for its push token (it is not available immediately!)
for await pushToken in activity.pushTokenUpdates {
let pushTokenString = pushToken.reduce("") { $0 + String(format: "%02x", $1) }
print("New activity detected with push token: \(pushTokenString)")
}
}
}
}
}

public func getPushToStartToken() {
if #available(iOS 17.2, *) {
Task {
for await data in Activity<LiveActivitiesAppAttributes>.pushToStartTokenUpdates {
let token = data.map {String(format: "%02x", $0)}.joined()
print("Activity PushToStart Token: \(token)")
//send this token to your notification server
}

for await activity in Activity<LiveActivitiesAppAttributes>.activityUpdates {
// Upon finding one, listen for its push token (it is not available immediately!)
for await pushToken in activity.pushTokenUpdates {
let pushTokenString = pushToken.reduce("") { $0 + String(format: "%02x", $1) }
print("New activity detected with push token: \(pushTokenString)")
}
}
}
}
}


public func detachFromEngine(for registrar: FlutterPluginRegistrar) {
urlSchemeSink = nil
Expand Down
34 changes: 31 additions & 3 deletions lib/services/app_groups_image_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@ import 'dart:io';
import 'dart:ui';

import 'package:app_group_directory/app_group_directory.dart';
import 'package:flutter_native_image/flutter_native_image.dart';
import 'package:live_activities/models/live_activity_image.dart';
import 'package:path_provider/path_provider.dart';
import 'package:image/image.dart' as img;


const kPictureFolderName = 'LiveActivitiesPictures';

Expand Down Expand Up @@ -59,11 +60,13 @@ class AppGroupsImageService {

final targetWidth = (imageWidth * value.resizeFactor).round();

file = await FlutterNativeImage.compressImage(
/*file = await FlutterNativeImage.compressImage(
file.path,
targetWidth: targetWidth,
targetHeight: (imageHeight * targetWidth / imageWidth).round(),
);
);*/

file = await compressImage(file, targetWidth);
}

final finalDestination = '${appGroupPicture.path}/$fileName';
Expand Down Expand Up @@ -94,3 +97,28 @@ class AppGroupsImageService {
}
}
}
Future<File> compressImage(File file, int targetWidth) async {
// Lade das Bild von der Datei
final bytes = await file.readAsBytes();
final image = img.decodeImage(bytes);

if (image == null) {
throw Exception("Das Bild konnte nicht geladen werden.");
}

// Berechne die Zielhöhe basierend auf den Bilddimensionen
final imageWidth = image.width;
final imageHeight = image.height;
final targetHeight = (imageHeight * targetWidth / imageWidth).round();

// Skaliere das Bild auf die Zielgröße
final resizedImage = img.copyResize(image, width: targetWidth, height: targetHeight);

// Komprimiere das Bild als JPEG
final compressedBytes = img.encodeJpg(resizedImage, quality: 85);

// Speichere das komprimierte Bild in einer neuen Datei
final compressedFile = File(file.path)..writeAsBytesSync(compressedBytes);

return compressedFile;
}
5 changes: 3 additions & 2 deletions pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,10 @@ dependencies:
flutter:
sdk: flutter
plugin_platform_interface: ^2.1.8
app_group_directory: ^2.0.0
app_group_directory:
git: https://github.com/SnapDrive/app_group_directory
path_provider: ^2.1.4
flutter_native_image: ^0.0.6+1
image: ^4.2.0

dev_dependencies:
flutter_test:
Expand Down

0 comments on commit a210d7f

Please sign in to comment.