1
0
mirror of https://github.com/moparisthebest/k-9 synced 2024-11-23 18:02:15 -05:00

Merge pull request #12 from k9mail/art/warn-if-not-serializable

Art/warn if not serializable
This commit is contained in:
cketti 2014-11-11 19:52:31 +01:00
commit 0f70d5db40
6 changed files with 22 additions and 38 deletions

View File

@ -117,7 +117,10 @@ public class Accounts extends K9ListActivity implements OnItemClickListener {
private static final int DIALOG_RECREATE_ACCOUNT = 3; private static final int DIALOG_RECREATE_ACCOUNT = 3;
private static final int DIALOG_NO_FILE_MANAGER = 4; private static final int DIALOG_NO_FILE_MANAGER = 4;
private ConcurrentMap<String, AccountStats> accountStats = new ConcurrentHashMap<String, AccountStats>(); /*
* Must be serializable hence implementation class used for declaration.
*/
private ConcurrentHashMap<String, AccountStats> accountStats = new ConcurrentHashMap<String, AccountStats>();
private ConcurrentMap<BaseAccount, String> pendingWork = new ConcurrentHashMap<BaseAccount, String>(); private ConcurrentMap<BaseAccount, String> pendingWork = new ConcurrentHashMap<BaseAccount, String>();
@ -492,7 +495,7 @@ public class Accounts extends K9ListActivity implements OnItemClickListener {
outState.putString(SELECTED_CONTEXT_ACCOUNT, mSelectedContextAccount.getUuid()); outState.putString(SELECTED_CONTEXT_ACCOUNT, mSelectedContextAccount.getUuid());
} }
outState.putSerializable(STATE_UNREAD_COUNT, mUnreadMessageCount); outState.putSerializable(STATE_UNREAD_COUNT, mUnreadMessageCount);
outState.putSerializable(ACCOUNT_STATS, Utility.toSerializableConcurrentMap(accountStats)); outState.putSerializable(ACCOUNT_STATS, accountStats);
} }
private StorageManager.StorageListener storageListener = new StorageManager.StorageListener() { private StorageManager.StorageListener storageListener = new StorageManager.StorageListener() {

View File

@ -1154,7 +1154,7 @@ public class MessageCompose extends K9Activity implements OnClickListener,
@Override @Override
protected void onSaveInstanceState(Bundle outState) { protected void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState); super.onSaveInstanceState(outState);
List<Attachment> attachments = new ArrayList<Attachment>(); ArrayList<Attachment> attachments = new ArrayList<Attachment>();
for (int i = 0, count = mAttachments.getChildCount(); i < count; i++) { for (int i = 0, count = mAttachments.getChildCount(); i < count; i++) {
View view = mAttachments.getChildAt(i); View view = mAttachments.getChildAt(i);
Attachment attachment = (Attachment) view.getTag(); Attachment attachment = (Attachment) view.getTag();
@ -1163,7 +1163,7 @@ public class MessageCompose extends K9Activity implements OnClickListener,
outState.putInt(STATE_KEY_NUM_ATTACHMENTS_LOADING, mNumAttachmentsLoading); outState.putInt(STATE_KEY_NUM_ATTACHMENTS_LOADING, mNumAttachmentsLoading);
outState.putString(STATE_KEY_WAITING_FOR_ATTACHMENTS, mWaitingForAttachments.name()); outState.putString(STATE_KEY_WAITING_FOR_ATTACHMENTS, mWaitingForAttachments.name());
outState.putParcelableArrayList(STATE_KEY_ATTACHMENTS, Utility.toArrayList(attachments)); outState.putParcelableArrayList(STATE_KEY_ATTACHMENTS, attachments);
outState.putBoolean(STATE_KEY_CC_SHOWN, mCcWrapper.getVisibility() == View.VISIBLE); outState.putBoolean(STATE_KEY_CC_SHOWN, mCcWrapper.getVisibility() == View.VISIBLE);
outState.putBoolean(STATE_KEY_BCC_SHOWN, mBccWrapper.getVisibility() == View.VISIBLE); outState.putBoolean(STATE_KEY_BCC_SHOWN, mBccWrapper.getVisibility() == View.VISIBLE);
outState.putSerializable(STATE_KEY_QUOTED_TEXT_MODE, mQuotedTextMode); outState.putSerializable(STATE_KEY_QUOTED_TEXT_MODE, mQuotedTextMode);

View File

@ -1,5 +1,6 @@
package com.fsck.k9.activity; package com.fsck.k9.activity;
import java.io.Serializable;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
@ -25,12 +26,12 @@ public class NotificationDeleteConfirmation extends Activity {
private final static int DIALOG_CONFIRM = 1; private final static int DIALOG_CONFIRM = 1;
private Account mAccount; private Account mAccount;
private List<MessageReference> mMessageRefs; private ArrayList<MessageReference> mMessageRefs;
public static PendingIntent getIntent(Context context, final Account account, final List<MessageReference> refs) { public static PendingIntent getIntent(Context context, final Account account, final Serializable refs) {
Intent i = new Intent(context, NotificationDeleteConfirmation.class); Intent i = new Intent(context, NotificationDeleteConfirmation.class);
i.putExtra(EXTRA_ACCOUNT, account.getUuid()); i.putExtra(EXTRA_ACCOUNT, account.getUuid());
i.putExtra(EXTRA_MESSAGE_LIST, Utility.toSerializableList(refs)); i.putExtra(EXTRA_MESSAGE_LIST, refs);
i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP); i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP);
return PendingIntent.getActivity(context, account.getAccountNumber(), i, PendingIntent.FLAG_UPDATE_CURRENT); return PendingIntent.getActivity(context, account.getAccountNumber(), i, PendingIntent.FLAG_UPDATE_CURRENT);

View File

@ -2,6 +2,7 @@ package com.fsck.k9.controller;
import java.io.CharArrayWriter; import java.io.CharArrayWriter;
import java.io.PrintWriter; import java.io.PrintWriter;
import java.io.Serializable;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.Collection; import java.util.Collection;
@ -286,17 +287,14 @@ public class MessagingController implements Runnable {
} }
/** /**
* Gets a list of references for all pending messages for the notification. * Adds a list of references for all pending messages for the notification to the supplied
* * List.
* @return Message reference list
*/ */
public List<MessageReference> getAllMessageRefs() { public void supplyAllMessageRefs(List<MessageReference> refs) {
List<MessageReference> refs = new ArrayList<MessageReference>();
for (Message m : messages) { for (Message m : messages) {
refs.add(m.makeMessageReference()); refs.add(m.makeMessageReference());
} }
refs.addAll(droppedMessages); refs.addAll(droppedMessages);
return refs;
} }
/** /**
@ -4844,7 +4842,8 @@ public class MessagingController implements Runnable {
String accountDescr = (account.getDescription() != null) ? String accountDescr = (account.getDescription() != null) ?
account.getDescription() : account.getEmail(); account.getDescription() : account.getEmail();
final List<MessageReference> allRefs = data.getAllMessageRefs(); final ArrayList<MessageReference> allRefs = new ArrayList<MessageReference>();
data.supplyAllMessageRefs(allRefs);
if (platformSupportsExtendedNotifications() && !privacyModeEnabled) { if (platformSupportsExtendedNotifications() && !privacyModeEnabled) {
if (newMessages > 1) { if (newMessages > 1) {

View File

@ -724,22 +724,4 @@ public class Utility {
return sMainThreadHandler; return sMainThreadHandler;
} }
public static <T> Serializable toSerializableList(List<T> list) {
return list instanceof Serializable ?
(Serializable) list :
new ArrayList<T>(list);
}
public static <T> ArrayList<T> toArrayList(List<T> list) {
return list instanceof ArrayList ?
(ArrayList<T>) list :
new ArrayList<T>(list);
}
public static <T,U> Serializable toSerializableConcurrentMap(ConcurrentMap<T,U> list) {
return list instanceof ConcurrentHashMap ?
(ConcurrentHashMap<T,U>) list :
new ConcurrentHashMap<T,U>(list);
}
} }

View File

@ -1,5 +1,6 @@
package com.fsck.k9.service; package com.fsck.k9.service;
import java.io.Serializable;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
@ -37,11 +38,10 @@ public class NotificationActionService extends CoreService {
return PendingIntent.getService(context, account.getAccountNumber(), i, PendingIntent.FLAG_UPDATE_CURRENT); return PendingIntent.getService(context, account.getAccountNumber(), i, PendingIntent.FLAG_UPDATE_CURRENT);
} }
public static PendingIntent getReadAllMessagesIntent(Context context, final Account account, public static PendingIntent getReadAllMessagesIntent(Context context, final Account account, final Serializable refs) {
final List<MessageReference> refs) {
Intent i = new Intent(context, NotificationActionService.class); Intent i = new Intent(context, NotificationActionService.class);
i.putExtra(EXTRA_ACCOUNT, account.getUuid()); i.putExtra(EXTRA_ACCOUNT, account.getUuid());
i.putExtra(EXTRA_MESSAGE_LIST, Utility.toSerializableList(refs)); i.putExtra(EXTRA_MESSAGE_LIST, refs);
i.setAction(READ_ALL_ACTION); i.setAction(READ_ALL_ACTION);
return PendingIntent.getService(context, account.getAccountNumber(), i, PendingIntent.FLAG_UPDATE_CURRENT); return PendingIntent.getService(context, account.getAccountNumber(), i, PendingIntent.FLAG_UPDATE_CURRENT);
@ -55,11 +55,10 @@ public class NotificationActionService extends CoreService {
return PendingIntent.getService(context, account.getAccountNumber(), i, PendingIntent.FLAG_UPDATE_CURRENT); return PendingIntent.getService(context, account.getAccountNumber(), i, PendingIntent.FLAG_UPDATE_CURRENT);
} }
public static Intent getDeleteAllMessagesIntent(Context context, final Account account, public static Intent getDeleteAllMessagesIntent(Context context, final Account account, final Serializable refs) {
final List<MessageReference> refs) {
Intent i = new Intent(context, NotificationActionService.class); Intent i = new Intent(context, NotificationActionService.class);
i.putExtra(EXTRA_ACCOUNT, account.getUuid()); i.putExtra(EXTRA_ACCOUNT, account.getUuid());
i.putExtra(EXTRA_MESSAGE_LIST, Utility.toSerializableList(refs)); i.putExtra(EXTRA_MESSAGE_LIST, refs);
i.setAction(DELETE_ALL_ACTION); i.setAction(DELETE_ALL_ACTION);
return i; return i;