This commit is contained in:
@ -16,6 +16,7 @@ import com.gh.common.notifier.Notifier
|
||||
import com.gh.common.util.DataUtils
|
||||
import com.gh.common.util.EntranceUtils
|
||||
import com.gh.common.util.StringUtils
|
||||
import com.gh.common.util.toObject
|
||||
import com.gh.gamecenter.R
|
||||
import com.gh.gamecenter.entity.PushEntity
|
||||
import com.gh.gamecenter.entity.PushMessageEntity
|
||||
@ -45,22 +46,16 @@ class GHUmengNotificationService : UmengMessageService() {
|
||||
|
||||
companion object {
|
||||
const val ACTION_UMENG = "com.gh.gamecenter.UMENG"
|
||||
|
||||
const val MESSAGE_FROM_SYSTEM = "message_from_system"
|
||||
|
||||
const val HALO_MESSAGE_DIALOG = "HALO_MESSAGE_DIALOG"
|
||||
|
||||
const val HALO_MESSAGE_CENTER = "HALO_MESSAGE_CENTER"
|
||||
|
||||
const val ANSWER = "answer"
|
||||
|
||||
const val FOLLOW_QUESTION = "follow_question"
|
||||
|
||||
const val NOTIFICATION_ID = 2015
|
||||
|
||||
const val DISPLAY_TYPE_NOTIFICATION = "notification"
|
||||
|
||||
const val DISPLAY_TYPE_CUSTOM = "custom"
|
||||
const val MESSAGE_ID = "message_id"
|
||||
const val PUSH_ID = "push_id"
|
||||
}
|
||||
|
||||
val notificationTags = arrayOf("GH_UMENG_TAG_1", "GH_UMENG_TAG_2", "GH_UMENG_TAG_3")
|
||||
@ -71,7 +66,7 @@ class GHUmengNotificationService : UmengMessageService() {
|
||||
val isMessageFromSystem = intent.getBooleanExtra(MESSAGE_FROM_SYSTEM, false)
|
||||
|
||||
try {
|
||||
val pushData = gson.fromJson(message, PushEntity::class.java)
|
||||
val pushData = message.toObject<PushEntity>()
|
||||
pushData?.let { handlePushData(context, it, message, isMessageFromSystem) }
|
||||
} catch (e: Exception) {
|
||||
e.printStackTrace()
|
||||
@ -84,10 +79,10 @@ class GHUmengNotificationService : UmengMessageService() {
|
||||
if (pushData.displayType == DISPLAY_TYPE_NOTIFICATION) {
|
||||
// 其它类型的透传信息
|
||||
// 显示到通知栏
|
||||
val msg = gson.fromJson(message, PushNotificationEntity::class.java)
|
||||
val msg = message.toObject<PushNotificationEntity>()
|
||||
val data = msg?.extra?.data
|
||||
|
||||
// 系统推送,直接处理跳转
|
||||
// 系统推送(非自定义信息),直接处理跳转
|
||||
if (isMessageFromSystem) {
|
||||
val intent = Intent()
|
||||
intent.setClass(context, UmengMessageReceiver::class.java)
|
||||
@ -98,13 +93,14 @@ class GHUmengNotificationService : UmengMessageService() {
|
||||
return
|
||||
}
|
||||
|
||||
// 判断是否过滤该消息
|
||||
val clickIntent = Intent()
|
||||
val removeIntent = Intent()
|
||||
|
||||
clickIntent.setClass(context, UmengMessageReceiver::class.java)
|
||||
clickIntent.putExtra(EntranceUtils.KEY_DATA, data?.link)
|
||||
clickIntent.putExtra(EntranceUtils.KEY_MESSAGE, message)
|
||||
clickIntent.putExtra(MESSAGE_ID, msg?.msgId)
|
||||
clickIntent.putExtra(PUSH_ID, data?.pushId)
|
||||
clickIntent.putExtra(EntranceUtils.KEY_TYPE, TYPE_CLICK)
|
||||
|
||||
removeIntent.setClass(context, UmengMessageReceiver::class.java)
|
||||
|
||||
@ -1,5 +1,6 @@
|
||||
package com.gh.common
|
||||
|
||||
import android.annotation.SuppressLint
|
||||
import android.preference.PreferenceManager
|
||||
import com.gh.base.GHUmengNotificationService
|
||||
import com.gh.common.constant.Config
|
||||
@ -77,6 +78,7 @@ object PushManager {
|
||||
})
|
||||
}
|
||||
|
||||
@SuppressLint("CheckResult")
|
||||
@JvmStatic
|
||||
fun getAndSetAlias() {
|
||||
if (deviceToken.isNullOrEmpty()) {
|
||||
|
||||
@ -79,7 +79,9 @@ object GameRepositoryHelper {
|
||||
}
|
||||
|
||||
/**
|
||||
* 从游戏库相应的专题中取出一个与其它游戏都不相同的游戏,为空时即为游戏用完或不存在该相应专题
|
||||
* 从补充游戏库相应的专题中取出一个与其它游戏都不相同的游戏,为空时即为游戏用完或不存在该相应专题
|
||||
* @param collectionId 补充游戏库相应专题 ID
|
||||
* @param gameIdList 该专题里已经包含的游戏 ID 列表
|
||||
*/
|
||||
fun getOneUniqueGame(collectionId: String?, gameIdList: List<String>): GameEntity? {
|
||||
collectionId?.let {
|
||||
|
||||
@ -30,8 +30,11 @@ data class PushNotificationEntity(
|
||||
|
||||
data class Extra(var data: Data? = null)
|
||||
|
||||
data class Data(var condition: Condition? = null,
|
||||
var link: Link? = null) {
|
||||
data class Data(
|
||||
@SerializedName("push_id")
|
||||
var pushId: String? = "",
|
||||
var condition: Condition? = null,
|
||||
var link: Link? = null) {
|
||||
|
||||
@Parcelize
|
||||
data class Link(var type: String? = "", var target: String? = "") : Parcelable
|
||||
|
||||
@ -3,11 +3,20 @@ package com.gh.gamecenter.receiver
|
||||
import android.content.BroadcastReceiver
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import com.gh.base.GHUmengNotificationService
|
||||
import com.gh.common.PushManager
|
||||
import com.gh.common.util.DirectUtils
|
||||
import com.gh.common.util.EntranceUtils
|
||||
import com.gh.gamecenter.entity.PushNotificationEntity
|
||||
import com.gh.gamecenter.retrofit.Response
|
||||
import com.gh.gamecenter.retrofit.RetrofitManager
|
||||
import com.umeng.message.UTrack
|
||||
import com.umeng.message.entity.UMessage
|
||||
import io.reactivex.schedulers.Schedulers
|
||||
import okhttp3.MediaType
|
||||
import okhttp3.RequestBody
|
||||
import okhttp3.ResponseBody
|
||||
import org.json.JSONException
|
||||
import org.json.JSONObject
|
||||
|
||||
class UmengMessageReceiver : BroadcastReceiver() {
|
||||
@ -31,6 +40,12 @@ class UmengMessageReceiver : BroadcastReceiver() {
|
||||
// 记录该推送通知被点击
|
||||
UTrack.getInstance(context).trackMsgClick(msgObject)
|
||||
|
||||
// TODO 记录点击了推送
|
||||
val msgId = intent.getStringExtra(GHUmengNotificationService.MESSAGE_ID)
|
||||
val pushId = intent.getStringExtra(GHUmengNotificationService.PUSH_ID)
|
||||
|
||||
postClickAction(context, msgId, pushId)
|
||||
|
||||
if (link == null || link.target == "system") {
|
||||
jumpToHaloOfficialNotificationPage(context)
|
||||
} else {
|
||||
@ -54,6 +69,29 @@ class UmengMessageReceiver : BroadcastReceiver() {
|
||||
}
|
||||
}
|
||||
|
||||
private fun postClickAction(context: Context, msgId: String?, pushId: String?) {
|
||||
val jsonObject = JSONObject()
|
||||
try {
|
||||
jsonObject.put("device_token", PushManager.deviceToken)
|
||||
jsonObject.put("push_id", pushId)
|
||||
jsonObject.put("msg_id", msgId)
|
||||
} catch (e: JSONException) {
|
||||
e.printStackTrace()
|
||||
}
|
||||
|
||||
val body = RequestBody.create(MediaType.parse("application/json"), jsonObject.toString())
|
||||
|
||||
RetrofitManager.getInstance(context)
|
||||
.api
|
||||
.postUmengReceiveInfo(body)
|
||||
.subscribeOn(Schedulers.io())
|
||||
.subscribe(object : Response<ResponseBody>() {
|
||||
override fun onError(e: Throwable) {
|
||||
e.printStackTrace()
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
private fun jumpToHaloOfficialNotificationPage(context: Context) {
|
||||
DirectUtils.directToOfficialNotification(context, EntranceUtils.ENTRANCE_UMENG)
|
||||
}
|
||||
|
||||
@ -1490,6 +1490,9 @@ public interface ApiService {
|
||||
@GET("communities/{community_id}/suggested_follows")
|
||||
Observable<List<SuggestedFollowEntity>> getSuggestedFollows(@Path("community_id") String communityId);
|
||||
|
||||
/**
|
||||
* 百度ocpc激活
|
||||
*/
|
||||
@POST("baidu/ocpc:activate")
|
||||
Observable<ResponseBody> postBaiduActivationInfo();
|
||||
|
||||
@ -1502,4 +1505,11 @@ public interface ApiService {
|
||||
*/
|
||||
@GET("reserve_columns")
|
||||
Observable<List<SubjectEntity>> getReserveColumns();
|
||||
|
||||
/**
|
||||
* 标记用户点击了该推送
|
||||
*/
|
||||
@POST("./umeng:receive")
|
||||
Observable<ResponseBody> postUmengReceiveInfo(@Body RequestBody body);
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user