private void updateSplits(long cumulativeTime, int cummulativeDistance, boolean reset) { MyLog.i("RaceTimerFragment", "updateSplits for Athlete " + mAthleteNumber); List<Split> splits = new ArrayList<>(); if (reset) { tvAthletePace.setText(getActivity().getString(R.string.header_pace)); } else { // gets the splits associated with the race Uuid splits = Split.getAllSplits(mRaceUuid, false); String paceAndDistance = CommonMethods.getAveragePaceString( cumulativeTime, cummulativeDistance, mPaceDistance, mPoolLengthUnits); if (mIsClockRunning) { paceAndDistance = paceAndDistance + CommonMethods.getEstimatedTotalDistance( cumulativeTime, cummulativeDistance, mEventDurationMs, mPoolLengthUnits); } tvAthletePace.setText(paceAndDistance); } mSplitArrayAdapter.setData(splits); mSplitArrayAdapter.notifyDataSetChanged(); }
private void completeRace(String lastLapDistanceString, String timerName, String eventLocation) { int lastLapDistance = Integer.valueOf(lastLapDistanceString); // create last split int totalDistance = (mLapNumber * mLapDistance) + lastLapDistance; String averagePaceString = CommonMethods.getAveragePaceString( mEventDurationMs, totalDistance, mPaceDistance, mPoolLengthUnits); long splitTime = mEventDurationMs - mPreviousCummulativeTime; createSplit( mSelectedAthlete, mSelectedSwimEvent, mLapNumber + 1, totalDistance, splitTime, mEventDurationMs); // create event summary mSwimEventSummary = new SwimEventSummary(); mSwimEventSummary.newInstance( mRaceUuid, mSelectedSwimEvent, mSelectedAthlete, mStartTime, timerName, eventLocation, mPoolLength, mPoolLengthUnits, totalDistance, averagePaceString); mSwimEventSummary.pinInBackground(); // Mark splits as Race Complete markSplitsRaceComplete(); MyLog.i("RaceTimerFragment", "completeRace: for Athlete " + mAthleteNumber); }
@Override public void onActivityCreated(Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); if (savedInstanceState != null) { MyLog.i("RaceTimerFragment", "onActivityCreated: savedInstanceState Not Null"); if (savedInstanceState.containsKey(ARG_ATHLETE_NUMBER)) { mAthleteNumber = savedInstanceState.getInt(ARG_ATHLETE_NUMBER); } if (savedInstanceState.containsKey(ARG_RACE_UUID)) { mRaceUuid = savedInstanceState.getString(ARG_RACE_UUID); } } else { switch (mAthleteNumber) { case 1: mRaceUuid = MySettings.getAthlete1RaceUuid(); break; case 2: mRaceUuid = MySettings.getAthlete2RaceUuid(); break; } } MyLog.i( "RaceTimerFragment", "onActivityCreated: Athlete" + mAthleteNumber + "RaceUuid: " + mRaceUuid); if (mAthleteNumber == 1) { mLapDistance = MySettings.getLapDistance(); mPaceDistance = MySettings.getPaceDistance(); mPoolLength = MySettings.getPoolLength(); mPoolLengthUnits = MySettings.getPoolLengthUnits(); mEventDurationMs = MySettings.getEventDurationMinutes() * 60000; mSplitButtonDisableDurationMs = MySettings.getSplitButtonDisabledSeconds() * 1000; } int spnAthletesStartingPosition = 0; switch (mAthleteNumber) { case 1: if (!MySettings.getSelectedAthlete1ID().equals(MySettings.NOT_AVAILABLE)) { spnAthletesStartingPosition = mAthleteSpinnerAdapter.getItemPosition(MySettings.getSelectedAthlete1ID()); } break; case 2: if (!MySettings.getSelectedAthlete2ID().equals(MySettings.NOT_AVAILABLE)) { spnAthletesStartingPosition = mAthleteSpinnerAdapter.getItemPosition(MySettings.getSelectedAthlete2ID()); } break; } mOkToResetLapCounter = false; spnAthletes.setSelection(spnAthletesStartingPosition); mIsClockRunning = false; String pace = getActivity().getString(R.string.header_pace); if (mSplitsOfCompletedRace.size() > 0) { Split lastSplit = mSplitsOfCompletedRace.get(0); long cummulativeDurationMs = lastSplit.getAccumulativeTimeMs(); int cummulativeDistance = lastSplit.getDistance(); pace = CommonMethods.getAveragePaceString( cummulativeDurationMs, cummulativeDistance, mPaceDistance, mPoolLengthUnits); } tvAthletePace.setText(pace); }