From 866cffd7d6ef21d98d5f13b2f58de7122264c24f Mon Sep 17 00:00:00 2001 From: Ishan Khanna Date: Tue, 22 Jul 2014 18:20:25 +0530 Subject: [PATCH] Date Selection Completed --- .../online/CenterListFragment.java | 37 +++++++++++++-- .../mifosxdroid/online/CentersActivity.java | 4 +- .../online/CollectionSheetFragment.java | 4 +- .../mifosxdroid/uihelpers/MFDatePicker.java | 25 ++++++---- .../objects/group/CenterWithAssociations.java | 4 ++ .../main/java/com/mifos/utils/DateHelper.java | 46 +------------------ 6 files changed, 59 insertions(+), 61 deletions(-) diff --git a/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/CenterListFragment.java b/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/CenterListFragment.java index 45a3c3b21e5..0ae96b2945f 100644 --- a/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/CenterListFragment.java +++ b/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/CenterListFragment.java @@ -18,12 +18,15 @@ import android.view.ViewGroup; import android.widget.AdapterView; import android.widget.ListView; +import android.widget.Toast; import com.joanzapata.android.iconify.IconDrawable; import com.joanzapata.android.iconify.Iconify; import com.mifos.mifosxdroid.R; import com.mifos.mifosxdroid.adapters.CentersListAdapter; +import com.mifos.mifosxdroid.uihelpers.MFDatePicker; import com.mifos.objects.group.Center; +import com.mifos.objects.group.CenterWithAssociations; import com.mifos.services.API; import com.mifos.utils.SafeUIBlockingUtility; @@ -95,9 +98,37 @@ public void onItemClick(AdapterView adapterView, View view, int i, long l) { lv_centers_list.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() { @Override - public boolean onItemLongClick(AdapterView parent, View view, int position, long id) { + public boolean onItemLongClick(AdapterView parent, View view, final int position, long id) { + + safeUIBlockingUtility.safelyBlockUI(); + + API.centerService.getCenterWithGroupMembersAndCollectionMeetingCalendar(centers.get(position).getId(), new Callback() { + @Override + public void success(final CenterWithAssociations centerWithAssociations, Response response) { + + safeUIBlockingUtility.safelyUnBlockUI(); + MFDatePicker mfDatePicker = new MFDatePicker(); + mfDatePicker.setOnDatePickListener(new MFDatePicker.OnDatePickListener() { + @Override + public void onDatePicked(String date) { + + mListener.loadCollectionSheetForCenter(centers.get(position).getId(), date, centerWithAssociations.getCollectionMeetingCalendar().getId()); + + } + }); + mfDatePicker.show(getActivity().getSupportFragmentManager(), MFDatePicker.TAG); + + } + + @Override + public void failure(RetrofitError retrofitError) { + + safeUIBlockingUtility.safelyUnBlockUI(); + Toast.makeText(getActivity(), "Cannot Generate Collection Sheet, There was some problem!", Toast.LENGTH_SHORT).show(); + + } + }); - mListener.loadCollectionSheetForCenter(centers.get(position).getId()); return true; } }); @@ -126,7 +157,7 @@ public void setupUI(){ public interface OnFragmentInteractionListener { public void loadGroupsOfCenter(int centerId); - public void loadCollectionSheetForCenter(int centerId); + public void loadCollectionSheetForCenter(int centerId, String collectionDate, int calenderInstanceId); } diff --git a/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/CentersActivity.java b/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/CentersActivity.java index 34cba250d5c..e9e1fb011a4 100644 --- a/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/CentersActivity.java +++ b/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/CentersActivity.java @@ -64,8 +64,8 @@ public void loadGroupsOfCenter(int centerId) { } @Override - public void loadCollectionSheetForCenter(int centerId) { - CollectionSheetFragment collectionSheetFragment = CollectionSheetFragment.newInstance(centerId, "18 July 2014", 161); + public void loadCollectionSheetForCenter(int centerId, String collectionDate, int calenderInstanceId) { + CollectionSheetFragment collectionSheetFragment = CollectionSheetFragment.newInstance(centerId, collectionDate, calenderInstanceId); FragmentTransaction fragmentTransaction = getSupportFragmentManager().beginTransaction(); fragmentTransaction.addToBackStack(FragmentConstants.FRAG_CENTER_LIST); fragmentTransaction.replace(R.id.center_container, collectionSheetFragment); diff --git a/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/CollectionSheetFragment.java b/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/CollectionSheetFragment.java index adf12faf1b3..bf455cabc03 100644 --- a/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/CollectionSheetFragment.java +++ b/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/CollectionSheetFragment.java @@ -161,7 +161,7 @@ public void fetchCollectionSheet() { Payload payload = new Payload(); payload.setCalendarId(calendarInstanceId); payload.setTransactionDate(dateOfCollection); - //payload.setDateFormat(); + payload.setDateFormat("dd-MM-YYYY"); API.centerService.getCollectionSheet(centerId, payload, new Callback() { @Override @@ -215,7 +215,7 @@ public synchronized void saveCollectionSheet() { collectionSheetPayload.setCalendarId(calendarInstanceId); collectionSheetPayload.setTransactionDate(dateOfCollection); - + collectionSheetPayload.setDateFormat("dd-MM-YYYY"); API.centerService.saveCollectionSheet(centerId, collectionSheetPayload, new Callback() { @Override public void success(SaveResponse saveResponse, Response response) { diff --git a/mifosng-android/src/main/java/com/mifos/mifosxdroid/uihelpers/MFDatePicker.java b/mifosng-android/src/main/java/com/mifos/mifosxdroid/uihelpers/MFDatePicker.java index 242e0b27bf7..935db19c421 100644 --- a/mifosng-android/src/main/java/com/mifos/mifosxdroid/uihelpers/MFDatePicker.java +++ b/mifosng-android/src/main/java/com/mifos/mifosxdroid/uihelpers/MFDatePicker.java @@ -19,6 +19,7 @@ */ public class MFDatePicker extends DialogFragment implements DatePickerDialog.OnDateSetListener { + public static final String TAG = "MFDatePicker"; static String dateSet; static Calendar calendar; @@ -38,7 +39,7 @@ public class MFDatePicker extends DialogFragment implements DatePickerDialog.OnD .toString(); } - OnDatePickListener mListener; + OnDatePickListener onDatePickListener; public MFDatePicker(){ @@ -46,7 +47,7 @@ public MFDatePicker(){ public static MFDatePicker newInsance(Fragment fragment) { MFDatePicker mfDatePicker = new MFDatePicker(); - mfDatePicker.mListener = (OnDatePickListener) fragment; + mfDatePicker.onDatePickListener = (OnDatePickListener) fragment; return mfDatePicker; } @@ -62,14 +63,14 @@ public Dialog onCreateDialog(Bundle savedInstanceState) { @Override public void onDateSet(DatePicker datePicker, int year, int month, int day) { //TODO Fix Single digit problem that fails with the locale - mListener.onDatePicked( + onDatePickListener.onDatePicked( new StringBuilder() - .append(day < 10 ? "0"+day : day) - .append("-") - .append((month+1) < 10 ? "0"+(month+1) : month+1) - .append("-") - .append(year) - .toString() + .append(day < 10 ? "0" + day : day) + .append("-") + .append((month + 1) < 10 ? "0" + (month + 1) : month + 1) + .append("-") + .append(year) + .toString() ); } @@ -82,4 +83,10 @@ public interface OnDatePickListener { public void onDatePicked(String date); } + public void setOnDatePickListener(OnDatePickListener onDatePickListener) { + this.onDatePickListener = onDatePickListener; + } + + + } diff --git a/mifosng-android/src/main/java/com/mifos/objects/group/CenterWithAssociations.java b/mifosng-android/src/main/java/com/mifos/objects/group/CenterWithAssociations.java index 436553b810b..328a2d3c12e 100644 --- a/mifosng-android/src/main/java/com/mifos/objects/group/CenterWithAssociations.java +++ b/mifosng-android/src/main/java/com/mifos/objects/group/CenterWithAssociations.java @@ -143,6 +143,10 @@ public void setGroupMembers(List groupMembers) { this.groupMembers = groupMembers; } + public CollectionMeetingCalendar getCollectionMeetingCalendar() { + return collectionMeetingCalendar; + } + public void setAdditionalProperties(Map additionalProperties) { this.additionalProperties = additionalProperties; } diff --git a/mifosng-android/src/main/java/com/mifos/utils/DateHelper.java b/mifosng-android/src/main/java/com/mifos/utils/DateHelper.java index 4a23820797b..69c9b5584fd 100644 --- a/mifosng-android/src/main/java/com/mifos/utils/DateHelper.java +++ b/mifosng-android/src/main/java/com/mifos/utils/DateHelper.java @@ -16,6 +16,7 @@ */ public class DateHelper { + public static String getCurrentDateAsString(){ Calendar calendar = Calendar.getInstance(); @@ -54,50 +55,6 @@ public static String getDateAsStringUsedForCollectionSheetPayload(String date) { //Return as dd-mmm-yyyy } - /* public static String getMonthName(int month) { - String monthName = ""; - switch (month) { - case 1: - monthName = "Jan"; - break; - case 2: - monthName = "Feb"; - break; - case 3: - monthName = "Mar"; - break; - case 4: - monthName = "Apr"; - break; - case 5: - monthName = "May"; - break; - case 6: - monthName = "Jun"; - break; - case 7: - monthName = "Jul"; - break; - case 8: - monthName = "Aug"; - break; - case 9: - monthName = "Sep"; - break; - case 10: - monthName = "Oct"; - break; - case 11: - monthName = "Nov"; - break; - case 12: - monthName = "Dec"; - break; - } - return monthName; - }*/ - - //Currently supports on "dd MM yyyy" public static String getCurrentDateAsDateFormat() { @@ -177,7 +134,6 @@ public static int dateComparator(List date1, List date2) { } } - public static String getMonthName(int month) { String monthName = ""; switch (month) {