您的位置:首页 > 移动开发 > Android开发

创新实训博客(36)——Android端push推送设置和主界面细节优化处理

2020-07-14 06:21 651 查看

Push处理——判断是否初次返回

[code]                val msg = JSON.parseObject(text)["msg"].toString()
if (msg != "收到消息") {

Push处理——推送文章

[code]                    val data = JSON.parseObject(text)["data"].toString()
val obj = JSON.parseObject(data)
notificationPush(
obj["id"].toString().toInt(),
obj["title"].toString(),
obj["verbalContent"].toString(),
token
)

Push处理——具体的推送函数

[code]    // 消息推送
fun notificationPush(id: Int, title: String, content: String, token: String) {
// 创建intent
val intent = Intent(applicationContext, BlogActivity::class.java).apply {
flags = Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_CLEAR_TASK
}

// pendingIntent设置
intent.putExtra("token", token)
intent.putExtra("id", id)
val pendingIntent: PendingIntent =
PendingIntent.getActivity(applicationContext, id, intent, PendingIntent.FLAG_ONE_SHOT)

// 展开式通知
val textStyle = NotificationCompat.BigTextStyle()
textStyle.bigText(content)

// 具体的通知对象
val builder = NotificationCompat.Builder(applicationContext, "push-channel")
.setSmallIcon(R.drawable.ic_notify)
.setLargeIcon(BitmapFactory.decodeResource(this.resources, R.drawable.ic_notify))
.setContentTitle(title)
.setContentText(content)
.setStyle(textStyle)
//            .setPriority(NotificationCompat.PRIORITY_HIGH)
//            .setDefaults(Notification.DEFAULT_ALL)
.setContentIntent(pendingIntent)
.setAutoCancel(true)
.setFullScreenIntent(pendingIntent,false)

// 显示通知
with(NotificationManagerCompat.from(applicationContext)) {
notify(id, builder.build())
}
}

Push处理——推送效果

主界面1——首页二次点击刷新

[code]        val indexSwipeLayout:SwipeRefreshLayout = activity!!.findViewById(R.id.index_swipe_layout)
indexSwipeLayout.isRefreshing = true
if(currentPage == 1){
fetchSubData()
} else if(currentPage == 2){
globalList_2 = LinkedList<ArticleItem>()
listPage = 1
fetchLatestData(listPage)
} else if(currentPage == 3){
fetchHotData()
} else if(currentPage == 4){
fetchLikestData()
}

主界面2——二次点击刷新

和前面处理大致一样

主界面3——二次点击刷新

[code]    fun changeTabThree(view: View) {
if (current == userNumber) {
userFragment.fetchData()
userFragment.fetchCountTotal()
userFragment.fetchUserRecent()
return
}

评分展示——处理五位数以上为w

[code]            double hotPoint = (double)mData.get(position).getRatingCount() / 888;
if(hotPoint >= 10000){
hotPoint /= 10000;
String count_text = String.format("%.1f", hotPoint) + "w 热度";
top_count.setText(count_text);
}else {
String count_text = String.format("%.0f", hotPoint) + " 热度";
top_count.setText(count_text);
}

 

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐