Skip to content

Commit

Permalink
Add advanced options to hide web results or hidden apps from searches.
Browse files Browse the repository at this point in the history
…Resolves #126
  • Loading branch information
threethan committed Apr 26, 2024
1 parent 48de64a commit 18457ad
Show file tree
Hide file tree
Showing 6 changed files with 109 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -68,16 +68,21 @@ public synchronized void setAppList(LauncherActivity activity) {
.getVisibleApps(activity, settingsManager.getAppGroupsSorted(true), fullAppSet)));
}
public synchronized void filterBy(String text) {
boolean showHidden = !text.isEmpty() && launcherActivity.dataStoreEditor.getBoolean(Settings.KEY_SEARCH_HIDDEN, Settings.DEFAULT_SEARCH_HIDDEN);

SettingsManager settingsManager = SettingsManager.getInstance(launcherActivity);
final List<ApplicationInfo> newItems =
settingsManager.getVisibleApps(launcherActivity, settingsManager.getAppGroupsSorted(false), fullAppSet);

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
newItems.removeIf(item -> !StringLib.forSort(SettingsManager.getAppLabel(item)).contains(StringLib.forSort(text)));
if (!showHidden)
newItems.removeIf(item -> Objects.equals(SettingsManager.getAppGroupMap().get(item.packageName), Settings.HIDDEN_GROUP));
}

boolean showWeb = !text.isEmpty() && launcherActivity.dataStoreEditor.getBoolean(Settings.KEY_SEARCH_WEB, Settings.DEFAULT_SEARCH_WEB);
// Add search queries
if (!text.isEmpty() && !launcherActivity.isEditing()) {
if (showWeb && !launcherActivity.isEditing()) {

final ApplicationInfo googleProxy = new ApplicationInfo();
googleProxy.packageName = StringLib.googleSearchForUrl(text);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,13 +67,17 @@ public abstract class Settings {
public static final String KEY_GROUPS_ENABLED = "KEY_GROUPS_ENABLED";
public static final String KEY_DETAILS_LONG_PRESS = "KEY_DETAILS_LONG_PRESS";
public static final String KEY_AUTO_HIDE_EMPTY = "KEY_AUTO_HIDE_EMPTY";
public static final String KEY_SEARCH_WEB = "KEY_SEARCH_WEB";
public static final String KEY_SEARCH_HIDDEN = "KEY_SEARCH_HIDDEN";
public static final int DEFAULT_BACKGROUND_VR = 0;
public static final int DEFAULT_BACKGROUND_TV = 9;
public static final int DEFAULT_ALPHA = 255;
public static final boolean DEFAULT_DARK_MODE = true;
public static final boolean DEFAULT_GROUPS_ENABLED = true;
public static boolean DEFAULT_DETAILS_LONG_PRESS = false;
public static final boolean DEFAULT_AUTO_HIDE_EMPTY = true;
public static final boolean DEFAULT_SEARCH_WEB = true;
public static final boolean DEFAULT_SEARCH_HIDDEN = true;
public static final String CUSTOM_BACKGROUND_PATH = "background.png";

// Basic UI keys
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -400,6 +400,12 @@ public void onStopTrackingTouch(SeekBar seekBar) {
defaultBrowserSelection[0] = index;
});

// Search settings
attachSwitchToSetting(dialog.findViewById(R.id.searchWebSwitch),
Settings.KEY_SEARCH_WEB, Settings.DEFAULT_SEARCH_WEB);
attachSwitchToSetting(dialog.findViewById(R.id.searchHiddenSwitch),
Settings.KEY_SEARCH_HIDDEN, Settings.DEFAULT_SEARCH_HIDDEN);

// Save/load settings
View loadSettings = dialog.findViewById(R.id.loadSettingsButton);
loadSettings.setAlpha(SettingsSaver.canLoad(a) ? 1F : 0.5F);
Expand Down Expand Up @@ -449,22 +455,6 @@ private void attachSwitchToSetting(Switch toggle, String setting,
boolean def) {
attachSwitchToSetting(toggle, setting, def, null);
}

/**
* Displays a one-time warning dialog
* @param dialogResource ResId for the dialog; must contain a button with id of "confirm"
* @param keySeenDialog Key to indicate the user has seen the dialog
*/
private void showOneTimeWarningDialog(int dialogResource, String keySeenDialog) {
if (!a.dataStoreEditor.getBoolean(keySeenDialog, false)) {
AlertDialog subDialog = Dialog.build(a, dialogResource);
if (subDialog == null) return;
subDialog.findViewById(R.id.confirm).setOnClickListener(view -> {
a.dataStoreEditor.putBoolean(keySeenDialog, true);
subDialog.dismiss();
});
}
}
/**
* Attaches a toggle switch to a specific setting
* @param toggle Switch ui element
Expand All @@ -474,7 +464,7 @@ private void showOneTimeWarningDialog(int dialogResource, String keySeenDialog)
*/
private void attachSwitchToSetting(Switch toggle, String setting,
boolean def, Consumer<Boolean> onSwitch) {
toggle.setChecked(!a.dataStoreEditor.getBoolean(setting, def));
toggle.setChecked(a.dataStoreEditor.getBoolean(setting, def));
toggle.setOnCheckedChangeListener((compoundButton, value) -> {
a.dataStoreEditor.putBoolean(setting, value);
if (onSwitch != null && Build.VERSION.SDK_INT >= Build.VERSION_CODES.N)
Expand All @@ -483,6 +473,22 @@ private void attachSwitchToSetting(Switch toggle, String setting,
});
}

/**
* Displays a one-time warning dialog
* @param dialogResource ResId for the dialog; must contain a button with id of "confirm"
* @param keySeenDialog Key to indicate the user has seen the dialog
*/
private void showOneTimeWarningDialog(int dialogResource, String keySeenDialog) {
if (!a.dataStoreEditor.getBoolean(keySeenDialog, false)) {
AlertDialog subDialog = Dialog.build(a, dialogResource);
if (subDialog == null) return;
subDialog.findViewById(R.id.confirm).setOnClickListener(view -> {
a.dataStoreEditor.putBoolean(keySeenDialog, true);
subDialog.dismiss();
});
}
}

private void showGroupSettings() {
clearedSort = false;
clearedGroups = false;
Expand Down
71 changes: 70 additions & 1 deletion Launcher/App/src/main/res/layout/dialog_settings_advanced.xml
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,6 @@
android:gravity="center">

<TextView
android:id="@+id/textView5"
style="@style/SettingsText"
android:layout_width="0dp"
android:layout_height="wrap_content"
Expand Down Expand Up @@ -293,6 +292,76 @@

</androidx.constraintlayout.widget.ConstraintLayout>

<TextView
style="@style/SettingSubtitle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/advanced_search" />

<androidx.constraintlayout.widget.ConstraintLayout
android:id="@+id/searchWebSection"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="10dp"
android:background="@drawable/bkg_button"
android:gravity="clip_vertical|center_vertical">

<TextView
style="@style/SettingButtonLabel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:singleLine="true"
android:text="@string/search_web"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />

<Switch
android:id="@+id/searchWebSwitch"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:foreground="@drawable/bkg_hover_button"
android:thumb="@drawable/switch_thumb_custom"
android:track="@drawable/switch_track_custom"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent"
tools:ignore="UseSwitchCompatOrMaterialXml" />

</androidx.constraintlayout.widget.ConstraintLayout>

<androidx.constraintlayout.widget.ConstraintLayout
android:id="@+id/searchHiddenSection"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="10dp"
android:background="@drawable/bkg_button"
android:gravity="clip_vertical|center_vertical">

<TextView
style="@style/SettingButtonLabel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:singleLine="true"
android:text="@string/search_hidden"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />

<Switch
android:id="@+id/searchHiddenSwitch"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:foreground="@drawable/bkg_hover_button"
android:thumb="@drawable/switch_thumb_custom"
android:track="@drawable/switch_track_custom"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent"
tools:ignore="UseSwitchCompatOrMaterialXml" />

</androidx.constraintlayout.widget.ConstraintLayout>

<TextView
style="@style/SettingSubtitle"
android:layout_width="match_parent"
Expand Down
3 changes: 3 additions & 0 deletions Launcher/App/src/main/res/values-zh-rCN/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
<string name="advanced_interface">界面选项</string>
<string name="advanced_launching">启动选项</string>
<string name="advanced_features">附加特性</string>
<string name="advanced_search">搜索设置</string>
<string name="advanced_backup">备份恢复</string>
<string name="advanced_alpha">背景透明度</string>

Expand All @@ -53,6 +54,8 @@
<string name="long_press">长按编辑</string>
<string name="hide_empty">隐藏空分组</string>
<string name="default_launch_out">默认在应用自身窗口启动</string>
<string name="search_web">在搜索中显示网络搜索引擎</string>
<string name="search_hidden">显示搜索中隐藏的应用程序</string>
<string name="settings_save">导出配置</string>
<string name="settings_load">导入配置</string>
<string name="groupings_save">导出分组</string>
Expand Down
3 changes: 3 additions & 0 deletions Launcher/App/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
<string name="advanced_interface">Interface Options</string>
<string name="advanced_launching">Launching Options</string>
<string name="advanced_features">Extra Features</string>
<string name="advanced_search">Search Settings</string>
<string name="advanced_backup">Backup &amp; Restore</string>
<string name="advanced_alpha">Background Translucency</string>

Expand All @@ -54,6 +55,8 @@
<string name="long_press">Long Press to Edit</string>
<string name="hide_empty">Hide Empty Groups</string>
<string name="default_launch_out">Launch Apps in Own Window by Default</string>
<string name="search_web">Show Web Search Engines in Searches</string>
<string name="search_hidden">Show Hidden Apps in Searches</string>
<string name="settings_save">Export Settings</string>
<string name="settings_load">Import Settings</string>
<string name="groupings_save">Export Groupings</string>
Expand Down

0 comments on commit 18457ad

Please sign in to comment.