diff --git a/res/layout/accounts_item.xml b/res/layout/accounts_item.xml index b25c398a8..8c76ac48e 100644 --- a/res/layout/accounts_item.xml +++ b/res/layout/accounts_item.xml @@ -9,7 +9,8 @@ android:paddingRight="6dip" android:paddingBottom="2dip" android:descendantFocusability="blocksDescendants" - android:gravity="center_vertical" > + android:gravity="center_vertical" + android:background="#ccc" > + android:layout_alignParentLeft="true" + android:background="@android:color/transparent" /> » Unable to connect. + + Account \"%s\" is unavailable; check storage + diff --git a/src/com/fsck/k9/AccountStats.java b/src/com/fsck/k9/AccountStats.java index d69685e66..146a8c94b 100644 --- a/src/com/fsck/k9/AccountStats.java +++ b/src/com/fsck/k9/AccountStats.java @@ -10,4 +10,5 @@ public class AccountStats implements Serializable { public long size = -1; public int unreadMessageCount = 0; public int flaggedMessageCount = 0; + public boolean available = true; } diff --git a/src/com/fsck/k9/activity/Accounts.java b/src/com/fsck/k9/activity/Accounts.java index a3c8c6430..43a0f2f61 100644 --- a/src/com/fsck/k9/activity/Accounts.java +++ b/src/com/fsck/k9/activity/Accounts.java @@ -27,6 +27,7 @@ import com.fsck.k9.activity.setup.Prefs; import com.fsck.k9.controller.MessagingController; import com.fsck.k9.controller.MessagingListener; import com.fsck.k9.mail.Flag; +import com.fsck.k9.mail.store.StorageManager; import com.fsck.k9.view.ColorChip; import java.util.*; @@ -158,6 +159,7 @@ public class Accounts extends K9ListActivity implements OnItemClickListener, OnC } if (stats == null) { stats = new AccountStats(); // empty stats for unavailable accounts + stats.available = false; } accountStats.put(account.getUuid(), stats); if (account instanceof Account) { @@ -291,18 +293,37 @@ public class Accounts extends K9ListActivity implements OnItemClickListener, OnC outState.putSerializable(ACCOUNT_STATS, accountStats); } + private StorageManager.StorageListener storageListener = new StorageManager.StorageListener() + { + + @Override + public void onUnmount(String providerId) + { + refresh(); + } + + @Override + public void onMount(String providerId) + { + refresh(); + } + }; + @Override public void onResume() { super.onResume(); refresh(); MessagingController.getInstance(getApplication()).addListener(mListener); + StorageManager.getInstance(getApplication()).addListener(storageListener); } @Override public void onPause() { super.onPause(); MessagingController.getInstance(getApplication()).removeListener(mListener); + StorageManager.getInstance(getApplication()).removeListener(storageListener); + } private void refresh() { @@ -408,6 +429,10 @@ public class Accounts extends K9ListActivity implements OnItemClickListener, OnC } else { Account realAccount = (Account)account; if (!realAccount.isAvailable(this)) { + String toastText = getString(R.string.account_unavailable, account.getDescription()); + Toast toast = Toast.makeText(getApplication(), toastText, Toast.LENGTH_SHORT); + toast.show(); + Log.i(K9.LOG_TAG, "refusing to open account that is not available"); return false; } @@ -780,24 +805,6 @@ public class Accounts extends K9ListActivity implements OnItemClickListener, OnC } AccountStats stats = accountStats.get(account.getUuid()); - /* - // 20101024/fiouzy: the following code throws NullPointerException because Background is null - - // display unavailable accounts translucent - if (account instanceof Account) { - Account realAccount = (Account) account; - if (realAccount.isAvailable(Accounts.this)) { - holder.email.getBackground().setAlpha(255); - holder.description.getBackground().setAlpha(255); - } else { - holder.email.getBackground().setAlpha(127); - holder.description.getBackground().setAlpha(127); - } - } else { - holder.email.getBackground().setAlpha(255); - holder.description.getBackground().setAlpha(255); - } - */ if (stats != null && account instanceof Account && stats.size >= 0) { holder.email.setText(SizeFormatter.formatSize(Accounts.this, stats.size)); holder.email.setVisibility(View.VISIBLE); @@ -828,6 +835,8 @@ public class Accounts extends K9ListActivity implements OnItemClickListener, OnC holder.flaggedMessageCount.setOnClickListener(new AccountClickListener(account, SearchModifier.FLAGGED)); holder.newMessageCount.setOnClickListener(new AccountClickListener(account, SearchModifier.UNREAD)); + + view.getBackground().setAlpha(stats.available ? 0 : 127); holder.activeIcons.setOnClickListener(new OnClickListener() { public void onClick(View v) { @@ -840,6 +849,7 @@ public class Accounts extends K9ListActivity implements OnItemClickListener, OnC } else { holder.newMessageCount.setVisibility(View.GONE); holder.flaggedMessageCount.setVisibility(View.GONE); + view.getBackground().setAlpha(0); } if (account instanceof Account) { Account realAccount = (Account)account;