diff --git a/mifosng-android/src/main/java/com/mifos/mifosxdroid/adapters/ClientListAdapter.java b/mifosng-android/src/main/java/com/mifos/mifosxdroid/adapters/ClientListAdapter.java index f3d6998b42b..4d05b02a03b 100644 --- a/mifosng-android/src/main/java/com/mifos/mifosxdroid/adapters/ClientListAdapter.java +++ b/mifosng-android/src/main/java/com/mifos/mifosxdroid/adapters/ClientListAdapter.java @@ -14,16 +14,14 @@ import android.widget.EditText; import android.widget.TextView; import android.widget.Toast; - +import butterknife.ButterKnife; +import butterknife.InjectView; import com.mifos.mifosxdroid.R; import com.mifos.objects.db.Loan; import java.util.List; import java.util.Map; -import butterknife.ButterKnife; -import butterknife.InjectView; - public class ClientListAdapter extends BaseAdapter { @@ -114,13 +112,17 @@ public void onFocusChange(View v, boolean hasFocus) { try { double changedValue = Double.parseDouble(((EditText) v).getText().toString()); listPaidAmounts.put(loan, changedValue); - loan.totalDue = changedValue; - loan.save(); - notifyDataSetChanged(); + if (loan.totalDue != changedValue) { + loan.totalDue = changedValue; + loan.save(); + notifyDataSetChanged(); + } } catch (NumberFormatException e) { Toast.makeText(context, context.getString(R.string.error_invalid_amount), Toast.LENGTH_SHORT).show(); } } } } + + } \ No newline at end of file diff --git a/mifosng-android/src/main/java/com/mifos/mifosxdroid/fragments/CenterListFragment.java b/mifosng-android/src/main/java/com/mifos/mifosxdroid/fragments/CenterListFragment.java index f14d1513aa0..9a34408125f 100644 --- a/mifosng-android/src/main/java/com/mifos/mifosxdroid/fragments/CenterListFragment.java +++ b/mifosng-android/src/main/java/com/mifos/mifosxdroid/fragments/CenterListFragment.java @@ -11,49 +11,28 @@ import android.os.Bundle; import android.support.v4.app.Fragment; import android.util.Log; -import android.view.LayoutInflater; -import android.view.Menu; -import android.view.MenuInflater; -import android.view.MenuItem; -import android.view.View; -import android.view.ViewGroup; -import android.widget.AdapterView; -import android.widget.ListView; -import android.widget.ProgressBar; -import android.widget.TextView; -import android.widget.Toast; - +import android.view.*; +import android.widget.*; +import butterknife.ButterKnife; +import butterknife.InjectView; import com.mifos.mifosxdroid.GroupActivity; +import com.mifos.mifosxdroid.LoginActivity; import com.mifos.mifosxdroid.OfflineCenterInputActivity; import com.mifos.mifosxdroid.R; import com.mifos.mifosxdroid.adapters.CenterAdapter; -import com.mifos.objects.db.AttendanceType; -import com.mifos.objects.db.Client; -import com.mifos.objects.db.CollectionMeetingCalendar; -import com.mifos.objects.db.Currency; -import com.mifos.objects.db.EntityType; -import com.mifos.objects.db.Loan; -import com.mifos.objects.db.MeetingCenter; -import com.mifos.objects.db.MeetingDate; -import com.mifos.objects.db.MifosGroup; -import com.mifos.objects.db.OfflineCenter; -import com.mifos.objects.db.RepaymentTransaction; -import com.mifos.objects.db.Status; +import com.mifos.objects.db.*; import com.mifos.services.API; import com.mifos.utils.DateHelper; import com.mifos.utils.Network; import com.mifos.utils.SaveOfflineDataHelper; import com.orm.query.Select; - -import java.util.ArrayList; -import java.util.List; - -import butterknife.ButterKnife; -import butterknife.InjectView; import retrofit.Callback; import retrofit.RetrofitError; import retrofit.client.Response; +import java.util.ArrayList; +import java.util.List; + public class CenterListFragment extends Fragment implements AdapterView.OnItemClickListener, SaveOfflineDataHelper.OfflineDataSaveListener { @@ -125,13 +104,15 @@ private List getAllCenters() { private void getData() { if (Network.isOnline(getActivity().getApplicationContext())) { + String dateFormant = "dd-MMM-yyyy"; + String locale = "en"; SharedPreferences preferences = getActivity().getSharedPreferences(OfflineCenterInputActivity.PREF_CENTER_DETAILS, Context.MODE_PRIVATE); int staffId = preferences.getInt(OfflineCenterInputActivity.STAFF_ID_KEY, -1); String meetingDate = DateHelper.getDateAsStringUsedForCollectionSheetPayload(preferences.getString(OfflineCenterInputActivity.TRANSACTION_DATE_KEY, null)); int branchId = preferences.getInt(OfflineCenterInputActivity.BRANCH_ID_KEY, -1); Log.i(TAG, "staffId:" + staffId + ", meetingDate: " + meetingDate + " , branchId:" + branchId); - //TODO -- Need to ask --- Hardcoding date format and locale - API.centerService.getCenterList("dd-MMM-yyyy", "en", meetingDate, branchId, staffId, + //TODO -- Need to ask --- Hard coding date format and locale + API.centerService.getCenterList(dateFormant, locale, meetingDate, branchId, staffId, new Callback>() { @Override public void success(List centers, Response response) { @@ -152,7 +133,10 @@ public void success(List centers, Response response) { @Override public void failure(RetrofitError error) { - + Toast.makeText(getActivity(), "Please login to continue", Toast.LENGTH_LONG).show(); + getActivity().finish(); + Intent intent = new Intent(getActivity(), LoginActivity.class); + startActivity(intent); } }); } @@ -187,9 +171,8 @@ private void startCenterInputActivity() { SharedPreferences.Editor editor = preferences.edit(); editor.clear(); editor.commit(); - Toast.makeText(getActivity(), "These is no data this input, please re-enter the details", Toast.LENGTH_LONG).show(); + Toast.makeText(getActivity(), "Offline data has been cleared.", Toast.LENGTH_LONG).show(); getActivity().finish(); - ; startActivity(new Intent(getActivity(), OfflineCenterInputActivity.class)); } diff --git a/mifosng-android/src/main/java/com/mifos/mifosxdroid/fragments/GroupFragment.java b/mifosng-android/src/main/java/com/mifos/mifosxdroid/fragments/GroupFragment.java index 9dcbb58ca53..751e422c704 100644 --- a/mifosng-android/src/main/java/com/mifos/mifosxdroid/fragments/GroupFragment.java +++ b/mifosng-android/src/main/java/com/mifos/mifosxdroid/fragments/GroupFragment.java @@ -12,18 +12,10 @@ import android.support.v4.app.Fragment; import android.support.v4.view.MenuItemCompat; import android.util.Log; -import android.view.LayoutInflater; -import android.view.Menu; -import android.view.MenuInflater; -import android.view.MenuItem; -import android.view.View; -import android.view.ViewGroup; -import android.widget.AdapterView; -import android.widget.ListView; -import android.widget.ProgressBar; -import android.widget.TextView; -import android.widget.Toast; - +import android.view.*; +import android.widget.*; +import butterknife.ButterKnife; +import butterknife.InjectView; import com.mifos.mifosxdroid.ClientActivity; import com.mifos.mifosxdroid.OfflineCenterInputActivity; import com.mifos.mifosxdroid.R; @@ -37,9 +29,6 @@ import java.util.ArrayList; import java.util.List; -import butterknife.ButterKnife; -import butterknife.InjectView; - public class GroupFragment extends Fragment implements AdapterView.OnItemClickListener, RepaymentTransactionSyncService.SyncFinishListener { @@ -128,7 +117,6 @@ private void setAdapter() { private List getAllGroups() { return Select.from(MifosGroup.class).where(Condition.prop("center_id").eq(centerId)).list(); - //return Select.from(MifosGroup.class).list(); } @Override @@ -143,16 +131,9 @@ public void onItemClick(AdapterView adapterView, View view, int i, long l) { public void onSyncFinish(String message, boolean isSyncable) { MenuItemCompat.setActionView(syncItem, null); Toast.makeText(getActivity(), message, Toast.LENGTH_SHORT).show(); - if (!isSyncable) { - SharedPreferences preferences = getActivity().getSharedPreferences(OfflineCenterInputActivity.PREF_CENTER_DETAILS, Context.MODE_PRIVATE); - SharedPreferences.Editor editor = preferences.edit(); - editor.clear(); - editor.commit(); - getActivity().finish(); - Intent intent = new Intent(getActivity(), OfflineCenterInputActivity.class); - startActivity(intent); - } else + if (isSyncable) { setCenterAsSynced(); + } } private void setCenterAsSynced() { @@ -160,6 +141,7 @@ private void setCenterAsSynced() { List center = Select.from(MeetingCenter.class).where(com.orm.query.Condition.prop("center_id").eq(centerId)).list(); center.get(0).setIsSynced(1); center.get(0).save(); + getActivity().finish(); } } } diff --git a/mifosng-android/src/main/java/com/mifos/objects/db/CollectionMeetingCalendar.java b/mifosng-android/src/main/java/com/mifos/objects/db/CollectionMeetingCalendar.java index fdd973fa110..7322faab2c8 100644 --- a/mifosng-android/src/main/java/com/mifos/objects/db/CollectionMeetingCalendar.java +++ b/mifosng-android/src/main/java/com/mifos/objects/db/CollectionMeetingCalendar.java @@ -17,6 +17,7 @@ public class CollectionMeetingCalendar extends SugarRecord { private int calendarInstanceId; + private long calendarId; private int entityId; private EntityType entityType; private String title; @@ -33,6 +34,14 @@ public boolean isNew() { return count == 0; } + public long getCalendarId() { + return calendarId; + } + + public void setCalendarId(long calendarId) { + this.calendarId = calendarId; + } + public MeetingDate getMeetingCalendarDate() { return meetingCalendarDate; } diff --git a/mifosng-android/src/main/java/com/mifos/services/RepaymentTransactionSyncService.java b/mifosng-android/src/main/java/com/mifos/services/RepaymentTransactionSyncService.java index a09ca933879..34919d7f40e 100644 --- a/mifosng-android/src/main/java/com/mifos/services/RepaymentTransactionSyncService.java +++ b/mifosng-android/src/main/java/com/mifos/services/RepaymentTransactionSyncService.java @@ -9,32 +9,26 @@ import android.content.SharedPreferences; import android.os.AsyncTask; import android.util.Log; - import com.mifos.mifosxdroid.OfflineCenterInputActivity; -import com.mifos.objects.db.AttendanceType; -import com.mifos.objects.db.Client; -import com.mifos.objects.db.Currency; -import com.mifos.objects.db.Loan; -import com.mifos.objects.db.MifosGroup; -import com.mifos.objects.db.RepaymentTransaction; +import com.mifos.objects.db.*; import com.mifos.services.data.BulkRepaymentTransactions; import com.mifos.services.data.CollectionSheetPayload; import com.mifos.services.data.SaveResponse; import com.mifos.utils.Constants; +import com.mifos.utils.DateHelper; import com.mifos.utils.Network; import com.orm.query.Select; +import retrofit.RetrofitError; import java.util.ArrayList; import java.util.List; -import retrofit.RetrofitError; - public class RepaymentTransactionSyncService { private static final String TAG = RepaymentTransactionSyncService.class.getSimpleName(); + private final String tag = getClass().getSimpleName(); private SyncFinishListener syncFinishListener; private long centerId; - public RepaymentTransactionSyncService(SyncFinishListener syncFinishListener, long centerId) { this.syncFinishListener = syncFinishListener; this.centerId = centerId; @@ -43,13 +37,15 @@ public RepaymentTransactionSyncService(SyncFinishListener syncFinishListener, lo public void syncRepayments() { List transactions = Select.from(RepaymentTransaction.class).list(); Log.i(TAG, "Fetching transactions from Database:" + transactions); - + List centerList = Select.from(MeetingCenter.class).where(com.orm.query.Condition.prop("center_id").eq(centerId)).list(); + MeetingCenter center = centerList.get(0); if (transactions.size() > 0) { List repaymentTransactions = new ArrayList(); for (RepaymentTransaction transaction : transactions) { Loan loan = transaction.getLoan(); - if (loan.getAccountStatusId() == 300) { + if (loan.getAccountStatusId() == 300) //ToDO need to ask about hard coding + { repaymentTransactions.add(new BulkRepaymentTransactions(loan.getLoanId(), transaction.getTransactionAmount())); } } @@ -60,7 +56,8 @@ public void syncRepayments() { CollectionSheetPayload payload = new CollectionSheetPayload(); payload.bulkRepaymentTransactions = repaymentTransactionArray; - + payload.setCalendarId(center.getCollectionMeetingCalendar().getCalendarId()); + payload.setTransactionDate(DateHelper.getPayloadDate()); SaveCollectionSheetTask task = new SaveCollectionSheetTask(); task.execute(payload); } else @@ -81,6 +78,7 @@ public interface SyncFinishListener { } private class SaveCollectionSheetTask extends AsyncTask { + private boolean isResponseNull = false; @Override protected void onPreExecute() { super.onPreExecute(); @@ -98,12 +96,12 @@ protected Void doInBackground(CollectionSheetPayload... collectionSheetPayloads) SharedPreferences.Editor editor = preferences.edit(); editor.clear(); editor.commit(); - // deleteAllOfflineCollectionSheetData(); - } + } else + isResponseNull = true; } catch (RetrofitError error) { - + isResponseNull = true; } catch (Exception ex) { - + isResponseNull = true; } } return null; @@ -112,7 +110,10 @@ protected Void doInBackground(CollectionSheetPayload... collectionSheetPayloads) @Override protected void onPostExecute(Void aVoid) { super.onPostExecute(aVoid); - syncFinishListener.onSyncFinish("Sync is completed successfully", true); + if (!isResponseNull) + syncFinishListener.onSyncFinish("Sync is completed successfully", true); + else + syncFinishListener.onSyncFinish("Couldn't sync the data, please try again", true); } } } diff --git a/mifosng-android/src/main/java/com/mifos/services/data/Payload.java b/mifosng-android/src/main/java/com/mifos/services/data/Payload.java index 39b9b5edc4f..7940128292d 100644 --- a/mifosng-android/src/main/java/com/mifos/services/data/Payload.java +++ b/mifosng-android/src/main/java/com/mifos/services/data/Payload.java @@ -9,7 +9,7 @@ public class Payload { private String dateFormat = "dd MMMM YYYY"; private String locale = "en"; - private int calendarId; + private long calendarId; private String transactionDate; public String getDateFormat() @@ -32,12 +32,12 @@ public void setLocale(String locale) this.locale = locale; } - public int getCalendarId() + public long getCalendarId() { return calendarId; } - public void setCalendarId(int calendarId) + public void setCalendarId(long calendarId) { this.calendarId = calendarId; } 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 69c9b5584fd..0f4434165dc 100644 --- a/mifosng-android/src/main/java/com/mifos/utils/DateHelper.java +++ b/mifosng-android/src/main/java/com/mifos/utils/DateHelper.java @@ -5,6 +5,10 @@ package com.mifos.utils; +import android.content.Context; +import android.content.SharedPreferences; +import com.mifos.mifosxdroid.OfflineCenterInputActivity; + import java.util.ArrayList; import java.util.Calendar; import java.util.List; @@ -177,4 +181,19 @@ public static String getMonthName(int month) { return monthName; } + public static String getPayloadDate() { + SharedPreferences preferences = Constants.applicationContext.getSharedPreferences(OfflineCenterInputActivity.PREF_CENTER_DETAILS, Context.MODE_PRIVATE); + String date = preferences.getString(OfflineCenterInputActivity.TRANSACTION_DATE_KEY, null); + final StringBuilder builder = new StringBuilder(); + if (date != null) { + String[] splittedDate = date.split("-"); + int month = Integer.parseInt(splittedDate[1]); + builder.append(splittedDate[0]); + builder.append(" "); + builder.append(DateHelper.getMonthName(month)); + builder.append(" "); + builder.append(splittedDate[2]); + } + return builder.toString(); + } } diff --git a/mifosng-android/src/main/java/com/mifos/utils/SaveOfflineDataHelper.java b/mifosng-android/src/main/java/com/mifos/utils/SaveOfflineDataHelper.java index cc370609780..ccf1bba94de 100644 --- a/mifosng-android/src/main/java/com/mifos/utils/SaveOfflineDataHelper.java +++ b/mifosng-android/src/main/java/com/mifos/utils/SaveOfflineDataHelper.java @@ -7,29 +7,19 @@ import android.content.Context; -import android.content.SharedPreferences; import android.util.Log; import android.widget.Toast; - -import com.mifos.mifosxdroid.OfflineCenterInputActivity; -import com.mifos.objects.db.CollectionMeetingCalendar; -import com.mifos.objects.db.CollectionSheet; -import com.mifos.objects.db.EntityType; -import com.mifos.objects.db.MeetingCenter; -import com.mifos.objects.db.MeetingDate; -import com.mifos.objects.db.OfflineCenter; -import com.mifos.objects.db.Status; +import com.mifos.objects.db.*; import com.mifos.services.API; import com.mifos.services.data.Payload; import com.orm.query.Select; - -import java.util.HashMap; -import java.util.List; - import retrofit.Callback; import retrofit.RetrofitError; import retrofit.client.Response; +import java.util.HashMap; +import java.util.List; + public class SaveOfflineDataHelper { private static final HashMap syncState; @@ -110,8 +100,7 @@ public void saveOfflineCenterData(Context context, OfflineCenter center) { collectionMeetingCalendar1.setRepeating(collectionMeetingCalendar.isRepeating()); collectionMeetingCalendar1.setTitle(collectionMeetingCalendar.getTitle()); collectionMeetingCalendar1.setEntityType(entityType); - //TODO this doesn't work why??? - // collectionMeetingCalendar1.setId(collectionMeetingCalendar.getId()); + collectionMeetingCalendar1.setCalendarId(collectionMeetingCalendar.getId()); collectionMeetingCalendar1.save(); MeetingCenter meetingCenter1 = new MeetingCenter(); @@ -144,20 +133,8 @@ public void saveOfflineCenterData(Context context, OfflineCenter center) { private Payload getPayload(Context context, MeetingCenter center) { final Payload payload = new Payload(); - SharedPreferences preferences = context.getSharedPreferences(OfflineCenterInputActivity.PREF_CENTER_DETAILS, Context.MODE_PRIVATE); - String date = preferences.getString(OfflineCenterInputActivity.TRANSACTION_DATE_KEY, null); - if (date != null) { - String[] splittedDate = date.split("-"); - int month = Integer.parseInt(splittedDate[1]); - final StringBuilder builder = new StringBuilder(); - builder.append(splittedDate[0]); - builder.append(" "); - builder.append(DateHelper.getMonthName(month)); - builder.append(" "); - builder.append(splittedDate[2]); - payload.setTransactionDate(builder.toString()); + payload.setTransactionDate(DateHelper.getPayloadDate()); payload.setCalendarId(center.getCollectionMeetingCalendar().getCalendarInstanceId()); - } return payload; } diff --git a/mifosng-android/src/main/res/layout/row_client_list_item.xml b/mifosng-android/src/main/res/layout/row_client_list_item.xml index c73880cfdd0..72e693f94af 100644 --- a/mifosng-android/src/main/res/layout/row_client_list_item.xml +++ b/mifosng-android/src/main/res/layout/row_client_list_item.xml @@ -41,7 +41,7 @@ android:layout_centerVertical="true" android:background="@drawable/rounded_background" android:gravity="left" - android:inputType="number" + android:inputType="numberDecimal" android:paddingLeft="5dp" android:text="460" android:textAppearance="?android:attr/textAppearanceMedium" />