2014-07-31 13:09:34 +00:00
|
|
|
package eu.siacs.conversations.ui.adapter;
|
|
|
|
|
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
import eu.siacs.conversations.R;
|
|
|
|
import eu.siacs.conversations.entities.Account;
|
|
|
|
import eu.siacs.conversations.ui.XmppActivity;
|
|
|
|
import android.content.Context;
|
|
|
|
import android.view.LayoutInflater;
|
|
|
|
import android.view.View;
|
|
|
|
import android.view.ViewGroup;
|
|
|
|
import android.widget.ArrayAdapter;
|
|
|
|
import android.widget.ImageView;
|
|
|
|
import android.widget.TextView;
|
|
|
|
|
|
|
|
public class AccountAdapter extends ArrayAdapter<Account> {
|
2014-08-31 14:28:21 +00:00
|
|
|
|
2014-07-31 13:09:34 +00:00
|
|
|
private XmppActivity activity;
|
2014-08-31 14:28:21 +00:00
|
|
|
|
2014-07-31 13:09:34 +00:00
|
|
|
public AccountAdapter(XmppActivity activity, List<Account> objects) {
|
|
|
|
super(activity, 0, objects);
|
|
|
|
this.activity = activity;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public View getView(int position, View view, ViewGroup parent) {
|
|
|
|
Account account = getItem(position);
|
|
|
|
if (view == null) {
|
|
|
|
LayoutInflater inflater = (LayoutInflater) getContext()
|
|
|
|
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
|
2014-10-26 17:54:10 +00:00
|
|
|
view = inflater.inflate(R.layout.account_row, parent, false);
|
2014-07-31 13:09:34 +00:00
|
|
|
}
|
|
|
|
TextView jid = (TextView) view.findViewById(R.id.account_jid);
|
2014-11-09 15:57:22 +00:00
|
|
|
jid.setText(account.getJid().toBareJid().toString());
|
2014-07-31 13:09:34 +00:00
|
|
|
TextView statusView = (TextView) view.findViewById(R.id.account_status);
|
|
|
|
ImageView imageView = (ImageView) view.findViewById(R.id.account_image);
|
2014-10-21 12:57:16 +00:00
|
|
|
imageView.setImageBitmap(activity.avatarService().get(account,
|
|
|
|
activity.getPixel(48)));
|
2014-07-31 13:09:34 +00:00
|
|
|
switch (account.getStatus()) {
|
2014-11-15 16:09:02 +00:00
|
|
|
case DISABLED:
|
2014-07-31 13:09:34 +00:00
|
|
|
statusView.setText(getContext().getString(
|
|
|
|
R.string.account_status_disabled));
|
|
|
|
statusView.setTextColor(activity.getSecondaryTextColor());
|
|
|
|
break;
|
2014-11-15 16:09:02 +00:00
|
|
|
case ONLINE:
|
2014-07-31 13:09:34 +00:00
|
|
|
statusView.setText(getContext().getString(
|
|
|
|
R.string.account_status_online));
|
|
|
|
statusView.setTextColor(activity.getPrimaryColor());
|
|
|
|
break;
|
2014-11-15 16:09:02 +00:00
|
|
|
case CONNECTING:
|
2014-07-31 13:09:34 +00:00
|
|
|
statusView.setText(getContext().getString(
|
|
|
|
R.string.account_status_connecting));
|
|
|
|
statusView.setTextColor(activity.getSecondaryTextColor());
|
|
|
|
break;
|
2014-11-15 16:09:02 +00:00
|
|
|
case OFFLINE:
|
2014-07-31 13:09:34 +00:00
|
|
|
statusView.setText(getContext().getString(
|
|
|
|
R.string.account_status_offline));
|
|
|
|
statusView.setTextColor(activity.getWarningTextColor());
|
|
|
|
break;
|
2014-11-15 16:09:02 +00:00
|
|
|
case UNAUTHORIZED:
|
2014-07-31 13:09:34 +00:00
|
|
|
statusView.setText(getContext().getString(
|
|
|
|
R.string.account_status_unauthorized));
|
|
|
|
statusView.setTextColor(activity.getWarningTextColor());
|
|
|
|
break;
|
2014-11-15 16:09:02 +00:00
|
|
|
case SERVER_NOT_FOUND:
|
2014-07-31 13:09:34 +00:00
|
|
|
statusView.setText(getContext().getString(
|
|
|
|
R.string.account_status_not_found));
|
|
|
|
statusView.setTextColor(activity.getWarningTextColor());
|
|
|
|
break;
|
2014-11-15 16:09:02 +00:00
|
|
|
case NO_INTERNET:
|
2014-07-31 13:09:34 +00:00
|
|
|
statusView.setText(getContext().getString(
|
|
|
|
R.string.account_status_no_internet));
|
|
|
|
statusView.setTextColor(activity.getWarningTextColor());
|
|
|
|
break;
|
2014-11-15 16:09:02 +00:00
|
|
|
case REGISTRATION_FAILED:
|
2014-07-31 13:09:34 +00:00
|
|
|
statusView.setText(getContext().getString(
|
|
|
|
R.string.account_status_regis_fail));
|
|
|
|
statusView.setTextColor(activity.getWarningTextColor());
|
|
|
|
break;
|
2014-11-15 16:09:02 +00:00
|
|
|
case REGISTRATION_CONFLICT:
|
2014-07-31 13:09:34 +00:00
|
|
|
statusView.setText(getContext().getString(
|
|
|
|
R.string.account_status_regis_conflict));
|
|
|
|
statusView.setTextColor(activity.getWarningTextColor());
|
|
|
|
break;
|
2014-11-15 16:09:02 +00:00
|
|
|
case REGISTRATION_SUCCESSFUL:
|
2014-07-31 13:09:34 +00:00
|
|
|
statusView.setText(getContext().getString(
|
|
|
|
R.string.account_status_regis_success));
|
|
|
|
statusView.setTextColor(activity.getSecondaryTextColor());
|
|
|
|
break;
|
2014-11-15 16:09:02 +00:00
|
|
|
case REGISTRATION_NOT_SUPPORTED:
|
2014-07-31 13:09:34 +00:00
|
|
|
statusView.setText(getContext().getString(
|
|
|
|
R.string.account_status_regis_not_sup));
|
|
|
|
statusView.setTextColor(activity.getWarningTextColor());
|
|
|
|
break;
|
2014-11-15 16:19:42 +00:00
|
|
|
case SECURITY_ERROR:
|
|
|
|
statusView.setText(getContext().getString
|
|
|
|
(R.string.account_status_security_error));
|
|
|
|
statusView.setTextColor(activity.getWarningTextColor());
|
2014-07-31 13:09:34 +00:00
|
|
|
default:
|
|
|
|
statusView.setText("");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return view;
|
|
|
|
}
|
|
|
|
}
|