Skip to content

Commit

Permalink
Upgrade in-app-messaging to plugin api v2 (firebase#1369)
Browse files Browse the repository at this point in the history
* Upgraded in-app-messaging to plugins api v2.
  • Loading branch information
gaaclarke authored and kroikie committed Nov 25, 2019
1 parent 8e91abe commit b55faff
Show file tree
Hide file tree
Showing 16 changed files with 151 additions and 55 deletions.
4 changes: 4 additions & 0 deletions packages/firebase_in_app_messaging/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 0.1.1

* Updated the plugin API to v2.

## 0.1.0

* Updated README instructions for contributing for consistency with other Flutterfire plugins.
Expand Down
30 changes: 30 additions & 0 deletions packages/firebase_in_app_messaging/android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,33 @@ android {
api 'com.google.firebase:firebase-inappmessaging-display:18.0.2'
}
}

dependencies {
implementation 'com.android.support:support-annotations:28.0.0'
}

// TODO(<github-username>): Remove this hack once androidx.lifecycle is included on stable. https://github.com/flutter/flutter/issues/42348
afterEvaluate {
def containsEmbeddingDependencies = false
for (def configuration : configurations.all) {
for (def dependency : configuration.dependencies) {
if (dependency.group == 'io.flutter' &&
dependency.name.startsWith('flutter_embedding') &&
dependency.isTransitive())
{
containsEmbeddingDependencies = true
break
}
}
}
if (!containsEmbeddingDependencies) {
android {
dependencies {
def lifecycle_version = "1.1.1"
compileOnly "android.arch.lifecycle:runtime:$lifecycle_version"
compileOnly "android.arch.lifecycle:common:$lifecycle_version"
compileOnly "android.arch.lifecycle:common-java8:$lifecycle_version"
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
org.gradle.jvmargs=-Xmx1536M

android.enableR8=true
Original file line number Diff line number Diff line change
Expand Up @@ -5,26 +5,48 @@
package com.example.firebase_in_app_messaging;

import com.google.firebase.inappmessaging.FirebaseInAppMessaging;
import io.flutter.embedding.engine.plugins.FlutterPlugin;
import io.flutter.plugin.common.BinaryMessenger;
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.PluginRegistry.Registrar;

/** FirebaseInAppMessagingPlugin */
public class FirebaseInAppMessagingPlugin implements MethodCallHandler {
public class FirebaseInAppMessagingPlugin implements FlutterPlugin, MethodCallHandler {
private final FirebaseInAppMessaging instance;
private MethodChannel channel;

public static void registerWith(Registrar registrar) {
private static MethodChannel setup(BinaryMessenger binaryMessenger) {
final MethodChannel channel =
new MethodChannel(registrar.messenger(), "plugins.flutter.io/firebase_in_app_messaging");
new MethodChannel(binaryMessenger, "plugins.flutter.io/firebase_in_app_messaging");
channel.setMethodCallHandler(new FirebaseInAppMessagingPlugin());
return channel;
}

public static void registerWith(Registrar registrar) {
setup(registrar.messenger());
}

private FirebaseInAppMessagingPlugin() {
public FirebaseInAppMessagingPlugin() {
instance = FirebaseInAppMessaging.getInstance();
}

@Override
public void onAttachedToEngine(FlutterPluginBinding binding) {
BinaryMessenger binaryMessenger = binding.getFlutterEngine().getDartExecutor();
channel = setup(binaryMessenger);
}

@Override
public void onDetachedFromEngine(FlutterPluginBinding binding) {
if (channel != null) {
channel.setMethodCallHandler(null);
channel = null;
}
}

@Override
public void onMethodCall(MethodCall call, Result result) {
switch (call.method) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ android {
targetSdkVersion 28
versionCode flutterVersionCode.toInteger()
versionName flutterVersionName
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
multiDexEnabled true
}

Expand All @@ -55,6 +55,7 @@ flutter {
}

dependencies {
androidTestImplementation 'androidx.test:rules:1.2.0'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test:runner:1.2.0'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.example.firebase_in_app_messaging;

import androidx.test.rule.ActivityTestRule;
import com.example.firebase_in_app_messaging_example.EmbeddingV1Activity;
import dev.flutter.plugins.e2e.FlutterRunner;
import org.junit.Rule;
import org.junit.runner.RunWith;

@RunWith(FlutterRunner.class)
public class EmbeddingV1ActivityTest {
@Rule
public ActivityTestRule<EmbeddingV1Activity> rule =
new ActivityTestRule<>(EmbeddingV1Activity.class);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.example.firebase_in_app_messaging;

import androidx.test.rule.ActivityTestRule;
import com.example.firebase_in_app_messaging_example.MainActivity;
import dev.flutter.plugins.e2e.FlutterRunner;
import org.junit.Rule;
import org.junit.runner.RunWith;

@RunWith(FlutterRunner.class)
public class MainActivityTest {
@Rule public ActivityTestRule<MainActivity> rule = new ActivityTestRule<>(MainActivity.class);
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,13 @@
android:name="io.flutter.app.FlutterApplication"
android:label="firebase_in_app_messaging_example"
android:icon="@mipmap/ic_launcher">
<activity
android:name=".EmbeddingV1Activity"
android:theme="@style/LaunchTheme"
android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale|layoutDirection|fontScale"
android:hardwareAccelerated="true"
android:windowSoftInputMode="adjustResize">
</activity>
<activity
android:name=".MainActivity"
android:launchMode="singleTop"
Expand All @@ -21,9 +28,6 @@
until Flutter renders its first frame. It can be removed if
there is no splash screen (such as the default splash screen
defined in @style/LaunchTheme). -->
<meta-data
android:name="io.flutter.app.android.SplashScreenUntilFirstFrame"
android:value="true" />
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.example.firebase_in_app_messaging_example;

import android.os.Bundle;
import io.flutter.app.FlutterActivity;
import io.flutter.plugins.GeneratedPluginRegistrant;

public class EmbeddingV1Activity extends FlutterActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
GeneratedPluginRegistrant.registerWith(this);
}
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,22 @@
package com.example.firebase_in_app_messaging_example;

import android.os.Bundle;
import io.flutter.app.FlutterActivity;
import io.flutter.plugins.GeneratedPluginRegistrant;
import com.example.firebase_in_app_messaging.FirebaseInAppMessagingPlugin;
import dev.flutter.plugins.e2e.E2EPlugin;
import io.flutter.embedding.android.FlutterActivity;
import io.flutter.embedding.engine.FlutterEngine;
import io.flutter.embedding.engine.plugins.shim.ShimPluginRegistry;
import io.flutter.plugins.firebaseanalytics.FirebaseAnalyticsPlugin;

public class MainActivity extends FlutterActivity {
// TODO(gaaclarke): Remove this once v2 of GeneratedPluginRegistrant rolls to stable.
// https://github.com/flutter/flutter/issues/42694
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
GeneratedPluginRegistrant.registerWith(this);
public void configureFlutterEngine(FlutterEngine flutterEngine) {
flutterEngine.getPlugins().add(new E2EPlugin());
flutterEngine.getPlugins().add(new FirebaseInAppMessagingPlugin());
final ShimPluginRegistry shimPluginRegistry = new ShimPluginRegistry(flutterEngine);
FirebaseAnalyticsPlugin.registerWith(
shimPluginRegistry.registrarFor(
"io.flutter.plugins.firebaseanalytics.FirebaseAnalyticsPlugin"));
}
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
org.gradle.jvmargs=-Xmx1536M
android.enableJetifier=true
android.useAndroidX=true
android.enableR8=true
1 change: 1 addition & 0 deletions packages/firebase_in_app_messaging/example/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ dependencies:
cupertino_icons: ^0.1.2

dev_dependencies:
e2e: ^0.2.1
flutter_test:
sdk: flutter
flutter_driver:
Expand Down

This file was deleted.

This file was deleted.

6 changes: 4 additions & 2 deletions packages/firebase_in_app_messaging/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
name: firebase_in_app_messaging
description: Flutter plugin for Firebase In-App Messaging.
version: 0.1.0
version: 0.1.1
author: Flutter Team <[email protected]>
homepage: https://github.com/FirebaseExtended/flutterfire/tree/master/packages/firebase_in_app_messaging

environment:
sdk: ">=2.1.0 <3.0.0"
sdk: ">=2.0.0-dev.28.0 <3.0.0"
flutter: ">=1.9.1+hotfix.5 <2.0.0"

dependencies:
meta: ^1.1.6
flutter:
sdk: flutter

dev_dependencies:
e2e: ^0.2.1
flutter_test:
sdk: flutter
flutter_driver:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import 'package:flutter_test/flutter_test.dart';
import 'package:e2e/e2e.dart';
import 'package:firebase_in_app_messaging/firebase_in_app_messaging.dart';

void main() {
E2EWidgetsFlutterBinding.ensureInitialized();
FirebaseInAppMessaging fiam;

setUp(() {
fiam = FirebaseInAppMessaging();
});

testWidgets('triggerEvent', (WidgetTester tester) async {
expect(fiam.triggerEvent('someEvent'), completes);
});

testWidgets('logging', (WidgetTester tester) async {
expect(fiam.setMessagesSuppressed(true), completes);
expect(fiam.setAutomaticDataCollectionEnabled(true), completes);
});
}

0 comments on commit b55faff

Please sign in to comment.