Browse Source

feat: messing

tongmengxiao 2 months ago
parent
commit
7ab5f18310

+ 17 - 5
app/src/main/java/com/swago/app/MyFirebaseMessagingService.kt

@@ -1,9 +1,11 @@
 package com.swago.app
 
+import android.app.NotificationChannel
 import android.app.NotificationManager
 import android.app.PendingIntent
 import android.content.Context
 import android.content.Intent
+import android.os.Build
 import androidx.core.app.NotificationCompat
 import com.google.firebase.messaging.FirebaseMessagingService
 import com.google.firebase.messaging.RemoteMessage
@@ -14,9 +16,9 @@ class MyFirebaseMessagingService: FirebaseMessagingService() {
 
     override fun onMessageReceived(message: RemoteMessage) {
         super.onMessageReceived(message)
-        LogUtil.d("MyFirebaseMessagingService","onMessageReceived")
-        message.notification?.body?.let {
-            sendNotification(it)
+        LogUtil.d("MyFirebaseMessagingService","onMessageReceived" + message)
+        message.notification?.let {
+            sendNotification(it.title,it.body)
         }
 
     }
@@ -25,19 +27,29 @@ class MyFirebaseMessagingService: FirebaseMessagingService() {
         super.onNewToken(token)
     }
 
-    private fun sendNotification(messageBody: String) {
+    private fun sendNotification(title:String?,messageBody: String?) {
+        LogUtil.d("FCM", "sendNotification: " + messageBody)
         val intent = Intent(this, HomeActivity::class.java)
         intent.flags = Intent.FLAG_ACTIVITY_CLEAR_TOP
         val pendIntent = PendingIntent.getActivity(this,0,intent,PendingIntent.FLAG_IMMUTABLE)
         val channelId = "default_channel_id"
         val notificationBuilder = NotificationCompat.Builder(this, channelId)
             .setSmallIcon(R.mipmap.ic_launcher_foreground)
-            .setContentTitle("FCM Message")
+            .setContentTitle(title)
             .setContentText(messageBody)
             .setAutoCancel(true)
             .setContentIntent(pendIntent)
 
         val notificationManager = getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
+        // Android 8.0及以上需要设置通知渠道
+        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
+            val channel = NotificationChannel(
+                channelId,
+                "Channel title",
+                NotificationManager.IMPORTANCE_DEFAULT
+            )
+            notificationManager.createNotificationChannel(channel)
+        }
         notificationManager.notify(0, notificationBuilder.build())
     }
 }

+ 5 - 1
room/src/main/java/com/swago/room/base/BaseComFragment.kt

@@ -839,6 +839,7 @@ abstract class BaseComFragment<T : FragmentBaseComBinding> : BaseXFragment<T>(),
     }
 
     private var isFirst = true
+    private var getOnlineRewards = true
     override fun joinedRoom(iRoomInfo: IRoomInfo) {
         roomOtherVm.getRedEnvelopeList()
         if (iRoomInfo.getRoomType() != RoomType.HOUSE.type){
@@ -892,7 +893,10 @@ abstract class BaseComFragment<T : FragmentBaseComBinding> : BaseXFragment<T>(),
 
                 if (it.user_wealth_level.toInt()>=10){
                     //查询直播间在线时长与奖励领取情况
-                    roomVm.getOnlineRewards()
+                    if (getOnlineRewards){
+                        getOnlineRewards = false
+                        roomVm.getOnlineRewards()
+                    }
                 } else {
                     binding.ivRewards.checkOnlineTime(null)
                     binding.ivRewards.visibility = View.VISIBLE

+ 0 - 1
room/src/main/java/com/swago/room/gift/GiftDialog.kt

@@ -824,7 +824,6 @@ class GiftDialog : BaseXDFragment<DialogGiftBinding>() {
                     it.im_data.data.receiverName = receiverName.toString()
                     it.im_data.data.svga = it.svgaUrl
                     msgVm.playSvgUrl?.invoke(it.im_data.data ,true)
-                    msgVm.addAudioGiftAnimFun?.invoke(it)
                 }
             }
             if (type == 2 || type == 3) {

+ 4 - 1
room/src/main/java/com/swago/room/reward/RewardView.kt

@@ -107,7 +107,7 @@ class RewardView : FrameLayout, IRoomActiveListener, RoomTimer.TimeTickListener
 
     override fun onTimeCount(time: Int) {
         if (timeL == 0L){
-            if (scaleXAnimator?.isRunning == false){
+            if (scaleXAnimator?.isRunning == false && rewardsModel != null){
                 startGetAnimation()
             }
         } else {
@@ -121,6 +121,9 @@ class RewardView : FrameLayout, IRoomActiveListener, RoomTimer.TimeTickListener
     fun checkOnlineTime(model: OnlineRewardsModel?) {
         if (model == null) {
             rewardsModel = null
+            binding?.tvTime?.setBackgroundResource(R.mipmap.bg_get_reward)
+            binding?.tvTime?.text = "Get!"
+            timeL = 0L
             return
         }
         rewardsModel = model

+ 2 - 1
room/src/main/java/com/swago/room/vm/MsgVm.kt

@@ -741,9 +741,10 @@ class MsgVm(application: Application) : AbsMsgVm(application) {
                                     imGiftModel.receiverName = receiverName.toString()
 
                                     playSvgUrl?.invoke(imGiftModel ,true)
+                                } else {
+                                    addAudioGiftAnimFun?.invoke(it)
                                 }
 
-                                addAudioGiftAnimFun?.invoke(it)
                             }
                         }
 

+ 8 - 10
room/src/main/res/layout/fragment_base_com.xml

@@ -97,13 +97,12 @@
 
     <com.swago.room.widget.RecommendBannerView
         android:id="@+id/playBannerView"
-        app:layout_constraintTop_toTopOf="parent"
-        app:layout_constraintBottom_toBottomOf="parent"
+        app:layout_constraintTop_toBottomOf="@+id/ivRewards"
         app:layout_constraintEnd_toEndOf="parent"
         tools:visibility="visible"
         android:visibility="gone"
+        android:layout_marginTop="@dimen/dp_10"
         android:layout_marginRight="2dp"
-        android:layout_marginTop="390dp"
         android:layout_width="wrap_content"
         android:layout_height="wrap_content"/>
 
@@ -166,13 +165,7 @@
         app:layout_constraintTop_toTopOf="parent"
         app:layout_constraintStart_toStartOf="parent"
         android:layout_width="match_parent"
-        android:layout_height="300dp">
-
-        <com.swago.room.audio.widget.AudioContainGiftView
-            android:id="@+id/audioAllGiftView"
-            android:layout_width="match_parent"
-            android:layout_height="match_parent" />
-    </com.swago.room.giftdandao.GiftDanDaoView>
+        android:layout_height="300dp"/>
 
     <com.swago.room.giftdandao.GiftDanDaoView
         android:id="@+id/danDaoView3"
@@ -247,4 +240,9 @@
         android:layout_width="wrap_content"
         android:layout_height="wrap_content"/>
 
+    <com.swago.room.audio.widget.AudioContainGiftView
+        android:id="@+id/audioAllGiftView"
+        android:layout_width="match_parent"
+        android:layout_height="match_parent" />
+
 </androidx.constraintlayout.widget.ConstraintLayout>

+ 2 - 1
room/src/main/res/layout/view_rewards.xml

@@ -12,7 +12,7 @@
         app:layout_constraintBottom_toBottomOf="parent"
         android:src="@mipmap/icon_rewards"
         android:layout_marginEnd="@dimen/dp_4"
-        android:layout_marginTop="@dimen/dp_4"
+        android:layout_marginTop="6dp"
         android:layout_width="wrap_content"
         android:layout_height="wrap_content"/>
 
@@ -22,6 +22,7 @@
         tools:text="0"
         android:gravity="center_horizontal"
         android:textSize="8sp"
+        android:layout_marginTop="2dp"
         android:background="@mipmap/bg_time_reward"
         app:layout_constraintTop_toTopOf="parent"
         app:layout_constraintEnd_toEndOf="parent"