mirror of
https://github.com/eclipse-sailing-analytics/sailing-analytics.git
synced 2026-10-10 14:20:55 +00:00
changed NavDrawer list to RaceFlagViewerFragment behaviour for showing flags
This commit is contained in:
1 parent
16dc4c17a4
commit
937b11dea9
3 files changed
+164
-98
No files matched your search
+86
-78
@@ -1,15 +1,10 @@
|
||||
package com.sap.sailing.racecommittee.app.ui.adapters.racelist;
|
||||
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Calendar;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.res.Resources;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.graphics.drawable.LayerDrawable;
|
||||
import android.support.v4.content.LocalBroadcastManager;
|
||||
import android.text.TextUtils;
|
||||
import android.view.LayoutInflater;
|
||||
@@ -19,10 +14,11 @@ import android.widget.ArrayAdapter;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.sap.sailing.android.shared.logging.ExLog;
|
||||
import com.sap.sailing.android.shared.util.ViewHolder;
|
||||
import com.sap.sailing.domain.abstractlog.race.state.RaceState;
|
||||
import com.sap.sailing.domain.abstractlog.race.state.racingprocedure.FlagPoleState;
|
||||
import com.sap.sailing.domain.abstractlog.race.state.racingprocedure.RacingProcedure;
|
||||
import com.sap.sailing.domain.common.racelog.FlagPole;
|
||||
import com.sap.sailing.domain.common.racelog.Flags;
|
||||
import com.sap.sailing.racecommittee.app.AppConstants;
|
||||
@@ -32,11 +28,17 @@ import com.sap.sailing.racecommittee.app.ui.adapters.racelist.RaceFilter.FilterS
|
||||
import com.sap.sailing.racecommittee.app.ui.utils.FlagsResources;
|
||||
import com.sap.sailing.racecommittee.app.utils.BitmapHelper;
|
||||
import com.sap.sailing.racecommittee.app.utils.ThemeHelper;
|
||||
import com.sap.sailing.racecommittee.app.utils.TimeUtils;
|
||||
import com.sap.sse.common.TimePoint;
|
||||
import com.sap.sse.common.impl.MillisecondsTimePoint;
|
||||
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.List;
|
||||
|
||||
public class ManagedRaceListAdapter extends ArrayAdapter<RaceListDataType> implements FilterSubscriber {
|
||||
|
||||
private final static String TAG = ManagedRaceListAdapter.class.getName();
|
||||
private final static int FLAG_SIZE = 48;
|
||||
private final Object mLockObject = new Object();
|
||||
private List<RaceListDataType> mAllViewItems;
|
||||
private RaceFilter mFilter;
|
||||
@@ -71,15 +73,6 @@ public class ManagedRaceListAdapter extends ArrayAdapter<RaceListDataType> imple
|
||||
dateFormat = new SimpleDateFormat("HH:mm", getContext().getResources().getConfiguration().locale);
|
||||
}
|
||||
|
||||
public String fill2(int value) {
|
||||
String erg = String.valueOf(value);
|
||||
|
||||
if (erg.length() < 2) {
|
||||
erg = "0" + erg;
|
||||
}
|
||||
return erg;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getCount() {
|
||||
synchronized (mLockObject) {
|
||||
@@ -87,46 +80,6 @@ public class ManagedRaceListAdapter extends ArrayAdapter<RaceListDataType> imple
|
||||
}
|
||||
}
|
||||
|
||||
public String getDuration(Date date1, Date date2) {
|
||||
TimeUnit timeUnit = TimeUnit.SECONDS;
|
||||
|
||||
long diffInMilli = date2.getTime() - date1.getTime();
|
||||
long s = timeUnit.convert(diffInMilli, TimeUnit.MILLISECONDS);
|
||||
|
||||
long days = s / (24 * 60 * 60);
|
||||
long rest = s - (days * 24 * 60 * 60);
|
||||
long hrs = rest / (60 * 60);
|
||||
long rest1 = rest - (hrs * 60 * 60);
|
||||
long min = rest1 / 60;
|
||||
long sec = s % 60;
|
||||
|
||||
String dates = "";
|
||||
if (days < 0 || hrs < 0 || min < 0 || sec < 0) {
|
||||
dates += "-";
|
||||
if (days < 0) {
|
||||
days *= -1;
|
||||
}
|
||||
if (hrs < 0) {
|
||||
hrs *= -1;
|
||||
}
|
||||
if (min < 0) {
|
||||
min *= -1;
|
||||
}
|
||||
if (sec < 0) {
|
||||
sec *= -1;
|
||||
}
|
||||
}
|
||||
if (days != 0) {
|
||||
dates = days + ":";
|
||||
}
|
||||
|
||||
dates += (days != 0 || hrs != 0) ? fill2((int) hrs) + ":" : "";
|
||||
dates += fill2((int) min) + ":";
|
||||
dates += fill2((int) sec);
|
||||
|
||||
return dates;
|
||||
}
|
||||
|
||||
@Override
|
||||
public RaceFilter getFilter() {
|
||||
if (mFilter == null) {
|
||||
@@ -157,6 +110,7 @@ public class ManagedRaceListAdapter extends ArrayAdapter<RaceListDataType> imple
|
||||
raceListElement = getItem(position);
|
||||
|
||||
int type = getItemViewType(position);
|
||||
TimePoint now = MillisecondsTimePoint.now();
|
||||
|
||||
if (convertView == null) {
|
||||
if (type == ViewType.HEADER.index) {
|
||||
@@ -186,7 +140,7 @@ public class ManagedRaceListAdapter extends ArrayAdapter<RaceListDataType> imple
|
||||
fleetSeries += header.getSeries().getName();
|
||||
}
|
||||
fleet_series.setText(fleetSeries);
|
||||
protest_image.setImageDrawable(FlagsResources.getFlagDrawable(getContext(), Flags.BRAVO.name(), 48));
|
||||
protest_image.setImageDrawable(FlagsResources.getFlagDrawable(getContext(), Flags.BRAVO.name(), FLAG_SIZE));
|
||||
protest_image.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
@@ -220,7 +174,7 @@ public class ManagedRaceListAdapter extends ArrayAdapter<RaceListDataType> imple
|
||||
String startTime = mResources.getString(startRes, dateFormat.format(state.getStartTime().asDate()));
|
||||
race_started.setText(startTime);
|
||||
if (state.getFinishedTime() == null) {
|
||||
String duration = getDuration(state.getStartTime().asDate(), Calendar.getInstance().getTime());
|
||||
String duration = TimeUtils.formatDuration(now, state.getStartTime());
|
||||
time.setText(duration);
|
||||
float textSize = getContext().getResources().getDimension(R.dimen.textSize_40);
|
||||
if (!TextUtils.isEmpty(duration) && duration.length() >= 6) {
|
||||
@@ -248,7 +202,7 @@ public class ManagedRaceListAdapter extends ArrayAdapter<RaceListDataType> imple
|
||||
update_badge.setVisibility(View.VISIBLE);
|
||||
}
|
||||
|
||||
updateFlag(race.getRace());
|
||||
updateFlag(race.getRace(), now);
|
||||
}
|
||||
return convertView;
|
||||
}
|
||||
@@ -323,32 +277,86 @@ public class ManagedRaceListAdapter extends ArrayAdapter<RaceListDataType> imple
|
||||
}
|
||||
}
|
||||
|
||||
private void updateFlag(ManagedRace race) {
|
||||
private void updateFlag(ManagedRace race, TimePoint now) {
|
||||
RaceState state = race.getState();
|
||||
if (state == null || state.getStartTime() == null) {
|
||||
return;
|
||||
}
|
||||
FlagPoleState flagPoleState = state.getTypedRacingProcedure()
|
||||
.getActiveFlags(state.getStartTime(), MillisecondsTimePoint.now());
|
||||
List<FlagPole> flagChanges = flagPoleState.computeUpcomingChanges();
|
||||
if (!flagChanges.isEmpty()) {
|
||||
TimePoint changeAt = flagPoleState.getNextStateValidFrom();
|
||||
FlagPole changePole = FlagPoleState.getMostInterestingFlagPole(flagChanges);
|
||||
|
||||
if (changeAt != null) {
|
||||
current_flag.setImageDrawable(
|
||||
FlagsResources.getFlagDrawable(getContext(), changePole.getUpperFlag().name(), 48));
|
||||
String text = getDuration(changeAt.asDate(), Calendar.getInstance().getTime());
|
||||
flag_timer.setText(text.replace("-", ""));
|
||||
Drawable arrow;
|
||||
if (changePole.isDisplayed()) {
|
||||
arrow = BitmapHelper.getAttrDrawable(getContext(), R.attr.arrow_up);
|
||||
} else {
|
||||
arrow = BitmapHelper.getAttrDrawable(getContext(), R.attr.arrow_down);
|
||||
RacingProcedure procedure = state.getTypedRacingProcedure();
|
||||
LayerDrawable flag = null;
|
||||
Drawable arrow = null;
|
||||
String timer = null;
|
||||
if (!procedure.isIndividualRecallDisplayed()) {
|
||||
FlagPoleState poleState = state.getRacingProcedure().getActiveFlags(state.getStartTime(), now);
|
||||
List<FlagPole> currentState = poleState.getCurrentState();
|
||||
List<FlagPole> upcoming = poleState.computeUpcomingChanges();
|
||||
FlagPole nextPole = FlagPoleState.getMostInterestingFlagPole(upcoming);
|
||||
TimePoint change = poleState.getNextStateValidFrom();
|
||||
Flags currentFlag;
|
||||
|
||||
if (change != null) {
|
||||
for (FlagPole pole : currentState) {
|
||||
int isNext = 0;
|
||||
|
||||
currentFlag = pole.getUpperFlag();
|
||||
if (isNextFlag(currentFlag, nextPole)) {
|
||||
isNext = 1;
|
||||
} else {
|
||||
currentFlag = pole.getLowerFlag();
|
||||
if (!Flags.NONE.equals(currentFlag)) {
|
||||
if (isNextFlag(currentFlag, nextPole)) {
|
||||
isNext = 2;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (isNext != 0) {
|
||||
flag = FlagsResources.getFlagDrawable(getContext(), currentFlag.name(), FLAG_SIZE);
|
||||
switch (isNext) {
|
||||
case 1:
|
||||
if (nextPole.isDisplayed()) {
|
||||
arrow = BitmapHelper.getAttrDrawable(getContext(), R.attr.arrow_up);
|
||||
} else {
|
||||
arrow = BitmapHelper.getAttrDrawable(getContext(), R.attr.arrow_down);
|
||||
}
|
||||
break;
|
||||
|
||||
case 2:
|
||||
arrow = BitmapHelper.getAttrDrawable(getContext(), R.attr.arrow_up);
|
||||
break;
|
||||
|
||||
default:
|
||||
ExLog.i(getContext(), TAG, "unknown flag");
|
||||
}
|
||||
timer = TimeUtils.formatDuration(now, poleState.getNextStateValidFrom());
|
||||
}
|
||||
}
|
||||
arrow_direction.setImageDrawable(arrow);
|
||||
race_flag.setVisibility(View.VISIBLE);
|
||||
}
|
||||
} else {
|
||||
TimePoint flagDown = procedure.getIndividualRecallRemovalTime();
|
||||
if (now.before(flagDown)) {
|
||||
flag = FlagsResources.getFlagDrawable(getContext(), Flags.XRAY.name(), FLAG_SIZE);
|
||||
arrow = BitmapHelper.getAttrDrawable(getContext(), R.attr.arrow_down);
|
||||
timer = TimeUtils.formatDuration(now, flagDown);
|
||||
}
|
||||
}
|
||||
if (timer != null) {
|
||||
timer = timer.replace("-", "");
|
||||
}
|
||||
showFlag(flag, arrow, timer);
|
||||
}
|
||||
|
||||
private boolean isNextFlag(Flags flag, FlagPole pole) {
|
||||
return pole != null && flag.equals(pole.getUpperFlag());
|
||||
}
|
||||
|
||||
private void showFlag(LayerDrawable flag, Drawable arrow, String timer) {
|
||||
if (flag != null && arrow != null && timer != null) {
|
||||
current_flag.setImageDrawable(flag);
|
||||
arrow_direction.setImageDrawable(arrow);
|
||||
flag_timer.setText(timer);
|
||||
race_flag.setVisibility(View.VISIBLE);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+44
-6
@@ -9,6 +9,8 @@ import android.widget.*;
|
||||
import com.sap.sailing.android.shared.util.ViewHolder;
|
||||
import com.sap.sailing.domain.abstractlog.race.state.racingprocedure.FlagPoleState;
|
||||
import com.sap.sailing.domain.abstractlog.race.state.racingprocedure.RacingProcedure;
|
||||
import com.sap.sailing.domain.abstractlog.race.state.racingprocedure.ReadonlyRacingProcedure;
|
||||
import com.sap.sailing.domain.abstractlog.race.state.racingprocedure.impl.BaseRacingProcedureChangedListener;
|
||||
import com.sap.sailing.domain.common.racelog.FlagPole;
|
||||
import com.sap.sailing.domain.common.racelog.Flags;
|
||||
import com.sap.sailing.racecommittee.app.R;
|
||||
@@ -32,8 +34,12 @@ public class RaceFlagViewerFragment extends BaseFragment {
|
||||
private TextView mXrayCountdown;
|
||||
private Button mXrayButton;
|
||||
|
||||
public RaceFlagViewerFragment() {
|
||||
private ProcedureChangedListener mProcedureListener;
|
||||
private FlagsCache mFlagCache;
|
||||
|
||||
public RaceFlagViewerFragment() {
|
||||
mProcedureListener = new ProcedureChangedListener();
|
||||
mFlagCache = null;
|
||||
}
|
||||
|
||||
public static RaceFlagViewerFragment newInstance() {
|
||||
@@ -69,6 +75,20 @@ public class RaceFlagViewerFragment extends BaseFragment {
|
||||
return layout;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStart() {
|
||||
super.onStart();
|
||||
|
||||
getRaceState().getRacingProcedure().addChangedListener(mProcedureListener);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStop() {
|
||||
super.onStop();
|
||||
|
||||
getRaceState().getRacingProcedure().removeChangedListener(mProcedureListener);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void notifyTick(TimePoint now) {
|
||||
super.notifyTick(now);
|
||||
@@ -102,10 +122,12 @@ public class RaceFlagViewerFragment extends BaseFragment {
|
||||
for (FlagPole flagPole : currentState) {
|
||||
size++;
|
||||
flag = flagPole.getUpperFlag();
|
||||
mLayout.addView(renderFlag(timePoint, poleState, flag, isNextFlag(flag, nextPole), currentState.size() == size, flagPole.isDisplayed(), UPPER_FLAG));
|
||||
mLayout.addView(renderFlag(timePoint, poleState, flag, isNextFlag(flag, nextPole),
|
||||
currentState.size() == size, flagPole.isDisplayed(), UPPER_FLAG));
|
||||
if (!flagPole.getLowerFlag().equals(Flags.NONE)) {
|
||||
flag = flagPole.getLowerFlag();
|
||||
mLayout.addView(renderFlag(timePoint, poleState, flag, isNextFlag(flag, nextPole), currentState.size() == size, false, LOWER_FLAG));
|
||||
mLayout
|
||||
.addView(renderFlag(timePoint, poleState, flag, isNextFlag(flag, nextPole), currentState.size() == size, false, LOWER_FLAG));
|
||||
}
|
||||
}
|
||||
} else {
|
||||
@@ -125,9 +147,10 @@ public class RaceFlagViewerFragment extends BaseFragment {
|
||||
return pole != null && flag.equals(pole.getUpperFlag());
|
||||
}
|
||||
|
||||
private RelativeLayout renderFlag(TimePoint timePoint, FlagPoleState poleState, final Flags flag, boolean isNext, boolean lastEntry, boolean isDisplayed, int flagType) {
|
||||
private RelativeLayout renderFlag(TimePoint timePoint, FlagPoleState poleState, final Flags flag, boolean isNext, boolean lastEntry,
|
||||
boolean isDisplayed, int flagType) {
|
||||
RelativeLayout layout = (RelativeLayout) getActivity().getLayoutInflater().inflate(R.layout.race_flag, mLayout, false);
|
||||
LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,LinearLayout.LayoutParams.MATCH_PARENT, 1.0f);
|
||||
LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.MATCH_PARENT, 1.0f);
|
||||
layout.setLayoutParams(layoutParams);
|
||||
|
||||
TimePoint changeAt = poleState.getNextStateValidFrom();
|
||||
@@ -187,7 +210,22 @@ public class RaceFlagViewerFragment extends BaseFragment {
|
||||
}
|
||||
|
||||
private int getFleetColorId() {
|
||||
Util.Triple<Integer, Integer, Integer> rgb = getRace().getFleet().getColor() == null ? new Util.Triple<>(0, 0, 0) : getRace().getFleet().getColor().getAsRGB();
|
||||
Util.Triple<Integer, Integer, Integer> rgb =
|
||||
getRace().getFleet().getColor() == null ? new Util.Triple<>(0, 0, 0) : getRace().getFleet().getColor().getAsRGB();
|
||||
return Color.rgb(rgb.getA(), rgb.getB(), rgb.getC());
|
||||
}
|
||||
|
||||
private class ProcedureChangedListener extends BaseRacingProcedureChangedListener {
|
||||
|
||||
@Override
|
||||
public void onActiveFlagsChanged(ReadonlyRacingProcedure racingProcedure) {
|
||||
super.onActiveFlagsChanged(racingProcedure);
|
||||
|
||||
mFlagCache = null;
|
||||
}
|
||||
}
|
||||
|
||||
private class FlagsCache {
|
||||
|
||||
}
|
||||
}
|
||||
+34
-14
@@ -1,12 +1,11 @@
|
||||
package com.sap.sailing.racecommittee.app.utils;
|
||||
|
||||
import java.util.Calendar;
|
||||
|
||||
import android.text.format.DateFormat;
|
||||
|
||||
import com.sap.sse.common.TimePoint;
|
||||
import com.sap.sse.common.impl.MillisecondsTimePoint;
|
||||
|
||||
import java.util.Calendar;
|
||||
|
||||
public class TimeUtils {
|
||||
|
||||
private TimeUtils() {
|
||||
@@ -16,33 +15,53 @@ public class TimeUtils {
|
||||
public static long timeUntil(TimePoint targetTime) {
|
||||
return targetTime.asMillis() - MillisecondsTimePoint.now().asMillis();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Formats your time to 'kk:mm:ss'.
|
||||
*
|
||||
* @param timePoint timestamp to format
|
||||
*/
|
||||
public static String formatTime(TimePoint timePoint) {
|
||||
return formatTime(timePoint, "kk:mm:ss");
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Formats your time with the help of {@link DateFormat}.
|
||||
*
|
||||
* @param timePoint timestamp to format
|
||||
* @param format format as defined by {@link DateFormat}
|
||||
* @param format format as defined by {@link DateFormat}
|
||||
* @return timestamp formatted as {@link String}
|
||||
*/
|
||||
public static String formatTime(TimePoint timePoint, String format) {
|
||||
return DateFormat.format(format, timePoint.asDate()).toString();
|
||||
}
|
||||
|
||||
public static String formatDurationSince(long milliseconds) {
|
||||
int secondsTillStart = (int) Math.floor(milliseconds / 1000f);
|
||||
return formatDuration(secondsTillStart);
|
||||
public static String formatDuration(TimePoint now, TimePoint timePoint) {
|
||||
String duration;
|
||||
if (timePoint.after(now)) {
|
||||
duration = "-" + TimeUtils.formatDurationUntil(timePoint.minus(now.asMillis()).asMillis(), false);
|
||||
} else {
|
||||
duration = TimeUtils.formatDurationSince(now.minus(timePoint.asMillis()).asMillis(), false);
|
||||
}
|
||||
return duration;
|
||||
}
|
||||
|
||||
|
||||
public static String formatDurationSince(long milliseconds) {
|
||||
return formatDurationSince(milliseconds, true);
|
||||
}
|
||||
|
||||
public static String formatDurationSince(long milliseconds, boolean emptyHours) {
|
||||
int secondsTillStart = (int) Math.floor(milliseconds / 1000f);
|
||||
return formatDuration(secondsTillStart, emptyHours);
|
||||
}
|
||||
|
||||
public static String formatDurationUntil(long milliseconds) {
|
||||
return formatDurationUntil(milliseconds, true);
|
||||
}
|
||||
|
||||
public static String formatDurationUntil(long milliseconds, boolean emptyHours) {
|
||||
int secondsTillStart = (int) Math.ceil(milliseconds / 1000f);
|
||||
return formatDuration(secondsTillStart);
|
||||
return formatDuration(secondsTillStart, emptyHours);
|
||||
}
|
||||
|
||||
public static String calcDuration(Calendar from, Calendar to) {
|
||||
@@ -73,7 +92,7 @@ public class TimeUtils {
|
||||
return calendar;
|
||||
}
|
||||
|
||||
public static int daysBetween(Calendar day1, Calendar day2){
|
||||
public static int daysBetween(Calendar day1, Calendar day2) {
|
||||
Calendar dayOne = (Calendar) day1.clone();
|
||||
Calendar dayTwo = (Calendar) day2.clone();
|
||||
|
||||
@@ -98,15 +117,16 @@ public class TimeUtils {
|
||||
}
|
||||
}
|
||||
|
||||
private static String formatDuration(int secondsTillStart) {
|
||||
private static String formatDuration(int secondsTillStart, boolean emptyHours) {
|
||||
int hours = secondsTillStart / 3600;
|
||||
int minutes = (secondsTillStart % 3600) / 60;
|
||||
int seconds = (secondsTillStart % 60);
|
||||
boolean negative = (hours < 0 || minutes < 0 || seconds < 0);
|
||||
String timePattern = ((negative) ? "-" : "") + "%s:%s:%s";
|
||||
String timePattern = ((negative) ? "-" : "") + "%s%s:%s";
|
||||
String secondsString = seconds < 10 ? "0" + Math.abs(seconds) : "" + Math.abs(seconds);
|
||||
String minutesString = minutes < 10 ? "0" + Math.abs(minutes) : "" + Math.abs(minutes);
|
||||
String hoursString = hours < 10 ? "0" + Math.abs(hours) : "" + Math.abs(hours);
|
||||
hoursString = !emptyHours && hoursString.equals("00") ? "" : hoursString + ":";
|
||||
return String.format(timePattern, hoursString, minutesString, secondsString);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user