Skip to content

Commit

Permalink
Formatted (flutter#45)
Browse files Browse the repository at this point in the history
  • Loading branch information
goderbauer committed May 12, 2017
1 parent 2e6a653 commit dc93097
Show file tree
Hide file tree
Showing 55 changed files with 496 additions and 571 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,18 @@

package io.flutter.firebase_analytics;

import java.util.Map;

import com.google.firebase.FirebaseApp;
import com.google.firebase.analytics.FirebaseAnalytics;

import android.app.Activity;
import android.os.Bundle;

import com.google.firebase.FirebaseApp;
import com.google.firebase.analytics.FirebaseAnalytics;
import io.flutter.plugin.common.MethodCall;
import io.flutter.plugin.common.MethodChannel;
import io.flutter.plugin.common.MethodChannel.MethodCallHandler;
import io.flutter.plugin.common.MethodChannel.Result;
import io.flutter.plugin.common.MethodCall;
import io.flutter.plugin.common.PluginRegistry;
import java.util.Map;

/**
* Flutter plugin for Firebase Analytics.
*/
/** Flutter plugin for Firebase Analytics. */
public class FirebaseAnalyticsPlugin implements MethodCallHandler {
private final Activity activity;
private final FirebaseAnalytics firebaseAnalytics;
Expand Down Expand Up @@ -72,7 +67,8 @@ private void handleLogEvent(MethodCall call, Result result) {
final String eventName = (String) arguments.get("name");

@SuppressWarnings("unchecked")
final Bundle parameterBundle = createBundleFromMap((Map<String, Object>) arguments.get("parameters"));
final Bundle parameterBundle =
createBundleFromMap((Map<String, Object>) arguments.get("parameters"));
firebaseAnalytics.logEvent(eventName, parameterBundle);
result.success(null);
}
Expand Down Expand Up @@ -139,7 +135,8 @@ private static Bundle createBundleFromMap(Map<String, Object> map) {
} else if (value instanceof Boolean) {
bundle.putBoolean(key, (Boolean) value);
} else {
throw new IllegalArgumentException("Unsupported value type: " + value.getClass().getCanonicalName());
throw new IllegalArgumentException(
"Unsupported value type: " + value.getClass().getCanonicalName());
}
}
return bundle;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
import io.flutter.plugins.GeneratedPluginRegistrant;

public class MainActivity extends FlutterActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
GeneratedPluginRegistrant.registerWith(this);
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
GeneratedPluginRegistrant.registerWith(this);
}
}
2 changes: 1 addition & 1 deletion packages/firebase_analytics/example/ios/Runner/AppDelegate.h
100755 → 100644
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#import <UIKit/UIKit.h>
#import <Flutter/Flutter.h>
#import <UIKit/UIKit.h>

@interface AppDelegate : FlutterAppDelegate

Expand Down
11 changes: 5 additions & 6 deletions packages/firebase_analytics/example/ios/Runner/main.m
100755 → 100644
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
#import <UIKit/UIKit.h>
#import <Flutter/Flutter.h>
#import <UIKit/UIKit.h>
#import "AppDelegate.h"

int main(int argc, char * argv[]) {
@autoreleasepool {
return UIApplicationMain(argc, argv, nil,
NSStringFromClass([AppDelegate class]));
}
int main(int argc, char* argv[]) {
@autoreleasepool {
return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class]));
}
}
10 changes: 4 additions & 6 deletions packages/firebase_analytics/ios/Classes/FirebaseAnalyticsPlugin.m
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ @implementation FirebaseAnalyticsPlugin {

+ (void)registerWithRegistrar:(NSObject<FlutterPluginRegistrar> *)registrar {
FlutterMethodChannel *channel =
[FlutterMethodChannel methodChannelWithName:@"firebase_analytics"
binaryMessenger:[registrar messenger]];
[FlutterMethodChannel methodChannelWithName:@"firebase_analytics"
binaryMessenger:[registrar messenger]];
FirebaseAnalyticsPlugin *instance = [[FirebaseAnalyticsPlugin alloc] init];
[registrar addMethodCallDelegate:instance channel:channel];
}
Expand All @@ -33,11 +33,9 @@ - (void)handleMethodCall:(FlutterMethodCall *)call result:(FlutterResult)result
id parameterMap = call.arguments[@"parameters"];

if (parameterMap != [NSNull null]) {
[FIRAnalytics logEventWithName:eventName
parameters:parameterMap];
[FIRAnalytics logEventWithName:eventName parameters:parameterMap];
} else {
[FIRAnalytics logEventWithName:eventName
parameters:nil];
[FIRAnalytics logEventWithName:eventName parameters:nil];
}

result(nil);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,37 +6,31 @@

import android.app.Activity;
import android.support.annotation.NonNull;

import com.google.android.gms.tasks.Task;
import com.google.android.gms.tasks.OnCompleteListener;
import com.google.android.gms.tasks.Task;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import com.google.firebase.FirebaseApp;
import com.google.firebase.auth.AuthCredential;
import com.google.firebase.auth.AuthResult;
import com.google.firebase.auth.FirebaseAuth;
import com.google.firebase.auth.AuthCredential;
import com.google.firebase.auth.GoogleAuthProvider;
import com.google.firebase.auth.FirebaseUser;
import com.google.firebase.auth.GoogleAuthProvider;
import com.google.firebase.auth.UserInfo;

import io.flutter.plugin.common.MethodCall;
import io.flutter.plugin.common.MethodChannel;
import io.flutter.plugin.common.MethodChannel.MethodCallHandler;
import io.flutter.plugin.common.MethodChannel.Result;
import io.flutter.plugin.common.MethodCall;
import io.flutter.plugin.common.PluginRegistry;

import java.util.Map;

/**
* Flutter plugin for Firebase Auth.
*/
/** Flutter plugin for Firebase Auth. */
public class FirebaseAuthPlugin implements MethodCallHandler {
private final Activity activity;
private final FirebaseAuth firebaseAuth;

private static final String ERROR_REASON_EXCEPTION = "exception";


public static void registerWith(PluginRegistry.Registrar registrar) {
final MethodChannel channel =
new MethodChannel(registrar.messenger(), "plugins.flutter.io/firebase_auth");
Expand Down Expand Up @@ -66,8 +60,8 @@ public void onMethodCall(MethodCall call, Result result) {

private void handleSignInAnonymously(MethodCall call, final Result result) {
firebaseAuth
.signInAnonymously()
.addOnCompleteListener(activity, new SignInCompleteListener(result));
.signInAnonymously()
.addOnCompleteListener(activity, new SignInCompleteListener(result));
}

private void handleSignInWithGoogle(MethodCall call, final Result result) {
Expand All @@ -76,8 +70,9 @@ private void handleSignInWithGoogle(MethodCall call, final Result result) {
String idToken = arguments.get("idToken");
String accessToken = arguments.get("accessToken");
AuthCredential credential = GoogleAuthProvider.getCredential(idToken, accessToken);
firebaseAuth.signInWithCredential(credential)
.addOnCompleteListener(activity, new SignInCompleteListener(result));
firebaseAuth
.signInWithCredential(credential)
.addOnCompleteListener(activity, new SignInCompleteListener(result));
}

private class SignInCompleteListener implements OnCompleteListener<AuthResult> {
Expand Down Expand Up @@ -117,11 +112,12 @@ public void onComplete(@NonNull Task<AuthResult> task) {
for (UserInfo userInfo : user.getProviderData()) {
providerDataBuilder.add(userInfoToMap(userInfo).build());
}
ImmutableMap<String, Object> userMap = userInfoToMap(user)
.put("isAnonymous", user.isAnonymous())
.put("isEmailVerified", user.isEmailVerified())
.put("providerData", providerDataBuilder.build())
.build();
ImmutableMap<String, Object> userMap =
userInfoToMap(user)
.put("isAnonymous", user.isAnonymous())
.put("isEmailVerified", user.isEmailVerified())
.put("providerData", providerDataBuilder.build())
.build();
result.success(userMap);
} else {
result.success(null);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
import io.flutter.plugins.GeneratedPluginRegistrant;

public class MainActivity extends FlutterActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
GeneratedPluginRegistrant.registerWith(this);
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
GeneratedPluginRegistrant.registerWith(this);
}
}
2 changes: 1 addition & 1 deletion packages/firebase_auth/example/ios/Runner/AppDelegate.h
100755 → 100644
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#import <UIKit/UIKit.h>
#import <Flutter/Flutter.h>
#import <UIKit/UIKit.h>

@interface AppDelegate : FlutterAppDelegate

Expand Down
2 changes: 1 addition & 1 deletion packages/firebase_auth/example/ios/Runner/AppDelegate.m
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
@implementation AppDelegate

- (BOOL)application:(UIApplication *)application
didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
[GeneratedPluginRegistrant registerWithRegistry:self];
return [super application:application didFinishLaunchingWithOptions:launchOptions];
}
Expand Down
11 changes: 5 additions & 6 deletions packages/firebase_auth/example/ios/Runner/main.m
100755 → 100644
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
#import <UIKit/UIKit.h>
#import <Flutter/Flutter.h>
#import <UIKit/UIKit.h>
#import "AppDelegate.h"

int main(int argc, char * argv[]) {
@autoreleasepool {
return UIApplicationMain(argc, argv, nil,
NSStringFromClass([AppDelegate class]));
}
int main(int argc, char* argv[]) {
@autoreleasepool {
return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class]));
}
}
36 changes: 13 additions & 23 deletions packages/firebase_auth/ios/Classes/FirebaseAuthPlugin.m
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,9 @@ @interface NSError (FlutterError)

@implementation NSError (FlutterError)
- (FlutterError *)flutterError {
return [FlutterError
errorWithCode:[NSString stringWithFormat:@"Error %d", (int)self.code]
message:self.domain
details:self.localizedDescription];
return [FlutterError errorWithCode:[NSString stringWithFormat:@"Error %d", (int)self.code]
message:self.domain
details:self.localizedDescription];
}
@end

Expand All @@ -30,14 +29,12 @@ @implementation FirebaseAuthPlugin {

+ (void)registerWithRegistrar:(NSObject<FlutterPluginRegistrar> *)registrar {
FlutterMethodChannel *channel =
[FlutterMethodChannel methodChannelWithName:@"plugins.flutter.io/firebase_auth"
binaryMessenger:[registrar messenger]];
[FlutterMethodChannel methodChannelWithName:@"plugins.flutter.io/firebase_auth"
binaryMessenger:[registrar messenger]];
FirebaseAuthPlugin *instance = [[FirebaseAuthPlugin alloc] init];
[registrar addMethodCallDelegate:instance channel:channel];
}



- (instancetype)init {
self = [super init];
if (self) {
Expand All @@ -48,32 +45,26 @@ - (instancetype)init {
return self;
}


- (void)handleMethodCall:(FlutterMethodCall *)call result:(FlutterResult)result {
if ([@"signInAnonymously" isEqualToString:call.method]) {
[[FIRAuth auth] signInAnonymouslyWithCompletion:^(FIRUser *user,
NSError *error) {
[[FIRAuth auth] signInAnonymouslyWithCompletion:^(FIRUser *user, NSError *error) {
[self sendResult:result forUser:user error:error];
}];
} else if ([@"signInWithGoogle" isEqualToString:call.method]) {
NSString *idToken = call.arguments[@"idToken"];
NSString *accessToken = call.arguments[@"accessToken"];
FIRAuthCredential *credential =
[FIRGoogleAuthProvider credentialWithIDToken:idToken
accessToken:accessToken];
[[FIRAuth auth]
signInWithCredential:credential
completion:^(FIRUser *user, NSError *error) {
[self sendResult:result forUser:user error:error];
}];
[FIRGoogleAuthProvider credentialWithIDToken:idToken accessToken:accessToken];
[[FIRAuth auth] signInWithCredential:credential
completion:^(FIRUser *user, NSError *error) {
[self sendResult:result forUser:user error:error];
}];
} else {
result(FlutterMethodNotImplemented);
}
}

- (void)sendResult:(FlutterResult)result
forUser:(FIRUser *)user
error:(NSError *)error {
- (void)sendResult:(FlutterResult)result forUser:(FIRUser *)user error:(NSError *)error {
if (error != nil) {
result(error.flutterError);
} else if (user == nil) {
Expand All @@ -86,8 +77,7 @@ - (void)sendResult:(FlutterResult)result
}
NSMutableDictionary *userData = [toDictionary(user) mutableCopy];
userData[@"isAnonymous"] = [NSNumber numberWithBool:user.isAnonymous];
userData[@"isEmailVerified"] =
[NSNumber numberWithBool:user.isEmailVerified];
userData[@"isEmailVerified"] = [NSNumber numberWithBool:user.isEmailVerified];
userData[@"providerData"] = providerData;
result(userData);
}
Expand Down
Loading

0 comments on commit dc93097

Please sign in to comment.