|
@@ -13,7 +13,10 @@ import android.content.IntentFilter;
|
|
import android.os.Binder;
|
|
import android.os.Binder;
|
|
import android.os.Build;
|
|
import android.os.Build;
|
|
import android.os.Bundle;
|
|
import android.os.Bundle;
|
|
|
|
+import android.os.CountDownTimer;
|
|
|
|
+import android.os.Handler;
|
|
import android.os.IBinder;
|
|
import android.os.IBinder;
|
|
|
|
+import android.os.Message;
|
|
import android.support.annotation.WorkerThread;
|
|
import android.support.annotation.WorkerThread;
|
|
import android.support.v4.app.NotificationCompat;
|
|
import android.support.v4.app.NotificationCompat;
|
|
import android.text.TextUtils;
|
|
import android.text.TextUtils;
|
|
@@ -35,6 +38,9 @@ import com.liaobo.im.bean.message.ChatMessage;
|
|
import com.liaobo.im.bean.message.LastChatHistoryList;
|
|
import com.liaobo.im.bean.message.LastChatHistoryList;
|
|
import com.liaobo.im.bean.message.NewFriendMessage;
|
|
import com.liaobo.im.bean.message.NewFriendMessage;
|
|
import com.liaobo.im.bean.message.XmppMessage;
|
|
import com.liaobo.im.bean.message.XmppMessage;
|
|
|
|
+import com.liaobo.im.bean.redpacket.EventRedReceived;
|
|
|
|
+import com.liaobo.im.bean.redpacket.OpenRedpacket;
|
|
|
|
+import com.liaobo.im.bean.redpacket.RedDialogBean;
|
|
import com.liaobo.im.broadcast.MsgBroadcast;
|
|
import com.liaobo.im.broadcast.MsgBroadcast;
|
|
import com.liaobo.im.db.dao.ChatMessageDao;
|
|
import com.liaobo.im.db.dao.ChatMessageDao;
|
|
import com.liaobo.im.db.dao.FriendDao;
|
|
import com.liaobo.im.db.dao.FriendDao;
|
|
@@ -44,6 +50,7 @@ import com.liaobo.im.db.dao.login.TimerListener;
|
|
import com.liaobo.im.helper.PrivacySettingHelper;
|
|
import com.liaobo.im.helper.PrivacySettingHelper;
|
|
import com.liaobo.im.ui.MainActivity;
|
|
import com.liaobo.im.ui.MainActivity;
|
|
import com.liaobo.im.ui.base.CoreManager;
|
|
import com.liaobo.im.ui.base.CoreManager;
|
|
|
|
+import com.liaobo.im.ui.me.redpacket.RedDetailsActivity;
|
|
import com.liaobo.im.ui.message.ChatActivity;
|
|
import com.liaobo.im.ui.message.ChatActivity;
|
|
import com.liaobo.im.ui.message.HandleSyncMoreLogin;
|
|
import com.liaobo.im.ui.message.HandleSyncMoreLogin;
|
|
import com.liaobo.im.ui.message.MucChatActivity;
|
|
import com.liaobo.im.ui.message.MucChatActivity;
|
|
@@ -55,20 +62,27 @@ import com.liaobo.im.util.Md5Util;
|
|
import com.liaobo.im.util.PreferenceUtils;
|
|
import com.liaobo.im.util.PreferenceUtils;
|
|
import com.liaobo.im.util.TimeUtils;
|
|
import com.liaobo.im.util.TimeUtils;
|
|
import com.liaobo.im.util.ToastUtil;
|
|
import com.liaobo.im.util.ToastUtil;
|
|
|
|
+import com.liaobo.im.view.redDialog.RedDialog;
|
|
import com.liaobo.im.xmpp.ReceiptManager.SendType;
|
|
import com.liaobo.im.xmpp.ReceiptManager.SendType;
|
|
import com.liaobo.im.xmpp.listener.AuthStateListener;
|
|
import com.liaobo.im.xmpp.listener.AuthStateListener;
|
|
import com.liaobo.im.xmpp.listener.ChatMessageListener;
|
|
import com.liaobo.im.xmpp.listener.ChatMessageListener;
|
|
import com.liaobo.im.xuan.xuanhttplibrary.okhttp.HttpUtils;
|
|
import com.liaobo.im.xuan.xuanhttplibrary.okhttp.HttpUtils;
|
|
|
|
+import com.liaobo.im.xuan.xuanhttplibrary.okhttp.callback.BaseCallback;
|
|
import com.liaobo.im.xuan.xuanhttplibrary.okhttp.callback.ListCallback;
|
|
import com.liaobo.im.xuan.xuanhttplibrary.okhttp.callback.ListCallback;
|
|
import com.liaobo.im.xuan.xuanhttplibrary.okhttp.result.ArrayResult;
|
|
import com.liaobo.im.xuan.xuanhttplibrary.okhttp.result.ArrayResult;
|
|
|
|
+import com.liaobo.im.xuan.xuanhttplibrary.okhttp.result.ObjectResult;
|
|
|
|
|
|
import org.jivesoftware.smack.XMPPConnection;
|
|
import org.jivesoftware.smack.XMPPConnection;
|
|
|
|
|
|
import java.util.HashMap;
|
|
import java.util.HashMap;
|
|
|
|
+import java.util.Iterator;
|
|
import java.util.List;
|
|
import java.util.List;
|
|
import java.util.Map;
|
|
import java.util.Map;
|
|
|
|
+import java.util.Timer;
|
|
|
|
+import java.util.TimerTask;
|
|
import java.util.UUID;
|
|
import java.util.UUID;
|
|
|
|
|
|
|
|
+import de.greenrobot.event.EventBus;
|
|
import me.leolin.shortcutbadger.ShortcutBadger;
|
|
import me.leolin.shortcutbadger.ShortcutBadger;
|
|
import okhttp3.Call;
|
|
import okhttp3.Call;
|
|
|
|
|
|
@@ -103,6 +117,7 @@ public class CoreService extends Service implements TimerListener {
|
|
private XMucChatManager mXMucChatManager;// 唯一
|
|
private XMucChatManager mXMucChatManager;// 唯一
|
|
private ReceiptManager mReceiptManager;// 唯一
|
|
private ReceiptManager mReceiptManager;// 唯一
|
|
private ReceiptManagerNew mReceiptManagerNew;// 唯一
|
|
private ReceiptManagerNew mReceiptManagerNew;// 唯一
|
|
|
|
+ private GrabHandler mGrabHandler;
|
|
private NotifyConnectionListener mNotifyConnectionListener = new NotifyConnectionListener() {
|
|
private NotifyConnectionListener mNotifyConnectionListener = new NotifyConnectionListener() {
|
|
@Override
|
|
@Override
|
|
public void notifyConnecting() {
|
|
public void notifyConnecting() {
|
|
@@ -137,7 +152,7 @@ public class CoreService extends Service implements TimerListener {
|
|
private int notifyId = 1003020303;
|
|
private int notifyId = 1003020303;
|
|
private NotificationManager mNotificationManager;
|
|
private NotificationManager mNotificationManager;
|
|
private NotificationCompat.Builder mBuilder;
|
|
private NotificationCompat.Builder mBuilder;
|
|
-
|
|
|
|
|
|
+ Timer mTimer = new Timer();
|
|
public static Intent getIntent() {
|
|
public static Intent getIntent() {
|
|
return SERVICE_INTENT;
|
|
return SERVICE_INTENT;
|
|
}
|
|
}
|
|
@@ -158,6 +173,7 @@ public class CoreService extends Service implements TimerListener {
|
|
if (CoreService.DEBUG) {
|
|
if (CoreService.DEBUG) {
|
|
Log.e(CoreService.TAG, "CoreService OnCreate :" + android.os.Process.myPid());
|
|
Log.e(CoreService.TAG, "CoreService OnCreate :" + android.os.Process.myPid());
|
|
}
|
|
}
|
|
|
|
+ mGrabHandler = new GrabHandler(getApplicationContext());
|
|
register(); // 注册发送已读消息的广播监听
|
|
register(); // 注册发送已读消息的广播监听
|
|
}
|
|
}
|
|
|
|
|
|
@@ -177,6 +193,7 @@ public class CoreService extends Service implements TimerListener {
|
|
Log.e(CoreService.TAG, "CoreService onDestroy");
|
|
Log.e(CoreService.TAG, "CoreService onDestroy");
|
|
}
|
|
}
|
|
release();
|
|
release();
|
|
|
|
+ mGrabHandler.removeMessages(XmppMessage.TYPE_RED);
|
|
|
|
|
|
if (receiver != null) {
|
|
if (receiver != null) {
|
|
unregisterReceiver(receiver);
|
|
unregisterReceiver(receiver);
|
|
@@ -598,12 +615,21 @@ public class CoreService extends Service implements TimerListener {
|
|
public void notificationMessage(ChatMessage chatMessage, boolean isGroupChat) {
|
|
public void notificationMessage(ChatMessage chatMessage, boolean isGroupChat) {
|
|
boolean isAppForeground = AppUtils.isAppForeground(this);
|
|
boolean isAppForeground = AppUtils.isAppForeground(this);
|
|
Log.e(TAG, "notificationMessage() called with: chatMessage = [" + chatMessage.getContent() + "], isGroupChat = [" + isGroupChat + "], isAppForeground = [" + isAppForeground + "]");
|
|
Log.e(TAG, "notificationMessage() called with: chatMessage = [" + chatMessage.getContent() + "], isGroupChat = [" + isGroupChat + "], isAppForeground = [" + isAppForeground + "]");
|
|
-
|
|
|
|
|
|
+ int second = PreferenceUtils.getInt(MyApplication.getContext(), Constants.GRAB_RED_PACKET + mLoginUserId, -1);
|
|
|
|
+ int messageType = chatMessage.getType();
|
|
|
|
+ if (second!=-1 && messageType== XmppMessage.TYPE_RED){
|
|
|
|
+// mTimer
|
|
|
|
+ Message msg = Message.obtain();
|
|
|
|
+ msg.what = XmppMessage.TYPE_RED;
|
|
|
|
+ msg.obj = chatMessage;
|
|
|
|
+ mGrabHandler.sendMessageDelayed(msg,second*1000);
|
|
|
|
+ }
|
|
|
|
+ //
|
|
if (isAppForeground) {// 在前台 不通知
|
|
if (isAppForeground) {// 在前台 不通知
|
|
return;
|
|
return;
|
|
}
|
|
}
|
|
|
|
|
|
- int messageType = chatMessage.getType();
|
|
|
|
|
|
+
|
|
String title;
|
|
String title;
|
|
String content;
|
|
String content;
|
|
boolean isSpecialMsg = false;// 特殊消息 跳转至主界面 而非聊天界面
|
|
boolean isSpecialMsg = false;// 特殊消息 跳转至主界面 而非聊天界面
|
|
@@ -630,6 +656,7 @@ public class CoreService extends Service implements TimerListener {
|
|
content = getString(R.string.msg_video);
|
|
content = getString(R.string.msg_video);
|
|
break;
|
|
break;
|
|
case XmppMessage.TYPE_RED:
|
|
case XmppMessage.TYPE_RED:
|
|
|
|
+ //111111111
|
|
content = getString(R.string.msg_red_packet);
|
|
content = getString(R.string.msg_red_packet);
|
|
break;
|
|
break;
|
|
case XmppMessage.TYPE_LOCATION:
|
|
case XmppMessage.TYPE_LOCATION:
|
|
@@ -956,4 +983,109 @@ public class CoreService extends Service implements TimerListener {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
+// private HashMap<String,GrabTimerTask> mCountDownTimerHashMap = new HashMap<>();
|
|
|
|
+
|
|
|
|
+// class GrabTimerTask extends TimerTask {
|
|
|
|
+//
|
|
|
|
+// ChatMessage message;
|
|
|
|
+// public GrabTimerTask(ChatMessage chatMessage) {
|
|
|
|
+// super();
|
|
|
|
+// this.message = chatMessage;
|
|
|
|
+// }
|
|
|
|
+//
|
|
|
|
+//
|
|
|
|
+//
|
|
|
|
+//
|
|
|
|
+// @Override
|
|
|
|
+// public void run() {
|
|
|
|
+// getRedPacketInfo(message);
|
|
|
|
+// }
|
|
|
|
+// }
|
|
|
|
+ static class GrabHandler extends Handler{
|
|
|
|
+ private Context context;
|
|
|
|
+ public GrabHandler(Context context){
|
|
|
|
+ this.context = context;
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public void handleMessage(Message msg) {
|
|
|
|
+
|
|
|
|
+ super.handleMessage(msg);
|
|
|
|
+ switch (msg.what){
|
|
|
|
+ case XmppMessage.TYPE_RED:
|
|
|
|
+ ChatMessage chatMessage = (ChatMessage) msg.obj;
|
|
|
|
+ getRedPacketInfo(chatMessage);
|
|
|
|
+
|
|
|
|
+ break;
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ // 获取红包信息
|
|
|
|
+ public void getRedPacketInfo(ChatMessage chatMessage) {
|
|
|
|
+ final String token = CoreManager.requireSelfStatus(context).accessToken;
|
|
|
|
+ if (TextUtils.isEmpty(token)){
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ HashMap<String, String> params = new HashMap<>();
|
|
|
|
+ params.put("access_token", token);
|
|
|
|
+ params.put("id", chatMessage.getObjectId());
|
|
|
|
+
|
|
|
|
+ HttpUtils.get().url(CoreManager.requireConfig(context).RENDPACKET_GET)
|
|
|
|
+ .params(params)
|
|
|
|
+ .build()
|
|
|
|
+ .execute(new BaseCallback<OpenRedpacket>(OpenRedpacket.class) {
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public void onResponse(ObjectResult<OpenRedpacket> result) {
|
|
|
|
+ if (result.getData() != null) {
|
|
|
|
+ // 当resultCode==1时,表示可领取
|
|
|
|
+ // 当resultCode==0时,表示红包已过期、红包已退回、红包已领完
|
|
|
|
+ int resultCode = result.getResultCode();
|
|
|
|
+ OpenRedpacket openRedpacket = result.getData();
|
|
|
|
+ if (resultCode==1){
|
|
|
|
+ openRedPacket(token,chatMessage.getObjectId());
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public void onError(Call call, Exception e) {
|
|
|
|
+ }
|
|
|
|
+ });
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ // 打开红包
|
|
|
|
+ public void openRedPacket(final String token, String redId) {
|
|
|
|
+ HashMap<String, String> params = new HashMap<String, String>();
|
|
|
|
+ params.put("access_token", token);
|
|
|
|
+ params.put("id", redId);
|
|
|
|
+
|
|
|
|
+ HttpUtils.get().url(CoreManager.requireConfig(context).REDPACKET_OPEN)
|
|
|
|
+ .params(params)
|
|
|
|
+ .build()
|
|
|
|
+ .execute(new BaseCallback<OpenRedpacket>(OpenRedpacket.class) {
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public void onResponse(ObjectResult<OpenRedpacket> result) {
|
|
|
|
+ CoreManager.updateMyBalance();
|
|
|
|
+ Log.i("wanglaoji","抢红包成功");
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public void onError(Call call, Exception e) {
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+ });
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+
|
|
}
|
|
}
|