Skip to content

Commit

Permalink
refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
KnollFrank committed Jun 10, 2024
1 parent e982cbc commit 0b2f8ec
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 69 deletions.
2 changes: 1 addition & 1 deletion OsmAnd/build-common.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,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:9dff94db45'
implementation 'com.github.KnollFrank:SearchPreference:ba22ab7cb2'
implementation 'com.google.guava:guava:33.2.0-android'

//implementation "androidx.tracing:tracing:1.1.0"
Expand Down
53 changes: 2 additions & 51 deletions OsmAnd/src/net/osmand/plus/activities/MapActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
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,8 +24,6 @@
import android.view.WindowManager;
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 @@ -39,13 +36,6 @@
import androidx.preference.PreferenceFragmentCompat;
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;
import net.osmand.SecondSplashScreenFragment;
Expand Down Expand Up @@ -159,7 +149,7 @@
public class MapActivity extends OsmandActionBarActivity implements DownloadEvents,
IRouteInformationListener, AMapPointUpdateListener, MapMarkerChangedListener,
OnDrawMapListener, OsmAndAppCustomizationListener, LockUIAdapter,
OnPreferenceStartFragmentCallback, SearchPreferenceResultListener {
OnPreferenceStartFragmentCallback {

public static final String INTENT_KEY_PARENT_MAP_ACTIVITY = "intent_parent_map_activity_key";
public static final String INTENT_PARAMS = "intent_prarams";
Expand Down Expand Up @@ -251,7 +241,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 @@ -1645,43 +1635,4 @@ public void onInAppPurchaseGetItems() {
public void onInAppPurchaseItemPurchased(String sku) {
getMapLayers().getRouteLayer().resetColorAvailabilityCache();
}

@IdRes
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.showPreferenceScreenAndHighlightPreference(
result.getPreferenceFragmentClass().getName(),
result.getKey(),
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(false);
searchConfiguration.setFuzzySearchEnabled(false);
return searchConfiguration;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@
import androidx.preference.TwoStatePreference;
import androidx.recyclerview.widget.RecyclerView;

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

Expand Down Expand Up @@ -83,6 +82,8 @@
import java.io.Serializable;
import java.util.Set;

import de.KnollFrank.lib.preferencesearch.BaseSearchPreferenceFragment;

public abstract class BaseSettingsFragment extends BaseSearchPreferenceFragment implements OnPreferenceChangeListener,
OnPreferenceClickListener, AppModeChangedListener, OnConfirmPreferenceChange, OnPreferenceChanged {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,7 @@ public void onProfileSelected(Bundle args) {
@Override
protected void createToolbar(@NonNull final LayoutInflater inflater, @NonNull final View view) {
super.createToolbar(inflater, view);
new SearchPreferenceButtonHelper(this).configureSearchPreferenceButton(view.findViewById(R.id.action_button));
new SearchPreferenceButtonHelper(this, R.id.fragmentContainer)
.configureSearchPreferenceButton(view.findViewById(R.id.action_button));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,24 @@
import android.view.View;
import android.widget.ImageView;

import com.bytehamster.lib.preferencesearch.SearchConfiguration;
import com.bytehamster.lib.preferencesearch.SearchPreferenceFragments;
import androidx.annotation.IdRes;

import net.osmand.plus.R;

import java.util.Optional;

import de.KnollFrank.lib.preferencesearch.SearchConfiguration;
import de.KnollFrank.lib.preferencesearch.SearchPreferenceFragments;

class SearchPreferenceButtonHelper {

private final BaseSettingsFragment baseSettingsFragment;
private static Optional<SearchConfiguration> searchConfigurationCache = Optional.empty();
private final @IdRes int fragmentContainerViewId;

public SearchPreferenceButtonHelper(final BaseSettingsFragment baseSettingsFragment) {
public SearchPreferenceButtonHelper(final BaseSettingsFragment baseSettingsFragment,
final @IdRes int fragmentContainerViewId) {
this.baseSettingsFragment = baseSettingsFragment;
this.fragmentContainerViewId = fragmentContainerViewId;
}

public void configureSearchPreferenceButton(final ImageView searchPreferenceButton) {
Expand All @@ -27,20 +31,15 @@ public void configureSearchPreferenceButton(final ImageView searchPreferenceButt

private void showSearchPreferenceFragment() {
final SearchPreferenceFragments searchPreferenceFragments =
new SearchPreferenceFragments(getSearchConfiguration());
new SearchPreferenceFragments(createSearchConfiguration());
searchPreferenceFragments.showSearchPreferenceFragment();
}

private SearchConfiguration getSearchConfiguration() {
if (!searchConfigurationCache.isPresent()) {
searchConfigurationCache = Optional.of(createSearchConfiguration());
}
return searchConfigurationCache.get();
}

private SearchConfiguration createSearchConfiguration() {
return baseSettingsFragment
.getMapActivity()
.createSearchConfiguration(new MainSettingsFragment());
return new SearchConfiguration(
Optional.of(baseSettingsFragment.getMapActivity()),
fragmentContainerViewId,
Optional.empty(),
baseSettingsFragment.getClass());
}
}

0 comments on commit 0b2f8ec

Please sign in to comment.