1
0
mirror of https://github.com/moparisthebest/k-9 synced 2024-12-24 08:38:51 -05:00

Grey out unavailable accounts.

Display a short toast when attempting to open an unavailable account.

Conflicts:

	res/values/strings.xml
	src/com/fsck/k9/activity/Accounts.java
This commit is contained in:
danapple 2011-03-19 12:36:58 -05:00
parent 6c37741e63
commit 90fc3d2c8d
4 changed files with 36 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

@ -1031,4 +1031,7 @@ Welcome to K-9 Mail setup. K-9 is an open source mail client for Android origin
<string name="messagelist_sent_to_me_sigil">»</string>
<string name="messagelist_sent_cc_me_sigil"></string>
<string name="error_unable_to_connect">Unable to connect.</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

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