package com.itant.joycity.activity;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.FragmentActivity;
import android.view.View;
import android.view.ViewGroup;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.itant.joycity.R;

/**
 * Created by Jason on 2016/10/6.
 */
public class BaseActivity extends FragmentActivity {
    private RelativeLayout rl_back;
    private TextView tv_title;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_base);

        rl_back = (RelativeLayout) findViewById(R.id.rl_back);
        rl_back.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });

        tv_title = (TextView) findViewById(R.id.tv_title);
    }

    /**
     * 设置标题栏
     * @param title
     */
    public void setTitleBar(String title) {
        tv_title.setText(title);
        ViewGroup view = (ViewGroup) findViewById(R.id.fl_content_view);
        view.addView(View.inflate(this, getContentView(), null));
    }

    /**
     * 设置标题
     * @param title
     */
    public void setTitle(String title) {
        tv_title.setText(title);
    }

    protected int getContentView() {
        return R.layout.activity_official_detail;// 任意非空的view
    }

    public void setBackable(boolean backable) {
        if (backable) {
            rl_back.setVisibility(View.VISIBLE);
        } else {
            rl_back.setVisibility(View.GONE);
        }
    }
}
