Skip to content

Commit

Permalink
Date Selection Completed
Browse files Browse the repository at this point in the history
  • Loading branch information
Ishan Khanna committed Jul 22, 2014
1 parent cd67922 commit 866cffd
Show file tree
Hide file tree
Showing 6 changed files with 59 additions and 61 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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<CenterWithAssociations>() {
@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;
}
});
Expand Down Expand Up @@ -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);

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<CollectionSheet>() {
@Override
Expand Down Expand Up @@ -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<SaveResponse>() {
@Override
public void success(SaveResponse saveResponse, Response response) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
*/
public class MFDatePicker extends DialogFragment implements DatePickerDialog.OnDateSetListener {

public static final String TAG = "MFDatePicker";
static String dateSet;
static Calendar calendar;

Expand All @@ -38,15 +39,15 @@ public class MFDatePicker extends DialogFragment implements DatePickerDialog.OnD
.toString();
}

OnDatePickListener mListener;
OnDatePickListener onDatePickListener;

public MFDatePicker(){

}

public static MFDatePicker newInsance(Fragment fragment) {
MFDatePicker mfDatePicker = new MFDatePicker();
mfDatePicker.mListener = (OnDatePickListener) fragment;
mfDatePicker.onDatePickListener = (OnDatePickListener) fragment;
return mfDatePicker;
}

Expand All @@ -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()
);

}
Expand All @@ -82,4 +83,10 @@ public interface OnDatePickListener {
public void onDatePicked(String date);
}

public void setOnDatePickListener(OnDatePickListener onDatePickListener) {
this.onDatePickListener = onDatePickListener;
}



}
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,10 @@ public void setGroupMembers(List<Group> groupMembers) {
this.groupMembers = groupMembers;
}

public CollectionMeetingCalendar getCollectionMeetingCalendar() {
return collectionMeetingCalendar;
}

public void setAdditionalProperties(Map<String, Object> additionalProperties) {
this.additionalProperties = additionalProperties;
}
Expand Down
46 changes: 1 addition & 45 deletions mifosng-android/src/main/java/com/mifos/utils/DateHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
*/
public class DateHelper {


public static String getCurrentDateAsString(){

Calendar calendar = Calendar.getInstance();
Expand Down Expand Up @@ -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() {
Expand Down Expand Up @@ -177,7 +134,6 @@ public static int dateComparator(List<Integer> date1, List<Integer> date2) {
}
}


public static String getMonthName(int month) {
String monthName = "";
switch (month) {
Expand Down

0 comments on commit 866cffd

Please sign in to comment.