1
0
mirror of https://github.com/moparisthebest/k-9 synced 2024-11-30 13:12:25 -05:00

Grey out unavailable accounts.

Display a short toast when attempting to open an unavailable account.
This commit is contained in:
danapple 2011-03-16 17:05:41 -05:00
parent 7891b24c31
commit c3cc43675b
4 changed files with 37 additions and 20 deletions

View File

@ -9,7 +9,8 @@
android:paddingRight="6dip"
android:paddingBottom="2dip"
android:descendantFocusability="blocksDescendants"
android:gravity="center_vertical" >
android:gravity="center_vertical"
android:background="#ccc" >
<View
android:id="@+id/chip"
@ -18,7 +19,8 @@
android:layout_marginTop="2dip"
android:layout_marginBottom="1dip"
android:layout_centerVertical="true"
android:layout_alignParentLeft="true" />
android:layout_alignParentLeft="true"
android:background="@android:color/transparent" />
<LinearLayout

View File

@ -1045,4 +1045,6 @@ Welcome to K-9 Mail setup. K-9 is an open source mail client for Android origin
<string name="settings_import_success_header">Import succeeded</string>
<string name="settings_import_failed_header">Import failed</string>
<string name="account_unavailable">Account \"<xliff:g id="account">%s</xliff:g>\" is unavailable; check storage</string>
</resources>

View File

@ -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;
}

View File

@ -32,6 +32,7 @@ import com.fsck.k9.controller.MessagingController;
import com.fsck.k9.controller.MessagingListener;
import com.fsck.k9.mail.Flag;
import com.fsck.k9.mail.internet.MimeUtility;
import com.fsck.k9.mail.store.StorageManager;
import com.fsck.k9.view.ColorChip;
import java.io.FileNotFoundException;
@ -171,6 +172,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) {
@ -298,6 +300,8 @@ public class Accounts extends K9ListActivity implements OnItemClickListener, OnC
restoreAccountStats(icicle);
}
}
@SuppressWarnings("unchecked")
@ -319,18 +323,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() {
@ -431,6 +454,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;
}
@ -900,24 +927,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);
@ -949,6 +958,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) {
Toast toast = Toast.makeText(getApplication(), getString(R.string.tap_hint), Toast.LENGTH_SHORT);
@ -960,6 +971,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;