package com.bokecc.cloudclass.demo.activity;

import android.content.Intent;
import android.os.Bundle;
import android.os.PersistableBundle;
import android.text.TextUtils;
import android.view.View;

import com.bokecc.cloudclass.demo.R;
import com.bokecc.cloudclass.demo.base.TitleActivity;
import com.bokecc.cloudclass.demo.base.TitleOptions;

import com.bokecc.cloudclass.demo.global.Config;
import com.bokecc.common.utils.Tools;

/**
 * 横竖屏选择界面
 */
public class DirectionActivity extends TitleActivity<DirectionActivity.DirectionViewHolder> {

    @Override
    protected int getContentLayoutId() {
        return R.layout.activity_direction;
    }

    @Override
    protected DirectionViewHolder getViewHolder(View contentView) {
        return new DirectionViewHolder(contentView);
    }

    @Override
    protected void onBindViewHolder(DirectionViewHolder holder) {
        TitleOptions.Builder builder = new TitleOptions.Builder();
        TitleOptions options = builder.leftStatus(TitleOptions.VISIBLE).
                leftResId(R.drawable.title_back).
                rightStatus(TitleOptions.GONE).
                titleStatus(TitleOptions.VISIBLE).title(Tools.getString(R.string.cc_demo_class_mode)).
                onTitleClickListener(new TitleOptions.OnLeftClickListener() {
                    @Override
                    public void onLeft() {
                        finish();
                    }
                }).
                build();
        setTitleOptions(options);

        //设置是否显示竖屏按钮
        String mTemplate = getIntent().getExtras().getString(Config.KEY_ROOM_TEMPLATE);
        if(!TextUtils.isEmpty(mTemplate)){
            findViewById(R.id.id_direction_class_v).setVisibility(View.GONE);
        }
    }

    final class DirectionViewHolder extends TitleActivity.ViewHolder {

        DirectionViewHolder(View view) {
            super(view);

            findViewById(R.id.id_direction_class_h).setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    goValidateActivity(1);
                }
            });

            findViewById(R.id.id_direction_class_v).setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    goValidateActivity(0);
                }
            });
        }

        /**
         * 跳转到登录界面
         */
        private void goValidateActivity(int classDirection) {
            Intent intent = new Intent(DirectionActivity.this, ValidateActivity.class);
            Bundle bundle = getIntent().getExtras();
            bundle.putInt(Config.KEY_CLASS_DIRECTION,classDirection);
            intent.putExtras(bundle);
            startActivity(intent);
        }
    }

    @Override
    public void onSaveInstanceState(Bundle outState, PersistableBundle outPersistentState) {
        outState.putString(Config.KEY_ROOM_TEMPLATE,getIntent().getStringExtra(Config.KEY_ROOM_TEMPLATE));
        super.onSaveInstanceState(outState, outPersistentState);
    }

    @Override
    protected void onRestoreInstanceState(Bundle savedInstanceState) {
        super.onRestoreInstanceState(savedInstanceState);
    }
}
