Parcourir la source

通讯录更新放子线程处理

weizhengliang il y a 3 ans
Parent
commit
5baffd893a

+ 6 - 4
home/src/main/code/com/wdkl/ncs/android/component/home/activity/WatchHome2Activity.kt

@@ -427,11 +427,13 @@ class WatchHome2Activity : BaseActivity<WatchHomeActivityPresenter, WatchActivit
     //写手机通讯录
     override fun setContact(contactVOs: List<WatchContactVO>) {
         if (contactVOs != null && contactVOs.size > 0) {
-            for (contactVO in contactVOs) {
-                if (!Strings.isNullOrEmpty(contactVO.name) && !Strings.isNullOrEmpty(contactVO.phoneNumber)) {
-                    ContactHelper.setContact(this, contactVO.name, contactVO.phoneNumber)
+            Thread {
+                for (contactVO in contactVOs) {
+                    if (!Strings.isNullOrEmpty(contactVO.name) && !Strings.isNullOrEmpty(contactVO.phoneNumber)) {
+                        ContactHelper.setContact(this, contactVO.name, contactVO.phoneNumber)
+                    }
                 }
-            }
+            }.start()
         }
     }
 

+ 3 - 1
middleware/src/main/code/com/wdkl/ncs/android/middleware/utils/ContactHelper.java

@@ -166,12 +166,14 @@ public class ContactHelper {
         Integer contact_id2 = isPhoneNumbExist(context, phoneNumber);
         Log.i("ContactId", "setContact: " + contact_id2 + "");
         if (contact_id != null && contact_id > 0) {
+            deleteContact(context,name);
             if (!(contact_id2 != null && contact_id2 > 0 && contact_id.equals(contact_id2))) { //非 通讯录中原有号码和姓名匹配的情况
                 if (contact_id2 != null && contact_id2 > 0) { //号码已经存在了
                     deleteContact(context, contact_id2); //删除号码
                 }
-                updateContact(context, contact_id, phoneNumber); //更新通讯录
+//                updateContact(context, contact_id, phoneNumber); //更新通讯录
             }//通讯录姓名和号码没有变化,不用操作
+            insertContact(context, name, phoneNumber);
         } else { //这个名字不存在通讯录中
             insertContact(context, name, phoneNumber);
             if(contact_id2!=null&&contact_id2>0){ //电话号码确在通讯录中