Skip to content

Commit

Permalink
UI review fix
Browse files Browse the repository at this point in the history
  • Loading branch information
0xRe1nk0 committed Mar 3, 2025
1 parent b0696f7 commit f241e75
Show file tree
Hide file tree
Showing 11 changed files with 175 additions and 95 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.widgets.popup.PopUpMenu;
import net.osmand.plus.widgets.popup.PopUpMenuDisplayData;
import net.osmand.plus.widgets.popup.PopUpMenuDisplayData.CustomDropDown;
import net.osmand.plus.widgets.popup.PopUpMenuItem;

import java.util.ArrayList;
Expand All @@ -24,6 +25,9 @@ public abstract class BaseMultiStateCardController implements IMultiStateCardCon
protected List<CardState> states;
protected CardState selectedState;

protected CustomDropDown customDropDownSelectorPopup;
protected Boolean limitHeightSelectorPopup;

public BaseMultiStateCardController(@NonNull OsmandApplication app) {
this.app = app;
}
Expand All @@ -49,6 +53,12 @@ public void onSelectorButtonClicked(@NonNull View view) {
}
}
PopUpMenuDisplayData data = new PopUpMenuDisplayData();
if (customDropDownSelectorPopup != null) {
data.customDropDown = customDropDownSelectorPopup;
}
if (limitHeightSelectorPopup != null) {
data.limitHeight = limitHeightSelectorPopup;
}
data.anchorView = view;
data.menuItems = items;
data.nightMode = nightMode;
Expand All @@ -74,6 +84,14 @@ protected CardState findCardState(@Nullable Object tag) {
return states.get(0);
}

public void setCustomDropDownSelectorPopup(@NonNull CustomDropDown customDropDownSelectorPopup) {
this.customDropDownSelectorPopup = customDropDownSelectorPopup;
}

public void setLimitHeightSelectorPopup(@Nullable Boolean limitHeightSelectorPopup) {
this.limitHeightSelectorPopup = limitHeightSelectorPopup;
}

protected boolean isCardStateAvailable(@NonNull CardState cardState) {
return true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import net.osmand.plus.myplaces.favorites.FavoriteGroup;
import net.osmand.plus.routepreparationmenu.cards.BaseCard;
import net.osmand.plus.routepreparationmenu.cards.BaseCard.CardListener;
import net.osmand.plus.widgets.popup.PopUpMenuDisplayData.CustomDropDown;
import net.osmand.shared.routing.ColoringType;

public class FavoriteAppearanceController implements IDialogController, IColorCardControllerListener, CardListener, OnIconsPaletteListener<String> {
Expand Down Expand Up @@ -61,6 +62,8 @@ public FavoriteAppearanceController(@NonNull OsmandApplication app, @NonNull Fav
}
editorIconController.init();
editorIconController.setIconsPaletteListener(this);
editorIconController.getCardController().setCustomDropDownSelectorPopup(CustomDropDown.TOP_DROPDOWN);
editorIconController.getCardController().setLimitHeightSelectorPopup(true);

shapesCardController = new FavoriteShapesCardController(app, this, selectedBackgroundType != null ? selectedBackgroundType : null);
}
Expand Down
12 changes: 0 additions & 12 deletions OsmAnd/src/net/osmand/plus/helpers/IntentHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -527,18 +527,6 @@ public void parseContentIntent() {
}
clearIntent(intent);
}
if (intent.hasExtra(EditFavoriteGroupDialogFragment.GROUP_NAME_KEY)) {
String groupName = intent.getStringExtra(EditFavoriteGroupDialogFragment.GROUP_NAME_KEY);
FavoriteGroup favoriteGroup = app.getFavoritesHelper().getGroup(FavoriteGroup.convertDisplayNameToGroupIdName(app, groupName));

PointsGroup pointsGroup = favoriteGroup != null ? favoriteGroup.toPointsGroup(app) : null;
FragmentManager manager = mapActivity.getSupportFragmentManager();
if (pointsGroup != null) {
FavoriteAppearanceFragment.showInstance(manager, pointsGroup, true);
}

clearIntent(intent);
}
if (intent.hasExtra(BaseSettingsFragment.OPEN_CONFIG_ON_MAP)) {
switch (intent.getStringExtra(BaseSettingsFragment.OPEN_CONFIG_ON_MAP)) {
case BaseSettingsFragment.MAP_CONFIG:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,11 +102,9 @@ public int getSecondDividerHeight() {
return getResources().getDimensionPixelSize(R.dimen.horizontal_divider_height);
}

public static void showInstance(@NonNull FragmentManager manager, @Nullable Fragment target,
@NonNull String editorTag, int pointsSize) {
public static void showInstance(@NonNull FragmentManager manager, @Nullable Fragment target, int pointsSize) {
if (AndroidUtils.isFragmentCanBeAdded(manager, TAG)) {
Bundle bundle = new Bundle();
bundle.putString(EDITOR_TAG_KEY, editorTag);
bundle.putInt(POINTS_SIZE_KEY, pointsSize);

DefaultFavoriteAppearanceSaveBottomSheet fragment = new DefaultFavoriteAppearanceSaveBottomSheet();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,30 @@
import static net.osmand.plus.configmap.tracks.appearance.favorite.FavoriteAppearanceController.PROCESS_ID;
import static net.osmand.shared.gpx.GpxUtilities.DEFAULT_ICON_NAME;

import android.app.Activity;
import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;

import androidx.annotation.ColorInt;
import androidx.annotation.ColorRes;
import androidx.annotation.DrawableRes;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.widget.Toolbar;
import androidx.core.view.ViewCompat;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentActivity;
import androidx.fragment.app.FragmentManager;

import net.osmand.data.BackgroundType;
import net.osmand.plus.R;
import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.base.BaseOsmAndFragment;
import net.osmand.plus.base.BaseOsmAndDialogFragment;
import net.osmand.plus.base.dialog.DialogManager;
import net.osmand.plus.card.base.multistate.IMultiStateCardController;
import net.osmand.plus.card.base.multistate.MultiStateCard;
Expand All @@ -32,15 +38,16 @@
import net.osmand.plus.myplaces.favorites.FavoriteGroup;
import net.osmand.plus.myplaces.favorites.FavouritesHelper;
import net.osmand.plus.myplaces.favorites.FavouritesHelper.SaveOption;
import net.osmand.plus.myplaces.favorites.dialogs.FavoritesTreeFragment;
import net.osmand.plus.render.RenderingIcons;
import net.osmand.plus.utils.AndroidUtils;
import net.osmand.plus.utils.ColorUtilities;
import net.osmand.plus.utils.UiUtilities;
import net.osmand.plus.widgets.dialogbutton.DialogButton;
import net.osmand.plus.widgets.dialogbutton.DialogButtonType;
import net.osmand.shared.gpx.GpxUtilities.PointsGroup;
import net.osmand.util.Algorithms;

public class FavoriteAppearanceFragment extends BaseOsmAndFragment {
public class FavoriteAppearanceFragment extends BaseOsmAndDialogFragment {

public static final String TAG = FavoriteAppearanceFragment.class.getName();

Expand All @@ -57,8 +64,6 @@ public class FavoriteAppearanceFragment extends BaseOsmAndFragment {
private String iconName = DEFAULT_ICON_NAME;
private BackgroundType backgroundType = DEFAULT_BACKGROUND_TYPE;

private boolean launchPrevIntent;

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Expand All @@ -78,6 +83,34 @@ public void onCreate(Bundle savedInstanceState) {
registerFavoriteAppearanceController();
}

@ColorRes
public int getStatusBarColorId() {
AndroidUiHelper.setStatusBarContentColor(getView(), nightMode);
return ColorUtilities.getStatusBarColorId(nightMode);
}

@NonNull
@Override
public Dialog onCreateDialog(@Nullable Bundle savedInstanceState) {
updateNightMode();
Activity activity = requireActivity();
int themeId = nightMode ? R.style.OsmandDarkTheme_DarkActionbar : R.style.OsmandLightTheme_DarkActionbar_LightStatusBar;
Dialog dialog = new Dialog(activity, themeId) {
@Override
public void onBackPressed() {
dismiss();
}
};
Window window = dialog.getWindow();
if (window != null) {
if (!settings.DO_NOT_USE_ANIMATIONS.get()) {
window.getAttributes().windowAnimations = R.style.Animations_Alpha;
}
window.setStatusBarColor(ColorUtilities.getColor(app, getStatusBarColorId()));
}
return dialog;
}

private void registerFavoriteAppearanceController() {
dialogManager.register(PROCESS_ID, new FavoriteAppearanceController(app, favoriteGroup, new DefaultFavoriteListener() {
@Override
Expand Down Expand Up @@ -106,7 +139,6 @@ public BackgroundType getOriginalShape() {
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
updateNightMode();
view = themedInflater.inflate(R.layout.favorite_default_appearance_fragment, container, false);
AndroidUtils.addStatusBarPadding21v(requireMyActivity(), view);

setupToolbar();
setupButtons();
Expand Down Expand Up @@ -170,31 +202,6 @@ public void setBackgroundType(@NonNull BackgroundType backgroundType) {
this.backgroundType = backgroundType;
}

@Override
public int getStatusBarColorId() {
return ColorUtilities.getStatusBarColorId(nightMode);
}

@Nullable
protected PointEditor getEditor() {
return requireMapActivity().getContextMenu().getFavoritePointEditor();
}

public void dismiss() {
hideKeyboard();
FragmentActivity activity = getActivity();
if (activity != null) {
activity.getSupportFragmentManager().popBackStack();
}
}

protected void hideKeyboard() {
FragmentActivity activity = getActivity();
if (activity != null) {
AndroidUtils.hideSoftKeyboard(activity, activity.getCurrentFocus());
}
}

private void setupToolbar() {
View appbar = view.findViewById(R.id.appbar);
ViewCompat.setElevation(appbar, 5.0f);
Expand All @@ -219,12 +226,38 @@ protected void setupButtons() {
}

protected void savePressed() {
PointEditor editor = getEditor();
FragmentActivity activity = getActivity();
if (editor != null && activity != null) {
String tag = editor.getFragmentTag();
if (activity != null) {
FragmentManager manager = activity.getSupportFragmentManager();
DefaultFavoriteAppearanceSaveBottomSheet.showInstance(manager, this, tag, pointsGroup.getPoints().size());
DefaultFavoriteAppearanceSaveBottomSheet.showInstance(manager, this, pointsGroup.getPoints().size());
}
}

@Override
public void dismiss() {
boolean hasChanges = false;
if (favoriteGroup != null) {
if (controller.getColor() != null && controller.getColor() != color) {
hasChanges = true;
}
if (controller.getIcon() != null && !controller.getIcon().equals(iconName)) {
hasChanges = true;
}
if (controller.getShape() != null && controller.getShape() != backgroundType) {
hasChanges = true;
}
}

if (hasChanges) {
Context themedContext = UiUtilities.getThemedContext(requireActivity(), nightMode);
AlertDialog.Builder dismissDialog = new AlertDialog.Builder(themedContext);
dismissDialog.setTitle(getString(R.string.exit_without_saving));
dismissDialog.setMessage(getString(R.string.dismiss_changes_descr));
dismissDialog.setNegativeButton(R.string.shared_string_cancel, null);
dismissDialog.setPositiveButton(R.string.shared_string_exit, (dialog, which) -> super.dismiss());
dismissDialog.show();
} else {
super.dismiss();
}
}

Expand All @@ -250,16 +283,16 @@ public void editPointsGroup(@NonNull SaveOption saveOption) {
favouritesHelper.saveCurrentPointsIntoFile(true);
}
}

Fragment targetFragment = getTargetFragment();
if (targetFragment instanceof FavoritesTreeFragment treeFragment) {
treeFragment.reloadData();
}
dismiss();
}

@Override
public void onDestroy() {
MapActivity mapActivity = getMapActivity();
if (launchPrevIntent && mapActivity != null && !mapActivity.isChangingConfigurations()) {
mapActivity.launchPrevActivityIntent();
}

FragmentActivity activity = getActivity();
if (activity != null && !activity.isChangingConfigurations()) {
dialogManager.unregister(FavoriteAppearanceController.PROCESS_ID);
Expand All @@ -268,28 +301,14 @@ public void onDestroy() {
super.onDestroy();
}

@Nullable
protected MapActivity getMapActivity() {
return (MapActivity) getActivity();
}

@NonNull
protected MapActivity requireMapActivity() {
return (MapActivity) requireActivity();
}

public static void showInstance(@NonNull FragmentManager manager,
@NonNull PointsGroup pointsGroup,
boolean launchPrevIntent) {
@NonNull Fragment treeFragment) {
if (AndroidUtils.isFragmentCanBeAdded(manager, TAG)) {
FavoriteAppearanceFragment fragment = new FavoriteAppearanceFragment();
fragment.pointsGroup = pointsGroup;
fragment.launchPrevIntent = launchPrevIntent;
fragment.setRetainInstance(true);
manager.beginTransaction()
.add(R.id.fragmentContainer, fragment, TAG)
.addToBackStack(TAG)
.commitAllowingStateLoss();
fragment.setTargetFragment(treeFragment, 0);
fragment.show(manager, TAG);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,7 @@ public void onBindCardContent(@NonNull FragmentActivity activity, @NonNull ViewG
} else {
BackgroundType type = (BackgroundType) selectedState.getTag();
if (type != null) {
MapActivity mapActivity = (MapActivity) activity;
shapesCard = new ShapesCard(mapActivity, type, centralController.requireColor()){
shapesCard = new ShapesCard(activity, type, centralController.requireColor()){

@Override
protected Drawable getOutlineDrawable(@DrawableRes int shapeIconId) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,23 +9,25 @@
import androidx.annotation.ColorInt;
import androidx.annotation.DrawableRes;
import androidx.annotation.NonNull;
import androidx.fragment.app.FragmentActivity;

import net.osmand.data.BackgroundType;
import net.osmand.plus.R;
import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.routepreparationmenu.cards.BaseCard;
import net.osmand.plus.routepreparationmenu.cards.MapBaseCard;
import net.osmand.plus.utils.ColorUtilities;
import net.osmand.plus.widgets.FlowLayout;

public class ShapesCard extends MapBaseCard {
public class ShapesCard extends BaseCard {

@NonNull
private BackgroundType selectedShape;
@ColorInt
protected int selectedColor;

public ShapesCard(@NonNull MapActivity mapActivity, @NonNull BackgroundType shape, @ColorInt int color) {
super(mapActivity);
public ShapesCard(@NonNull FragmentActivity fragmentActivity, @NonNull BackgroundType shape, @ColorInt int color) {
super(fragmentActivity);
this.selectedShape = shape;
this.selectedColor = color;
}
Expand Down
Loading

0 comments on commit f241e75

Please sign in to comment.