Compare commits

..

No commits in common. "53b6b65e7049ce5ead2ff07afe8602c329e2fc10" and "c905b3242d37eb87bea19baf5666812bb0567287" have entirely different histories.

10 changed files with 34 additions and 67 deletions

View File

@ -3,10 +3,7 @@ package org.moxxy.moxxy_native
const val TAG = "moxxy_native" const val TAG = "moxxy_native"
// The event channel name for the keyboard height // The event channel name for the keyboard height
const val KEYBOARD_HEIGHT_EVENT_CHANNEL_NAME = "org.moxxy.moxxyv2/keyboard_stream" const val KEYBOARD_HEIGHT_EVENT_CHANNEL_NAME = "org.moxxy.moxxyv2/notification_stream"
// The event channel name for notification events
const val NOTIFICATION_EVENT_CHANNEL_NAME = "org.moxxy.moxxyv2/notification_stream"
// The size of buffers to use for various operations // The size of buffers to use for various operations
const val BUFFER_SIZE = 4096 const val BUFFER_SIZE = 4096

View File

@ -25,7 +25,6 @@ import org.moxxy.moxxy_native.media.MediaImplementation
import org.moxxy.moxxy_native.media.MoxxyMediaApi import org.moxxy.moxxy_native.media.MoxxyMediaApi
import org.moxxy.moxxy_native.notifications.MoxxyNotificationsApi import org.moxxy.moxxy_native.notifications.MoxxyNotificationsApi
import org.moxxy.moxxy_native.notifications.NotificationEvent import org.moxxy.moxxy_native.notifications.NotificationEvent
import org.moxxy.moxxy_native.notifications.NotificationStreamHandler
import org.moxxy.moxxy_native.notifications.NotificationsImplementation import org.moxxy.moxxy_native.notifications.NotificationsImplementation
import org.moxxy.moxxy_native.picker.FilePickerType import org.moxxy.moxxy_native.picker.FilePickerType
import org.moxxy.moxxy_native.picker.MoxxyPickerApi import org.moxxy.moxxy_native.picker.MoxxyPickerApi
@ -38,6 +37,23 @@ import org.moxxy.moxxy_native.service.MoxxyServiceApi
import org.moxxy.moxxy_native.service.PluginTracker import org.moxxy.moxxy_native.service.PluginTracker
import org.moxxy.moxxy_native.service.ServiceImplementation import org.moxxy.moxxy_native.service.ServiceImplementation
object MoxxyEventChannels {
var notificationChannel: EventChannel? = null
var notificationEventSink: EventChannel.EventSink? = null
}
object NotificationStreamHandler : EventChannel.StreamHandler {
override fun onListen(arguments: Any?, events: EventChannel.EventSink?) {
Log.d(TAG, "NotificationStreamHandler: Attached stream")
MoxxyEventChannels.notificationEventSink = events
}
override fun onCancel(arguments: Any?) {
Log.d(TAG, "NotificationStreamHandler: Detached stream")
MoxxyEventChannels.notificationEventSink = null
}
}
/* /*
* Hold the last notification event in case we did a cold start. * Hold the last notification event in case we did a cold start.
*/ */
@ -91,10 +107,6 @@ class MoxxyNativePlugin : FlutterPlugin, ActivityAware, ServiceAware, BroadcastR
val keyboardChannel = EventChannel(flutterPluginBinding.getBinaryMessenger(), KEYBOARD_HEIGHT_EVENT_CHANNEL_NAME) val keyboardChannel = EventChannel(flutterPluginBinding.getBinaryMessenger(), KEYBOARD_HEIGHT_EVENT_CHANNEL_NAME)
keyboardChannel?.setStreamHandler(KeyboardStreamHandler) keyboardChannel?.setStreamHandler(KeyboardStreamHandler)
// Special handling from notification events
val notificationChannel = EventChannel(flutterPluginBinding.getBinaryMessenger(), NOTIFICATION_EVENT_CHANNEL_NAME)
notificationChannel?.setStreamHandler(NotificationStreamHandler)
// Register the picker handler // Register the picker handler
pickerListener = PickerResultListener(context!!) pickerListener = PickerResultListener(context!!)
Log.d(TAG, "Attached to engine") Log.d(TAG, "Attached to engine")

View File

@ -1,6 +1,8 @@
package org.moxxy.moxxy_native.notifications package org.moxxy.moxxy_native.notifications
import android.content.Intent import android.content.Intent
import android.util.Log
import org.moxxy.moxxy_native.TAG
/* /*
* Extract all user-added extra key-value pairs from @intent. * Extract all user-added extra key-value pairs from @intent.
@ -8,7 +10,9 @@ import android.content.Intent
fun extractPayloadMapFromIntent(intent: Intent): Map<String?, String?> { fun extractPayloadMapFromIntent(intent: Intent): Map<String?, String?> {
val extras = mutableMapOf<String?, String?>() val extras = mutableMapOf<String?, String?>()
intent.extras?.keySet()!!.forEach { intent.extras?.keySet()!!.forEach {
Log.d(TAG, "Checking $it -> ${intent.extras!!.get(it)}")
if (it.startsWith("payload_")) { if (it.startsWith("payload_")) {
Log.d(TAG, "Adding $it")
extras[it.substring(8)] = intent.extras!!.getString(it) extras[it.substring(8)] = intent.extras!!.getString(it)
} }
} }

View File

@ -15,6 +15,7 @@ import androidx.core.app.RemoteInput
import androidx.core.content.FileProvider import androidx.core.content.FileProvider
import org.moxxy.moxxy_native.MARK_AS_READ_ACTION import org.moxxy.moxxy_native.MARK_AS_READ_ACTION
import org.moxxy.moxxy_native.MOXXY_FILEPROVIDER_ID import org.moxxy.moxxy_native.MOXXY_FILEPROVIDER_ID
import org.moxxy.moxxy_native.MoxxyEventChannels
import org.moxxy.moxxy_native.NOTIFICATION_EXTRA_ID_KEY import org.moxxy.moxxy_native.NOTIFICATION_EXTRA_ID_KEY
import org.moxxy.moxxy_native.NOTIFICATION_EXTRA_JID_KEY import org.moxxy.moxxy_native.NOTIFICATION_EXTRA_JID_KEY
import org.moxxy.moxxy_native.NOTIFICATION_MESSAGE_EXTRA_MIME import org.moxxy.moxxy_native.NOTIFICATION_MESSAGE_EXTRA_MIME
@ -49,7 +50,7 @@ class NotificationReceiver : BroadcastReceiver() {
} }
private fun handleMarkAsRead(context: Context, intent: Intent) { private fun handleMarkAsRead(context: Context, intent: Intent) {
NotificationStreamHandler.sink?.success( MoxxyEventChannels.notificationEventSink?.success(
NotificationEvent( NotificationEvent(
intent.getLongExtra(NOTIFICATION_EXTRA_ID_KEY, -1), intent.getLongExtra(NOTIFICATION_EXTRA_ID_KEY, -1),
intent.getStringExtra(NOTIFICATION_EXTRA_JID_KEY)!!, intent.getStringExtra(NOTIFICATION_EXTRA_JID_KEY)!!,
@ -64,7 +65,7 @@ class NotificationReceiver : BroadcastReceiver() {
private fun handleReply(context: Context, intent: Intent) { private fun handleReply(context: Context, intent: Intent) {
val remoteInput = RemoteInput.getResultsFromIntent(intent) ?: return val remoteInput = RemoteInput.getResultsFromIntent(intent) ?: return
val replyPayload = remoteInput.getCharSequence(REPLY_TEXT_KEY) val replyPayload = remoteInput.getCharSequence(REPLY_TEXT_KEY)
NotificationStreamHandler.sink?.success( MoxxyEventChannels.notificationEventSink?.success(
NotificationEvent( NotificationEvent(
intent.getLongExtra(NOTIFICATION_EXTRA_ID_KEY, -1), intent.getLongExtra(NOTIFICATION_EXTRA_ID_KEY, -1),
intent.getStringExtra(NOTIFICATION_EXTRA_JID_KEY)!!, intent.getStringExtra(NOTIFICATION_EXTRA_JID_KEY)!!,
@ -164,7 +165,7 @@ class NotificationReceiver : BroadcastReceiver() {
} }
private fun handleTap(context: Context, intent: Intent) { private fun handleTap(context: Context, intent: Intent) {
NotificationStreamHandler.sink?.success( MoxxyEventChannels.notificationEventSink?.success(
NotificationEvent( NotificationEvent(
intent.getLongExtra(NOTIFICATION_EXTRA_ID_KEY, -1), intent.getLongExtra(NOTIFICATION_EXTRA_ID_KEY, -1),
intent.getStringExtra(NOTIFICATION_EXTRA_JID_KEY)!!, intent.getStringExtra(NOTIFICATION_EXTRA_JID_KEY)!!,

View File

@ -1,22 +0,0 @@
package org.moxxy.moxxy_native.notifications
import android.util.Log
import io.flutter.plugin.common.EventChannel
import org.moxxy.moxxy_native.TAG
object NotificationStreamHandler : EventChannel.StreamHandler {
// The event sink to use for sending notification events to the service.
var sink: EventChannel.EventSink? = null
override fun onListen(arguments: Any?, events: EventChannel.EventSink?) {
// "register" the event sink
sink = events
Log.d(TAG, "NotificationStreamHandler: Attached stream")
}
override fun onCancel(arguments: Any?) {
sink = null
Log.d(TAG, "NotificationStreamHandler: Detached stream")
}
}

View File

@ -94,7 +94,7 @@ class NotificationsImplementation(private val context: Context) : MoxxyNotificat
context.applicationContext, context.applicationContext,
0, 0,
replyIntent, replyIntent,
PendingIntent.FLAG_MUTABLE or PendingIntent.FLAG_UPDATE_CURRENT, PendingIntent.FLAG_MUTABLE,
) )
val replyAction = NotificationCompat.Action.Builder( val replyAction = NotificationCompat.Action.Builder(
R.drawable.reply, R.drawable.reply,
@ -113,14 +113,13 @@ class NotificationsImplementation(private val context: Context) : MoxxyNotificat
notification.extra?.forEach { notification.extra?.forEach {
putExtra("payload_${it.key}", it.value) putExtra("payload_${it.key}", it.value)
Log.d(TAG, "Adding payload_${it.key} -> ${it.value}")
} }
} }
val markAsReadPendingIntent = PendingIntent.getBroadcast( val markAsReadPendingIntent = PendingIntent.getBroadcast(
context.applicationContext, context.applicationContext,
0, 0,
markAsReadIntent, markAsReadIntent,
PendingIntent.FLAG_IMMUTABLE or PendingIntent.FLAG_UPDATE_CURRENT, PendingIntent.FLAG_IMMUTABLE,
) )
val markAsReadAction = NotificationCompat.Action.Builder( val markAsReadAction = NotificationCompat.Action.Builder(
R.drawable.mark_as_read, R.drawable.mark_as_read,
@ -251,7 +250,7 @@ class NotificationsImplementation(private val context: Context) : MoxxyNotificat
setCategory(Notification.CATEGORY_MESSAGE) setCategory(Notification.CATEGORY_MESSAGE)
// Prevent no notification when we replied before // Prevent no notification when we replied before
setOnlyAlertOnce(true) setOnlyAlertOnce(false)
// Automatically dismiss the notification on tap // Automatically dismiss the notification on tap
setAutoCancel(true) setAutoCancel(true)

View File

@ -1,13 +0,0 @@
package org.moxxy.moxxy_native.picker
object MimeUtils {
// A reverse-mapping of image mime types to their commonly used file extension.
val imageMimeTypesToFileExtension = mapOf(
"image/png" to ".png",
"image/apng" to ".apng",
"image/avif" to ".avif",
"image/gif" to ".gif",
"image/jpeg" to ".jpeg",
"image/webp" to ".webp",
)
}

View File

@ -6,7 +6,7 @@ import android.content.Context
import android.content.Intent import android.content.Intent
import android.net.Uri import android.net.Uri
import android.os.Build import android.os.Build
import android.provider.MediaStore.Images import android.provider.OpenableColumns
import android.util.Log import android.util.Log
import io.flutter.plugin.common.PluginRegistry.ActivityResultListener import io.flutter.plugin.common.PluginRegistry.ActivityResultListener
import org.moxxy.moxxy_native.AsyncRequestTracker import org.moxxy.moxxy_native.AsyncRequestTracker
@ -29,22 +29,10 @@ class PickerResultListener(private val context: Context) : ActivityResultListene
private fun queryFileName(context: Context, uri: Uri): String { private fun queryFileName(context: Context, uri: Uri): String {
var result: String? = null var result: String? = null
if (uri.scheme == "content") { if (uri.scheme == "content") {
val projection = arrayOf(
Images.Media._ID,
Images.Media.MIME_TYPE,
Images.Media.DISPLAY_NAME,
)
val cursor = context.contentResolver.query(uri, null, null, null, null) val cursor = context.contentResolver.query(uri, null, null, null, null)
cursor.use { cursor -> cursor.use { cursor ->
if (cursor != null && cursor.moveToFirst()) { if (cursor != null && cursor.moveToFirst()) {
val mimeType = cursor.getString(cursor.getColumnIndex(Images.Media.MIME_TYPE)) result = cursor.getString(cursor.getColumnIndex(OpenableColumns.DISPLAY_NAME))
val displayName = cursor.getString(cursor.getColumnIndex(Images.Media.DISPLAY_NAME))
val fileExtension = MimeUtils.imageMimeTypesToFileExtension[mimeType]
// Note: This is a workaround for the Dart image library failing to parse the file
// because displayName somehow is always ".jpg", which confuses image.
result = if (fileExtension != null) "$displayName$fileExtension" else displayName
Log.d(TAG, "Returning $result as filename (MIME: $mimeType)")
} }
} }
} }

View File

@ -8,6 +8,7 @@ import android.view.ViewTreeObserver
import androidx.core.view.ViewCompat import androidx.core.view.ViewCompat
import androidx.core.view.WindowInsetsCompat import androidx.core.view.WindowInsetsCompat
import io.flutter.plugin.common.EventChannel import io.flutter.plugin.common.EventChannel
import org.moxxy.moxxy_native.MoxxyEventChannels
import org.moxxy.moxxy_native.TAG import org.moxxy.moxxy_native.TAG
object KeyboardStreamHandler : EventChannel.StreamHandler { object KeyboardStreamHandler : EventChannel.StreamHandler {
@ -66,7 +67,7 @@ object KeyboardStreamHandler : EventChannel.StreamHandler {
} }
override fun onCancel(arguments: Any?) { override fun onCancel(arguments: Any?) {
sink = null MoxxyEventChannels.notificationEventSink = null
Log.d(TAG, "KeyboardStreamHandler: Detached stream") Log.d(TAG, "KeyboardStreamHandler: Detached stream")
} }
} }

View File

@ -1,6 +1,6 @@
name: moxxy_native name: moxxy_native
description: Interactions with the system for Moxxy description: Interactions with the system for Moxxy
version: 0.3.1 version: 0.3.0
publish_to: https://git.polynom.me/api/packages/Moxxy/pub publish_to: https://git.polynom.me/api/packages/Moxxy/pub
homepage: homepage: