package com.xxfc.discovery.popupwindow;

import android.app.Activity;
import android.graphics.Rect;
import android.os.Build;
import android.support.annotation.NonNull;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;

import com.ruiwenliu.wrapper.dialog.BasePopupWindow;
import com.ruiwenliu.wrapper.util.ViewHolder;
import com.xxfc.discovery.R;

/**
 * 发现增加功能
 */
public class AddDiscoveryContentPw extends BasePopupWindow {

    public AddDiscoveryContentPw(@NonNull Activity context) {
        super(context);
        setOutsideTouchable(false);
    }

    @Override
    public int getViewLayout() {
        return R.layout.pop_add_discovery_content;
    }

    @Override
    public void helper(ViewHolder helper) {
        super.helper(helper);
        helper.setOnClickListener(R.id.fl_dismiss, new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                dismiss();
            }
        });
        RecyclerView recyclerView = helper.getView(R.id.recyclerView);
        recyclerView.setLayoutManager(new LinearLayoutManager(getDialogContext()));
    }

    /**
     *
     * @param anchor v
     */
    public  void showPopupWindow(final View anchor) {
        if (Build.VERSION.SDK_INT >= 24) {
            Rect visibleFrame = new Rect();
            anchor.getGlobalVisibleRect(visibleFrame);
            int height = anchor.getResources().getDisplayMetrics().heightPixels - visibleFrame.bottom;
            this.setHeight(height);
            this.showAsDropDown(anchor, 0, 0);
        } else {
            this.showAsDropDown(anchor, 0, 0);
        }
    }



    private void fullScreenImmersive(View view) {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
            int uiOptions = View.SYSTEM_UI_FLAG_LAYOUT_STABLE | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_FULLSCREEN;
            view.setSystemUiVisibility(uiOptions);
        }
    }
}
