feat(interface,android): Allow passing an initial locale to the service
This commit is contained in:
parent
81e819b4a7
commit
4167227c7b
@ -114,7 +114,7 @@ public class BackgroundService extends Service implements MethodChannel.MethodCa
|
|||||||
| (PendingIntent.FLAG_MUTABLE & (aboveS ? PendingIntent.FLAG_MUTABLE : 0))
|
| (PendingIntent.FLAG_MUTABLE & (aboveS ? PendingIntent.FLAG_MUTABLE : 0))
|
||||||
);
|
);
|
||||||
|
|
||||||
NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this, "FOREGROUND_DEFAULT")
|
NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this, "foreground_service")
|
||||||
.setSmallIcon(R.drawable.ic_service_icon)
|
.setSmallIcon(R.drawable.ic_service_icon)
|
||||||
.setAutoCancel(true)
|
.setAutoCancel(true)
|
||||||
.setOngoing(true)
|
.setOngoing(true)
|
||||||
|
@ -52,8 +52,9 @@ Future<void> androidEntrypoint() async {
|
|||||||
final srv = AndroidBackgroundService();
|
final srv = AndroidBackgroundService();
|
||||||
GetIt.I.registerSingleton<BackgroundService>(srv);
|
GetIt.I.registerSingleton<BackgroundService>(srv);
|
||||||
srv.init(
|
srv.init(
|
||||||
entrypoint! as Future<void> Function(),
|
entrypoint! as Future<void> Function(String),
|
||||||
handleUIEvent! as Future<void> Function(Map<String, dynamic>? data),
|
handleUIEvent! as Future<void> Function(Map<String, dynamic>? data),
|
||||||
|
data['initialLocale']! as String,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -80,9 +81,10 @@ class AndroidIsolateHandler extends IsolateHandler {
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
Future<void> start(
|
Future<void> start(
|
||||||
Future<void> Function() entrypoint,
|
Future<void> Function(String initialLocale) entrypoint,
|
||||||
Future<void> Function(Map<String, dynamic>? data) handleUIEvent,
|
Future<void> Function(Map<String, dynamic>? data) handleUIEvent,
|
||||||
Future<void> Function(Map<String, dynamic>? data) handleIsolateEvent,
|
Future<void> Function(Map<String, dynamic>? data) handleIsolateEvent,
|
||||||
|
String initialLocale,
|
||||||
) async {
|
) async {
|
||||||
_log.finest('Called start');
|
_log.finest('Called start');
|
||||||
WidgetsFlutterBinding.ensureInitialized();
|
WidgetsFlutterBinding.ensureInitialized();
|
||||||
@ -96,7 +98,8 @@ class AndroidIsolateHandler extends IsolateHandler {
|
|||||||
'genericEntrypoint':
|
'genericEntrypoint':
|
||||||
PluginUtilities.getCallbackHandle(entrypoint)!.toRawHandle(),
|
PluginUtilities.getCallbackHandle(entrypoint)!.toRawHandle(),
|
||||||
'eventHandle':
|
'eventHandle':
|
||||||
PluginUtilities.getCallbackHandle(handleUIEvent)!.toRawHandle()
|
PluginUtilities.getCallbackHandle(handleUIEvent)!.toRawHandle(),
|
||||||
|
'initialLocale': initialLocale,
|
||||||
}),
|
}),
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
@ -24,7 +24,10 @@ class AndroidPlatformImplementation extends PlatformImplementation {
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
Future<bool> generateVideoThumbnail(
|
Future<bool> generateVideoThumbnail(
|
||||||
String src, String dest, int width) async {
|
String src,
|
||||||
|
String dest,
|
||||||
|
int width,
|
||||||
|
) async {
|
||||||
return MoxplatformInterface.api.generateVideoThumbnail(src, dest, width);
|
return MoxplatformInterface.api.generateVideoThumbnail(src, dest, width);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -39,8 +39,9 @@ class AndroidBackgroundService extends BackgroundService {
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
void init(
|
void init(
|
||||||
Future<void> Function() entrypoint,
|
Future<void> Function(String initialLocale) entrypoint,
|
||||||
Future<void> Function(Map<String, dynamic>? data) handleEvent,
|
Future<void> Function(Map<String, dynamic>? data) handleEvent,
|
||||||
|
String initialLocale,
|
||||||
) {
|
) {
|
||||||
WidgetsFlutterBinding.ensureInitialized();
|
WidgetsFlutterBinding.ensureInitialized();
|
||||||
|
|
||||||
@ -58,6 +59,6 @@ class AndroidBackgroundService extends BackgroundService {
|
|||||||
|
|
||||||
_log.finest('Running...');
|
_log.finest('Running...');
|
||||||
|
|
||||||
entrypoint();
|
entrypoint(initialLocale);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -8,10 +8,12 @@ abstract class IsolateHandler {
|
|||||||
/// [entrypoint] is the entrypoint that is run inside the new isolate.
|
/// [entrypoint] is the entrypoint that is run inside the new isolate.
|
||||||
/// [handleUIEvent] is a handler function that is called when the isolate receives data from the UI.
|
/// [handleUIEvent] is a handler function that is called when the isolate receives data from the UI.
|
||||||
/// [handleIsolateEvent] is a handler function that is called when the UI receives data from the service.
|
/// [handleIsolateEvent] is a handler function that is called when the UI receives data from the service.
|
||||||
|
/// [initialLocale] the locale to pass to the background service when first starting.
|
||||||
Future<void> start(
|
Future<void> start(
|
||||||
Future<void> Function() entrypoint,
|
Future<void> Function(String initialLocale) entrypoint,
|
||||||
Future<void> Function(Map<String, dynamic>? data) handleUIEvent,
|
Future<void> Function(Map<String, dynamic>? data) handleUIEvent,
|
||||||
Future<void> Function(Map<String, dynamic>? data) handleIsolateEvent,
|
Future<void> Function(Map<String, dynamic>? data) handleIsolateEvent,
|
||||||
|
String initialLocale,
|
||||||
);
|
);
|
||||||
|
|
||||||
/// Make sure that the UI event handler is registered without starting the isolate.
|
/// Make sure that the UI event handler is registered without starting the isolate.
|
||||||
|
@ -22,9 +22,10 @@ class StubIsolateHandler extends IsolateHandler {
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
Future<void> start(
|
Future<void> start(
|
||||||
Future<void> Function() entrypoint,
|
Future<void> Function(String initialLocale) entrypoint,
|
||||||
Future<void> Function(Map<String, dynamic>? data) handleUIEvent,
|
Future<void> Function(Map<String, dynamic>? data) handleUIEvent,
|
||||||
Future<void> Function(Map<String, dynamic>? data) handleIsolateEvent,
|
Future<void> Function(Map<String, dynamic>? data) handleIsolateEvent,
|
||||||
|
String initialLocale,
|
||||||
) async {
|
) async {
|
||||||
// ignore: avoid_print
|
// ignore: avoid_print
|
||||||
print('STUB STARTED!!!!!!');
|
print('STUB STARTED!!!!!!');
|
||||||
|
@ -17,6 +17,9 @@ class StubPlatformImplementation extends PlatformImplementation {
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
Future<bool> generateVideoThumbnail(
|
Future<bool> generateVideoThumbnail(
|
||||||
String src, String dest, int width) async =>
|
String src,
|
||||||
|
String dest,
|
||||||
|
int width,
|
||||||
|
) async =>
|
||||||
false;
|
false;
|
||||||
}
|
}
|
||||||
|
@ -11,7 +11,8 @@ abstract class BackgroundService {
|
|||||||
/// [handleEvent] is a function that is called whenever the service receives
|
/// [handleEvent] is a function that is called whenever the service receives
|
||||||
/// data.
|
/// data.
|
||||||
void init(
|
void init(
|
||||||
Future<void> Function() entrypoint,
|
Future<void> Function(String initialLocale) entrypoint,
|
||||||
Future<void> Function(Map<String, dynamic>? data) handleEvent,
|
Future<void> Function(Map<String, dynamic>? data) handleEvent,
|
||||||
|
String initialLocale,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user