Skip to content

Feature Offline #299

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

Merged
merged 31 commits into from
Jun 29, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
ffd1db0
CenterListFragment Instrumentation need rewrite
therajanmaurya Jun 23, 2016
27338b8
DBFlow version updated
therajanmaurya Jun 23, 2016
e210604
Client Model Annotation done
therajanmaurya Jun 23, 2016
bb6ead5
MifosBaseModel organized
therajanmaurya Jun 23, 2016
884e471
All Check Passing
therajanmaurya Jun 23, 2016
1f6442b
DatabaseHelper added
therajanmaurya Jun 23, 2016
3b27f71
DatabaseHelper added .
therajanmaurya Jun 23, 2016
2b1d04a
DataManager Architecure Implemented
therajanmaurya Jun 24, 2016
24a09f9
DataManager managed
therajanmaurya Jun 24, 2016
28bc823
User Status method added in Prefrence Manager class
therajanmaurya Jun 24, 2016
70321c9
Splitted DataManager in Multiple sub DataManager and DataManagerOffli…
therajanmaurya Jun 24, 2016
6f93234
DataManager and DatabaseHelper Layer setup complete
therajanmaurya Jun 25, 2016
2be07a5
stetho added and Saving Clients in DBFLow
therajanmaurya Jun 25, 2016
76566be
Stetho added
therajanmaurya Jun 26, 2016
cc32f95
Client List saving in Database
therajanmaurya Jun 26, 2016
8e24d99
client primary id set
therajanmaurya Jun 26, 2016
f6e7b6a
DatabaseHelper and DatabaseHelperClientApi wired perfectly
therajanmaurya Jun 26, 2016
5bbfde1
All check passing
therajanmaurya Jun 27, 2016
31c54ec
Loading Client List with RxObserable
therajanmaurya Jun 27, 2016
72881e8
ClientListFragment is Well decoupled and managed with pagination and …
therajanmaurya Jun 27, 2016
5355b1a
Documentation done, Removed unused file DatabaseHelper
therajanmaurya Jun 27, 2016
f0db843
DataManagerGroups and DatabaseHelperGroups added and all logic shifte…
therajanmaurya Jun 28, 2016
83a88a9
Group DBFlow Model done and Parcelable added in Client Model
therajanmaurya Jun 28, 2016
bf38db0
Groups saving and reading in Database
therajanmaurya Jun 28, 2016
7d122a8
removed unsed code from DataManager
therajanmaurya Jun 28, 2016
585714d
All check passing
therajanmaurya Jun 28, 2016
645e8fb
GroupsListFragmentTest Added and All check Passing
therajanmaurya Jun 28, 2016
ee7dbf0
Center DatabaseHelper and DataManager added
therajanmaurya Jun 28, 2016
4b209a8
Offline feature in Centers List
therajanmaurya Jun 28, 2016
5ea9e06
Documentation added
therajanmaurya Jun 28, 2016
7b20c00
All check passing now
therajanmaurya Jun 29, 2016
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
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ ext {
playServicesVersion = '8.3.0'
mapUtilsServices = '0.4.2'
daggerVersion = '2.2'
raizLabsDBFlow = '3.0.0-beta1'
raizLabsDBFlow = '3.0.1'
espressoVersion = '2.2.1'
runnerVersion = '0.4.1'
rulesVersion = '0.4.1'
Expand Down
5 changes: 5 additions & 0 deletions mifosng-android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ android {
// The Hamcrest is used in tests.
packagingOptions {
exclude 'LICENSE.txt'
exclude 'META-INF/LICENSE.txt'
}
useLibrary 'org.apache.http.legacy'

Expand Down Expand Up @@ -174,6 +175,10 @@ dependencies {
compile 'io.reactivex:rxandroid:1.1.0'
compile 'io.reactivex:rxjava:1.1.4'

compile 'com.facebook.stetho:stetho:1.3.1'
compile 'com.facebook.stetho:stetho-okhttp3:1.3.1'


compile 'com.joanzapata.iconify:android-iconify-material:2.1.1' // (v2.0.0)
compile 'com.crashlytics.android:crashlytics:1.+'
compile 'com.amulyakhare:com.amulyakhare.textdrawable:1.0.1'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,5 @@ public class FakeJsonName {
public static final String CHARGES_JSON = "charges.json";
public static final String LOAN_CHARGES_JSON = "loancharges.json";
public static final String DOCUMENTS_JSON = "documents.json";
public static final String GROUPS_JSON = "groups.json";
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import com.mifos.objects.client.Page;
import com.mifos.objects.group.Center;
import com.mifos.objects.group.CenterWithAssociations;
import com.mifos.objects.group.Group;
import com.mifos.objects.noncore.Document;

import java.util.List;
Expand Down Expand Up @@ -47,9 +48,14 @@ public static List<Charges> getLoanCharges() {
}, FakeJsonName.LOAN_CHARGES_JSON);
}

public static List<Document> getDouments() {
public static List<Document> getDocuments() {
return mTestDataFactory.getListTypePojo(new TypeToken<List<Document>>() {
}, FakeJsonName.DOCUMENTS_JSON);
}

public static Page<Group> getGroups() {
return mTestDataFactory.getListTypePojo(new TypeToken<Page<Group>>() {
}, FakeJsonName.GROUPS_JSON);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,19 @@

import android.test.ActivityInstrumentationTestCase2;
import android.test.ViewAsserts;
import android.test.suitebuilder.annotation.MediumTest;
import android.test.suitebuilder.annotation.SmallTest;
import android.test.suitebuilder.annotation.Suppress;
import android.util.Log;
import android.view.KeyEvent;
import android.view.View;
import android.widget.ListView;

import com.mifos.mifosxdroid.R;
import com.mifos.mifosxdroid.online.CentersActivity;

import static android.support.test.espresso.Espresso.onData;
import static android.support.test.espresso.action.ViewActions.click;
import static android.support.test.espresso.matcher.ViewMatchers.withId;

/**
* Created by Gabriel Esteban on 12/12/14.
*/
@Suppress // TODO: Fix NPE
@Suppress // TODO: Fix NPE and Rewrite Test with new Documentation
public class CenterListFragmentTest extends ActivityInstrumentationTestCase2<CentersActivity> {

public final String LOG_TAG = getClass().getSimpleName();
Expand All @@ -40,7 +34,7 @@ protected void setUp() throws Exception {
//API wait for charging all centers
Thread.sleep(6000);
//instantiating view objects
lv_centers_list = (ListView) centersActivity.findViewById(R.id.lv_center_list);
//lv_centers_list = (ListView) centersActivity.findViewById(R.id.lv_center_list);
}

@SmallTest
Expand Down Expand Up @@ -87,7 +81,7 @@ public void run() {
* - press back and check title is "Groups"
* - press back and check title is "Centers"
*/
@MediumTest
/*@MediumTest
public void testCorrectTitles() throws InterruptedException {
assertEquals(getActivity().getTitle().toString(), "Centers");

Expand Down Expand Up @@ -123,5 +117,5 @@ public void testCorrectTitles() throws InterruptedException {
assertEquals(getActivity().getTitle().toString(), "Centers");


}
}*/
}
5 changes: 5 additions & 0 deletions mifosng-android/src/main/java/com/mifos/App.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,15 @@
import android.graphics.Typeface;

import com.crashlytics.android.Crashlytics;
import com.facebook.stetho.Stetho;
import com.joanzapata.iconify.Iconify;
import com.joanzapata.iconify.fonts.MaterialModule;
import com.mifos.mifosxdroid.injection.component.ApplicationComponent;
import com.mifos.mifosxdroid.injection.component.DaggerApplicationComponent;
import com.mifos.mifosxdroid.injection.module.ApplicationModule;
import com.orm.SugarApp;
import com.raizlabs.android.dbflow.config.FlowConfig;
import com.raizlabs.android.dbflow.config.FlowManager;

import java.util.HashMap;
import java.util.Map;
Expand Down Expand Up @@ -49,6 +52,8 @@ public void onCreate() {
Crashlytics.start(this);

Iconify.with(new MaterialModule());
FlowManager.init(new FlowConfig.Builder(this).build());
Stetho.initializeWithDefaults(this);
}

public ApplicationComponent getComponent() {
Expand Down
32 changes: 16 additions & 16 deletions mifosng-android/src/main/java/com/mifos/api/BaseApiManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -103,67 +103,67 @@ public static void createService() {
init();
}

protected AuthService getAuthApi() {
public AuthService getAuthApi() {
return authApi;
}

protected CenterService getCenterApi() {
public CenterService getCenterApi() {
return centerApi;
}

protected ClientAccountsService getAccountsApi() {
public ClientAccountsService getAccountsApi() {
return accountsApi;
}

protected ClientService getClientsApi() {
public ClientService getClientsApi() {
return clientsApi;
}

protected DataTableService getDataTableApi() {
public DataTableService getDataTableApi() {
return dataTableApi;
}

protected LoanService getLoanApi() {
public LoanService getLoanApi() {
return loanApi;
}

protected SavingsAccountService getSavingsApi() {
public SavingsAccountService getSavingsApi() {
return savingsApi;
}

protected SearchService getSearchApi() {
public SearchService getSearchApi() {
return searchApi;
}

protected GpsCoordinatesService getGpsApi() {
public GpsCoordinatesService getGpsApi() {
return gpsApi;
}

protected GroupService getGroupApi() {
public GroupService getGroupApi() {
return groupApi;
}

protected GroupAccountService getGroupAccountsServiceApi() {
public GroupAccountService getGroupAccountsServiceApi() {
return groupAccountsServiceApi;
}

protected DocumentService getDocumentApi() {
public DocumentService getDocumentApi() {
return documentApi;
}

protected IdentifierService getIdentifierApi() {
public IdentifierService getIdentifierApi() {
return identifierApi;
}

protected OfficeService getOfficeApi() {
public OfficeService getOfficeApi() {
return officeApi;
}

protected StaffService getStaffApi() {
public StaffService getStaffApi() {
return staffApi;
}

protected SurveyService getSurveyApi() {
public SurveyService getSurveyApi() {
return surveyApi;
}

Expand Down
21 changes: 11 additions & 10 deletions mifosng-android/src/main/java/com/mifos/api/DataManager.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.mifos.api;

import com.google.gson.JsonArray;
import com.mifos.api.datamanager.DataManagerClient;
import com.mifos.api.model.ClientPayload;
import com.mifos.api.model.CollectionSheetPayload;
import com.mifos.api.model.GpsCoordinatesRequest;
Expand Down Expand Up @@ -69,12 +70,20 @@
@Singleton
public class DataManager {

public final BaseApiManager mBaseApiManager;
private final BaseApiManager mBaseApiManager;
private DataManagerClient mDataManagerClient;

@Inject

//TODO : This Constructor is temp after splitting the Datamanager layer into Sub DataManager
public DataManager(BaseApiManager baseApiManager) {
mBaseApiManager = baseApiManager;
}

@Inject
public DataManager(BaseApiManager baseApiManager,
DataManagerClient dataManagerClient) {
mBaseApiManager = baseApiManager;
mDataManagerClient = dataManagerClient;
}

/**
Expand Down Expand Up @@ -242,14 +251,6 @@ public Observable<Group> getGroup(int groupId) {
return mBaseApiManager.getGroupApi().getGroup(groupId);
}

public Observable<Page<Group>> getAllGroup() {
return mBaseApiManager.getGroupApi().getAllGroup();
}

public Observable<Page<Group>> listAllGroups(int offset, int limit) {
return mBaseApiManager.getGroupApi().listAllGroups(offset, limit);
}

/**
* Offices API
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.mifos.api;

import com.facebook.stetho.okhttp3.StethoInterceptor;

import java.security.cert.CertificateException;
import java.security.cert.X509Certificate;

Expand Down Expand Up @@ -78,6 +80,7 @@ public boolean verify(String hostname, SSLSession session) {
//Interceptor :> Full Body Logger and ApiRequest Header
builder.addInterceptor(logger);
builder.addInterceptor(new MifosInterceptor());
builder.addNetworkInterceptor(new StethoInterceptor());

return builder.build();

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
package com.mifos.api.datamanager;

import com.mifos.api.BaseApiManager;
import com.mifos.api.local.databasehelper.DatabaseHelperCenter;
import com.mifos.objects.client.Page;
import com.mifos.objects.group.Center;
import com.mifos.utils.PrefManager;

import javax.inject.Inject;
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
* and In Response, We are getting Center API Observable Response using Retrofit2.
* DataManagerCenter saving response in Database and response to Presenter as accordingly.
* Created by Rajan Maurya on 28/6/16.
*/
@Singleton
public class DataManagerCenter {

public final BaseApiManager mBaseApiManager;
public final DatabaseHelperCenter mDatabaseHelperCenter;

@Inject
public DataManagerCenter(BaseApiManager baseApiManager,
DatabaseHelperCenter databaseHelperCenter) {
mBaseApiManager = baseApiManager;
mDatabaseHelperCenter = databaseHelperCenter;
}


/**
* This Method sending the Request to REST API if UserStatus is 0 and
* get list of the centers. The response is pass to the DatabaseHelperCenter
* that save the response in Database in different thread and next pass the response to
* Presenter to show in the view
* <p/>
* If the offset is zero and UserStatus is 1 then fetch all Center list and show on the view.
* else if offset is not zero and UserStatus is 1 then return default empty response to
* presenter
*
* @param paged True Enable the Pagination of the center list REST API
* @param offset Value give from which position Fetch CentersList
* @param limit Maximum Number of centers will come in response
* @return Centers List page from offset to max Limit
*/
public Observable<Page<Center>> getCenters(boolean paged, int offset, int limit) {
switch (PrefManager.getUserStatus()) {
case 0:
return mBaseApiManager.getCenterApi().getCenters(paged, offset, limit)
.concatMap(new Func1<Page<Center>, Observable<? extends Page<Center>>>() {
@Override
public Observable<? extends Page<Center>> call(Page<Center>
centerPage) {
//Saving Clients in Database
mDatabaseHelperCenter.saveAllCenters(centerPage);
return Observable.just(centerPage);
}
});
case 1:
/**
* 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
*/
if (offset == 0)
return mDatabaseHelperCenter.readAllCenters();

default:
return Observable.just(new Page<Center>());
}
}

}
Loading