feat: Move recordSentMessage to pigeon
This commit is contained in:
@@ -93,6 +93,18 @@ public class Api {
|
||||
}
|
||||
}
|
||||
|
||||
public enum FallbackIconType {
|
||||
NONE(0),
|
||||
PERSON(1),
|
||||
NOTES(2);
|
||||
|
||||
final int index;
|
||||
|
||||
private FallbackIconType(final int index) {
|
||||
this.index = index;
|
||||
}
|
||||
}
|
||||
|
||||
/** Generated class from Pigeon that represents data sent in messages. */
|
||||
public static final class NotificationMessageContent {
|
||||
/** The textual body of the message. */
|
||||
@@ -1072,6 +1084,8 @@ public class Api {
|
||||
|
||||
@NonNull
|
||||
String getCacheDataPath();
|
||||
/** Contacts APIs */
|
||||
void recordSentMessage(@NonNull String name, @NonNull String jid, @Nullable String avatarPath, @NonNull FallbackIconType fallbackIcon);
|
||||
/** Cryptography APIs */
|
||||
void encryptFile(@NonNull String sourcePath, @NonNull String destPath, @NonNull byte[] key, @NonNull byte[] iv, @NonNull CipherAlgorithm algorithm, @NonNull String hashSpec, @NonNull Result<CryptographyResult> result);
|
||||
|
||||
@@ -1268,6 +1282,33 @@ public class Api {
|
||||
String output = api.getCacheDataPath();
|
||||
wrapped.add(0, output);
|
||||
}
|
||||
catch (Throwable exception) {
|
||||
ArrayList<Object> wrappedError = wrapError(exception);
|
||||
wrapped = wrappedError;
|
||||
}
|
||||
reply.reply(wrapped);
|
||||
});
|
||||
} else {
|
||||
channel.setMessageHandler(null);
|
||||
}
|
||||
}
|
||||
{
|
||||
BasicMessageChannel<Object> channel =
|
||||
new BasicMessageChannel<>(
|
||||
binaryMessenger, "dev.flutter.pigeon.moxplatform_platform_interface.MoxplatformApi.recordSentMessage", getCodec());
|
||||
if (api != null) {
|
||||
channel.setMessageHandler(
|
||||
(message, reply) -> {
|
||||
ArrayList<Object> wrapped = new ArrayList<Object>();
|
||||
ArrayList<Object> args = (ArrayList<Object>) message;
|
||||
String nameArg = (String) args.get(0);
|
||||
String jidArg = (String) args.get(1);
|
||||
String avatarPathArg = (String) args.get(2);
|
||||
FallbackIconType fallbackIconArg = args.get(3) == null ? null : FallbackIconType.values()[(int) args.get(3)];
|
||||
try {
|
||||
api.recordSentMessage(nameArg, jidArg, avatarPathArg, fallbackIconArg);
|
||||
wrapped.add(0, null);
|
||||
}
|
||||
catch (Throwable exception) {
|
||||
ArrayList<Object> wrappedError = wrapError(exception);
|
||||
wrapped = wrappedError;
|
||||
|
||||
@@ -18,6 +18,7 @@ import android.content.SharedPreferences;
|
||||
import android.util.Log;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.core.app.NotificationManagerCompat;
|
||||
import androidx.core.content.ContextCompat;
|
||||
import androidx.localbroadcastmanager.content.LocalBroadcastManager;
|
||||
@@ -166,11 +167,6 @@ public class MoxplatformAndroidPlugin extends BroadcastReceiver implements Flutt
|
||||
}
|
||||
result.success(true);
|
||||
break;
|
||||
case "recordSentMessage":
|
||||
ArrayList rargs = (ArrayList) call.arguments;
|
||||
recordSentMessage(context, (String) rargs.get(0), (String) rargs.get(1), (String) rargs.get(2), (int) rargs.get(3));
|
||||
result.success(true);
|
||||
break;
|
||||
default:
|
||||
result.notImplemented();
|
||||
break;
|
||||
@@ -261,6 +257,11 @@ public class MoxplatformAndroidPlugin extends BroadcastReceiver implements Flutt
|
||||
return context.getCacheDir().getPath();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void recordSentMessage(@NonNull String name, @NonNull String jid, @Nullable String avatarPath, @NonNull FallbackIconType fallbackIcon) {
|
||||
systemRecordSentMessage(context, name, jid, avatarPath, fallbackIcon);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void encryptFile(@NonNull String sourcePath, @NonNull String destPath, @NonNull byte[] key, @NonNull byte[] iv, @NonNull CipherAlgorithm algorithm, @NonNull String hashSpec, @NonNull Api.Result<CryptographyResult> result) {
|
||||
CryptoKt.encryptAndHash(
|
||||
|
||||
@@ -7,12 +7,15 @@ import androidx.core.app.Person
|
||||
import androidx.core.content.pm.ShortcutInfoCompat
|
||||
import androidx.core.content.pm.ShortcutManagerCompat
|
||||
import androidx.core.graphics.drawable.IconCompat
|
||||
import me.polynom.moxplatform_android.Api.FallbackIconType
|
||||
|
||||
/*
|
||||
* Uses Android's direct share API to create dynamic share targets that are compatible
|
||||
* with share_handler's media handling.
|
||||
* NOTE: The "system" prefix is to prevent confusion between pigeon's abstract recordSentMessage
|
||||
* method and this one.
|
||||
* */
|
||||
fun recordSentMessage(context: Context, name: String, jid: String, avatarPath: String?, fallbackIconType: Int) {
|
||||
fun systemRecordSentMessage(context: Context, name: String, jid: String, avatarPath: String?, fallbackIcon: FallbackIconType) {
|
||||
val pkgName = context.packageName
|
||||
val intent = Intent(context, Class.forName("$pkgName.MainActivity")).apply {
|
||||
action = Intent.ACTION_SEND
|
||||
@@ -43,9 +46,9 @@ fun recordSentMessage(context: Context, name: String, jid: String, avatarPath: S
|
||||
shortcutBuilder.setIcon(icon)
|
||||
personBuilder.setIcon(icon)
|
||||
} else {
|
||||
val resourceId = when(fallbackIconType) {
|
||||
0 -> R.mipmap.person
|
||||
1 -> R.mipmap.notes
|
||||
val resourceId = when(fallbackIcon) {
|
||||
FallbackIconType.PERSON -> R.mipmap.person
|
||||
FallbackIconType.NOTES -> R.mipmap.notes
|
||||
// "Fallthrough"
|
||||
else -> R.mipmap.person
|
||||
}
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:moxplatform_platform_interface/moxplatform_platform_interface.dart';
|
||||
import 'package:moxplatform_platform_interface/src/api.g.dart';
|
||||
|
||||
class AndroidContactsImplementation extends ContactsImplementation {
|
||||
final _methodChannel = const MethodChannel('me.polynom.moxplatform_android');
|
||||
final MoxplatformApi _api = MoxplatformApi();
|
||||
|
||||
@override
|
||||
Future<void> recordSentMessage(
|
||||
@@ -19,14 +19,11 @@ class AndroidContactsImplementation extends ContactsImplementation {
|
||||
);
|
||||
}
|
||||
|
||||
await _methodChannel.invokeMethod<void>(
|
||||
'recordSentMessage',
|
||||
[
|
||||
name,
|
||||
jid,
|
||||
avatarPath,
|
||||
fallbackIcon.id,
|
||||
],
|
||||
return _api.recordSentMessage(
|
||||
name,
|
||||
jid,
|
||||
avatarPath,
|
||||
fallbackIcon,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user