amend track menu layout;

add init for action segments;
Taping on any stat block should open "Analyze on map";
This commit is contained in:
Skalii 2021-01-21 05:10:08 +02:00
parent 5d6101f23a
commit fdbf7a0f4b
5 changed files with 102 additions and 43 deletions

View file

@ -1,16 +1,15 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:osmand="http://schemas.android.com/apk/res-auto" xmlns:osmand="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools" xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="wrap_content"
android:orientation="vertical"> android:orientation="vertical">
<androidx.recyclerview.widget.RecyclerView <androidx.recyclerview.widget.RecyclerView
android:id="@+id/recycler_overview" android:id="@+id/recycler_overview"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginTop="@dimen/content_padding_small"
android:layout_marginBottom="@dimen/content_padding_small_half" android:layout_marginBottom="@dimen/content_padding_small_half"
android:clipToPadding="false" android:clipToPadding="false"
android:orientation="horizontal" android:orientation="horizontal"

View file

@ -7,8 +7,8 @@
<androidx.appcompat.widget.AppCompatImageView <androidx.appcompat.widget.AppCompatImageView
android:id="@+id/filled" android:id="@+id/filled"
android:layout_width="@dimen/context_menu_top_right_button_min_width" android:layout_width="@dimen/fab_recycler_view_padding_bottom"
android:layout_height="@dimen/context_menu_controller_height" android:layout_height="@dimen/setting_list_item_small_height"
tools:alpha="0.1" tools:alpha="0.1"
tools:srcCompat="@drawable/bg_topbar_shield_exit_ref" /> tools:srcCompat="@drawable/bg_topbar_shield_exit_ref" />

View file

@ -43,12 +43,13 @@
android:paddingStart="@dimen/context_menu_padding_margin_default" android:paddingStart="@dimen/context_menu_padding_margin_default"
android:paddingLeft="@dimen/context_menu_padding_margin_default" android:paddingLeft="@dimen/context_menu_padding_margin_default"
android:paddingEnd="@dimen/context_menu_padding_margin_default" android:paddingEnd="@dimen/context_menu_padding_margin_default"
android:paddingRight="@dimen/context_menu_padding_margin_default"> android:paddingRight="@dimen/context_menu_padding_margin_default"
android:paddingBottom="@dimen/context_menu_direction_margin">
<LinearLayout <LinearLayout
android:layout_width="0dp" android:layout_width="0dp"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginTop="@dimen/context_menu_first_line_top_margin" android:layout_marginTop="@dimen/context_menu_second_line_top_margin"
android:layout_marginEnd="@dimen/context_menu_padding_margin_default" android:layout_marginEnd="@dimen/context_menu_padding_margin_default"
android:layout_marginRight="@dimen/context_menu_padding_margin_default" android:layout_marginRight="@dimen/context_menu_padding_margin_default"
android:layout_weight="1" android:layout_weight="1"
@ -71,7 +72,8 @@
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_gravity="center_vertical" android:layout_gravity="center_vertical"
tools:text="@string/amenity_type_finance" /> android:visibility="gone"
tools:text="@string/amenity_type_finance" />
</LinearLayout> </LinearLayout>
@ -79,7 +81,7 @@
android:id="@+id/icon_view" android:id="@+id/icon_view"
android:layout_width="@dimen/map_widget_icon" android:layout_width="@dimen/map_widget_icon"
android:layout_height="@dimen/map_widget_icon" android:layout_height="@dimen/map_widget_icon"
android:layout_marginTop="@dimen/context_menu_padding_margin_default" android:layout_marginTop="@dimen/context_menu_second_line_top_margin"
android:tint="?attr/default_icon_color" android:tint="?attr/default_icon_color"
osmand:srcCompat="@drawable/ic_action_polygom_dark" /> osmand:srcCompat="@drawable/ic_action_polygom_dark" />
@ -94,7 +96,6 @@
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:background="?attr/activity_background_basic" android:background="?attr/activity_background_basic"
android:foreground="@drawable/bg_contextmenu_shadow"
android:foregroundGravity="top|fill_horizontal"> android:foregroundGravity="top|fill_horizontal">
<net.osmand.plus.LockableScrollView <net.osmand.plus.LockableScrollView

View file

@ -274,6 +274,7 @@
<color name="gpx_chart_green_label">#197d2a</color> <color name="gpx_chart_green_label">#197d2a</color>
<color name="gpx_split_segment_icon_color">#b3b3b3</color> <color name="gpx_split_segment_icon_color">#b3b3b3</color>
<color name="gpx_pale_green">#87CC70</color>
<color name="map_background_color_light">#fafafa</color> <color name="map_background_color_light">#fafafa</color>
<color name="map_background_color_dark">#101821</color> <color name="map_background_color_dark">#101821</color>

View file

@ -21,18 +21,28 @@ import androidx.recyclerview.widget.DefaultItemAnimator;
import androidx.recyclerview.widget.LinearLayoutManager; import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView; import androidx.recyclerview.widget.RecyclerView;
import com.github.mikephil.charting.charts.LineChart;
import com.github.mikephil.charting.interfaces.datasets.ILineDataSet;
import net.osmand.GPXUtilities.GPXFile; import net.osmand.GPXUtilities.GPXFile;
import net.osmand.GPXUtilities.GPXTrackAnalysis;
import net.osmand.plus.GPXDatabase.GpxDataItem;
import net.osmand.plus.GpxSelectionHelper.GpxDisplayItem;
import net.osmand.plus.GpxSelectionHelper.GpxDisplayItemType; import net.osmand.plus.GpxSelectionHelper.GpxDisplayItemType;
import net.osmand.plus.OsmAndFormatter;
import net.osmand.plus.R; import net.osmand.plus.R;
import net.osmand.plus.UiUtilities.UpdateLocationViewCache; import net.osmand.plus.UiUtilities.UpdateLocationViewCache;
import net.osmand.plus.activities.MapActivity; import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.helpers.GpxUiHelper;
import net.osmand.plus.helpers.GpxUiHelper.LineGraphType;
import net.osmand.plus.mapcontextmenu.MapContextMenu; import net.osmand.plus.mapcontextmenu.MapContextMenu;
import net.osmand.plus.myplaces.SegmentActionsListener; import net.osmand.plus.myplaces.SegmentActionsListener;
import net.osmand.plus.myplaces.SegmentGPXAdapter; import net.osmand.plus.myplaces.SegmentGPXAdapter;
import net.osmand.plus.routepreparationmenu.cards.BaseCard; import net.osmand.plus.routepreparationmenu.cards.BaseCard;
import net.osmand.plus.widgets.TextViewEx; import net.osmand.plus.widgets.TextViewEx;
import net.osmand.util.Algorithms;
import java.util.ArrayList; import java.util.Arrays;
import java.util.List; import java.util.List;
import static net.osmand.plus.myplaces.TrackActivityFragmentAdapter.isGpxFileSelected; import static net.osmand.plus.myplaces.TrackActivityFragmentAdapter.isGpxFileSelected;
@ -54,7 +64,7 @@ public class OverviewCard extends BaseCard {
private TrackDisplayHelper displayHelper; private TrackDisplayHelper displayHelper;
private GPXFile gpxFile; private GPXFile gpxFile;
private GpxDisplayItemType[] filterTypes = new GpxDisplayItemType[] {GpxDisplayItemType.TRACK_SEGMENT}; private GpxDisplayItemType[] filterTypes = new GpxDisplayItemType[]{GpxDisplayItemType.TRACK_SEGMENT};
private SegmentGPXAdapter adapter; private SegmentGPXAdapter adapter;
private SegmentActionsListener listener; private SegmentActionsListener listener;
@ -78,13 +88,19 @@ public class OverviewCard extends BaseCard {
int iconColorDef = R.color.icon_color_active_light; int iconColorDef = R.color.icon_color_active_light;
int iconColorPres = R.color.active_buttons_and_links_text_dark; int iconColorPres = R.color.active_buttons_and_links_text_dark;
boolean fileAvailable = gpxFile.path != null && !gpxFile.showCurrentTrack;
showButton = view.findViewById(R.id.show_button); showButton = view.findViewById(R.id.show_button);
appearanceButton = view.findViewById(R.id.appearance_button); appearanceButton = view.findViewById(R.id.appearance_button);
editButton = view.findViewById(R.id.edit_button); editButton = view.findViewById(R.id.edit_button);
directionsButton = view.findViewById(R.id.directions_button); directionsButton = view.findViewById(R.id.directions_button);
rvOverview = view.findViewById(R.id.recycler_overview);
boolean fileAvailable = gpxFile.path != null && !gpxFile.showCurrentTrack; menu = mapActivity.getContextMenu();
distanceText = (TextView) view.findViewById(R.id.distance);
direction = (ImageView) view.findViewById(R.id.direction);
UpdateLocationViewCache updateLocationViewCache = app.getUIUtilities().getUpdateLocationViewCache();
app.getUIUtilities().updateLocationView(updateLocationViewCache, direction, distanceText, menu.getLatLon());
initShowButton(iconColorDef, iconColorPres); initShowButton(iconColorDef, iconColorPres);
initAppearanceButton(iconColorDef, iconColorPres); initAppearanceButton(iconColorDef, iconColorPres);
@ -93,35 +109,37 @@ public class OverviewCard extends BaseCard {
initDirectionsButton(iconColorDef, iconColorPres); initDirectionsButton(iconColorDef, iconColorPres);
} }
menu = mapActivity.getContextMenu(); initSegments();
distanceText = (TextView) view.findViewById(R.id.distance); }
direction = (ImageView) view.findViewById(R.id.direction);
UpdateLocationViewCache updateLocationViewCache = app.getUIUtilities().getUpdateLocationViewCache();
app.getUIUtilities().updateLocationView(updateLocationViewCache, direction, distanceText, menu.getLatLon());
SegmentItem item1 = new SegmentItem("Distance", "700 km", R.drawable.ic_action_track_16); void initSegments() {
SegmentItem item2 = new SegmentItem("Ascent", "156 km", R.drawable.ic_action_arrow_up_16); GpxDisplayItem gpxItem = TrackDisplayHelper.flatten(displayHelper.getOriginalGroups(filterTypes)).get(0);
SegmentItem item3 = new SegmentItem("Descent", "338 km", R.drawable.ic_action_arrow_down_16); GPXTrackAnalysis analysis = gpxItem.analysis;
SegmentItem item4 = new SegmentItem("Average speed", "9.9 km/h", R.drawable.ic_action_speed_16); boolean joinSegments = displayHelper.isJoinSegments();
SegmentItem item5 = new SegmentItem("Max. speed", "12.7 km/h", R.drawable.ic_action_max_speed_16); float totalDistance = !joinSegments && gpxItem.isGeneralTrack() ? analysis.totalDistanceWithoutGaps : analysis.totalDistance;
SegmentItem item6 = new SegmentItem("Time span", "4:00:18", R.drawable.ic_action_time_span_16); float timeSpan = !joinSegments && gpxItem.isGeneralTrack() ? analysis.timeSpanWithoutGaps : analysis.timeSpan;
List<SegmentItem> items = new ArrayList<>(); String asc = OsmAndFormatter.getFormattedAlt(analysis.diffElevationUp, app);
items.add(item1); String desc = OsmAndFormatter.getFormattedAlt(analysis.diffElevationDown, app);
items.add(item2); String avg = OsmAndFormatter.getFormattedSpeed(analysis.avgSpeed, app);
items.add(item3); String max = OsmAndFormatter.getFormattedSpeed(analysis.maxSpeed, app);
items.add(item4);
items.add(item5); SegmentItem sDistance = new SegmentItem(app.getResources().getString(R.string.distance), OsmAndFormatter.getFormattedDistance(totalDistance, app),
items.add(item6); R.drawable.ic_action_track_16, R.color.icon_color_default_light, LineGraphType.ALTITUDE, LineGraphType.SPEED);
SegmentItem sAscent = new SegmentItem(app.getResources().getString(R.string.altitude_ascent), asc, R.drawable.ic_action_arrow_up_16, R.color.gpx_chart_red, LineGraphType.SLOPE, null);
SegmentItem sDescent = new SegmentItem(app.getResources().getString(R.string.altitude_descent), desc, R.drawable.ic_action_arrow_down_16, R.color.gpx_pale_green, LineGraphType.ALTITUDE, LineGraphType.SLOPE);
SegmentItem sAvSpeed = new SegmentItem(app.getResources().getString(R.string.average_speed), avg, R.drawable.ic_action_speed_16, R.color.icon_color_default_light, LineGraphType.SPEED, null);
SegmentItem sMaxSpeed = new SegmentItem(app.getResources().getString(R.string.max_speed), max, R.drawable.ic_action_max_speed_16, R.color.icon_color_default_light, LineGraphType.SPEED, null);
SegmentItem sTimeSpan = new SegmentItem(app.getResources().getString(R.string.shared_string_time_span), Algorithms.formatDuration((int) (timeSpan / 1000), app.accessibilityEnabled()),
R.drawable.ic_action_time_span_16, R.color.icon_color_default_light, LineGraphType.SPEED, null);
rvOverview = view.findViewById(R.id.recycler_overview);
LinearLayoutManager llManager = new LinearLayoutManager(app); LinearLayoutManager llManager = new LinearLayoutManager(app);
llManager.setOrientation(LinearLayoutManager.HORIZONTAL); llManager.setOrientation(LinearLayoutManager.HORIZONTAL);
rvOverview.setLayoutManager(llManager); rvOverview.setLayoutManager(llManager);
rvOverview.setItemAnimator(new DefaultItemAnimator()); rvOverview.setItemAnimator(new DefaultItemAnimator());
final SegmentItemAdapter oiAdapter = new SegmentItemAdapter(items); List<SegmentItem> items = Arrays.asList(sDistance, sAscent, sDescent, sAvSpeed, sMaxSpeed, sTimeSpan);
rvOverview.setAdapter(oiAdapter); final SegmentItemAdapter siAdapter = new SegmentItemAdapter(items);
rvOverview.setAdapter(siAdapter);
rvOverview.addItemDecoration(new HorizontalDividerDecoration(app)); rvOverview.addItemDecoration(new HorizontalDividerDecoration(app));
} }
private void initShowButton(final int iconColorDef, final int iconColorPres) { private void initShowButton(final int iconColorDef, final int iconColorPres) {
@ -138,12 +156,9 @@ public class OverviewCard extends BaseCard {
@Override @Override
public void onClick(View v) { public void onClick(View v) {
gpxFileSelected[0] = !gpxFileSelected[0]; gpxFileSelected[0] = !gpxFileSelected[0];
filled.setAlpha(gpxFileSelected[0] ? 1f : 0.1f);
setImageDrawable(image, gpxFileSelected[0] ? iconShowResId : iconHideResId, setImageDrawable(image, gpxFileSelected[0] ? iconShowResId : iconHideResId,
gpxFileSelected[0] ? iconColorPres : iconColorDef); gpxFileSelected[0] ? iconColorPres : iconColorDef);
filled.setAlpha(gpxFileSelected[0] ? 1f : 0.1f);
CardListener listener = getListener(); CardListener listener = getListener();
if (listener != null) { if (listener != null) {
listener.onCardButtonPressed(OverviewCard.this, SHOW_ON_MAP_BUTTON_INDEX); listener.onCardButtonPressed(OverviewCard.this, SHOW_ON_MAP_BUTTON_INDEX);
@ -236,7 +251,6 @@ public class OverviewCard extends BaseCard {
holder.bind(item); holder.bind(item);
} }
class SegmentItemViewHolder extends RecyclerView.ViewHolder { class SegmentItemViewHolder extends RecyclerView.ViewHolder {
private final TextViewEx valueText; private final TextViewEx valueText;
private final TextView titleText; private final TextView titleText;
@ -249,10 +263,23 @@ public class OverviewCard extends BaseCard {
imageView = view.findViewById(R.id.image); imageView = view.findViewById(R.id.image);
} }
public void bind(SegmentItem overviewItem) { public void bind(final SegmentItem overviewItem) {
valueText.setText(overviewItem.value); valueText.setText(overviewItem.value);
valueText.setTextColor(app.getResources().getColor(R.color.active_color_primary_light));
titleText.setText(overviewItem.title); titleText.setText(overviewItem.title);
setImageDrawable(imageView, overviewItem.imageResId, R.color.text_color_primary_light); //todo change color titleText.setTextColor(app.getResources().getColor(R.color.text_color_secondary_light));
setImageDrawable(imageView, overviewItem.imageResId, overviewItem.imageColorId);
itemView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
GpxDisplayItem gpxItem = TrackDisplayHelper.flatten(displayHelper.getOriginalGroups(filterTypes)).get(0);
GPXTrackAnalysis analysis = gpxItem.analysis;
GpxDataItem gpxDataItem = displayHelper.getGpxDataItem();
boolean calcWithoutGaps = gpxItem.isGeneralTrack() && gpxDataItem != null && !gpxDataItem.isJoinSegments();
List<ILineDataSet> dataSets = GpxUiHelper.getDataSets(new LineChart(app), app, analysis, overviewItem.firstType, overviewItem.secondType, calcWithoutGaps);
listener.openAnalyzeOnMap(gpxItem, dataSets, null);
}
});
} }
} }
} }
@ -300,11 +327,17 @@ public class OverviewCard extends BaseCard {
private String title; private String title;
private String value; private String value;
private int imageResId; private int imageResId;
private int imageColorId;
private LineGraphType firstType;
private LineGraphType secondType;
public SegmentItem(String title, String value, int imageResId) { public SegmentItem(String title, String value, @DrawableRes int imageResId, @ColorRes int imageColorId, LineGraphType firstType, LineGraphType secondType) {
this.title = title; this.title = title;
this.value = value; this.value = value;
this.imageResId = imageResId; this.imageResId = imageResId;
this.imageColorId = imageColorId;
this.firstType = firstType;
this.secondType = secondType;
} }
public String getTitle() { public String getTitle() {
@ -330,5 +363,30 @@ public class OverviewCard extends BaseCard {
public void setImageResId(int imageResId) { public void setImageResId(int imageResId) {
this.imageResId = imageResId; this.imageResId = imageResId;
} }
public int getImageColorId() {
return imageColorId;
}
public void setImageColorId(int imageColorId) {
this.imageColorId = imageColorId;
}
public LineGraphType getFirstType() {
return firstType;
}
public void setFirstType(LineGraphType firstType) {
this.firstType = firstType;
}
public LineGraphType getSecondType() {
return secondType;
}
public void getSecondType(LineGraphType secondType) {
this.secondType = secondType;
}
} }
} }