package com.jiuqi.njt.management.task; import android.app.Activity; import android.app.Dialog; import android.graphics.drawable.Drawable; import android.os.AsyncTask; import android.util.Log; import android.view.View; import android.widget.Button; import android.widget.TextView; import com.jiuqi.mobile.nigo.comeclose.bean.app.file.CollectionBean; import com.jiuqi.mobile.nigo.comeclose.manager.file.ICollectionManager; import com.jiuqi.mobile.nigo.comeclose.ws.client.ClientContext; import com.jiuqi.njt.R; import com.jiuqi.njt.data.MyApp; import com.jiuqi.njt.model.TableRawItem; import com.jiuqi.njt.util.Constants; import com.jiuqi.njt.util.RepairUtils; import com.jiuqi.njt.util.UIUtil; /** * 收藏维修点 (或者取消收藏) * * */ public class AddOrDeleteFavorTask extends AsyncTask<Void, Void, Boolean> { private Activity activity; private MyApp application; private Dialog pd = null; private String message; private CollectionBean collectionBean; private View view ; public AddOrDeleteFavorTask(Activity con, CollectionBean collectionBean,boolean favorOrNo,View v) { super(); this.activity = con; this.application = (MyApp) con.getApplication(); this.collectionBean = collectionBean; this.view = v; } @Override protected void onPreExecute() { // TODO Auto-generated method stub super.onPreExecute(); pd = RepairUtils.myShowDialog(activity, 4); message =""; } @Override protected Boolean doInBackground(Void... params) { // TODO Auto-generated method stub try { ClientContext context = application.getClientContext(); if (null == context) { context = ClientContext.getClientContext(Constants.SERVER_URL, Constants.ANONYMOUS, Constants.ANONYMOUS); application.setClientContext(context); } ICollectionManager collectionManager = context.getManager(ICollectionManager.class); String result = collectionManager.createCollection(collectionBean); message = result; return true; } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); message = "失败"; } return false; } @Override protected void onPostExecute(Boolean result) { // TODO Auto-generated method stub super.onPostExecute(result); RepairUtils.myRemoveDialog(pd); if(!"".equals(message)){ UIUtil.showMsg(activity, message); } if ("收藏成功".equals(message)) { // Drawable drawable = activity.getResources().getDrawable(R.drawable.poi_shoucang_new_pressed); // ((TextView) view).setCompoundDrawables(null, null,drawable, null); // ((TextView) view).setBackgroundResource(R.color.red); ((TextView) view).setBackgroundResource(R.drawable.poi_shoucang_new_pressed); }else if("取消收藏成功".equals(message)) { // view.setBackgroundResource(R.drawable.poi_shoucang_new); ((TextView) view).setBackgroundResource(R.drawable.poi_shoucang_new); } } }