Commit 16db7270 by 徐健

增加flutter公共channel模块

parent 2659147b
...@@ -178,6 +178,7 @@ dependencies { ...@@ -178,6 +178,7 @@ dependencies {
if (true) { if (true) {
//开发模式 //开发模式
implementation fileTree(dir: 'aars', include: ['*.aar'])
api project(':m-user') api project(':m-user')
implementation modularPublication('com.ydl:m-user-api') implementation modularPublication('com.ydl:m-user-api')
api project(':m-tests') api project(':m-tests')
...@@ -212,6 +213,7 @@ dependencies { ...@@ -212,6 +213,7 @@ dependencies {
api(rootProject.ext.dependencies["ydl-platform"]) { api(rootProject.ext.dependencies["ydl-platform"]) {
transitive = true transitive = true
} }
api rootProject.ext.dependencies["ydl-flutter"]
} }
......
...@@ -5,6 +5,8 @@ import android.app.Application; ...@@ -5,6 +5,8 @@ import android.app.Application;
import android.content.Context; import android.content.Context;
import android.content.Intent; import android.content.Intent;
import com.ydl.component.single.CustomBinaryMessagerImpl;
import com.ydl.component.single.YDLCommonPlugin;
import com.ydl.devicesidlib.DeviceIDHelper; import com.ydl.devicesidlib.DeviceIDHelper;
import com.ydl.media.audio.PlayService; import com.ydl.media.audio.PlayService;
import com.ydl.ydlcommon.base.delegate.IAppLifecycles; import com.ydl.ydlcommon.base.delegate.IAppLifecycles;
...@@ -13,6 +15,8 @@ import com.yidianling.course.lifeCallback.CoursePlayLifecycle; ...@@ -13,6 +15,8 @@ import com.yidianling.course.lifeCallback.CoursePlayLifecycle;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import io.flutter.plugin.common.BinaryMessenger;
import io.flutter.plugin.common.MethodChannel;
import io.flutter.view.FlutterMain; import io.flutter.view.FlutterMain;
/** /**
...@@ -35,6 +39,7 @@ public class DemoAppLifecycles implements IAppLifecycles { ...@@ -35,6 +39,7 @@ public class DemoAppLifecycles implements IAppLifecycles {
//Flutter 初始化需要在主线程中执行 //Flutter 初始化需要在主线程中执行
FlutterMain.startInitialization(application); FlutterMain.startInitialization(application);
initFlutterChannel();
Intent intent = new Intent(application, PlayService.class); Intent intent = new Intent(application, PlayService.class);
application.startService(intent); application.startService(intent);
...@@ -42,6 +47,14 @@ public class DemoAppLifecycles implements IAppLifecycles { ...@@ -42,6 +47,14 @@ public class DemoAppLifecycles implements IAppLifecycles {
application.registerActivityLifecycleCallbacks(new CoursePlayLifecycle()); application.registerActivityLifecycleCallbacks(new CoursePlayLifecycle());
} }
/**
* 初始化一个公共channel
*/
private void initFlutterChannel() {
YDLCommonPlugin commonPlugin = new YDLCommonPlugin();
new MethodChannel(CustomBinaryMessagerImpl.Companion.getINSTANCE(), commonPlugin.CHANNEL).setMethodCallHandler(commonPlugin);
}
@Override @Override
public void onTerminate(@NotNull Application application) { public void onTerminate(@NotNull Application application) {
......
package com.ydl.component.single
import io.flutter.plugin.common.BinaryMessenger
import java.nio.ByteBuffer
/**
* Created by xj on 2019/11/20.
*/
class CustomBinaryMessagerImpl: BinaryMessenger {
override fun setMessageHandler(p0: String, p1: BinaryMessenger.BinaryMessageHandler?) {
}
override fun send(p0: String, p1: ByteBuffer?) {
}
override fun send(p0: String, p1: ByteBuffer?, p2: BinaryMessenger.BinaryReply?) {
}
companion object {
val INSTANCE by lazy { CustomBinaryMessagerImpl() }
}
}
\ No newline at end of file
package com.ydl.ydl_flutter.flutter.base.plugin package com.ydl.component.single
import android.text.TextUtils import android.text.TextUtils
import com.ydl.ydl_flutter.BuildConfig import com.ydl.component.BuildConfig
import com.ydl.ydl_flutter.flutter.base.BaseFlutterFragment
import com.ydl.ydlcommon.base.BaseApp import com.ydl.ydlcommon.base.BaseApp
import com.ydl.ydlcommon.data.PlatformDataManager import com.ydl.ydlcommon.data.PlatformDataManager
import com.ydl.ydlcommon.modular.ModularServiceManager import com.ydl.ydlcommon.modular.ModularServiceManager
import com.yidianling.common.tools.RxDeviceTool import com.yidianling.common.tools.RxDeviceTool
import io.flutter.app.FlutterActivity
import io.flutter.plugin.common.MethodCall import io.flutter.plugin.common.MethodCall
import io.flutter.plugin.common.MethodChannel import io.flutter.plugin.common.MethodChannel
import io.flutter.view.FlutterView
/** /**
* Created by xj on 2019/11/19. * Created by xj on 2019/11/19.
*/ */
class CommonPlugin : MethodChannel.MethodCallHandler { class YDLCommonPlugin : MethodChannel.MethodCallHandler {
private var mActivity: FlutterActivity? = null
private var mFragment: BaseFlutterFragment? = null
private constructor(activity: FlutterActivity) {
mActivity = activity
}
private constructor(fragment: BaseFlutterFragment) {
mFragment = fragment
}
companion object { companion object {
const val CHANNEL: String = "lib/common/channel" const val CHANNEL: String = "lib/common/channel"
const val GETPUBLICPARAMAS: String = "getPublicParamas" const val GETPUBLICPARAMAS: String = "getPublicParamas"
fun rigisterActivity(activity: FlutterActivity, flutterView: FlutterView) {
MethodChannel(flutterView, CHANNEL).setMethodCallHandler(CommonPlugin(activity))
}
fun rigisterFragment(fragment: BaseFlutterFragment, flutterView: FlutterView) {
MethodChannel(flutterView, CHANNEL).setMethodCallHandler(CommonPlugin(fragment))
}
} }
override fun onMethodCall(methodCall: MethodCall, result: MethodChannel.Result) { override fun onMethodCall(methodCall: MethodCall, result: MethodChannel.Result) {
......
ext { ext {
kotlin_version = "1.3.21" kotlin_version = "1.3.21"
dev_mode = false dev_mode = true
ydl_app = [ ydl_app = [
appName : "心理咨询壹点灵", appName : "心理咨询壹点灵",
......
...@@ -75,7 +75,6 @@ dependencies { ...@@ -75,7 +75,6 @@ dependencies {
//开发时使用 //开发时使用
api project(':ydl-webview') api project(':ydl-webview')
api project(':ydl-platform') api project(':ydl-platform')
api project(":ydl-flutter-base")
implementation modularPublication('com.ydl:m-test-api') implementation modularPublication('com.ydl:m-test-api')
implementation modularPublication('com.ydl:m-user-api') implementation modularPublication('com.ydl:m-user-api')
}else { }else {
...@@ -83,9 +82,6 @@ dependencies { ...@@ -83,9 +82,6 @@ dependencies {
compileOnly rootProject.ext.dependencies["ydl-m-tests-api"] compileOnly rootProject.ext.dependencies["ydl-m-tests-api"]
compileOnly rootProject.ext.dependencies["ydl-m-user-api"] compileOnly rootProject.ext.dependencies["ydl-m-user-api"]
api rootProject.ext.dependencies["ydl-webview"] api rootProject.ext.dependencies["ydl-webview"]
api (rootProject.ext.dependencies["ydl-flutter-base"]){
transitive = true
}
api(rootProject.ext.dependencies["ydl-platform"]) { api(rootProject.ext.dependencies["ydl-platform"]) {
transitive = true transitive = true
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment