From 0052d3f43dd633d9f46af03bba9054f9b232658a Mon Sep 17 00:00:00 2001 From: TheFinestArtist Date: Tue, 17 Oct 2023 06:41:31 -0700 Subject: [PATCH] fix(android_alarm_manager): Add Kotlin dependency and convert AlarmBroadcastReceiver class to Kotlin --- .../android/build.gradle | 8 +++++ .../AlarmBroadcastReceiver.java | 31 ------------------- .../AlarmBroadcastReceiver.kt | 29 +++++++++++++++++ 3 files changed, 37 insertions(+), 31 deletions(-) delete mode 100644 packages/android_alarm_manager_plus/android/src/main/java/dev/fluttercommunity/plus/androidalarmmanager/AlarmBroadcastReceiver.java create mode 100644 packages/android_alarm_manager_plus/android/src/main/kotlin/dev/fluttercommunity/plus/androidalarmmanager/AlarmBroadcastReceiver.kt diff --git a/packages/android_alarm_manager_plus/android/build.gradle b/packages/android_alarm_manager_plus/android/build.gradle index 5ab9b080e4..891af289fb 100644 --- a/packages/android_alarm_manager_plus/android/build.gradle +++ b/packages/android_alarm_manager_plus/android/build.gradle @@ -2,6 +2,7 @@ group 'dev.fluttercommunity.plus.androidalarmmanager' version '1.0-SNAPSHOT' buildscript { + ext.kotlin_version = '1.7.22' repositories { google() mavenCentral() @@ -9,6 +10,7 @@ buildscript { dependencies { classpath 'com.android.tools.build:gradle:8.1.2' + classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" } } @@ -20,6 +22,7 @@ rootProject.allprojects { } apply plugin: 'com.android.library' +apply plugin: 'kotlin-android' android { compileSdkVersion 33 @@ -31,6 +34,10 @@ android { targetCompatibility JavaVersion.VERSION_1_8 } + kotlinOptions { + jvmTarget = '1.8' + } + defaultConfig { minSdkVersion 19 testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" @@ -42,6 +49,7 @@ android { } dependencies { + implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version" implementation 'androidx.appcompat:appcompat:1.6.1' api 'androidx.core:core:1.10.1' } diff --git a/packages/android_alarm_manager_plus/android/src/main/java/dev/fluttercommunity/plus/androidalarmmanager/AlarmBroadcastReceiver.java b/packages/android_alarm_manager_plus/android/src/main/java/dev/fluttercommunity/plus/androidalarmmanager/AlarmBroadcastReceiver.java deleted file mode 100644 index 5391a2d6ca..0000000000 --- a/packages/android_alarm_manager_plus/android/src/main/java/dev/fluttercommunity/plus/androidalarmmanager/AlarmBroadcastReceiver.java +++ /dev/null @@ -1,31 +0,0 @@ -// Copyright 2019 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -package dev.fluttercommunity.plus.androidalarmmanager; - -import android.content.BroadcastReceiver; -import android.content.Context; -import android.content.Intent; - -public class AlarmBroadcastReceiver extends BroadcastReceiver { - /** - * Invoked by the OS when a timer goes off. - * - *

The associated timer was registered in {@link AlarmService}. - * - *

In Android, timer notifications require a {@link BroadcastReceiver} as the artifact that is - * notified when the timer goes off. As a result, this method is kept simple, immediately - * offloading any work to {@link AlarmService#enqueueAlarmProcessing(Context, Intent)}. - * - *

This method is the beginning of an execution path that will eventually execute a desired - * Dart callback function, as registered by the Dart side of the android_alarm_manager plugin. - * However, there may be asynchronous gaps between {@code onReceive()} and the eventual invocation - * of the Dart callback because {@link AlarmService} may need to spin up a Flutter execution - * context before the callback can be invoked. - */ - @Override - public void onReceive(Context context, Intent intent) { - AlarmService.enqueueAlarmProcessing(context, intent); - } -} diff --git a/packages/android_alarm_manager_plus/android/src/main/kotlin/dev/fluttercommunity/plus/androidalarmmanager/AlarmBroadcastReceiver.kt b/packages/android_alarm_manager_plus/android/src/main/kotlin/dev/fluttercommunity/plus/androidalarmmanager/AlarmBroadcastReceiver.kt new file mode 100644 index 0000000000..8b81bed771 --- /dev/null +++ b/packages/android_alarm_manager_plus/android/src/main/kotlin/dev/fluttercommunity/plus/androidalarmmanager/AlarmBroadcastReceiver.kt @@ -0,0 +1,29 @@ +// Copyright 2019 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. +package dev.fluttercommunity.plus.androidalarmmanager + +import android.content.BroadcastReceiver +import android.content.Context +import android.content.Intent + +class AlarmBroadcastReceiver : BroadcastReceiver() { + /** + * Invoked by the OS when a timer goes off. + * + * The associated timer was registered in [AlarmService]. + * + * In Android, timer notifications require a [BroadcastReceiver] as the artifact that is + * notified when the timer goes off. As a result, this method is kept simple, immediately + * offloading any work to [AlarmService.enqueueAlarmProcessing]. + * + * This method is the beginning of an execution path that will eventually execute a desired + * Dart callback function, as registered by the Dart side of the android_alarm_manager plugin. + * However, there may be asynchronous gaps between [onReceive] and the eventual invocation + * of the Dart callback because [AlarmService] may need to spin up a Flutter execution + * context before the callback can be invoked. + */ + override fun onReceive(context: Context, intent: Intent) { + AlarmService.enqueueAlarmProcessing(context, intent) + } +} \ No newline at end of file