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;
|
2015-04-01 10:14:05 +00:00
|
|
|
import eu.siacs.conversations.ui.ManageAccountActivity;
|
2014-07-31 13:09:34 +00:00
|
|
|
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;
|
2015-04-01 10:14:05 +00:00
|
|
|
import android.widget.Switch;
|
2014-07-31 13:09:34 +00:00
|
|
|
|
|
|
|
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) {
|
2015-04-01 10:14:05 +00:00
|
|
|
final Account account = getItem(position);
|
2014-07-31 13:09:34 +00:00
|
|
|
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);
|
2015-04-01 10:14:05 +00:00
|
|
|
imageView.setImageBitmap(activity.avatarService().get(account, activity.getPixel(48)));
|
|
|
|
statusView.setText(getContext().getString(account.getStatus().getReadableId()));
|
|
|
|
switch (account.getStatus()) {
|
|
|
|
case ONLINE:
|
|
|
|
statusView.setTextColor(activity.getOnlineColor());
|
|
|
|
break;
|
|
|
|
case DISABLED:
|
|
|
|
case CONNECTING:
|
|
|
|
statusView.setTextColor(activity.getSecondaryTextColor());
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
statusView.setTextColor(activity.getWarningTextColor());
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
final Switch tglAccountState = (Switch) view.findViewById(R.id.tgl_account_status);
|
|
|
|
boolean isDisabled = (account.getStatus() == Account.State.DISABLED) ? true : false;
|
|
|
|
tglAccountState.setChecked(!isDisabled);
|
|
|
|
tglAccountState.setOnClickListener(new View.OnClickListener() {
|
|
|
|
@Override
|
|
|
|
public void onClick(View v) {
|
|
|
|
if (activity instanceof ManageAccountActivity) {
|
|
|
|
((ManageAccountActivity) activity).onClickTglAccountState(account);
|
|
|
|
tglAccountState.toggle();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
2014-07-31 13:09:34 +00:00
|
|
|
return view;
|
|
|
|
}
|
|
|
|
}
|