FairEmail/app/src/main/java/eu/faircode/email/AdapterIdentitySelect.java

93 lines
3.3 KiB
Java
Raw Normal View History

2019-09-26 17:17:03 +00:00
package eu.faircode.email;
2021-01-01 07:56:36 +00:00
/*
This file is part of FairEmail.
FairEmail is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
FairEmail is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with FairEmail. If not, see <http://www.gnu.org/licenses/>.
2022-01-01 08:46:36 +00:00
Copyright 2018-2022 by Marcel Bokhorst (M66B)
2021-01-01 07:56:36 +00:00
*/
2019-09-26 17:17:03 +00:00
import android.content.Context;
import android.graphics.Color;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import java.util.List;
public class AdapterIdentitySelect extends ArrayAdapter<TupleIdentityEx> {
private Context context;
private List<TupleIdentityEx> identities;
2021-01-01 08:20:41 +00:00
private boolean hasColor = false;
2019-09-26 17:17:03 +00:00
AdapterIdentitySelect(@NonNull Context context, List<TupleIdentityEx> identities) {
super(context, 0, identities);
this.context = context;
this.identities = identities;
2021-01-01 08:20:41 +00:00
for (TupleIdentityEx identity : identities)
if (identity.color != null) {
hasColor = true;
break;
}
2019-09-26 17:17:03 +00:00
}
@NonNull
@Override
public View getView(int position, @Nullable View convertView, @NonNull ViewGroup parent) {
return getLayout(position, convertView, parent, R.layout.spinner_identity);
2019-09-26 17:17:03 +00:00
}
@Override
2019-11-08 19:19:11 +00:00
public View getDropDownView(int position, View convertView, @NonNull ViewGroup parent) {
2020-03-30 16:12:36 +00:00
return getLayout(position, convertView, parent, R.layout.spinner_identity);
2019-09-26 17:17:03 +00:00
}
2019-11-08 19:19:11 +00:00
private View getLayout(int position, View convertView, ViewGroup parent, int resid) {
2019-09-26 17:17:03 +00:00
View view = LayoutInflater.from(context).inflate(resid, parent, false);
TupleIdentityEx identity = identities.get(position);
View vwColor = view.findViewById(R.id.vwColor);
TextView text1 = view.findViewById(android.R.id.text1);
TextView text2 = view.findViewById(android.R.id.text2);
2020-03-30 16:12:36 +00:00
TextView tvExtra = view.findViewById(R.id.tvExtra);
2019-09-26 17:17:03 +00:00
vwColor.setBackgroundColor(identity.color == null ? Color.TRANSPARENT : identity.color);
2021-01-01 08:20:41 +00:00
vwColor.setVisibility(hasColor ? View.VISIBLE : View.GONE);
boolean single = (identities.size() == 1 && identity.cc == null && identity.bcc == null);
if (single)
text1.setText(identity.getDisplayName() + " <" + identity.email + ">");
else {
text1.setText(identity.getDisplayName() + (identity.primary ? "" : ""));
text2.setText(identity.accountName + "/" + identity.email);
}
2020-03-30 16:12:36 +00:00
tvExtra.setText((identity.cc == null ? "" : "+CC") + (identity.bcc == null ? "" : "+BCC"));
2021-01-01 08:20:41 +00:00
text2.setVisibility(single ? View.GONE : View.VISIBLE);
2020-03-30 16:12:36 +00:00
tvExtra.setVisibility(identity.cc == null && identity.bcc == null ? View.GONE : View.VISIBLE);
2019-09-26 17:17:03 +00:00
return view;
}
}