Browse Source

feat: firebase 注册令牌

tongmengxiao 3 months ago
parent
commit
5eb17ab1e2

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

@@ -32,7 +32,7 @@ class MyFirebaseMessagingService: FirebaseMessagingService() {
         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 channelId = "meliv_channel_id"
         val notificationBuilder = NotificationCompat.Builder(this, channelId)
             .setSmallIcon(R.mipmap.ic_launcher_foreground)
             .setContentTitle(title)

+ 6 - 0
baseswago/src/main/java/com/swago/baseswago/inter/HomeApi.kt

@@ -61,4 +61,10 @@ interface HomeApi {
     @POST("/v1/user/last/invite/log")
     suspend fun getInviteLog():InviteLogModel
 
+    /**
+     * firebase上报用户deviceToken
+     */
+    @FormUrlEncoded
+    @POST("/v1/user/upload/devicetoken")
+    suspend fun pushDeviceToken(@Field("device_token")page:String): Any
 }

+ 7 - 0
home/src/main/java/com/swago/home/HomeActivity.kt

@@ -9,6 +9,7 @@ import androidx.lifecycle.lifecycleScope
 import androidx.viewpager.widget.ViewPager
 import com.alibaba.android.arouter.facade.annotation.Route
 import com.android.billingclient.api.Purchase
+import com.google.firebase.messaging.FirebaseMessaging
 import com.swago.baseswago.PayVm
 import com.swago.baseswago.SwagoAdapter
 import com.swago.baseswago.UserVm
@@ -155,6 +156,12 @@ class HomeActivity : BaseXActivity<ActivityHomeBinding>(), IPayCallback {
             SpUtil.putString("systemCount" , it.unreadTotal.toString())
             unreadMessageVm.setSystemUnreadCount(it.unreadTotal)
         }
+        FirebaseMessaging.getInstance().token.addOnCompleteListener {
+            if (it.isSuccessful){
+                homeVm.pushDeviceToken(it.result)
+            }
+        }
+
     }
 
     /**

+ 7 - 0
home/src/main/java/com/swago/home/innerhome/HomeVm.kt

@@ -141,4 +141,11 @@ class HomeVm(application: Application) : BaseViewModel(application) {
         }
     }
 
+    fun pushDeviceToken(token:String){
+        requestData2 {
+            requestData{
+                ApiManager.homeApi.pushDeviceToken(token)
+            }
+        }
+    }
 }

+ 1 - 3
room/src/main/java/com/swago/room/dialog/GetRewardsDialog.kt

@@ -4,10 +4,7 @@ import android.os.Bundle
 import android.view.Gravity
 import com.swago.baseswago.dialog.BaseXDFragment
 import com.swago.baseswago.util.NoDoubleClickListener
-import com.swago.baseswago.util.TimeUtil
-import com.swago.room.databinding.DialogCanStartLiveBinding
 import com.swago.room.databinding.DialogGetRewardsBinding
-import java.sql.Time
 
 class GetRewardsDialog : BaseXDFragment<DialogGetRewardsBinding>() {
     private var duration :String =""
@@ -38,6 +35,7 @@ class GetRewardsDialog : BaseXDFragment<DialogGetRewardsBinding>() {
             val nextCoins = it.getInt("nextCoins")
             val nextTimes = it.getInt("nextTimes")
             binding.tvCoins.text = "+${coins}"
+            binding.tvHint.text= "Continue in the room for ${nextTimes} mins to earn another ${nextCoins} coins."
 
         }
 

+ 1 - 1
room/src/main/res/layout/dialog_get_rewards.xml

@@ -74,7 +74,7 @@
             android:layout_marginEnd="30dp"
             android:gravity="center"
             android:textColor="@color/_ffffff"
-            android:text="Continue in the room for 25 mins to earn another 100 coins."
+            tools:text="sssssss"
             android:drawablePadding="2dp"
             android:layout_width="match_parent"
             android:layout_height="wrap_content"/>