Skip to content

Commit

Permalink
Merge commit '4b723e750d1371206520b10a122a444c4bba7475' into mindapps…
Browse files Browse the repository at this point in the history
…_flutter_local_notifications

* commit '4b723e750d1371206520b10a122a444c4bba7475': (76 commits)
  [flutter_local_notifications] update docs on initialize method to describe callbacks more (MaikuB#1841)
  enable usePubspecOverrides with melos (MaikuB#1822)
  replaced placeholder.com with dummyimage.com in example app due to Cloudflare blocking requests (MaikuB#1821)
  Google Java Format
  [flutter_local_notifications] Fixes MaikuB#1486 :Adds ability to count down chronometer with chronometerCountDown (MaikuB#1778)
  Implement options to hide or crop attachments in the thumbnail on iOS (MaikuB#1785)
  bump linux plugin's Flutter version requirement to 3.0.0 and add explicit ffi dependency (MaikuB#1812)
  [flutter_local_notifications] re-add imports needed for Flutter 3.0 and add build tasks that use Flutter 3.0 (MaikuB#1811)
  updated example app to not request the ability to display critical alerts (MaikuB#1809)
  Add note about keeping `@mipmap/ic_launcher` resource (MaikuB#1804)
  Recommend WindowManager to fix Android 12L+ bugs (MaikuB#1803)
  [flutter_local_notifications] Upgraded Android Gradle Plugin to fix Android build (MaikuB#1781)
  [flutter_local_notifications] fixes parsing of callback handles for notification actions on Android (MaikuB#1798)
  [flutter_local_notifications] fix Kotlin version used in example app (MaikuB#1791)
  Updates readme for iOS Setup (MaikuB#1776)
  added missing kudos for contributions relating to flutter_local_notifications 12.0.3 release
  release flutter_local_notifications 12.0.3
  updated code snippet  in readme on requesting permissions on Android (MaikuB#1754)
  Google Java Format
  Drop registerWith in Android plugin (MaikuB#1745)
  ...
  • Loading branch information
Marina González committed Apr 12, 2023
2 parents 9813860 + 4b723e7 commit 94c9e9d
Show file tree
Hide file tree
Showing 109 changed files with 6,743 additions and 2,116 deletions.
70 changes: 64 additions & 6 deletions .cirrus.yml
@@ -1,5 +1,5 @@
task:
name: Build Android example app
name: Build Android example app (stable channel)
container:
image: cirrusci/flutter:stable
pub_cache:
Expand All @@ -12,7 +12,20 @@ task:
- melos run build:example_android

task:
name: Build iOS example app
name: Build Android example app (3.0.0)
container:
image: cirrusci/flutter:3.0.0
pub_cache:
folder: ~/.pub-cache
install_melos_script:
- dart pub global activate melos
build_script:
- export PATH="$PATH":"$HOME/.pub-cache/bin"
- melos bootstrap
- melos run build:example_android

task:
name: Build iOS example app (stable channel)
osx_instance:
image: monterey-xcode
pub_cache:
Expand All @@ -28,7 +41,7 @@ task:
- melos run build:example_ios

task:
name: Build macOS example app
name: Build macOS example app (stable channel)
osx_instance:
image: monterey-xcode
pub_cache:
Expand All @@ -46,7 +59,24 @@ task:
- melos run build:example_macos

task:
name: Build Linux example app
name: Build Linux example app (3.0.0)
container:
image: cirrusci/flutter:3.0.0
pub_cache:
folder: ~/.pub-cache
setup_script:
- apt update
- apt install cmake ninja-build clang pkg-config libgtk-3-dev -y
- flutter config --enable-linux-desktop
install_melos_script:
- dart pub global activate melos
build_script:
- export PATH="$PATH":"$HOME/.pub-cache/bin"
- melos bootstrap
- melos run build:example_linux

task:
name: Build Linux example app (stable channel)
container:
image: cirrusci/flutter:stable
pub_cache:
Expand All @@ -62,6 +92,23 @@ task:
- melos bootstrap
- melos run build:example_linux

task:
name: Build Linux example app (3.0.0)
container:
image: cirrusci/flutter:3.0.0
pub_cache:
folder: ~/.pub-cache
setup_script:
- apt update
- apt install cmake ninja-build clang pkg-config libgtk-3-dev -y
- flutter config --enable-linux-desktop
install_melos_script:
- dart pub global activate melos
build_script:
- export PATH="$PATH":"$HOME/.pub-cache/bin"
- melos bootstrap
- melos run build:example_linux

task:
name: Run all unit tests (Dart)
container:
Expand All @@ -73,6 +120,17 @@ task:
- melos bootstrap
- melos run test:unit --no-select

task:
name: Run all unit tests (Android)
container:
image: cirrusci/flutter:stable
install_melos_script:
- dart pub global activate melos
test_script:
- export PATH="$PATH":"$HOME/.pub-cache/bin"
- melos bootstrap
- melos run test:unit:android

task:
name: Run integration tests (Android)
env:
Expand Down Expand Up @@ -103,14 +161,14 @@ task:
task:
name: Run integration tests (iOS)
osx_instance:
image: monterey-xcode
image: monterey-xcode-13.3
pub_cache:
folder: ~/.pub-cache
simulator_script:
- xcrun simctl list devicetypes
- xcrun simctl list runtimes
# create simulator
- udid=$(xcrun simctl create "iPhone 13" com.apple.CoreSimulator.SimDeviceType.iPhone-13 com.apple.CoreSimulator.SimRuntime.iOS-15-2)
- udid=$(xcrun simctl create "iPhone 13" com.apple.CoreSimulator.SimDeviceType.iPhone-13 com.apple.CoreSimulator.SimRuntime.iOS-15-4)
# boot simulator
- xcrun simctl boot $udid
# enable notifications permissions via AppleSimulatorUtils
Expand Down
14 changes: 14 additions & 0 deletions .github/dependabot.yml
@@ -0,0 +1,14 @@
version: 2
updates:
- package-ecosystem: "pub"
directory: "/flutter_local_notifications_platform_interface"
schedule:
interval: "daily"
- package-ecosystem: "pub"
directory: "/flutter_local_notifications_linux"
schedule:
interval: "daily"
- package-ecosystem: "pub"
directory: "/flutter_local_notifications"
schedule:
interval: "daily"
5 changes: 4 additions & 1 deletion .gitignore
@@ -1,4 +1,7 @@
pubspec.lock
.vscode
*.idea
*.DS_Store
*.DS_Store

# Melos
pubspec_overrides.yaml
219 changes: 164 additions & 55 deletions flutter_local_notifications/CHANGELOG.md

Large diffs are not rendered by default.

398 changes: 318 additions & 80 deletions flutter_local_notifications/README.md

Large diffs are not rendered by default.

20 changes: 16 additions & 4 deletions flutter_local_notifications/android/build.gradle
Expand Up @@ -8,7 +8,7 @@ buildscript {
}

dependencies {
classpath 'com.android.tools.build:gradle:3.6.3'
classpath 'com.android.tools.build:gradle:7.3.1'
}
}

Expand All @@ -22,20 +22,32 @@ rootProject.allprojects {
apply plugin: 'com.android.library'

android {
compileSdkVersion 31
compileSdkVersion 33
compileOptions {
coreLibraryDesugaringEnabled true
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}

defaultConfig {
multiDexEnabled true
minSdkVersion 16
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}

lintOptions {
disable 'InvalidPackage'
}
}

dependencies {
coreLibraryDesugaring 'com.android.tools:desugar_jdk_libs:1.1.5'
implementation "androidx.core:core:1.3.0"
implementation "androidx.media:media:1.1.0"
implementation "com.google.code.gson:gson:2.8.6"
implementation "com.jakewharton.threetenabp:threetenabp:1.2.3"
implementation "com.google.code.gson:gson:2.8.9"

testImplementation 'junit:junit:4.12'
testImplementation 'org.mockito:mockito-core:3.10.0'
testImplementation 'androidx.test:core:1.2.0'
testImplementation "org.robolectric:robolectric:4.7.3"
}
Expand Up @@ -4,7 +4,9 @@
<uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="android.permission.USE_FULL_SCREEN_INTENT" />
<uses-permission android:name="android.permission.SCHEDULE_EXACT_ALARM" />
<uses-permission android:name="android.permission.POST_NOTIFICATIONS"/>
<application>
<receiver android:exported="false" android:name="com.dexterous.flutterlocalnotifications.ActionBroadcastReceiver" />
<receiver android:exported="false" android:name="com.dexterous.flutterlocalnotifications.ScheduledNotificationReceiver" />
<receiver android:exported="false" android:name="com.dexterous.flutterlocalnotifications.ScheduledNotificationBootReceiver">
<intent-filter>
Expand Down
@@ -0,0 +1,135 @@
package com.dexterous.flutterlocalnotifications;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.util.Log;

import androidx.annotation.Keep;
import androidx.annotation.Nullable;
import androidx.annotation.VisibleForTesting;
import androidx.core.app.NotificationManagerCompat;

import com.dexterous.flutterlocalnotifications.isolate.IsolatePreferences;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import io.flutter.FlutterInjector;
import io.flutter.embedding.engine.FlutterEngine;
import io.flutter.embedding.engine.dart.DartExecutor;
import io.flutter.embedding.engine.loader.FlutterLoader;
import io.flutter.plugin.common.EventChannel;
import io.flutter.plugin.common.EventChannel.EventSink;
import io.flutter.plugin.common.EventChannel.StreamHandler;
import io.flutter.view.FlutterCallbackInformation;

public class ActionBroadcastReceiver extends BroadcastReceiver {
public static final String ACTION_TAPPED =
"com.dexterous.flutterlocalnotifications.ActionBroadcastReceiver.ACTION_TAPPED";
private static final String TAG = "ActionBroadcastReceiver";
@Nullable private static ActionEventSink actionEventSink;
@Nullable private static FlutterEngine engine;
IsolatePreferences preferences;

@VisibleForTesting
ActionBroadcastReceiver(IsolatePreferences preferences) {
this.preferences = preferences;
}

@Keep
public ActionBroadcastReceiver() {}

@Override
public void onReceive(Context context, Intent intent) {
if (!ACTION_TAPPED.equalsIgnoreCase(intent.getAction())) {
return;
}

preferences = preferences == null ? new IsolatePreferences(context) : preferences;

final Map<String, Object> action =
FlutterLocalNotificationsPlugin.extractNotificationResponseMap(intent);

if (intent.getBooleanExtra(FlutterLocalNotificationsPlugin.CANCEL_NOTIFICATION, false)) {
NotificationManagerCompat.from(context)
.cancel((int) action.get(FlutterLocalNotificationsPlugin.NOTIFICATION_ID));
}

if (actionEventSink == null) {
actionEventSink = new ActionEventSink();
}
actionEventSink.addItem(action);

startEngine(context);
}

private void startEngine(Context context) {
if (engine != null) {
Log.e(TAG, "Engine is already initialised");
return;
}

FlutterInjector injector = FlutterInjector.instance();
FlutterLoader loader = injector.flutterLoader();

loader.startInitialization(context);
loader.ensureInitializationComplete(context, null);

engine = new FlutterEngine(context);

/// This lookup needs to be done after creating an instance of `FlutterEngine` or lookup may
// fail
FlutterCallbackInformation dispatcherHandle = preferences.lookupDispatcherHandle();
if (dispatcherHandle == null) {
Log.w(TAG, "Callback information could not be retrieved");
return;
}

DartExecutor dartExecutor = engine.getDartExecutor();

initializeEventChannel(dartExecutor);

String dartBundlePath = loader.findAppBundlePath();
dartExecutor.executeDartCallback(
new DartExecutor.DartCallback(context.getAssets(), dartBundlePath, dispatcherHandle));
}

private void initializeEventChannel(DartExecutor dartExecutor) {
EventChannel channel =
new EventChannel(
dartExecutor.getBinaryMessenger(), "dexterous.com/flutter/local_notifications/actions");
channel.setStreamHandler(actionEventSink);
}

private static class ActionEventSink implements StreamHandler {

final List<Map<String, Object>> cache = new ArrayList<>();

@Nullable private EventSink eventSink;

public void addItem(Map<String, Object> item) {
if (eventSink != null) {
eventSink.success(item);
} else {
cache.add(item);
}
}

@Override
public void onListen(Object arguments, EventSink events) {
for (Map<String, Object> item : cache) {
events.success(item);
}

cache.clear();
eventSink = events;
}

@Override
public void onCancel(Object arguments) {
eventSink = null;
}
}
}

0 comments on commit 94c9e9d

Please sign in to comment.