Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 12 additions & 8 deletions mifosng-android/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -112,16 +112,20 @@
android:screenOrientation="portrait" />

<activity android:name=".offline.syncclientpayloads.SyncClientPayloadActivity"
android:label="@string/sync_clients"
android:screenOrientation="portrait" />
android:label="@string/sync_clients"
android:screenOrientation="portrait" />

<activity android:name=".offline.syncgrouppayloads.SyncGroupPayloadsActivity"
android:label="@string/sync_groups"
android:screenOrientation="portrait" />
android:label="@string/sync_groups"
android:screenOrientation="portrait" />

<activity android:name=".offline.synccenterpayloads.SyncCenterPayloadActivity"
android:label="@string/sync_centers"
android:screenOrientation="portrait" />

<activity android:name=".offline.syncloanrepaymenttransacition.SyncLoanRepaymentTransactionActivity"
android:label="@string/sync_loanrepayments"
android:screenOrientation="portrait" />
android:label="@string/sync_loanrepayments"
android:screenOrientation="portrait" />

<activity
android:name=".offline.syncsavingsaccounttransaction.SyncSavingsAccountTransactionActivity"
Expand All @@ -130,8 +134,8 @@


<service android:name=".activity.pathtracking.PathTrackingService"
android:exported="false"/>
android:exported="false"/>

</application>

</manifest>
</manifest>
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public Observable<Page<Center>> getCenters(boolean paged, int offset, int limit)
/**
* Return All Centers List from DatabaseHelperCenter only one time.
* If offset is zero this means this is first request and
* return all clients from DatabaseHelperCenter
* return all centers from DatabaseHelperCenter
*/
if (offset == 0)
return mDatabaseHelperCenter.readAllCenters();
Expand All @@ -88,13 +88,55 @@ public Observable<CenterWithAssociations> getCentersGroupAndMeeting(int id) {
}

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() {
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
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,5 @@ public class MifosDatabase {
public static final String NAME = "Mifos";

//Always Increase the Version Number
public static final int VERSION = 1;
public static final int VERSION = 2;
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,20 @@

import com.mifos.objects.client.Page;
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 java.util.List;

import javax.inject.Inject;
import javax.inject.Singleton;

import rx.Observable;
import rx.Subscriber;
import rx.functions.Func0;

/**
* Created by Rajan Maurya on 28/6/16.
Expand Down Expand Up @@ -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);
}
});
}
}
Original file line number Diff line number Diff line change
@@ -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);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import com.mifos.mifosxdroid.injection.module.ActivityModule;
import com.mifos.mifosxdroid.login.LoginActivity;
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.syncgrouppayloads.SyncGroupPayloadsFragment;
import com.mifos.mifosxdroid.offline.syncloanrepaymenttransacition.SyncLoanRepaymentTransactionFragment;
Expand Down Expand Up @@ -145,6 +146,8 @@ public interface ActivityComponent {

void inject(SyncGroupPayloadsFragment syncGroupPayloadsFragment);

void inject(SyncCenterPayloadsFragment syncCenterPayloadsFragment);

void inject(OfflineDashboardFragment offlineDashboardFragment);

void inject(SyncLoanRepaymentTransactionFragment syncLoanRepaymentTransactionFragment);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import com.mifos.mifosxdroid.core.MifosBaseFragment;
import com.mifos.mifosxdroid.core.RecyclerItemClickListener;
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.syncgrouppayloads.SyncGroupPayloadsActivity;
import com.mifos.mifosxdroid.offline.syncloanrepaymenttransacition.SyncLoanRepaymentTransactionActivity;
Expand All @@ -30,6 +31,7 @@
import com.mifos.objects.accounts.savings.SavingsAccountTransactionRequest;
import com.mifos.objects.client.ClientPayload;
import com.mifos.objects.group.GroupPayload;
import com.mifos.services.data.CenterPayload;
import com.mifos.utils.ItemOffsetDecoration;

import java.util.ArrayList;
Expand Down Expand Up @@ -90,14 +92,16 @@ public class OfflineDashboardFragment extends MifosBaseFragment implements
OfflineDashboardAdapter mOfflineDashboardAdapter;

// 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 List<Class> mPayloadClasses;

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};


Expand Down Expand Up @@ -155,10 +159,11 @@ public void onStart() {
super.onStart();
mOfflineDashboardAdapter.removeAllCards();
mPayloadClasses.clear();
mPayloadIndex = 4;
mPayloadIndex = 5;

mOfflineDashboardPresenter.loadDatabaseClientPayload();
mOfflineDashboardPresenter.loadDatabaseGroupPayload();
mOfflineDashboardPresenter.loadDatabaseCenterPayload();
mOfflineDashboardPresenter.loadDatabaseLoanRepaymentTransactions();
mOfflineDashboardPresenter.loadDatabaseSavingsAccountTransactions();
}
Expand Down Expand Up @@ -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
Expand All @@ -217,7 +241,7 @@ public void showLoanRepaymentTransactions(List<LoanRepaymentRequest> loanRepayme
if (loanRepaymentRequests.size() != 0) {
mOfflineDashboardAdapter.showCard(getActivity().getResources()
.getString(R.string.transactions_count) +
loanRepaymentRequests.size(), SYNC_CARD_UI_NAMES[2]);
loanRepaymentRequests.size(), SYNC_CARD_UI_NAMES[3]);
mPayloadClasses.add(SyncLoanRepaymentTransactionActivity.class);
} else {
mPayloadIndex = mPayloadIndex - 1;
Expand All @@ -238,7 +262,7 @@ public void showSavingsAccountTransaction(List<SavingsAccountTransactionRequest>
if (transactions.size() != 0) {
mOfflineDashboardAdapter.showCard(getActivity().getResources()
.getString(R.string.transactions_count) +
transactions.size(), SYNC_CARD_UI_NAMES[3]);
transactions.size(), SYNC_CARD_UI_NAMES[4]);
mPayloadClasses.add(SyncSavingsAccountTransactionActivity.class);
} else {
mPayloadIndex = mPayloadIndex - 1;
Expand Down
Loading