mirror of
https://github.com/moparisthebest/k-9
synced 2024-12-25 09:08:49 -05:00
Fix remote search
This commit is contained in:
parent
9814833008
commit
ff156ac7c9
@ -98,7 +98,6 @@ public class MessageList extends K9FragmentActivity implements MessageListFragme
|
||||
private LocalSearch mSearch;
|
||||
private boolean mSingleFolderMode;
|
||||
private boolean mSingleAccountMode;
|
||||
private boolean mIsRemote;
|
||||
|
||||
/**
|
||||
* {@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) {
|
||||
FragmentTransaction ft = fragmentManager.beginTransaction();
|
||||
mMessageListFragment = MessageListFragment.newInstance(mSearch,
|
||||
(K9.isThreadedViewEnabled() && !mNoThreading), mIsRemote);
|
||||
(K9.isThreadedViewEnabled() && !mNoThreading));
|
||||
ft.add(R.id.message_list_container, mMessageListFragment);
|
||||
ft.commit();
|
||||
}
|
||||
@ -142,6 +141,7 @@ public class MessageList extends K9FragmentActivity implements MessageListFragme
|
||||
String query = intent.getStringExtra(SearchManager.QUERY);
|
||||
|
||||
mSearch = new LocalSearch(getString(R.string.search_results));
|
||||
mSearch.setManualSearch(true);
|
||||
mNoThreading = true;
|
||||
|
||||
mSearch.or(new SearchCondition(Searchfield.SENDER, Attribute.CONTAINS, query));
|
||||
@ -152,8 +152,6 @@ public class MessageList extends K9FragmentActivity implements MessageListFragme
|
||||
if (appData != null) {
|
||||
mSearch.addAccountUuid(appData.getString(EXTRA_SEARCH_ACCOUNT));
|
||||
mSearch.addAllowedFolder(appData.getString(EXTRA_SEARCH_FOLDER));
|
||||
|
||||
mIsRemote = true;
|
||||
} else {
|
||||
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.folder_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 {
|
||||
menu.findItem(R.id.search).setVisible(true);
|
||||
menu.findItem(R.id.folder_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);
|
||||
}
|
||||
}
|
||||
|
||||
// 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.and(Searchfield.SENDER, senderAddress, Attribute.CONTAINS);
|
||||
|
||||
MessageListFragment fragment = MessageListFragment.newInstance(tmpSearch, false, false);
|
||||
MessageListFragment fragment = MessageListFragment.newInstance(tmpSearch, false);
|
||||
|
||||
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) {
|
||||
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.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);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void remoteSearchStarted() {
|
||||
// Remove action button for remote search
|
||||
configureMenu(mMenu);
|
||||
}
|
||||
}
|
||||
|
@ -142,14 +142,11 @@ public class MessageListFragment extends SherlockFragment implements OnItemClick
|
||||
THREAD_COUNT_COLUMN);
|
||||
|
||||
|
||||
public static MessageListFragment newInstance(LocalSearch search, boolean threadedList,
|
||||
boolean remoteSearch) {
|
||||
public static MessageListFragment newInstance(LocalSearch search, boolean threadedList) {
|
||||
MessageListFragment fragment = new MessageListFragment();
|
||||
Bundle args = new Bundle();
|
||||
args.putParcelable(ARG_SEARCH, search);
|
||||
args.putBoolean(ARG_THREADED_LIST, threadedList);
|
||||
//FIXME: Remote search temporarily disabled
|
||||
//args.putBoolean(ARG_REMOTE_SEARCH, remoteSearch);
|
||||
fragment.setArguments(args);
|
||||
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_THREADED_LIST = "threadedList";
|
||||
private static final String ARG_REMOTE_SEARCH = "remoteSearch";
|
||||
private static final String STATE_LIST_POSITION = "listPosition";
|
||||
|
||||
/**
|
||||
@ -350,10 +346,7 @@ public class MessageListFragment extends SherlockFragment implements OnItemClick
|
||||
*/
|
||||
private String mFolderName;
|
||||
|
||||
/**
|
||||
* If we're doing a search, this contains the query string.
|
||||
*/
|
||||
private boolean mRemoteSearch = false;
|
||||
private boolean mRemoteSearchPerformed = false;
|
||||
private Future mRemoteSearchFuture = null;
|
||||
|
||||
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_REFRESH_TITLE = 2;
|
||||
private static final int ACTION_PROGRESS = 3;
|
||||
private static final int ACTION_REMOTE_SEARCH_FINISHED = 4;
|
||||
|
||||
|
||||
public void folderLoading(String folder, boolean loading) {
|
||||
@ -439,6 +433,11 @@ public class MessageListFragment extends SherlockFragment implements OnItemClick
|
||||
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) {
|
||||
post(new Runnable() {
|
||||
@Override
|
||||
@ -466,6 +465,10 @@ public class MessageListFragment extends SherlockFragment implements OnItemClick
|
||||
MessageListFragment.this.progress(progress);
|
||||
break;
|
||||
}
|
||||
case ACTION_REMOTE_SEARCH_FINISHED: {
|
||||
MessageListFragment.this.remoteSearchFinished();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -512,7 +515,7 @@ public class MessageListFragment extends SherlockFragment implements OnItemClick
|
||||
|
||||
private void refreshTitle() {
|
||||
setWindowTitle();
|
||||
if (!mRemoteSearch) {
|
||||
if (!mSearch.isManualSearch()) {
|
||||
setWindowProgress();
|
||||
}
|
||||
}
|
||||
@ -535,7 +538,7 @@ public class MessageListFragment extends SherlockFragment implements OnItemClick
|
||||
|
||||
private void setWindowTitle() {
|
||||
// regular folder content display
|
||||
if (mSingleFolderMode) {
|
||||
if (!isManualSearch() && mSingleFolderMode) {
|
||||
Activity activity = getActivity();
|
||||
String displayName = FolderInfoHolder.getDisplayName(activity, mAccount,
|
||||
mFolderName);
|
||||
@ -602,7 +605,7 @@ public class MessageListFragment extends SherlockFragment implements OnItemClick
|
||||
@Override
|
||||
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
|
||||
if (view == mFooterView) {
|
||||
if (mCurrentFolder != null && !mRemoteSearch) {
|
||||
if (mCurrentFolder != null && !mSearch.isManualSearch()) {
|
||||
mController.loadMoreMessages(mAccount, mFolderName, null);
|
||||
} /*else if (mRemoteSearch && mAdapter.mExtraSearchResults != null && mAdapter.mExtraSearchResults.size() > 0 && mSearchAccount != null) {
|
||||
int numResults = mAdapter.mExtraSearchResults.size();
|
||||
@ -728,7 +731,6 @@ public class MessageListFragment extends SherlockFragment implements OnItemClick
|
||||
Bundle args = getArguments();
|
||||
|
||||
mThreadedList = args.getBoolean(ARG_THREADED_LIST, false);
|
||||
mRemoteSearch = args.getBoolean(ARG_REMOTE_SEARCH, false);
|
||||
mSearch = args.getParcelable(ARG_SEARCH);
|
||||
mTitle = mSearch.getName();
|
||||
|
||||
@ -881,7 +883,7 @@ public class MessageListFragment extends SherlockFragment implements OnItemClick
|
||||
}
|
||||
|
||||
if (mSingleFolderMode) {
|
||||
if (mRemoteSearch && mAccount.allowRemoteSearch()) {
|
||||
if (mSearch.isManualSearch() && mAccount.allowRemoteSearch()) {
|
||||
mPullToRefreshView.setOnRefreshListener(new PullToRefreshBase.OnRefreshListener<ListView>() {
|
||||
@Override
|
||||
public void onRefresh(PullToRefreshBase<ListView> refreshView) {
|
||||
@ -919,7 +921,7 @@ public class MessageListFragment extends SherlockFragment implements OnItemClick
|
||||
mController.notifyAccountCancel(appContext, accountWithNotification);
|
||||
}
|
||||
|
||||
if (mAccount != null && mFolderName != null && !mRemoteSearch) {
|
||||
if (mAccount != null && mFolderName != null && !mSearch.isManualSearch()) {
|
||||
mController.getFolderUnreadMessageCount(mAccount, mFolderName, mListener);
|
||||
}
|
||||
|
||||
@ -984,7 +986,13 @@ public class MessageListFragment extends SherlockFragment implements OnItemClick
|
||||
searchAccount = mAccount.getUuid();
|
||||
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
|
||||
public void remoteSearchFinished(Account acct, String folder, int numResults, List<Message> extraResults) {
|
||||
mHandler.progress(false);
|
||||
mHandler.remoteSearchFinished();
|
||||
if (extraResults != null && extraResults.size() > 0) {
|
||||
mHandler.updateFooter(String.format(mContext.getString(R.string.load_more_messages_fmt), acct.getRemoteSearchNumResults()), false);
|
||||
} else {
|
||||
@ -1790,7 +1799,7 @@ public class MessageListFragment extends SherlockFragment implements OnItemClick
|
||||
}
|
||||
|
||||
private void updateFooterView() {
|
||||
if (mCurrentFolder != null && mAccount != null) {
|
||||
if (!mSearch.isManualSearch() && mCurrentFolder != null && mAccount != null) {
|
||||
if (mCurrentFolder.loading) {
|
||||
final boolean showProgress = true;
|
||||
updateFooter(mContext.getString(R.string.status_loading_more), showProgress);
|
||||
@ -2589,7 +2598,6 @@ public class MessageListFragment extends SherlockFragment implements OnItemClick
|
||||
public interface MessageListFragmentListener {
|
||||
void setMessageListProgress(int level);
|
||||
void showThread(Account account, String folderName, long rootId);
|
||||
void remoteSearch(String searchAccount, String searchFolder, String queryString);
|
||||
void showMoreFromSameSender(String senderAddress);
|
||||
void onResendMessage(Message message);
|
||||
void onForward(Message message);
|
||||
@ -2601,6 +2609,7 @@ public class MessageListFragment extends SherlockFragment implements OnItemClick
|
||||
void setUnreadCount(int unread);
|
||||
void onCompose(Account account);
|
||||
boolean startSearch(Account account, String folderName);
|
||||
void remoteSearchStarted();
|
||||
}
|
||||
|
||||
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() {
|
||||
return (mFolderName != null && mFolderName.equals(mAccount.getOutboxFolderName()));
|
||||
}
|
||||
@ -2708,7 +2713,7 @@ public class MessageListFragment extends SherlockFragment implements OnItemClick
|
||||
}
|
||||
|
||||
public boolean isRemoteFolder() {
|
||||
if (isSearchQuery() || isOutbox() || isErrorFolder()) {
|
||||
if (mSearch.isManualSearch() || isOutbox() || isErrorFolder()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -2720,6 +2725,10 @@ public class MessageListFragment extends SherlockFragment implements OnItemClick
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean isManualSearch() {
|
||||
return mSearch.isManualSearch();
|
||||
}
|
||||
|
||||
public boolean isAccountExpungeCapable() {
|
||||
try {
|
||||
return (mAccount != null && mAccount.getRemoteStore().isExpungeCapable());
|
||||
@ -2739,11 +2748,11 @@ public class MessageListFragment extends SherlockFragment implements OnItemClick
|
||||
}
|
||||
|
||||
public boolean isRemoteSearch() {
|
||||
return mRemoteSearch;
|
||||
return mRemoteSearchPerformed;
|
||||
}
|
||||
|
||||
public boolean isRemoteSearchAllowed() {
|
||||
if (!isSearchQuery() || mRemoteSearch || !mSingleFolderMode) {
|
||||
if (!mSearch.isManualSearch() || mRemoteSearchPerformed || !mSingleFolderMode) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -2879,4 +2888,8 @@ public class MessageListFragment extends SherlockFragment implements OnItemClick
|
||||
String accountUuid = cursor.getString(ACCOUNT_UUID_COLUMN);
|
||||
return mPreferences.getAccount(accountUuid);
|
||||
}
|
||||
|
||||
private void remoteSearchFinished() {
|
||||
mRemoteSearchFuture = null;
|
||||
}
|
||||
}
|
||||
|
@ -27,6 +27,7 @@ public class LocalSearch implements SearchSpecification {
|
||||
|
||||
private String mName;
|
||||
private boolean mPredefined;
|
||||
private boolean mManualSearch = false;
|
||||
|
||||
// since the uuid isn't in the message table it's not in the tree neither
|
||||
private HashSet<String> mAccountUuids = new HashSet<String>();
|
||||
@ -85,6 +86,7 @@ public class LocalSearch implements SearchSpecification {
|
||||
ConditionsTreeNode conditions = (mConditions == null) ? null : mConditions.cloneTree();
|
||||
|
||||
LocalSearch copy = new LocalSearch(mName, conditions, null, mPredefined);
|
||||
copy.mManualSearch = mManualSearch;
|
||||
copy.mAccountUuids = new HashSet<String>(mAccountUuids);
|
||||
|
||||
return copy;
|
||||
@ -340,6 +342,14 @@ public class LocalSearch implements SearchSpecification {
|
||||
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
|
||||
* match against.
|
||||
@ -388,6 +398,7 @@ public class LocalSearch implements SearchSpecification {
|
||||
public void writeToParcel(Parcel dest, int flags) {
|
||||
dest.writeString(mName);
|
||||
dest.writeByte((byte) (mPredefined ? 1 : 0));
|
||||
dest.writeByte((byte) (mManualSearch ? 1 : 0));
|
||||
dest.writeStringList(new ArrayList<String>(mAccountUuids));
|
||||
dest.writeParcelable(mConditions, flags);
|
||||
}
|
||||
@ -409,6 +420,7 @@ public class LocalSearch implements SearchSpecification {
|
||||
public LocalSearch(Parcel in) {
|
||||
mName = in.readString();
|
||||
mPredefined = (in.readByte() == 1);
|
||||
mManualSearch = (in.readByte() == 1);
|
||||
mAccountUuids.addAll(in.createStringArrayList());
|
||||
mConditions = in.readParcelable(LocalSearch.class.getClassLoader());
|
||||
mLeafSet = (mConditions == null) ? null : mConditions.getLeafSet();
|
||||
|
Loading…
Reference in New Issue
Block a user