Skip to content

Commit

Permalink
chore(firebase_in_app_messaging, android): update deprecated `Task.ca…
Browse files Browse the repository at this point in the history
…ll()` to `TaskCompletionSource` API (#9407)
  • Loading branch information
russellwheatley authored Aug 24, 2022
1 parent 490ef20 commit bb9b3b2
Showing 1 changed file with 31 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@

package io.flutter.plugins.firebase.inappmessaging;

import androidx.annotation.NonNull;
import com.google.android.gms.tasks.Task;
import com.google.android.gms.tasks.Tasks;
import com.google.android.gms.tasks.TaskCompletionSource;
import com.google.firebase.FirebaseApp;
import com.google.firebase.inappmessaging.FirebaseInAppMessaging;
import io.flutter.embedding.engine.plugins.FlutterPlugin;
Expand All @@ -16,6 +17,7 @@
import io.flutter.plugin.common.MethodChannel.Result;
import io.flutter.plugins.firebase.core.FlutterFirebasePlugin;
import java.util.Map;
import java.util.Objects;

/** FirebaseInAppMessagingPlugin */
public class FirebaseInAppMessagingPlugin
Expand All @@ -30,26 +32,26 @@ public void onAttachedToEngine(FlutterPluginBinding binding) {
}

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

@Override
public void onMethodCall(MethodCall call, Result result) {
public void onMethodCall(MethodCall call, @NonNull Result result) {
switch (call.method) {
case "FirebaseInAppMessaging#triggerEvent":
{
String eventName = call.argument("eventName");
String eventName = Objects.requireNonNull(call.argument("eventName"));
FirebaseInAppMessaging.getInstance().triggerEvent(eventName);
result.success(null);
break;
}
case "FirebaseInAppMessaging#setMessagesSuppressed":
{
Boolean suppress = (Boolean) call.argument("suppress");
Boolean suppress = Objects.requireNonNull(call.argument("suppress"));
FirebaseInAppMessaging.getInstance().setMessagesSuppressed(suppress);
result.success(null);
break;
Expand All @@ -71,11 +73,33 @@ public void onMethodCall(MethodCall call, Result result) {

@Override
public Task<Map<String, Object>> getPluginConstantsForFirebaseApp(FirebaseApp firebaseApp) {
return Tasks.call(() -> null);
TaskCompletionSource<Map<String, Object>> taskCompletionSource = new TaskCompletionSource<>();

cachedThreadPool.execute(
() -> {
try {
taskCompletionSource.setResult(null);
} catch (Exception e) {
taskCompletionSource.setException(e);
}
});

return taskCompletionSource.getTask();
}

@Override
public Task<Void> didReinitializeFirebaseCore() {
return Tasks.call(() -> null);
TaskCompletionSource<Void> taskCompletionSource = new TaskCompletionSource<>();

cachedThreadPool.execute(
() -> {
try {
taskCompletionSource.setResult(null);
} catch (Exception e) {
taskCompletionSource.setException(e);
}
});

return taskCompletionSource.getTask();
}
}

0 comments on commit bb9b3b2

Please sign in to comment.