Skip to content

Commit

Permalink
Revert "refactoring ProfileAppearanceFragment"
Browse files Browse the repository at this point in the history
This reverts commit f3a89d4.
  • Loading branch information
KnollFrank committed Dec 18, 2024
1 parent a887b18 commit db7bf4d
Show file tree
Hide file tree
Showing 6 changed files with 63 additions and 63 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,13 @@
import androidx.annotation.NonNull;
import androidx.fragment.app.FragmentManager;

import net.osmand.plus.OsmandApplication;
import net.osmand.plus.base.bottomsheetmenu.BaseBottomSheetItem;
import net.osmand.plus.base.bottomsheetmenu.BottomSheetItemWithCompoundButton;
import net.osmand.plus.base.bottomsheetmenu.BottomSheetItemWithCompoundButton.Builder;
import net.osmand.plus.base.bottomsheetmenu.simpleitems.DividerItem;
import net.osmand.plus.base.bottomsheetmenu.simpleitems.LongDescriptionItem;
import net.osmand.plus.base.bottomsheetmenu.simpleitems.TitleItem;
import net.osmand.plus.base.dialog.data.DisplayItem;
import net.osmand.plus.settings.fragments.search.SearchablePreferenceDialog;
import net.osmand.plus.utils.UiUtilities;

import java.util.List;
Expand All @@ -30,7 +28,7 @@
* When choosing one of the options, the selected option is passed to the controller
* and dialog automatically closed without the need for confirmation by the user.
*/
public class CustomizableSingleSelectionBottomSheet extends CustomizableBottomSheet implements SearchablePreferenceDialog {
public class CustomizableSingleSelectionBottomSheet extends CustomizableBottomSheet {

public static final String TAG = CustomizableSingleSelectionBottomSheet.class.getSimpleName();

Expand Down Expand Up @@ -90,24 +88,25 @@ protected boolean hideButtonsContainer() {
return show == null || !show;
}

public static boolean showInstance(@NonNull FragmentManager fragmentManager,
@NonNull String processId, boolean usedOnMap) {
return createInstance(processId, usedOnMap).show(fragmentManager);
}

public static @NonNull CustomizableSingleSelectionBottomSheet createInstance(final @NonNull String processId, final boolean usedOnMap) {
final CustomizableSingleSelectionBottomSheet fragment = new CustomizableSingleSelectionBottomSheet();
fragment.setProcessId(processId);
fragment.setUsedOnMap(usedOnMap);
return fragment;
}

@Override
public void show(final FragmentManager fragmentManager, final OsmandApplication app) {
show(fragmentManager, TAG);
}

@Override
public String getSearchableInfo() {
return CustomizableSingleSelectionBottomSheetSearchableInfoProvider.getSearchableInfo(
getTitle(),
getDescription(),
getDisplayItems());
public boolean show(@NonNull final FragmentManager fragmentManager) {
try {
show(fragmentManager, TAG);
return true;
} catch (final RuntimeException e) {
return false;
}
}

private String getTitle() {
Expand All @@ -121,4 +120,11 @@ private String getDescription() {
private List<DisplayItem> getDisplayItems() {
return displayData.getDisplayItems();
}

public String getSearchableInfo() {
return CustomizableSingleSelectionBottomSheetSearchableInfoProvider.getSearchableInfo(
getTitle(),
getDescription(),
getDisplayItems());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@ public CompassModeWidgetDialogController(OsmandApplication app) {
super(app, app.getSettings().getApplicationMode());
}

@NonNull
@Override
@NonNull @Override
public String getProcessId() {
return PROCESS_ID;
}
Expand All @@ -41,8 +40,6 @@ public static void showDialog(@NonNull MapActivity mapActivity) {
dialogManager.register(PROCESS_ID, controller);

FragmentManager manager = mapActivity.getSupportFragmentManager();
CustomizableSingleSelectionBottomSheet
.createInstance(PROCESS_ID, true)
.show(manager, app);
CustomizableSingleSelectionBottomSheet.showInstance(manager, PROCESS_ID, true);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
import net.osmand.plus.base.dialog.DialogManager;
import net.osmand.plus.base.dialog.data.DisplayData;
import net.osmand.plus.base.dialog.data.DisplayItem;
import net.osmand.plus.base.dialog.interfaces.controller.IDialogItemSelected;
import net.osmand.plus.base.dialog.interfaces.controller.IDisplayDataProvider;
import net.osmand.plus.base.dialog.interfaces.controller.IDialogItemSelected;
import net.osmand.plus.settings.backend.ApplicationMode;
import net.osmand.plus.settings.backend.OsmandSettings;
import net.osmand.plus.settings.bottomsheets.CustomizableSingleSelectionBottomSheet;
Expand Down Expand Up @@ -97,8 +97,6 @@ public static void showDialog(@NonNull MapActivity mapActivity, @NonNull Applica
dialogManager.register(PROCESS_ID, controller);

FragmentManager manager = mapActivity.getSupportFragmentManager();
CustomizableSingleSelectionBottomSheet
.createInstance(PROCESS_ID, true)
.show(manager, app);
CustomizableSingleSelectionBottomSheet.showInstance(manager, PROCESS_ID, true);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -866,9 +866,7 @@ protected void showSingleSelectionDialog(@NonNull String processId,
DialogManager dialogManager = app.getDialogManager();
dialogManager.register(processId, controller);
FragmentManager fm = activity.getSupportFragmentManager();
CustomizableSingleSelectionBottomSheet
.createInstance(processId, false)
.show(fm, app);
CustomizableSingleSelectionBottomSheet.showInstance(fm, processId, false);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,10 @@
import net.osmand.plus.card.icon.IconsPaletteCard;
import net.osmand.plus.helpers.AndroidUiHelper;
import net.osmand.plus.routepreparationmenu.cards.BaseCard;
import net.osmand.plus.settings.bottomsheets.CustomizableSingleSelectionBottomSheet;
import net.osmand.plus.settings.fragments.BaseSettingsFragment;
import net.osmand.plus.settings.fragments.SettingsScreenType;
import net.osmand.plus.settings.fragments.search.SearchablePreferenceDialog;
import net.osmand.plus.settings.fragments.search.ShowableSearchablePreferenceDialog;
import net.osmand.plus.settings.fragments.search.ShowableSearchablePreferenceDialogProvider;
import net.osmand.plus.settings.fragments.search.SearchablePreferenceDialogProvider;
import net.osmand.plus.utils.AndroidUtils;
import net.osmand.plus.utils.ColorUtilities;
import net.osmand.plus.utils.UiUtilities;
Expand All @@ -55,7 +54,9 @@

import java.util.Optional;

public class ProfileAppearanceFragment extends BaseSettingsFragment implements IProfileAppearanceScreen, ShowableSearchablePreferenceDialogProvider {
import de.KnollFrank.lib.settingssearch.provider.PreferenceDialogAndSearchableInfoByPreferenceDialogProvider;

public class ProfileAppearanceFragment extends BaseSettingsFragment implements IProfileAppearanceScreen, SearchablePreferenceDialogProvider {

private static final Log LOG = PlatformUtil.getLog(ProfileAppearanceFragment.class);

Expand Down Expand Up @@ -229,45 +230,48 @@ public void afterTextChanged(Editable s) {
}

@Override
public Optional<ShowableSearchablePreferenceDialog<?>> getShowableSearchablePreferenceDialog(final Preference preference, final Fragment target) {
public boolean onPreferenceClick(Preference preference) {
MapActivity mapActivity = getMapActivity();
if (mapActivity != null) {
this
.createPreferenceDialog(preference)
.ifPresent(dialog -> dialog.show(mapActivity.getSupportFragmentManager()));
}
return super.onPreferenceClick(preference);
}

@Override
public Optional<PreferenceDialogAndSearchableInfoByPreferenceDialogProvider<?>> getPreferenceDialogAndSearchableInfoByPreferenceDialogProvider(final Preference preference) {
return this
.createPreferenceDialog(preference)
.map(preferenceDialog ->
new PreferenceDialogAndSearchableInfoByPreferenceDialogProvider<>(
preferenceDialog,
CustomizableSingleSelectionBottomSheet::getSearchableInfo));
}

private Optional<CustomizableSingleSelectionBottomSheet> createPreferenceDialog(final Preference preference) {
if (settings.VIEW_ANGLE_VISIBILITY.getId().equals(preference.getKey())) {
return Optional.of(
new ShowableSearchablePreferenceDialog<>(
screenController
.getProfileOptionController()
.createDialog(
app.getString(R.string.view_angle),
app.getString(R.string.view_angle_description),
settings.VIEW_ANGLE_VISIBILITY)) {
@Override
protected void show(final SearchablePreferenceDialog searchablePreferenceDialog) {
ProfileAppearanceFragment.this.show(searchablePreferenceDialog);
}
});
screenController
.getProfileOptionController()
.createDialog(
app.getString(R.string.view_angle),
app.getString(R.string.view_angle_description),
settings.VIEW_ANGLE_VISIBILITY));
}
if (settings.LOCATION_RADIUS_VISIBILITY.getId().equals(preference.getKey())) {
return Optional.of(
new ShowableSearchablePreferenceDialog<>(
screenController
.getProfileOptionController()
.createDialog(
app.getString(R.string.location_radius),
app.getString(R.string.location_radius_description),
settings.LOCATION_RADIUS_VISIBILITY)) {

@Override
protected void show(final SearchablePreferenceDialog searchablePreferenceDialog) {
ProfileAppearanceFragment.this.show(searchablePreferenceDialog);
}
});
screenController
.getProfileOptionController()
.createDialog(
app.getString(R.string.location_radius),
app.getString(R.string.location_radius_description),
settings.LOCATION_RADIUS_VISIBILITY));
}
return Optional.empty();
}

private void show(final SearchablePreferenceDialog searchablePreferenceDialog) {
searchablePreferenceDialog.show(getMapActivity().getSupportFragmentManager(), app);
}

private void bindCard(@NonNull PreferenceViewHolder holder, @NonNull BaseCard card) {
ViewGroup container = (ViewGroup) holder.itemView;
container.removeAllViews();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,6 @@ public static Iterable<Object[]> data() {

{"SendAnalyticsBottomSheetDialogFragment: description", R.string.make_osmand_better_descr},

{"ProfileAppearanceFragment: view_angle_description", R.string.view_angle_description},
{"ProfileAppearanceFragment: location_radius_description", R.string.location_radius_description},

// FK-TODO: enable development plugin for these two test cases
// {"LocationInterpolationBottomSheet: title", R.string.location_interpolation_percent},
// {"LocationInterpolationBottomSheet: description", R.string.location_interpolation_percent_desc}
Expand Down

0 comments on commit db7bf4d

Please sign in to comment.