1
0
mirror of https://github.com/moparisthebest/k-9 synced 2024-11-27 11:42:16 -05:00

Add cloud search icon to local search result screen. Implement pull-to-remote-search.

This commit is contained in:
Andrew Chen 2012-09-22 09:40:46 -07:00
parent 7631af1572
commit 360b3f1be8
8 changed files with 157 additions and 99 deletions

View File

@ -39,4 +39,15 @@
android:textColor="?android:attr/textColorTertiary"
android:textSize="36sp" />
<ImageButton
android:id="@+id/actionbar_remote_search"
android:gravity="center_vertical"
android:focusable="false"
android:layout_marginRight="3dip"
android:background="?attr/iconActionRemoteSearch"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:contentDescription="@string/action_remote_search"
android:visibility="gone"/>
</LinearLayout>

View File

@ -1,6 +1,14 @@
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
<item
android:id="@+id/search_remote"
android:icon="?attr/iconActionRemoteSearch"
android:showAsAction="always"
android:title="@string/action_remote_search"
android:visible="false"
/>
<item
android:id="@+id/compose"
android:alphabeticShortcut="c"

View File

@ -23,6 +23,7 @@
<attr name="iconActionSpam" format="reference" />
<attr name="iconActionToggleFlag" format="reference" />
<attr name="iconActionToggleRead" format="reference" />
<attr name="iconActionRemoteSearch" format="reference" />
<attr name="iconMenuAdd" format="reference" />
<attr name="iconMenuAttachment" format="reference" />
<attr name="iconMenuClear" format="reference" />

View File

@ -1120,8 +1120,7 @@ http://k9mail.googlecode.com/
<string name="image_saved_as">Saved image as \"<xliff:g id="filename">%s</xliff:g>\"</string>
<string name="image_saving_failed">Saving the image failed.</string>
<string name="account_settings_allow_remote_search_label">Allow remote search</string>
<string name="account_settings_allow_remote_search_summary">Enable remote searching for this account</string>
<string name="account_settings_remote_search_num_results_entries_all">All</string>
<string name="account_settings_remote_search_num_results_entries_10">10</string>
<string name="account_settings_remote_search_num_results_entries_25">25</string>
@ -1130,19 +1129,19 @@ http://k9mail.googlecode.com/
<string name="account_settings_remote_search_num_results_entries_250">250</string>
<string name="account_settings_remote_search_num_results_entries_500">500</string>
<string name="account_settings_remote_search_num_results_entries_1000">1000</string>
<string name="account_settings_remote_search_num_label">Results limit</string>
<string name="search_mode_local_all">All Local Folders</string>
<string name="search_mode_remote">Remote Folder</string>
<string name="search_mode_title">Search Location</string>
<string name="account_settings_remote_search_num_label">Server search result limit</string>
<string name="account_settings_remote_search_num_summary">Search will stop after <xliff:g id="num_results">%s</xliff:g> results have been found.</string>
<string name="account_settings_remote_search">Remote folder searching</string>
<string name="account_settings_remote_search_full_text_summary">Can be slow</string>
<string name="account_settings_remote_search_full_text">Include body text</string>
<string name="account_settings_allow_remote_search_help">
To perform a remote search, press your device\'s Search button while viewing a folder from this account.
\n\nNote: Remote search is NOT available from the Unified Inbox or from a list of folders.
</string>
<string name="account_settings_remote_search_full_text">Include body text in server search</string>
<string name="account_settings_remote_search_full_text_summary">Full text searches can be slow.</string>
<string name="remote_search_sending_query">Sending query to server</string>
<string name="no_show_again">Don\'t Show Again</string>
<string name="remote_search_downloading">Fetching %d results</string>
<string name="remote_search_downloading_limited">Fetching %1$d of %2$d results</string>
<string name="account_settings_search">Search</string>
<string name="account_settings_remote_search_enabled">Enable server search</string>
<string name="account_settings_remote_search_enabled_summary">Search messages on the server in addition to those on your device</string>
<string name="action_remote_search">Search messages on server</string>
<string name="pull_to_refresh_remote_search_from_local_search_pull">Pull to search server…</string>
<string name="pull_to_refresh_remote_search_from_local_search_release">Release to search server…</string>
</resources>

View File

@ -25,6 +25,7 @@
<item name="iconActionSpam">@drawable/ic_action_spam_light</item>
<item name="iconActionToggleFlag">@drawable/ic_action_toggle_flag_light</item>
<item name="iconActionToggleRead">@drawable/ic_action_toggle_read_light</item>
<item name="iconActionRemoteSearch">@drawable/ic_action_remote_search_light</item>
<item name="iconMenuAdd">@drawable/ic_menu_add</item>
<item name="iconMenuAttachment">@drawable/ic_menu_attachment</item>
<item name="iconMenuClear">@drawable/ic_menu_clear</item>
@ -67,6 +68,7 @@
<item name="iconActionSpam">@drawable/ic_action_spam_dark</item>
<item name="iconActionToggleFlag">@drawable/ic_action_toggle_flag_dark</item>
<item name="iconActionToggleRead">@drawable/ic_action_toggle_read_dark</item>
<item name="iconActionRemoteSearch">@drawable/ic_action_remote_search_dark</item>
<item name="iconMenuAdd">@drawable/ic_menu_add</item>
<item name="iconMenuAttachment">@drawable/ic_menu_attachment</item>
<item name="iconMenuClear">@drawable/ic_menu_clear</item>

View File

@ -462,10 +462,11 @@
</PreferenceScreen>
<PreferenceScreen android:title="@string/account_settings_remote_search" android:key="remote_search">
<PreferenceScreen android:title="@string/account_settings_search" android:key="search">
<CheckBoxPreference
android:key="account_allow_remote_search"
android:title="@string/account_settings_allow_remote_search_label"
android:key="remote_search_enabled"
android:title="@string/account_settings_remote_search_enabled"
android:summary="@string/account_settings_remote_search_enabled_summary"
android:persistent="false"/>
<ListPreference
@ -474,14 +475,14 @@
android:key="account_remote_search_num_results"
android:title="@string/account_settings_remote_search_num_label"
android:dialogTitle="@string/account_settings_remote_search_num_label"
android:dependency="account_allow_remote_search"/>
android:dependency="remote_search_enabled"/>
<CheckBoxPreference
android:key="account_remote_search_full_text"
android:title="@string/account_settings_remote_search_full_text"
android:summary="@string/account_settings_remote_search_full_text_summary"
android:persistent="false"
android:dependency="account_allow_remote_search"/>
android:dependency="remote_search_enabled"/>
</PreferenceScreen>

View File

@ -12,8 +12,8 @@ import java.util.Map;
import android.app.AlertDialog;
import android.app.Dialog;
import android.app.SearchManager;
import android.content.ComponentName;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.SharedPreferences.Editor;
import android.graphics.Color;
@ -28,10 +28,8 @@ import android.text.style.ForegroundColorSpan;
import android.text.style.StyleSpan;
import android.util.Log;
import android.util.TypedValue;
import android.view.GestureDetector;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
@ -926,14 +924,34 @@ public class MessageList extends K9ListActivity implements OnItemClickListener {
mStars = K9.messageListStars();
mCheckboxes = K9.messageListCheckboxes();
// TODO Add support for pull to fresh on searches.
if(mQueryString == null) {
final Preferences prefs = Preferences.getPreferences(getApplicationContext());
boolean allowRemoteSearch = false;
if (mSearchAccount != null) {
final Account searchAccount = prefs.getAccount(mSearchAccount);
if (searchAccount != null) {
allowRemoteSearch = searchAccount.allowRemoteSearch();
}
}
if (mQueryString == null) {
mPullToRefreshView.setOnRefreshListener(new PullToRefreshBase.OnRefreshListener<ListView>() {
@Override
public void onRefresh(PullToRefreshBase<ListView> refreshView) {
checkMail(mAccount, mFolderName);
}
});
} else if (allowRemoteSearch && !mRemoteSearch && !mIntegrate) {
// mQueryString != null is implied if we get this far.
mPullToRefreshView.setOnRefreshListener(new PullToRefreshBase.OnRefreshListener<ListView>() {
@Override
public void onRefresh(PullToRefreshBase<ListView> refreshView) {
mPullToRefreshView.onRefreshComplete();
onRemoteSearchRequested(true);
}
});
mPullToRefreshView.setPullLabel(getString(R.string.pull_to_refresh_remote_search_from_local_search_pull));
mPullToRefreshView.setReleaseLabel(getString(R.string.pull_to_refresh_remote_search_from_local_search_release));
} else {
mPullToRefreshView.setMode(PullToRefreshBase.Mode.DISABLED);
}
@ -943,7 +961,6 @@ public class MessageList extends K9ListActivity implements OnItemClickListener {
//Cancel pending new mail notifications when we open an account
Account[] accountsWithNotification;
Preferences prefs = Preferences.getPreferences(getApplicationContext());
Account account = getCurrentAccount(prefs);
if (account != null) {
@ -1285,44 +1302,47 @@ public class MessageList extends K9ListActivity implements OnItemClickListener {
AccountSettings.actionSettings(this, mAccount);
}
@Override
public boolean onSearchRequested() {
if (mAccount != null && mCurrentFolder != null && mAccount.allowRemoteSearch()) {
//if in a remote searchable folder, ask user what they want.
//TODO: Add ability to remember selection?
final CharSequence[] items = new CharSequence[2];
items[0] = getString(R.string.search_mode_local_all);
items[1] = getString(R.string.search_mode_remote);
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle(getString(R.string.search_mode_title));
builder.setItems(items, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int item) {
Bundle appData = null;
if (item == 1) {
appData = new Bundle();
appData.putString(EXTRA_SEARCH_ACCOUNT, mAccount.getUuid());
appData.putString(EXTRA_SEARCH_FOLDER, mCurrentFolder.name);
appData.putBoolean(EXTRA_REMOTE_SEARCH, true);
}
//else do regular search, which doesn't require any special parameter setup
startSearch(null, false, appData, false);
}
});
AlertDialog alert = builder.create();
alert.show();
return true;
/**
* User has requested a remote search. Setup the bundle and start the intent.
* @param fromLocalSearch true if this is being called from a local search result screen. This affects
* where we pull the account and folder info used for the next search.
*/
public void onRemoteSearchRequested(final boolean fromLocalSearch) {
final Bundle appData = new Bundle();
if (fromLocalSearch) {
appData.putString(EXTRA_SEARCH_ACCOUNT, mSearchAccount);
appData.putString(EXTRA_SEARCH_FOLDER, mSearchFolder);
} else {
appData.putString(EXTRA_SEARCH_ACCOUNT, mAccount.getUuid());
appData.putString(EXTRA_SEARCH_FOLDER, mCurrentFolder.name);
}
appData.putBoolean(EXTRA_REMOTE_SEARCH, true);
startSearch(null, false, null, false);
return true;
final Intent intent = new Intent(Intent.ACTION_SEARCH);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.putExtra(SearchManager.QUERY, mQueryString);
intent.putExtra(SearchManager.APP_DATA, appData);
intent.setComponent(new ComponentName(context.getApplicationContext(), MessageList.class));
context.startActivity(intent);
}
@Override
public boolean onSearchRequested() {
// If this search was started from a MessageList of a single folder, pass along that folder info
// so that we can enable remote search.
if (mAccount != null && mCurrentFolder != null) {
final Bundle appData = new Bundle();
appData.putString(EXTRA_SEARCH_ACCOUNT, mAccount.getUuid());
appData.putString(EXTRA_SEARCH_FOLDER, mCurrentFolder.name);
startSearch(null, false, appData, false);
} else {
// TODO Handle the case where we're searching from within a search result.
startSearch(null, false, null, false);
}
return true;
}
private void changeSort(SortType sortType) {
Boolean sortAscending = (mSortType == sortType) ? !mSortAscending : null;
changeSort(sortType, sortAscending);
@ -1627,6 +1647,10 @@ public class MessageList extends K9ListActivity implements OnItemClickListener {
onEditPrefs();
return true;
}
case R.id.search_remote: {
onRemoteSearchRequested(true);
return true;
}
}
if (mQueryString != null) {
@ -1679,6 +1703,21 @@ public class MessageList extends K9ListActivity implements OnItemClickListener {
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.
final Preferences prefs = Preferences.getPreferences(getApplicationContext());
boolean allowRemoteSearch = false;
if (mSearchAccount != null) {
final Account searchAccount = prefs.getAccount(mSearchAccount);
if (searchAccount != null) {
allowRemoteSearch = searchAccount.allowRemoteSearch();
}
}
if (allowRemoteSearch && mQueryString != null && !mRemoteSearch && !mIntegrate && mSearchFolder != null) {
menu.findItem(R.id.search_remote).setVisible(true);
}
} else {
if (mCurrentFolder != null && mCurrentFolder.name.equals(mAccount.getOutboxFolderName())) {
menu.findItem(R.id.check_mail).setVisible(false);

View File

@ -58,11 +58,12 @@ public class AccountSettings extends K9PreferenceActivity {
private static final int ACTIVITY_MANAGE_IDENTITIES = 2;
private static final String PREFERENCE_SCREEN_MAIN = "main";
private static final String PREFERENCE_SCREEN_COMPOSING = "composing";
private static final String PREFERENCE_SCREEN_INCOMING = "incoming_prefs";
private static final String PREFERENCE_SCREEN_PUSH_ADVANCED = "push_advanced";
private static final String PREFERENCE_SCREEN_NOTIFICATIONS = "notifications";
private static final String PREFERENCE_SCREEN_REMOTE_SEARCH = "remote_search";
private static final String PREFERENCE_SCREEN_SEARCH = "search";
private static final String PREFERENCE_DESCRIPTION = "account_description";
private static final String PREFERENCE_MARK_MESSAGE_AS_READ_ON_VIEW = "mark_message_as_read_on_view";
@ -112,7 +113,7 @@ public class AccountSettings extends K9PreferenceActivity {
private static final String PREFERENCE_CRYPTO_APP = "crypto_app";
private static final String PREFERENCE_CRYPTO_AUTO_SIGNATURE = "crypto_auto_signature";
private static final String PREFERENCE_CRYPTO_AUTO_ENCRYPT = "crypto_auto_encrypt";
private static final String PREFERENCE_ALLOW_REMOTE_SEARCH = "account_allow_remote_search";
private static final String PREFERENCE_CLOUD_SEARCH_ENABLED = "cloud_search_enabled";
private static final String PREFERENCE_REMOTE_SEARCH_NUM_RESULTS = "account_remote_search_num_results";
private static final String PREFERENCE_REMOTE_SEARCH_FULL_TEXT = "account_remote_search_full_text";
@ -131,6 +132,7 @@ public class AccountSettings extends K9PreferenceActivity {
private boolean mIsPushCapable = false;
private boolean mIsExpungeCapable = false;
private PreferenceScreen mMainScreen;
private PreferenceScreen mComposingScreen;
private EditTextPreference mAccountDescription;
@ -177,9 +179,12 @@ public class AccountSettings extends K9PreferenceActivity {
private ListPreference mCryptoApp;
private CheckBoxPreference mCryptoAutoSignature;
private CheckBoxPreference mCryptoAutoEncrypt;
private CheckBoxPreference mAllowRemoteSearch;
private PreferenceScreen mSearchScreen;
private CheckBoxPreference mCloudSearchEnabled;
private ListPreference mRemoteSearchNumResults;
private CheckBoxPreference mRemoteSearchFullText;
private ListPreference mLocalStorageProvider;
private ListPreference mArchiveFolder;
private ListPreference mDraftsFolder;
@ -213,6 +218,8 @@ public class AccountSettings extends K9PreferenceActivity {
addPreferencesFromResource(R.xml.account_settings_preferences);
mMainScreen = (PreferenceScreen) findPreference(PREFERENCE_SCREEN_MAIN);
mAccountDescription = (EditTextPreference) findPreference(PREFERENCE_DESCRIPTION);
mAccountDescription.setSummary(mAccount.getDescription());
mAccountDescription.setText(mAccount.getDescription());
@ -415,7 +422,7 @@ public class AccountSettings extends K9PreferenceActivity {
if (!mAccount.isSearchByDateCapable()) {
((PreferenceScreen) findPreference(PREFERENCE_SCREEN_INCOMING)).removePreference(mMessageAge);
} else {
} else {
mMessageAge.setValue(String.valueOf(mAccount.getMaximumPolledMessageAge()));
mMessageAge.setSummary(mMessageAge.getEntry());
mMessageAge.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
@ -489,27 +496,30 @@ public class AccountSettings extends K9PreferenceActivity {
}
});
}
// IMAP-specific preferences
mAllowRemoteSearch = (CheckBoxPreference) findPreference(PREFERENCE_ALLOW_REMOTE_SEARCH);
mAllowRemoteSearch.setOnPreferenceChangeListener(
// IMAP-specific preferences
mSearchScreen = (PreferenceScreen) findPreference(PREFERENCE_SCREEN_SEARCH);
mCloudSearchEnabled = (CheckBoxPreference) findPreference(PREFERENCE_CLOUD_SEARCH_ENABLED);
mRemoteSearchNumResults = (ListPreference) findPreference(PREFERENCE_REMOTE_SEARCH_NUM_RESULTS);
mRemoteSearchNumResults.setOnPreferenceChangeListener(
new OnPreferenceChangeListener() {
public boolean onPreferenceChange(Preference pref, Object newVal) {
if ((Boolean) newVal) {
showRemoteSearchHelp();
}
updateRemoteSearchLimit((String)newVal);
return true;
}
});
mRemoteSearchNumResults = (ListPreference) findPreference(PREFERENCE_REMOTE_SEARCH_NUM_RESULTS);
}
);
updateRemoteSearchLimit(mRemoteSearchNumResults.getValue());
mRemoteSearchFullText = (CheckBoxPreference) findPreference(PREFERENCE_REMOTE_SEARCH_FULL_TEXT);
mPushPollOnConnect = (CheckBoxPreference) findPreference(PREFERENCE_PUSH_POLL_ON_CONNECT);
mIdleRefreshPeriod = (ListPreference) findPreference(PREFERENCE_IDLE_REFRESH_PERIOD);
mMaxPushFolders = (ListPreference) findPreference(PREFERENCE_MAX_PUSH_FOLDERS);
if (mIsPushCapable) {
mPushPollOnConnect.setChecked(mAccount.isPushPollOnConnect());
mAllowRemoteSearch.setChecked(mAccount.allowRemoteSearch());
mCloudSearchEnabled.setChecked(mAccount.allowRemoteSearch());
mRemoteSearchNumResults.setValue(Integer.toString(mAccount.getRemoteSearchNumResults()));
mRemoteSearchFullText.setChecked(mAccount.isRemoteSearchFullText());
@ -552,9 +562,7 @@ public class AccountSettings extends K9PreferenceActivity {
PreferenceScreen incomingPrefs = (PreferenceScreen) findPreference(PREFERENCE_SCREEN_INCOMING);
incomingPrefs.removePreference((PreferenceScreen) findPreference(PREFERENCE_SCREEN_PUSH_ADVANCED));
incomingPrefs.removePreference((ListPreference) findPreference(PREFERENCE_PUSH_MODE));
((PreferenceScreen) findPreference("main")).removePreference((PreferenceScreen) findPreference(PREFERENCE_SCREEN_REMOTE_SEARCH));
mMainScreen.removePreference(mSearchScreen);
}
mAccountNotify = (CheckBoxPreference) findPreference(PREFERENCE_NOTIFY);
@ -714,31 +722,6 @@ public class AccountSettings extends K9PreferenceActivity {
handleCryptoAppDependencies();
}
protected void showRemoteSearchHelp() {
final String noShowHelpPref = "account_settings_remote_search_hide_help";
final SharedPreferences prefs = getPreferences(MODE_PRIVATE);
if (!prefs.getBoolean(noShowHelpPref, false)) {
AlertDialog.Builder adb = new AlertDialog.Builder(this);
final CheckBox noShowAgain = new CheckBox(this);
noShowAgain.setChecked(false);
noShowAgain.setText(R.string.no_show_again);
adb.setView(noShowAgain)
.setMessage(getString(R.string.account_settings_allow_remote_search_help))
.setCancelable(false)
.setPositiveButton(R.string.okay_action, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
if(noShowAgain.isChecked()){
Editor edit = prefs.edit();
edit.putBoolean(noShowHelpPref, true);
edit.commit();
}
}
});
adb.create().show();
}
}
private void handleCryptoAppDependencies() {
if ("".equals(mCryptoApp.getValue())) {
mCryptoAutoSignature.setEnabled(false);
@ -812,7 +795,7 @@ public class AccountSettings extends K9PreferenceActivity {
mAccount.setPushPollOnConnect(mPushPollOnConnect.isChecked());
mAccount.setIdleRefreshMinutes(Integer.parseInt(mIdleRefreshPeriod.getValue()));
mAccount.setMaxPushFolders(Integer.parseInt(mMaxPushFolders.getValue()));
mAccount.setAllowRemoteSearch(mAllowRemoteSearch.isChecked());
mAccount.setAllowRemoteSearch(mCloudSearchEnabled.isChecked());
mAccount.setRemoteSearchNumResults(Integer.parseInt(mRemoteSearchNumResults.getValue()));
mAccount.setRemoteSearchFullText(mRemoteSearchFullText.isChecked());
}
@ -989,6 +972,20 @@ public class AccountSettings extends K9PreferenceActivity {
Integer.parseInt(mAccountVibrateTimes.getValue())), -1);
}
/**
* Remote search result limit summary contains the current limit. On load or change, update this value.
* @param maxResults Search limit to update the summary with.
*/
private void updateRemoteSearchLimit(String maxResults) {
if (maxResults != null) {
if (maxResults.equals("0")) {
maxResults = getString(R.string.account_settings_remote_search_num_results_entries_all);
}
mRemoteSearchNumResults.setSummary(String.format(getString(R.string.account_settings_remote_search_num_summary), maxResults));
}
}
private class PopulateFolderPrefsTask extends AsyncTask<Void, Void, Void> {
List <? extends Folder > folders = new LinkedList<LocalFolder>();
String[] allFolderValues;