forked from organicmaps/organicmaps
[android] Add an option to disable search history
Signed-off-by: Bukkapatnam Sandilya <sandysandilya99@gmail.com> Signed-off-by: Roman Tsisyk <roman@tsisyk.com>
This commit is contained in:
parent
8df3689034
commit
80f64af67d
6 changed files with 67 additions and 23 deletions
|
@ -39,6 +39,7 @@ import app.organicmaps.widget.SearchToolbarController;
|
|||
import app.organicmaps.util.SharedPropertiesUtils;
|
||||
import app.organicmaps.util.UiUtils;
|
||||
import app.organicmaps.util.Utils;
|
||||
import app.organicmaps.util.Config;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
|
@ -259,6 +260,12 @@ public class SearchFragment extends BaseMwmFragment
|
|||
|
||||
mToolbarController = new ToolbarController(view);
|
||||
TabLayout tabLayout = root.findViewById(R.id.tabs);
|
||||
|
||||
if (Config.isSearchHistoryEnabled())
|
||||
tabLayout.setVisibility(View.VISIBLE);
|
||||
else
|
||||
tabLayout.setVisibility(View.GONE);
|
||||
|
||||
final TabAdapter tabAdapter = new TabAdapter(getChildFragmentManager(), pager, tabLayout);
|
||||
|
||||
mResultsFrame = root.findViewById(R.id.results_frame);
|
||||
|
@ -288,7 +295,7 @@ public class SearchFragment extends BaseMwmFragment
|
|||
|
||||
SearchEngine.INSTANCE.addListener(this);
|
||||
|
||||
if (SearchRecents.getSize() == 0)
|
||||
if (SearchRecents.getSize() == 0 && Config.isSearchHistoryEnabled())
|
||||
pager.setCurrentItem(TabAdapter.Tab.CATEGORIES.ordinal());
|
||||
|
||||
tabAdapter.setTabSelectedListener(tab -> mToolbarController.deactivate());
|
||||
|
@ -383,7 +390,8 @@ public class SearchFragment extends BaseMwmFragment
|
|||
void showSingleResultOnMap(@NonNull SearchResult result, int resultIndex)
|
||||
{
|
||||
final String query = getQuery();
|
||||
SearchRecents.add(query, requireContext());
|
||||
if (Config.isSearchHistoryEnabled())
|
||||
SearchRecents.add(query, requireContext());
|
||||
SearchEngine.INSTANCE.cancel();
|
||||
SearchEngine.INSTANCE.setQuery(query);
|
||||
|
||||
|
@ -417,7 +425,8 @@ public class SearchFragment extends BaseMwmFragment
|
|||
SearchEngine.INSTANCE.cancel();
|
||||
|
||||
final String query = getQuery();
|
||||
SearchRecents.add(query, requireContext());
|
||||
if (Config.isSearchHistoryEnabled())
|
||||
SearchRecents.add(query, requireContext());
|
||||
mLastQueryTimestamp = System.nanoTime();
|
||||
|
||||
SearchEngine.INSTANCE.searchInteractive(
|
||||
|
|
|
@ -2,6 +2,7 @@ package app.organicmaps.search;
|
|||
|
||||
import android.content.Context;
|
||||
import android.util.SparseArray;
|
||||
import android.view.View;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.fragment.app.Fragment;
|
||||
|
@ -12,6 +13,7 @@ import androidx.viewpager.widget.ViewPager;
|
|||
import com.google.android.material.tabs.TabLayout;
|
||||
import app.organicmaps.R;
|
||||
import app.organicmaps.util.Graphics;
|
||||
import app.organicmaps.util.Config;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
@ -105,14 +107,17 @@ class TabAdapter extends FragmentPagerAdapter
|
|||
private final List<Class<? extends Fragment>> mClasses = new ArrayList<>();
|
||||
private final SparseArray<Fragment> mFragments = new SparseArray<>();
|
||||
private OnTabSelectedListener mTabSelectedListener;
|
||||
|
||||
private TabLayout mTabs;
|
||||
TabAdapter(FragmentManager fragmentManager, ViewPager pager, TabLayout tabs)
|
||||
{
|
||||
super(fragmentManager);
|
||||
|
||||
this.mTabs = tabs;
|
||||
for (Tab tab : Tab.values())
|
||||
{
|
||||
if (tab==tab.HISTORY && !Config.isSearchHistoryEnabled())
|
||||
continue;
|
||||
mClasses.add(tab.getFragmentClass());
|
||||
|
||||
}
|
||||
final List<Fragment> fragments = fragmentManager.getFragments();
|
||||
if (fragments != null)
|
||||
{
|
||||
|
@ -130,8 +135,8 @@ class TabAdapter extends FragmentPagerAdapter
|
|||
|
||||
mPager = pager;
|
||||
mPager.setAdapter(this);
|
||||
|
||||
attachTo(tabs);
|
||||
if (mTabs.getVisibility() != View.GONE)
|
||||
attachTo(tabs);
|
||||
}
|
||||
|
||||
private void attachTo(TabLayout tabs)
|
||||
|
|
|
@ -39,6 +39,7 @@ import app.organicmaps.util.ThemeSwitcher;
|
|||
import app.organicmaps.util.UiUtils;
|
||||
import app.organicmaps.util.Utils;
|
||||
import app.organicmaps.util.log.LogsManager;
|
||||
import app.organicmaps.search.SearchRecents;
|
||||
import com.google.android.material.dialog.MaterialAlertDialogBuilder;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
@ -272,14 +273,8 @@ public class SettingsPrefsFragment extends BaseXmlSettingsFragment
|
|||
initEmulationBadStorage();
|
||||
initUseMobileDataPrefsCallbacks();
|
||||
initPowerManagementPrefsCallbacks();
|
||||
final boolean playServices = initPlayServicesPrefsCallbacks();
|
||||
if (!playServices)
|
||||
{
|
||||
// Remove "Tracking" section completely.
|
||||
final PreferenceCategory tracking = findPreference(getString(R.string.pref_privacy));
|
||||
if (tracking != null)
|
||||
mPreferenceScreen.removePreference(tracking);
|
||||
}
|
||||
initPlayServicesPrefsCallbacks();
|
||||
initSearchPrivacyPrefsCallbacks();
|
||||
initScreenSleepEnabledPrefsCallbacks();
|
||||
initShowOnLockScreenPrefsCallbacks();
|
||||
}
|
||||
|
@ -526,17 +521,14 @@ public class SettingsPrefsFragment extends BaseXmlSettingsFragment
|
|||
});
|
||||
}
|
||||
|
||||
private boolean initPlayServicesPrefsCallbacks()
|
||||
private void initPlayServicesPrefsCallbacks()
|
||||
{
|
||||
final Preference pref = findPreference(getString(R.string.pref_play_services));
|
||||
if (pref == null)
|
||||
return false;
|
||||
return;
|
||||
|
||||
if (!LocationProviderFactory.isGoogleLocationAvailable(requireActivity().getApplicationContext()))
|
||||
{
|
||||
removePreference(getString(R.string.pref_privacy), pref);
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
((TwoStatePreference) pref).setChecked(Config.useGoogleServices());
|
||||
|
@ -561,10 +553,31 @@ public class SettingsPrefsFragment extends BaseXmlSettingsFragment
|
|||
return true;
|
||||
}
|
||||
});
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
private void initSearchPrivacyPrefsCallbacks()
|
||||
{
|
||||
final Preference pref = findPreference(getString(R.string.pref_search_history));
|
||||
if (pref == null)
|
||||
return;
|
||||
|
||||
final boolean isHistoryEnabled = Config.isSearchHistoryEnabled();
|
||||
((TwoStatePreference) pref).setChecked(isHistoryEnabled);
|
||||
pref.setOnPreferenceChangeListener((preference, newValue) -> {
|
||||
boolean newVal = (Boolean) newValue;
|
||||
if (newVal != isHistoryEnabled)
|
||||
{
|
||||
Config.setSearchHistoryEnabled(newVal);
|
||||
if (newVal)
|
||||
SearchRecents.refresh();
|
||||
else
|
||||
SearchRecents.clear();
|
||||
}
|
||||
return true;
|
||||
});
|
||||
}
|
||||
|
||||
private void init3dModePrefsCallbacks()
|
||||
{
|
||||
final TwoStatePreference pref = getPreference(getString(R.string.pref_3d_buildings));
|
||||
|
|
|
@ -3,7 +3,6 @@ package app.organicmaps.util;
|
|||
import android.content.Context;
|
||||
import android.content.SharedPreferences;
|
||||
import android.os.Build;
|
||||
import android.text.TextUtils;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.preference.PreferenceManager;
|
||||
|
@ -37,6 +36,7 @@ public final class Config
|
|||
private static final String KEY_MISC_SHOW_ON_LOCK_SCREEN = "ShowOnLockScreen";
|
||||
private static final String KEY_MISC_AGPS_TIMESTAMP = "AGPSTimestamp";
|
||||
private static final String KEY_DONATE_URL = "DonateUrl";
|
||||
private static final String KEY_PREF_SEARCH_HISTORY = "SearchHistoryEnabled";
|
||||
|
||||
/**
|
||||
* The total number of app launches.
|
||||
|
@ -403,6 +403,16 @@ public final class Config
|
|||
.apply();
|
||||
}
|
||||
|
||||
public static boolean isSearchHistoryEnabled()
|
||||
{
|
||||
return getBool(KEY_PREF_SEARCH_HISTORY, true);
|
||||
}
|
||||
|
||||
public static void setSearchHistoryEnabled(boolean enabled)
|
||||
{
|
||||
setBool(KEY_PREF_SEARCH_HISTORY, enabled);
|
||||
}
|
||||
|
||||
private static native boolean nativeHasConfigValue(String name);
|
||||
private static native boolean nativeDeleteConfigValue(String name);
|
||||
private static native boolean nativeGetBoolean(String name, boolean defaultValue);
|
||||
|
|
|
@ -56,6 +56,7 @@
|
|||
<string name="tag_height_limited" translatable="false">height limited</string>
|
||||
|
||||
<string name="pref_privacy" translatable="false">pref_privacy</string>
|
||||
<string name="pref_search_history" translatable="false">pref_search_history</string>
|
||||
<string name="never_enum_value" translatable="false">NEVER</string>
|
||||
<string name="always_enum_value" translatable="false">ALWAYS</string>
|
||||
<string name="auto_enum_value" translatable="false">AUTO</string>
|
||||
|
|
|
@ -184,6 +184,12 @@
|
|||
android:summary="@string/pref_use_google_play"
|
||||
android:defaultValue="true"
|
||||
android:order="1"/>
|
||||
<SwitchPreferenceCompat
|
||||
android:key="@string/pref_search_history"
|
||||
android:title="@string/search_history_title"
|
||||
app:singleLineTitle="false"
|
||||
android:defaultValue="true"
|
||||
android:order="2"/>
|
||||
</androidx.preference.PreferenceCategory>
|
||||
<androidx.preference.PreferenceCategory
|
||||
android:key="@string/pref_information"
|
||||
|
|
Loading…
Add table
Reference in a new issue