package com.hatai.smartlokey.modules.admin; import android.graphics.Color; import android.graphics.drawable.ColorDrawable; import android.os.Bundle; import android.text.TextUtils; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.AdapterView; import android.widget.GridView; import android.widget.ImageView; import android.widget.TextView; import com.google.gson.Gson; import com.hatai.smartlokey.R; import com.hatai.smartlokey.base.MvpFragment; import com.hatai.smartlokey.modules.admin.adapter.AdminOpenBoxAdapter; import com.hatai.smartlokey.modules.admin.presenter.AdminPresenter; import com.hatai.smartlokey.modules.admin.reponse.adminOpenBox; import com.hatai.smartlokey.modules.admin.view.AdminView; import com.hatai.smartlokey.modules.result.ResultFragment; import com.hatai.smartlokey.utils.view.CountdownView; import java.util.ArrayList; import java.util.List; public class AdminOpenBoxFragment extends MvpFragment<AdminView,AdminPresenter> implements AdminView { private ImageView mToolbar; private CountdownView cd_time; private GridView mGridView; private ArrayList<String> list; private TextView bt_done_box_jijian, all, deselect_all, largeTv, MediumTv, SmallTv; public static AdminOpenBoxFragment newInstance() { Bundle args = new Bundle(); AdminOpenBoxFragment fragment = new AdminOpenBoxFragment(); fragment.setArguments(args); return fragment; } @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View view=inflater.inflate(R.layout.fragment_admin_open_box,container,false); initView(view); return view; } AdminOpenBoxAdapter adapter; private void initView(View view) { list = new ArrayList<>(); mGridView = view.findViewById(R.id.gv_open); all = view.findViewById(R.id.all); deselect_all = view.findViewById(R.id.deselect_all); largeTv = view.findViewById(R.id.large); MediumTv = view.findViewById(R.id.Medium); SmallTv = view.findViewById(R.id.Small); mToolbar = view.findViewById(R.id.toolbar); mToolbar.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { // cd_time.stop(); // cd_time.restart(); // start(Admin_mainFragment.newInstance()); initToolbarNav(); } }); bt_done_box_jijian = view.findViewById(R.id.bt_done_box_jijian); bt_done_box_jijian.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { FRAGMENTALL = 5; start(ResultFragment.newInstance(), FRAGMENTALL); } }); cd_time = view.findViewById(R.id.cd_time); long time = (long) 60 * 1000; cd_time.start(time); cd_time.setOnCountdownEndListener(new CountdownView.OnCountdownEndListener() { @Override public void onEnd(CountdownView cv) { // start(MainFragment.newInstance()); } }); all.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { cd_time.stop(); long time = (long) 60 * 1000; cd_time.start(time); for (int i = 0; i < lists.size(); i++) { //選中 if (lists.get(i).isTag()==false) { lists.get(i).setTag(true); } } adapter.notifyDataSetChanged(); } }); deselect_all.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { cd_time.stop(); long time = (long) 60 * 1000; cd_time.start(time); for (int i = 0; i < lists.size(); i++) { //選中 if (lists.get(i).isTag()==true) { lists.get(i).setTag(false); } } adapter.notifyDataSetChanged(); } }); largeTv.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { cd_time.stop(); long time = (long) 60 * 1000; cd_time.start(time); for (int i = 0; i < lists.size(); i++) { if (lists.get(i).getType().equals("L")){ if (lists.get(i).isTag()==false){ lists.get(i).setTag(true); }else if (lists.get(i).isTag()==true){ lists.get(i).setTag(false); } } } adapter.notifyDataSetChanged(); } }); MediumTv.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { cd_time.stop(); long time = (long) 60 * 1000; cd_time.start(time); for (int i = 0; i < lists.size(); i++) { if (lists.get(i).getType().equals("M")){ if (lists.get(i).isTag()==false){ lists.get(i).setTag(true); }else if (lists.get(i).isTag()==true){ lists.get(i).setTag(false); } } } adapter.notifyDataSetChanged(); } }); SmallTv.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { cd_time.stop(); long time = (long) 60 * 1000; cd_time.start(time); for (int i = 0; i < lists.size(); i++) { if (lists.get(i).getType().equals("S")){ if (lists.get(i).isTag()==false){ lists.get(i).setTag(true); }else if (lists.get(i).isTag()==true){ lists.get(i).setTag(false); } } } adapter.notifyDataSetChanged(); } }); mGridView.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> adapterView, View view, int position, long l) { cd_time.stop(); long time = (long) 60 * 1000; cd_time.start(time); adminOpenBox.UnitsBean entity = adapter.getItem(position); if (entity.isTag()==false){ lists.get(position).setTag(true); }else if (entity.isTag()==true){ lists.get(position).setTag(false); } adapter.notifyDataSetChanged(); } }); } @Override public void onResume() { super.onResume(); mvpPresenter.adminopenById(); } List<adminOpenBox.UnitsBean> lists=new ArrayList<>(); private List<adminOpenBox.UnitsBean> getLists(List<adminOpenBox.UnitsBean> units) { for (int i = 0; i <units.size() ; i++) { lists.add(units.get(i)); adapter = new AdminOpenBoxAdapter(getActivity(), lists); mGridView.setAdapter(adapter); mGridView.setSelector(new ColorDrawable(Color.TRANSPARENT)); } return lists; } @Override public void getDataHttp(String data) { adminOpenBox datas=null; if (!TextUtils.isEmpty(data)){ Gson gson = new Gson(); datas=gson.fromJson(data,adminOpenBox.class); if (datas.getStatus()==1){ List<adminOpenBox.UnitsBean> units=datas.getUnits(); getLists(units); }else { } } } @Override public void getDataHttpFail(String msg) { adminOpenBox data=null; if (!TextUtils.isEmpty(msg)){ Gson gson = new Gson(); data=gson.fromJson(msg,adminOpenBox.class); if (data.getStatus()==1){ List<adminOpenBox.UnitsBean> units=data.getUnits(); getLists(units); }else { } } } @Override protected AdminPresenter createPresenter() { return new AdminPresenter(); } }
適配器java
package com.hatai.smartlokey.modules.admin.adapter; import android.annotation.SuppressLint; import android.content.Context; import android.graphics.Color; import android.support.v4.content.ContextCompat; import android.util.Log; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.BaseAdapter; import android.widget.ImageView; import android.widget.LinearLayout; import android.widget.TextView; import com.bumptech.glide.Glide; import com.hatai.smartlokey.R; import com.hatai.smartlokey.modules.admin.bean.ChannelEntity; import com.hatai.smartlokey.modules.admin.bean.Entity; import com.hatai.smartlokey.modules.admin.reponse.adminOpenBox; import java.util.ArrayList; import java.util.List; /** * Created by administrato on 2017-11-05. */ public class AdminOpenBoxAdapter extends BaseAdapter { private Context mContext; List<adminOpenBox.UnitsBean> lists=new ArrayList<>(); public AdminOpenBoxAdapter(Context mContext, List<adminOpenBox.UnitsBean> lists){ this.mContext = mContext; this.lists= lists; } @Override public int getCount() { return lists.size(); } @Override public adminOpenBox.UnitsBean getItem(int i) { return lists.get(i); } @Override public long getItemId(int i) { return 0; } @SuppressLint({"ResourceAsColor", "ResourceType"}) @Override public View getView(int position, View convertView, ViewGroup viewGroup) { if (convertView == null) { convertView = View.inflate(mContext, R.layout.adapter_admin_openbox, null); } TextView tv_box = (TextView) convertView.findViewById(R.id.tv_box); ImageView iv_box = (ImageView) convertView.findViewById(R.id.iv_box); LinearLayout ll_box=convertView.findViewById(R.id.ll_box); Log.e("tag",getItem(position).isTag()+""); adminOpenBox.UnitsBean item=getItem(position); String door_status=getItem(position).getDoor_status(); String types=getItem(position).getType(); if (door_status.equals("O")){ if (types.equals("L")){ iv_box.setImageResource(R.drawable.big_open); }else if (types.equals("M")){ iv_box.setImageResource(R.drawable.medium_open); }else if (types.equals("S")){ iv_box.setImageResource(R.drawable.small_open); } }else if (door_status.equals("C")) { String status = getItem(position).getStatus(); String type = getItem(position).getType(); if (status .equals("F")) { if (type .equals("L")) { iv_box.setImageResource(R.drawable.big_qujian); } else if (type .equals("M")) { iv_box.setImageResource(R.drawable.medium_qujian); } else if (type .equals("S")) { iv_box.setImageResource(R.drawable.small_qujian); } } else if (status.equals("C")) { if (type .equals("L")) { iv_box.setImageResource(R.drawable.big_shoujian); } else if (type .equals("M")) { iv_box.setImageResource(R.drawable.medium_shoujian); } else if (type .equals("S")) { iv_box.setImageResource(R.drawable.small_shoujian); } } else if (status .equals("FL") || status .equals("CL")) { if (type .equals("L")) { iv_box.setImageResource(R.drawable.big_bug); } else if (type .equals("M")) { iv_box.setImageResource(R.drawable.medium_bug); } else if (type .equals("S")) { iv_box.setImageResource(R.drawable.small_bug); } } else if (status .equals("E")) { if (type .equals("L")) { iv_box.setImageResource(R.drawable.big_null); } else if (type .equals("M")) { iv_box.setImageResource(R.drawable.medium_bug); } else if (type .equals("S")) { iv_box.setImageResource(R.drawable.small_null); } } } if (getItem(position).isTag()==true){ tv_box.setTextColor(ContextCompat.getColor(mContext,R.color.white_FFFFFF)); iv_box.setBackgroundColor(ContextCompat.getColor(mContext,R.color.blue_2196F3)); ll_box.setBackgroundColor(ContextCompat.getColor(mContext,R.color.blue_2196F3)); }else if (getItem(position).isTag()==false){ tv_box.setTextColor(ContextCompat.getColor(mContext,R.color.text_blue)); iv_box.setBackgroundColor(ContextCompat.getColor(mContext,R.color.blue_dibu)); ll_box.setBackgroundColor(ContextCompat.getColor(mContext,R.color.blue_dibu)); } tv_box.setText(getItem(position).getNo()); return convertView; } }
數據android
package com.hatai.smartlokey.modules.admin.presenter; import com.hatai.smartlokey.api.BaseUrl; import com.hatai.smartlokey.base.BasePresent; import com.hatai.smartlokey.modules.admin.view.AdminView; import com.lzy.okgo.OkGo; import com.lzy.okgo.callback.StringCallback; import com.lzy.okgo.model.Response; import org.json.JSONObject; import java.util.HashMap; import static com.hatai.smartlokey.modules.admin.reponse.adminOpenBoxTest.All; /** * Created by administrato on 2017/10/6. */ public class AdminPresenter extends BasePresent<AdminView> { //管理員登陸 public void adminopenById(){ HashMap<String, String> params = new HashMap<>(); params.put("key", ""); params.put("cmd", "adminLoginByPwd"); params.put("mobile", ""); params.put("password",""); JSONObject jsonObject = new JSONObject(params); OkGo.<String>post(BaseUrl.HomeUrl) .tag(this) .upJson(jsonObject) .execute(new StringCallback() { @Override public void onSuccess(Response<String> response) { view.getDataHttp(All); } @Override public void onError(Response<String> response) { view.getDataHttpFail(All); } }); } }
package com.hatai.smartlokey.modules.admin.reponse; /** * Created by administrato on 2017-11-08. */ public interface adminOpenBoxTest { String All="{\n" + " \"status\": 1,\n" + " \"msg\": \"\",\n" + " \"units\": [\n" + " {\n" + " \"no\": \"1\",\n" + " \"code\": \"0x01\",\n" + " \"type\": \"L\",\n" + "\t\t\t\"status\": \"F\",\n" + " \"door_status\": \"C\",\n" + " \"fault\": \"0\"\n" + " },\n" + " {\n" + " \"no\": \"2\",\n" + " \"code\": \"0x02\",\n" + " \"type\": \"M\",\n" + "\t\t\t\"status\": \"FL\",\n" + " \"door_status\": \"C\",\n" + " \"fault\": \"0\"\n" + " },\n" + " {\n" + " \"no\": \"3\",\n" + " \"code\": \"0x03\",\n" + " \"type\": \"S\",\n" + "\t\t\t\"status\": \"C\",\n" + " \"door_status\": \"C\",\n" + " \"fault\": \"0\"\n" + " },\n" + " {\n" + " \"no\": \"4\",\n" + " \"code\": \"0x04\",\n" + " \"type\": \"L\",\n" + "\t\t\t\"status\": \"E\",\n" + " \"door_status\": \"C\",\n" + " \"fault\": \"0\"\n" + " },\n" + " {\n" + " \"no\": \"5\",\n" + " \"code\": \"0x05\",\n" + " \"type\": \"S\",\n" + "\t\t\t\"status\": \"CL\",\n" + " \"door_status\": \"C\",\n" + " \"fault\": \"0\"\n" + " },\n" + " {\n" + " \"no\": \"6\",\n" + " \"code\": \"0x06\",\n" + " \"type\": \"L\",\n" + "\t\t\t\"status\": \"F\",\n" + " \"door_status\": \"O\",\n" + " \"fault\": \"0\"\n" + " }\n" + " ]\n" + "}"; }
big_bug.png
big_null.png
big_open.png
big_qujian.png
medium_bug.png
medium_null.png
big_shoujian.png
medium_open.png
medium_qujian.png
medium_shoujian.png
small_bug.png
small_null.png
small_open.png
small_qujian.png
small_shoujian.pngjson