MainActivity.java 4.5 KB
package com.hh.xuetubao;

import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.FragmentTransaction;
import android.view.View;
import android.widget.RadioButton;

import com.hh.xuetubao.activity.pratice.PracticeActivity;
import com.hh.xuetubao.activity.study.StudyActivity;
import com.hh.xuetubao.activity.work.JobHuntActivity;
import com.hh.xuetubao.fragment.HomeFragment;
import com.hh.xuetubao.fragment.MineFragment;
import com.hh.xuetubao.fragment.PraticeWrongFragment;
import com.hh.xuetubao.model.MainModel;
import com.hh.xuetubao.mvp.BaseMvpActivity;
import com.hh.xuetubao.mvp.CommonPresenter;
import com.hh.xuetubao.mvp.ICommonView;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * 主页面
 */

public class MainActivity extends BaseMvpActivity<CommonPresenter, MainModel> implements ICommonView, View.OnClickListener {

    @BindView(R.id.rl_home)
    RadioButton rlHome;
    @BindView(R.id.rl_study)
    RadioButton rlStudy;
    @BindView(R.id.rl_job)
    RadioButton rlJob;
    @BindView(R.id.rl_biancheng)
    RadioButton rlBiancheng;
    @BindView(R.id.rl_mine)
    RadioButton rlMine;
    private FragmentTransaction transaction;
    private MineFragment mineFragment;
    private HomeFragment homeFragment;
    private PraticeWrongFragment wrongFragment;

    int selectTag = 3;

    @Override
    public void initView() {

     /*   //添加变色标志
        this.getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR);
        //导航栏颜色
        getWindow().setNavigationBarColor(Color.parseColor("#fcfcfc"));
        //状态栏颜色
        getWindow().setStatusBarColor(Color.parseColor("#fcfcfc"));*/

        wrongFragment = new PraticeWrongFragment();
        transaction = getSupportFragmentManager().beginTransaction();

        if(homeFragment==null){
            homeFragment=new HomeFragment();
            transaction.add(R.id.frame, homeFragment);
        }else{
            transaction.show(homeFragment);
        }
        transaction.commit();

        rlHome.setChecked(true);

        rlHome.setOnClickListener(this);
        rlStudy.setOnClickListener(this);
        rlJob.setOnClickListener(this);
        rlBiancheng.setOnClickListener(this);
        rlMine.setOnClickListener(this);

    }

    @Override
    public int initLayout() {
        return R.layout.activity_mine;
    }

    @Override
    public void initData() {

    }

    @Override
    public CommonPresenter getPresenter() {
        return new CommonPresenter();
    }

    @Override
    public MainModel getModel() {
        return new MainModel();
    }

    @Override
    public void getData(Object o, int api, int intent) {

    }

    @Override
    public void onComplete(int api) {

    }

    @Override
    public void onError(Throwable e, int api) {

    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        // TODO: add setContentView(...) invocation
        ButterKnife.bind(this);
    }

    @Override
    public void onClick(View v) {
        transaction = getSupportFragmentManager().beginTransaction();
        mineFragment = new MineFragment();
        homeFragment = new HomeFragment();
        switch (v.getId()) {
            case R.id.rl_home:
                transaction.replace(R.id.frame, homeFragment);
                transaction.commit();
                selectTag = 0;
                break;
            case R.id.rl_study:
                startActivity(new Intent(this, StudyActivity.class));
                rlStudy.setChecked(true);
                selectTag = 0;
                MainActivity.this.finish();
                break;
            case R.id.rl_job:
                startActivity(new Intent(this, JobHuntActivity.class));
                rlJob.setChecked(true);
                selectTag = 0;
                MainActivity.this.finish();
                break;
            case R.id.rl_biancheng:
                startActivity(new Intent(this, PracticeActivity.class));
                rlBiancheng.setChecked(true);
                selectTag = 0;
                MainActivity.this.finish();
                break;
            case R.id.rl_mine:
                transaction.replace(R.id.frame, mineFragment, "1");
                transaction.commit();
                rlMine.setChecked(true);
                selectTag = 4;
                break;
        }
    }

    @Override
    protected void onResume() {
        super.onResume();
    }

}