package com.sobot.demo.activity.more;

import android.os.Bundle;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import android.view.View;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.sobot.demo.R;
import com.sobot.demo.SobotSPUtil;

/**
 * Created by Administrator on 2017/11/21.
 */

public class SobotSwitchAllSetActivity extends AppCompatActivity implements View.OnClickListener{
    private RelativeLayout sobotDemoTvLeft;
    private TextView sobotDemoTvTitle;
    private RelativeLayout sobotScreenSet;
    private RelativeLayout sobotIsShowSatisfactionClose;
    private ImageView imgOpenClose;
    private ImageView imgOpenNotify3;
    private RelativeLayout sobotRl3;
    private ImageView sobotImage3;




    private boolean isLandscape_Screen,isInterceptLink,isShowChatStatus;




    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.sobot_switch_all_activity);
        if (getSupportActionBar() != null){
            getSupportActionBar().hide();
        }
        findvViews();
    }

    private void findvViews(){
        sobotDemoTvLeft = (RelativeLayout) findViewById(R.id.sobot_demo_tv_left);
        sobotDemoTvTitle = (TextView) findViewById(R.id.sobot_demo_tv_title);
        sobotScreenSet = (RelativeLayout) findViewById(R.id.sobot_screen_set);
        sobotIsShowSatisfactionClose = (RelativeLayout) findViewById(R.id.sobot_isShowSatisfactionClose);
        imgOpenClose = (ImageView) findViewById(R.id.img_open_close);
        imgOpenNotify3 = (ImageView) findViewById(R.id.img_open_notify3);


        sobotScreenSet.setOnClickListener(this);
        sobotIsShowSatisfactionClose.setOnClickListener(this);
        sobotDemoTvLeft .setOnClickListener(this);


        sobotRl3 = (RelativeLayout) findViewById(R.id.sobot_rl3);
        sobotRl3.setOnClickListener(this);
        sobotImage3 = (ImageView) findViewById(R.id.sobot_image3);

        sobotDemoTvTitle.setText("全局开关设置");

        getSobotStartSet();
    }

    private void getSobotStartSet() {
        isLandscape_Screen = SobotSPUtil.getBooleanData(this, "sobot_isLandscapeScreen", false);
        setShowSatisfaction(isLandscape_Screen);
        isInterceptLink = SobotSPUtil.getBooleanData(this, "isInterceptLink", false);
        setShowSatisfactionClose(isInterceptLink);
        isShowChatStatus = SobotSPUtil.getBooleanData(this, "isShowChatStatus", false);
        setImageShowChatStatus(isShowChatStatus);

    }

    private void saveSobotStartSet() {
        SobotSPUtil.saveBooleanData(this, "sobot_isLandscapeScreen", isLandscape_Screen);
        SobotSPUtil.saveBooleanData(this, "isInterceptLink", isInterceptLink);
        SobotSPUtil.saveBooleanData(this, "isShowChatStatus", isShowChatStatus);

    }

    @Override
    public void onBackPressed() {
        saveSobotStartSet();
        finish();
    }


    @Override
    public void onClick(View v) {
        if (v == sobotDemoTvLeft){
            saveSobotStartSet();
            finish();
        } else if (v == sobotScreenSet){//横竖屏
            isLandscape_Screen = !isLandscape_Screen;
            setShowSatisfaction(isLandscape_Screen);
            saveSobotStartSet();
        } else if (v == sobotIsShowSatisfactionClose){//超链接拦截
            isInterceptLink = !isInterceptLink;
            setShowSatisfactionClose(isInterceptLink);
            saveSobotStartSet();
        }else if (v == sobotRl3){//是否显示聊天状态
            isShowChatStatus = !isShowChatStatus;
            setImageShowChatStatus(isShowChatStatus);
            saveSobotStartSet();
        }
    }

    private void setImageShowChatStatus(boolean open){
        if (open){
            isShowChatStatus = true;
            sobotImage3.setBackgroundResource(R.drawable.sobot_demo_icon_open);
        } else {
            isShowChatStatus = false;
            sobotImage3.setBackgroundResource(R.drawable.sobot_demo_icon_close);
        }
    }
    private void setShowSatisfaction(boolean open){
        if (open){
            isLandscape_Screen = true;
            imgOpenClose.setBackgroundResource(R.drawable.sobot_demo_icon_open);
        } else {
            isLandscape_Screen = false;
            imgOpenClose.setBackgroundResource(R.drawable.sobot_demo_icon_close);
        }
    }
    private void setShowSatisfactionClose(boolean open){
        if (open){
            isInterceptLink = true;
            imgOpenNotify3.setBackgroundResource(R.drawable.sobot_demo_icon_open);
        } else {
            isInterceptLink = false;
            imgOpenNotify3.setBackgroundResource(R.drawable.sobot_demo_icon_close);
        }
    }


}