private AppointmentListFragment getCurrentFragment() { AppointmentListFragment fragment = ((AppointmentListFragment) getSupportFragmentManager().findFragmentById(R.id.appointment_list)); if (fragment == null || fragment.getAdapter() == null) { return null; } return fragment; }
/** Refresh the list with the items in the Mobile Service Table */ private void refreshItemsFromTable() { // Get the items that weren't marked as completed and add them in the // adapter final ProgressDialog progress; progress = ProgressDialog.show( this, "", getResources().getString(R.string.appointments_loading), true); SharedPreferences prefs = getSharedPreferences(SHAREDPREFFILE, Context.MODE_PRIVATE); Boolean tmpSync = prefs.getBoolean(SYNCACTIVATED, true); // final String calendarPrimaryId = MyUtils.getCalendarId(getContentResolver()); String tmpCalendarPrimaryId = prefs.getString(CALENDARID, ""); if (tmpSync) { if (tmpCalendarPrimaryId.isEmpty()) { tmpCalendarPrimaryId = MyUtils.getCalendarId(getContentResolver()); if (tmpCalendarPrimaryId.isEmpty()) { createAndShowDialog( getResources().getString(R.string.no_calendar_found), getResources().getString(R.string.warning)); Editor editor = prefs.edit(); editor.putBoolean(SYNCACTIVATED, false); editor.commit(); tmpSync = false; } else { Editor editor = prefs.edit(); editor.putString(CALENDARID, tmpCalendarPrimaryId); editor.commit(); } } } final Boolean sync = tmpSync; final Activity currentActivity = this; final String calendarPrimaryId = tmpCalendarPrimaryId; AppointmentListFragment tmpFragment = ((AppointmentListFragment) getSupportFragmentManager().findFragmentById(R.id.appointment_list)); if (tmpFragment == null || tmpFragment.getAdapter() == null) { return; } ArrayAdapter<MemberAppointments> tmpadapter = tmpFragment.getAdapter(); tmpadapter.clear(); // DataContent.ClearData(); Map tmpcalEntries = MyUtils.getStoredAppointments(currentActivity); Iterator it = tmpcalEntries.entrySet().iterator(); while (it.hasNext()) { Map.Entry pair = (Map.Entry) it.next(); // System.out.println(pair.getKey() + " = " + pair.getValue()); tmpadapter.add((MemberAppointments) pair.getValue()); } tmpadapter.notifyDataSetChanged(); AppointmentListFragment taskFragment = ((AppointmentListFragment) getSupportFragmentManager().findFragmentById(R.id.appointment_list)); LoadingTask task = new LoadingTask( this, mAppointmentTable, mNotificationAppointmentId, calendarPrimaryId, progress, sync, getContentResolver(), taskFragment, getResources()); task.execute(); }