Commit f62fb1db authored by Grigory Fedorov's avatar Grigory Fedorov

AccountToggleAdapter: light refactoring.

parent 392f4a5d
...@@ -76,17 +76,16 @@ public class AccountToggleAdapter implements UpdatableAdapter { ...@@ -76,17 +76,16 @@ public class AccountToggleAdapter implements UpdatableAdapter {
final LayoutInflater inflater = (LayoutInflater) activity final LayoutInflater inflater = (LayoutInflater) activity
.getSystemService(Activity.LAYOUT_INFLATER_SERVICE); .getSystemService(Activity.LAYOUT_INFLATER_SERVICE);
while (linearLayout.getChildCount() < size) { while (linearLayout.getChildCount() < size) {
final View view = inflater.inflate(R.layout.account_toggler_item, final View view = inflater.inflate(R.layout.account_toggler_item, linearLayout, false);
linearLayout, false);
linearLayout.addView(view); linearLayout.addView(view);
final AccountViewHolder accountViewHolder = new AccountViewHolder( final AccountViewHolder accountViewHolder = new AccountViewHolder(view);
view);
view.setTag(accountViewHolder); view.setTag(accountViewHolder);
activity.registerForContextMenu(accountViewHolder.statusMode); activity.registerForContextMenu(accountViewHolder.statusMode);
accountViewHolder.statusMode.setOnClickListener(onClickListener); accountViewHolder.statusMode.setOnClickListener(onClickListener);
} }
while (linearLayout.getChildCount() > size) while (linearLayout.getChildCount() > size) {
linearLayout.removeViewAt(size); linearLayout.removeViewAt(size);
}
onChange(); onChange();
} }
...@@ -96,26 +95,24 @@ public class AccountToggleAdapter implements UpdatableAdapter { ...@@ -96,26 +95,24 @@ public class AccountToggleAdapter implements UpdatableAdapter {
String selected = AccountManager.getInstance().getSelectedAccount(); String selected = AccountManager.getInstance().getSelectedAccount();
for (int index = 0; index < accounts.size(); index++) { for (int index = 0; index < accounts.size(); index++) {
final View view = linearLayout.getChildAt(index); final View view = linearLayout.getChildAt(index);
final AccountViewHolder accountViewHolder = (AccountViewHolder) view final AccountViewHolder accountViewHolder = (AccountViewHolder) view.getTag();
.getTag();
final String account = accounts.get(index); final String account = accounts.get(index);
StatusMode statusMode = AccountManager.getInstance() StatusMode statusMode = AccountManager.getInstance().getAccount(account).getDisplayStatusMode();
.getAccount(account).getDisplayStatusMode(); int colorLevel = AccountManager.getInstance().getColorLevel(account);
int colorLevel = AccountManager.getInstance()
.getColorLevel(account);
view.getBackground().setLevel(colorLevel); view.getBackground().setLevel(colorLevel);
if (contactsShowAccounts) if (contactsShowAccounts) {
accountViewHolder.statusMode.setBackgroundResource(R.drawable.account_border); accountViewHolder.statusMode.setBackgroundResource(R.drawable.account_border);
else } else {
accountViewHolder.statusMode.setBackgroundResource(R.drawable.account_border_persistent); 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); accountViewHolder.disabled.setVisibility(View.GONE);
else } else {
accountViewHolder.disabled.setVisibility(View.VISIBLE); accountViewHolder.disabled.setVisibility(View.VISIBLE);
}
accountViewHolder.statusMode.getBackground().setLevel(colorLevel); accountViewHolder.statusMode.getBackground().setLevel(colorLevel);
accountViewHolder.statusMode.setImageLevel(statusMode.ordinal()); accountViewHolder.statusMode.setImageLevel(statusMode.ordinal());
accountViewHolder.avatar.setImageDrawable(AvatarManager accountViewHolder.avatar.setImageDrawable(AvatarManager.getInstance().getAccountAvatar(account));
.getInstance().getAccountAvatar(account));
} }
} }
...@@ -135,11 +132,14 @@ public class AccountToggleAdapter implements UpdatableAdapter { ...@@ -135,11 +132,14 @@ public class AccountToggleAdapter implements UpdatableAdapter {
* @return The data for the specified view. * @return The data for the specified view.
*/ */
public String getItemForView(View view) { public String getItemForView(View view) {
if (view.getId() == R.id.status_mode) if (view.getId() == R.id.status_mode) {
view = (View) view.getParent(); 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 accounts.get(index);
}
}
return null; 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