Browse Source

Show identity email

Requested by @Primokorn
main
M66B 6 years ago
parent
commit
dbff583f05
3 changed files with 69 additions and 3 deletions
  1. +40
    -1
      app/src/main/java/eu/faircode/email/FragmentCompose.java
  2. +3
    -2
      app/src/main/res/layout/fragment_compose.xml
  3. +26
    -0
      app/src/main/res/layout/spinner_item2.xml

+ 40
- 1
app/src/main/java/eu/faircode/email/FragmentCompose.java View File

@ -45,6 +45,7 @@ import android.widget.FilterQueryProvider;
import android.widget.ImageView; import android.widget.ImageView;
import android.widget.ProgressBar; import android.widget.ProgressBar;
import android.widget.Spinner; import android.widget.Spinner;
import android.widget.TextView;
import android.widget.Toast; import android.widget.Toast;
import com.google.android.material.bottomnavigation.BottomNavigationView; import com.google.android.material.bottomnavigation.BottomNavigationView;
@ -659,7 +660,7 @@ public class FragmentCompose extends FragmentEx {
}); });
// Show identities // Show identities
ArrayAdapter<EntityIdentity> adapter = new ArrayAdapter<>(getContext(), R.layout.spinner_item, identities);
IdentityAdapter adapter = new IdentityAdapter(getContext(), identities);
adapter.setDropDownViewResource(R.layout.spinner_dropdown_item); adapter.setDropDownViewResource(R.layout.spinner_dropdown_item);
spFrom.setAdapter(adapter); spFrom.setAdapter(adapter);
@ -874,4 +875,42 @@ public class FragmentCompose extends FragmentEx {
Toast.makeText(getContext(), ex.toString(), Toast.LENGTH_LONG).show(); Toast.makeText(getContext(), ex.toString(), Toast.LENGTH_LONG).show();
} }
}; };
public class IdentityAdapter extends ArrayAdapter<EntityIdentity> {
private Context context;
private List<EntityIdentity> identities;
public IdentityAdapter(@NonNull Context context, List<EntityIdentity> identities) {
super(context, 0, identities);
this.context = context;
this.identities = identities;
}
@NonNull
@Override
public View getView(int position, @Nullable View convertView, @NonNull ViewGroup parent) {
return getLayout(position, convertView, parent);
}
@Override
public View getDropDownView(int position, View convertView, ViewGroup parent) {
return getLayout(position, convertView, parent);
}
public View getLayout(int position, View convertView, ViewGroup parent) {
View view = convertView;
if (view == convertView)
view = LayoutInflater.from(context).inflate(R.layout.spinner_item2, parent, false);
EntityIdentity identity = identities.get(position);
TextView name = view.findViewById(android.R.id.text1);
name.setText(identity.name);
TextView email = view.findViewById(android.R.id.text2);
email.setText(identity.email);
return view;
}
}
} }

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

@ -6,10 +6,11 @@
<Spinner <Spinner
android:id="@+id/spFrom" android:id="@+id/spFrom"
android:layout_width="wrap_content"
android:layout_width="0dp"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginStart="6dp" android:layout_marginStart="6dp"
android:layout_marginTop="6dp" android:layout_marginTop="6dp"
app:layout_constraintEnd_toStartOf="@+id/ivIdentityAdd"
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" /> app:layout_constraintTop_toTopOf="parent" />
@ -21,7 +22,7 @@
android:layout_marginStart="6dp" android:layout_marginStart="6dp"
android:src="@drawable/baseline_person_add_24" android:src="@drawable/baseline_person_add_24"
app:layout_constraintBottom_toBottomOf="@id/spFrom" app:layout_constraintBottom_toBottomOf="@id/spFrom"
app:layout_constraintStart_toEndOf="@id/spFrom"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="@id/spFrom" /> app:layout_constraintTop_toTopOf="@id/spFrom" />
<AutoCompleteTextView <AutoCompleteTextView


+ 26
- 0
app/src/main/res/layout/spinner_item2.xml View File

@ -0,0 +1,26 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="wrap_content"
android:layout_height="?android:attr/listPreferredItemHeightSmall"
android:paddingEnd="?android:attr/listPreferredItemPaddingEnd"
android:paddingStart="?android:attr/listPreferredItemPaddingStart">
<TextView
android:id="@android:id/text1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Name"
android:textAppearance="@style/TextAppearance.AppCompat.Medium"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="@android:id/text2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Email"
android:textAppearance="@style/TextAppearance.AppCompat.Small"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@android:id/text1" />
</androidx.constraintlayout.widget.ConstraintLayout>

Loading…
Cancel
Save