Skip to content

Commit

Permalink
refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
KnollFrank committed Dec 2, 2024
1 parent a02465b commit 068e29f
Show file tree
Hide file tree
Showing 8 changed files with 55 additions and 51 deletions.
2 changes: 1 addition & 1 deletion OsmAnd/build-common.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -375,7 +375,7 @@ dependencies {
implementation "androidx.car.app:app-projected:1.4.0"

implementation 'com.google.android.gms:play-services-location:21.3.0'
implementation 'com.github.KnollFrank:SettingsSearch:8bf5afa4dc'
implementation 'com.github.KnollFrank:SettingsSearch:8e7bf73a41'
// https://mvnrepository.com/artifact/com.google.guava/guava
implementation 'com.google.guava:guava:33.3.1-android'

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -419,14 +419,14 @@ public Optional<PreferenceFragmentHandler> getPreferenceFragmentHandler(final Pr
new PreferenceFragmentHandler() {

@Override
public String getClassNameOfPreferenceFragment() {
return EXTERNAL_INPUT_DEVICE.fragmentName;
public Class<? extends PreferenceFragmentCompat> getClassOfPreferenceFragment() {
return EXTERNAL_INPUT_DEVICE.fragmentClass.asSubclass(PreferenceFragmentCompat.class);
}

@Override
public PreferenceFragmentCompat createPreferenceFragment(final Context context, final Fragment target) {
return (PreferenceFragmentCompat) BaseSettingsFragment.createFragment(
getClassNameOfPreferenceFragment(),
getClassOfPreferenceFragment().getName(),
context,
getSelectedAppMode(),
new Bundle(),
Expand All @@ -438,7 +438,7 @@ public boolean showPreferenceFragment(final PreferenceFragmentCompat preferenceF
return BaseSettingsFragment.showFragment(
preferenceFragment,
requireActivity(),
getClassNameOfPreferenceFragment());
getClassOfPreferenceFragment().getName());
}
}
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -175,14 +175,14 @@ public Optional<PreferenceFragmentHandler> getPreferenceFragmentHandler(final Pr
new PreferenceFragmentHandler() {

@Override
public String getClassNameOfPreferenceFragment() {
return SettingsScreenType.CONFIGURE_PROFILE.fragmentName;
public Class<? extends PreferenceFragmentCompat> getClassOfPreferenceFragment() {
return SettingsScreenType.CONFIGURE_PROFILE.fragmentClass.asSubclass(PreferenceFragmentCompat.class);
}

@Override
public PreferenceFragmentCompat createPreferenceFragment(final Context context, final Fragment target) {
return (PreferenceFragmentCompat) BaseSettingsFragment.createFragment(
getClassNameOfPreferenceFragment(),
getClassOfPreferenceFragment().getName(),
context,
applicationMode,
new Bundle(),
Expand All @@ -194,7 +194,7 @@ public boolean showPreferenceFragment(final PreferenceFragmentCompat preferenceF
return BaseSettingsFragment.showFragment(
preferenceFragment,
requireActivity(),
getClassNameOfPreferenceFragment());
getClassOfPreferenceFragment().getName());
}
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -599,14 +599,14 @@ public Optional<PreferenceFragmentHandler> getPreferenceFragmentHandler(final Pr
new PreferenceFragmentHandler() {

@Override
public String getClassNameOfPreferenceFragment() {
return DANGEROUS_GOODS.fragmentName;
public Class<? extends PreferenceFragmentCompat> getClassOfPreferenceFragment() {
return DANGEROUS_GOODS.fragmentClass.asSubclass(PreferenceFragmentCompat.class);
}

@Override
public PreferenceFragmentCompat createPreferenceFragment(final Context context, final Fragment target) {
return (PreferenceFragmentCompat) BaseSettingsFragment.createFragment(
getClassNameOfPreferenceFragment(),
getClassOfPreferenceFragment().getName(),
context,
getSelectedAppMode(),
new Bundle(),
Expand All @@ -618,7 +618,7 @@ public boolean showPreferenceFragment(final PreferenceFragmentCompat preferenceF
return BaseSettingsFragment.showFragment(
preferenceFragment,
requireActivity(),
getClassNameOfPreferenceFragment());
getClassOfPreferenceFragment().getName());
}
});
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package net.osmand.plus.settings.fragments;

import androidx.fragment.app.Fragment;

import net.osmand.plus.R;
import net.osmand.plus.keyevent.fragments.MainExternalInputDevicesFragment;
import net.osmand.plus.plugins.accessibility.AccessibilitySettingsFragment;
Expand All @@ -17,49 +19,51 @@

public enum SettingsScreenType {

MAIN_SETTINGS(MainSettingsFragment.class.getName(), false, null, R.xml.settings_main_screen, R.layout.global_preference_toolbar),
GLOBAL_SETTINGS(GlobalSettingsFragment.class.getName(), false, null, R.xml.global_settings, R.layout.global_preference_toolbar),
CONFIGURE_PROFILE(ConfigureProfileFragment.class.getName(), true, null, R.xml.configure_profile, R.layout.profile_preference_toolbar_with_switch),
PROXY_SETTINGS(ProxySettingsFragment.class.getName(), false, null, R.xml.proxy_preferences, R.layout.global_preferences_toolbar_with_switch),
SEND_UUID(SendUniqueIdentifiersFragment.class.getName(), false, null, R.xml.send_uuid_preferences, R.layout.global_preference_toolbar),
GENERAL_PROFILE(GeneralProfileSettingsFragment.class.getName(), true, ApplyQueryType.BOTTOM_SHEET, R.xml.general_profile_settings, R.layout.profile_preference_toolbar),
NAVIGATION(NavigationFragment.class.getName(), true, ApplyQueryType.SNACK_BAR, R.xml.navigation_settings_new, R.layout.profile_preference_toolbar),
COORDINATES_FORMAT(CoordinatesFormatFragment.class.getName(), true, ApplyQueryType.BOTTOM_SHEET, R.xml.coordinates_format, R.layout.profile_preference_toolbar),
ROUTE_PARAMETERS(RouteParametersFragment.class.getName(), true, ApplyQueryType.SNACK_BAR, R.xml.route_parameters, R.layout.profile_preference_toolbar),
SCREEN_ALERTS(ScreenAlertsFragment.class.getName(), true, ApplyQueryType.SNACK_BAR, R.xml.screen_alerts, R.layout.profile_preference_toolbar_with_switch),
VOICE_ANNOUNCES(VoiceAnnouncesFragment.class.getName(), true, ApplyQueryType.SNACK_BAR, R.xml.voice_announces, R.layout.profile_preference_toolbar_with_switch),
VEHICLE_PARAMETERS(VehicleParametersFragment.class.getName(), true, ApplyQueryType.SNACK_BAR, R.xml.vehicle_parameters, R.layout.profile_preference_toolbar),
MAP_DURING_NAVIGATION(MapDuringNavigationFragment.class.getName(), true, ApplyQueryType.SNACK_BAR, R.xml.map_during_navigation, R.layout.profile_preference_toolbar),
TURN_SCREEN_ON(TurnScreenOnFragment.class.getName(), true, ApplyQueryType.BOTTOM_SHEET, R.xml.turn_screen_on, R.layout.profile_preference_toolbar),
DATA_STORAGE(DataStorageFragment.class.getName(), false, null, R.xml.data_storage, R.layout.global_preference_toolbar),
DIALOGS_AND_NOTIFICATIONS_SETTINGS(DialogsAndNotificationsSettingsFragment.class.getName(), false, null, R.xml.dialogs_and_notifications_preferences, R.layout.global_preference_toolbar),
HISTORY_SETTINGS(HistorySettingsFragment.class.getName(), false, null, R.xml.history_preferences, R.layout.global_preference_toolbar),
PROFILE_APPEARANCE(ProfileAppearanceFragment.TAG, true, null, R.xml.profile_appearance_screen, R.layout.profile_preference_toolbar),
OPEN_STREET_MAP_EDITING(OsmEditingFragment.class.getName(), false, null, R.xml.osm_editing, R.layout.global_preference_toolbar),
MAIN_SETTINGS(MainSettingsFragment.class, false, null, R.xml.settings_main_screen, R.layout.global_preference_toolbar),
GLOBAL_SETTINGS(GlobalSettingsFragment.class, false, null, R.xml.global_settings, R.layout.global_preference_toolbar),
CONFIGURE_PROFILE(ConfigureProfileFragment.class, true, null, R.xml.configure_profile, R.layout.profile_preference_toolbar_with_switch),
PROXY_SETTINGS(ProxySettingsFragment.class, false, null, R.xml.proxy_preferences, R.layout.global_preferences_toolbar_with_switch),
SEND_UUID(SendUniqueIdentifiersFragment.class, false, null, R.xml.send_uuid_preferences, R.layout.global_preference_toolbar),
GENERAL_PROFILE(GeneralProfileSettingsFragment.class, true, ApplyQueryType.BOTTOM_SHEET, R.xml.general_profile_settings, R.layout.profile_preference_toolbar),
NAVIGATION(NavigationFragment.class, true, ApplyQueryType.SNACK_BAR, R.xml.navigation_settings_new, R.layout.profile_preference_toolbar),
COORDINATES_FORMAT(CoordinatesFormatFragment.class, true, ApplyQueryType.BOTTOM_SHEET, R.xml.coordinates_format, R.layout.profile_preference_toolbar),
ROUTE_PARAMETERS(RouteParametersFragment.class, true, ApplyQueryType.SNACK_BAR, R.xml.route_parameters, R.layout.profile_preference_toolbar),
SCREEN_ALERTS(ScreenAlertsFragment.class, true, ApplyQueryType.SNACK_BAR, R.xml.screen_alerts, R.layout.profile_preference_toolbar_with_switch),
VOICE_ANNOUNCES(VoiceAnnouncesFragment.class, true, ApplyQueryType.SNACK_BAR, R.xml.voice_announces, R.layout.profile_preference_toolbar_with_switch),
VEHICLE_PARAMETERS(VehicleParametersFragment.class, true, ApplyQueryType.SNACK_BAR, R.xml.vehicle_parameters, R.layout.profile_preference_toolbar),
MAP_DURING_NAVIGATION(MapDuringNavigationFragment.class, true, ApplyQueryType.SNACK_BAR, R.xml.map_during_navigation, R.layout.profile_preference_toolbar),
TURN_SCREEN_ON(TurnScreenOnFragment.class, true, ApplyQueryType.BOTTOM_SHEET, R.xml.turn_screen_on, R.layout.profile_preference_toolbar),
DATA_STORAGE(DataStorageFragment.class, false, null, R.xml.data_storage, R.layout.global_preference_toolbar),
DIALOGS_AND_NOTIFICATIONS_SETTINGS(DialogsAndNotificationsSettingsFragment.class, false, null, R.xml.dialogs_and_notifications_preferences, R.layout.global_preference_toolbar),
HISTORY_SETTINGS(HistorySettingsFragment.class, false, null, R.xml.history_preferences, R.layout.global_preference_toolbar),
PROFILE_APPEARANCE(ProfileAppearanceFragment.class, true, null, R.xml.profile_appearance_screen, R.layout.profile_preference_toolbar),
OPEN_STREET_MAP_EDITING(OsmEditingFragment.class, false, null, R.xml.osm_editing, R.layout.global_preference_toolbar),
// FK-TODO: make searchable:
MULTIMEDIA_NOTES(MultimediaNotesFragment.class.getName(), true, ApplyQueryType.SNACK_BAR, R.xml.multimedia_notes, R.layout.profile_preference_toolbar),
MULTIMEDIA_NOTES(MultimediaNotesFragment.class, true, ApplyQueryType.SNACK_BAR, R.xml.multimedia_notes, R.layout.profile_preference_toolbar),
// FK-TODO: make searchable:
MONITORING_SETTINGS(MonitoringSettingsFragment.class.getName(), true, ApplyQueryType.SNACK_BAR, R.xml.monitoring_settings, R.layout.profile_preference_toolbar),
LIVE_MONITORING(LiveMonitoringFragment.class.getName(), false, ApplyQueryType.SNACK_BAR, R.xml.live_monitoring, R.layout.global_preferences_toolbar_with_switch),
ACCESSIBILITY_SETTINGS(AccessibilitySettingsFragment.class.getName(), true, ApplyQueryType.SNACK_BAR, R.xml.accessibility_settings, R.layout.profile_preference_toolbar),
DEVELOPMENT_SETTINGS(DevelopmentSettingsFragment.class.getName(), false, null, R.xml.development_settings, R.layout.global_preference_toolbar),
MONITORING_SETTINGS(MonitoringSettingsFragment.class, true, ApplyQueryType.SNACK_BAR, R.xml.monitoring_settings, R.layout.profile_preference_toolbar),
LIVE_MONITORING(LiveMonitoringFragment.class, false, ApplyQueryType.SNACK_BAR, R.xml.live_monitoring, R.layout.global_preferences_toolbar_with_switch),
ACCESSIBILITY_SETTINGS(AccessibilitySettingsFragment.class, true, ApplyQueryType.SNACK_BAR, R.xml.accessibility_settings, R.layout.profile_preference_toolbar),
DEVELOPMENT_SETTINGS(DevelopmentSettingsFragment.class, false, null, R.xml.development_settings, R.layout.global_preference_toolbar),
// FK-TODO: make searchable:
SIMULATION_NAVIGATION(SimulationNavigationSettingFragment.class.getName(), true, ApplyQueryType.NONE, R.xml.simulation_navigation_setting, R.layout.profile_preference_toolbar_with_switch),
ANT_PLUS_SETTINGS(ExternalDevicesListFragment.class.getName(), false, null, R.xml.antplus_settings, R.layout.global_preference_toolbar),
VEHICLE_METRICS_SETTINGS(VehicleMetricsSettingsFragment.class.getName(), false, null, R.xml.antplus_settings, R.layout.global_preference_toolbar),
WEATHER_SETTINGS(WeatherSettingsFragment.class.getName(), true, ApplyQueryType.SNACK_BAR, R.xml.weather_settings, R.layout.profile_preference_toolbar),
EXTERNAL_SETTINGS_WRITE_TO_TRACK_SETTINGS(ExternalSettingsWriteToTrackSettingsFragment.class.getName(), true, ApplyQueryType.BOTTOM_SHEET, R.xml.external_sensors_write_to_track_settings, R.layout.profile_preference_toolbar),
DANGEROUS_GOODS(DangerousGoodsFragment.class.getName(), true, ApplyQueryType.NONE, R.xml.dangerous_goods_parameters, R.layout.global_preference_toolbar),
EXTERNAL_INPUT_DEVICE(MainExternalInputDevicesFragment.class.getName(), true, ApplyQueryType.SNACK_BAR, R.xml.external_input_device_settings, R.layout.profile_preference_toolbar_with_switch);
SIMULATION_NAVIGATION(SimulationNavigationSettingFragment.class, true, ApplyQueryType.NONE, R.xml.simulation_navigation_setting, R.layout.profile_preference_toolbar_with_switch),
ANT_PLUS_SETTINGS(ExternalDevicesListFragment.class, false, null, R.xml.antplus_settings, R.layout.global_preference_toolbar),
VEHICLE_METRICS_SETTINGS(VehicleMetricsSettingsFragment.class, false, null, R.xml.antplus_settings, R.layout.global_preference_toolbar),
WEATHER_SETTINGS(WeatherSettingsFragment.class, true, ApplyQueryType.SNACK_BAR, R.xml.weather_settings, R.layout.profile_preference_toolbar),
EXTERNAL_SETTINGS_WRITE_TO_TRACK_SETTINGS(ExternalSettingsWriteToTrackSettingsFragment.class, true, ApplyQueryType.BOTTOM_SHEET, R.xml.external_sensors_write_to_track_settings, R.layout.profile_preference_toolbar),
DANGEROUS_GOODS(DangerousGoodsFragment.class, true, ApplyQueryType.NONE, R.xml.dangerous_goods_parameters, R.layout.global_preference_toolbar),
EXTERNAL_INPUT_DEVICE(MainExternalInputDevicesFragment.class, true, ApplyQueryType.SNACK_BAR, R.xml.external_input_device_settings, R.layout.profile_preference_toolbar_with_switch);

public final Class<? extends Fragment> fragmentClass;
public final String fragmentName;
public final boolean profileDependent;
public final ApplyQueryType applyQueryType;
public final int preferencesResId;
public final int toolbarResId;

SettingsScreenType(String fragmentName, boolean profileDependent, ApplyQueryType applyQueryType, int preferencesResId, int toolbarResId) {
this.fragmentName = fragmentName;
SettingsScreenType(Class<? extends Fragment> fragmentClass, boolean profileDependent, ApplyQueryType applyQueryType, int preferencesResId, int toolbarResId) {
this.fragmentClass = fragmentClass;
this.fragmentName = fragmentClass.getName();
this.profileDependent = profileDependent;
this.applyQueryType = applyQueryType;
this.preferencesResId = preferencesResId;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@

import java.util.Optional;

class PreferenceConnected2PreferenceFragmentProvider implements de.KnollFrank.lib.settingssearch.provider.PreferenceConnected2PreferenceFragmentProvider {
class PreferenceFragmentConnected2PreferenceProvider implements de.KnollFrank.lib.settingssearch.provider.PreferenceFragmentConnected2PreferenceProvider {

@Override
public Optional<String> getClassNameOfConnectedPreferenceFragment(final Preference preference, final PreferenceFragmentCompat hostOfPreference) {
public Optional<Class<? extends PreferenceFragmentCompat>> getPreferenceFragmentConnected2Preference(Preference preference, final PreferenceFragmentCompat hostOfPreference) {
return hostOfPreference instanceof final PreferenceFragmentHandlerProvider preferenceFragmentHandlerProvider ?
preferenceFragmentHandlerProvider
.getPreferenceFragmentHandler(preference)
.map(PreferenceFragmentHandler::getClassNameOfPreferenceFragment) :
.map(PreferenceFragmentHandler::getClassOfPreferenceFragment) :
Optional.empty();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

public interface PreferenceFragmentHandler {

String getClassNameOfPreferenceFragment();
Class<? extends PreferenceFragmentCompat> getClassOfPreferenceFragment();

PreferenceFragmentCompat createPreferenceFragment(Context context, final Fragment target);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public static SearchPreferenceFragments createSearchPreferenceFragments(
.withSearchResultsFragmentUI(new SearchResultsFragmentUI())
.withCreateSearchDatabaseTaskSupplier(createSearchDatabaseTaskSupplier)
.withFragmentFactory(new FragmentFactory())
.withPreferenceConnected2PreferenceFragmentProvider(new PreferenceConnected2PreferenceFragmentProvider())
.withPreferenceFragmentConnected2PreferenceProvider(new PreferenceFragmentConnected2PreferenceProvider())
.withPrepareShow(new PrepareShow())
.withSearchableInfoProvider(new SearchableInfoProvider())
.withPreferenceDialogAndSearchableInfoProvider(new PreferenceDialogAndSearchableInfoProvider())
Expand Down

0 comments on commit 068e29f

Please sign in to comment.