1
0
Fork 0
mirror of https://github.com/M66B/FairEmail.git synced 2025-03-15 08:29:24 +00:00

Added setting to search local

This commit is contained in:
M66B 2019-02-18 09:49:59 +00:00
parent f3aaeca24c
commit 459f084890
7 changed files with 57 additions and 35 deletions

View file

@ -421,16 +421,18 @@ public class ActivityView extends ActivityBilling implements FragmentManager.OnB
db.message().resetSearch();
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
if (prefs.getBoolean("search_local", false))
return null;
EntityFolder archive = db.folder().getPrimaryArchive();
if (archive == null)
throw new IllegalArgumentException("No primary archive");
return archive.id;
return (archive == null ? null : archive.id);
}
@Override
protected void onExecuted(Bundle args, Long archive) {
Bundle sargs = new Bundle();
sargs.putLong("folder", archive);
sargs.putLong("folder", archive == null ? -1 : archive);
sargs.putString("search", args.getString("search"));
FragmentMessages fragment = new FragmentMessages();

View file

@ -86,11 +86,6 @@ public interface DaoFolder {
" WHERE `primary` AND type = '" + EntityFolder.DRAFTS + "'")
LiveData<EntityFolder> livePrimaryDrafts();
@Query("SELECT folder.* FROM folder" +
" JOIN account ON account.id = folder.account" +
" WHERE `primary` AND type = '" + EntityFolder.ARCHIVE + "'")
LiveData<EntityFolder> livePrimaryArchive();
@Query("SELECT folder.*, account.name AS accountName, account.color AS accountColor, account.state AS accountState" +
", COUNT(message.id) AS messages" +
", SUM(CASE WHEN message.content = 1 THEN 1 ELSE 0 END) AS content" +

View file

@ -97,6 +97,7 @@ public class FragmentOptions extends FragmentBase implements SharedPreferences.O
private SwitchCompat swAutoSend;
private SwitchCompat swNotifyPreview;
private SwitchCompat swSearchLocal;
private SwitchCompat swLight;
private Button btnSound;
@ -117,7 +118,7 @@ public class FragmentOptions extends FragmentBase implements SharedPreferences.O
"unified", "date", "threading", "avatars", "identicons", "name_email", "preview", "addresses", "autoimages", "actionbar",
"pull", "swipenav", "autoexpand", "autoclose", "autonext", "collapse", "autoread", "automove",
"autoresize", "sender", "autosend",
"notify_preview", "light", "sound",
"notify_preview", "search_local", "light", "sound",
"updates", "debug",
"first", "why", "last_update_check", "app_support", "message_swipe", "message_select", "folder_actions", "folder_sync",
"edit_ref_confirmed", "show_html_confirmed", "show_images_confirmed"
@ -166,6 +167,7 @@ public class FragmentOptions extends FragmentBase implements SharedPreferences.O
swAutoSend = view.findViewById(R.id.swAutoSend);
swNotifyPreview = view.findViewById(R.id.swNotifyPreview);
swSearchLocal = view.findViewById(R.id.swSearchLocal);
swLight = view.findViewById(R.id.swLight);
btnSound = view.findViewById(R.id.btnSound);
@ -450,6 +452,13 @@ public class FragmentOptions extends FragmentBase implements SharedPreferences.O
}
});
swSearchLocal.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton compoundButton, boolean checked) {
prefs.edit().putBoolean("search_local", checked).apply();
}
});
swLight.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton compoundButton, boolean checked) {
@ -584,6 +593,7 @@ public class FragmentOptions extends FragmentBase implements SharedPreferences.O
swAutoSend.setChecked(!prefs.getBoolean("autosend", false));
swNotifyPreview.setChecked(prefs.getBoolean("notify_preview", true));
swSearchLocal.setChecked(prefs.getBoolean("search_local", false));
swLight.setChecked(prefs.getBoolean("light", false));
swUpdates.setChecked(prefs.getBoolean("updates", true));
swUpdates.setVisibility(Helper.isPlayStoreInstall(getContext()) ? View.GONE : View.VISIBLE);

View file

@ -273,7 +273,6 @@ public class FragmentSetup extends FragmentBase {
db.account().liveSynchronizingAccounts().observe(getViewLifecycleOwner(), new Observer<List<EntityAccount>>() {
private boolean done = false;
private LiveData<EntityFolder> livePrimaryDrafts = null;
private LiveData<EntityFolder> livePrimaryArchive = null;
@Override
public void onChanged(@Nullable List<EntityAccount> accounts) {
@ -293,30 +292,12 @@ public class FragmentSetup extends FragmentBase {
else
livePrimaryDrafts.removeObservers(getViewLifecycleOwner());
if (livePrimaryArchive == null)
livePrimaryArchive = db.folder().livePrimaryArchive();
else
livePrimaryArchive.removeObservers(getViewLifecycleOwner());
livePrimaryDrafts.observe(getViewLifecycleOwner(), new Observer<EntityFolder>() {
@Override
public void onChanged(EntityFolder drafts) {
tvNoPrimaryDrafts.setVisibility(done && drafts == null ? View.VISIBLE : View.GONE);
}
});
livePrimaryArchive.observe(getViewLifecycleOwner(), new Observer<EntityFolder>() {
@Override
public void onChanged(EntityFolder archive) {
PackageManager pm = getContext().getPackageManager();
pm.setComponentEnabledSetting(
new ComponentName(getContext(), ActivitySearch.class),
archive == null
? PackageManager.COMPONENT_ENABLED_STATE_DISABLED
: PackageManager.COMPONENT_ENABLED_STATE_ENABLED,
PackageManager.DONT_KILL_APP);
}
});
}
});
@ -329,6 +310,13 @@ public class FragmentSetup extends FragmentBase {
tvIdentityDone.setCompoundDrawablesWithIntrinsicBounds(done ? check : null, null, null, null);
}
});
// Backward compatibility
PackageManager pm = getContext().getPackageManager();
pm.setComponentEnabledSetting(
new ComponentName(getContext(), ActivitySearch.class),
PackageManager.COMPONENT_ENABLED_STATE_ENABLED,
PackageManager.DONT_KILL_APP);
}
@Override

View file

@ -97,7 +97,7 @@ public class ViewModelBrowse extends ViewModel {
if (state.messages == null) {
state.messages = db.message().getMessageIdsByFolder(state.fid);
Log.i("Messages=" + state.messages.size());
Log.i("Boundary search folder=" + state.fid + " messages=" + state.messages.size());
}
for (int i = state.local; i < state.messages.size() && local < state.pageSize; i++) {

View file

@ -675,7 +675,7 @@
app:switchPadding="12dp" />
<TextView
android:id="@+id/swNotifyPreviewHint"
android:id="@+id/tvNotifyPreviewHint"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="12dp"
@ -688,7 +688,7 @@
app:layout_constraintTop_toBottomOf="@id/swNotifyPreview" />
<TextView
android:id="@+id/swNotifyPreviewPro"
android:id="@+id/tvNotifyPreviewPro"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="12dp"
@ -698,7 +698,32 @@
android:textStyle="italic"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/swNotifyPreviewHint" />
app:layout_constraintTop_toBottomOf="@id/tvNotifyPreviewHint" />
<androidx.appcompat.widget.SwitchCompat
android:id="@+id/swSearchLocal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="12dp"
android:layout_marginTop="12dp"
android:layout_marginEnd="12dp"
android:text="@string/title_advanced_search_local"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/tvNotifyPreviewPro"
app:switchPadding="12dp" />
<TextView
android:id="@+id/tvSearchLocalHint"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="12dp"
android:layout_marginEnd="60dp"
android:text="@string/title_advanced_search_local_hint"
android:textAppearance="@style/TextAppearance.AppCompat.Small"
android:textStyle="italic"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/swSearchLocal" />
<androidx.appcompat.widget.SwitchCompat
android:id="@+id/swLight"
@ -709,7 +734,7 @@
android:layout_marginEnd="12dp"
android:text="@string/title_advanced_light"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/swNotifyPreviewPro"
app:layout_constraintTop_toBottomOf="@id/tvSearchLocalHint"
app:switchPadding="12dp" />
<Button

View file

@ -174,6 +174,7 @@
<string name="title_advanced_autosend">Confirm sending messages</string>
<string name="title_advanced_notify_preview">Show message preview in notifications</string>
<string name="title_advanced_search_local">Search on device</string>
<string name="title_advanced_light">Use notification light</string>
<string name="title_advanced_sound">Select notification sound</string>
<string name="title_advanced_updates">Check for updates</string>
@ -185,11 +186,12 @@
<string name="title_advanced_unified_hint">Show unified inbox folders or unified inbox messages</string>
<string name="title_advanced_threading_hint">Group messages related to each other</string>
<string name="title_advanced_name_email_hint">When disabled only names will be shown when available</string>
<string name="title_advanced_preview_hint">Only available when message text was downloaded</string>
<string name="title_advanced_autoexpand_hint">Automatically open message when there is just one message or just one unread message in a conversation</string>
<string name="title_advanced_autocollapse_hint">Multiple expanded messages will always be closed on \'back\'</string>
<string name="title_advanced_autoclose_hint">Automatically close conversations when all messages are archived, sent or trashed</string>
<string name="title_advanced_sender_hint">Most providers do not allow modified sender addresses</string>
<string name="title_advanced_preview_hint">Only available when message text was downloaded</string>
<string name="title_advanced_search_local_hint">Instead of searching in the primary archive folder on the server</string>
<string name="title_select">Select &#8230;</string>
<string name="title_identity_name">Your name</string>