Skip to content

Commit

Permalink
chore: run format
Browse files Browse the repository at this point in the history
  • Loading branch information
pr-Mais committed Dec 2, 2021
1 parent 4d65e23 commit fdd2d21
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 71 deletions.
@@ -1,19 +1,12 @@
package io.flutter.plugins.firebase.installations.firebase_installations;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import com.google.android.gms.tasks.Task;
import com.google.android.gms.tasks.Tasks;
import com.google.firebase.FirebaseApp;
import com.google.firebase.installations.FirebaseInstallations;
import com.google.firebase.installations.InstallationTokenResult;
import com.google.firebase.installations.internal.FidListener;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import java.util.HashMap;
import java.util.Map;
import java.util.Objects;

import io.flutter.embedding.engine.plugins.FlutterPlugin;
import io.flutter.plugin.common.BinaryMessenger;
import io.flutter.plugin.common.EventChannel;
Expand All @@ -23,27 +16,26 @@
import io.flutter.plugin.common.MethodChannel.Result;
import io.flutter.plugins.firebase.core.FlutterFirebasePlugin;
import io.flutter.plugins.firebase.core.FlutterFirebasePluginRegistry;
import java.util.HashMap;
import java.util.Map;
import java.util.Objects;

/**
* FirebaseInstallationsPlugin
*/
public class FirebaseInstallationsPlugin implements FlutterFirebasePlugin, FlutterPlugin, MethodCallHandler {
/** FirebaseInstallationsPlugin */
public class FirebaseInstallationsPlugin
implements FlutterFirebasePlugin, FlutterPlugin, MethodCallHandler {
private MethodChannel channel;
private static final String METHOD_CHANNEL_NAME = "plugins.flutter.io/firebase_installations";
private final Map<EventChannel, EventChannel.StreamHandler> streamHandlers = new HashMap<>();

@Nullable
private BinaryMessenger messenger;
@Nullable private BinaryMessenger messenger;

private MethodChannel setup(BinaryMessenger binaryMessenger) {
final MethodChannel channel =
new MethodChannel(binaryMessenger, METHOD_CHANNEL_NAME);
final MethodChannel channel = new MethodChannel(binaryMessenger, METHOD_CHANNEL_NAME);
channel.setMethodCallHandler(this);
this.messenger = binaryMessenger;
return channel;
}


@Override
public void onAttachedToEngine(@NonNull FlutterPluginBinding flutterPluginBinding) {
BinaryMessenger binaryMessenger = flutterPluginBinding.getBinaryMessenger();
Expand All @@ -59,7 +51,6 @@ public void onDetachedFromEngine(@NonNull FlutterPluginBinding binding) {
messenger = null;

removeEventListeners();

}

private FirebaseInstallations getInstallations(Map<String, Object> arguments) {
Expand All @@ -74,31 +65,32 @@ private Task<String> getId(Map<String, Object> arguments) {

private Task<String> getToken(Map<String, Object> arguments) {
return Tasks.call(
cachedThreadPool,
() -> {
FirebaseInstallations firebaseInstallations = getInstallations(arguments);
Boolean forceRefresh = (Boolean) Objects.requireNonNull(arguments.get("forceRefresh"));
InstallationTokenResult tokenResult = Tasks.await(firebaseInstallations.getToken(forceRefresh));
return tokenResult.getToken();
});
cachedThreadPool,
() -> {
FirebaseInstallations firebaseInstallations = getInstallations(arguments);
Boolean forceRefresh = (Boolean) Objects.requireNonNull(arguments.get("forceRefresh"));
InstallationTokenResult tokenResult =
Tasks.await(firebaseInstallations.getToken(forceRefresh));
return tokenResult.getToken();
});
}

private Task<String> registerTokenListener(Map<String, Object> arguments) {
return Tasks.call(
cachedThreadPool,
() -> {
String appName = (String) Objects.requireNonNull(arguments.get("appName"));
FirebaseInstallations firebaseInstallations = getInstallations(arguments);
cachedThreadPool,
() -> {
String appName = (String) Objects.requireNonNull(arguments.get("appName"));
FirebaseInstallations firebaseInstallations = getInstallations(arguments);

TokenChannelStreamHandler handler = new TokenChannelStreamHandler(firebaseInstallations);
TokenChannelStreamHandler handler = new TokenChannelStreamHandler(firebaseInstallations);

final String name = METHOD_CHANNEL_NAME + "/token/" + appName;
final EventChannel channel = new EventChannel(messenger, name);
channel.setStreamHandler(handler);
streamHandlers.put(channel, handler);
final String name = METHOD_CHANNEL_NAME + "/token/" + appName;
final EventChannel channel = new EventChannel(messenger, name);
channel.setStreamHandler(handler);
streamHandlers.put(channel, handler);

return name;
});
return name;
});
}

private Task<Void> deleteId(Map<String, Object> arguments) {
Expand Down Expand Up @@ -126,21 +118,20 @@ public void onMethodCall(@NonNull MethodCall call, @NonNull Result result) {
default:
result.notImplemented();
return;

}

methodCallTask.addOnCompleteListener(
task -> {
if (task.isSuccessful()) {
result.success(task.getResult());
} else {
Exception exception = task.getException();
result.error(
"firebase_installations",
exception != null ? exception.getMessage() : null,
getExceptionDetails(exception));
}
});
task -> {
if (task.isSuccessful()) {
result.success(task.getResult());
} else {
Exception exception = task.getException();
result.error(
"firebase_installations",
exception != null ? exception.getMessage() : null,
getExceptionDetails(exception));
}
});
}

private Map<String, Object> getExceptionDetails(@Nullable Exception exception) {
Expand All @@ -154,7 +145,6 @@ private Map<String, Object> getExceptionDetails(@Nullable Exception exception) {
return details;
}


@Override
public Task<Map<String, Object>> getPluginConstantsForFirebaseApp(FirebaseApp firebaseApp) {
return Tasks.call(cachedThreadPool, () -> null);
Expand Down
Expand Up @@ -3,6 +3,7 @@
// found in the LICENSE file.

package io.flutter.plugins.firebase.installations.firebase_installations;

import androidx.annotation.Keep;
import com.google.firebase.components.Component;
import com.google.firebase.components.ComponentRegistrar;
Expand All @@ -15,6 +16,6 @@ public class FlutterFirebaseAppRegistrar implements ComponentRegistrar {
@Override
public List<Component<?>> getComponents() {
return Collections.<Component<?>>singletonList(
LibraryVersionComponent.create(BuildConfig.LIBRARY_NAME, BuildConfig.LIBRARY_VERSION));
LibraryVersionComponent.create(BuildConfig.LIBRARY_NAME, BuildConfig.LIBRARY_VERSION));
}
}
@@ -1,16 +1,12 @@
package io.flutter.plugins.firebase.installations.firebase_installations;

import androidx.annotation.NonNull;

import com.google.firebase.installations.FirebaseInstallations;
import com.google.firebase.installations.internal.FidListener;

import io.flutter.plugin.common.EventChannel;
import java.util.HashMap;
import java.util.Map;

import io.flutter.Log;
import io.flutter.plugin.common.EventChannel;

public class TokenChannelStreamHandler implements EventChannel.StreamHandler {

private final FirebaseInstallations firebaseInstallations;
Expand All @@ -25,7 +21,6 @@ public void onListen(Object arguments, EventChannel.EventSink events) {

listener = createTokenEventListener(events);


firebaseInstallations.registerFidListener(listener);
}

Expand All @@ -40,7 +35,7 @@ FidListener createTokenEventListener(final EventChannel.EventSink events) {
return token -> {
Map<String, Object> event = new HashMap<>();

event.put("token" , token);
event.put("token", token);

events.success(event);
};
Expand Down
@@ -1,5 +1,5 @@
#import <Flutter/Flutter.h>
#import <firebase_core/FLTFirebasePlugin.h>

@interface FirebaseInstallationsPlugin : FLTFirebasePlugin<FlutterPlugin, FLTFirebasePlugin>
@interface FirebaseInstallationsPlugin : FLTFirebasePlugin <FlutterPlugin, FLTFirebasePlugin>
@end
Expand Up @@ -13,25 +13,24 @@ + (void)registerWithRegistrar:(NSObject<FlutterPluginRegistrar>*)registrar {
[SwiftFirebaseInstallationsPlugin registerWithRegistrar:registrar];
}

- (void)didReinitializeFirebaseCore:(void (^ _Nonnull)(void))completion {
completion();
- (void)didReinitializeFirebaseCore:(void (^_Nonnull)(void))completion {
completion();
}

- (NSString * _Nonnull)firebaseLibraryName {
return LIBRARY_NAME;
- (NSString* _Nonnull)firebaseLibraryName {
return LIBRARY_NAME;
}

- (NSString * _Nonnull)firebaseLibraryVersion {
return LIBRARY_VERSION;
- (NSString* _Nonnull)firebaseLibraryVersion {
return LIBRARY_VERSION;
}

- (NSString * _Nonnull)flutterChannelName {
return @"plugins.flutter.io/firebase_installations";
- (NSString* _Nonnull)flutterChannelName {
return @"plugins.flutter.io/firebase_installations";
}

- (NSDictionary * _Nonnull)pluginConstantsForFIRApp:(FIRApp * _Nonnull)firebaseApp {
return @{};
- (NSDictionary* _Nonnull)pluginConstantsForFIRApp:(FIRApp* _Nonnull)firebaseApp {
return @{};
}

@end

Expand Up @@ -180,7 +180,7 @@ - (void)messaging:(nonnull FIRMessaging *)messaging
if ([[GULAppDelegateSwizzler sharedApplication].delegate
respondsToSelector:messaging_didReceiveRegistrationTokenSelector]) {
void (*usersDidReceiveRegistrationTokenIMP)(id, SEL, FIRMessaging *, NSString *) =
(typeof(usersDidReceiveRegistrationTokenIMP)) & objc_msgSend;
(typeof(usersDidReceiveRegistrationTokenIMP))&objc_msgSend;
usersDidReceiveRegistrationTokenIMP([GULAppDelegateSwizzler sharedApplication].delegate,
messaging_didReceiveRegistrationTokenSelector, messaging,
fcmToken);
Expand Down

0 comments on commit fdd2d21

Please sign in to comment.