SettingsActivity.java 3.46 KB
package com.lijinji.call;

import android.content.Context;
import android.os.Bundle;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.RecyclerView;

import com.lijinji.call.adapter.MenuBean;
import com.lijinji.call.adapter.RecyclerViewAdapter;
import com.lijinji.call.adapter.SettingsBean;
import com.lijinji.call.adapter.SettingsViewAdapter;
import com.lijinji.call.download.DownloadUtils;
import com.lijinji.call.util.CommonActivity;
import com.lijinji.call.util.Constant;
import com.lijinji.call.util.WMSLog;
import com.lijinji.call.util.WMSUtils;

import java.util.ArrayList;

import butterknife.BindView;
import butterknife.ButterKnife;

public class SettingsActivity extends CommonActivity {

    @BindView(R.id.recycleSettingsView)
    RecyclerView recycleSettingsView;
    private Context mContext;
    private SettingsViewAdapter adapter;
    private ArrayList<SettingsBean> menuBeans;
    private GridLayoutManager layoutManager;
    private boolean isDownloading = false;

    @Override
    protected void initActivityOnCreate(Bundle savedInstanceState) {
        super.initActivityOnCreate(savedInstanceState);
        setContentView(R.layout.activity_settings);
        ButterKnife.bind(this);
        this.setTitle(this.getString(R.string.setting));
        mContext = this;
        initView();
    }

    private void initView() {
        adapter = new SettingsViewAdapter(mContext);
        layoutManager = new GridLayoutManager(mContext, 3);
        recycleSettingsView.setLayoutManager(layoutManager);
        recycleSettingsView.setAdapter(adapter);
        menuBeans = buildMenuBeans();
        if (menuBeans != null) {
            adapter.setList(menuBeans);
        }
        adapter.setOnItemClickListener(listener);
    }

    private ArrayList<SettingsBean> buildMenuBeans() {
        ArrayList<SettingsBean> menuBeans = new ArrayList<>();
        menuBeans.add(new SettingsBean(mContext.getResources().getDrawable(R.mipmap.cangku), mContext.getString(R.string.current_warehouse), WMSUtils.getData(Constant.CURREN_WAREHOUSE)));
        menuBeans.add(new SettingsBean(mContext.getResources().getDrawable(R.mipmap.station), mContext.getString(R.string.current_station), WMSUtils.getData(Constant.CURREN_LINE_NAME) + " " +  WMSUtils.getData(Constant.CURREN_STATION)));
        menuBeans.add(new SettingsBean(mContext.getResources().getDrawable(R.mipmap.upgrade), mContext.getString(R.string.upgrade), "当前版本:" + WMSUtils.getVersionName()));
        menuBeans.add(new SettingsBean(mContext.getResources().getDrawable(R.mipmap.exit), mContext.getString(R.string.exit), ""));
        return menuBeans;
    }

    private RecyclerViewAdapter.OnRecyclerViewItemClickListener listener = new RecyclerViewAdapter.OnRecyclerViewItemClickListener() {
        @Override
        public void onItemClick(int position) {
            chooseItemListener(position);
        }
    };

    private void chooseItemListener(int positino) {
        SettingsBean bean = menuBeans.get(positino);
        String name = bean.getName();
        if (name.equals(mContext.getString(R.string.current_warehouse))) {

        } else if (name.equals(mContext.getString(R.string.upgrade))) {
            if(!isDownloading) {
                DownloadUtils.as(mContext).startDownload();
                isDownloading = true;
            }
        } else if (name.equals(mContext.getString(R.string.exit))) {
            finish();
            WMSUtils.startActivity(mContext, LoginActivity.class);
        }
    }
}