1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.exoplatform.accountswitcher;
20
21
22
23 import java.util.ArrayList;
24 import java.util.Locale;
25
26 import org.exoplatform.R;
27 import org.exoplatform.model.ExoAccount;
28 import org.exoplatform.singleton.AccountSetting;
29 import org.exoplatform.singleton.ServerSettingHelper;
30 import org.exoplatform.utils.SocialActivityUtil;
31
32 import android.content.Context;
33 import android.view.LayoutInflater;
34 import android.view.View;
35 import android.view.ViewGroup;
36 import android.widget.BaseAdapter;
37 import android.widget.ImageView;
38 import android.widget.TextView;
39
40 import com.squareup.picasso.Picasso;
41
42
43
44
45
46
47
48 public class AccountListAdapter extends BaseAdapter {
49
50 private ArrayList<ExoAccount> mAccountList;
51
52 private final String TAG = "eXo____AccountListAdapter____";
53
54 public AccountListAdapter(Context ctx) {
55 mAccountList = ServerSettingHelper.getInstance().getServerInfoList(ctx);
56 }
57
58 @Override
59 public int getCount() {
60 return mAccountList.size();
61 }
62
63 @Override
64 public Object getItem(int index) {
65 return mAccountList.get(index);
66 }
67
68 @Override
69 public long getItemId(int index) {
70 return index;
71 }
72
73 @Override
74 public View getView(int index, View convertView, ViewGroup parent) {
75 ViewHolder holder;
76 Context mContext = parent.getContext();
77 if (convertView == null) {
78 LayoutInflater inflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
79 convertView = inflater.inflate(R.layout.account_switcher_item_layout, parent, false);
80 holder = new ViewHolder();
81 holder.accountName = (TextView)convertView.findViewById(R.id.account_name_textview);
82 holder.accountServerURL = (TextView)convertView.findViewById(R.id.account_server_textview);
83 holder.userFullName = (TextView)convertView.findViewById(R.id.account_user_fullname_textview);
84 holder.accountUsername = (TextView)convertView.findViewById(R.id.account_username_textview);
85 holder.connectionStatus = (TextView)convertView.findViewById(R.id.account_connection_status_textview);
86 holder.userAvatar = (ImageView)convertView.findViewById(R.id.account_avatar_imageview);
87 convertView.setTag(holder);
88 } else {
89 holder = (ViewHolder)convertView.getTag();
90 }
91
92 ExoAccount account = mAccountList.get(index);
93 holder.accountName.setText(account.accountName.toUpperCase(Locale.getDefault()));
94 holder.accountServerURL.setText(account.serverUrl);
95 holder.accountUsername.setText(account.username);
96 holder.userFullName.setText(account.userFullName);
97 String connStatus;
98 if (String.valueOf(index).equals(AccountSetting.getInstance().getDomainIndex())) {
99
100 connStatus = mContext.getResources().getString(R.string.Connected);
101 holder.connectionStatus.setVisibility(View.VISIBLE);
102 } else {
103 if (account.lastLoginDate == -1) {
104
105 connStatus = "";
106 holder.connectionStatus.setVisibility(View.GONE);
107 } else {
108 StringBuilder statusBld = new StringBuilder();
109
110 statusBld.append(mContext.getResources().getString(R.string.LastLoginDate));
111
112 statusBld.append(": ").append(SocialActivityUtil.getPostedTimeString(mContext, account.lastLoginDate));
113 connStatus = statusBld.toString();
114 holder.connectionStatus.setVisibility(View.VISIBLE);
115 }
116 }
117 holder.connectionStatus.setText(connStatus);
118
119 if ("".equalsIgnoreCase(account.avatarUrl)) {
120
121 Picasso.with(mContext).load(R.drawable.default_avatar)
122 .resizeDimen(R.dimen.account_list_avatar_size, R.dimen.account_list_avatar_size).centerCrop()
123 .into(holder.userAvatar);
124 } else {
125
126 Picasso.with(mContext).load(account.avatarUrl)
127 .resizeDimen(R.dimen.account_list_avatar_size, R.dimen.account_list_avatar_size).centerCrop()
128 .into(holder.userAvatar);
129 }
130
131 return convertView;
132 }
133
134 static class ViewHolder {
135 TextView accountName;
136 TextView accountServerURL;
137 TextView userFullName;
138 TextView accountUsername;
139 TextView connectionStatus;
140 ImageView userAvatar;
141 }
142
143 }