1
0
mirror of https://github.com/moparisthebest/k-9 synced 2024-12-26 01:28:50 -05:00

Fix remote search

This commit is contained in:
cketti 2012-11-14 00:19:10 +01:00
parent 9814833008
commit ff156ac7c9
3 changed files with 68 additions and 47 deletions

View File

@ -98,7 +98,6 @@ public class MessageList extends K9FragmentActivity implements MessageListFragme
private LocalSearch mSearch; private LocalSearch mSearch;
private boolean mSingleFolderMode; private boolean mSingleFolderMode;
private boolean mSingleAccountMode; private boolean mSingleAccountMode;
private boolean mIsRemote;
/** /**
* {@code true} if the message list should be displayed as flat list (i.e. no threading) * {@code true} if the message list should be displayed as flat list (i.e. no threading)
@ -128,7 +127,7 @@ public class MessageList extends K9FragmentActivity implements MessageListFragme
if (mMessageListFragment == null) { if (mMessageListFragment == null) {
FragmentTransaction ft = fragmentManager.beginTransaction(); FragmentTransaction ft = fragmentManager.beginTransaction();
mMessageListFragment = MessageListFragment.newInstance(mSearch, mMessageListFragment = MessageListFragment.newInstance(mSearch,
(K9.isThreadedViewEnabled() && !mNoThreading), mIsRemote); (K9.isThreadedViewEnabled() && !mNoThreading));
ft.add(R.id.message_list_container, mMessageListFragment); ft.add(R.id.message_list_container, mMessageListFragment);
ft.commit(); ft.commit();
} }
@ -142,6 +141,7 @@ public class MessageList extends K9FragmentActivity implements MessageListFragme
String query = intent.getStringExtra(SearchManager.QUERY); String query = intent.getStringExtra(SearchManager.QUERY);
mSearch = new LocalSearch(getString(R.string.search_results)); mSearch = new LocalSearch(getString(R.string.search_results));
mSearch.setManualSearch(true);
mNoThreading = true; mNoThreading = true;
mSearch.or(new SearchCondition(Searchfield.SENDER, Attribute.CONTAINS, query)); mSearch.or(new SearchCondition(Searchfield.SENDER, Attribute.CONTAINS, query));
@ -152,8 +152,6 @@ public class MessageList extends K9FragmentActivity implements MessageListFragme
if (appData != null) { if (appData != null) {
mSearch.addAccountUuid(appData.getString(EXTRA_SEARCH_ACCOUNT)); mSearch.addAccountUuid(appData.getString(EXTRA_SEARCH_ACCOUNT));
mSearch.addAllowedFolder(appData.getString(EXTRA_SEARCH_FOLDER)); mSearch.addAllowedFolder(appData.getString(EXTRA_SEARCH_FOLDER));
mIsRemote = true;
} else { } else {
mSearch.addAccountUuid(LocalSearch.ALL_ACCOUNTS); mSearch.addAccountUuid(LocalSearch.ALL_ACCOUNTS);
} }
@ -479,15 +477,7 @@ public class MessageList extends K9FragmentActivity implements MessageListFragme
menu.findItem(R.id.send_messages).setVisible(false); menu.findItem(R.id.send_messages).setVisible(false);
menu.findItem(R.id.folder_settings).setVisible(false); menu.findItem(R.id.folder_settings).setVisible(false);
menu.findItem(R.id.account_settings).setVisible(false); menu.findItem(R.id.account_settings).setVisible(false);
// If this is an explicit local search, show the option to search the cloud.
if (!mMessageListFragment.isRemoteSearch() &&
mMessageListFragment.isRemoteSearchAllowed()) {
menu.findItem(R.id.search_remote).setVisible(true);
}
} else { } else {
menu.findItem(R.id.search).setVisible(true);
menu.findItem(R.id.folder_settings).setVisible(true); menu.findItem(R.id.folder_settings).setVisible(true);
menu.findItem(R.id.account_settings).setVisible(true); menu.findItem(R.id.account_settings).setVisible(true);
@ -505,6 +495,14 @@ public class MessageList extends K9FragmentActivity implements MessageListFragme
menu.findItem(R.id.expunge).setVisible(false); menu.findItem(R.id.expunge).setVisible(false);
} }
} }
// If this is an explicit local search, show the option to search the cloud.
if (!mMessageListFragment.isRemoteSearch() &&
mMessageListFragment.isRemoteSearchAllowed()) {
menu.findItem(R.id.search_remote).setVisible(true);
} else if (!mMessageListFragment.isManualSearch()) {
menu.findItem(R.id.search).setVisible(true);
}
} }
} }
@ -610,7 +608,7 @@ public class MessageList extends K9FragmentActivity implements MessageListFragme
tmpSearch.addAccountUuids(mSearch.getAccountUuids()); tmpSearch.addAccountUuids(mSearch.getAccountUuids());
tmpSearch.and(Searchfield.SENDER, senderAddress, Attribute.CONTAINS); tmpSearch.and(Searchfield.SENDER, senderAddress, Attribute.CONTAINS);
MessageListFragment fragment = MessageListFragment.newInstance(tmpSearch, false, false); MessageListFragment fragment = MessageListFragment.newInstance(tmpSearch, false);
addMessageListFragment(fragment, true); addMessageListFragment(fragment, true);
} }
@ -657,14 +655,6 @@ public class MessageList extends K9FragmentActivity implements MessageListFragme
} }
} }
@Override
public void remoteSearch(String searchAccount, String searchFolder, String queryString) {
MessageListFragment fragment = MessageListFragment.newInstance(mSearch, false, true);
mMenu.findItem(R.id.search_remote).setVisible(false);
addMessageListFragment(fragment, false);
}
private void addMessageListFragment(MessageListFragment fragment, boolean addToBackStack) { private void addMessageListFragment(MessageListFragment fragment, boolean addToBackStack) {
FragmentTransaction ft = getSupportFragmentManager().beginTransaction(); FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
@ -700,7 +690,13 @@ public class MessageList extends K9FragmentActivity implements MessageListFragme
tmpSearch.and(Searchfield.THREAD_ROOT, String.valueOf(threadRootId), Attribute.EQUALS); tmpSearch.and(Searchfield.THREAD_ROOT, String.valueOf(threadRootId), Attribute.EQUALS);
tmpSearch.or(new SearchCondition(Searchfield.ID, Attribute.EQUALS, String.valueOf(threadRootId))); tmpSearch.or(new SearchCondition(Searchfield.ID, Attribute.EQUALS, String.valueOf(threadRootId)));
MessageListFragment fragment = MessageListFragment.newInstance(tmpSearch, false, false); MessageListFragment fragment = MessageListFragment.newInstance(tmpSearch, false);
addMessageListFragment(fragment, true); addMessageListFragment(fragment, true);
} }
@Override
public void remoteSearchStarted() {
// Remove action button for remote search
configureMenu(mMenu);
}
} }

View File

@ -142,14 +142,11 @@ public class MessageListFragment extends SherlockFragment implements OnItemClick
THREAD_COUNT_COLUMN); THREAD_COUNT_COLUMN);
public static MessageListFragment newInstance(LocalSearch search, boolean threadedList, public static MessageListFragment newInstance(LocalSearch search, boolean threadedList) {
boolean remoteSearch) {
MessageListFragment fragment = new MessageListFragment(); MessageListFragment fragment = new MessageListFragment();
Bundle args = new Bundle(); Bundle args = new Bundle();
args.putParcelable(ARG_SEARCH, search); args.putParcelable(ARG_SEARCH, search);
args.putBoolean(ARG_THREADED_LIST, threadedList); args.putBoolean(ARG_THREADED_LIST, threadedList);
//FIXME: Remote search temporarily disabled
//args.putBoolean(ARG_REMOTE_SEARCH, remoteSearch);
fragment.setArguments(args); fragment.setArguments(args);
return fragment; return fragment;
} }
@ -299,7 +296,6 @@ public class MessageListFragment extends SherlockFragment implements OnItemClick
private static final String ARG_SEARCH = "searchObject"; private static final String ARG_SEARCH = "searchObject";
private static final String ARG_THREADED_LIST = "threadedList"; private static final String ARG_THREADED_LIST = "threadedList";
private static final String ARG_REMOTE_SEARCH = "remoteSearch";
private static final String STATE_LIST_POSITION = "listPosition"; private static final String STATE_LIST_POSITION = "listPosition";
/** /**
@ -350,10 +346,7 @@ public class MessageListFragment extends SherlockFragment implements OnItemClick
*/ */
private String mFolderName; private String mFolderName;
/** private boolean mRemoteSearchPerformed = false;
* If we're doing a search, this contains the query string.
*/
private boolean mRemoteSearch = false;
private Future mRemoteSearchFuture = null; private Future mRemoteSearchFuture = null;
private String mTitle; private String mTitle;
@ -420,6 +413,7 @@ public class MessageListFragment extends SherlockFragment implements OnItemClick
private static final int ACTION_FOLDER_LOADING = 1; private static final int ACTION_FOLDER_LOADING = 1;
private static final int ACTION_REFRESH_TITLE = 2; private static final int ACTION_REFRESH_TITLE = 2;
private static final int ACTION_PROGRESS = 3; private static final int ACTION_PROGRESS = 3;
private static final int ACTION_REMOTE_SEARCH_FINISHED = 4;
public void folderLoading(String folder, boolean loading) { public void folderLoading(String folder, boolean loading) {
@ -439,6 +433,11 @@ public class MessageListFragment extends SherlockFragment implements OnItemClick
sendMessage(msg); sendMessage(msg);
} }
public void remoteSearchFinished() {
android.os.Message msg = android.os.Message.obtain(this, ACTION_REMOTE_SEARCH_FINISHED);
sendMessage(msg);
}
public void updateFooter(final String message, final boolean showProgress) { public void updateFooter(final String message, final boolean showProgress) {
post(new Runnable() { post(new Runnable() {
@Override @Override
@ -466,6 +465,10 @@ public class MessageListFragment extends SherlockFragment implements OnItemClick
MessageListFragment.this.progress(progress); MessageListFragment.this.progress(progress);
break; break;
} }
case ACTION_REMOTE_SEARCH_FINISHED: {
MessageListFragment.this.remoteSearchFinished();
break;
}
} }
} }
} }
@ -512,7 +515,7 @@ public class MessageListFragment extends SherlockFragment implements OnItemClick
private void refreshTitle() { private void refreshTitle() {
setWindowTitle(); setWindowTitle();
if (!mRemoteSearch) { if (!mSearch.isManualSearch()) {
setWindowProgress(); setWindowProgress();
} }
} }
@ -535,7 +538,7 @@ public class MessageListFragment extends SherlockFragment implements OnItemClick
private void setWindowTitle() { private void setWindowTitle() {
// regular folder content display // regular folder content display
if (mSingleFolderMode) { if (!isManualSearch() && mSingleFolderMode) {
Activity activity = getActivity(); Activity activity = getActivity();
String displayName = FolderInfoHolder.getDisplayName(activity, mAccount, String displayName = FolderInfoHolder.getDisplayName(activity, mAccount,
mFolderName); mFolderName);
@ -602,7 +605,7 @@ public class MessageListFragment extends SherlockFragment implements OnItemClick
@Override @Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) { public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
if (view == mFooterView) { if (view == mFooterView) {
if (mCurrentFolder != null && !mRemoteSearch) { if (mCurrentFolder != null && !mSearch.isManualSearch()) {
mController.loadMoreMessages(mAccount, mFolderName, null); mController.loadMoreMessages(mAccount, mFolderName, null);
} /*else if (mRemoteSearch && mAdapter.mExtraSearchResults != null && mAdapter.mExtraSearchResults.size() > 0 && mSearchAccount != null) { } /*else if (mRemoteSearch && mAdapter.mExtraSearchResults != null && mAdapter.mExtraSearchResults.size() > 0 && mSearchAccount != null) {
int numResults = mAdapter.mExtraSearchResults.size(); int numResults = mAdapter.mExtraSearchResults.size();
@ -728,7 +731,6 @@ public class MessageListFragment extends SherlockFragment implements OnItemClick
Bundle args = getArguments(); Bundle args = getArguments();
mThreadedList = args.getBoolean(ARG_THREADED_LIST, false); mThreadedList = args.getBoolean(ARG_THREADED_LIST, false);
mRemoteSearch = args.getBoolean(ARG_REMOTE_SEARCH, false);
mSearch = args.getParcelable(ARG_SEARCH); mSearch = args.getParcelable(ARG_SEARCH);
mTitle = mSearch.getName(); mTitle = mSearch.getName();
@ -881,7 +883,7 @@ public class MessageListFragment extends SherlockFragment implements OnItemClick
} }
if (mSingleFolderMode) { if (mSingleFolderMode) {
if (mRemoteSearch && mAccount.allowRemoteSearch()) { if (mSearch.isManualSearch() && mAccount.allowRemoteSearch()) {
mPullToRefreshView.setOnRefreshListener(new PullToRefreshBase.OnRefreshListener<ListView>() { mPullToRefreshView.setOnRefreshListener(new PullToRefreshBase.OnRefreshListener<ListView>() {
@Override @Override
public void onRefresh(PullToRefreshBase<ListView> refreshView) { public void onRefresh(PullToRefreshBase<ListView> refreshView) {
@ -919,7 +921,7 @@ public class MessageListFragment extends SherlockFragment implements OnItemClick
mController.notifyAccountCancel(appContext, accountWithNotification); mController.notifyAccountCancel(appContext, accountWithNotification);
} }
if (mAccount != null && mFolderName != null && !mRemoteSearch) { if (mAccount != null && mFolderName != null && !mSearch.isManualSearch()) {
mController.getFolderUnreadMessageCount(mAccount, mFolderName, mListener); mController.getFolderUnreadMessageCount(mAccount, mFolderName, mListener);
} }
@ -984,7 +986,13 @@ public class MessageListFragment extends SherlockFragment implements OnItemClick
searchAccount = mAccount.getUuid(); searchAccount = mAccount.getUuid();
searchFolder = mCurrentFolder.name; searchFolder = mCurrentFolder.name;
mFragmentListener.remoteSearch(searchAccount, searchFolder, mSearch.getRemoteSearchArguments()); String queryString = mSearch.getRemoteSearchArguments();
mRemoteSearchPerformed = true;
mRemoteSearchFuture = mController.searchRemoteMessages(searchAccount, searchFolder,
queryString, null, null, mListener);
mFragmentListener.remoteSearchStarted();
} }
/** /**
@ -1435,6 +1443,7 @@ public class MessageListFragment extends SherlockFragment implements OnItemClick
@Override @Override
public void remoteSearchFinished(Account acct, String folder, int numResults, List<Message> extraResults) { public void remoteSearchFinished(Account acct, String folder, int numResults, List<Message> extraResults) {
mHandler.progress(false); mHandler.progress(false);
mHandler.remoteSearchFinished();
if (extraResults != null && extraResults.size() > 0) { if (extraResults != null && extraResults.size() > 0) {
mHandler.updateFooter(String.format(mContext.getString(R.string.load_more_messages_fmt), acct.getRemoteSearchNumResults()), false); mHandler.updateFooter(String.format(mContext.getString(R.string.load_more_messages_fmt), acct.getRemoteSearchNumResults()), false);
} else { } else {
@ -1790,7 +1799,7 @@ public class MessageListFragment extends SherlockFragment implements OnItemClick
} }
private void updateFooterView() { private void updateFooterView() {
if (mCurrentFolder != null && mAccount != null) { if (!mSearch.isManualSearch() && mCurrentFolder != null && mAccount != null) {
if (mCurrentFolder.loading) { if (mCurrentFolder.loading) {
final boolean showProgress = true; final boolean showProgress = true;
updateFooter(mContext.getString(R.string.status_loading_more), showProgress); updateFooter(mContext.getString(R.string.status_loading_more), showProgress);
@ -2589,7 +2598,6 @@ public class MessageListFragment extends SherlockFragment implements OnItemClick
public interface MessageListFragmentListener { public interface MessageListFragmentListener {
void setMessageListProgress(int level); void setMessageListProgress(int level);
void showThread(Account account, String folderName, long rootId); void showThread(Account account, String folderName, long rootId);
void remoteSearch(String searchAccount, String searchFolder, String queryString);
void showMoreFromSameSender(String senderAddress); void showMoreFromSameSender(String senderAddress);
void onResendMessage(Message message); void onResendMessage(Message message);
void onForward(Message message); void onForward(Message message);
@ -2601,6 +2609,7 @@ public class MessageListFragment extends SherlockFragment implements OnItemClick
void setUnreadCount(int unread); void setUnreadCount(int unread);
void onCompose(Account account); void onCompose(Account account);
boolean startSearch(Account account, String folderName); boolean startSearch(Account account, String folderName);
void remoteSearchStarted();
} }
public void onReverseSort() { public void onReverseSort() {
@ -2695,10 +2704,6 @@ public class MessageListFragment extends SherlockFragment implements OnItemClick
} }
} }
public boolean isSearchQuery() {
return (mSearch.getRemoteSearchArguments() != null || !mSingleAccountMode);
}
public boolean isOutbox() { public boolean isOutbox() {
return (mFolderName != null && mFolderName.equals(mAccount.getOutboxFolderName())); return (mFolderName != null && mFolderName.equals(mAccount.getOutboxFolderName()));
} }
@ -2708,7 +2713,7 @@ public class MessageListFragment extends SherlockFragment implements OnItemClick
} }
public boolean isRemoteFolder() { public boolean isRemoteFolder() {
if (isSearchQuery() || isOutbox() || isErrorFolder()) { if (mSearch.isManualSearch() || isOutbox() || isErrorFolder()) {
return false; return false;
} }
@ -2720,6 +2725,10 @@ public class MessageListFragment extends SherlockFragment implements OnItemClick
return true; return true;
} }
public boolean isManualSearch() {
return mSearch.isManualSearch();
}
public boolean isAccountExpungeCapable() { public boolean isAccountExpungeCapable() {
try { try {
return (mAccount != null && mAccount.getRemoteStore().isExpungeCapable()); return (mAccount != null && mAccount.getRemoteStore().isExpungeCapable());
@ -2739,11 +2748,11 @@ public class MessageListFragment extends SherlockFragment implements OnItemClick
} }
public boolean isRemoteSearch() { public boolean isRemoteSearch() {
return mRemoteSearch; return mRemoteSearchPerformed;
} }
public boolean isRemoteSearchAllowed() { public boolean isRemoteSearchAllowed() {
if (!isSearchQuery() || mRemoteSearch || !mSingleFolderMode) { if (!mSearch.isManualSearch() || mRemoteSearchPerformed || !mSingleFolderMode) {
return false; return false;
} }
@ -2879,4 +2888,8 @@ public class MessageListFragment extends SherlockFragment implements OnItemClick
String accountUuid = cursor.getString(ACCOUNT_UUID_COLUMN); String accountUuid = cursor.getString(ACCOUNT_UUID_COLUMN);
return mPreferences.getAccount(accountUuid); return mPreferences.getAccount(accountUuid);
} }
private void remoteSearchFinished() {
mRemoteSearchFuture = null;
}
} }

View File

@ -27,6 +27,7 @@ public class LocalSearch implements SearchSpecification {
private String mName; private String mName;
private boolean mPredefined; private boolean mPredefined;
private boolean mManualSearch = false;
// since the uuid isn't in the message table it's not in the tree neither // since the uuid isn't in the message table it's not in the tree neither
private HashSet<String> mAccountUuids = new HashSet<String>(); private HashSet<String> mAccountUuids = new HashSet<String>();
@ -85,6 +86,7 @@ public class LocalSearch implements SearchSpecification {
ConditionsTreeNode conditions = (mConditions == null) ? null : mConditions.cloneTree(); ConditionsTreeNode conditions = (mConditions == null) ? null : mConditions.cloneTree();
LocalSearch copy = new LocalSearch(mName, conditions, null, mPredefined); LocalSearch copy = new LocalSearch(mName, conditions, null, mPredefined);
copy.mManualSearch = mManualSearch;
copy.mAccountUuids = new HashSet<String>(mAccountUuids); copy.mAccountUuids = new HashSet<String>(mAccountUuids);
return copy; return copy;
@ -340,6 +342,14 @@ public class LocalSearch implements SearchSpecification {
return mPredefined; return mPredefined;
} }
public boolean isManualSearch() {
return mManualSearch;
}
public void setManualSearch(boolean manualSearch) {
mManualSearch = manualSearch;
}
/** /**
* Returns all the account uuids that this search will try to * Returns all the account uuids that this search will try to
* match against. * match against.
@ -388,6 +398,7 @@ public class LocalSearch implements SearchSpecification {
public void writeToParcel(Parcel dest, int flags) { public void writeToParcel(Parcel dest, int flags) {
dest.writeString(mName); dest.writeString(mName);
dest.writeByte((byte) (mPredefined ? 1 : 0)); dest.writeByte((byte) (mPredefined ? 1 : 0));
dest.writeByte((byte) (mManualSearch ? 1 : 0));
dest.writeStringList(new ArrayList<String>(mAccountUuids)); dest.writeStringList(new ArrayList<String>(mAccountUuids));
dest.writeParcelable(mConditions, flags); dest.writeParcelable(mConditions, flags);
} }
@ -409,6 +420,7 @@ public class LocalSearch implements SearchSpecification {
public LocalSearch(Parcel in) { public LocalSearch(Parcel in) {
mName = in.readString(); mName = in.readString();
mPredefined = (in.readByte() == 1); mPredefined = (in.readByte() == 1);
mManualSearch = (in.readByte() == 1);
mAccountUuids.addAll(in.createStringArrayList()); mAccountUuids.addAll(in.createStringArrayList());
mConditions = in.readParcelable(LocalSearch.class.getClassLoader()); mConditions = in.readParcelable(LocalSearch.class.getClassLoader());
mLeafSet = (mConditions == null) ? null : mConditions.getLeafSet(); mLeafSet = (mConditions == null) ? null : mConditions.getLeafSet();