package com.example.cmknowledgegraph;

import android.app.Person;
import android.content.Context;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.ImageButton;
import android.widget.ImageView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.Toolbar;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.example.PersonalCenter.FeedAdapter;
import com.example.PersonalCenter.MenuListFragment;
import com.mxn.soul.flowingdrawer_core.ElasticDrawer;
import com.mxn.soul.flowingdrawer_core.FlowingDrawer;

import yalantis.com.sidemenu.interfaces.Resourceble;
import yalantis.com.sidemenu.interfaces.ScreenShotable;
import yalantis.com.sidemenu.util.ViewAnimator;

public class PersonContent extends Fragment  {


    protected int res;

    private RecyclerView rvFeed;
    private FlowingDrawer mDrawer;
    @Override
    public void onAttach(@NonNull Context context) {
        super.onAttach(context);
        MainActivity mainActivity = (MainActivity) context;
    }

    AppCompatActivity appCompatActivity;

    public AppCompatActivity getAppCompatActivity() {
        return appCompatActivity;
    }

    public void setAppCompatActivity(AppCompatActivity appCompatActivity) {
        this.appCompatActivity = appCompatActivity;
    }



        public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        return inflater.inflate( R.layout.activity_personality_center, container, false );  //要加载的layout文件
    }

    @Override
    public void onActivityCreated(@Nullable Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
        rvFeed = (RecyclerView) appCompatActivity.findViewById(R.id.rvFeed);
        mDrawer = (FlowingDrawer) appCompatActivity.findViewById(R.id.drawerlayout);
        mDrawer.setTouchMode(ElasticDrawer.TOUCH_MODE_BEZEL);
        //设置工具栏
        setupToolbar();
        //设置直接页面
        setupFeed();
       //设置侧滑菜单
        setupMenu();
    }
    protected void setupToolbar() {
        Toolbar toolbar = (Toolbar) appCompatActivity.findViewById(R.id.toolbar);
        appCompatActivity.setSupportActionBar(toolbar);
        //这里是图片，可以将其动态加载用户图片，如果没有登录就改成别的。
        toolbar.setNavigationIcon(R.drawable.ic_menu_white);
        //点击了就开始侧滑
        toolbar.setNavigationOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                mDrawer.toggleMenu();
            }
        });
    }
    //设置没有侧滑之前的状态页面
    //在这里将东西其改成几个按钮
    private void setupFeed() {
        LinearLayoutManager linearLayoutManager = new LinearLayoutManager(appCompatActivity) {
            @Override
            protected int getExtraLayoutSpace(RecyclerView.State state) {
                return 300;
            }
        };
        rvFeed.setLayoutManager(linearLayoutManager);
        FeedAdapter feedAdapter = new FeedAdapter(appCompatActivity);
        rvFeed.setAdapter(feedAdapter);
        feedAdapter.updateItems();
    }

    //设置菜单
    private void setupMenu() {
        FragmentManager fm = appCompatActivity.getSupportFragmentManager();//获取Fragment管理器
        MenuListFragment mMenuFragment = (MenuListFragment) fm.findFragmentById(R.id.id_container_menu);
        if (mMenuFragment == null) {
            mMenuFragment = new MenuListFragment();
            fm.beginTransaction().add(R.id.id_container_menu, mMenuFragment).commit();
            //向activity添加一个布局
        }

//        mDrawer.setOnDrawerStateChangeListener(new ElasticDrawer.OnDrawerStateChangeListener() {
//            @Override
//            public void onDrawerStateChange(int oldState, int newState) {
//                if (newState == ElasticDrawer.STATE_CLOSED) {
//                    Log.i("MainActivity", "Drawer STATE_CLOSED");
//                }
//            }
//
//            @Override
//            public void onDrawerSlide(float openRatio, int offsetPixels) {
//                Log.i("MainActivity", "openRatio=" + openRatio + " ,offsetPixels=" + offsetPixels);
//            }
//        });
    }
    //
//    public void onActivityCreated(Bundle savedInstanceState) {
//        // TODO Auto-generated method stub
//        super.onActivityCreated(savedInstanceState);
//
//        Button login_pc_btn = (Button) getActivity().findViewById(R.id.login_pc_button);
//        login_pc_btn.setOnClickListener(new View.OnClickListener() {
//            public void onClick(View v) {
//
//                Intent intent=new Intent();
//                intent.setClass(getActivity(),LoginActivity.class);
//                startActivity(intent);
//            }
//        });
//    }

//    @Override
//    public void onResume() {
//        super.onResume();
//        if(LoginActivity.isLogin){
//            Button longin_pc_btn=(Button) getActivity().findViewById(R.id.login_pc_button);
//            longin_pc_btn.setText("Hello"+LoginActivity.username);
//        }
//
////高血压
//    }
}
