packagecom.tfot.hotel.yichengyiyu.Activity.zhou_activity;importandroid.content.Intent;importandroid.os.Bundle;importandroid.support.annotation.Nullable;importandroid.view.View;importandroid.widget.AdapterView;importandroid.widget.ImageView;importandroid.widget.ListView;importcom.squareup.okhttp.Call;importcom.squareup.okhttp.FormEncodingBuilder;importcom.squareup.okhttp.OkHttpClient;importcom.squareup.okhttp.Request;importcom.squareup.okhttp.RequestBody;importcom.squareup.okhttp.Response;importcom.tfot.hotel.yichengyiyu.Activity.NewActivivty.XiangQingActivity;importcom.tfot.hotel.yichengyiyu.Activity.NewActivivty.XiangQingActivity_Long;importcom.tfot.hotel.yichengyiyu.Activity.zhou_activity.adapter.ChaXunJieGuoAdapter;importcom.tfot.hotel.yichengyiyu.Activity.zhou_activity.bean.ChaXunJieGuo;importcom.tfot.hotel.yichengyiyu.R;importcom.tfot.hotel.yichengyiyu.Util.Common;importcom.tfot.hotel.yichengyiyu.Util.base.BaseActivity;importorg.json.JSONArray;importorg.json.JSONException;importorg.json.JSONObject;importjava.io.IOException;importjava.util.ArrayList;importjava.util.List;importrx.Observable;importrx.Observer;importrx.Subscriber;importrx.Subscription;importrx.android.schedulers.AndroidSchedulers;importrx.schedulers.Schedulers;importrx.subscriptions.CompositeSubscription;/*** 查询结果界面
* Created by huizhou on 2017/6/26.*/
public class ChaXunJieGuoActivity extendsBaseActivity {private List chaXunJieGuoList=new ArrayList<>(); //查询结果数据源
private String changOrduang ;//CONDITION 判断长租或者短租的字符串
private Boolean yeOrNo = false ;//查询内容是否存在
privateString sousuoneiron;privateListView activity_chaxunjieguo_list;privateImageView activivty_chaxunjieguo_fanhuui;privateChaXunJieGuoAdapter chaXunJieGuoAdapter;privateView kongbaiye_sousuo;private CompositeSubscription mCompositeSubscription;//第三方线程
private final OkHttpClient client = newOkHttpClient();
@Overrideprotected voidonCreate(@Nullable Bundle savedInstanceState) {super.onCreate(savedInstanceState);
setContentView(R.layout.activity_chaxunjieguo_l);
Intent intent=getIntent();
Bundle bundle=intent.getExtras();//.getExtras()得到intent所附带的额外数据
changOrduang = bundle.getString("changOrduang");
sousuoneiron= bundle.getString("sousuojieguoneiron");
initData();
}private voidinitData() {
mCompositeSubscription= new CompositeSubscription(); //第三方线程
activity_chaxunjieguo_list=(ListView) findViewById(R.id.activity_chaxunjieguo_list);
activivty_chaxunjieguo_fanhuui=(ImageView) findViewById(R.id.activivty_chaxunjieguo_fanhuui);
kongbaiye_sousuo= findViewById(R.id.kongbaiye_sousuo); //空白页
chaxunjieguo(sousuoneiron);
chaXunJieGuoAdapter= new ChaXunJieGuoAdapter(ChaXunJieGuoActivity.this,chaXunJieGuoList);
activity_chaxunjieguo_list.setAdapter(chaXunJieGuoAdapter);
activity_chaxunjieguo_list.setOnItemClickListener(newAdapterView.OnItemClickListener() {
@Overridepublic void onItemClick(AdapterView> parent, View view, int position, longid) {//TODO 查询条目跳转
Intent intent =null;if(changOrduang.equals("day")){
intent= new Intent(ChaXunJieGuoActivity.this, XiangQingActivity.class); //短租的房间详情页
}else if(changOrduang.equals("long")){
intent= new Intent(ChaXunJieGuoActivity.this, XiangQingActivity_Long.class); //长租的房间详情页
}
Bundle bundle= newBundle();
bundle.putString("RoomStyleId",chaXunJieGuoList.get(position).getRoomStyleId());
bundle.putString("Brandname",chaXunJieGuoList.get(position).getBrandname());
intent.putExtras(bundle);
startActivity(intent);
}
});
activivty_chaxunjieguo_fanhuui.setOnClickListener(newView.OnClickListener() {
@Overridepublic voidonClick(View v) {
finish();
}
});
}//查询结果的的网路连接
private void chaxunjieguo(finalString chaxuneironB){
Subscription subscription= Observable.create(new Observable.OnSubscribe() {
@Overridepublic void call(Subscriber super String>subscriber) {
RequestBody formBody= newFormEncodingBuilder()
.add("ACT", "likesearch")
.add("CONDITION",changOrduang)
.add("content",chaxuneironB)
.build();final Request request = newRequest.Builder()
.url(Common.NEW_CHAXUNJIEGUO)
.post(formBody)
.build();
Call call=client.newCall(request);try{
Response response=call.execute();
subscriber.onNext(response.body().string());
subscriber.onCompleted();
}catch(IOException e) {
e.printStackTrace();
}
}
}).subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(new Observer() {
@Overridepublic voidonCompleted() {
}
@Overridepublic voidonError(Throwable e) {
}
@Overridepublic voidonNext(String s) {//原生解析
try{
JSONArray array= newJSONArray(s);
chaXunJieGuoList.clear();for (int i = 0; i < array.length(); i++) {
JSONObject temp=(JSONObject) array.get(i);
String RoomStyleId=temp.getString("RoomStyleId");
String Unitprice=temp.getString("Unitprice");
String evaluate=temp.getString("evaluate");
JSONObject banner=temp.getJSONObject("Brand");
String Brandname=banner.getString("Brandname");
JSONArray jsonArray=temp.getJSONArray("RoomStyleImage");
ArrayList RoomStyleImage=new ArrayList();for (int i2=0;i2
String a= Common.BASIC_IC_API+jsonArray.get(i).toString();
RoomStyleImage.add(a);
}
String RoomStyleAddres=temp.getString("RoomStyleAddres");
String Roomlongrentom=temp.getString("Roomlongrentom");
String RoomStyleName= temp.getString("RoomStyleName");
String RoomStar= temp.getString("RoomStar");
ChaXunJieGuo chaXunJieGuoData= newChaXunJieGuo(RoomStyleId,Unitprice,
evaluate, Brandname,RoomStyleImage,RoomStyleAddres,Roomlongrentom,RoomStyleName,RoomStar);
chaXunJieGuoList.add(chaXunJieGuoData);
}if(!chaXunJieGuoList.isEmpty()){
kongbaiye_sousuo.setVisibility(View.GONE);
activity_chaxunjieguo_list.setVisibility(View.VISIBLE);
}else{
kongbaiye_sousuo.setVisibility(View.VISIBLE);
activity_chaxunjieguo_list.setVisibility(View.GONE);
}
}catch(JSONException e) {
e.printStackTrace();
}
chaXunJieGuoAdapter.notifyDataSetChanged();
}
});
mCompositeSubscription.add(subscription);
}
}