创新实训博客(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); }
相关文章推荐
- 创新实训博客(42)——搜索界面自动补全的前端处理
- 创新实训博客(38)——顶栏添加搜索框以及搜索页面的处理和思考
- 【Android游戏开发之九】(细节处理)触屏事件中的Bug解决方案以及禁止横屏和竖屏切换!
- 【Android游戏开发之九】(细节处理)触屏事件中的Bug解决方案以及禁止横屏和竖屏切换!...
- Android Push Notification实现信息推送使用
- 【Android游戏开发之九】(细节处理)触屏事件中的Bug解决方案以及禁止横屏和竖屏切换!
- 使用Vitamio打造自己的Android万能播放器(8)——细节优化
- Android Push Notification实现信息推送使用
- android使用LruCache对listview加载图片时候优化处理
- 【Android游戏开发之十】(优化处理)详细剖析Android Traceview 效率检视工具!分析程序运行速度!并讲解两种创建SDcard方式!
- Android面面观——Android事件处理下(按键、触摸屏和滚动球的一些实现细节)
- Android心得1.3--Android一些常见设置和错误处理
- Android Push Notification实现信息推送使用
- Android Push Notification实现信息推送使用
- 博客优化细节分享
- JPush极光推送3分钟搞定Android Push
- 细节决定品质-&nbsp;android优化
- 【Android游戏开发之十】(优化处理)详细剖析Android Traceview 效率检视工具
- 【Android游戏开发之九】(细节处理)触屏事件中的Bug解决方案以及禁止横屏和竖屏切换!
- Android Push Notificatioin Service(Android消息推送)