消息推送业务逻辑处理 “MessageUI”

package com.xunpige.myapplication.ui; import android.app.Activity; import android.content.Context; import android.content.Intent; 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.BaseAdapter; import android.widget.ImageButton; import android.widget.ListView; import android.widget.TextView; import com.lidroid.xutils.ViewUtils; import com.lidroid.xutils.view.annotation.ViewInject; import com.umeng.analytics.MobclickAgent; import com.xunpige.myapplication.R; import com.xunpige.myapplication.bean.NotificationHistory; import com.xunpige.myapplication.ui.base.BaseApplication; import com.xunpige.myapplication.ui.base.BaseUI; import com.xunpige.myapplication.utils.ToastUtils; import com.xunpige.myapplication.utils.VersionNameUtils; import org.json.JSONException; import org.json.JSONObject; import org.litepal.crud.DataSupport; import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.Collections; import java.util.Date; import java.util.List; /** * Created by Administrator on 2016/1/11 0011. * * @author: crs * @Project: XunPiGe * @Package: com.xunpige.myapplication.ui * @Date: 2016年02月28日 16:51 * @Version: V1.0 */ public class MessageUI extends BaseUI implements AdapterView.OnItemClickListener { @ViewInject(R.id.tv_title) private TextView tv_title; @ViewInject(R.id.ib_back) private ImageButton ib_back; @ViewInject(R.id.lv_message) private ListView lv_message; private double code_client; private double code_service; private List mList = new ArrayList<>(); @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_message); ViewUtils.inject(this); initView(); initListener(); } private void initView() { tv_title.setText("消息"); ib_back.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { finish(); } }); //查询数据库的操作 mList = DataSupport.findAll(NotificationHistory.class); //把集合里面的数据进行倒序排列 Collections.reverse(mList); if (mList != null && mList.size() > 0) { MessageAdapter messageAdapter = new MessageAdapter(this, mList); lv_message.setAdapter(messageAdapter); } } private void initListener() { lv_message.setOnItemClickListener(this); } @Override public void onItemClick(AdapterView parent, View view, int position, long id) { NotificationHistory notificationHistory = mList.get(position); //点击后直接删除通知 notificationHistory.delete(); String model = notificationHistory.getModel(); if (!TextUtils.isEmpty(model)) { //如果获取的是报价信息 if ("offer".equals(model)) { String contentDetails = notificationHistory.getContentDetails(); //可能会出现 JSONException JSONObject jsonObject = null; try { jsonObject = new JSONObject(contentDetails); JSONObject offer = (JSONObject) jsonObject.get("offer"); String offer_price_id = offer.get("id") + ""; Intent intent = new Intent(MessageUI.this, OfferPriceDetailgetUI.class); intent.putExtra("offerPrice_id", offer_price_id); startActivity(intent); } catch (JSONException e) { e.printStackTrace(); } } else if ("order".equals(model)) { String contentDetails = notificationHistory.getContentDetails(); try { JSONObject jsonObject = new JSONObject(contentDetails); JSONObject order = (JSONObject) jsonObject.get("order"); //订单id String order_id = order.get("id") + ""; boolean user_flag = (boolean) order.get("user_flag"); String order_type = (String) order.get("order_type"); //跳转到收样订单 if (true == user_flag && "sample".equals(order_type)) { Intent intent = new Intent(MessageUI.this, OrderGetSampleDetailsUI.class); intent.putExtra("order_id", order_id); startActivity(intent); //跳转到收货订单 } else if (true == user_flag && "goods".equals(order_type)) { Intent intent = new Intent(MessageUI.this, OrderGetGoodsDetailsUI.class); intent.putExtra("order_id", order_id); startActivity(intent); //跳转到发货订单 } else if (false == user_flag && "goods".equals(order_type)) { Intent intent = new Intent(MessageUI.this, OrderSendGoodsDetailsUI.class); intent.putExtra("order_id", order_id); startActivity(intent); //跳转到寄样订单 } else if (false == user_flag && "sample".equals(order_type)) { Intent intent = new Intent(MessageUI.this, OrderSendSampleDetailsUI.class); intent.putExtra("order_id", order_id); startActivity(intent); } } catch (JSONException e) { e.printStackTrace(); } //如果是全局推送 } else if ("recommend".equals(model)) { String contentDetails = notificationHistory.getContentDetails(); try { JSONObject jsonObject = new JSONObject(contentDetails); JSONObject recommend = (JSONObject) jsonObject.get("recommend"); String type = (String) recommend.get("type"); if ("wants".equals(type)) { //获取需求id String want_id = recommend.get("id") + ""; Intent intent = new Intent(MessageUI.this, WantsDetailsUI.class); intent.putExtra("detailId", want_id); intent.putExtra("to", ""); startActivity(intent); } } catch (JSONException e) { e.printStackTrace(); } } else if ("soft".equals(model)) { String contentDetails = notificationHistory.getContentDetails(); try { JSONObject jsonObject = new JSONObject(contentDetails); //全局推送 版本更新功能 JSONObject soft = (JSONObject) jsonObject.get("soft"); String url = (String) soft.get("url"); String version_code = (String) soft.get("version_code"); String versionName = VersionNameUtils.getVersionName(MessageUI.this); if (!TextUtils.isEmpty(version_code)) { code_service = Double.parseDouble(version_code); } if (!TextUtils.isEmpty(versionName)) { code_client = Double.parseDouble(versionName); } if (code_client > code_service || code_client == code_service) { return; } else { Intent intent = new Intent(MessageUI.this, BannerDetailUI.class); intent.putExtra("sliderUrl", url); startActivity(intent); } } catch (JSONException e) { e.printStackTrace(); } } } } private class MessageAdapter extends BaseAdapter { private Context mContext; private List mList; public MessageAdapter(Context mContext, List mList) { this.mContext = mContext; this.mList = mList; } @Override public int getCount() { return mList.size(); } @Override public Object getItem(int position) { return null; } @Override public long getItemId(int position) { return 0; } @Override public View getView(int position, View convertView, ViewGroup parent) { View v = LayoutInflater.from(MessageUI.this).inflate(R.layout.item_message, null); TextView tv_body = (TextView) v.findViewById(R.id.tv_body); NotificationHistory notificationHistory = mList.get(position); String body = notificationHistory.getBody(); if (!TextUtils.isEmpty(body)) { tv_body.setText(body); } return v; } } @Override protected void onResume() { super.onResume(); MobclickAgent.onResume(this); } @Override protected void onPause() { super.onPause(); MobclickAgent.onResume(this); } }

你可能感兴趣的:(消息推送业务逻辑处理 “MessageUI”)