diff --git a/contacts/build.properties b/contacts/build.properties index 8a3dba2..87d0fd5 100644 --- a/contacts/build.properties +++ b/contacts/build.properties @@ -1,8 +1,8 @@ #Created by .winboll/winboll_app_build.gradle -#Thu Mar 06 20:00:52 HKT 2025 +#Thu Mar 06 13:42:11 GMT 2025 stageCount=12 libraryProject= baseVersion=1.0 publishVersion=1.0.11 -buildCount=0 +buildCount=3 baseBetaVersion=1.0.12 diff --git a/contacts/src/main/java/cc/winboll/studio/contacts/adapters/CallLogAdapter.java b/contacts/src/main/java/cc/winboll/studio/contacts/adapters/CallLogAdapter.java index 985378e..3dde402 100644 --- a/contacts/src/main/java/cc/winboll/studio/contacts/adapters/CallLogAdapter.java +++ b/contacts/src/main/java/cc/winboll/studio/contacts/adapters/CallLogAdapter.java @@ -5,7 +5,10 @@ package cc.winboll.studio.contacts.adapters; * @Date 2025/02/26 13:09:32 * @Describe CallLogAdapter */ +import android.content.ContentResolver; import android.content.Intent; +import android.database.Cursor; +import android.provider.ContactsContract; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; @@ -17,15 +20,24 @@ import cc.winboll.studio.contacts.R; import cc.winboll.studio.contacts.beans.CallLogModel; import com.hjq.toast.ToastUtils; import java.text.SimpleDateFormat; +import java.util.ArrayList; +import java.util.HashMap; import java.util.List; import java.util.Locale; +import java.util.Map; +import cc.winboll.studio.contacts.utils.ContactUtils; +import android.content.Context; public class CallLogAdapter extends RecyclerView.Adapter { public static final String TAG = "CallLogAdapter"; private List callLogList; - - public CallLogAdapter(List callLogList) { + ContactUtils mContactUtils; + Context mContext; + + public CallLogAdapter(Context context, List callLogList) { + mContext = context; + this.mContactUtils = ContactUtils.getInstance(mContext); this.callLogList = callLogList; } @@ -39,7 +51,7 @@ public class CallLogAdapter extends RecyclerView.Adapter contactMap = new HashMap<>(); + + static volatile ContactUtils _ContactUtils; + Context mContext; + ContactUtils(Context context) { + mContext = context; + relaodContacts(); + } + public synchronized static ContactUtils getInstance(Context context) { + if (_ContactUtils == null) { + _ContactUtils = new ContactUtils(context); + } + return _ContactUtils; + } + + public void relaodContacts() { + readContacts(); + } + + private void readContacts() { + contactMap.clear(); + ContentResolver contentResolver = mContext.getContentResolver(); + Cursor cursor = contentResolver.query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI, + null, null, null, null); + if (cursor != null) { + while (cursor.moveToNext()) { + String displayName = cursor.getString(cursor.getColumnIndex(ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME)); + String phoneNumber = cursor.getString(cursor.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER)); + //Map contactMap = new HashMap<>(); + contactMap.put(getSimplePhone(phoneNumber), displayName); + } + cursor.close(); + } + // 此时 contactList 就是存储联系人信息的 Map 列表 + } + + public String getContactsName(String phone) { + String result = contactMap.get(getSimplePhone(phone)); + return result == null ? "[NoInContacts]" : result; + } + + static String getSimplePhone(String phone) { + return phone.replaceAll("[+\\s]", ""); + } +}