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

Make stars and envelopes on folder active.

This commit is contained in:
Daniel Applebaum 2010-04-24 19:10:57 +00:00
parent 4bec5ea2a3
commit f185240f67
8 changed files with 170 additions and 46 deletions

View File

@ -40,6 +40,7 @@
android:layout_height="wrap_content" />
</LinearLayout>
<RelativeLayout
android:id="@+id/active_icons"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:orientation="vertical"
@ -48,6 +49,7 @@
android:paddingLeft="6dip"
android:paddingRight="6dip"
android:gravity="right"
android:clickable="true"
>
<TextView
android:id="@+id/folder_unread_message_count"
@ -65,7 +67,9 @@
android:paddingRight="10dip"
android:gravity="right"
android:layout_gravity="top"
android:layout_alignParentTop="true"/>
android:layout_alignParentTop="true"
android:clickable="true"
/>
<TextView
android:id="@+id/folder_flagged_message_count"
android:ellipsize="end"
@ -82,6 +86,7 @@
android:gravity="right"
android:layout_gravity="bottom"
android:layout_alignParentBottom="true"
android:clickable="true"
/>
</RelativeLayout>
</LinearLayout>

View File

@ -701,7 +701,7 @@ public class MessagingController implements Runnable
public void searchLocalMessages(SearchSpecification searchSpecification, final Message[] messages, final MessagingListener listener)
{
searchLocalMessages(searchSpecification.getAccountUuids(), null, messages,
searchLocalMessages(searchSpecification.getAccountUuids(), searchSpecification.getFolderNames(), messages,
searchSpecification.getQuery(), searchSpecification.isIntegrate(), searchSpecification.getRequiredFlags(), searchSpecification.getForbiddenFlags(), listener);
}
@ -719,20 +719,33 @@ public class MessagingController implements Runnable
public void searchLocalMessages(final String[] accountUuids, final String[] folderNames, final Message[] messages, final String query, final boolean integrate,
final Flag[] requiredFlags, final Flag[] forbiddenFlags, final MessagingListener listener)
{
final AccountStats stats = new AccountStats();
final Set<String> accountUuidsSet = new HashSet<String>();
if (accountUuids != null)
if (K9.DEBUG)
{
for (String accountUuid : accountUuids)
{
accountUuidsSet.add(accountUuid);
}
Log.i(K9.LOG_TAG, "searchLocalMessages ("
+ "accounts=" + Utility.combine(accountUuids, ',')
+ ", folders = " + Utility.combine(folderNames, ',')
+ ", messages.size() = " + (messages != null ? messages.length : null)
+ ", query = " + query
+ ", integrate = " + integrate
+ ", requiredFlags = " + Utility.combine(requiredFlags, ',')
+ ", forbiddenFlags = " + Utility.combine(forbiddenFlags, ',')
+ ")");
}
threadPool.execute(new Runnable()
{
public void run()
{
final AccountStats stats = new AccountStats();
final Set<String> accountUuidsSet = new HashSet<String>();
if (accountUuids != null)
{
for (String accountUuid : accountUuids)
{
accountUuidsSet.add(accountUuid);
}
}
final Preferences prefs = Preferences.getPreferences(mApplication.getApplicationContext());
Account[] accounts = prefs.getAccounts();
List<LocalFolder> foldersToSearch = null;
@ -768,20 +781,20 @@ public class MessagingController implements Runnable
listener.listLocalMessagesStarted(account, null);
}
if (integrate || displayableOnly || folderNames != null || noSpecialFolders)
if (integrate || displayableOnly || folderNames != null || noSpecialFolders)
{
List<LocalFolder> tmpFoldersToSearch = new LinkedList<LocalFolder>();
try
{
LocalStore store = account.getLocalStore();
List<? extends Folder> folders = store.getPersonalNamespaces();
ArrayList<String> folderNameList = null;
Set<String> folderNameSet = null;
if (folderNames != null)
{
folderNameList = new ArrayList<String>();
folderNameSet = new HashSet<String>();
for (String folderName : folderNames)
{
folderNameList.add(folderName);
folderNameSet.add(folderName);
}
}
for (Folder folder : folders)
@ -796,9 +809,13 @@ public class MessagingController implements Runnable
}
else
{
if (folderNameList != null && folderNameList.contains(localFolder.getName()) == false)
if (folderNameSet != null)
{
include = false;
if (folderNameSet.contains(localFolderName) == false)
{
include = false;
}
}
else if (noSpecialFolders && (
localFolderName.equals(account.getTrashFolderName()) ||
@ -836,12 +853,7 @@ public class MessagingController implements Runnable
public void messageFinished(Message message, int number, int ofTotal)
{
List<Message> messages = new ArrayList<Message>();
LocalFolder localFolder = (LocalStore.LocalFolder)message.getFolder();
if (localFolder.getName().equals(localFolder.getAccount().getErrorFolderName()))
{
return;
}
messages.add(message);
stats.unreadMessageCount += (message.isSet(Flag.SEEN) == false) ? 1 : 0;
stats.flaggedMessageCount += (message.isSet(Flag.FLAGGED)) ? 1 : 0;
@ -2934,7 +2946,6 @@ public class MessagingController implements Runnable
{
throw new IllegalArgumentException("Message not found: folder=" + folder + ", uid=" + uid);
}
for (MessagingListener l : getListeners())
{
l.loadMessageForViewHeadersAvailable(account, folder, uid, message);

View File

@ -9,7 +9,6 @@ import java.util.UUID;
import android.content.Context;
import com.fsck.k9.mail.Flag;
import com.fsck.k9.mail.Message;
public class SearchAccount implements BaseAccount, SearchSpecification, Serializable
{
@ -22,6 +21,7 @@ public class SearchAccount implements BaseAccount, SearchSpecification, Serializ
private String mUuid = UUID.randomUUID().toString();
private boolean builtin = false;
private String[] accountUuids = null;
private String[] folderNames = null;
public SearchAccount(Preferences preferences)
{
@ -122,4 +122,13 @@ public class SearchAccount implements BaseAccount, SearchSpecification, Serializ
{
this.accountUuids = accountUuids;
}
@Override
public String[] getFolderNames()
{
return folderNames;
}
public void setFolderNames(String[] folderNames)
{
this.folderNames = folderNames;
}
}

View File

@ -15,4 +15,6 @@ public interface SearchSpecification
public String getQuery();
public String[] getAccountUuids();
public String[] getFolderNames();
}

View File

@ -968,6 +968,12 @@ public class Accounts extends K9ListActivity implements OnItemClickListener, OnC
{
return false;
}
@Override
public String[] getFolderNames()
{
return null;
}
};
MessageList.actionHandle(Accounts.this, description, searchSpec);
@ -975,23 +981,5 @@ public class Accounts extends K9ListActivity implements OnItemClickListener, OnC
}
}
private enum SearchModifier
{
FLAGGED(R.string.flagged_modifier, new Flag[] { Flag.FLAGGED}, null), UNREAD(R.string.unread_modifier, null, new Flag[] { Flag.SEEN} );
final int resId;
final Flag[] requiredFlags;
final Flag[] forbiddenFlags;
SearchModifier(int nResId, Flag[] nRequiredFlags, Flag[] nForbiddenFlags)
{
resId = nResId;
requiredFlags = nRequiredFlags;
forbiddenFlags = nForbiddenFlags;
}
}
}

View File

@ -16,6 +16,7 @@ import android.util.Log;
import android.util.TypedValue;
import android.view.*;
import android.view.ContextMenu.ContextMenuInfo;
import android.view.View.OnClickListener;
import android.widget.*;
import android.widget.AdapterView.AdapterContextMenuInfo;
import android.widget.AdapterView.OnItemClickListener;
@ -23,6 +24,7 @@ import com.fsck.k9.*;
import com.fsck.k9.Account.FolderMode;
import com.fsck.k9.activity.setup.AccountSettings;
import com.fsck.k9.activity.setup.FolderSettings;
import com.fsck.k9.mail.Flag;
import com.fsck.k9.mail.Folder;
import com.fsck.k9.mail.Message;
import com.fsck.k9.mail.MessagingException;
@ -64,7 +66,6 @@ public class FolderList extends K9ListActivity
private FolderListHandler mHandler = new FolderListHandler();
private int mUnreadMessageCount;
private int mFlaggedMessageCount;
private FontSizes mFontSizes = K9.getFontSizes();
@ -1190,6 +1191,7 @@ public class FolderList extends K9ListActivity
holder.newMessageCount = (TextView) view.findViewById(R.id.folder_unread_message_count);
holder.flaggedMessageCount = (TextView) view.findViewById(R.id.folder_flagged_message_count);
holder.folderStatus = (TextView) view.findViewById(R.id.folder_status);
holder.activeIcons = (RelativeLayout) view.findViewById(R.id.active_icons);
holder.chip = view.findViewById(R.id.chip);
holder.rawFolderName = folder.name;
@ -1240,6 +1242,7 @@ public class FolderList extends K9ListActivity
{
holder.newMessageCount.setText(Integer
.toString(folder.unreadMessageCount));
holder.newMessageCount.setOnClickListener(new FolderClickListener(mAccount, folder.name, folder.displayName, SearchModifier.UNREAD));
holder.newMessageCount.setVisibility(View.VISIBLE);
}
else
@ -1251,13 +1254,23 @@ public class FolderList extends K9ListActivity
{
holder.flaggedMessageCount.setText(Integer
.toString(folder.flaggedMessageCount));
holder.flaggedMessageCount.setOnClickListener(new FolderClickListener(mAccount, folder.name, folder.displayName, SearchModifier.FLAGGED));
holder.flaggedMessageCount.setVisibility(View.VISIBLE);
}
else
{
holder.flaggedMessageCount.setVisibility(View.GONE);
}
holder.activeIcons.setOnClickListener(new OnClickListener()
{
public void onClick(View v)
{
Toast toast = Toast.makeText(getApplication(), getString(R.string.tap_hint), Toast.LENGTH_SHORT);
toast.show();
}
}
);
holder.chip.setBackgroundResource(K9.COLOR_CHIP_RES_IDS[mAccount.getAccountNumber() % K9.COLOR_CHIP_RES_IDS.length]);
holder.chip.getBackground().setAlpha(folder.unreadMessageCount == 0 ? 127 : 255);
@ -1422,8 +1435,77 @@ public class FolderList extends K9ListActivity
public TextView newMessageCount;
public TextView flaggedMessageCount;
public RelativeLayout activeIcons;
public String rawFolderName;
public View chip;
}
private class FolderClickListener implements OnClickListener
{
final BaseAccount account;
final String folderName;
final String displayName;
final SearchModifier searchModifier;
FolderClickListener(BaseAccount nAccount, String folderName, String displayName, SearchModifier nSearchModifier )
{
account = nAccount;
this.folderName = folderName;
searchModifier = nSearchModifier;
this.displayName = displayName;
}
@Override
public void onClick(View v)
{
String description = getString(R.string.search_title,
getString(R.string.message_list_title, account.getDescription(), displayName),
getString(searchModifier.resId));
SearchSpecification searchSpec = new SearchSpecification()
{
@Override
public String[] getAccountUuids()
{
return new String[] { account.getUuid() };
}
@Override
public Flag[] getForbiddenFlags()
{
return searchModifier.forbiddenFlags;
}
@Override
public String getQuery()
{
return "";
}
@Override
public Flag[] getRequiredFlags()
{
return searchModifier.requiredFlags;
}
@Override
public boolean isIntegrate()
{
return false;
}
@Override
public String[] getFolderNames()
{
return new String[] { folderName };
}
};
MessageList.actionHandle(FolderList.this, description, searchSpec);
}
}
}

View File

@ -67,7 +67,8 @@ public class MessageList
private static final String EXTRA_QUERY_FLAGS = "queryFlags";
private static final String EXTRA_FORBIDDEN_FLAGS = "forbiddenFlags";
private static final String EXTRA_INTEGRATE = "integrate";
private static final String EXTRA_ACCOUNT_UUIDS = "accountUuids";
private static final String EXTRA_ACCOUNT_UUIDS = "accountUuids";
private static final String EXTRA_FOLDER_NAMES = "folderNames";
private static final String EXTRA_TITLE = "title";
private ListView mListView;
@ -99,6 +100,7 @@ public class MessageList
private Flag[] mForbiddenFlags = null;
private boolean mIntegrate = false;
private String[] mAccountUuids = null;
private String[] mFolderNames = null;
private String mTitle;
private MessageListHandler mHandler = new MessageListHandler();
@ -343,6 +345,7 @@ public class MessageList
}
intent.putExtra(EXTRA_INTEGRATE, searchSpecification.isIntegrate());
intent.putExtra(EXTRA_ACCOUNT_UUIDS, searchSpecification.getAccountUuids());
intent.putExtra(EXTRA_FOLDER_NAMES, searchSpecification.getFolderNames());
intent.putExtra(EXTRA_TITLE, title);
context.startActivity(intent);
@ -414,7 +417,7 @@ public class MessageList
}
mIntegrate = intent.getBooleanExtra(EXTRA_INTEGRATE, false);
mAccountUuids = intent.getStringArrayExtra(EXTRA_ACCOUNT_UUIDS);
mFolderNames = intent.getStringArrayExtra(EXTRA_FOLDER_NAMES);
mTitle = intent.getStringExtra(EXTRA_TITLE);
// Take the initial folder into account only if we are *not* restoring the
@ -488,7 +491,7 @@ public class MessageList
}
else if (mQueryString != null)
{
mController.searchLocalMessages(mAccountUuids, null, null, mQueryString, mIntegrate, mQueryFlags, mForbiddenFlags, mAdapter.mListener);
mController.searchLocalMessages(mAccountUuids, mFolderNames, null, mQueryString, mIntegrate, mQueryFlags, mForbiddenFlags, mAdapter.mListener);
}
mHandler.refreshTitle();

View File

@ -0,0 +1,24 @@
/**
*
*/
package com.fsck.k9.activity;
import com.fsck.k9.R;
import com.fsck.k9.mail.Flag;
enum SearchModifier
{
FLAGGED(R.string.flagged_modifier, new Flag[] { Flag.FLAGGED}, null), UNREAD(R.string.unread_modifier, null, new Flag[] { Flag.SEEN} );
final int resId;
final Flag[] requiredFlags;
final Flag[] forbiddenFlags;
SearchModifier(int nResId, Flag[] nRequiredFlags, Flag[] nForbiddenFlags)
{
resId = nResId;
requiredFlags = nRequiredFlags;
forbiddenFlags = nForbiddenFlags;
}
}