package kr.co.hanwha.hifive.view;

import android.content.Context;
import android.content.res.TypedArray;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.text.TextUtils;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;

import kr.co.hanwha.hifive.R;
import kr.co.hanwha.hifive.data.model.ProjectInfoData;

public class HFSettingMenuActionView extends LinearLayout {
    private View mViewTopLine;
    private TextView mTextViewName;
    private TextView mTextViewSubName;

    private ProjectInfoData mData;

    public HFSettingMenuActionView(Context context) {
        super(context);
        initialize(context, null);
    }

    public HFSettingMenuActionView(Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
        initialize(context, attrs);
    }

    public HFSettingMenuActionView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        initialize(context, attrs);
    }

    private void initialize(Context context, @Nullable AttributeSet attrs) {
//        if (isInEditMode()) return;

        LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        inflater.inflate(R.layout.view_hf_setting_menu_action, this, true);

        mViewTopLine = (View) findViewById(R.id.topLine_view);
        mTextViewName = (TextView) findViewById(R.id.name_textView);
        mTextViewSubName = (TextView) findViewById(R.id.subName_textView);

        if (attrs != null) {
            TypedArray type = null;
            try {
                type = context.obtainStyledAttributes(attrs, R.styleable.SettingView);
                String name = type.getString(R.styleable.SettingView_name);
                String subName = type.getString(R.styleable.SettingView_subName);
                boolean isTopLine = type.getBoolean(R.styleable.SettingView_topLine, false);

                if (TextUtils.isEmpty(name) == false)
                    mTextViewName.setText(name);

                if (TextUtils.isEmpty(subName) == false)
                    mTextViewSubName.setText(subName);

                mViewTopLine.setVisibility(isTopLine ? View.VISIBLE : View.GONE);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }

    public void setSubName(String subName) {
        if (subName == null) return;
        mTextViewSubName.setText(subName);
    }
}