package com.unis.sxzcl.ui.user;

import android.view.LayoutInflater;
import android.view.ViewGroup;

import com.unis.model.event.TextSizeEvent;
import com.unis.sxzcl.R;
import com.unis.sxzcl.base.BaseFragment;
import com.unis.sxzcl.databinding.FragmentTextSizeBinding;
import com.unis.model.Constant;
import com.xyxsbj.mylibrary.tool.SPTool;

import org.greenrobot.eventbus.EventBus;

/**
 * 包名: com.cargocenter.app.ui.setting
 * 类名: TextSizeFragment
 * 作用描述:
 * 创建人: mQ
 * 创建时间: 2020/11/21 9:08
 * 更新人:
 * 更新时间: 2020/11/21 9:08
 * 更新说明:
 * 版本号: 1.0
 */
public class TextSizeFragment extends BaseFragment<FragmentTextSizeBinding> {

    @Override
    protected FragmentTextSizeBinding getViewBinding(LayoutInflater inflater, ViewGroup container) {
        return FragmentTextSizeBinding.inflate(inflater,container,false);
    }

    @Override
    protected void init() {
        mBinding.bar.setLeftClickListener(v -> onBack());

        mBinding.btnUpdate.setOnClickListener(v -> {
            String flag = "2";
            switch (mBinding.radioGroup.getCheckedRadioButtonId()) {
                case R.id.rb_1:
                    flag = "1";
                    break;
                case R.id.rb_2:
                    flag = "2";
                    break;
                case R.id.rb_3:
                    flag = "3";
                    break;
                case R.id.rb_4:
                    flag = "4";
                    break;
                case R.id.rb_5:
                    flag = "5";
                    break;
                case R.id.rb_6:
                    flag = "6";
                    break;
            }
            SPTool.saveString(Constant.KEY_TEXT_SIZE, flag);

            EventBus.getDefault().post(new TextSizeEvent());
        });

    }

    @Override
    protected void onFirstShow() {
        String themeFlag = (String) SPTool.getString(Constant.KEY_TEXT_SIZE, "2");
        switch (themeFlag) {
            case "1":
                mBinding.rb1.setChecked(true);
                break;
            case "2":
                mBinding.rb2.setChecked(true);
                break;
            case "3":
                mBinding.rb3.setChecked(true);
                break;
            case "4":
                mBinding.rb4.setChecked(true);
                break;
            case "5":
                mBinding.rb5.setChecked(true);
                break;
            case "6":
                mBinding.rb6.setChecked(true);
                break;
        }
    }

}
