Example #1
0
  public void setUpHeader(View header) {
    Typeface robotoBold = AndroidUtils.robotoBold(this.context);
    TextView patientID = (TextView) header.findViewById(R.id.menu_patient_id);
    TextView patientIDSubtitle = (TextView) header.findViewById(R.id.menu_subtitle_patient_id);
    TextView nextVisit = (TextView) header.findViewById(R.id.menu_next_visit);
    TextView nextVisitSubtitle = (TextView) header.findViewById(R.id.menu_subtitle_next_visit);
    TextView week = (TextView) header.findViewById(R.id.menu_week);
    TextView weekSubtitle = (TextView) header.findViewById(R.id.menu_subtitle_week);

    patientID.setText(DataManager.getCurrentPatient().getUserID());
    patientID.setTypeface(robotoBold);
    patientIDSubtitle.setText(context.getResources().getString(R.string.patient_id_subtitle));

    // set localized date for next visit
    Locale locale = context.getResources().getConfiguration().locale;
    Date nextDate = DataManager.getCurrentPatient().getDateOfNextVisit();
    nextVisit.setText(Utils.localizedDateWithoutYear(nextDate, locale));
    nextVisit.setTypeface(robotoBold);

    nextVisitSubtitle.setText(context.getResources().getString(R.string.next_visit_subtitle));
    week.setText(
        "Visit "
            + DataManager.getCurrentPatient().getVisitsUsed()
            + "/"
            + DataManager.getCurrentPatient().getVisitsTotal());
    week.setTypeface(robotoBold);
    weekSubtitle.setText(context.getResources().getString(R.string.week_subtitle));
  }
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    Routine selectedRoutine = DataManager.getCurrentPatient().getSelectedRoutine();
    setListAdapter(
        new ExerciseAdapter(
            getActivity(), DataManager.getCurrentPatient().getExercises(selectedRoutine)));
  }
  @Override
  public void onActivityCreated(Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);

    if (getView() != null) {
      Routine routine = DataManager.getCurrentPatient().getSelectedRoutine();
      TextView routineName = (TextView) getView().findViewById(R.id.routine_name);
      routineName.setText(routine.getRoutineTitle());
    }
  }
  @Override
  public void onListItemClick(ListView l, View v, int position, long id) {
    super.onListItemClick(l, v, position, id);

    Exercise selectedExercise = (Exercise) getListAdapter().getItem(position);
    DataManager.getCurrentPatient().setSelectedExercise(selectedExercise);

    getFragmentManager()
        .beginTransaction()
        .replace(R.id.fragment_container, new VideoFragment())
        .addToBackStack(null)
        .commit();
  }
  private void loadExerciseData() {
    final List<Routine> routines = DataManager.getCurrentPatient().getRoutines();

    // no routines to get data for, proceed to landing screen
    if (routines.isEmpty()) {
      dataIsAvailable();
    }

    for (final Routine routine : routines) {
      WLProcedureCaller wlProcedureCaller =
          new WLProcedureCaller("HealthcareAdapter", "getExercisesForRoutine");
      Object[] params = new Object[] {routine.getId()};
      wlProcedureCaller.invoke(
          params,
          new WLResponseListener() {
            @Override
            public void onSuccess(final WLResponse wlResponse) {
              runOnUiThread(
                  new Runnable() {
                    @Override
                    public void run() {
                      Exercise[] exercises = getExercisesFromJson(wlResponse.getResponseJSON());
                      DataManager.getCurrentPatient()
                          .addExercises(routine, Arrays.asList(exercises));

                      // check to see if all exercise data has been retrieved
                      int exerciseSets = DataManager.getCurrentPatient().getNumberOfExerciseSets();
                      if (exerciseSets == routines.size()) {
                        dataIsAvailable();
                      }
                    }
                  });
            }

            @Override
            public void onFailure(WLFailResponse wlFailResponse) {
              Log.i(TAG, "Could not load exercise data!");

              runOnUiThread(
                  new Runnable() {
                    @Override
                    public void run() {
                      dataIsAvailable();
                    }
                  });
            }
          });
    }
  }