package com.yeshi.ec.rebate.myapplication.ui.main;
|
|
import android.content.Context;
|
import android.content.Intent;
|
import android.content.SharedPreferences;
|
import android.content.pm.PackageInfo;
|
import android.content.pm.PackageManager;
|
import android.graphics.Color;
|
import android.graphics.drawable.AnimationDrawable;
|
import android.os.Build;
|
import android.os.Bundle;
|
import android.provider.Settings;
|
import android.support.v4.widget.SwipeRefreshLayout;
|
import android.support.v7.widget.LinearLayoutCompat;
|
import android.support.v7.widget.LinearLayoutManager;
|
import android.support.v7.widget.RecyclerView;
|
import android.view.LayoutInflater;
|
import android.view.View;
|
import android.view.Window;
|
import android.view.WindowManager;
|
import android.widget.FrameLayout;
|
import android.widget.ImageView;
|
import android.widget.LinearLayout;
|
import android.widget.TextView;
|
import android.widget.Toast;
|
|
import com.google.gson.Gson;
|
import com.google.gson.GsonBuilder;
|
import com.google.gson.reflect.TypeToken;
|
import com.wpc.library.content.ConnectivityChangeHelper;
|
import com.wpc.library.recyclerviewhelper.DividerItemDecoration;
|
import com.wpc.library.util.NetUtils;
|
import com.wpc.library.util.cache.DiskLruCache;
|
import com.wpc.library.util.common.DimenUtils;
|
import com.wpc.library.util.common.StorageUtils;
|
import com.wpc.library.widget.MyListView;
|
import com.yeshi.ec.rebate.myapplication.BasicTextHttpResponseHandler;
|
import com.yeshi.ec.rebate.myapplication.R;
|
import com.yeshi.ec.rebate.myapplication.ShoppingApi;
|
import com.yeshi.ec.rebate.myapplication.callBack.MessagePush;
|
import com.yeshi.ec.rebate.myapplication.contract.MessgeContract;
|
import com.yeshi.ec.rebate.myapplication.entity.CommonList;
|
import com.yeshi.ec.rebate.myapplication.entity.MainMessage;
|
import com.yeshi.ec.rebate.myapplication.entity.UserMessage;
|
import com.yeshi.ec.rebate.myapplication.presenter.MessgePresenter;
|
import com.yeshi.ec.rebate.myapplication.ui.dialog.RedPacketHintDialog;
|
import com.yeshi.ec.rebate.myapplication.ui.message.AppMailActivity;
|
import com.yeshi.ec.rebate.myapplication.ui.message.IDeleteMessageListener;
|
import com.yeshi.ec.rebate.myapplication.ui.message.MainMessageAdapter;
|
import com.yeshi.ec.rebate.myapplication.ui.message.SystemMessageActivity;
|
import com.yeshi.ec.rebate.myapplication.ui.message.UserMessageActivity;
|
import com.yeshi.ec.rebate.myapplication.ui.recommend.MessagelistAdapter;
|
import com.yeshi.ec.rebate.myapplication.util.umengCustomEvent.MessageCustomEvent;
|
import com.yeshi.ec.rebate.myapplication.util.user.LoginAndInviteStatusUtil;
|
import com.yeshi.ec.rebate.myapplication.util.user.UserUtil;
|
import com.yeshi.ec.rebate.myapplication.view.BaseFragment;
|
|
import org.apache.http.Header;
|
import org.json.JSONArray;
|
import org.json.JSONException;
|
import org.json.JSONObject;
|
|
import java.io.File;
|
import java.io.IOException;
|
import java.text.ParseException;
|
import java.util.ArrayList;
|
import java.util.Date;
|
import java.util.List;
|
|
|
/**
|
* 消息页面
|
*/
|
public class MessageFragment extends BaseFragment<MessgeContract.MessgeView, MessgePresenter> implements MessgeContract.MessgeView, View.OnClickListener, MessagePush {
|
|
private TextView tv_middle, tv_top_bar_right, tv_no_data_hint;
|
private ImageView iv_top_bar_clear;
|
private SwipeRefreshLayout srl_message;
|
private RecyclerView rv_message;
|
|
private View bottom;
|
private ImageView iv_loading, iv_no_data;
|
private TextView tv_loading;
|
|
/*
|
消息分类
|
*/
|
private FrameLayout fl_order_notice;
|
private FrameLayout fl_capital_notice;
|
private FrameLayout fl_account_notice;
|
private FrameLayout fl_invite_notice;
|
private FrameLayout fl_other_msg;
|
private LinearLayout ll_order_notice_num;
|
private LinearLayout ll_capital_notice_num;
|
private LinearLayout ll_account_notice_num;
|
private LinearLayout ll_invite_notice_num;
|
private LinearLayout ll_other_msg_num;
|
private TextView tv_order_notice_num;
|
private TextView tv_capital_notice_num;
|
private TextView tv_account_notice_num;
|
private TextView tv_invite_notice_num;
|
private TextView tv_other_msg_num;
|
private LinearLayout ll_critical_notice;//系统消息布局
|
private ImageView iv_critical_msg_img;
|
private ImageView iv_critical_msg_grade;
|
private TextView tv_critical_msg_title;
|
private TextView tv_critical_msg_time;
|
private TextView tv_critical_msg_content;
|
private TextView iv_red_dot;//系统消息红点
|
//公告
|
private LinearLayoutCompat ll_critical_announce;//公告布局
|
private TextView ll_critical_announce_title;//标题
|
private TextView ll_critical_announce_time;//时间
|
private TextView ll_critical_announce_content;//公告内容
|
private ImageView ll_critical_announce_reddot;//红点
|
private ImageView ll_critical_announce_img;//公告图片
|
//Topview listview
|
private MyListView ll_critical_list;//listview
|
|
|
private boolean isLoad = false;
|
public int mPage = 1;
|
public int count = 0;
|
List<MainMessage> mList;
|
MainMessageAdapter adapter;
|
|
private ConnectivityChangeHelper mChangeHelper;
|
private LinearLayout ll_no_net, ll_no_data, ll_request_failture;
|
|
private SharedPreferences sp;
|
private SharedPreferences spkefu;
|
private boolean isChoice = false;//表示已经点击过按钮
|
private int iscategory = 0;//表示 选择的按钮类型
|
private MessagelistAdapter messagelistAdapter;
|
private DiskLruCache cache;
|
|
|
@Override
|
protected int initFragmentView() {
|
return R.layout.fragment_message;
|
}
|
|
@Override
|
protected void initFragmentChildView(View view) {
|
try {
|
cache = DiskLruCache.open(
|
new File(StorageUtils.getCacheDirectory(getContext())
|
.toString(), "http"), getVersionNum(getContext()),
|
1, 1024 * 1024);
|
} catch (IOException e) {
|
e.printStackTrace();
|
}
|
initView(view);
|
addListener();
|
spkefu = getActivity().getSharedPreferences("kefurecord", Context.MODE_PRIVATE);//是否打开过客服 记录
|
if (sp.getBoolean("isLogin", false)) {//登陆显示消息中心红包弹窗
|
getMSGConfig();//消息中心红包
|
}
|
}
|
|
@Override
|
protected void initFragmentData(Bundle savedInstanceState) {
|
|
}
|
|
@Override
|
protected MessgePresenter createPresenter() {
|
return new MessgePresenter(getActivity());
|
}
|
|
|
private int getVersionNum(Context context) {
|
try {
|
PackageInfo pi = context.getPackageManager().getPackageInfo(
|
context.getPackageName(), 0);
|
return pi.versionCode;
|
} catch (PackageManager.NameNotFoundException e) {
|
e.printStackTrace();
|
return 1;
|
}
|
}
|
|
private void initView(View view) {
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
|
Window window = getActivity().getWindow();
|
window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
|
window.getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
|
| View.SYSTEM_UI_FLAG_LAYOUT_STABLE);
|
window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
|
window.setStatusBarColor(Color.TRANSPARENT);
|
int result = 0;
|
int resourceId = getActivity().getResources().getIdentifier("status_bar_height",
|
"dimen", "android");
|
if (resourceId > 0) {
|
result = getActivity().getResources().getDimensionPixelSize(resourceId);
|
}
|
//设置状态栏文字颜色及图标为深色
|
getActivity().getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR);
|
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,
|
result);
|
view.findViewById(R.id.v_status_bar).setLayoutParams(params);
|
} else {
|
view.findViewById(R.id.v_status_bar).setVisibility(View.GONE);
|
}
|
tv_middle = view.findViewById(R.id.tv_top_bar_middle);
|
iv_top_bar_clear = view.findViewById(R.id.iv_top_bar_clear);
|
tv_top_bar_right = view.findViewById(R.id.tv_top_bar_right);
|
srl_message = view.findViewById(R.id.srl_message);
|
rv_message = view.findViewById(R.id.rv_message);
|
srl_message.setColorSchemeColors(getResources().getColor(R.color.theme));
|
rv_message.setLayoutManager(new LinearLayoutManager(rv_message.getContext()));
|
DividerItemDecoration decoration = new DividerItemDecoration();
|
decoration.setSize(DimenUtils.dip2px(rv_message.getContext(), 5));
|
rv_message.addItemDecoration(decoration);
|
|
mList = new ArrayList<>();
|
adapter = new MainMessageAdapter(rv_message.getContext(), mList, new IDeleteMessageListener() {
|
@Override
|
public void delete(final UserMessage msg) {
|
if (LoginAndInviteStatusUtil.acessNext(getContext(), UserUtil.getUid(getContext()) + "", true)) {
|
ShoppingApi.deleteMsg(getContext(), UserUtil.getUid(getContext()) + "", msg.getType(), msg.getId(), new BasicTextHttpResponseHandler() {
|
@Override
|
public void onSuccessPerfect(int statusCode, Header[] headers, JSONObject jsonObject) throws Exception {
|
super.onSuccessPerfect(statusCode, headers, jsonObject);
|
if (jsonObject.optInt("code") == 0) {
|
for (int i = 0; i < mList.size(); i++) {
|
if (mList.get(i).getUserMsg() != null && msg.getId().equalsIgnoreCase(mList.get(i).getUserMsg().getId()) && msg.getType().equalsIgnoreCase(mList.get(i).getUserMsg().getType())) {
|
mList.remove(i);
|
adapter.notifyDataSetChanged();
|
Toast.makeText(getContext(), "删除成功", Toast.LENGTH_SHORT).show();
|
break;
|
}
|
|
}
|
|
} else {
|
Toast.makeText(getContext(), jsonObject.optString("msg"), Toast.LENGTH_SHORT).show();
|
}
|
}
|
|
@Override
|
public void onFailure(int statusCode, Header[] headers, String jsonObject, Throwable e) {
|
super.onFailure(statusCode, headers, jsonObject, e);
|
Toast.makeText(getContext(), "网络连接出错", Toast.LENGTH_SHORT).show();
|
}
|
});
|
}
|
|
}
|
});
|
rv_message.setAdapter(adapter);
|
|
bottom = LayoutInflater.from(rv_message.getContext()).inflate(R.layout.item_recyclerview_bottom, null);
|
tv_loading = bottom.findViewById(R.id.tv_loading);
|
iv_loading = bottom.findViewById(R.id.iv_loading);
|
AnimationDrawable animationDrawable = (AnimationDrawable) getResources().getDrawable(
|
R.drawable.anim_list_loading);
|
iv_loading.setImageDrawable(animationDrawable);
|
animationDrawable.start();
|
// Glide.with(this).load(R.drawable.gif_loading).into(iv_loading);
|
bottom.setVisibility(View.GONE);
|
View top = LayoutInflater.from(rv_message.getContext()).inflate(R.layout.item_message_top, null);
|
fl_order_notice = top.findViewById(R.id.fl_order_notice);
|
fl_capital_notice = top.findViewById(R.id.fl_capital_notice);
|
fl_account_notice = top.findViewById(R.id.fl_account_notice);
|
fl_invite_notice = top.findViewById(R.id.fl_invite_notice);
|
fl_other_msg = top.findViewById(R.id.fl_other_msg);
|
ll_order_notice_num = top.findViewById(R.id.ll_order_notice_num);
|
ll_capital_notice_num = top.findViewById(R.id.ll_capital_notice_num);
|
ll_account_notice_num = top.findViewById(R.id.ll_account_notice_num);
|
ll_invite_notice_num = top.findViewById(R.id.ll_invite_notice_num);
|
ll_other_msg_num = top.findViewById(R.id.ll_other_msg_num);
|
tv_order_notice_num = top.findViewById(R.id.tv_order_notice_num);
|
tv_capital_notice_num = top.findViewById(R.id.tv_capital_notice_num);
|
tv_account_notice_num = top.findViewById(R.id.tv_account_notice_num);
|
tv_invite_notice_num = top.findViewById(R.id.tv_invite_notice_num);
|
tv_other_msg_num = top.findViewById(R.id.tv_other_msg_num);
|
ll_critical_notice = top.findViewById(R.id.ll_critical_notice);
|
iv_critical_msg_img = top.findViewById(R.id.iv_critical_msg_img);
|
iv_critical_msg_grade = top.findViewById(R.id.iv_critical_msg_grade);
|
tv_critical_msg_title = top.findViewById(R.id.tv_critical_msg_title);
|
tv_critical_msg_time = top.findViewById(R.id.tv_critical_msg_time);
|
tv_critical_msg_content = top.findViewById(R.id.tv_critical_msg_content);
|
iv_red_dot = top.findViewById(R.id.iv_red_dot);
|
ll_critical_notice.setVisibility(View.GONE);//系统消息
|
ll_critical_list = top.findViewById(R.id.ll_critical_list);
|
ll_critical_list.getFocusedChild();
|
//公告
|
ll_critical_announce = top.findViewById(R.id.ll_critical_announce);//公告布局
|
ll_critical_announce_title = top.findViewById(R.id.ll_critical_announce_title);//标题
|
ll_critical_announce_time = top.findViewById(R.id.ll_critical_announce_time);//时间
|
ll_critical_announce_content = top.findViewById(R.id.ll_critical_announce_content);//公告内容
|
ll_critical_announce_reddot = top.findViewById(R.id.ll_critical_announce_reddot);//红点
|
ll_critical_announce_img = top.findViewById(R.id.ll_critical_announce_img);//公告图片
|
ll_critical_announce.setOnClickListener(this);
|
//------------------------------------------
|
adapter.addHeaderView(top);
|
adapter.addFooterView(bottom);
|
//注册 eventbus
|
// EventBus.getDefault().register(this);
|
//注册 主页消息推送传播接口
|
((MainActivity) getActivity()).setMessagePush(this);
|
|
sp = getActivity().getSharedPreferences("user", Context.MODE_PRIVATE);
|
ll_no_net = view.findViewById(R.id.ll_no_net);
|
ll_no_data = view.findViewById(R.id.ll_no_data);
|
ll_request_failture = view.findViewById(R.id.ll_request_failture);
|
tv_no_data_hint = view.findViewById(R.id.tv_no_data_hint);
|
iv_no_data = view.findViewById(R.id.iv_no_data);
|
tv_no_data_hint.setText("还没有消息~");
|
iv_no_data.setImageDrawable(getActivity().getResources().getDrawable(R.drawable.ic_no_friends));
|
view.findViewById(R.id.tv_net_setting).setOnClickListener(this);
|
view.findViewById(R.id.tv_refresh).setOnClickListener(this);
|
|
//
|
messagelistAdapter = new MessagelistAdapter((MainActivity) getActivity(), commList);
|
ll_critical_list.setAdapter(messagelistAdapter);
|
ll_critical_list.setDividerHeight(0);
|
|
tv_middle.setText("消息");
|
getCache();
|
}
|
|
/**
|
* 获取缓存
|
*/
|
private void getCache() {
|
mPresenter.getCaChe(cache, mPage, mList, adapter, ll_critical_notice, tv_critical_msg_title,
|
tv_critical_msg_time, tv_critical_msg_content, iv_red_dot, iv_critical_msg_img, iv_critical_msg_grade, new MessgeContract.onCommonListCallback() {
|
@Override
|
public void onSuccess(JSONArray mJsonArray) throws JSONException {
|
if (mJsonArray != null)
|
setMsgdeal(mJsonArray);//推送消息处理 客服/推荐记录/官宣/小助手
|
}
|
});
|
}
|
|
private void addListener() {
|
fl_order_notice.setOnClickListener(this);
|
fl_capital_notice.setOnClickListener(this);
|
fl_account_notice.setOnClickListener(this);
|
fl_invite_notice.setOnClickListener(this);
|
fl_other_msg.setOnClickListener(this);
|
ll_critical_notice.setOnClickListener(this);
|
tv_top_bar_right.setOnClickListener(this);
|
iv_top_bar_clear.setOnClickListener(this);
|
|
mChangeHelper = new ConnectivityChangeHelper(rv_message.getContext(),
|
new ConnectivityChangeHelper.OnConnectivityChangeListener() {
|
|
@Override
|
public void onNetworkUnAvailable() {
|
if (mList.size() == 0)
|
requestState(3);
|
}
|
|
@Override
|
public void onNetworkAvailable() {
|
requestState(0);
|
if (mList.size() == 0) {
|
getMessage();
|
getUnReadMsgCount();
|
}
|
}
|
});
|
srl_message.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {//下拉刷新
|
@Override
|
public void onRefresh() {
|
mPage = 1;
|
((MainActivity) getActivity()).setmPage(mPage);
|
srl_message.setRefreshing(true);
|
getMessage();
|
getUnReadMsgCount();
|
}
|
});
|
|
rv_message.addOnScrollListener(new RecyclerView.OnScrollListener() {
|
@Override
|
public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
|
super.onScrollStateChanged(recyclerView, newState);
|
LinearLayoutManager manager = (LinearLayoutManager) recyclerView.getLayoutManager();
|
int last = manager.findLastVisibleItemPosition();
|
int total = manager.getItemCount();
|
if (newState == RecyclerView.SCROLL_STATE_IDLE) {
|
if (last == total - 1 && mList.size() < count && !isLoad) {
|
mPage++;
|
((MainActivity) getActivity()).setmPage(mPage);
|
isLoad = true;
|
iv_loading.setVisibility(View.VISIBLE);
|
tv_loading.setText("正在加载更多是数据");
|
getMessage();
|
}
|
}
|
}
|
|
@Override
|
public void onScrolled(RecyclerView recyclerView, int dx, final int dy) {
|
super.onScrolled(recyclerView, dx, dy);
|
}
|
});
|
}
|
|
@Override
|
public void onResume() {
|
super.onResume();
|
mChangeHelper.registerReceiver();
|
getMessage();
|
getUnReadMsgCount();
|
boolean isLogin = sp.getBoolean("isLogin", false);
|
if (!isLogin) { //判断未登陆 隐藏清空按钮和 去旧版
|
if (iv_top_bar_clear.getVisibility() == View.VISIBLE | tv_top_bar_right.getVisibility() == View.VISIBLE) {
|
iv_top_bar_clear.setVisibility(View.GONE);
|
tv_top_bar_right.setVisibility(View.GONE);
|
}
|
} else { //登陆显示清空按钮和 去旧版
|
if (iv_top_bar_clear.getVisibility() == View.GONE | tv_top_bar_right.getVisibility() == View.GONE) {
|
iv_top_bar_clear.setVisibility(View.VISIBLE);
|
tv_top_bar_right.setVisibility(View.INVISIBLE);
|
}
|
IsSkipActivity();//判断登陆跳转 是否是点击按钮后再登陆 如是则跳转到相应的页面
|
}
|
isChoice = false;
|
iscategory = 0;
|
}
|
|
//判断是否点击 订单 资金 账号 邀请 其他按钮 点击后 则跳转到相应的页面
|
private void IsSkipActivity() {
|
if (isChoice) {
|
if (iscategory == 1001) {//订单
|
fl_order_notice.performClick();
|
} else if (iscategory == 1002) {//资金
|
fl_capital_notice.performClick();
|
} else if (iscategory == 1003) {//账号
|
fl_account_notice.performClick();
|
} else if (iscategory == 1004) {//邀请
|
fl_invite_notice.performClick();
|
} else if (iscategory == 1005) {//其他
|
fl_other_msg.performClick();
|
}
|
}
|
}
|
|
@Override
|
public void onPause() {
|
super.onPause();
|
mChangeHelper.unregisterReceiver();
|
// Log.e("mResult", "消息页面onPause");
|
}
|
|
|
/**
|
* 获取主页消息列表
|
*/
|
private void getMessage() {
|
final boolean isLogin = sp.getBoolean("isLogin", false);
|
((MainActivity) getActivity()).getMessageMain(new MainActivity.getHomeMsgListListener() {
|
@Override
|
public void onSuccessPerfect(int statusCode, Header[] headers, JSONObject jsonObject) throws JSONException, ParseException {
|
if (jsonObject.optInt("code") == 0) {
|
Gson gson = new GsonBuilder().serializeNulls().create();
|
List<MainMessage> list = gson.fromJson(jsonObject.optJSONObject("data").optJSONArray("list").toString(), new TypeToken<List<MainMessage>>() {
|
}.getType());
|
if (mPage == 1) {
|
mList.clear();
|
setMsgdeal(jsonObject.optJSONObject("data").optJSONArray("commonList"));//处理 推送消息
|
setAnnounce(jsonObject);//处理公告消息
|
}
|
// adapter.notifyItemRangeChanged(adapter.getItemCount(), list.size());//倒序批量刷新列表
|
//处理系统消息-列表信息
|
mPresenter.setMessage(mPage, jsonObject, ll_critical_notice, isLogin, iv_critical_msg_img, iv_critical_msg_grade, tv_critical_msg_title, tv_critical_msg_time, tv_critical_msg_content, iv_red_dot);
|
count = Integer.parseInt(jsonObject.optJSONObject("data").optString("count"));
|
mList.addAll(list);
|
adapter.notifyDataSetChanged();
|
|
if (mList.size() == count) {
|
bottom.setVisibility(View.VISIBLE);
|
iv_loading.setVisibility(View.GONE);
|
tv_loading.setText(getResources().getString(R.string.list_no_more));
|
}
|
// requestState(mList.size() == 0 ? 1 : 0);
|
} else {
|
if (mList.size() == 0)
|
requestState(2);
|
}
|
}
|
|
@Override
|
public void onFinish() {
|
isLoad = false;
|
srl_message.setRefreshing(false);
|
}
|
|
@Override
|
public void onFailure(int statusCode, Header[] headers, String responseString, Throwable throwable) {
|
if (mList.size() == 0) {
|
if (NetUtils.getNetworkState(rv_message.getContext()).equalsIgnoreCase(NetUtils.NETWORK_NONE)) {
|
requestState(3);
|
} else {
|
requestState(2);
|
}
|
} else {
|
if (NetUtils.getNetworkState(rv_message.getContext()).equalsIgnoreCase(NetUtils.NETWORK_NONE)) {
|
Toast.makeText(rv_message.getContext(), "网络连接异常,请检测网络设置", Toast.LENGTH_SHORT).show();
|
} else {
|
Toast.makeText(rv_message.getContext(), "网络连接异常,请检测网络设置", Toast.LENGTH_SHORT).show();
|
}
|
}
|
}
|
}, true);//继续请求 消息列表
|
}
|
|
/**
|
* 处理公告消息
|
*
|
* @param jsonObject
|
*/
|
private void setAnnounce(JSONObject jsonObject) {
|
final JSONObject notifyMsg = jsonObject.optJSONObject("data").optJSONObject("notifyMsg");
|
if (notifyMsg != null) {
|
ll_critical_announce.setVisibility(View.VISIBLE);//显示 公告布局
|
//处理公告消息
|
mPresenter.setAnnounce(notifyMsg, ll_critical_announce, ll_critical_announce_title, ll_critical_announce_time, ll_critical_announce_content
|
, ll_critical_announce_img, ll_critical_announce_reddot);
|
} else {
|
ll_critical_announce.setVisibility(View.GONE);//隐藏 公告布局
|
}
|
}
|
|
private List<CommonList> commList = new ArrayList<>();
|
|
/**
|
* 推送消息处理 客服/推荐记录/官宣/小助手
|
*/
|
public void setMsgdeal(JSONArray array) throws JSONException {
|
if (array != null && array.length() > 0) {
|
if (commList != null && commList.size() > 0) {
|
commList.clear();
|
}
|
Gson gson = new Gson();
|
for (int i = 0; i < array.length(); i++) {
|
JSONObject object = (JSONObject) array.get(i);
|
CommonList user = gson.fromJson(object.toString(), CommonList.class);
|
if (user.getType().equals("kefu") && user.getLatestMsg().equals("")) {
|
user.setLatestMsg("[点击打开人工客服]");
|
}
|
commList.add(user);
|
}
|
messagelistAdapter.notifyDataSetChanged();
|
}
|
|
}
|
|
/**
|
* 获取消息未读数量
|
*/
|
private void getUnReadMsgCount() {
|
mPresenter.getUnReadMsgCount(mPresenter.getUID());
|
}
|
|
/**
|
* 一键清空未读消息
|
*/
|
private void setAllMsgRead() {
|
mPresenter.setAllMsgRead(mPresenter.getUID());
|
}
|
|
@Override
|
public void onClick(View v) {
|
boolean isLogin = sp.getBoolean("isLogin", false);
|
switch (v.getId()) {
|
case R.id.fl_order_notice: {
|
if (!LoginAndInviteStatusUtil.acessNext(getContext(), UserUtil.getUid(getContext()) + "", true))
|
return;
|
|
if (!isLogin) {//判断登陆
|
isChoice = true;//代表点击
|
iscategory = 1001;
|
UserUtil.jumpLogin(fl_order_notice.getContext());
|
break;
|
}
|
// MessageCustomEvent.msgOrder(rv_message.getContext());
|
Intent intent = new Intent(rv_message.getContext(), UserMessageActivity.class);
|
intent.putExtra("title", "订单消息");
|
intent.putExtra("type", "order");
|
startActivity(intent);
|
break;
|
}
|
case R.id.fl_capital_notice: {
|
if (!LoginAndInviteStatusUtil.acessNext(getContext(), UserUtil.getUid(getContext()) + "", true))
|
return;
|
if (!isLogin) {//判断登陆
|
isChoice = true;//代表点击
|
iscategory = 1002;
|
UserUtil.jumpLogin(fl_order_notice.getContext());
|
break;
|
}
|
Intent intent = new Intent(rv_message.getContext(), UserMessageActivity.class);
|
intent.putExtra("title", "资金消息");
|
intent.putExtra("type", "money");
|
startActivity(intent);
|
break;
|
}
|
case R.id.fl_account_notice: {
|
if (!LoginAndInviteStatusUtil.acessNext(getContext(), UserUtil.getUid(getContext()) + "", true))
|
return;
|
if (!isLogin) {//判断登陆
|
isChoice = true;//代表点击
|
iscategory = 1003;
|
UserUtil.jumpLogin(fl_order_notice.getContext());
|
break;
|
}
|
Intent intent = new Intent(rv_message.getContext(), UserMessageActivity.class);
|
intent.putExtra("title", "账号消息");
|
intent.putExtra("type", "account");
|
startActivity(intent);
|
break;
|
}
|
case R.id.fl_invite_notice: {
|
if (!LoginAndInviteStatusUtil.acessNext(getContext(), UserUtil.getUid(getContext()) + "", true))
|
return;
|
if (!isLogin) {//判断登陆
|
isChoice = true;//代表点击
|
iscategory = 1004;
|
UserUtil.jumpLogin(fl_order_notice.getContext());
|
break;
|
}
|
Intent intent = new Intent(rv_message.getContext(), UserMessageActivity.class);
|
intent.putExtra("title", "邀请消息");
|
intent.putExtra("type", "invite");
|
startActivity(intent);
|
break;
|
}
|
case R.id.fl_other_msg: {
|
if (!LoginAndInviteStatusUtil.acessNext(getContext(), UserUtil.getUid(getContext()) + "", true))
|
return;
|
if (!isLogin) {//判断登陆
|
isChoice = true;//代表点击
|
iscategory = 1005;
|
UserUtil.jumpLogin(fl_order_notice.getContext());
|
break;
|
}
|
Intent intent = new Intent(rv_message.getContext(), UserMessageActivity.class);
|
intent.putExtra("title", "其它消息");
|
intent.putExtra("type", "other");
|
startActivity(intent);
|
break;
|
}
|
case R.id.ll_critical_notice://系统消息
|
if (!LoginAndInviteStatusUtil.acessNext(getContext(), UserUtil.getUid(getContext()) + "", true))
|
return;
|
if (!isLogin) {//判断登陆
|
UserUtil.jumpLogin(fl_order_notice.getContext());
|
break;
|
}
|
MessageCustomEvent.msgItemClick(rv_message.getContext(), "系统消息");
|
startActivity(new Intent(rv_message.getContext(), SystemMessageActivity.class));
|
break;
|
case R.id.tv_top_bar_right:
|
MessageCustomEvent.msgOld(rv_message.getContext());
|
startActivity(new Intent(rv_message.getContext(), AppMailActivity.class));
|
break;
|
case R.id.tv_net_setting:
|
startActivity(new Intent(Settings.ACTION_SETTINGS));
|
break;
|
case R.id.tv_refresh:
|
startActivity(new Intent(Settings.ACTION_SETTINGS));
|
break;
|
case R.id.iv_top_bar_clear:
|
MessageCustomEvent.msgClearNotify(rv_message.getContext());
|
setAllMsgRead();
|
break;
|
//点击公告
|
case R.id.ll_critical_announce:
|
|
break;
|
|
default:
|
break;
|
}
|
}
|
|
/**
|
* 请求状态 0 数据正常展示;1 返回数据为空;2 网络请求失败;3 没有连接网络
|
*
|
* @param state
|
*/
|
private void requestState(int state) {
|
srl_message.setVisibility(state == 0 ? View.VISIBLE : View.GONE);
|
rv_message.setVisibility(state == 0 ? View.VISIBLE : View.GONE);
|
ll_no_data.setVisibility(state == 1 ? View.VISIBLE : View.GONE);
|
ll_request_failture.setVisibility(state == 2 ? View.VISIBLE : View.GONE);
|
ll_no_net.setVisibility(state == 3 ? View.VISIBLE : View.GONE);
|
}
|
|
|
@Override
|
public void onDestroyView() {
|
super.onDestroyView();
|
// Log.e("mResult", "消息页面onDestroyView");
|
}
|
|
@Override
|
public void onDestroy() {
|
super.onDestroy();
|
// Log.e("mResult", "消息页面onDestroy");
|
// messageReceiver = null;
|
// EventBus.getDefault().unregister(this);
|
//注册 主页消息推送传播接口
|
((MainActivity) getActivity()).setMessagePush(null);
|
}
|
|
private boolean accountLogin = false;
|
private JSONObject floatImgDetail;
|
|
/**
|
* 消息中心红包
|
*/
|
private void getMSGConfig() {
|
mPresenter.getMSGConfig(mPresenter.getUID());
|
}
|
|
/**
|
* 展示红包等级福利提示Dialog
|
*/
|
private void showHintDialog(RedPacketHintDialog.Builder builder, final JSONObject floatImgDetail) {
|
final boolean isLogin = getContext().getSharedPreferences("user", Context.MODE_PRIVATE).getBoolean("isLogin", false);
|
mPresenter.showHintDialog(builder, floatImgDetail, accountLogin, isLogin);
|
}
|
|
|
/**
|
* 获取未读消息条数
|
*
|
* @param jsonObject
|
*/
|
@Override
|
public void onUnReadMsgCount(JSONObject jsonObject) {
|
srl_message.setRefreshing(false);
|
if (jsonObject.optInt("code") == 0) {
|
mPresenter.setUnReadMsgCount(jsonObject, tv_order_notice_num, tv_capital_notice_num, tv_account_notice_num, tv_invite_notice_num, tv_other_msg_num
|
, ll_order_notice_num, ll_capital_notice_num, ll_account_notice_num, ll_invite_notice_num, ll_other_msg_num, iv_red_dot);
|
((MainActivity) getActivity()).setUnReadMsgCount(jsonObject);
|
}
|
}
|
|
/**
|
* 删除所有未读消息条数
|
*
|
* @param jsonObject
|
*/
|
@Override
|
public void onAllMsgReadSuccess(JSONObject jsonObject) {
|
if (jsonObject.optInt("code") == 0) {
|
getUnReadMsgCount();
|
Toast.makeText(rv_message.getContext(), "消息全部已读", Toast.LENGTH_SHORT).show();
|
} else {
|
if (!spkefu.getString("read", "false").equals("false")) {
|
Toast.makeText(rv_message.getContext(), jsonObject.optString("msg"), Toast.LENGTH_SHORT).show();
|
}
|
}
|
int i = 0;
|
for (CommonList cmlist : commList) {
|
if (cmlist.getType().equals("kefu")) {
|
commList.get(i).setRead(true);
|
break;
|
}
|
i++;
|
}
|
// 设置 客服未读消息已读
|
SharedPreferences.Editor editor = spkefu.edit();
|
editor.putString("read", "true");//是否已读
|
editor.apply();
|
messagelistAdapter.notifyDataSetChanged();
|
((MainActivity) getActivity()).setclear(true);
|
}
|
|
/**
|
* 消息中心红包
|
*
|
* @param jsonObject
|
*/
|
@Override
|
public void onMSGConfigSuccess(JSONObject jsonObject) {
|
if (jsonObject.optInt("code") == 0) {
|
SharedPreferences sp = getContext().getSharedPreferences("user", Context.MODE_PRIVATE);
|
floatImgDetail = jsonObject.optJSONObject("data").optJSONObject("floatImgDetail");
|
//底部网页链接
|
if (floatImgDetail != null) {
|
accountLogin = floatImgDetail.optBoolean("accountLogin");
|
String imgUrl = floatImgDetail.optString("img");
|
JSONObject jumpDetail = floatImgDetail.optJSONObject("jumpDetail");
|
RedPacketHintDialog.Builder builder = new RedPacketHintDialog.Builder(getActivity());
|
builder.imgUrl(imgUrl);
|
if (jumpDetail == null) {
|
mPresenter.setMSGConfig_jumpDetailnull(builder);
|
} else {
|
String showTime = floatImgDetail.optString("showTime");
|
final boolean isLogin = sp.getBoolean("isLogin", false);
|
//是否是当天当月当年
|
if (showTime.equalsIgnoreCase("everyday") && mPresenter.isSameDay(new Date(System.currentTimeMillis()), new Date(sp.getLong("redPacketHintmsg", 0l)))) {
|
return;
|
}
|
//记录打开时间
|
if (showTime.equalsIgnoreCase("everyday")) {
|
SharedPreferences.Editor editor1 = sp.edit();
|
editor1.putLong("redPacketHintmsg", System.currentTimeMillis());
|
editor1.commit();
|
}
|
//百川打开
|
if (jumpDetail.optString("type").equalsIgnoreCase("baichuan!")) {
|
mPresenter.setMSGConfig_baichuan(floatImgDetail, accountLogin, isLogin, imgUrl, builder);
|
} else {//跳转其他activity
|
showHintDialog(builder, floatImgDetail);
|
}
|
}
|
}
|
}
|
}
|
|
/**
|
* 推送消息 接受方法 从新请求一次消息未读数量
|
*/
|
@Override
|
public void MessagePush(boolean b) {
|
if (b) {
|
mPage = 1;
|
((MainActivity) getActivity()).setmPage(mPage);
|
srl_message.setRefreshing(true);
|
getMessage();
|
getUnReadMsgCount();
|
}
|
}
|
|
|
}
|