Skip to content
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

Revert "Sync for Centers" #722

Closed
wants to merge 1 commit into from
Closed
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
Revert "Sync for Centers"
therajanmaurya authored Jul 25, 2017
commit f748798e0c993aa698a01553a999c61ce48f48fc
Original file line number Diff line number Diff line change
@@ -3,7 +3,6 @@
import com.mifos.api.BaseApiManager;
import com.mifos.api.GenericResponse;
import com.mifos.api.local.databasehelper.DatabaseHelperCenter;
import com.mifos.objects.accounts.CenterAccounts;
import com.mifos.objects.client.ActivatePayload;
import com.mifos.objects.client.Page;
import com.mifos.objects.group.Center;
@@ -19,7 +18,6 @@
import javax.inject.Singleton;

import rx.Observable;
import rx.functions.Func1;

/**
* This DataManager is for Managing Center API, In which Request is going to Server
@@ -75,34 +73,6 @@ public Observable<Page<Center>> getCenters(boolean paged, int offset, int limit)
}
}

/**
* This method save the single Center in Database.
*
* @param center Center
* @return Center
*/
public Observable<Center> syncCenterInDatabase(Center center) {
return mDatabaseHelperCenter.saveCenter(center);
}

/**
* This Method Fetching the Center Accounts (Loan, saving, etc Accounts ) from REST API
* and then Saving all Accounts into the Database and then returns the Center Group Accounts
*
* @param centerId Center Id
* @return CenterAccounts
*/
public Observable<CenterAccounts> syncCenterAccounts(final int centerId) {
return mBaseApiManager.getCenterApi().getCenterAccounts(centerId)
.concatMap(new Func1<CenterAccounts, Observable<? extends CenterAccounts>>() {
@Override
public Observable<? extends CenterAccounts> call(CenterAccounts
centerAccounts) {
return mDatabaseHelperCenter.saveCenterAccounts(centerAccounts, centerId);
}
});
}

/**
* Method Fetching CollectionSheet of the Center from :
* demo.openmf.org/fineract-provider/api/v1/centers/{centerId}
@@ -132,36 +102,6 @@ public Observable<SaveResponse> createCenter(CenterPayload centerPayload) {
}
}

/**
* This Method Fetch the Groups that are attached to the Centers.
* @param centerId Center Id
* @return CenterWithAssociations
*/
public Observable<CenterWithAssociations> getCenterWithAssociations(int centerId) {
switch (PrefManager.getUserStatus()) {
case 0:
return mBaseApiManager.getCenterApi().getAllGroupsForCenter(centerId);
case 1:
/**
* Return Groups from DatabaseHelperGroups.
*/
return mDatabaseHelperCenter.getCenterAssociateGroups(centerId);

default:
return Observable.just(new CenterWithAssociations());
}
}

/**
* This Method Request to the DatabaseHelperCenter and DatabaseHelperCenter Read the All
* centers from Center_Table and give the response Page of List of Center
*
* @return Page of Center List
*/
public Observable<Page<Center>> getAllDatabaseCenters() {
return mDatabaseHelperCenter.readAllCenters();
}

public Observable<List<Office>> getOffices() {
return mBaseApiManager.getOfficeApi().getAllOffices();
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -3,15 +3,8 @@
import android.os.AsyncTask;
import android.support.annotation.Nullable;

import com.mifos.objects.accounts.CenterAccounts;
import com.mifos.objects.accounts.loan.LoanAccount;
import com.mifos.objects.accounts.savings.SavingsAccount;
import com.mifos.objects.client.Page;
import com.mifos.objects.group.Center;
import com.mifos.objects.group.CenterDate;
import com.mifos.objects.group.CenterWithAssociations;
import com.mifos.objects.group.Group;
import com.mifos.objects.group.Group_Table;
import com.mifos.objects.response.SaveResponse;
import com.mifos.services.data.CenterPayload;
import com.mifos.services.data.CenterPayload_Table;
@@ -105,53 +98,6 @@ public Observable<List<CenterPayload>> call() {
});
}

/**
* This Method Fetch the Groups that are attached to the Center.
* @param centerId Center Id
* @return CenterWithAssociations
*/

public Observable<CenterWithAssociations> getCenterAssociateGroups(final int centerId) {
return Observable.defer(new Func0<Observable<CenterWithAssociations>>() {
@Override
public Observable<CenterWithAssociations> call() {

List<Group> groups = SQLite.select()
.from(Group.class)
.where(Group_Table.centerId.eq(centerId))
.queryList();
CenterWithAssociations centerWithAssociations = new CenterWithAssociations();
centerWithAssociations.setGroupMembers(groups);

return Observable.just(centerWithAssociations);
}
});
}

/**
* This Method Saving the Single Center in the Database
*
* @param center
* @return Observable.just(Center)
*/
public Observable<Center> saveCenter(final Center center) {
return Observable.defer(new Func0<Observable<Center>>() {
@Override
public Observable<Center> call() {

if (center.getActivationDate().size() != 0) {
CenterDate centerDate = new CenterDate(center.getId(), 0,
center.getActivationDate().get(0),
center.getActivationDate().get(1),
center.getActivationDate().get(2));
center.setCenterDate(centerDate);
}
center.save();
return Observable.just(center);
}
});
}

/**
* This Method for deleting the center payload from the Database according to Id and
* again fetch the center List from the Database CenterPayload_Table
@@ -182,42 +128,4 @@ public Observable<CenterPayload> call() {
}
});
}

/**
* This Method write the CenterAccounts in tho DB. According to Schema Defined in Model
*
* @param centerAccounts Model of List of LoanAccount and SavingAccount
* @param centerId Center Id
* @return CenterAccounts
*/
public Observable<CenterAccounts> saveCenterAccounts(final CenterAccounts centerAccounts,
final int centerId) {

return Observable.defer(new Func0<Observable<CenterAccounts>>() {
@Override
public Observable<CenterAccounts> call() {

List<LoanAccount> loanAccounts = centerAccounts.getLoanAccounts();
List<SavingsAccount> savingsAccounts = centerAccounts.getSavingsAccounts();
List<LoanAccount> memberLoanAccounts = centerAccounts.getMemberLoanAccounts();

for (LoanAccount loanAccount : loanAccounts) {
loanAccount.setCenterId(centerId);
loanAccount.save();
}

for (SavingsAccount savingsAccount : savingsAccounts) {
savingsAccount.setCenterId(centerId);
savingsAccount.save();
}

for (LoanAccount memberLoanAccount : memberLoanAccounts) {
memberLoanAccount.setCenterId(centerId);
memberLoanAccount.save();
}

return Observable.just(centerAccounts);
}
});
}
}
Original file line number Diff line number Diff line change
@@ -8,7 +8,6 @@
import com.mifos.api.model.APIEndPoint;
import com.mifos.api.model.CollectionSheetPayload;
import com.mifos.api.model.Payload;
import com.mifos.objects.accounts.CenterAccounts;
import com.mifos.objects.client.ActivatePayload;
import com.mifos.objects.response.SaveResponse;
import com.mifos.objects.client.Page;
@@ -40,9 +39,6 @@ Observable<Page<Center>> getCenters(@Query("paged") boolean b,
@Query("offset") int offset,
@Query("limit") int limit);

@GET(APIEndPoint.CENTERS + "/{centerId}/accounts")
Observable<CenterAccounts> getCenterAccounts(@Path("centerId") int centerId);

@GET(APIEndPoint.CENTERS + "/{centerId}?associations=groupMembers,collectionMeetingCalendar")
Observable<CenterWithAssociations> getCenterWithGroupMembersAndCollectionMeetingCalendar
(@Path("centerId") int centerId);
Original file line number Diff line number Diff line change
@@ -6,18 +6,13 @@
package com.mifos.mifosxdroid.adapters;

import android.content.Context;
import android.graphics.Color;
import android.support.v4.content.ContextCompat;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.mifos.mifosxdroid.R;
import com.mifos.mifosxdroid.core.SelectableAdapter;
import com.mifos.mifosxdroid.views.CircularImageView;
import com.mifos.objects.group.Center;
import com.mifos.utils.Utils;
@@ -33,7 +28,7 @@
/**
* Created by ishankhanna on 11/03/14.
*/
public class CentersListAdapter extends SelectableAdapter<RecyclerView.ViewHolder> {
public class CentersListAdapter extends RecyclerView.Adapter<CentersListAdapter.ViewHolder> {

private List<Center> centers;
private Context context;
@@ -51,38 +46,28 @@ public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
}

@Override
public void onBindViewHolder(final RecyclerView.ViewHolder holder, int position) {
if (holder instanceof ViewHolder) {
Center center = centers.get(position);

((ViewHolder) holder).tvAccountNumber.setText(String.format(context.
getString(R.string.centerList_account_prefix), center.getAccountNo()));
((ViewHolder) holder).tvCenterId.setText(String.valueOf(center.getId()));
((ViewHolder) holder).tvCenterName.setText(center.getName());
if (center.getStaffId() != null) {
((ViewHolder) holder).tvStaffId.setText(String.valueOf(center.getStaffId()));
((ViewHolder) holder).tvStaffName.setText(center.getStaffName());
} else {
((ViewHolder) holder).tvStaffId.setText("");
((ViewHolder) holder).tvStaffName.setText(R.string.no_staff);
}
((ViewHolder) holder).tvOfficeId.setText(String.valueOf(center.getOfficeId()));
((ViewHolder) holder).tvOfficeName.setText(center.getOfficeName());
if (center.getActive()) {
((ViewHolder) holder).ivStatusIndicator.setImageDrawable(
Utils.setCircularBackground(R.color.light_green, context));
} else {
((ViewHolder) holder).ivStatusIndicator.setImageDrawable(
Utils.setCircularBackground(R.color.light_red, context));
}

//Changing the Color of Selected Centers
((ViewHolder) holder).viewSelectedOverlay
.setBackgroundColor(isSelected(position) ? ContextCompat.getColor(context,
R.color.gray_light) : Color.WHITE);

((ViewHolder) holder).ivSyncStatus
.setVisibility(center.isSync() ? View.VISIBLE : View.INVISIBLE);
public void onBindViewHolder(ViewHolder holder, int position) {
Center center = centers.get(position);

holder.tvAccountNumber.setText(String.format(context.
getString(R.string.centerList_account_prefix), center.getAccountNo()));
holder.tvCenterId.setText(String.valueOf(center.getId()));
holder.tvCenterName.setText(center.getName());
if (center.getStaffId() != null) {
holder.tvStaffId.setText(String.valueOf(center.getStaffId()));
holder.tvStaffName.setText(center.getStaffName());
} else {
holder.tvStaffId.setText("");
holder.tvStaffName.setText(R.string.no_staff);
}
holder.tvOfficeId.setText(String.valueOf(center.getOfficeId()));
holder.tvOfficeName.setText(center.getOfficeName());
if (center.getActive()) {
holder.ivStatusIndicator.setImageDrawable(
Utils.setCircularBackground(R.color.light_green, context));
} else {
holder.ivStatusIndicator.setImageDrawable(
Utils.setCircularBackground(R.color.light_red, context));
}
}

@@ -136,12 +121,6 @@ public static class ViewHolder extends RecyclerView.ViewHolder {
@BindView(R.id.tv_office_id)
TextView tvOfficeId;

@BindView(R.id.linearLayout)
LinearLayout viewSelectedOverlay;

@BindView(R.id.iv_sync_status)
ImageView ivSyncStatus;

public ViewHolder(View v) {
super(v);
ButterKnife.bind(this, v);
Loading