package com.jiuqi.njt.management.task;
import java.util.ArrayList;
import android.app.Activity;
import android.app.Dialog;
import android.os.AsyncTask;
import com.jiuqi.mobile.nigo.comeclose.bean.LoadOnGetList;
import com.jiuqi.mobile.nigo.comeclose.bean.app.collect.DealerServiceBean;
import com.jiuqi.mobile.nigo.comeclose.bean.app.collect.DrivingSchoolServiceBean;
import com.jiuqi.mobile.nigo.comeclose.bean.app.collect.GasStationServiceBean;
import com.jiuqi.mobile.nigo.comeclose.bean.app.collect.RepairServiceBean;
import com.jiuqi.mobile.nigo.comeclose.bean.app.collect.ServiceCollectBean;
import com.jiuqi.mobile.nigo.comeclose.bean.base.AdminAreaBean;
import com.jiuqi.mobile.nigo.comeclose.manager.app.IServiceCollectManager;
import com.jiuqi.mobile.nigo.comeclose.manager.app.SelectServiceKey;
import com.jiuqi.mobile.nigo.comeclose.ws.client.ClientContext;
import com.jiuqi.njt.data.MyApp;
import com.jiuqi.njt.management.FregmentWorkRepair.WhenTaskFinish;
import com.jiuqi.njt.util.Constants;
import com.jiuqi.njt.widget.ProgressDialogStyle;
/**
* 查询服务网点服务机构异步类
* @author
*
*/
public class GetQueryResultAsyncTask extends
AsyncTask<Void, Void, ArrayList<ServiceCollectBean>> {
@SuppressWarnings("rawtypes")
private Class[] clz = new Class[] { RepairServiceBean.class,
GasStationServiceBean.class, DealerServiceBean.class,
DrivingSchoolServiceBean.class }; // 服务网点和服务机构查询类型
private Dialog pd = null;
private Activity context;
private MyApp application;
private boolean isFirst;
private SelectServiceKey key;
private AdminAreaBean xzqh; // 所在地
private int idxInfoType;
private WhenTaskFinish taskFinish;
public GetQueryResultAsyncTask(Activity context,
boolean isFirst, SelectServiceKey key, AdminAreaBean xzqh,
int idxInfoType,WhenTaskFinish taskFinish) {
super();
this.context = context;
this.application = (MyApp) context.getApplication();
this.isFirst = isFirst;
this.key = key;
this.xzqh = xzqh;
this.idxInfoType = idxInfoType;
this.taskFinish = taskFinish;
}
@Override
protected void onPreExecute() {
if (isFirst) {
pd = ProgressDialogStyle.createLoadingDialog(context, null);
pd.show();
isFirst = false;
}
}
@SuppressWarnings("unchecked")
@Override
protected ArrayList<ServiceCollectBean> doInBackground(Void... params) {
ArrayList<ServiceCollectBean> seviceCollectList = new ArrayList<ServiceCollectBean>();
LoadOnGetList<? extends ServiceCollectBean> jobnewslist = new LoadOnGetList<ServiceCollectBean>();
try {
ClientContext context = application.getClientContext();
if (!application.getIsLogin()) {
context = null;
}
if (null == context) {
context = ClientContext.getClientContext(Constants.SERVER_URL,
Constants.ANONYMOUS, Constants.ANONYMOUS);
application.setClientContext(context);
}
long code = 0;
if (null != xzqh) {
code = xzqh.getCode();
} else {
code = 0;
}
key.setAdminAreaCode(code);
IServiceCollectManager manager = context
.getManager(IServiceCollectManager.class);
if (clz[idxInfoType] == DrivingSchoolServiceBean.class) {
key.setRoleCode(15);
}
jobnewslist = manager.getLoad(clz[idxInfoType], key);
seviceCollectList = (ArrayList<ServiceCollectBean>) jobnewslist
.getList();
} catch (Exception e) {
if(null!=pd){
pd.dismiss();
}
e.printStackTrace();
}
return seviceCollectList;
}
@Override
protected void onPostExecute(ArrayList<ServiceCollectBean> result) {
// initUI(result);
// onLoad();
if (null != pd) {
pd.dismiss();
}
taskFinish.taskFinished(result);
}
}