package com.anren.omplayer;

import com.facebook.react.bridge.Callback;
import com.facebook.react.bridge.ReactApplicationContext;
import com.facebook.react.bridge.ReactContextBaseJavaModule;
import com.facebook.react.bridge.ReactMethod;
import com.facebook.react.bridge.ReadableMap;
import com.facebook.react.bridge.WritableMap;
import com.facebook.react.bridge.WritableNativeMap;
import com.facebook.react.modules.core.DeviceEventManagerModule;

import java.lang.ref.WeakReference;
import java.util.HashMap;
import java.util.Map;

import javax.annotation.Nullable;

/**
 * Created by lcg on 2017/6/18.
 */
public class OMVideoPlayerModule extends ReactContextBaseJavaModule {

    private static WeakReference<OMFullScreenManager> fullScreenManagerRef = null;

    public OMVideoPlayerModule(ReactApplicationContext reactContent){
        super(reactContent);
    }

    @Override
    public String getName() {
        return "OMVideoPlayerManager";
    }

    public static void setFullScreenManager(OMFullScreenManager fullScreenManager){
        OMVideoPlayerModule.fullScreenManagerRef = new WeakReference<>(fullScreenManager);
    }

    @ReactMethod
    public void hideFullScreenView(){
        getCurrentActivity().runOnUiThread(new Runnable() {
            @Override
            public void run() {
                if (fullScreenManagerRef != null) {
                    OMFullScreenManager fullScreenManager = fullScreenManagerRef.get();
                    if (fullScreenManager != null) {
                        fullScreenManager.hide();
                    }
                }
            }
        });
    }
}
