package com.sl.house_property; import android.app.ProgressDialog; import android.content.Intent; import android.graphics.Color; import android.os.Bundle; import android.view.View; import android.widget.LinearLayout; import com.cutil.ScreenUtils; import com.dalong.refreshlayout.OnRefreshListener; import com.google.gson.Gson; import com.google.gson.internal.LinkedTreeMap; import com.google.gson.reflect.TypeToken; import com.sl.house_property.f1.AddAcarActivity; import com.sl.house_property.f1.AddcararageIttemActivity; import com.sl.house_property.f1.CarragelistActivity; import com.sl.house_property.f1.UserdlistActivity; import com.sl.house_property.databinding.ActivityCarGarageBinding; import com.sl.house_property.databinding.CararageitemBinding; import com.sl.house_property.databinding.CargaraItem2Binding; import com.sl.house_property.databinding.CargaraItemBinding; import org.json.JSONException; import org.json.JSONObject; import java.lang.reflect.Type; import java.util.ArrayList; import java.util.HashMap; import java.util.Map; import adapter.BaseRecycleViewAdapter; import entity.CarEntity; import entity.GarageEntity; import entity.RegisterUser; import my_loader.Loader; import my_loader.Resultcode; import my_view.tao_bao_refresh.FullyGridLayoutManager; import tools.Config; import http.ApiConfig; import rx.Subscription; import rx.functions.Action1; import utils.Md5; public class CarGarageActivity extends BaseActivity { private ArrayList homegridentityvArrayList = new ArrayList<>(); private ArrayList homegridentityvArrayList2 = new ArrayList<>(); private ProgressDialog progressDialog; private Integer resCode = 2000; private OnRefreshListener onrefalshlister = new OnRefreshListener() { @Override public void onRefresh() { getlist(); //getGankList(ApiConfig.GETHOMEBANNER,new HashMap(),getString(R.string.loading),0); mDataBinding.taobaoRefreshLayout.postDelayed(new Runnable() { @Override public void run() { mDataBinding.taobaoRefreshLayout.stopRefresh(true); } }, 10000); } @Override public void onLoadMore() { mDataBinding.taobaoRefreshLayout.postDelayed(new Runnable() { @Override public void run() { mDataBinding.taobaoRefreshLayout.stopLoadMore(true); } }, 1000); } }; private Loader mGankLoader; @Override protected int getLayoutResId() { return R.layout.activity_car_garage; } @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setAbr("车库", new View.OnClickListener() { @Override public void onClick(View view) { finish(); } }, 0, null, 0, null, 0, new View.OnClickListener() { @Override public void onClick(View view) { Intent intent = new Intent(CarGarageActivity.this, UserdlistActivity.class); startActivity(intent); } }, "使用记录"); progressDialog = new ProgressDialog(this); progressDialog.show(); progressDialog.setMessage(this.getString(R.string.loading)); //getGankList(ApiConfig.GETHOMEBANNER,new HashMap(),getString(R.string.loading),0); mDataBinding.taobaoRefreshLayout.setOnRefreshListener(onrefalshlister); intRecycleVerization(); intRecycleVerization2(); getlist(); mDataBinding.fabu.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { Intent intent = null; if ((Config.getInstance(CarGarageActivity.this).getUser() == null)) { intent = new Intent(CarGarageActivity.this, LoginActivity.class); } else { intent = new Intent(CarGarageActivity.this, AddcararageIttemActivity.class); } startActivity(intent); } }); mDataBinding.liulan.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { Intent intent = new Intent(CarGarageActivity.this, CarragelistActivity.class); startActivity(intent); } }); mDataBinding.addcar.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { Intent intent = new Intent(CarGarageActivity.this, AddAcarActivity.class); intent.putExtra("titile", mDataBinding.addcar.getText().toString().replace("+", "").trim()); // startActivity(intent); startActivityForResult(intent,resCode); } }); mDataBinding.addcarager.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { Intent intent = new Intent(CarGarageActivity.this, AddAcarActivity.class); intent.putExtra("titile", mDataBinding.addcarager.getText().toString().replace("+", "").trim()); // startActivity(intent); startActivityForResult(intent,resCode); } }); View topLayout = mDataBinding.topLayout; LinearLayout.LayoutParams bannerLP = (LinearLayout.LayoutParams) topLayout.getLayoutParams(); bannerLP.width = ScreenUtils.getScreenWidth(); bannerLP.height = ScreenUtils.getScreenWidth()*179/436; topLayout.setLayoutParams(bannerLP); } @Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { if(resCode == requestCode && RESULT_OK == resultCode){ getlist(); } } private void getlist() { RegisterUser user = Config.getInstance(this).getUser(); Map map = new HashMap<>(); if (user != null) { map.put("userid", user.getUserid()); } else { map.put("userid", 0 + ""); } map.put("app", "Garage"); map.put("class", "GarageCarList"); map.put("sign", Md5.md5("Garage" + "GarageCarList" + Md5.secret)); getGankList(ApiConfig.BASE_URL, map, getResources().getString(R.string.requsting), 0); } private void intRecycleVerization() { FullyGridLayoutManager mgr = new FullyGridLayoutManager(this, 1); mgr.setOrientation(FullyGridLayoutManager.VERTICAL); mgr.setSmoothScrollbarEnabled(true); mDataBinding.recyView.setLayoutManager(mgr); BaseRecycleViewAdapter baseRecycleViewAdapter = new BaseRecycleViewAdapter(this, R.layout.cargara_item); baseRecycleViewAdapter.setOnBindViewHolder(new BaseRecycleViewAdapter.BindView() { @Override public void onBindViewHolder(Object b, final int position) { if (!(position >= homegridentityvArrayList.size())) { CargaraItemBinding homeGridAdapterItemBinding = (CargaraItemBinding) b; homeGridAdapterItemBinding.setMyentity(homegridentityvArrayList.get(position)); String state = homegridentityvArrayList.get(position).getStatus(); if (state.equals("0")) { homeGridAdapterItemBinding.states.setText("无车"); homeGridAdapterItemBinding.number.setText(""); homeGridAdapterItemBinding.number.setBackgroundColor(Color.TRANSPARENT); } if (state.equals("1")) { homeGridAdapterItemBinding.states.setText("有车"); homeGridAdapterItemBinding.number.setText(homegridentityvArrayList.get(position).getNumber_plate_all()); } homeGridAdapterItemBinding.cagitem.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { /* Intent intent =new Intent(CarGarageActivity.this, MyCaragradetailActivity.class); intent.putExtra("cagitem",homegridentityvArrayList.get(position)); startActivity(intent);*/ } }); } } }); mDataBinding.recyView.setAdapter(baseRecycleViewAdapter); baseRecycleViewAdapter.setData(homegridentityvArrayList); } private void addRecycleVerization(ArrayList list) { BaseRecycleViewAdapter baseRecycleViewAdapter = (BaseRecycleViewAdapter) mDataBinding.recyView.getAdapter(); homegridentityvArrayList = list; baseRecycleViewAdapter.setData(homegridentityvArrayList); } private void getGankList(String myurl, Map map, String msg, final int requstecode) { progressDialog.setMessage(msg); progressDialog.setCancelable(false); progressDialog.show(); mGankLoader = new Loader(); Subscription subscription = mGankLoader.getMovie(myurl, map).subscribe(new Action1() { @Override public void call(Resultcode resultcode) { progressDialog.dismiss(); mDataBinding.taobaoRefreshLayout.stopRefresh(true); mDataBinding.taobaoRefreshLayout.stopLoadMore(true); if (!(resultcode.status == 0)) { setToast(1, resultcode.msg); } if (resultcode.status == 0) { if (requstecode == 0) { Gson gs = new Gson(); LinkedTreeMap adta = (LinkedTreeMap) resultcode.data; String s = gs.toJson(adta); JSONObject jsonObject = null; try { jsonObject = new JSONObject(s); org.json.JSONArray array = jsonObject.getJSONArray("garage"); Type type = new TypeToken>() { }.getType(); ArrayList list = new Gson().fromJson(array.toString(), type); homegridentityvArrayList = list; addRecycleVerization(list); } catch (JSONException e) { e.printStackTrace(); } try { jsonObject = new JSONObject(s); org.json.JSONArray array = jsonObject.getJSONArray("car"); Type type = new TypeToken>() { }.getType(); ArrayList list = new Gson().fromJson(array.toString(), type); homegridentityvArrayList2 = list; addRecycleVerization2(list); } catch (JSONException e) { e.printStackTrace(); } } } } }, new Action1() { @Override public void call(Throwable throwable) { progressDialog.dismiss(); setToast(2, getString(R.string.getdatafailure)); throwable.printStackTrace(); } }); addSubscription(subscription); } private void addRecycleVerization2(ArrayList list) { BaseRecycleViewAdapter baseRecycleViewAdapter = (BaseRecycleViewAdapter) mDataBinding.recyView2.getAdapter(); homegridentityvArrayList2 = list; baseRecycleViewAdapter.setData(homegridentityvArrayList2); } private void intRecycleVerization2() { FullyGridLayoutManager mgr = new FullyGridLayoutManager(this, 1); mgr.setOrientation(FullyGridLayoutManager.VERTICAL); mgr.setSmoothScrollbarEnabled(true); mDataBinding.recyView2.setLayoutManager(mgr); BaseRecycleViewAdapter baseRecycleViewAdapter = new BaseRecycleViewAdapter(this, R.layout.cargara_item2); baseRecycleViewAdapter.setOnBindViewHolder(new BaseRecycleViewAdapter.BindView() { @Override public void onBindViewHolder(Object b, final int position) { if (!(position >= homegridentityvArrayList2.size())) { CargaraItem2Binding homeGridAdapterItemBinding = (CargaraItem2Binding) b; homeGridAdapterItemBinding.setMyentity(homegridentityvArrayList2.get(position)); //String state= homegridentityvArrayList2.get(position).getStatus(); // if(state.equals("0")) { homeGridAdapterItemBinding.states.setText(homegridentityvArrayList2.get(position).getName()); homeGridAdapterItemBinding.number.setText(homegridentityvArrayList2.get(position).getPlate_first() + homegridentityvArrayList2.get(position).getNumber_plate()); } homeGridAdapterItemBinding.cagitem.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { /* Intent intent =new Intent(CarGarageActivity.this, MyCaragradetailActivity.class); intent.putExtra("cagitem",homegridentityvArrayList.get(position)); startActivity(intent);*/ } }); } } }); mDataBinding.recyView2.setAdapter(baseRecycleViewAdapter); baseRecycleViewAdapter.setData(homegridentityvArrayList); } }