reduce connectivity

This commit is contained in:
nazar-kutz 2021-04-05 21:45:50 +03:00
parent 9fdfa1270b
commit d9bea4ecd4
5 changed files with 56 additions and 43 deletions

View file

@ -27,9 +27,8 @@ import net.osmand.plus.routepreparationmenu.cards.BaseCard;
import net.osmand.plus.routepreparationmenu.cards.BaseCard.CardListener; import net.osmand.plus.routepreparationmenu.cards.BaseCard.CardListener;
import net.osmand.plus.routing.RouteLineDrawInfo; import net.osmand.plus.routing.RouteLineDrawInfo;
import net.osmand.plus.settings.backend.ListStringPreference; import net.osmand.plus.settings.backend.ListStringPreference;
import net.osmand.plus.settings.fragments.RouteLineAppearanceFragment; import net.osmand.plus.settings.fragments.HeaderInfo;
import net.osmand.plus.settings.fragments.RouteLineAppearanceFragment.HeaderInfo; import net.osmand.plus.settings.fragments.HeaderUiAdapter;
import net.osmand.plus.settings.fragments.RouteLineAppearanceFragment.HeaderUiAdapter;
import net.osmand.plus.track.AppearanceViewHolder; import net.osmand.plus.track.AppearanceViewHolder;
import net.osmand.plus.track.ColorsCard; import net.osmand.plus.track.ColorsCard;
import net.osmand.plus.track.CustomColorBottomSheet.ColorPickerListener; import net.osmand.plus.track.CustomColorBottomSheet.ColorPickerListener;
@ -159,8 +158,8 @@ public class RouteLineColorCard extends BaseCard implements CardListener, ColorP
} }
private void changeMapTheme(DayNightMode mapTheme) { private void changeMapTheme(DayNightMode mapTheme) {
if (targetFragment instanceof RouteLineAppearanceFragment) { if (targetFragment instanceof OnMapThemeUpdateListener) {
((RouteLineAppearanceFragment) targetFragment).onMapThemeUpdated(mapTheme); ((OnMapThemeUpdateListener) targetFragment).onMapThemeUpdated(mapTheme);
} }
if (selectedMode == ColorMode.CUSTOM) { if (selectedMode == ColorMode.CUSTOM) {
Integer color = getRouteLineColor(); Integer color = getRouteLineColor();
@ -219,14 +218,14 @@ public class RouteLineColorCard extends BaseCard implements CardListener, ColorP
} }
private void updateColorItems() { private void updateColorItems() {
if (targetFragment instanceof RouteLineAppearanceFragment) { if (targetFragment instanceof OnSelectedColorChangeListener) {
((RouteLineAppearanceFragment) targetFragment).onSelectedColorChanged(); ((OnSelectedColorChangeListener) targetFragment).onSelectedColorChanged();
} }
updateColorName(); updateColorName();
} }
@Override @Override
public void onNeedHeaderUpdate() { public void onNeedUpdateHeader() {
updateColorName(); updateColorName();
} }
@ -239,7 +238,7 @@ public class RouteLineColorCard extends BaseCard implements CardListener, ColorP
int colorNameId = ColorDialogs.getColorName(getRouteLineColor()); int colorNameId = ColorDialogs.getColorName(getRouteLineColor());
colorName = app.getString(colorNameId); colorName = app.getString(colorNameId);
} }
headerUiAdapter.onHeaderUpdate(this, title, colorName); headerUiAdapter.onUpdateHeader(this, title, colorName);
} }
private void updateDescription() { private void updateDescription() {
@ -360,4 +359,12 @@ public class RouteLineColorCard extends BaseCard implements CardListener, ColorP
} }
} }
public interface OnSelectedColorChangeListener {
void onSelectedColorChanged();
}
public interface OnMapThemeUpdateListener {
void onMapThemeUpdated(@NonNull DayNightMode mapTheme);
}
} }

View file

@ -26,8 +26,8 @@ import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.helpers.AndroidUiHelper; import net.osmand.plus.helpers.AndroidUiHelper;
import net.osmand.plus.routepreparationmenu.cards.BaseCard; import net.osmand.plus.routepreparationmenu.cards.BaseCard;
import net.osmand.plus.routing.RouteLineDrawInfo; import net.osmand.plus.routing.RouteLineDrawInfo;
import net.osmand.plus.settings.fragments.RouteLineAppearanceFragment.HeaderInfo; import net.osmand.plus.settings.fragments.HeaderInfo;
import net.osmand.plus.settings.fragments.RouteLineAppearanceFragment.HeaderUiAdapter; import net.osmand.plus.settings.fragments.HeaderUiAdapter;
import net.osmand.plus.track.AppearanceViewHolder; import net.osmand.plus.track.AppearanceViewHolder;
import net.osmand.plus.track.TrackAppearanceFragment.OnNeedScrollListener; import net.osmand.plus.track.TrackAppearanceFragment.OnNeedScrollListener;
import net.osmand.util.Algorithms; import net.osmand.util.Algorithms;
@ -129,7 +129,7 @@ public class RouteLineWidthCard extends BaseCard implements HeaderInfo {
} }
@Override @Override
public void onNeedHeaderUpdate() { public void onNeedUpdateHeader() {
updateHeader(); updateHeader();
} }
@ -137,7 +137,7 @@ public class RouteLineWidthCard extends BaseCard implements HeaderInfo {
String title = app.getString(R.string.select_track_width); String title = app.getString(R.string.select_track_width);
String description = app.getString(selectedMode.titleId); String description = app.getString(selectedMode.titleId);
tvSelectedType.setText(description); tvSelectedType.setText(description);
headerUiAdapter.onHeaderUpdate(this, title, description); headerUiAdapter.onUpdateHeader(this, title, description);
} }
private void updateDescription() { private void updateDescription() {

View file

@ -0,0 +1,7 @@
package net.osmand.plus.settings.fragments;
public interface HeaderInfo {
void onNeedUpdateHeader();
}

View file

@ -0,0 +1,11 @@
package net.osmand.plus.settings.fragments;
import androidx.annotation.NonNull;
public interface HeaderUiAdapter {
void onUpdateHeader(@NonNull HeaderInfo headerInfo,
@NonNull String title,
@NonNull String description);
}

View file

@ -31,13 +31,17 @@ import net.osmand.plus.helpers.AndroidUiHelper;
import net.osmand.plus.helpers.enums.DayNightMode; import net.osmand.plus.helpers.enums.DayNightMode;
import net.osmand.plus.routing.RouteLineDrawInfo; import net.osmand.plus.routing.RouteLineDrawInfo;
import net.osmand.plus.routing.cards.RouteLineColorCard; import net.osmand.plus.routing.cards.RouteLineColorCard;
import net.osmand.plus.routing.cards.RouteLineColorCard.OnMapThemeUpdateListener;
import net.osmand.plus.routing.cards.RouteLineColorCard.OnSelectedColorChangeListener;
import net.osmand.plus.routing.cards.RouteLineWidthCard; import net.osmand.plus.routing.cards.RouteLineWidthCard;
import net.osmand.plus.track.CustomColorBottomSheet.ColorPickerListener; import net.osmand.plus.track.CustomColorBottomSheet.ColorPickerListener;
import net.osmand.plus.track.TrackAppearanceFragment.OnNeedScrollListener; import net.osmand.plus.track.TrackAppearanceFragment.OnNeedScrollListener;
import static net.osmand.util.Algorithms.objectEquals; import static net.osmand.util.Algorithms.objectEquals;
public class RouteLineAppearanceFragment extends ContextMenuScrollFragment implements ColorPickerListener { public class RouteLineAppearanceFragment extends ContextMenuScrollFragment
implements ColorPickerListener, OnMapThemeUpdateListener, OnSelectedColorChangeListener,
HeaderUiAdapter {
public static final String TAG = RouteLineAppearanceFragment.class.getName(); public static final String TAG = RouteLineAppearanceFragment.class.getName();
@ -172,31 +176,24 @@ public class RouteLineAppearanceFragment extends ContextMenuScrollFragment imple
ViewGroup cardsContainer = getCardsContainer(); ViewGroup cardsContainer = getCardsContainer();
cardsContainer.removeAllViews(); cardsContainer.removeAllViews();
colorCard = new RouteLineColorCard(mapActivity, this, routeLineDrawInfo, initMapTheme, selectedMapTheme, getHeaderUiAdapter()); colorCard = new RouteLineColorCard(mapActivity, this, routeLineDrawInfo, initMapTheme, selectedMapTheme, this);
cardsContainer.addView(colorCard.build(mapActivity)); cardsContainer.addView(colorCard.build(mapActivity));
widthCard = new RouteLineWidthCard(mapActivity, routeLineDrawInfo, createScrollListener(), getHeaderUiAdapter()); widthCard = new RouteLineWidthCard(mapActivity, routeLineDrawInfo, createScrollListener(), this);
cardsContainer.addView(widthCard.build(mapActivity)); cardsContainer.addView(widthCard.build(mapActivity));
} }
private HeaderUiAdapter getHeaderUiAdapter() { @Override
if (headerUiAdapter == null) { public void onUpdateHeader(@NonNull HeaderInfo headerInfo,
headerUiAdapter = new HeaderUiAdapter() { @NonNull String title,
@Override @NonNull String description) {
public void onHeaderUpdate(@NonNull HeaderInfo headerInfo, if (selectedHeader == null) {
@NonNull String title, selectedHeader = headerInfo;
@NonNull String description) { }
if (selectedHeader == null) { if (objectEquals(selectedHeader, headerInfo)) {
selectedHeader = headerInfo; headerTitle.setText(title);
} headerDescr.setText(description);
if (objectEquals(selectedHeader, headerInfo)) {
headerTitle.setText(title);
headerDescr.setText(description);
}
}
};
} }
return headerUiAdapter;
} }
private OnNeedScrollListener createScrollListener() { private OnNeedScrollListener createScrollListener() {
@ -319,7 +316,7 @@ public class RouteLineAppearanceFragment extends ContextMenuScrollFragment imple
} else { } else {
selectedHeader = colorCard; selectedHeader = colorCard;
} }
selectedHeader.onNeedHeaderUpdate(); selectedHeader.onNeedUpdateHeader();
} }
private void initVisibleRect() { private void initVisibleRect() {
@ -473,13 +470,4 @@ public class RouteLineAppearanceFragment extends ContextMenuScrollFragment imple
void applyRouteLineAppearance(@NonNull RouteLineDrawInfo routeLineDrawInfo); void applyRouteLineAppearance(@NonNull RouteLineDrawInfo routeLineDrawInfo);
} }
public interface HeaderUiAdapter {
void onHeaderUpdate(@NonNull HeaderInfo headerInfo,
@NonNull String title,
@NonNull String description);
}
public interface HeaderInfo {
void onNeedHeaderUpdate();
}
} }