Commit f62fb1db authored by Grigory Fedorov's avatar Grigory Fedorov

AccountToggleAdapter: light refactoring.

parent 392f4a5d
......@@ -76,17 +76,16 @@ public class AccountToggleAdapter implements UpdatableAdapter {
final LayoutInflater inflater = (LayoutInflater) activity
.getSystemService(Activity.LAYOUT_INFLATER_SERVICE);
while (linearLayout.getChildCount() < size) {
final View view = inflater.inflate(R.layout.account_toggler_item,
linearLayout, false);
final View view = inflater.inflate(R.layout.account_toggler_item, linearLayout, false);
linearLayout.addView(view);
final AccountViewHolder accountViewHolder = new AccountViewHolder(
view);
final AccountViewHolder accountViewHolder = new AccountViewHolder(view);
view.setTag(accountViewHolder);
activity.registerForContextMenu(accountViewHolder.statusMode);
accountViewHolder.statusMode.setOnClickListener(onClickListener);
}
while (linearLayout.getChildCount() > size)
while (linearLayout.getChildCount() > size) {
linearLayout.removeViewAt(size);
}
onChange();
}
......@@ -96,26 +95,24 @@ public class AccountToggleAdapter implements UpdatableAdapter {
String selected = AccountManager.getInstance().getSelectedAccount();
for (int index = 0; index < accounts.size(); index++) {
final View view = linearLayout.getChildAt(index);
final AccountViewHolder accountViewHolder = (AccountViewHolder) view
.getTag();
final AccountViewHolder accountViewHolder = (AccountViewHolder) view.getTag();
final String account = accounts.get(index);
StatusMode statusMode = AccountManager.getInstance()
.getAccount(account).getDisplayStatusMode();
int colorLevel = AccountManager.getInstance()
.getColorLevel(account);
StatusMode statusMode = AccountManager.getInstance().getAccount(account).getDisplayStatusMode();
int colorLevel = AccountManager.getInstance().getColorLevel(account);
view.getBackground().setLevel(colorLevel);
if (contactsShowAccounts)
if (contactsShowAccounts) {
accountViewHolder.statusMode.setBackgroundResource(R.drawable.account_border);
else
} else {
accountViewHolder.statusMode.setBackgroundResource(R.drawable.account_border_persistent);
if (selected == null || account.equals(selected))
}
if (selected == null || account.equals(selected)) {
accountViewHolder.disabled.setVisibility(View.GONE);
else
} else {
accountViewHolder.disabled.setVisibility(View.VISIBLE);
}
accountViewHolder.statusMode.getBackground().setLevel(colorLevel);
accountViewHolder.statusMode.setImageLevel(statusMode.ordinal());
accountViewHolder.avatar.setImageDrawable(AvatarManager
.getInstance().getAccountAvatar(account));
accountViewHolder.avatar.setImageDrawable(AvatarManager.getInstance().getAccountAvatar(account));
}
}
......@@ -135,11 +132,14 @@ public class AccountToggleAdapter implements UpdatableAdapter {
* @return The data for the specified view.
*/
public String getItemForView(View view) {
if (view.getId() == R.id.status_mode)
if (view.getId() == R.id.status_mode) {
view = (View) view.getParent();
for (int index = 0; index < linearLayout.getChildCount(); index++)
if (view == linearLayout.getChildAt(index))
}
for (int index = 0; index < linearLayout.getChildCount(); index++) {
if (view == linearLayout.getChildAt(index)) {
return accounts.get(index);
}
}
return null;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment