Merge pull request #10671 from osmandapp/fix_gpx_context_menu_overview_actions
Fix gpx context menu overview actions
This commit is contained in:
commit
53415e0e87
5 changed files with 201 additions and 179 deletions
|
@ -9,7 +9,7 @@
|
||||||
<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="@dimen/list_header_height"
|
||||||
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"
|
||||||
|
@ -48,55 +48,60 @@
|
||||||
|
|
||||||
<LinearLayout
|
<LinearLayout
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="@dimen/setting_list_item_small_height"
|
||||||
android:layout_marginStart="@dimen/content_padding"
|
android:layout_marginStart="@dimen/card_padding"
|
||||||
android:layout_marginLeft="@dimen/content_padding"
|
android:layout_marginLeft="@dimen/card_padding"
|
||||||
android:layout_marginTop="@dimen/content_padding_half"
|
android:layout_marginTop="@dimen/content_padding_half"
|
||||||
android:layout_marginEnd="@dimen/content_padding"
|
android:layout_marginEnd="@dimen/card_padding"
|
||||||
android:layout_marginRight="@dimen/content_padding"
|
android:layout_marginRight="@dimen/card_padding"
|
||||||
android:layout_marginBottom="@dimen/content_padding"
|
android:layout_marginBottom="@dimen/content_padding"
|
||||||
|
android:baselineAligned="false"
|
||||||
|
android:minHeight="@dimen/context_menu_controller_height"
|
||||||
android:orientation="horizontal"
|
android:orientation="horizontal"
|
||||||
android:weightSum="4">
|
android:weightSum="4">
|
||||||
<!-- todo stretch buttons correctly -->
|
|
||||||
|
|
||||||
<include
|
<include
|
||||||
android:id="@+id/show_button"
|
android:id="@+id/show_button"
|
||||||
layout="@layout/item_gpx_action"
|
layout="@layout/item_gpx_action"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="0dp"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="match_parent"
|
||||||
|
android:layout_marginStart="@dimen/list_item_button_padding"
|
||||||
|
android:layout_marginLeft="@dimen/list_item_button_padding"
|
||||||
|
android:layout_marginEnd="@dimen/list_item_button_padding"
|
||||||
|
android:layout_marginRight="@dimen/list_item_button_padding"
|
||||||
android:layout_weight="1" />
|
android:layout_weight="1" />
|
||||||
|
|
||||||
<Space
|
|
||||||
android:layout_width="@dimen/content_padding_half"
|
|
||||||
android:layout_height="match_parent" />
|
|
||||||
|
|
||||||
<include
|
<include
|
||||||
android:id="@+id/appearance_button"
|
android:id="@+id/appearance_button"
|
||||||
layout="@layout/item_gpx_action"
|
layout="@layout/item_gpx_action"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="0dp"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="match_parent"
|
||||||
|
android:layout_marginStart="@dimen/list_item_button_padding"
|
||||||
|
android:layout_marginLeft="@dimen/list_item_button_padding"
|
||||||
|
android:layout_marginEnd="@dimen/list_item_button_padding"
|
||||||
|
android:layout_marginRight="@dimen/list_item_button_padding"
|
||||||
android:layout_weight="1" />
|
android:layout_weight="1" />
|
||||||
|
|
||||||
<Space
|
|
||||||
android:layout_width="@dimen/content_padding_half"
|
|
||||||
android:layout_height="match_parent" />
|
|
||||||
|
|
||||||
<include
|
<include
|
||||||
android:id="@+id/edit_button"
|
android:id="@+id/edit_button"
|
||||||
layout="@layout/item_gpx_action"
|
layout="@layout/item_gpx_action"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="0dp"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="match_parent"
|
||||||
|
android:layout_marginStart="@dimen/list_item_button_padding"
|
||||||
|
android:layout_marginLeft="@dimen/list_item_button_padding"
|
||||||
|
android:layout_marginEnd="@dimen/list_item_button_padding"
|
||||||
|
android:layout_marginRight="@dimen/list_item_button_padding"
|
||||||
android:layout_weight="1" />
|
android:layout_weight="1" />
|
||||||
|
|
||||||
<Space
|
|
||||||
android:layout_width="@dimen/content_padding_half"
|
|
||||||
android:layout_height="match_parent" />
|
|
||||||
|
|
||||||
<include
|
<include
|
||||||
android:id="@+id/directions_button"
|
android:id="@+id/directions_button"
|
||||||
layout="@layout/item_gpx_action"
|
layout="@layout/item_gpx_action"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="0dp"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="match_parent"
|
||||||
|
android:layout_marginStart="@dimen/list_item_button_padding"
|
||||||
|
android:layout_marginLeft="@dimen/list_item_button_padding"
|
||||||
|
android:layout_marginEnd="@dimen/list_item_button_padding"
|
||||||
|
android:layout_marginRight="@dimen/list_item_button_padding"
|
||||||
android:layout_weight="1" />
|
android:layout_weight="1" />
|
||||||
|
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
|
|
@ -1,13 +1,15 @@
|
||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
xmlns:tools="http://schemas.android.com/tools"
|
xmlns:tools="http://schemas.android.com/tools"
|
||||||
android:layout_width="wrap_content"
|
android:minHeight="@dimen/context_menu_controller_height"
|
||||||
android:layout_height="wrap_content">
|
android:minWidth="@dimen/context_menu_top_right_button_min_width"
|
||||||
|
android:layout_width="@dimen/fab_recycler_view_padding_bottom"
|
||||||
|
android:layout_height="@dimen/setting_list_item_small_height">
|
||||||
|
|
||||||
<androidx.appcompat.widget.AppCompatImageView
|
<androidx.appcompat.widget.AppCompatImageView
|
||||||
android:id="@+id/filled"
|
android:id="@+id/filled"
|
||||||
android:layout_width="@dimen/fab_recycler_view_padding_bottom"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="@dimen/setting_list_item_small_height"
|
android:layout_height="match_parent"
|
||||||
tools:alpha="0.1"
|
tools:alpha="0.1"
|
||||||
tools:srcCompat="@drawable/bg_topbar_shield_exit_ref" />
|
tools:srcCompat="@drawable/bg_topbar_shield_exit_ref" />
|
||||||
|
|
||||||
|
|
|
@ -3,42 +3,62 @@
|
||||||
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="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="@dimen/list_header_height"
|
||||||
android:orientation="vertical">
|
android:layout_marginStart="@dimen/content_padding"
|
||||||
|
android:layout_marginLeft="@dimen/content_padding"
|
||||||
|
android:gravity="center_vertical"
|
||||||
|
android:orientation="horizontal">
|
||||||
|
|
||||||
<LinearLayout
|
<LinearLayout
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="match_parent"
|
||||||
android:orientation="horizontal">
|
android:layout_marginEnd="@dimen/content_padding"
|
||||||
|
android:layout_marginRight="@dimen/content_padding"
|
||||||
|
android:orientation="vertical">
|
||||||
|
|
||||||
<net.osmand.plus.widgets.TextViewEx
|
<LinearLayout
|
||||||
android:id="@+id/value"
|
android:layout_width="wrap_content"
|
||||||
android:layout_width="match_parent"
|
android:layout_height="wrap_content"
|
||||||
|
android:orientation="horizontal">
|
||||||
|
|
||||||
|
<net.osmand.plus.widgets.TextViewEx
|
||||||
|
android:id="@+id/value"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:background="@null"
|
||||||
|
android:textColor="?android:attr/textColorPrimary"
|
||||||
|
android:textSize="@dimen/default_desc_text_size"
|
||||||
|
osmand:typeface="@string/font_roboto_medium"
|
||||||
|
tools:text="700 km" />
|
||||||
|
|
||||||
|
<androidx.appcompat.widget.AppCompatImageView
|
||||||
|
android:id="@+id/image"
|
||||||
|
android:layout_width="@dimen/context_menu_transport_icon_size"
|
||||||
|
android:layout_height="@dimen/context_menu_transport_icon_size"
|
||||||
|
android:layout_gravity="center_vertical"
|
||||||
|
android:layout_marginStart="@dimen/context_menu_first_line_top_margin"
|
||||||
|
android:layout_marginLeft="@dimen/context_menu_first_line_top_margin"
|
||||||
|
tools:src="@drawable/ic_action_track_16" />
|
||||||
|
|
||||||
|
</LinearLayout>
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/title"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:background="@null"
|
android:background="@null"
|
||||||
android:textColor="?android:attr/textColorPrimary"
|
android:textColor="?android:attr/textColorSecondary"
|
||||||
android:textSize="@dimen/default_desc_text_size"
|
android:textSize="@dimen/default_desc_text_size"
|
||||||
osmand:typeface="@string/font_roboto_medium"
|
tools:text="@string/distance" />
|
||||||
tools:text="700 km" />
|
|
||||||
|
|
||||||
<androidx.appcompat.widget.AppCompatImageView
|
|
||||||
android:id="@+id/image"
|
|
||||||
android:layout_width="@dimen/context_menu_transport_icon_size"
|
|
||||||
android:layout_height="@dimen/context_menu_transport_icon_size"
|
|
||||||
android:layout_gravity="center_vertical"
|
|
||||||
android:layout_marginStart="@dimen/context_menu_first_line_top_margin"
|
|
||||||
android:layout_marginLeft="@dimen/context_menu_first_line_top_margin"
|
|
||||||
tools:src="@drawable/ic_action_track_16" />
|
|
||||||
|
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
|
||||||
<TextView
|
<View
|
||||||
android:id="@+id/title"
|
android:id="@+id/divider"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="1dp"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="match_parent"
|
||||||
android:background="@null"
|
android:layout_marginTop="@dimen/map_small_button_margin"
|
||||||
android:textColor="?android:attr/textColorSecondary"
|
android:layout_marginBottom="@dimen/map_small_button_margin"
|
||||||
android:textSize="@dimen/default_desc_text_size"
|
tools:background="@color/divider_color_light" />
|
||||||
tools:text="@string/distance" />
|
|
||||||
|
|
||||||
</LinearLayout>
|
</LinearLayout>
|
|
@ -1,10 +1,6 @@
|
||||||
package net.osmand.plus.track;
|
package net.osmand.plus.track;
|
||||||
|
|
||||||
import android.annotation.SuppressLint;
|
import android.annotation.SuppressLint;
|
||||||
import android.content.Context;
|
|
||||||
import android.content.res.TypedArray;
|
|
||||||
import android.graphics.Canvas;
|
|
||||||
import android.graphics.Rect;
|
|
||||||
import android.graphics.drawable.Drawable;
|
import android.graphics.drawable.Drawable;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
import android.view.MotionEvent;
|
import android.view.MotionEvent;
|
||||||
|
@ -17,11 +13,10 @@ import androidx.annotation.ColorRes;
|
||||||
import androidx.annotation.DrawableRes;
|
import androidx.annotation.DrawableRes;
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
import androidx.appcompat.widget.AppCompatImageView;
|
import androidx.appcompat.widget.AppCompatImageView;
|
||||||
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 androidx.recyclerview.widget.RecyclerView.ItemDecoration;
|
|
||||||
|
|
||||||
|
import net.osmand.AndroidUtils;
|
||||||
import net.osmand.GPXUtilities.GPXFile;
|
import net.osmand.GPXUtilities.GPXFile;
|
||||||
import net.osmand.GPXUtilities.GPXTrackAnalysis;
|
import net.osmand.GPXUtilities.GPXTrackAnalysis;
|
||||||
import net.osmand.plus.GpxSelectionHelper.GpxDisplayGroup;
|
import net.osmand.plus.GpxSelectionHelper.GpxDisplayGroup;
|
||||||
|
@ -29,6 +24,7 @@ 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.OsmAndFormatter;
|
||||||
import net.osmand.plus.R;
|
import net.osmand.plus.R;
|
||||||
|
import net.osmand.plus.UiUtilities;
|
||||||
import net.osmand.plus.activities.MapActivity;
|
import net.osmand.plus.activities.MapActivity;
|
||||||
import net.osmand.plus.helpers.AndroidUiHelper;
|
import net.osmand.plus.helpers.AndroidUiHelper;
|
||||||
import net.osmand.plus.helpers.GpxUiHelper.GPXDataSetType;
|
import net.osmand.plus.helpers.GpxUiHelper.GPXDataSetType;
|
||||||
|
@ -38,7 +34,6 @@ import net.osmand.plus.widgets.TextViewEx;
|
||||||
import net.osmand.util.Algorithms;
|
import net.osmand.util.Algorithms;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
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;
|
||||||
|
@ -46,6 +41,7 @@ import static net.osmand.plus.track.OptionsCard.APPEARANCE_BUTTON_INDEX;
|
||||||
import static net.osmand.plus.track.OptionsCard.DIRECTIONS_BUTTON_INDEX;
|
import static net.osmand.plus.track.OptionsCard.DIRECTIONS_BUTTON_INDEX;
|
||||||
import static net.osmand.plus.track.OptionsCard.EDIT_BUTTON_INDEX;
|
import static net.osmand.plus.track.OptionsCard.EDIT_BUTTON_INDEX;
|
||||||
import static net.osmand.plus.track.OptionsCard.SHOW_ON_MAP_BUTTON_INDEX;
|
import static net.osmand.plus.track.OptionsCard.SHOW_ON_MAP_BUTTON_INDEX;
|
||||||
|
import static net.osmand.plus.track.OverviewCard.StatBlock.ItemType.*;
|
||||||
|
|
||||||
public class OverviewCard extends BaseCard {
|
public class OverviewCard extends BaseCard {
|
||||||
|
|
||||||
|
@ -57,15 +53,22 @@ public class OverviewCard extends BaseCard {
|
||||||
|
|
||||||
private final TrackDisplayHelper displayHelper;
|
private final TrackDisplayHelper displayHelper;
|
||||||
private final GPXFile gpxFile;
|
private final GPXFile gpxFile;
|
||||||
private final GpxDisplayItemType[] filterTypes = new GpxDisplayItemType[] {GpxDisplayItemType.TRACK_SEGMENT};
|
private final GpxDisplayItemType[] filterTypes = {GpxDisplayItemType.TRACK_SEGMENT};
|
||||||
private final SegmentActionsListener listener;
|
private final SegmentActionsListener listener;
|
||||||
|
private boolean gpxFileSelected;
|
||||||
|
private GpxDisplayItem gpxItem;
|
||||||
|
|
||||||
public OverviewCard(@NonNull MapActivity mapActivity, @NonNull TrackDisplayHelper displayHelper,
|
public OverviewCard(@NonNull MapActivity mapActivity, @NonNull TrackDisplayHelper displayHelper,
|
||||||
@NonNull SegmentActionsListener listener) {
|
@NonNull SegmentActionsListener listener) {
|
||||||
super(mapActivity);
|
super(mapActivity);
|
||||||
this.displayHelper = displayHelper;
|
this.displayHelper = displayHelper;
|
||||||
this.gpxFile = displayHelper.getGpx();
|
|
||||||
this.listener = listener;
|
this.listener = listener;
|
||||||
|
gpxFile = displayHelper.getGpx();
|
||||||
|
gpxFileSelected = isGpxFileSelected(app, gpxFile);
|
||||||
|
List<GpxDisplayGroup> groups = displayHelper.getOriginalGroups(filterTypes);
|
||||||
|
if (!Algorithms.isEmpty(groups)) {
|
||||||
|
gpxItem = TrackDisplayHelper.flatten(displayHelper.getOriginalGroups(filterTypes)).get(0);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -75,7 +78,7 @@ public class OverviewCard extends BaseCard {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void updateContent() {
|
protected void updateContent() {
|
||||||
int iconColorDef = R.color.icon_color_active_light;
|
int iconColorDef = nightMode ? R.color.icon_color_active_dark : 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;
|
boolean fileAvailable = gpxFile.path != null && !gpxFile.showCurrentTrack;
|
||||||
|
|
||||||
|
@ -95,9 +98,7 @@ public class OverviewCard extends BaseCard {
|
||||||
}
|
}
|
||||||
|
|
||||||
void initStatBlocks() {
|
void initStatBlocks() {
|
||||||
List<GpxDisplayGroup> groups = displayHelper.getOriginalGroups(filterTypes);
|
if (gpxItem != null) {
|
||||||
if (!Algorithms.isEmpty(groups)) {
|
|
||||||
GpxDisplayItem gpxItem = TrackDisplayHelper.flatten(groups).get(0);
|
|
||||||
GPXTrackAnalysis analysis = gpxItem.analysis;
|
GPXTrackAnalysis analysis = gpxItem.analysis;
|
||||||
boolean joinSegments = displayHelper.isJoinSegments();
|
boolean joinSegments = displayHelper.isJoinSegments();
|
||||||
float totalDistance = !joinSegments && gpxItem.isGeneralTrack() ? analysis.totalDistanceWithoutGaps : analysis.totalDistance;
|
float totalDistance = !joinSegments && gpxItem.isGeneralTrack() ? analysis.totalDistanceWithoutGaps : analysis.totalDistance;
|
||||||
|
@ -106,95 +107,85 @@ public class OverviewCard extends BaseCard {
|
||||||
String desc = OsmAndFormatter.getFormattedAlt(analysis.diffElevationDown, app);
|
String desc = OsmAndFormatter.getFormattedAlt(analysis.diffElevationDown, app);
|
||||||
String avg = OsmAndFormatter.getFormattedSpeed(analysis.avgSpeed, app);
|
String avg = OsmAndFormatter.getFormattedSpeed(analysis.avgSpeed, app);
|
||||||
String max = OsmAndFormatter.getFormattedSpeed(analysis.maxSpeed, app);
|
String max = OsmAndFormatter.getFormattedSpeed(analysis.maxSpeed, app);
|
||||||
|
List<StatBlock> items = new ArrayList<>();
|
||||||
|
|
||||||
StatBlock sDistance = new StatBlock(app.getString(R.string.distance), OsmAndFormatter.getFormattedDistance(totalDistance, app),
|
StatBlock.prepareData(analysis, items, app.getString(R.string.distance), OsmAndFormatter.getFormattedDistance(totalDistance, app),
|
||||||
R.drawable.ic_action_track_16, R.color.icon_color_default_light, GPXDataSetType.ALTITUDE, GPXDataSetType.SPEED);
|
R.drawable.ic_action_track_16, R.color.icon_color_default_light, GPXDataSetType.ALTITUDE, GPXDataSetType.SPEED, ITEM_DISTANCE);
|
||||||
StatBlock sAscent = new StatBlock(app.getString(R.string.altitude_ascent), asc,
|
StatBlock.prepareData(analysis, items, app.getString(R.string.altitude_ascent), asc,
|
||||||
R.drawable.ic_action_arrow_up_16, R.color.gpx_chart_red, GPXDataSetType.SLOPE, null);
|
R.drawable.ic_action_arrow_up_16, R.color.gpx_chart_red, GPXDataSetType.SLOPE, null, ITEM_ALTITUDE);
|
||||||
StatBlock sDescent = new StatBlock(app.getString(R.string.altitude_descent), desc,
|
StatBlock.prepareData(analysis, items, app.getString(R.string.altitude_descent), desc,
|
||||||
R.drawable.ic_action_arrow_down_16, R.color.gpx_pale_green, GPXDataSetType.ALTITUDE, GPXDataSetType.SLOPE);
|
R.drawable.ic_action_arrow_down_16, R.color.gpx_pale_green, GPXDataSetType.ALTITUDE, GPXDataSetType.SLOPE, ITEM_ALTITUDE);
|
||||||
StatBlock sAvSpeed = new StatBlock(app.getString(R.string.average_speed), avg,
|
StatBlock.prepareData(analysis, items, app.getString(R.string.average_speed), avg,
|
||||||
R.drawable.ic_action_speed_16, R.color.icon_color_default_light, GPXDataSetType.SPEED, null);
|
R.drawable.ic_action_speed_16, R.color.icon_color_default_light, GPXDataSetType.SPEED, null, ITEM_SPEED);
|
||||||
StatBlock sMaxSpeed = new StatBlock(app.getString(R.string.max_speed), max,
|
StatBlock.prepareData(analysis, items, app.getString(R.string.max_speed), max,
|
||||||
R.drawable.ic_action_max_speed_16, R.color.icon_color_default_light, GPXDataSetType.SPEED, null);
|
R.drawable.ic_action_max_speed_16, R.color.icon_color_default_light, GPXDataSetType.SPEED, null, ITEM_SPEED);
|
||||||
StatBlock sTimeSpan = new StatBlock(app.getString(R.string.shared_string_time_span),
|
StatBlock.prepareData(analysis, items, app.getString(R.string.shared_string_time_span),
|
||||||
Algorithms.formatDuration((int) (timeSpan / 1000), app.accessibilityEnabled()),
|
Algorithms.formatDuration((int) (timeSpan / 1000), app.accessibilityEnabled()),
|
||||||
R.drawable.ic_action_time_span_16, R.color.icon_color_default_light, GPXDataSetType.SPEED, null);
|
R.drawable.ic_action_time_span_16, R.color.icon_color_default_light, GPXDataSetType.SPEED, null, ITEM_TIME);
|
||||||
|
|
||||||
LinearLayoutManager llManager = new LinearLayoutManager(app);
|
if (Algorithms.isEmpty(items)) {
|
||||||
llManager.setOrientation(LinearLayoutManager.HORIZONTAL);
|
AndroidUiHelper.updateVisibility(rvOverview, false);
|
||||||
rvOverview.setLayoutManager(llManager);
|
} else {
|
||||||
rvOverview.setItemAnimator(new DefaultItemAnimator());
|
final StatBlockAdapter sbAdapter = new StatBlockAdapter(items);
|
||||||
List<StatBlock> items = Arrays.asList(sDistance, sAscent, sDescent, sAvSpeed, sMaxSpeed, sTimeSpan);
|
rvOverview.setLayoutManager(new LinearLayoutManager(app, LinearLayoutManager.HORIZONTAL, false));
|
||||||
final StatBlockAdapter siAdapter = new StatBlockAdapter(items);
|
rvOverview.setAdapter(sbAdapter);
|
||||||
rvOverview.setAdapter(siAdapter);
|
}
|
||||||
rvOverview.addItemDecoration(new HorizontalDividerDecoration(app));
|
|
||||||
} else {
|
} else {
|
||||||
AndroidUiHelper.updateVisibility(rvOverview, false);
|
AndroidUiHelper.updateVisibility(rvOverview, false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void initShowButton(final int iconColorDef, final int iconColorPres) {
|
@DrawableRes
|
||||||
final AppCompatImageView image = showButton.findViewById(R.id.image);
|
private int getActiveShowHideIcon() {
|
||||||
final AppCompatImageView filled = showButton.findViewById(R.id.filled);
|
gpxFileSelected = isGpxFileSelected(app, gpxFile);
|
||||||
final int iconShowResId = R.drawable.ic_action_view;
|
return gpxFileSelected ? R.drawable.ic_action_view : R.drawable.ic_action_hide;
|
||||||
final int iconHideResId = R.drawable.ic_action_hide;
|
|
||||||
final boolean[] gpxFileSelected = {isGpxFileSelected(app, gpxFile)};
|
|
||||||
filled.setImageResource(R.drawable.bg_topbar_shield_exit_ref);
|
|
||||||
filled.setAlpha(gpxFileSelected[0] ? 1f : 0.1f);
|
|
||||||
setImageDrawable(image, gpxFileSelected[0] ? iconShowResId : iconHideResId,
|
|
||||||
gpxFileSelected[0] ? iconColorPres : iconColorDef);
|
|
||||||
showButton.setOnClickListener(new View.OnClickListener() {
|
|
||||||
@Override
|
|
||||||
public void onClick(View v) {
|
|
||||||
gpxFileSelected[0] = !gpxFileSelected[0];
|
|
||||||
filled.setAlpha(gpxFileSelected[0] ? 1f : 0.1f);
|
|
||||||
setImageDrawable(image, gpxFileSelected[0] ? iconShowResId : iconHideResId,
|
|
||||||
gpxFileSelected[0] ? iconColorPres : iconColorDef);
|
|
||||||
CardListener listener = getListener();
|
|
||||||
if (listener != null) {
|
|
||||||
listener.onCardButtonPressed(OverviewCard.this, SHOW_ON_MAP_BUTTON_INDEX);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void initAppearanceButton(int iconColorDef, int iconColorPres) {
|
private void initShowButton(final int iconColorDef, final int iconColorPres) {
|
||||||
|
initButton(showButton, SHOW_ON_MAP_BUTTON_INDEX, getActiveShowHideIcon(), iconColorDef, iconColorPres);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void initAppearanceButton(@ColorRes int iconColorDef, @ColorRes int iconColorPres) {
|
||||||
initButton(appearanceButton, APPEARANCE_BUTTON_INDEX, R.drawable.ic_action_appearance, iconColorDef, iconColorPres);
|
initButton(appearanceButton, APPEARANCE_BUTTON_INDEX, R.drawable.ic_action_appearance, iconColorDef, iconColorPres);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void initEditButton(int iconColorDef, int iconColorPres) {
|
private void initEditButton(@ColorRes int iconColorDef, @ColorRes int iconColorPres) {
|
||||||
initButton(editButton, EDIT_BUTTON_INDEX, R.drawable.ic_action_edit_dark, iconColorDef, iconColorPres);
|
initButton(editButton, EDIT_BUTTON_INDEX, R.drawable.ic_action_edit_dark, iconColorDef, iconColorPres);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void initDirectionsButton(int iconColorDef, int iconColorPres) {
|
private void initDirectionsButton(@ColorRes int iconColorDef, @ColorRes int iconColorPres) {
|
||||||
initButton(directionsButton, DIRECTIONS_BUTTON_INDEX, R.drawable.ic_action_gdirections_dark, iconColorDef, iconColorPres);
|
initButton(directionsButton, DIRECTIONS_BUTTON_INDEX, R.drawable.ic_action_gdirections_dark, iconColorDef, iconColorPres);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void initButton(View item, final int buttonIndex, int iconResId, int iconColorDef, int iconColorPres) {
|
private void initButton(View item, final int buttonIndex, @DrawableRes Integer iconResId,
|
||||||
final AppCompatImageView image = item.findViewById(R.id.image);
|
@ColorRes final int iconColorDef, @ColorRes int iconColorPres) {
|
||||||
|
final AppCompatImageView icon = item.findViewById(R.id.image);
|
||||||
final AppCompatImageView filled = item.findViewById(R.id.filled);
|
final AppCompatImageView filled = item.findViewById(R.id.filled);
|
||||||
filled.setImageResource(R.drawable.bg_topbar_shield_exit_ref);
|
filled.setImageResource(nightMode ? R.drawable.bg_plugin_logo_enabled_dark : R.drawable.bg_topbar_shield_exit_ref);
|
||||||
filled.setAlpha(0.1f);
|
filled.setAlpha(0.1f);
|
||||||
setImageDrawable(image, iconResId, iconColorDef);
|
setImageDrawable(icon, iconResId, iconColorDef);
|
||||||
setOnTouchItem(item, image, filled, iconResId, iconColorDef, iconColorPres);
|
setOnTouchItem(item, icon, filled, iconResId, iconColorDef, iconColorPres);
|
||||||
item.setOnClickListener(new View.OnClickListener() {
|
item.setOnClickListener(new View.OnClickListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onClick(View v) {
|
public void onClick(View v) {
|
||||||
CardListener listener = getListener();
|
CardListener listener = getListener();
|
||||||
if (listener != null) {
|
if (listener != null) {
|
||||||
listener.onCardButtonPressed(OverviewCard.this, buttonIndex);
|
listener.onCardButtonPressed(OverviewCard.this, buttonIndex);
|
||||||
|
if (buttonIndex == SHOW_ON_MAP_BUTTON_INDEX) {
|
||||||
|
setImageDrawable(icon, getActiveShowHideIcon(), iconColorDef);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setImageDrawable(ImageView iv, @DrawableRes int resId, @ColorRes int color) {
|
private void setImageDrawable(ImageView iv, @DrawableRes Integer resId, @ColorRes int color) {
|
||||||
Drawable icon = app.getUIUtilities().getIcon(resId, color);
|
Drawable icon = resId != null ? app.getUIUtilities().getIcon(resId, color)
|
||||||
|
: UiUtilities.tintDrawable(iv.getDrawable(), getResolvedColor(color));
|
||||||
iv.setImageDrawable(icon);
|
iv.setImageDrawable(icon);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setOnTouchItem(View item, final ImageView image, final ImageView filled, @DrawableRes final int resId, @ColorRes final int colorDef, @ColorRes final int colorPres) {
|
private void setOnTouchItem(View item, final ImageView image, final ImageView filled, @DrawableRes final Integer resId, @ColorRes final int colorDef, @ColorRes final int colorPres) {
|
||||||
item.setOnTouchListener(new View.OnTouchListener() {
|
item.setOnTouchListener(new View.OnTouchListener() {
|
||||||
@SuppressLint("ClickableViewAccessibility")
|
@SuppressLint("ClickableViewAccessibility")
|
||||||
@Override
|
@Override
|
||||||
|
@ -241,26 +232,24 @@ public class OverviewCard extends BaseCard {
|
||||||
@Override
|
@Override
|
||||||
public void onBindViewHolder(StatBlockViewHolder holder, int position) {
|
public void onBindViewHolder(StatBlockViewHolder holder, int position) {
|
||||||
final StatBlock item = statBlocks.get(position);
|
final StatBlock item = statBlocks.get(position);
|
||||||
|
|
||||||
holder.valueText.setText(item.value);
|
holder.valueText.setText(item.value);
|
||||||
holder.titleText.setText(item.title);
|
holder.titleText.setText(item.title);
|
||||||
holder.valueText.setTextColor(app.getResources().getColor(R.color.active_color_primary_light));
|
holder.valueText.setTextColor(getActiveColor());
|
||||||
holder.titleText.setTextColor(app.getResources().getColor(R.color.text_color_secondary_light));
|
holder.titleText.setTextColor(app.getResources().getColor(R.color.text_color_secondary_light));
|
||||||
holder.itemView.setOnClickListener(new View.OnClickListener() {
|
holder.itemView.setOnClickListener(new View.OnClickListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onClick(View v) {
|
public void onClick(View v) {
|
||||||
GpxDisplayItem gpxItem = TrackDisplayHelper.flatten(displayHelper.getOriginalGroups(filterTypes)).get(0);
|
|
||||||
if (gpxItem != null && gpxItem.analysis != null) {
|
if (gpxItem != null && gpxItem.analysis != null) {
|
||||||
ArrayList<GPXDataSetType> list = new ArrayList<>();
|
ArrayList<GPXDataSetType> list = new ArrayList<>();
|
||||||
if (item.firstType != null) {
|
if (gpxItem.analysis.hasElevationData || gpxItem.analysis.isSpeedSpecified() || gpxItem.analysis.hasSpeedData) {
|
||||||
list.add(item.firstType);
|
if (item.firstType != null) {
|
||||||
}
|
list.add(item.firstType);
|
||||||
if (item.secondType != null) {
|
}
|
||||||
list.add(item.secondType);
|
if (item.secondType != null) {
|
||||||
}
|
list.add(item.secondType);
|
||||||
if (list.size() > 0) {
|
}
|
||||||
gpxItem.chartTypes = list.toArray(new GPXDataSetType[0]);
|
|
||||||
}
|
}
|
||||||
|
gpxItem.chartTypes = list.size() > 0 ? list.toArray(new GPXDataSetType[0]) : null;
|
||||||
gpxItem.locationOnMap = gpxItem.locationStart;
|
gpxItem.locationOnMap = gpxItem.locationStart;
|
||||||
|
|
||||||
listener.openAnalyzeOnMap(gpxItem);
|
listener.openAnalyzeOnMap(gpxItem);
|
||||||
|
@ -268,6 +257,8 @@ public class OverviewCard extends BaseCard {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
setImageDrawable(holder.imageView, item.imageResId, item.imageColorId);
|
setImageDrawable(holder.imageView, item.imageResId, item.imageColorId);
|
||||||
|
AndroidUtils.setBackgroundColor(view.getContext(), holder.divider, nightMode, R.color.divider_color_light, R.color.divider_color_dark);
|
||||||
|
AndroidUiHelper.updateVisibility(holder.divider, position != statBlocks.size() - 1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -276,55 +267,18 @@ public class OverviewCard extends BaseCard {
|
||||||
private final TextViewEx valueText;
|
private final TextViewEx valueText;
|
||||||
private final TextView titleText;
|
private final TextView titleText;
|
||||||
private final AppCompatImageView imageView;
|
private final AppCompatImageView imageView;
|
||||||
|
private final View divider;
|
||||||
|
|
||||||
StatBlockViewHolder(View view) {
|
StatBlockViewHolder(View view) {
|
||||||
super(view);
|
super(view);
|
||||||
valueText = view.findViewById(R.id.value);
|
valueText = view.findViewById(R.id.value);
|
||||||
titleText = view.findViewById(R.id.title);
|
titleText = view.findViewById(R.id.title);
|
||||||
imageView = view.findViewById(R.id.image);
|
imageView = view.findViewById(R.id.image);
|
||||||
|
divider = view.findViewById(R.id.divider);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static class HorizontalDividerDecoration extends ItemDecoration {
|
protected static class StatBlock {
|
||||||
|
|
||||||
private final Drawable divider;
|
|
||||||
private final int marginV;
|
|
||||||
private final int marginH;
|
|
||||||
|
|
||||||
public HorizontalDividerDecoration(Context context) {
|
|
||||||
int[] ATTRS = new int[] {android.R.attr.listDivider};
|
|
||||||
final TypedArray ta = context.obtainStyledAttributes(ATTRS);
|
|
||||||
divider = ta.getDrawable(0);
|
|
||||||
// DrawableCompat.setTint(divider, context.getResources().getColor(R.color.divider_color_light)); //todo change drawable color
|
|
||||||
ta.recycle();
|
|
||||||
marginV = context.getResources().getDimensionPixelSize(R.dimen.map_small_button_margin);
|
|
||||||
marginH = context.getResources().getDimensionPixelSize(R.dimen.content_padding);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onDraw(@NonNull Canvas c, @NonNull RecyclerView parent, @NonNull RecyclerView.State state) {
|
|
||||||
drawHorizontal(c, parent);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void drawHorizontal(Canvas c, RecyclerView parent) {
|
|
||||||
for (int i = 0; i < parent.getChildCount(); i++) {
|
|
||||||
final View child = parent.getChildAt(i);
|
|
||||||
final int left = child.getRight() - divider.getIntrinsicWidth() + marginH;
|
|
||||||
final int right = left + divider.getIntrinsicHeight();
|
|
||||||
final int top = child.getTop() + marginV;
|
|
||||||
final int bottom = child.getBottom() - marginV;
|
|
||||||
divider.setBounds(left, top, right, bottom);
|
|
||||||
divider.draw(c);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void getItemOffsets(Rect outRect, @NonNull View view, @NonNull RecyclerView parent, @NonNull RecyclerView.State state) {
|
|
||||||
outRect.set(marginH - divider.getIntrinsicWidth(), marginV, marginH + divider.getIntrinsicWidth(), marginV);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static class StatBlock {
|
|
||||||
|
|
||||||
private final String title;
|
private final String title;
|
||||||
private final String value;
|
private final String value;
|
||||||
|
@ -332,15 +286,56 @@ public class OverviewCard extends BaseCard {
|
||||||
private final int imageColorId;
|
private final int imageColorId;
|
||||||
private final GPXDataSetType firstType;
|
private final GPXDataSetType firstType;
|
||||||
private final GPXDataSetType secondType;
|
private final GPXDataSetType secondType;
|
||||||
|
private final ItemType itemType;
|
||||||
|
|
||||||
public StatBlock(String title, String value, @DrawableRes int imageResId, @ColorRes int imageColorId,
|
public StatBlock(String title, String value, @DrawableRes int imageResId, @ColorRes int imageColorId,
|
||||||
GPXDataSetType firstType, GPXDataSetType secondType) {
|
GPXDataSetType firstType, GPXDataSetType secondType, ItemType itemType) {
|
||||||
this.title = title;
|
this.title = title;
|
||||||
this.value = value;
|
this.value = value;
|
||||||
this.imageResId = imageResId;
|
this.imageResId = imageResId;
|
||||||
this.imageColorId = imageColorId;
|
this.imageColorId = imageColorId;
|
||||||
this.firstType = firstType;
|
this.firstType = firstType;
|
||||||
this.secondType = secondType;
|
this.secondType = secondType;
|
||||||
|
this.itemType = itemType;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void prepareData(GPXTrackAnalysis analysis, List<StatBlock> listItems, String title,
|
||||||
|
String value, @DrawableRes int imageResId, @ColorRes int imageColorId,
|
||||||
|
GPXDataSetType firstType, GPXDataSetType secondType, ItemType itemType) {
|
||||||
|
StatBlock statBlock = new StatBlock(title, value, imageResId, imageColorId, firstType, secondType, itemType);
|
||||||
|
switch (statBlock.itemType) {
|
||||||
|
case ITEM_DISTANCE: {
|
||||||
|
if (analysis.totalDistance != 0f) {
|
||||||
|
listItems.add(statBlock);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case ITEM_ALTITUDE: {
|
||||||
|
if (analysis.hasElevationData) {
|
||||||
|
listItems.add(statBlock);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case ITEM_SPEED: {
|
||||||
|
if (analysis.isSpeedSpecified()) {
|
||||||
|
listItems.add(statBlock);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case ITEM_TIME: {
|
||||||
|
if (analysis.hasSpeedData) {
|
||||||
|
listItems.add(statBlock);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public enum ItemType {
|
||||||
|
ITEM_DISTANCE,
|
||||||
|
ITEM_ALTITUDE,
|
||||||
|
ITEM_SPEED,
|
||||||
|
ITEM_TIME;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -21,4 +21,4 @@
|
||||||
# UPDATE 3: Turn on D8 to recover builds with new gradle 6.5 and pluigin 4.1.1
|
# UPDATE 3: Turn on D8 to recover builds with new gradle 6.5 and pluigin 4.1.1
|
||||||
#android.enableD8=false
|
#android.enableD8=false
|
||||||
android.enableJetifier=true
|
android.enableJetifier=true
|
||||||
android.useAndroidX=true
|
android.useAndroidX=true
|
Loading…
Reference in a new issue