diff --git a/contacts/build.gradle b/contacts/build.gradle index 7bf188e..55ef8d2 100644 --- a/contacts/build.gradle +++ b/contacts/build.gradle @@ -49,23 +49,19 @@ android { } dependencies { - // 二维码使用的类库 - api 'com.google.zxing:core:3.4.1' - api 'com.journeyapps:zxing-android-embedded:3.6.0' + implementation fileTree(dir: 'libs', include: ['*.jar']) - api 'io.github.medyo:android-about-page:2.0.0' - api 'com.github.getActivity:ToastUtils:10.5' - api 'com.jcraft:jsch:0.1.55' - api 'org.jsoup:jsoup:1.13.1' - api 'com.squareup.okhttp3:okhttp:4.4.1' + // https://mvnrepository.com/artifact/com.github.open-android/pinyin4j + implementation 'com.github.open-android:pinyin4j:2.5.0' + + implementation 'io.github.medyo:android-about-page:2.0.0' + implementation 'com.github.getActivity:ToastUtils:10.5' - api 'androidx.appcompat:appcompat:1.1.0' - api 'androidx.viewpager:viewpager:1.0.0' - api 'androidx.fragment:fragment:1.1.0' - api 'com.google.android.material:material:1.4.0' + implementation 'androidx.appcompat:appcompat:1.1.0' + implementation 'androidx.viewpager:viewpager:1.0.0' + implementation 'androidx.fragment:fragment:1.1.0' + implementation 'com.google.android.material:material:1.4.0' - api 'cc.winboll.studio:libapputils:9.3.2' - api 'cc.winboll.studio:libappbase:1.5.6' - - api fileTree(dir: 'libs', include: ['*.jar']) + implementation 'cc.winboll.studio:libapputils:9.3.2' + implementation 'cc.winboll.studio:libappbase:1.5.6' } diff --git a/contacts/build.properties b/contacts/build.properties index fe4eca4..769e989 100644 --- a/contacts/build.properties +++ b/contacts/build.properties @@ -1,8 +1,8 @@ #Created by .winboll/winboll_app_build.gradle -#Wed Feb 26 06:08:35 GMT 2025 +#Wed Feb 26 06:42:40 GMT 2025 stageCount=4 libraryProject= baseVersion=1.0 publishVersion=1.0.3 -buildCount=5 +buildCount=8 baseBetaVersion=1.0.4 diff --git a/contacts/src/main/java/cc/winboll/studio/contacts/adapters/ContactAdapter.java b/contacts/src/main/java/cc/winboll/studio/contacts/adapters/ContactAdapter.java index c1b526f..b2e2950 100644 --- a/contacts/src/main/java/cc/winboll/studio/contacts/adapters/ContactAdapter.java +++ b/contacts/src/main/java/cc/winboll/studio/contacts/adapters/ContactAdapter.java @@ -5,9 +5,12 @@ package cc.winboll.studio.contacts.adapters; * @Date 2025/02/26 13:35:44 * @Describe ContactAdapter */ +import android.content.Intent; +import android.net.Uri; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; +import android.widget.Button; import android.widget.TextView; import androidx.annotation.NonNull; import androidx.recyclerview.widget.RecyclerView; @@ -19,6 +22,7 @@ public class ContactAdapter extends RecyclerView.Adapter contactList; public ContactAdapter(List contactList) { @@ -34,9 +38,18 @@ public class ContactAdapter extends RecyclerView.Adapter contactList = new ArrayList<>(); - + private List originalContactList = new ArrayList<>(); + private EditText searchEditText; public static ContactsFragment newInstance(int page) { Bundle args = new Bundle(); @@ -54,10 +58,6 @@ public class ContactsFragment extends Fragment { } } - - - - @Nullable @Override public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { @@ -72,6 +72,22 @@ public class ContactsFragment extends Fragment { contactAdapter = new ContactAdapter(contactList); recyclerView.setAdapter(contactAdapter); + searchEditText = view.findViewById(R.id.search_edit_text); + searchEditText.addTextChangedListener(new TextWatcher() { + @Override + public void beforeTextChanged(CharSequence s, int start, int count, int after) { + } + + @Override + public void onTextChanged(CharSequence s, int start, int before, int count) { + filterContacts(s.toString()); + } + + @Override + public void afterTextChanged(Editable s) { + } + }); + if (ActivityCompat.checkSelfPermission(requireContext(), Manifest.permission.READ_CONTACTS) != PackageManager.PERMISSION_GRANTED) { ActivityCompat.requestPermissions(requireActivity(), new String[]{Manifest.permission.READ_CONTACTS}, REQUEST_READ_CONTACTS); } else { @@ -91,6 +107,7 @@ public class ContactsFragment extends Fragment { private void readContacts() { contactList.clear(); + originalContactList.clear(); Cursor cursor = requireContext().getContentResolver().query( ContactsContract.CommonDataKinds.Phone.CONTENT_URI, null, @@ -102,10 +119,29 @@ public class ContactsFragment extends Fragment { while (cursor.moveToNext()) { String name = cursor.getString(cursor.getColumnIndex(ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME)); String number = cursor.getString(cursor.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER)); - contactList.add(new ContactModel(name, number)); + ContactModel contact = new ContactModel(name, number); + contactList.add(contact); + originalContactList.add(contact); } cursor.close(); contactAdapter.notifyDataSetChanged(); } } + + private void filterContacts(String query) { + contactList.clear(); + if (query.isEmpty()) { + contactList.addAll(originalContactList); + } else { + for (ContactModel contact : originalContactList) { + if (contact.getName().toLowerCase().contains(query.toLowerCase()) || + contact.getPinyin().toLowerCase().contains(query.toLowerCase()) || + contact.getNumber().toLowerCase().contains(query.toLowerCase())) { + contactList.add(contact); + } + } + } + contactAdapter.notifyDataSetChanged(); + } } + diff --git a/contacts/src/main/res/layout/fragment_contacts.xml b/contacts/src/main/res/layout/fragment_contacts.xml index 1628f8a..b2769a6 100644 --- a/contacts/src/main/res/layout/fragment_contacts.xml +++ b/contacts/src/main/res/layout/fragment_contacts.xml @@ -6,6 +6,13 @@ android:layout_width="match_parent" android:layout_height="match_parent"> + + - + - + - + + +