New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Offline support for center creation #712

Merged
merged 1 commit into from Jul 9, 2017
Jump to file or symbol
Failed to load files and symbols.
+1,006 −30
Diff settings

Always

Just for now

@@ -112,16 +112,20 @@
android:screenOrientation="portrait" /> android:screenOrientation="portrait" />
<activity android:name=".offline.syncclientpayloads.SyncClientPayloadActivity" <activity android:name=".offline.syncclientpayloads.SyncClientPayloadActivity"
android:label="@string/sync_clients" android:label="@string/sync_clients"
android:screenOrientation="portrait" /> android:screenOrientation="portrait" />
<activity android:name=".offline.syncgrouppayloads.SyncGroupPayloadsActivity" <activity android:name=".offline.syncgrouppayloads.SyncGroupPayloadsActivity"
android:label="@string/sync_groups" android:label="@string/sync_groups"
android:screenOrientation="portrait" /> android:screenOrientation="portrait" />
<activity android:name=".offline.synccenterpayloads.SyncCenterPayloadActivity"
android:label="@string/sync_centers"
android:screenOrientation="portrait" />
<activity android:name=".offline.syncloanrepaymenttransacition.SyncLoanRepaymentTransactionActivity" <activity android:name=".offline.syncloanrepaymenttransacition.SyncLoanRepaymentTransactionActivity"
android:label="@string/sync_loanrepayments" android:label="@string/sync_loanrepayments"
android:screenOrientation="portrait" /> android:screenOrientation="portrait" />
<activity <activity
android:name=".offline.syncsavingsaccounttransaction.SyncSavingsAccountTransactionActivity" android:name=".offline.syncsavingsaccounttransaction.SyncSavingsAccountTransactionActivity"
@@ -130,8 +134,8 @@
<service android:name=".activity.pathtracking.PathTrackingService" <service android:name=".activity.pathtracking.PathTrackingService"
android:exported="false"/> android:exported="false"/>
</application> </application>
</manifest> </manifest>
@@ -63,7 +63,7 @@ public DataManagerCenter(BaseApiManager baseApiManager,
/** /**
* Return All Centers List from DatabaseHelperCenter only one time. * Return All Centers List from DatabaseHelperCenter only one time.
* If offset is zero this means this is first request and * If offset is zero this means this is first request and
* return all clients from DatabaseHelperCenter * return all centers from DatabaseHelperCenter
*/ */
if (offset == 0) if (offset == 0)
return mDatabaseHelperCenter.readAllCenters(); return mDatabaseHelperCenter.readAllCenters();
@@ -88,13 +88,55 @@ public DataManagerCenter(BaseApiManager baseApiManager,
} }
public Observable<SaveResponse> createCenter(CenterPayload centerPayload) { public Observable<SaveResponse> createCenter(CenterPayload centerPayload) {
return mBaseApiManager.getCenterApi().createCenter(centerPayload); switch (PrefManager.getUserStatus()) {
case 0:
return mBaseApiManager.getCenterApi().createCenter(centerPayload);
case 1:
/**
* Save CenterPayload in Database table.
*/
return mDatabaseHelperCenter.saveCenterPayload(centerPayload);
default:
return Observable.just(new SaveResponse());
}
} }
public Observable<List<Office>> getOffices() { public Observable<List<Office>> getOffices() {
return mBaseApiManager.getOfficeApi().getAllOffices(); return mBaseApiManager.getOfficeApi().getAllOffices();
} }
/**
* This method loading the all CenterPayloads from the Database.
*
* @return List<CenterPayload>
*/
public Observable<List<CenterPayload>> getAllDatabaseCenterPayload() {
return mDatabaseHelperCenter.readAllCenterPayload();
}
/**
* This method will called when user is syncing the Database center.
* whenever a center is synced then request goes to Database to delete that center form
* Database and reload the list from Database and update the list in UI
*
* @param id of the centerPayload in Database
* @return List<CenterPayload></>
*/
public Observable<List<CenterPayload>> deleteAndUpdateCenterPayloads(int id) {
return mDatabaseHelperCenter.deleteAndUpdateCenterPayloads(id);
}
/**
* This Method updating the CenterPayload in Database and return the same CenterPayload
*
* @param centerPayload CenterPayload
* @return CenterPayload
*/
public Observable<CenterPayload> updateCenterPayload(CenterPayload centerPayload) {
return mDatabaseHelperCenter.updateDatabaseCenterPayload(centerPayload);
}
/** /**
* This method is activating the center * This method is activating the center
* *
@@ -12,5 +12,5 @@
public static final String NAME = "Mifos"; public static final String NAME = "Mifos";
//Always Increase the Version Number //Always Increase the Version Number
public static final int VERSION = 1; public static final int VERSION = 2;
} }
@@ -5,13 +5,20 @@
import com.mifos.objects.client.Page; import com.mifos.objects.client.Page;
import com.mifos.objects.group.Center; import com.mifos.objects.group.Center;
import com.mifos.objects.response.SaveResponse;
import com.mifos.services.data.CenterPayload;
import com.mifos.services.data.CenterPayload_Table;
import com.raizlabs.android.dbflow.sql.language.Delete;
import com.raizlabs.android.dbflow.sql.language.SQLite; import com.raizlabs.android.dbflow.sql.language.SQLite;
import java.util.List;
import javax.inject.Inject; import javax.inject.Inject;
import javax.inject.Singleton; import javax.inject.Singleton;
import rx.Observable; import rx.Observable;
import rx.Subscriber; import rx.Subscriber;
import rx.functions.Func0;
/** /**
* Created by Rajan Maurya on 28/6/16. * Created by Rajan Maurya on 28/6/16.
@@ -69,4 +76,56 @@ public void call(Subscriber<? super Page<Center>> subscriber) {
} }
public Observable<SaveResponse> saveCenterPayload(final CenterPayload centerPayload) {
return Observable.defer(new Func0<Observable<SaveResponse>>() {
@Override
public Observable<SaveResponse> call() {
centerPayload.save();
return Observable.just(new SaveResponse());
}
});
}
public Observable<List<CenterPayload>> readAllCenterPayload() {
return Observable.defer(new Func0<Observable<List<CenterPayload>>>() {
@Override
public Observable<List<CenterPayload>> call() {
List<CenterPayload> centerPayloads = SQLite.select()
.from(CenterPayload.class)
.queryList();
return Observable.just(centerPayloads);
}
});
}
/**
* This Method for deleting the center payload from the Database according to Id and
* again fetch the center List from the Database CenterPayload_Table
* @param id is Id of the Center Payload in which reference center was saved into Database
* @return List<CenterPayload></>
*/
public Observable<List<CenterPayload>> deleteAndUpdateCenterPayloads(final int id) {
return Observable.defer(new Func0<Observable<List<CenterPayload>>>() {
@Override
public Observable<List<CenterPayload>> call() {
Delete.table(CenterPayload.class, CenterPayload_Table.id.eq(id));
List<CenterPayload> groupPayloads = SQLite.select()
.from(CenterPayload.class)
.queryList();
return Observable.just(groupPayloads);
}
});
}
public Observable<CenterPayload> updateDatabaseCenterPayload(
final CenterPayload centerPayload) {
return Observable.defer(new Func0<Observable<CenterPayload>>() {
@Override
public Observable<CenterPayload> call() {
centerPayload.update();
return Observable.just(centerPayload);
}
});
}
} }
@@ -0,0 +1,91 @@
package com.mifos.mifosxdroid.adapters;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import com.mifos.mifosxdroid.R;
import com.mifos.services.data.CenterPayload;
import java.util.ArrayList;
import java.util.List;
import javax.inject.Inject;
import butterknife.BindView;
import butterknife.ButterKnife;
/**
* Created by mayankjindal on 04/07/17.
*/
public class SyncCenterPayloadAdapter extends
RecyclerView.Adapter<SyncCenterPayloadAdapter.ViewHolder> {
private List<CenterPayload> mCenterPayloads;
@Inject
public SyncCenterPayloadAdapter() {
mCenterPayloads = new ArrayList<>();
}
@Override
public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View view = LayoutInflater.from(parent.getContext())
.inflate(R.layout.item_sync_center, parent, false);
return new ViewHolder(view);
}
@Override
public void onBindViewHolder(ViewHolder holder, int position) {
CenterPayload centerPayload = mCenterPayloads.get(position);
holder.tvName.setText(centerPayload.getName());
holder.tvOfficeId.setText(String.valueOf(centerPayload.getOfficeId()));
holder.tvActivationDate.setText(centerPayload.getActivationDate());
if (centerPayload.isActive()) {
holder.tvActiveStatus.setText(String.valueOf(true));
} else {
holder.tvActiveStatus.setText(String.valueOf(false));
}
if (mCenterPayloads.get(position).getErrorMessage() != null) {
holder.tvErrorMessage.setText(centerPayload.getErrorMessage());
holder.tvErrorMessage.setVisibility(View.VISIBLE);
}
}
@Override
public int getItemCount() {
return mCenterPayloads.size();
}
public void setCenterPayload(List<CenterPayload> centerPayload) {
mCenterPayloads = centerPayload;
notifyDataSetChanged();
}
public static class ViewHolder extends RecyclerView.ViewHolder {
@BindView(R.id.tv_db_name)
TextView tvName;
@BindView(R.id.tv_db_office_id)
TextView tvOfficeId;
@BindView(R.id.tv_db_activation_date)
TextView tvActivationDate;
@BindView(R.id.tv_db_active_status)
TextView tvActiveStatus;
@BindView(R.id.tv_error_message)
TextView tvErrorMessage;
public ViewHolder(View v) {
super(v);
ButterKnife.bind(this, v);
}
}
}
@@ -13,6 +13,7 @@
import com.mifos.mifosxdroid.injection.module.ActivityModule; import com.mifos.mifosxdroid.injection.module.ActivityModule;
import com.mifos.mifosxdroid.login.LoginActivity; import com.mifos.mifosxdroid.login.LoginActivity;
import com.mifos.mifosxdroid.offline.offlinedashbarod.OfflineDashboardFragment; import com.mifos.mifosxdroid.offline.offlinedashbarod.OfflineDashboardFragment;
import com.mifos.mifosxdroid.offline.synccenterpayloads.SyncCenterPayloadsFragment;
import com.mifos.mifosxdroid.offline.syncclientpayloads.SyncClientPayloadsFragment; import com.mifos.mifosxdroid.offline.syncclientpayloads.SyncClientPayloadsFragment;
import com.mifos.mifosxdroid.offline.syncgrouppayloads.SyncGroupPayloadsFragment; import com.mifos.mifosxdroid.offline.syncgrouppayloads.SyncGroupPayloadsFragment;
import com.mifos.mifosxdroid.offline.syncloanrepaymenttransacition.SyncLoanRepaymentTransactionFragment; import com.mifos.mifosxdroid.offline.syncloanrepaymenttransacition.SyncLoanRepaymentTransactionFragment;
@@ -145,6 +146,8 @@
void inject(SyncGroupPayloadsFragment syncGroupPayloadsFragment); void inject(SyncGroupPayloadsFragment syncGroupPayloadsFragment);
void inject(SyncCenterPayloadsFragment syncCenterPayloadsFragment);
void inject(OfflineDashboardFragment offlineDashboardFragment); void inject(OfflineDashboardFragment offlineDashboardFragment);
void inject(SyncLoanRepaymentTransactionFragment syncLoanRepaymentTransactionFragment); void inject(SyncLoanRepaymentTransactionFragment syncLoanRepaymentTransactionFragment);
@@ -20,6 +20,7 @@
import com.mifos.mifosxdroid.core.MifosBaseFragment; import com.mifos.mifosxdroid.core.MifosBaseFragment;
import com.mifos.mifosxdroid.core.RecyclerItemClickListener; import com.mifos.mifosxdroid.core.RecyclerItemClickListener;
import com.mifos.mifosxdroid.core.util.Toaster; import com.mifos.mifosxdroid.core.util.Toaster;
import com.mifos.mifosxdroid.offline.synccenterpayloads.SyncCenterPayloadActivity;
import com.mifos.mifosxdroid.offline.syncclientpayloads.SyncClientPayloadActivity; import com.mifos.mifosxdroid.offline.syncclientpayloads.SyncClientPayloadActivity;
import com.mifos.mifosxdroid.offline.syncgrouppayloads.SyncGroupPayloadsActivity; import com.mifos.mifosxdroid.offline.syncgrouppayloads.SyncGroupPayloadsActivity;
import com.mifos.mifosxdroid.offline.syncloanrepaymenttransacition.SyncLoanRepaymentTransactionActivity; import com.mifos.mifosxdroid.offline.syncloanrepaymenttransacition.SyncLoanRepaymentTransactionActivity;
@@ -30,6 +31,7 @@
import com.mifos.objects.accounts.savings.SavingsAccountTransactionRequest; import com.mifos.objects.accounts.savings.SavingsAccountTransactionRequest;
import com.mifos.objects.client.ClientPayload; import com.mifos.objects.client.ClientPayload;
import com.mifos.objects.group.GroupPayload; import com.mifos.objects.group.GroupPayload;
import com.mifos.services.data.CenterPayload;
import com.mifos.utils.ItemOffsetDecoration; import com.mifos.utils.ItemOffsetDecoration;
import java.util.ArrayList; import java.util.ArrayList;
@@ -90,14 +92,16 @@
OfflineDashboardAdapter mOfflineDashboardAdapter; OfflineDashboardAdapter mOfflineDashboardAdapter;
// update mPayloadIndex to number of request is going to fetch data in Presenter; // update mPayloadIndex to number of request is going to fetch data in Presenter;
private int mPayloadIndex = 4; private int mPayloadIndex = 5;
private static final int GRID_COUNT = 2; private static final int GRID_COUNT = 2;
private List<Class> mPayloadClasses; private List<Class> mPayloadClasses;
public static final int[] SYNC_CARD_UI_NAMES = {R.string.sync_clients, public static final int[] SYNC_CARD_UI_NAMES = {R.string.sync_clients,
R.string.sync_groups, R.string.sync_loanrepayments, R.string.sync_groups,
R.string.sync_centers,
R.string.sync_loanrepayments,
R.string.sync_savingsaccounttransactions}; R.string.sync_savingsaccounttransactions};
@@ -155,10 +159,11 @@ public void onStart() {
super.onStart(); super.onStart();
mOfflineDashboardAdapter.removeAllCards(); mOfflineDashboardAdapter.removeAllCards();
mPayloadClasses.clear(); mPayloadClasses.clear();
mPayloadIndex = 4; mPayloadIndex = 5;
mOfflineDashboardPresenter.loadDatabaseClientPayload(); mOfflineDashboardPresenter.loadDatabaseClientPayload();
mOfflineDashboardPresenter.loadDatabaseGroupPayload(); mOfflineDashboardPresenter.loadDatabaseGroupPayload();
mOfflineDashboardPresenter.loadDatabaseCenterPayload();
mOfflineDashboardPresenter.loadDatabaseLoanRepaymentTransactions(); mOfflineDashboardPresenter.loadDatabaseLoanRepaymentTransactions();
mOfflineDashboardPresenter.loadDatabaseSavingsAccountTransactions(); mOfflineDashboardPresenter.loadDatabaseSavingsAccountTransactions();
} }
@@ -203,6 +208,25 @@ public void showGroups(List<GroupPayload> groupPayloads) {
} }
} }
/**
* This method set the response of DataManager from DatabaseHelper that if List<CenterPayload>
* Size is zero, then decrease the value of mPayloadIndex by 1 and if size is not equal to zero
* the update the adapter and add the Card UI name and size() of the List to sync.
*
* @param centerPayloads List<CenterPayload> from DatabaseHelperGroup
*/
@Override
public void showCenters(List<CenterPayload> centerPayloads) {
if (centerPayloads.size() != 0) {
mOfflineDashboardAdapter.showCard(getActivity()
.getResources().getString(R.string.payloads_count) +
centerPayloads.size(), SYNC_CARD_UI_NAMES[2]);
mPayloadClasses.add(SyncCenterPayloadActivity.class);
} else {
mPayloadIndex = mPayloadIndex - 1;
showNoPayloadToShow();
}
}
/** /**
* This method set the response of DataManager from DatabaseHelper that if * This method set the response of DataManager from DatabaseHelper that if
@@ -217,7 +241,7 @@ public void showLoanRepaymentTransactions(List<LoanRepaymentRequest> loanRepayme
if (loanRepaymentRequests.size() != 0) { if (loanRepaymentRequests.size() != 0) {
mOfflineDashboardAdapter.showCard(getActivity().getResources() mOfflineDashboardAdapter.showCard(getActivity().getResources()
.getString(R.string.transactions_count) + .getString(R.string.transactions_count) +
loanRepaymentRequests.size(), SYNC_CARD_UI_NAMES[2]); loanRepaymentRequests.size(), SYNC_CARD_UI_NAMES[3]);
mPayloadClasses.add(SyncLoanRepaymentTransactionActivity.class); mPayloadClasses.add(SyncLoanRepaymentTransactionActivity.class);
} else { } else {
mPayloadIndex = mPayloadIndex - 1; mPayloadIndex = mPayloadIndex - 1;
@@ -238,7 +262,7 @@ public void showSavingsAccountTransaction(List<SavingsAccountTransactionRequest>
if (transactions.size() != 0) { if (transactions.size() != 0) {
mOfflineDashboardAdapter.showCard(getActivity().getResources() mOfflineDashboardAdapter.showCard(getActivity().getResources()
.getString(R.string.transactions_count) + .getString(R.string.transactions_count) +
transactions.size(), SYNC_CARD_UI_NAMES[3]); transactions.size(), SYNC_CARD_UI_NAMES[4]);
mPayloadClasses.add(SyncSavingsAccountTransactionActivity.class); mPayloadClasses.add(SyncSavingsAccountTransactionActivity.class);
} else { } else {
mPayloadIndex = mPayloadIndex - 1; mPayloadIndex = mPayloadIndex - 1;
Oops, something went wrong.
ProTip! Use n and p to navigate between commits in a pull request.