option to show keyboard immediately on search, close #1261

This commit is contained in:
Austin Huang 2021-05-18 15:48:28 -04:00
parent bedae1804f
commit 256a2ae88d
No known key found for this signature in database
GPG Key ID: 84C23AA04587A91F
6 changed files with 34 additions and 16 deletions

View File

@ -1,5 +1,6 @@
package awais.instagrabber.fragments.search;
import android.content.Context;
import android.os.Bundle;
import android.text.Editable;
import android.text.TextUtils;
@ -7,6 +8,7 @@ import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.inputmethod.InputMethodManager;
import android.widget.EditText;
import androidx.annotation.NonNull;
@ -36,6 +38,9 @@ import awais.instagrabber.models.enums.FavoriteType;
import awais.instagrabber.repositories.responses.search.SearchItem;
import awais.instagrabber.viewmodels.SearchFragmentViewModel;
import static awais.instagrabber.fragments.settings.PreferenceKeys.PREF_SEARCH_FOCUS_KEYBOARD;
import static awais.instagrabber.utils.Utils.settingsHelper;
public class SearchFragment extends Fragment implements SearchCategoryFragment.OnSearchItemClickListener {
private static final String TAG = SearchFragment.class.getSimpleName();
private static final String QUERY = "query";
@ -119,9 +124,11 @@ public class SearchFragment extends Fragment implements SearchCategoryFragment.O
if (mainActivity != null) {
mainActivity.showSearchView();
}
// if (searchInputLayout != null) {
// searchInputLayout.requestFocus();
// }
if (settingsHelper.getBoolean(PREF_SEARCH_FOCUS_KEYBOARD)) {
searchInput.requestFocus();
final InputMethodManager imm = (InputMethodManager) requireContext().getSystemService(Context.INPUT_METHOD_SERVICE);
if (imm != null) imm.showSoftInput(searchInput, InputMethodManager.SHOW_IMPLICIT);
}
}
private void init(@Nullable final Bundle savedInstanceState) {
@ -147,7 +154,11 @@ public class SearchFragment extends Fragment implements SearchCategoryFragment.O
searchInput.setText(savedQuery);
triggerEmptyQuery = false;
}
// searchInput.requestFocus();
if (settingsHelper.getBoolean(PREF_SEARCH_FOCUS_KEYBOARD)) {
searchInput.requestFocus();
final InputMethodManager imm = (InputMethodManager) requireContext().getSystemService(Context.INPUT_METHOD_SERVICE);
if (imm != null) imm.showSoftInput(searchInput, InputMethodManager.SHOW_IMPLICIT);
}
if (triggerEmptyQuery) {
viewModel.submitQuery("");
}

View File

@ -36,6 +36,7 @@ public class GeneralPreferencesFragment extends BasePreferencesFragment implemen
}
screen.addPreference(getUpdateCheckPreference(context));
screen.addPreference(getFlagSecurePreference(context));
screen.addPreference(getSearchFocusPreference(context));
final List<Preference> preferences = FlavorSettings.getInstance()
.getPreferences(context,
getChildFragmentManager(),
@ -101,6 +102,14 @@ public class GeneralPreferencesFragment extends BasePreferencesFragment implemen
});
}
private Preference getSearchFocusPreference(@NonNull final Context context) {
final SwitchPreferenceCompat preference = new SwitchPreferenceCompat(context);
preference.setKey(PreferenceKeys.PREF_SEARCH_FOCUS_KEYBOARD);
preference.setTitle(R.string.pref_search_focus_keyboard);
preference.setIconSpaceReserved(false);
return preference;
}
@Override
public void onSave(final boolean orderHasChanged) {
if (!orderHasChanged) return;

View File

@ -1,6 +1,7 @@
package awais.instagrabber.fragments.settings;
public final class PreferenceKeys {
// new boolean prefs
public static final String PREF_ENABLE_DM_NOTIFICATIONS = "enable_dm_notifications";
public static final String PREF_ENABLE_DM_AUTO_REFRESH = "enable_dm_auto_refresh";
public static final String PREF_ENABLE_DM_AUTO_REFRESH_FREQ_UNIT = "enable_dm_auto_refresh_freq_unit";
@ -8,6 +9,7 @@ public final class PreferenceKeys {
public static final String PREF_ENABLE_SENTRY = "enable_sentry";
public static final String PREF_TAB_ORDER = "tab_order";
public static final String PREF_SHOWN_COUNT_TOOLTIP = "shown_count_tooltip";
public static final String PREF_SEARCH_FOCUS_KEYBOARD = "search_focus_keyboard";
// string prefs
public static final String FOLDER_PATH = "custom_path";
public static final String DATE_TIME_FORMAT = "date_time_format";
@ -18,12 +20,11 @@ public final class PreferenceKeys {
public static final String STORY_SORT = "story_sort";
// set string prefs
public static final String KEYWORD_FILTERS = "keyword_filters";
// boolean prefs
// old boolean prefs
public static final String DOWNLOAD_USER_FOLDER = "download_user_folder";
public static final String TOGGLE_KEYWORD_FILTER = "toggle_keyword_filter";
public static final String DOWNLOAD_PREPEND_USER_NAME = "download_user_name";
public static final String PLAY_IN_BACKGROUND = "play_in_background";
// deprecated: public static final String BOTTOM_TOOLBAR = "bottom_toolbar";
public static final String FOLDER_SAVE_TO = "saved_to";
public static final String AUTOPLAY_VIDEOS = "autoplay_videos";
public static final String MUTED_VIDEOS = "muted_videos";
@ -33,10 +34,6 @@ public final class PreferenceKeys {
public static final String MARK_AS_SEEN = "mark_as_seen";
public static final String HIDE_MUTED_REELS = "hide_muted_reels";
public static final String DM_MARK_AS_SEEN = "dm_mark_as_seen";
// deprecated: public static final String INSTADP = "instadp";
// deprecated: public static final String STORIESIG = "storiesig";
// deprecated: public static final String STORY_VIEWER = "story_viewer";
// deprecated: public static final String AMOLED_THEME = "amoled_theme";
public static final String CHECK_ACTIVITY = "check_activity";
public static final String CHECK_UPDATES = "check_updates";
public static final String FLAG_SECURE = "flag_secure";

View File

@ -9,7 +9,7 @@ public final class Constants {
public static final String APP_UA_CODE = "app_ua_code";
// never Export
public static final String COOKIE = "cookie";
public static final String SHOW_QUICK_ACCESS_DIALOG = "show_quick_dlg";
// deprecated: public static final String SHOW_QUICK_ACCESS_DIALOG = "show_quick_dlg";
public static final String DEVICE_UUID = "device_uuid";
public static final String BROWSER_UA = "browser_ua";
public static final String APP_UA = "app_ua";

View File

@ -58,8 +58,8 @@ import static awais.instagrabber.utils.Constants.PREF_SAVED_POSTS_LAYOUT;
import static awais.instagrabber.utils.Constants.PREF_TAGGED_POSTS_LAYOUT;
import static awais.instagrabber.utils.Constants.PREF_TOPIC_POSTS_LAYOUT;
import static awais.instagrabber.utils.Constants.PREV_INSTALL_VERSION;
import static awais.instagrabber.fragments.settings.PreferenceKeys.PREF_SEARCH_FOCUS_KEYBOARD;
import static awais.instagrabber.fragments.settings.PreferenceKeys.SHOW_CAPTIONS;
import static awais.instagrabber.utils.Constants.SHOW_QUICK_ACCESS_DIALOG;
import static awais.instagrabber.utils.Constants.SKIPPED_VERSION;
import static awais.instagrabber.fragments.settings.PreferenceKeys.STORY_SORT;
import static awais.instagrabber.fragments.settings.PreferenceKeys.SWAP_DATE_TIME_FORMAT_ENABLED;
@ -155,18 +155,18 @@ public final class SettingsHelper {
return sharedPreferences != null && sharedPreferences.contains(key);
}
@StringDef(
{APP_LANGUAGE, APP_THEME, APP_UA, BROWSER_UA, COOKIE, FOLDER_PATH, DATE_TIME_FORMAT, DATE_TIME_SELECTION,
@StringDef({APP_LANGUAGE, APP_THEME, APP_UA, BROWSER_UA, COOKIE, FOLDER_PATH, DATE_TIME_FORMAT, DATE_TIME_SELECTION,
CUSTOM_DATE_TIME_FORMAT, DEVICE_UUID, SKIPPED_VERSION, DEFAULT_TAB, PREF_DARK_THEME, PREF_LIGHT_THEME,
PREF_POSTS_LAYOUT, PREF_PROFILE_POSTS_LAYOUT, PREF_TOPIC_POSTS_LAYOUT, PREF_HASHTAG_POSTS_LAYOUT,
PREF_LOCATION_POSTS_LAYOUT, PREF_LIKED_POSTS_LAYOUT, PREF_TAGGED_POSTS_LAYOUT, PREF_SAVED_POSTS_LAYOUT,
STORY_SORT, PREF_EMOJI_VARIANTS, PREF_REACTIONS, PREF_ENABLE_DM_AUTO_REFRESH_FREQ_UNIT, PREF_TAB_ORDER})
public @interface StringSettings {}
@StringDef({DOWNLOAD_USER_FOLDER, DOWNLOAD_PREPEND_USER_NAME, FOLDER_SAVE_TO, AUTOPLAY_VIDEOS, SHOW_QUICK_ACCESS_DIALOG, MUTED_VIDEOS,
@StringDef({DOWNLOAD_USER_FOLDER, DOWNLOAD_PREPEND_USER_NAME, FOLDER_SAVE_TO, AUTOPLAY_VIDEOS, MUTED_VIDEOS,
SHOW_CAPTIONS, CUSTOM_DATE_TIME_FORMAT_ENABLED, MARK_AS_SEEN, DM_MARK_AS_SEEN, CHECK_ACTIVITY,
CHECK_UPDATES, SWAP_DATE_TIME_FORMAT_ENABLED, PREF_ENABLE_DM_NOTIFICATIONS, PREF_ENABLE_DM_AUTO_REFRESH,
FLAG_SECURE, TOGGLE_KEYWORD_FILTER, PREF_ENABLE_SENTRY, HIDE_MUTED_REELS, PLAY_IN_BACKGROUND, PREF_SHOWN_COUNT_TOOLTIP})
FLAG_SECURE, TOGGLE_KEYWORD_FILTER, PREF_ENABLE_SENTRY, HIDE_MUTED_REELS, PLAY_IN_BACKGROUND,
PREF_SHOWN_COUNT_TOOLTIP, PREF_SEARCH_FOCUS_KEYBOARD})
public @interface BooleanSettings {}
@StringDef({PREV_INSTALL_VERSION, BROWSER_UA_CODE, APP_UA_CODE, PREF_ENABLE_DM_AUTO_REFRESH_FREQ_NUMBER})

View File

@ -269,6 +269,7 @@
<string name="skip_update_checkbox">Do not show again until next update</string>
<string name="version">Version</string>
<string name="pref_start_screen">Start screen</string>
<string name="pref_search_focus_keyboard" comment="basically bring up the keyboard immediately when someone does search">Show keyboard on search</string>
<string name="pref_category_general">General</string>
<string name="pref_category_theme">Theme</string>
<string name="pref_category_downloads">Downloads</string>