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

Replace flutter_local_notifications with pigeon bindings #856

Open
wants to merge 13 commits into
base: main
Choose a base branch
from
Open
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
8 changes: 0 additions & 8 deletions android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,6 @@ android {
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8

// The use of desugar_jdk_libs causes warning noise at build time:
// https://github.com/zulip/zulip-flutter/pull/887#issuecomment-2287653388
// https://issuetracker.google.com/issues/294273986
// TODO(#351): Try removing core-library desugaring once we've
// removed flutter_local_notifications.
coreLibraryDesugaringEnabled true
}

kotlinOptions {
Expand Down Expand Up @@ -103,5 +96,4 @@ flutter {

dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlinVersion"
coreLibraryDesugaring "com.android.tools:desugar_jdk_libs:2.0.4"
}
81 changes: 60 additions & 21 deletions android/app/src/main/kotlin/com/zulip/flutter/Notifications.g.kt
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,40 @@ data class NotificationChannel (
}
}

/**
* Corresponds to `android.content.Intent`
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

notif [nfc]: Replace PendingIntent.intentPayload with PendingIntent.intent

Hmm, tools/check pigeon fails for me at this commit; do you reproduce?

Running pigeon...
Error: there were changes to pigeons:
 M android/app/src/main/kotlin/com/zulip/flutter/Notifications.g.kt
 M lib/host/android_notifications.g.dart

FAILED: pigeon

But the commit after it passes. So maybe some generated code was committed in that later commit but should have been committed here.

*
* See:
* https://developer.android.com/reference/android/content/Intent
* https://developer.android.com/reference/android/content/Intent#Intent(java.lang.String,%20android.net.Uri,%20android.content.Context,%20java.lang.Class%3C?%3E)
*
* Generated class from Pigeon that represents data sent in messages.
*/
data class AndroidIntent (
val action: String,
val uri: String,
/** A combination of flags from [IntentFlag]. */
val flags: Long

) {
companion object {
@Suppress("LocalVariableName")
fun fromList(__pigeon_list: List<Any?>): AndroidIntent {
val action = __pigeon_list[0] as String
val uri = __pigeon_list[1] as String
val flags = __pigeon_list[2].let { num -> if (num is Int) num.toLong() else num as Long }
return AndroidIntent(action, uri, flags)
}
}
fun toList(): List<Any?> {
return listOf(
action,
uri,
flags,
)
}
}

/**
* Corresponds to `android.app.PendingIntent`.
*
Expand All @@ -96,11 +130,7 @@ data class NotificationChannel (
*/
data class PendingIntent (
val requestCode: Long,
/**
* A value set on an extra on the Intent, and passed to
* the on-notification-opened callback.
*/
val intentPayload: String,
val intent: AndroidIntent,
/**
* A combination of flags from [PendingIntent.flags], and others associated
* with `Intent`; see Android docs for `PendingIntent.getActivity`.
Expand All @@ -112,15 +142,15 @@ data class PendingIntent (
@Suppress("LocalVariableName")
fun fromList(__pigeon_list: List<Any?>): PendingIntent {
val requestCode = __pigeon_list[0].let { num -> if (num is Int) num.toLong() else num as Long }
val intentPayload = __pigeon_list[1] as String
val intent = __pigeon_list[1] as AndroidIntent
val flags = __pigeon_list[2].let { num -> if (num is Int) num.toLong() else num as Long }
return PendingIntent(requestCode, intentPayload, flags)
return PendingIntent(requestCode, intent, flags)
}
}
fun toList(): List<Any?> {
return listOf(
requestCode,
intentPayload,
intent,
flags,
)
}
Expand Down Expand Up @@ -325,35 +355,40 @@ private object NotificationsPigeonCodec : StandardMessageCodec() {
}
130.toByte() -> {
return (readValue(buffer) as? List<Any?>)?.let {
PendingIntent.fromList(it)
AndroidIntent.fromList(it)
}
}
131.toByte() -> {
return (readValue(buffer) as? List<Any?>)?.let {
InboxStyle.fromList(it)
PendingIntent.fromList(it)
}
}
132.toByte() -> {
return (readValue(buffer) as? List<Any?>)?.let {
Person.fromList(it)
InboxStyle.fromList(it)
}
}
133.toByte() -> {
return (readValue(buffer) as? List<Any?>)?.let {
MessagingStyleMessage.fromList(it)
Person.fromList(it)
}
}
134.toByte() -> {
return (readValue(buffer) as? List<Any?>)?.let {
MessagingStyle.fromList(it)
MessagingStyleMessage.fromList(it)
}
}
135.toByte() -> {
return (readValue(buffer) as? List<Any?>)?.let {
Notification.fromList(it)
MessagingStyle.fromList(it)
}
}
136.toByte() -> {
return (readValue(buffer) as? List<Any?>)?.let {
Notification.fromList(it)
}
}
137.toByte() -> {
return (readValue(buffer) as? List<Any?>)?.let {
StatusBarNotification.fromList(it)
}
Expand All @@ -367,34 +402,38 @@ private object NotificationsPigeonCodec : StandardMessageCodec() {
stream.write(129)
writeValue(stream, value.toList())
}
is PendingIntent -> {
is AndroidIntent -> {
stream.write(130)
writeValue(stream, value.toList())
}
is InboxStyle -> {
is PendingIntent -> {
stream.write(131)
writeValue(stream, value.toList())
}
is Person -> {
is InboxStyle -> {
stream.write(132)
writeValue(stream, value.toList())
}
is MessagingStyleMessage -> {
is Person -> {
stream.write(133)
writeValue(stream, value.toList())
}
is MessagingStyle -> {
is MessagingStyleMessage -> {
stream.write(134)
writeValue(stream, value.toList())
}
is Notification -> {
is MessagingStyle -> {
stream.write(135)
writeValue(stream, value.toList())
}
is StatusBarNotification -> {
is Notification -> {
stream.write(136)
writeValue(stream, value.toList())
}
is StatusBarNotification -> {
stream.write(137)
writeValue(stream, value.toList())
}
else -> super.writeValue(stream, value)
}
}
Expand Down
16 changes: 9 additions & 7 deletions android/app/src/main/kotlin/com/zulip/flutter/ZulipPlugin.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package com.zulip.flutter
import android.annotation.SuppressLint
import android.content.Context
import android.content.Intent
import android.net.Uri
import android.os.Bundle
import android.util.Log
import androidx.annotation.Keep
Expand Down Expand Up @@ -97,13 +98,14 @@ private class AndroidNotificationHost(val context: Context)
contentIntent?.let { setContentIntent(
android.app.PendingIntent.getActivity(context,
it.requestCode.toInt(),
Intent(context, MainActivity::class.java).apply {
// This action name and extra name are special to
// FlutterLocalNotificationsPlugin, which handles receiving the Intent.
// TODO take care of receiving the notification-opened Intent ourselves
action = "SELECT_NOTIFICATION"
putExtra("payload", it.intentPayload)
},
it.intent.let { intent -> Intent(
intent.action,
Uri.parse(intent.uri),
context,
MainActivity::class.java
).apply {
flags = intent.flags.toInt()
} },
it.flags.toInt())
) }
contentText?.let { setContentText(it) }
Expand Down
6 changes: 0 additions & 6 deletions ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,6 @@ PODS:
- GoogleUtilities/UserDefaults (~> 7.8)
- nanopb (< 2.30911.0, >= 2.30908.0)
- Flutter (1.0.0)
- flutter_local_notifications (0.0.1):
- Flutter
- GoogleDataTransport (9.4.1):
- GoogleUtilities/Environment (~> 7.7)
- nanopb (< 2.30911.0, >= 2.30908.0)
Expand Down Expand Up @@ -155,7 +153,6 @@ DEPENDENCIES:
- firebase_core (from `.symlinks/plugins/firebase_core/ios`)
- firebase_messaging (from `.symlinks/plugins/firebase_messaging/ios`)
- Flutter (from `Flutter`)
- flutter_local_notifications (from `.symlinks/plugins/flutter_local_notifications/ios`)
- image_picker_ios (from `.symlinks/plugins/image_picker_ios/ios`)
- integration_test (from `.symlinks/plugins/integration_test/ios`)
- package_info_plus (from `.symlinks/plugins/package_info_plus/ios`)
Expand Down Expand Up @@ -196,8 +193,6 @@ EXTERNAL SOURCES:
:path: ".symlinks/plugins/firebase_messaging/ios"
Flutter:
:path: Flutter
flutter_local_notifications:
:path: ".symlinks/plugins/flutter_local_notifications/ios"
image_picker_ios:
:path: ".symlinks/plugins/image_picker_ios/ios"
integration_test:
Expand Down Expand Up @@ -231,7 +226,6 @@ SPEC CHECKSUMS:
FirebaseInstallations: 913cf60d0400ebd5d6b63a28b290372ab44590dd
FirebaseMessaging: 7b5d8033e183ab59eb5b852a53201559e976d366
Flutter: e0871f40cf51350855a761d2e70bf5af5b9b5de7
flutter_local_notifications: 4cde75091f6327eb8517fa068a0a5950212d2086
GoogleDataTransport: 6c09b596d841063d76d4288cc2d2f42cc36e1e2a
GoogleUtilities: ea963c370a38a8069cc5f7ba4ca849a60b6d7d15
image_picker_ios: c560581cceedb403a6ff17f2f816d7fea1421fc1
Expand Down
19 changes: 19 additions & 0 deletions lib/host/android_notifications.dart
Original file line number Diff line number Diff line change
Expand Up @@ -60,3 +60,22 @@ abstract class PendingIntentFlag {
/// Corresponds to `FLAG_ALLOW_UNSAFE_IMPLICIT_INTENT`.
static const allowUnsafeImplicitIntent = 1 << 24;
}

/// For use in [AndroidIntent.action].
///
/// See: https://developer.android.com/reference/android/content/Intent#constants_1
abstract class IntentAction {
/// Corresponds to `ACTION_VIEW`.
static const view = 'android.intent.action.VIEW';
}

/// For use in [AndroidIntent.flags].
///
/// See: https://developer.android.com/reference/android/content/Intent#constants_1
abstract class IntentFlag {
/// Corresponds to `FLAG_ACTIVITY_CLEAR_TOP`.
static const activityClearTop = 1 << 26;

/// Corresponds to `FLAG_ACTIVITY_NEW_TASK`.
static const activityNewTask = 1 << 28;
}
Loading