minor fixes
This commit is contained in:
parent
84c879e02d
commit
10ae234c30
1 changed files with 22 additions and 76 deletions
|
@ -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.graphics.Canvas;
|
|
||||||
import android.graphics.Rect;
|
|
||||||
import android.graphics.drawable.ColorDrawable;
|
|
||||||
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;
|
||||||
|
@ -16,16 +12,14 @@ import android.widget.TextView;
|
||||||
import androidx.annotation.ColorRes;
|
import androidx.annotation.ColorRes;
|
||||||
import androidx.annotation.DrawableRes;
|
import androidx.annotation.DrawableRes;
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
import androidx.annotation.Nullable;
|
|
||||||
import androidx.appcompat.widget.AppCompatImageView;
|
import androidx.appcompat.widget.AppCompatImageView;
|
||||||
import androidx.core.content.ContextCompat;
|
|
||||||
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.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.GpxDisplayItem;
|
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;
|
||||||
|
@ -71,7 +65,10 @@ public class OverviewCard extends BaseCard {
|
||||||
this.listener = listener;
|
this.listener = listener;
|
||||||
gpxFile = displayHelper.getGpx();
|
gpxFile = displayHelper.getGpx();
|
||||||
gpxFileSelected = isGpxFileSelected(app, gpxFile);
|
gpxFileSelected = isGpxFileSelected(app, gpxFile);
|
||||||
gpxItem = TrackDisplayHelper.flatten(displayHelper.getOriginalGroups(filterTypes)).get(0);
|
List<GpxDisplayGroup> groups = displayHelper.getOriginalGroups(filterTypes);
|
||||||
|
if (!Algorithms.isEmpty(groups)) {
|
||||||
|
gpxItem = TrackDisplayHelper.flatten(displayHelper.getOriginalGroups(filterTypes)).get(0);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -101,8 +98,8 @@ public class OverviewCard extends BaseCard {
|
||||||
}
|
}
|
||||||
|
|
||||||
void initStatBlocks() {
|
void initStatBlocks() {
|
||||||
GPXTrackAnalysis analysis = gpxItem.analysis;
|
if (gpxItem != null) {
|
||||||
if (analysis != null) {
|
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;
|
||||||
float timeSpan = !joinSegments && gpxItem.isGeneralTrack() ? analysis.timeSpanWithoutGaps : analysis.timeSpan;
|
float timeSpan = !joinSegments && gpxItem.isGeneralTrack() ? analysis.timeSpanWithoutGaps : analysis.timeSpan;
|
||||||
|
@ -128,47 +125,39 @@ public class OverviewCard extends BaseCard {
|
||||||
|
|
||||||
final StatBlockAdapter sbAdapter = new StatBlockAdapter(items);
|
final StatBlockAdapter sbAdapter = new StatBlockAdapter(items);
|
||||||
rvOverview.setLayoutManager(new LinearLayoutManager(app, LinearLayoutManager.HORIZONTAL, false));
|
rvOverview.setLayoutManager(new LinearLayoutManager(app, LinearLayoutManager.HORIZONTAL, false));
|
||||||
// rvOverview.addItemDecoration(new HorizontalDividerDecoration(app, nightMode));
|
|
||||||
rvOverview.setAdapter(sbAdapter);
|
rvOverview.setAdapter(sbAdapter);
|
||||||
} else {
|
|
||||||
AndroidUiHelper.updateVisibility(rvOverview, false);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@DrawableRes
|
||||||
|
private int getActiveShowHideIcon() {
|
||||||
|
gpxFileSelected = isGpxFileSelected(app, gpxFile);
|
||||||
|
return gpxFileSelected ? R.drawable.ic_action_view : R.drawable.ic_action_hide;
|
||||||
|
}
|
||||||
|
|
||||||
private void initShowButton(final int iconColorDef, final int iconColorPres) {
|
private void initShowButton(final int iconColorDef, final int iconColorPres) {
|
||||||
initButton(showButton, SHOW_ON_MAP_BUTTON_INDEX, null, iconColorDef, iconColorPres, new StatBlockCallback() {
|
initButton(showButton, SHOW_ON_MAP_BUTTON_INDEX, getActiveShowHideIcon(), iconColorDef, iconColorPres);
|
||||||
@Override
|
|
||||||
public void run(AppCompatImageView image) {
|
|
||||||
gpxFileSelected = isGpxFileSelected(app, gpxFile);
|
|
||||||
setImageDrawable(image, gpxFileSelected ? R.drawable.ic_action_view : R.drawable.ic_action_hide, iconColorDef);
|
|
||||||
image.requestLayout();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void initAppearanceButton(@ColorRes int iconColorDef, @ColorRes int iconColorPres) {
|
private void initAppearanceButton(@ColorRes int iconColorDef, @ColorRes int iconColorPres) {
|
||||||
initButton(appearanceButton, APPEARANCE_BUTTON_INDEX, R.drawable.ic_action_appearance, iconColorDef, iconColorPres, null);
|
initButton(appearanceButton, APPEARANCE_BUTTON_INDEX, R.drawable.ic_action_appearance, iconColorDef, iconColorPres);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void initEditButton(@ColorRes int iconColorDef, @ColorRes int iconColorPres) {
|
private void initEditButton(@ColorRes int iconColorDef, @ColorRes int iconColorPres) {
|
||||||
initButton(editButton, EDIT_BUTTON_INDEX, R.drawable.ic_action_edit_dark, iconColorDef, iconColorPres, null);
|
initButton(editButton, EDIT_BUTTON_INDEX, R.drawable.ic_action_edit_dark, iconColorDef, iconColorPres);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void initDirectionsButton(@ColorRes int iconColorDef, @ColorRes int iconColorPres) {
|
private void initDirectionsButton(@ColorRes int iconColorDef, @ColorRes int iconColorPres) {
|
||||||
initButton(directionsButton, DIRECTIONS_BUTTON_INDEX, R.drawable.ic_action_gdirections_dark, iconColorDef, iconColorPres, null);
|
initButton(directionsButton, DIRECTIONS_BUTTON_INDEX, R.drawable.ic_action_gdirections_dark, iconColorDef, iconColorPres);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void initButton(View item, final int buttonIndex, @DrawableRes Integer iconResId,
|
private void initButton(View item, final int buttonIndex, @DrawableRes Integer iconResId,
|
||||||
@ColorRes int iconColorDef, @ColorRes int iconColorPres, @Nullable final StatBlockCallback callback) {
|
@ColorRes final int iconColorDef, @ColorRes int iconColorPres) {
|
||||||
final AppCompatImageView icon = item.findViewById(R.id.image);
|
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(nightMode ? R.drawable.bg_plugin_logo_enabled_dark : 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);
|
||||||
if (callback != null) {
|
setImageDrawable(icon, iconResId, iconColorDef);
|
||||||
callback.run(icon);
|
|
||||||
} else {
|
|
||||||
setImageDrawable(icon, iconResId, iconColorDef);
|
|
||||||
}
|
|
||||||
setOnTouchItem(item, icon, filled, iconResId, iconColorDef, iconColorPres);
|
setOnTouchItem(item, icon, filled, iconResId, iconColorDef, iconColorPres);
|
||||||
item.setOnClickListener(new View.OnClickListener() {
|
item.setOnClickListener(new View.OnClickListener() {
|
||||||
@Override
|
@Override
|
||||||
|
@ -176,8 +165,8 @@ public class OverviewCard extends BaseCard {
|
||||||
CardListener listener = getListener();
|
CardListener listener = getListener();
|
||||||
if (listener != null) {
|
if (listener != null) {
|
||||||
listener.onCardButtonPressed(OverviewCard.this, buttonIndex);
|
listener.onCardButtonPressed(OverviewCard.this, buttonIndex);
|
||||||
if (callback != null) {
|
if (buttonIndex == SHOW_ON_MAP_BUTTON_INDEX) {
|
||||||
callback.run(icon);
|
setImageDrawable(icon, getActiveShowHideIcon(), iconColorDef);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -213,10 +202,6 @@ public class OverviewCard extends BaseCard {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private interface StatBlockCallback {
|
|
||||||
void run(AppCompatImageView image);
|
|
||||||
}
|
|
||||||
|
|
||||||
private class StatBlockAdapter extends RecyclerView.Adapter<StatBlockViewHolder> {
|
private class StatBlockAdapter extends RecyclerView.Adapter<StatBlockViewHolder> {
|
||||||
|
|
||||||
private final List<StatBlock> statBlocks;
|
private final List<StatBlock> statBlocks;
|
||||||
|
@ -241,13 +226,9 @@ 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);
|
||||||
final int textColor = nightMode ?
|
|
||||||
app.getResources().getColor(R.color.active_color_primary_dark)
|
|
||||||
: app.getResources().getColor(R.color.active_color_primary_light);
|
|
||||||
|
|
||||||
holder.valueText.setText(item.value);
|
holder.valueText.setText(item.value);
|
||||||
holder.titleText.setText(item.title);
|
holder.titleText.setText(item.title);
|
||||||
holder.valueText.setTextColor(textColor);
|
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
|
||||||
|
@ -293,41 +274,6 @@ public class OverviewCard extends BaseCard {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static class HorizontalDividerDecoration extends ItemDecoration {
|
|
||||||
|
|
||||||
private final Drawable divider;
|
|
||||||
private final int marginV;
|
|
||||||
private final int marginH;
|
|
||||||
|
|
||||||
public HorizontalDividerDecoration(Context context, boolean nightMode) {
|
|
||||||
divider = new ColorDrawable(ContextCompat.getColor(context, nightMode ? R.color.divider_color_dark : R.color.divider_color_light));
|
|
||||||
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() - 1; 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(@NonNull Rect outRect, @NonNull View view, @NonNull RecyclerView parent, @NonNull RecyclerView.State state) {
|
|
||||||
outRect.set(marginH - divider.getIntrinsicWidth(), 0, marginH + divider.getIntrinsicWidth(), 0);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
protected static class StatBlock {
|
protected static class StatBlock {
|
||||||
|
|
||||||
private final String title;
|
private final String title;
|
||||||
|
|
Loading…
Reference in a new issue