Skip to content

Commit

Permalink
updating SearchPreference dependency
Browse files Browse the repository at this point in the history
  • Loading branch information
KnollFrank committed Jun 4, 2024
1 parent eda1532 commit 9d75a3e
Show file tree
Hide file tree
Showing 5 changed files with 69 additions and 27 deletions.
2 changes: 1 addition & 1 deletion OsmAnd/build-common.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -386,7 +386,7 @@ dependencies {
implementation "androidx.car.app:app-projected:1.2.0"

implementation 'com.google.android.gms:play-services-location:21.0.1'
implementation 'com.github.KnollFrank:SearchPreference:0bb034822d'
implementation 'com.github.KnollFrank:SearchPreference:ac4c4f9fa5'
implementation 'com.google.guava:guava:33.2.0-android'

//implementation "androidx.tracing:tracing:1.1.0"
Expand Down
3 changes: 0 additions & 3 deletions OsmAnd/res/xml/settings_main_screen.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@
xmlns:tools="http://schemas.android.com/tools"
android:title="@string/shared_string_settings">

<com.bytehamster.lib.preferencesearch.SearchPreference
android:key="searchPreference" />

<Preference
android:key="global_settings"
android:layout="@layout/preference_with_descr"
Expand Down
42 changes: 37 additions & 5 deletions OsmAnd/src/net/osmand/plus/activities/MapActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.util.Pair;
import android.view.KeyEvent;
import android.view.MotionEvent;
import android.view.View;
Expand All @@ -25,6 +26,7 @@
import android.widget.ProgressBar;

import androidx.annotation.IdRes;
import androidx.annotation.LayoutRes;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.core.app.ActivityCompat;
Expand All @@ -38,8 +40,11 @@
import androidx.preference.PreferenceFragmentCompat.OnPreferenceStartFragmentCallback;

import com.bytehamster.lib.preferencesearch.Navigation;
import com.bytehamster.lib.preferencesearch.PreferenceFragments;
import com.bytehamster.lib.preferencesearch.SearchConfiguration;
import com.bytehamster.lib.preferencesearch.SearchPreferenceResult;
import com.bytehamster.lib.preferencesearch.SearchPreferenceResultListener;
import com.bytehamster.lib.preferencesearch.common.UIUtils;

import net.osmand.Location;
import net.osmand.PlatformUtil;
Expand Down Expand Up @@ -246,7 +251,7 @@ public void onCreate(Bundle savedInstanceState) {
trackDetailsMenu.setMapActivity(this);

super.onCreate(savedInstanceState);
setContentView(R.layout.main);
_setContentView(R.layout.main);
enterToFullScreen();
// Navigation Drawer
AndroidUtils.addStatusBarPadding21v(this, findViewById(R.id.menuItems));
Expand Down Expand Up @@ -1642,15 +1647,42 @@ public void onInAppPurchaseItemPurchased(String sku) {
}

@IdRes
public static final int FRAGMENT_CONTAINER_VIEW = R.id.fragmentContainer;
private static final int FRAGMENT_CONTAINER_VIEW = R.id.fragmentContainer;

@IdRes
private int dummyFragmentContainerViewId = View.NO_ID;

@Override
public void onSearchResultClicked(@NonNull final SearchPreferenceResult result) {
Navigation.navigatePathAndHighlightPreference(
result.getResourceFile().getName(),
Navigation.showPreferenceScreenAndHighlightPreference(
result.getPreferenceFragmentClass().getName(),
result.getKey(),
true,
this,
FRAGMENT_CONTAINER_VIEW);
}

private void _setContentView(final @LayoutRes int resource) {
final Pair<View, Integer> contentViewAndDummyFragmentContainerViewId =
UIUtils.createContentViewAndDummyFragmentContainerViewId(
resource,
this);
dummyFragmentContainerViewId = contentViewAndDummyFragmentContainerViewId.second;
setContentView(contentViewAndDummyFragmentContainerViewId.first);
}

public SearchConfiguration createSearchConfiguration(final PreferenceFragmentCompat root) {
final SearchConfiguration searchConfiguration = new SearchConfiguration();
searchConfiguration.setActivity(this);
searchConfiguration.setFragmentContainerViewId(FRAGMENT_CONTAINER_VIEW);
searchConfiguration.setDummyFragmentContainerViewId(dummyFragmentContainerViewId);
searchConfiguration.setPreferenceFragments(
PreferenceFragments.getPreferenceFragments(
root,
this,
dummyFragmentContainerViewId));
searchConfiguration.setBreadcrumbsEnabled(true);
searchConfiguration.setFuzzySearchEnabled(false);
searchConfiguration.setHistoryEnabled(true);
return searchConfiguration;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import static net.osmand.aidlapi.OsmAndCustomizationConstants.DRAWER_SETTINGS_ID;
import static net.osmand.aidlapi.OsmAndCustomizationConstants.SETTINGS_ID;
import static net.osmand.plus.activities.MapActivity.FRAGMENT_CONTAINER_VIEW;

import android.annotation.SuppressLint;
import android.app.Activity;
Expand Down Expand Up @@ -47,9 +46,6 @@
import androidx.recyclerview.widget.RecyclerView;

import com.bytehamster.lib.preferencesearch.BaseSearchPreferenceFragment;
import com.bytehamster.lib.preferencesearch.PreferenceFragments;
import com.bytehamster.lib.preferencesearch.SearchConfiguration;
import com.bytehamster.lib.preferencesearch.SearchPreference;
import com.google.android.material.appbar.AppBarLayout;
import com.google.android.material.snackbar.Snackbar;

Expand Down Expand Up @@ -147,7 +143,7 @@ public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container,
PreferenceManager prefManager = getPreferenceManager();
PreferenceScreen preferenceScreen = prefManager.inflateFromResource(prefManager.getContext(), currentScreenType.preferencesResId, null);
if (prefManager.setPreferences(preferenceScreen)) {
setupSearchablePreferences();
setupPreferences();
registerPreferences(preferenceScreen);
}
} else {
Expand Down Expand Up @@ -388,18 +384,6 @@ public void recreate() {

protected abstract void setupPreferences();

private void setupSearchablePreferences() {
setupPreferences();
final SearchPreference searchPreference = findPreference("searchPreference");
if (searchPreference != null) {
final SearchConfiguration config = searchPreference.getSearchConfiguration();
config.setActivity(getMapActivity());
config.setFragmentContainerViewId(FRAGMENT_CONTAINER_VIEW);
config.setPreferenceFragmentsSupplier(() -> PreferenceFragments.getPreferenceFragments(new MainSettingsFragment(), getActivity(), FRAGMENT_CONTAINER_VIEW));
config.setFuzzySearchEnabled(false);
}
}

protected void onBindPreferenceViewHolder(@NonNull Preference preference, @NonNull PreferenceViewHolder holder) {
if (preference.isSelectable()) {
View selectableView = holder.itemView.findViewById(R.id.selectable_list_item);
Expand Down Expand Up @@ -559,7 +543,7 @@ private void updatePreferencesScreen() {
if (resId != -1) {
addPreferencesFromResource(resId);
}
setupSearchablePreferences();
setupPreferences();
registerPreferences(getPreferenceScreen());
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@
import android.graphics.drawable.ColorDrawable;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.ColorRes;
Expand All @@ -17,8 +19,12 @@
import androidx.fragment.app.FragmentManager;
import androidx.preference.Preference;
import androidx.preference.PreferenceCategory;
import androidx.preference.PreferenceFragmentCompat;
import androidx.preference.PreferenceViewHolder;

import com.bytehamster.lib.preferencesearch.SearchConfiguration;
import com.bytehamster.lib.preferencesearch.SearchPreferenceFragments;

import net.osmand.plus.OsmandApplication;
import net.osmand.plus.R;
import net.osmand.plus.activities.MapActivity;
Expand Down Expand Up @@ -263,4 +269,27 @@ public void onProfileSelected(Bundle args) {
profileKey, imported);
}
}

@Override
protected void createToolbar(@NonNull final LayoutInflater inflater, @NonNull final View view) {
super.createToolbar(inflater, view);
configureSearchPreferenceButton(view.findViewById(R.id.action_button));
}

@Override
protected void updateToolbar() {
super.updateToolbar();
}

private void configureSearchPreferenceButton(final ImageView searchPreferenceButton) {
searchPreferenceButton.setOnClickListener(v -> showSearchPreferenceFragment(new MainSettingsFragment()));
searchPreferenceButton.setImageDrawable(getIcon(R.drawable.searchpreference_ic_search));
searchPreferenceButton.setVisibility(View.VISIBLE);
}

private void showSearchPreferenceFragment(final PreferenceFragmentCompat root) {
final SearchConfiguration searchConfiguration = getMapActivity().createSearchConfiguration(root);
final SearchPreferenceFragments searchPreferenceFragments = new SearchPreferenceFragments(searchConfiguration);
searchPreferenceFragments.showSearchPreferenceFragment();
}
}

0 comments on commit 9d75a3e

Please sign in to comment.