Browse Source

更新FCM配置文件

carlos.cheng 1 year ago
parent
commit
92538c4faa

+ 1 - 1
app/build.gradle

@@ -20,7 +20,7 @@ android {
         minSdkVersion 27
         targetSdkVersion 34
         versionCode 13
-        versionName "0.5.4"
+        versionName "0.5.6"
         multiDexEnabled true
         //manifestPlaceholders=[UMENG_CHANNEL_VALUE:name]
     }

+ 6 - 16
app/google-services.json

@@ -1,31 +1,21 @@
 {
   "project_info": {
-    "project_number": "389777651454",
-    "firebase_url": "https://kido-158903.firebaseio.com",
-    "project_id": "kido-158903",
-    "storage_bucket": "kido-158903.appspot.com"
+    "project_number": "939861786046",
+    "project_id": "sik-veryfit",
+    "storage_bucket": "sik-veryfit.appspot.com"
   },
   "client": [
     {
       "client_info": {
-        "mobilesdk_app_id": "1:389777651454:android:5f5ed0e160c8b19f9f17af",
+        "mobilesdk_app_id": "1:939861786046:android:c287eb08059396a7264def",
         "android_client_info": {
           "package_name": "com.sikey.veryfit"
         }
       },
-      "oauth_client": [
-        {
-          "client_id": "389777651454-t1h7khdocjf7avicleb6e1o997jbpokn.apps.googleusercontent.com",
-          "client_type": 1,
-          "android_info": {
-            "package_name": "com.sikey.veryfit",
-            "certificate_hash": "8f2668baf60a0b920de8896503b4aabf85c83dbc"
-          }
-        }
-      ],
+      "oauth_client": [],
       "api_key": [
         {
-          "current_key": "AIzaSyA-jGorZyhppk2jIYsbSn2MxIV39bZFb6E"
+          "current_key": "AIzaSyAPixxqidp2Lf4mD_VcKKozQ9sgGZ5tHKI"
         }
       ],
       "services": {

+ 1 - 0
app/src/main/AndroidManifest.xml

@@ -630,6 +630,7 @@
             android:exported="true">
             <intent-filter>
                 <action android:name="com.google.firebase.MESSAGING_EVENT" />
+                <action android:name="com.google.firebase.INSTANCE_ID_EVENT"/>
             </intent-filter>
         </service>
 

+ 3 - 0
app/src/main/java/com/sikey/veryfit/component/network/http/HttpService.kt

@@ -241,6 +241,9 @@ interface AlarmService : BaseHttpService {
 interface MsgCenterService:BaseHttpService {
     @GET(UrlConstants.getPushMessageCenter)
     fun fetchMsgCenter(): CustomFlowable<FetchMsgCenterRepo>
+
+    @POST(UrlConstants.refreshFcmToken)
+    fun refreshFcmToken()
 }
 
 interface SkFileService : BaseHttpService {

+ 5 - 3
app/src/main/java/com/sikey/veryfit/component/network/http/model/ChildInfo.kt

@@ -57,9 +57,11 @@ data class ChildInfo(
     val internationalAreaCode: String,
     @SerializedName("phoneNumber")
     val phoneNumber: String,
-    // 0 - 普通用户
-    // 1 - 超级管理员
-    // 2 - identity管理员
+//    const val IDENTITY_UNKNOWN: Int = 0
+//    const val IDENTITY_OTHER: Int = 1
+//    const val IDENTITY_FAMILY: Int = 2
+//    const val IDENTITY_ADMIN: Int = 3
+//    const val IDENTITY_SUPER_ADMIN: Int = 4
     @SerializedName("identity")
     val roleType: Int,
     @SerializedName("stepCount")

+ 44 - 70
app/src/main/java/com/sikey/veryfit/component/receiver/FCMMessagingService.kt

@@ -1,94 +1,68 @@
-package com.sikey.veryfit.component.receiver;
+package com.sikey.veryfit.component.receiver
 
-import android.util.Log;
-
-import com.google.firebase.messaging.FirebaseMessagingService;
-import com.google.firebase.messaging.RemoteMessage;
-import com.sikey.veryfit.constant.Constant;
-import com.sikey.veryfit.utils.SharedPreferenceUtil;
-
-import java.util.Map;
+import android.util.Log
+import com.google.firebase.messaging.FirebaseMessagingService
+import com.google.firebase.messaging.RemoteMessage
+import com.sikey.veryfit.constant.Constant
+import com.sikey.veryfit.utils.SharedPreferenceUtil
 
 /**
  * Created by yolo.huang on 2018/11/27.
  */
-
-public class FCMMessagingService extends FirebaseMessagingService {
-
-    private static final String TAG = "FCMService";
-
-    public static final String VOICE_NUM_KEY="Voice_Num_Key";
-    public static final String SP_PREF_NAME="sp_jpush_name";
-
-    private static OnReceivedNewVoiceListener mListener;
-
-    @Override
-    public void onMessageReceived(RemoteMessage remoteMessage) {
-        super.onMessageReceived(remoteMessage);
-        Log.d(TAG, "Message received: ");
+class FCMMessagingService : FirebaseMessagingService() {
+    override fun onMessageReceived(remoteMessage: RemoteMessage) {
+        super.onMessageReceived(remoteMessage)
+        Log.d(TAG, "Message received: ${remoteMessage.data}")
         // Check if message contains a data payload.
-        if (remoteMessage.getData().size() > 0) {
-            Log.d(TAG, "Message data payload: " + remoteMessage.getData());
-            receivingNotification(remoteMessage.getData());
-
+        if (remoteMessage.data.isNotEmpty()) {
+            Log.d(TAG, "Message data payload: " + remoteMessage.data)
+            receivingNotification(remoteMessage.data)
         }
     }
 
-    @Override
-    public void onDeletedMessages() {
-        super.onDeletedMessages();
-    }
 
-    @Override
-    public void onMessageSent(String s) {
-        super.onMessageSent(s);
-    }
+    private fun receivingNotification(map: Map<String, String>) {
+        val type = map["type"]!!.toInt()
+        when (type) {
+            Constant.PUSH_GROUP_VOICE, Constant.PUSH_GROUP_EMOJI, Constant.PUSH_PRIVATE_VOICE, Constant.PUSH_PRIVATE_EMOJI -> {
+                val childId = map["childid"]!!.toInt()
+                handleReceivingNewVoice(childId)
+            }
 
-    @Override
-    public void onSendError(String s, Exception e) {
-        super.onSendError(s, e);
+            else -> {}
+        }
     }
 
+    private fun handleReceivingNewVoice(childId: Int) {
+        val key = String.format("%d%s", childId, VOICE_NUM_KEY)
+        val num = SharedPreferenceUtil.getIntValueFromSP(SP_PREF_NAME, key, 0)
+        SharedPreferenceUtil.setIntDataIntoSP(SP_PREF_NAME, key, num + 1)
 
-    public static void setOnReceivedNewVoiceListener(OnReceivedNewVoiceListener listener)
-    {
-        mListener = listener;
+        if (mListener != null) {
+            mListener!!.onReceivedNewVoice()
+        }
     }
 
-    private void receivingNotification(Map<String,String> map){
-        int type = Integer.parseInt(map.get("type"));
-        switch (type){
-            case Constant.PUSH_GROUP_VOICE:
-            case Constant.PUSH_GROUP_EMOJI:
-            case Constant.PUSH_PRIVATE_VOICE:
-            case Constant.PUSH_PRIVATE_EMOJI:
-                int childId = Integer.parseInt(map.get("childid"));
-                handleReceivingNewVoice(childId);
-                break;
-            default:
-                break;
+    interface OnReceivedNewVoiceListener {
+        fun onReceivedNewVoice()
+    }
 
-        }
+    override fun onNewToken(s: String) {
+        super.onNewToken(s)
+        Log.d(TAG, "Refreshed token: $s")
+        SharedPreferenceUtil.setStringDataIntoSP(Constant.SP_TOKEN, Constant.TOKEN, s)
     }
 
-    private void handleReceivingNewVoice(int childId) {
-        String key = String.format("%d%s", childId, VOICE_NUM_KEY);
-        int num = SharedPreferenceUtil.getIntValueFromSP(SP_PREF_NAME, key, 0);
-        SharedPreferenceUtil.setIntDataIntoSP(SP_PREF_NAME, key, num+1);
+    companion object {
+        const val TAG: String = "FCMService"
 
-        if(mListener != null) {
-            mListener.onReceivedNewVoice();
-        }
-    }
+        const val VOICE_NUM_KEY: String = "Voice_Num_Key"
+        const val SP_PREF_NAME: String = "sp_jpush_name"
 
-    public interface OnReceivedNewVoiceListener {
-        void onReceivedNewVoice();
-    }
+        private var mListener: OnReceivedNewVoiceListener? = null
 
-    @Override
-    public void onNewToken(String s) {
-        super.onNewToken(s);
-        Log.d(TAG, "Refreshed token: " + s);
-        SharedPreferenceUtil.setStringDataIntoSP(Constant.SP_TOKEN, Constant.TOKEN,s);
+        fun setOnReceivedNewVoiceListener(listener: OnReceivedNewVoiceListener?) {
+            mListener = listener
+        }
     }
 }

+ 2 - 0
app/src/main/java/com/sikey/veryfit/constant/UrlConstants.kt

@@ -55,6 +55,8 @@ object UrlConstants {
 
     const val getPushMessageCenter = "/chat/api/message_center"
 
+    const val refreshFcmToken = "/chat/api/firebase/messaging/token"
+
     const val videoCall = "chat/api/client/video_call"
 
     const val remoteShutdown = "chat/api/client/shutdown"

+ 22 - 5
app/src/main/java/com/sikey/veryfit/ui/avtivity/component/right/AccountManagerActivity.kt

@@ -35,6 +35,7 @@ import com.sikey.veryfit.component.service.BleGuardService
 import com.sikey.veryfit.component.service.FetchMainChildTrackService
 import com.sikey.veryfit.constant.Constant
 import com.sikey.veryfit.constant.JSONConstants
+import com.sikey.veryfit.constant.RoleTypeConstants.ADMIN
 import com.sikey.veryfit.constant.UrlConstants
 import com.sikey.veryfit.data.AccountManager
 import com.sikey.veryfit.data.DataStorageHelper
@@ -81,9 +82,9 @@ class AccountManagerActivity : BaseNoActionBarActivity(), View.OnClickListener,
 
     private fun generateAccountInfo(): List<Pair<String, String>> {
         val items: MutableList<Pair<String, String>> = ArrayList()
-        items.add(Pair("ID", (instance.loginResponse?.id?:"").split("-").last()))
+        items.add(Pair("ID", (instance.loginResponse?.id ?: "").split("-").last()))
 //        items.add(ResUtils.getString(R.string.current_account))
-        items.add(Pair(getString(R.string.phone_num), instance.loginResponse?.phone?:""))
+        items.add(Pair(getString(R.string.phone_num), instance.loginResponse?.phone ?: ""))
         items.add(Pair(ResUtils.getString(R.string.alter_passwd), ""))
         items.add(Pair(ResUtils.getString(R.string.remove_account), ""))
         return items
@@ -117,7 +118,23 @@ class AccountManagerActivity : BaseNoActionBarActivity(), View.OnClickListener,
             .setTitle(getString(R.string.remove_account))
             .setMessage(getString(R.string.remove_account_content))
             .setNegativeButton(R.string.protect_cancel_cancel) { dialog, _ -> dialog.dismiss() }
-            .setPositiveButton(R.string.alert_dialog_ok) { _, _ -> showPWDDialog() }
+            .setPositiveButton(R.string.alert_dialog_ok) { _, _ ->
+                instance.childTrackInfos?.onEach {
+                    if(it.roleType >= ADMIN && (it.device != null && it.device.deviceId != 0)) {
+                        showUnbindTipsDialog()
+                        return@setPositiveButton
+                    }
+                }
+                showPWDDialog()
+            }
+            .show()
+    }
+
+    private fun showUnbindTipsDialog() {
+        AlertDialog.Builder(this)
+            .setTitle(getString(R.string.remove_account))
+            .setMessage(getString(R.string.unbind_tips))
+            .setNegativeButton(R.string.ok) { dialog, _ -> dialog.dismiss() }
             .show()
     }
 
@@ -130,7 +147,7 @@ class AccountManagerActivity : BaseNoActionBarActivity(), View.OnClickListener,
             .setView(input)
             .setNegativeButton(R.string.protect_cancel_cancel) { dialog, _ -> dialog.dismiss() }
             .setPositiveButton(R.string.alert_dialog_ok) { _, _ ->
-                if(input.text.isNullOrBlank()) {
+                if (input.text.isNullOrBlank()) {
                     ToastUtils.showShortToast(R.string.flow_null_err)
                     return@setPositiveButton
                 }
@@ -148,7 +165,7 @@ class AccountManagerActivity : BaseNoActionBarActivity(), View.OnClickListener,
             .show()
     }
 
-    private fun requestRemoveAccount(pwd:String) {
+    private fun requestRemoveAccount(pwd: String) {
         lifecycleScope.launch {
             showProgressDialog()
             HttpServiceExecutor.execute(

+ 6 - 3
app/src/main/java/com/sikey/veryfit/ui/avtivity/main/DispatchActivity.kt

@@ -47,6 +47,7 @@ import com.sikey.veryfit.component.network.http.model.LocationWSContent
 import com.sikey.veryfit.component.network.http.model.PushMessageWSContent
 import com.sikey.veryfit.component.network.http.model.VideoCallWSContent
 import com.sikey.veryfit.component.receiver.CustomMIPushReceiver
+import com.sikey.veryfit.component.receiver.FCMMessagingService
 import com.sikey.veryfit.component.service.SocketService
 import com.sikey.veryfit.constant.Constant
 import com.sikey.veryfit.constant.JSONConstants
@@ -684,12 +685,13 @@ class DispatchActivity : BaseNoActionBarActivity(), BottomNavigationBar.OnTabSel
         FirebaseMessaging.getInstance().token
             .addOnCompleteListener(OnCompleteListener { task ->
                 if (!task.isSuccessful) {
-                    Log.w(TAG, "getInstanceId failed", task.exception)
+                    Log.w(FCMMessagingService.TAG, "getInstanceId failed", task.exception)
                     return@OnCompleteListener
                 }
 
                 // Get new Instance ID token
                 val token = task.result
+                Log.d(FCMMessagingService.TAG, "addOnCompleteListener : $token")
                 SharedPreferenceUtil.setStringDataIntoSP(Constant.SP_TOKEN, Constant.TOKEN, token)
                 sendRegistrationToServer()
             })
@@ -718,11 +720,11 @@ class DispatchActivity : BaseNoActionBarActivity(), BottomNavigationBar.OnTabSel
         val loginResponse = DataManager.instance.loginResponse
 
         if (null == loginResponse) {
-            Logger.d(TAG, "Attention! try to atttain without login!")
+            Logger.d(FCMMessagingService.TAG, "Attention! try to atttain without login!")
             gotoLogin()
             return
         }
-        Log.d(TAG, "token=$token")
+        Log.d(FCMMessagingService.TAG, "token=$token")
         val params = JSONObject()
         try {
             params.put(JSONConstants.USER_ID, loginResponse.id)
@@ -742,6 +744,7 @@ class DispatchActivity : BaseNoActionBarActivity(), BottomNavigationBar.OnTabSel
                     response: JSONObject?,
                     array: JSONArray?
                 ) {
+                    Log.d(FCMMessagingService.TAG, "on request token ")
                     if (null != error) {
                         ToastUtils.showShortToast(error.message)
                     }

+ 9 - 1
app/src/main/java/com/sikey/veryfit/ui/custom/widget/listview/ConstraintHeightListView.kt

@@ -2,6 +2,7 @@ package com.sikey.veryfit.ui.custom.widget.listview
 
 import android.content.Context
 import android.util.AttributeSet
+import android.util.TypedValue
 import android.widget.ListView
 import kotlin.math.roundToInt
 
@@ -9,7 +10,7 @@ import kotlin.math.roundToInt
  * Created by allen on 15-9-17.
  */
 class ConstraintHeightListView : ListView {
-    private var mMaxHeight = 1200f
+    private var mMaxHeight = getMaxHeight()
     constructor(context: Context?) : super(context)
     constructor(context: Context?, attrs: AttributeSet?) : super(context, attrs)
     constructor(context: Context?, attrs: AttributeSet?, defStyle: Int) : super(
@@ -25,4 +26,11 @@ class ConstraintHeightListView : ListView {
         } else heightMeasureSpec
         super.onMeasure(widthMeasureSpec, mExpandSpec)
     }
+
+    private fun getMaxHeight(): Float {
+        return TypedValue.applyDimension(
+            TypedValue.COMPLEX_UNIT_DIP, 400.toFloat(),
+            context.resources.displayMetrics
+        )
+    }
 }

+ 16 - 16
app/src/main/res/layout/baby_list_item.xml

@@ -14,6 +14,7 @@
         android:layout_marginTop="5dp"
         android:layout_marginBottom="5dp">
 
+
         <RelativeLayout
             android:id="@+id/lyt_icon"
             android:layout_width="match_parent"
@@ -28,55 +29,54 @@
                 android:layout_marginEnd="@dimen/left_menu_left_margin"
                 android:layout_marginBottom="@dimen/left_menu_left_margin"
                 android:src="@drawable/default_guardian_avatar" />
+
             <RelativeLayout
                 android:layout_width="wrap_content"
                 android:layout_height="wrap_content"
-                android:layout_toRightOf="@id/babyImageView"
                 android:layout_centerVertical="true"
-                >
+                android:layout_toRightOf="@id/babyImageView">
 
                 <TextView
                     android:id="@+id/babyNameTv"
                     android:layout_width="120dp"
-                    android:singleLine="true"
                     android:layout_height="wrap_content"
-                    android:textSize="@dimen/text_size_large"
+                    android:singleLine="true"
+                    android:text="ExampleExampleExample"
                     android:textColor="@color/dark"
-                    android:text="ExampleExampleExample"/>
+                    android:textSize="@dimen/text_size_large" />
 
                 <TextView
                     android:id="@+id/babyTelNumTv"
                     android:layout_width="wrap_content"
                     android:layout_height="wrap_content"
                     android:layout_below="@id/babyNameTv"
-                    android:textSize="12sp"
-                    android:textColor="@color/gray_60"
                     android:layout_marginTop="8dp"
-                    android:text="12345678901"/>
+                    android:text="12345678901"
+                    android:textColor="@color/gray_60"
+                    android:textSize="12sp" />
 
             </RelativeLayout>
 
             <ImageView
                 android:id="@+id/iv_next"
+                android:layout_width="20dp"
+                android:layout_height="20dp"
                 android:layout_alignParentRight="true"
-                android:layout_marginRight="@dimen/left_menu_left_margin"
-                android:src="@drawable/ic_next"
                 android:layout_centerVertical="true"
-                android:layout_width="20dp"
-                android:layout_height="20dp" />
+                android:layout_marginRight="@dimen/left_menu_left_margin"
+                android:src="@drawable/ic_next" />
+
             <ImageView
                 android:id="@+id/iv_qr"
                 android:layout_width="wrap_content"
                 android:layout_height="wrap_content"
                 android:layout_centerVertical="true"
-                android:src="@drawable/ic_qr_code"
+                android:layout_toLeftOf="@+id/iv_next"
                 android:alpha="0.2"
-                android:layout_toLeftOf="@+id/iv_next"/>
+                android:src="@drawable/ic_qr_code" />
 
         </RelativeLayout>
 
-
-
         <RelativeLayout
             android:layout_width="match_parent"
             android:layout_height="@dimen/toolbar_height"

+ 1 - 0
app/src/main/res/values-de/strings.xml

@@ -734,4 +734,5 @@
     <string name="fence_area_empty_tip">Bitte stellen Sie den Zaunbereich ein.</string>
     <string name="at_least_one">Bitte wählen Sie mindestens einen Artikel aus</string>
     <string name="qr_format_error">QR-Code-Formatfehler</string>
+    <string name="unbind_tips">Bitte binden Sie zuerst die Uhren ab.</string>
 </resources>

+ 1 - 0
app/src/main/res/values-es/strings.xml

@@ -735,4 +735,5 @@
     <string name="fence_area_empty_tip">Por favor, establezca un área de valla.</string>
     <string name="at_least_one">Por favor, elija al menos un proyecto</string>
     <string name="qr_format_error">Formato de código QR incorrecto</string>
+    <string name="unbind_tips">Desata el reloj primero, por favor.</string>
 </resources>

+ 1 - 0
app/src/main/res/values-fr/strings.xml

@@ -724,4 +724,5 @@
     <string name="fence_area_empty_tip">Veuillez définir une zone clôturée.</string>
     <string name="at_least_one">Veuillez sélectionner au moins un projet</string>
     <string name="qr_format_error">Erreur de format du Code QR</string>
+    <string name="unbind_tips">Veuillez d\'abord défaire la montre.</string>
 </resources>

+ 1 - 0
app/src/main/res/values-it/strings.xml

@@ -785,4 +785,5 @@
     <string name="fence_area_empty_tip">Per favore, imposta l\'area della recinzione.</string>
     <string name="at_least_one">Seleziona almeno un elemento</string>
     <string name="qr_format_error">Errore di formato del codice QR</string>
+    <string name="unbind_tips">Per favore sblocca prima gli orologi.</string>
 </resources>

+ 1 - 0
app/src/main/res/values-zh-rCN/strings.xml

@@ -965,5 +965,6 @@
     <string name="at_least_one">请至少选择一项</string>
     <string name="push_content_fence_in">宝贝%1$s在%3$s进入了区域:%2$s</string>
     <string name="qr_format_error">二维码格式错误</string>
+    <string name="unbind_tips">请先解绑手表。</string>
 </resources>
 

+ 1 - 0
app/src/main/res/values/strings.xml

@@ -1066,4 +1066,5 @@
     
     <string name="at_least_one">Please select at least one item</string>
     <string name="qr_format_error">QR code format error</string>
+    <string name="unbind_tips">Please unbind the watches first.</string>
 </resources>

+ 6 - 16
google-services.json

@@ -1,31 +1,21 @@
 {
   "project_info": {
-    "project_number": "389777651454",
-    "firebase_url": "https://kido-158903.firebaseio.com",
-    "project_id": "kido-158903",
-    "storage_bucket": "kido-158903.appspot.com"
+    "project_number": "939861786046",
+    "project_id": "sik-veryfit",
+    "storage_bucket": "sik-veryfit.appspot.com"
   },
   "client": [
     {
       "client_info": {
-        "mobilesdk_app_id": "1:389777651454:android:5f5ed0e160c8b19f9f17af",
+        "mobilesdk_app_id": "1:939861786046:android:c287eb08059396a7264def",
         "android_client_info": {
           "package_name": "com.sikey.veryfit"
         }
       },
-      "oauth_client": [
-        {
-          "client_id": "389777651454-t1h7khdocjf7avicleb6e1o997jbpokn.apps.googleusercontent.com",
-          "client_type": 1,
-          "android_info": {
-            "package_name": "com.sikey.veryfit",
-            "certificate_hash": "8f2668baf60a0b920de8896503b4aabf85c83dbc"
-          }
-        }
-      ],
+      "oauth_client": [],
       "api_key": [
         {
-          "current_key": "AIzaSyA-jGorZyhppk2jIYsbSn2MxIV39bZFb6E"
+          "current_key": "AIzaSyAPixxqidp2Lf4mD_VcKKozQ9sgGZ5tHKI"
         }
       ],
       "services": {