Browse Source

Search contacts on typing

main
M66B 6 years ago
parent
commit
53d77fe205
6 changed files with 64 additions and 11 deletions
  1. +1
    -1
      app/src/main/AndroidManifest.xml
  2. +57
    -3
      app/src/main/java/eu/faircode/email/FragmentCompose.java
  3. +1
    -0
      app/src/main/java/eu/faircode/email/FragmentSetup.java
  4. +3
    -3
      app/src/main/res/layout/fragment_compose.xml
  5. +1
    -4
      app/src/main/res/layout/fragment_setup.xml
  6. +1
    -0
      app/src/main/res/values/strings.xml

+ 1
- 1
app/src/main/AndroidManifest.xml View File

@ -5,7 +5,7 @@
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<!-- uses-permission android:name="android.permission.READ_CONTACTS" / -->
<uses-permission android:name="android.permission.READ_CONTACTS" />
<application
android:name=".ApplicationEx"


+ 57
- 3
app/src/main/java/eu/faircode/email/FragmentCompose.java View File

@ -19,8 +19,10 @@ package eu.faircode.email;
Copyright 2018 by Marcel Bokhorst (M66B)
*/
import android.Manifest;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.database.Cursor;
import android.os.Bundle;
import android.os.Handler;
@ -35,7 +37,9 @@ import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.AutoCompleteTextView;
import android.widget.EditText;
import android.widget.FilterQueryProvider;
import android.widget.ImageView;
import android.widget.ProgressBar;
import android.widget.Spinner;
@ -56,6 +60,8 @@ import javax.mail.internet.InternetAddress;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.constraintlayout.widget.Group;
import androidx.core.content.ContextCompat;
import androidx.cursoradapter.widget.SimpleCursorAdapter;
import androidx.fragment.app.FragmentTransaction;
import androidx.lifecycle.Observer;
import androidx.loader.app.LoaderManager;
@ -71,11 +77,11 @@ public class FragmentCompose extends FragmentEx {
private Spinner spFrom;
private ImageView ivIdentityAdd;
private EditText etTo;
private AutoCompleteTextView etTo;
private ImageView ivToAdd;
private EditText etCc;
private AutoCompleteTextView etCc;
private ImageView ivCcAdd;
private EditText etBcc;
private AutoCompleteTextView etBcc;
private ImageView ivBccAdd;
private EditText etSubject;
private EditText etBody;
@ -182,6 +188,54 @@ public class FragmentCompose extends FragmentEx {
pbWait.setVisibility(View.VISIBLE);
bottom_navigation.getMenu().setGroupEnabled(0, false);
if (ContextCompat.checkSelfPermission(getContext(), Manifest.permission.READ_CONTACTS)
== PackageManager.PERMISSION_GRANTED) {
SimpleCursorAdapter adapter = new SimpleCursorAdapter(
getContext(),
android.R.layout.simple_list_item_2,
null,
new String[]{
ContactsContract.Contacts.DISPLAY_NAME,
ContactsContract.CommonDataKinds.Email.DATA
},
new int[]{
android.R.id.text1,
android.R.id.text2
},
0);
etTo.setAdapter(adapter);
etCc.setAdapter(adapter);
etBcc.setAdapter(adapter);
adapter.setFilterQueryProvider(new FilterQueryProvider() {
public Cursor runQuery(CharSequence typed) {
return getContext().getContentResolver().query(
ContactsContract.CommonDataKinds.Email.CONTENT_URI,
new String[]{
ContactsContract.RawContacts._ID,
ContactsContract.Contacts.DISPLAY_NAME,
ContactsContract.CommonDataKinds.Email.DATA
},
ContactsContract.CommonDataKinds.Email.DATA + " <> ''" +
" AND (" + ContactsContract.Contacts.DISPLAY_NAME + " LIKE '%" + typed + "%'" +
" OR " + ContactsContract.CommonDataKinds.Email.DATA + " LIKE '%" + typed + "%')",
null,
"CASE WHEN " + ContactsContract.Contacts.DISPLAY_NAME + " NOT LIKE '%@%' THEN 0 ELSE 1 END" +
", " + ContactsContract.Contacts.DISPLAY_NAME +
", " + ContactsContract.CommonDataKinds.Email.DATA + " COLLATE NOCASE");
}
});
adapter.setCursorToStringConverter(new SimpleCursorAdapter.CursorToStringConverter() {
public CharSequence convertToString(Cursor cursor) {
int colName = cursor.getColumnIndex(ContactsContract.Contacts.DISPLAY_NAME);
int colEmail = cursor.getColumnIndex(ContactsContract.CommonDataKinds.Email.DATA);
return cursor.getString(colName) + "<" + cursor.getString(colEmail) + ">";
}
});
}
return view;
}


+ 1
- 0
app/src/main/java/eu/faircode/email/FragmentSetup.java View File

@ -114,6 +114,7 @@ public class FragmentSetup extends FragmentEx {
btnPermissions.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
btnPermissions.setEnabled(false);
requestPermissions(permissions, 1);
}
});


+ 3
- 3
app/src/main/res/layout/fragment_compose.xml View File

@ -24,7 +24,7 @@
app:layout_constraintStart_toEndOf="@id/spFrom"
app:layout_constraintTop_toTopOf="@id/spFrom" />
<EditText
<AutoCompleteTextView
android:id="@+id/etTo"
android:layout_width="0dp"
android:layout_height="wrap_content"
@ -49,7 +49,7 @@
app:layout_constraintStart_toEndOf="@id/etTo"
app:layout_constraintTop_toTopOf="@+id/etTo" />
<EditText
<AutoCompleteTextView
android:id="@+id/etCc"
android:layout_width="0dp"
android:layout_height="wrap_content"
@ -74,7 +74,7 @@
app:layout_constraintStart_toEndOf="@id/etCc"
app:layout_constraintTop_toTopOf="@+id/etCc" />
<EditText
<AutoCompleteTextView
android:id="@+id/etBcc"
android:layout_width="0dp"
android:layout_height="wrap_content"


+ 1
- 4
app/src/main/res/layout/fragment_setup.xml View File

@ -108,7 +108,6 @@
android:layout_marginTop="24dp"
android:text="@string/title_setup_permissions"
android:textAppearance="@style/TextAppearance.AppCompat.Medium"
android:visibility="gone"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/tvIdentityDone" />
@ -119,7 +118,6 @@
android:layout_height="wrap_content"
android:text="@string/title_setup_permissions_remark"
android:textAppearance="@style/TextAppearance.AppCompat.Small"
android:visibility="gone"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/btnPermissions" />
@ -128,9 +126,8 @@
android:id="@+id/tvPermissionsDone"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/title_setup_done"
android:text="@string/title_setup_granted"
android:textAppearance="@style/TextAppearance.AppCompat.Medium"
android:visibility="gone"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/tvPermissions" />


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

@ -51,6 +51,7 @@
<string name="title_setup_permissions_remark">To read contacts (optional)</string>
<string name="title_setup_messages">View messages</string>
<string name="title_setup_done">Done</string>
<string name="title_setup_granted">Granted</string>
<string name="title_setup_dark_theme">Dark theme</string>
<string name="title_setup_debug">Debug</string>


Loading…
Cancel
Save