package com.ydl.component.base;


import android.app.Application;
import android.content.Context;
import android.content.Intent;
import android.os.Handler;

import com.channel.ydl_flutter_base.base.BaseFlutterActivity;
import com.channel.ydl_flutter_base.plugin.YDLCommonPlugin;
import com.ydl.devicesidlib.DeviceIDHelper;
import com.ydl.media.audio.PlayService;
import com.ydl.ydlcommon.base.delegate.IAppLifecycles;
import com.ydl.ydlcommon.utils.YdlBuryPointUtil;
import com.yidianling.course.lifeCallback.CoursePlayLifecycle;

import org.jetbrains.annotations.NotNull;

import java.util.concurrent.TimeUnit;

import io.flutter.app.FlutterActivityDelegate;
import io.flutter.embedding.engine.FlutterEngine;
import io.flutter.embedding.engine.dart.DartExecutor;
import io.flutter.plugin.common.MethodChannel;
import io.flutter.plugins.GeneratedPluginRegistrant;
import io.flutter.view.FlutterMain;
import io.reactivex.Observable;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.schedulers.Schedulers;

/**
 * Created by haorui on 2019-09-02.
 * Des:
 */
public class DemoAppLifecycles implements IAppLifecycles {

    @Override
    public void attachBaseContext(@NotNull Context base) {

    }

    @Override
    public void onCreate(@NotNull Application application) {
        //数据埋点初始化--一定要放在主进程中
        YdlBuryPointUtil.init(application);

        //设备ID初始化
        DeviceIDHelper.getInstance().init(application);

        //Flutter 初始化需要在主线程中执行
        FlutterMain.startInitialization(application);
//        FlutterMain.ensureInitializationComplete(application, null);
//
//        FlutterEngine flutterEngine = new FlutterEngine(application);
//        flutterEngine.getDartExecutor().executeDartEntrypoint(DartExecutor.DartEntrypoint.createDefault());
//        YDLCommonPlugin plugin = new YDLCommonPlugin();
//        flutterEngine.getLocalizationChannel().channel.setMethodCallHandler(plugin);

        Intent intent = new Intent(application, PlayService.class);
        application.startService(intent);

        application.registerActivityLifecycleCallbacks(new CoursePlayLifecycle());
    }

    @Override
    public void onTerminate(@NotNull Application application) {
    }
}