AI智能
改变未来

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


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) {// 创建intentval 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 = trueif(currentPage == 1){fetchSubData()} else if(currentPage == 2){globalList_2 = LinkedList<ArticleItem>()listPage = 1fetchLatestData(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);}

 

赞(0) 打赏
未经允许不得转载:爱站程序员基地 » 创新实训博客(36)——Android端push推送设置和主界面细节优化处理