예제 #1
0
  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();
  }
예제 #2
0
  @Override
  public View onCreateView(
      LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    // Inflate the layout for this fragment
    MyLog.i("RaceTimerFragment", "onCreateView: Athlete" + mAthleteNumber);
    View view = null;

    if (savedInstanceState != 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);
      }
    }

    switch (mAthleteNumber) {
      case 1:
        view = inflater.inflate(R.layout.frag_race_timer_athlete1, container, false);
        break;

      case 2:
        view = inflater.inflate(R.layout.frag_race_timer_athlete2, container, false);
        break;
    }

    if (view != null) {
      llAthlete = (LinearLayout) view.findViewById(R.id.llAthletes);
      spnAthletes = (Spinner) view.findViewById(R.id.spnAthletes);
      mAthleteSpinnerAdapter =
          new AthleteSpinnerAdapter(getActivity(), new ArrayList<Athlete>(), mAthleteNumber);
      spnAthletes.setAdapter(mAthleteSpinnerAdapter);
      updateAthletesSpinner();
      spnAthletes.setOnItemSelectedListener(
          new AdapterView.OnItemSelectedListener() {
            @Override
            public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
              mSelectedAthlete = mAthleteSpinnerAdapter.getItem(position);
              switch (mAthleteNumber) {
                case 1:
                  MySettings.setSelectedAthlete1ID(mSelectedAthlete.getAthleteID());
                  break;
                case 2:
                  MySettings.setSelectedAthlete2ID(mSelectedAthlete.getAthleteID());
                  break;
              }
              EventBus.getDefault().post(new MyEvents.updateAthletesSpinner(mAthleteNumber));
              if (mOkToResetLapCounter) {
                resetLapCounter();
              } else {
                mOkToResetLapCounter = true;
              }
            }

            @Override
            public void onNothingSelected(AdapterView<?> parent) {}
          });

      Button btnEditAthlete = (Button) view.findViewById(R.id.btnEditAthlete);

      tvAthletePace = (TextView) view.findViewById(R.id.tvAthletePace);
      ListView lvAthleteRaceSplits = (ListView) view.findViewById(R.id.lvAthleteRaceSplits);

      mSplitsOfCompletedRace = Split.getAllSplits(mRaceUuid, false);
      mSplitArrayAdapter =
          new SplitArrayAdapter(getActivity(), mSplitsOfCompletedRace, mAthleteNumber);
      lvAthleteRaceSplits.setAdapter(mSplitArrayAdapter);

      btnStart = (Button) view.findViewById(R.id.btnStart);
      btnSplit = (Button) view.findViewById(R.id.btnSplit);
      btnEmail = (Button) view.findViewById(R.id.btnEmail);

      btnEditAthlete.setOnClickListener(this);
      btnStart.setOnClickListener(this);
      btnSplit.setOnClickListener(this);
      btnEmail.setOnClickListener(this);
    }
    return view;
  }
예제 #3
0
 private void markSplitsRaceComplete() {
   List<Split> splits = Split.getAllSplits(mRaceUuid, false);
   for (Split split : splits) {
     split.setIsRaceComplete(true);
   }
 }