minor fixes

This commit is contained in:
Skalii 2021-01-27 14:04:43 +02:00
parent 84c879e02d
commit 10ae234c30

View file

@ -1,10 +1,6 @@
package net.osmand.plus.track;
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.view.LayoutInflater;
import android.view.MotionEvent;
@ -16,16 +12,14 @@ import android.widget.TextView;
import androidx.annotation.ColorRes;
import androidx.annotation.DrawableRes;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.widget.AppCompatImageView;
import androidx.core.content.ContextCompat;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import androidx.recyclerview.widget.RecyclerView.ItemDecoration;
import net.osmand.AndroidUtils;
import net.osmand.GPXUtilities.GPXFile;
import net.osmand.GPXUtilities.GPXTrackAnalysis;
import net.osmand.plus.GpxSelectionHelper.GpxDisplayGroup;
import net.osmand.plus.GpxSelectionHelper.GpxDisplayItem;
import net.osmand.plus.GpxSelectionHelper.GpxDisplayItemType;
import net.osmand.plus.OsmAndFormatter;
@ -71,7 +65,10 @@ public class OverviewCard extends BaseCard {
this.listener = listener;
gpxFile = displayHelper.getGpx();
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
@ -101,8 +98,8 @@ public class OverviewCard extends BaseCard {
}
void initStatBlocks() {
GPXTrackAnalysis analysis = gpxItem.analysis;
if (analysis != null) {
if (gpxItem != null) {
GPXTrackAnalysis analysis = gpxItem.analysis;
boolean joinSegments = displayHelper.isJoinSegments();
float totalDistance = !joinSegments && gpxItem.isGeneralTrack() ? analysis.totalDistanceWithoutGaps : analysis.totalDistance;
float timeSpan = !joinSegments && gpxItem.isGeneralTrack() ? analysis.timeSpanWithoutGaps : analysis.timeSpan;
@ -128,47 +125,39 @@ public class OverviewCard extends BaseCard {
final StatBlockAdapter sbAdapter = new StatBlockAdapter(items);
rvOverview.setLayoutManager(new LinearLayoutManager(app, LinearLayoutManager.HORIZONTAL, false));
// rvOverview.addItemDecoration(new HorizontalDividerDecoration(app, nightMode));
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) {
initButton(showButton, SHOW_ON_MAP_BUTTON_INDEX, null, iconColorDef, iconColorPres, new StatBlockCallback() {
@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();
}
});
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, null);
initButton(appearanceButton, APPEARANCE_BUTTON_INDEX, R.drawable.ic_action_appearance, iconColorDef, 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) {
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,
@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 filled = item.findViewById(R.id.filled);
filled.setImageResource(nightMode ? R.drawable.bg_plugin_logo_enabled_dark : R.drawable.bg_topbar_shield_exit_ref);
filled.setAlpha(0.1f);
if (callback != null) {
callback.run(icon);
} else {
setImageDrawable(icon, iconResId, iconColorDef);
}
setImageDrawable(icon, iconResId, iconColorDef);
setOnTouchItem(item, icon, filled, iconResId, iconColorDef, iconColorPres);
item.setOnClickListener(new View.OnClickListener() {
@Override
@ -176,8 +165,8 @@ public class OverviewCard extends BaseCard {
CardListener listener = getListener();
if (listener != null) {
listener.onCardButtonPressed(OverviewCard.this, buttonIndex);
if (callback != null) {
callback.run(icon);
if (buttonIndex == SHOW_ON_MAP_BUTTON_INDEX) {
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 final List<StatBlock> statBlocks;
@ -241,13 +226,9 @@ public class OverviewCard extends BaseCard {
@Override
public void onBindViewHolder(StatBlockViewHolder holder, int 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.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.itemView.setOnClickListener(new View.OnClickListener() {
@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 {
private final String title;