Skip to content

Commit

Permalink
WD| Fix Login remote and local #4
Browse files Browse the repository at this point in the history
  • Loading branch information
baksosapi committed Nov 16, 2017
1 parent bceca6e commit b1dd497
Show file tree
Hide file tree
Showing 21 changed files with 1,372 additions and 373 deletions.
114 changes: 82 additions & 32 deletions bidan-cloudant/build.gradle
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
buildscript {
repositories {
jcenter()
maven { url 'https://maven.fabric.io/public' }
}
dependencies {
classpath "com.android.tools.build:gradle:1.2.3"
classpath 'org.apache.commons:commons-lang3:3.3.2'
classpath 'org.robolectric:robolectric-gradle-plugin:1.1.0'
classpath 'org.kt3k.gradle.plugin:coveralls-gradle-plugin:2.8.1'
classpath 'io.fabric.tools:gradle:1.+'
classpath 'org.kt3k.gradle.plugin:coveralls-gradle-plugin:2.4.0'
}
}

Expand All @@ -17,23 +20,27 @@ allprojects {
}

apply plugin: 'com.android.application'
apply plugin: 'io.fabric'
apply plugin: 'jacoco'
apply plugin: 'com.github.kt3k.coveralls'

repositories {
maven { url 'https://maven.fabric.io/public' }
maven { url 'https://jitpack.io' }

}

android {
compileSdkVersion 23
compileSdkVersion 22
buildToolsVersion "26.0.1"

defaultConfig {
applicationId "org.smartregister.bidan_cloudant"
minSdkVersion 18
targetSdkVersion 21
versionCode 1
versionName "1.0"
versionCode 10
versionName "1.3.1"
multiDexEnabled true
buildConfigField "long", "MAX_SERVER_TIME_DIFFERENCE", "1800000l"
buildConfigField "boolean", "TIME_CHECK", "false"
resValue "string", 'opensrp_url', '"http://192.168.1.253:8080/opensrp"'
}

dexOptions {
Expand All @@ -43,14 +50,19 @@ android {

lintOptions {
lintConfig file("lint.xml")
abortOnError false
}

buildTypes {
release {
minifyEnabled false
zipAlignEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
buildConfigField "int", "OPENMRS_UNIQUE_ID_INITIAL_BATCH_SIZE", '250'
buildConfigField "int", "OPENMRS_UNIQUE_ID_BATCH_SIZE", '100'
buildConfigField "int", "OPENMRS_UNIQUE_ID_SOURCE", '1'
buildConfigField "int", "DATABASE_VERSION", '9'
buildConfigField "long", "MAX_SERVER_TIME_DIFFERENCE", "1800000l"
buildConfigField "boolean", "TIME_CHECK", "true"
}

debug {
Expand All @@ -64,7 +76,6 @@ android {
buildConfigField "boolean", "TIME_CHECK", "false"
testCoverageEnabled true
}

}
packagingOptions {
exclude 'META-INF/DEPENDENCIES.txt'
Expand All @@ -80,50 +91,91 @@ android {
exclude 'LICENSE.txt'
}


testOptions {
unitTests.returnDefaultValues = true
}

dexOptions {
incremental false
javaMaxHeapSize "4g"
}
}

dependencies {
compile fileTree(include: ['commons-validator-1.6.jar'], dir: 'libs')

compile('org.smartregister:opensrp-client-native-form:1.0.2-SNAPSHOT@aar') {
transitive = true
exclude group: 'com.android.support', module: 'recyclerview-v7'
}

compile('org.smartregister:opensrp-client-core:1.1.1-SNAPSHOT@aar') {
transitive = true
exclude group: 'com.github.bmelnychuk', module: 'atv'
exclude group: 'com.google.guava', module: 'guava'
}

// compile('org.smartregister:opensrp-client-immunization:1.1.4-SNAPSHOT@aar') {
// transitive = true
// }
// compile('org.smartregister:opensrp-client-growth-monitoring:1.0.3-SNAPSHOT@aar') {
// transitive = true
// }

compile('org.smartregister:opensrp-client-enketo:1.0.0-SNAPSHOT@aar') {
transitive = true
exclude group: 'com.github.bmelnychuk', module: 'atv'
exclude group: 'com.google.guava', module: 'guava'
}

compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:design:22.2.1'

compile 'com.jjoe64:graphview:4.0.1'
compile 'com.google.code.gson:gson:2.8.2'
compile 'com.android.support:appcompat-v7:22.2.1'
// compile project(':json2view')
compile 'com.google.guava:guava:20.0'
compile('com.android.support:design:22.2.1') {
exclude group: 'com.android.support', module: 'recyclerview-v7'

}
compile 'com.android.support:appcompat-v7:22.1.1'
compile 'com.android.support:cardview-v7:22.2.1'
compile 'com.android.support:leanback-v17:22.2.1'
compile('com.crashlytics.sdk.android:crashlytics:2.6.5@aar') {
transitive = true;
}
compile 'com.jjoe64:graphview:4.2.1'
compile 'com.android.support:support-v4:22.2.1'
compile 'id.zelory:compressor:1.0.4'
compile 'com.twotoasters.SectionCursorAdapter:library:1.0.+'
compile 'com.github.ybq:Android-SpinKit:1.1.0'
compile 'junit:junit:4.12'

testCompile('org.robolectric:robolectric:3.4.2') {

androidTestCompile 'junit:junit:4.12'
exclude group: 'com.google.guava', module: 'guava'
exclude group: 'org.apache.maven', module: 'maven-model'
exclude group: 'org.apache.maven', module: 'maven-ant-tasks'
exclude group: 'com.android.support'
}

testCompile 'junit:junit:4.12'
testCompile 'org.apache.maven:maven-ant-tasks:2.1.3'
testCompile('com.squareup:fest-android:1.0.8') { exclude module: 'support-v4' }
testCompile 'org.robolectric:robolectric:3.4.2'
testCompile "org.robolectric:shadows-multidex:3.4-rc2"
testCompile("org.robolectric:shadows-multidex:3.4-rc2") {
exclude group: 'com.google.guava', module: 'guava'
}

androidTestCompile('com.android.support.test.espresso:espresso-core:2.+') {

exclude group: 'com.android.support', module: 'support-annotations'
exclude group: 'junit', module: 'junit'
}
// PowerMock
def powerMockVersion = '1.7.3'
def powerMockVersion = '1.7.1'
testCompile "org.powermock:powermock-module-junit4:$powerMockVersion"
testCompile "org.powermock:powermock-module-junit4-rule:$powerMockVersion"
testCompile "org.powermock:powermock-api-mockito2:$powerMockVersion"
testCompile("org.powermock:powermock-classloading-xstream:$powerMockVersion")
testCompile("org.powermock:powermock-classloading-xstream:$powerMockVersion") {

exclude group: 'com.thoughtworks.xstream', module: 'xstream'
}

testCompile 'org.apache.maven:maven-ant-tasks:2.1.3'
}

//Testing and coveralls

coveralls {
jacocoReportPath = "${buildDir}/reports/jacoco/jacocoRootReport/merged.xml"
}

task jacocoTestReport(type: JacocoReport, dependsOn: ['testDebug']) {
Expand All @@ -147,6 +199,4 @@ task jacocoTestReport(type: JacocoReport, dependsOn: ['testDebug']) {
])
}

coveralls {
jacocoReportPath = "${buildDir}/reports/jacoco/jacocoRootReport/merged.xml"
}
//End testing and coveralls
Original file line number Diff line number Diff line change
@@ -0,0 +1,196 @@
package org.smartregister.bidan_cloudant.activity;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.StringRes;
import android.support.design.widget.NavigationView;
import android.support.design.widget.Snackbar;
import android.support.v4.widget.DrawerLayout;
import android.support.v7.app.ActionBarDrawerToggle;
import android.text.TextUtils;
import android.view.MenuItem;
import android.view.View;
import android.widget.TextView;

import org.joda.time.DateTime;
import org.joda.time.Days;
import org.joda.time.Hours;
import org.joda.time.Minutes;
import org.joda.time.Seconds;
import org.smartregister.Context;
import org.smartregister.bidan_cloudant.R;
import org.smartregister.bidan_cloudant.application.BidanApplication;
import org.smartregister.bidan_cloudant.receiver.SyncStatusBroadcastReceiver;
import org.smartregister.bidan_cloudant.service.intent.SyncIntentService;
import org.smartregister.bidan_cloudant.sync.ECSyncUpdater;
import org.smartregister.domain.FetchStatus;
import org.smartregister.provider.SmartRegisterClientsProvider;
import org.smartregister.view.activity.SecuredNativeSmartRegisterActivity;

import java.util.Calendar;

/**
* Created by sid-tech on 11/14/17.
*/

public class BaseRegisterActivity extends SecuredNativeSmartRegisterActivity
implements NavigationView.OnNavigationItemSelectedListener, SyncStatusBroadcastReceiver.SyncStatusListener {

public static final String IS_REMOTE_LOGIN = "is_remote_login";
private Snackbar syncStatusSnackbar;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// setContentView(R.layout.activity_main_bidan);

// DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);

// BaseActivityToggle toggle = new BaseActivityToggle(this, drawer,
// R.string.navigation_drawer_open, R.string.navigation_drawer_close) {
//
// public void onDrawerClosed(View view) {
// super.onDrawerClosed(view);
// }
//
// public void onDrawerOpened(View drawerView) {
// super.onDrawerOpened(drawerView);
//
// }
// };
//
// drawer.setDrawerListener(toggle);
// toggle.syncState();
//
// NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
// navigationView.setNavigationItemSelectedListener(this);

Bundle extras = this.getIntent().getExtras();
if (extras != null) {
boolean isRemote = extras.getBoolean(IS_REMOTE_LOGIN);
if (isRemote) {
updateFromServer();
}
}
}


@Override
public boolean onNavigationItemSelected(MenuItem menuItem) {
return false;
}

@Override
public void onSyncStart() {

}

@Override
public void onSyncComplete(FetchStatus fetchStatus) {

}

@Override
protected DefaultOptionsProvider getDefaultOptionsProvider() {
return null;
}

@Override
protected NavBarOptionsProvider getNavBarOptionsProvider() {
return null;
}

@Override
protected SmartRegisterClientsProvider clientsProvider() {
return null;
}

@Override
protected void onInitialization() {

}

@Override
public void startRegistration() {

}

private void updateFromServer() {
startService(new Intent(getApplicationContext(), SyncIntentService.class));
}



private void updateLastSyncText() {
// NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
// if (navigationView != null && navigationView.getMenu() != null) {
// TextView syncMenuItem = ((TextView) navigationView.findViewById(R.id.nav_synctextview));
// if (syncMenuItem != null) {
// String lastSync = getLastSyncTime();
//
// if (!TextUtils.isEmpty(lastSync)) {
// lastSync = " " + String.format(getString(R.string.last_sync), lastSync);
// }
// syncMenuItem.setText(String.format(getString(R.string.sync_), lastSync));
// }
// }
}

private String getLastSyncTime() {
String lastSync = "";
long milliseconds = ECSyncUpdater.getInstance(this).getLastCheckTimeStamp();
if (milliseconds > 0) {
DateTime lastSyncTime = new DateTime(milliseconds);
DateTime now = new DateTime(Calendar.getInstance());
Minutes minutes = Minutes.minutesBetween(lastSyncTime, now);
if (minutes.getMinutes() < 1) {
Seconds seconds = Seconds.secondsBetween(lastSyncTime, now);
lastSync = seconds.getSeconds() + "s";
} else if (minutes.getMinutes() >= 1 && minutes.getMinutes() < 60) {
lastSync = minutes.getMinutes() + "m";
} else if (minutes.getMinutes() >= 60 && minutes.getMinutes() < 1440) {
Hours hours = Hours.hoursBetween(lastSyncTime, now);
lastSync = hours.getHours() + "h";
} else {
Days days = Days.daysBetween(lastSyncTime, now);
lastSync = days.getDays() + "d";
}
}
return lastSync;
}

@Override
protected Context context() {
return BidanApplication.getInstance().context();
}


////////////////////////////////////////////////////////////////
// Inner classes
////////////////////////////////////////////////////////////////
private class BaseActivityToggle extends ActionBarDrawerToggle {

private BaseActivityToggle(Activity activity, DrawerLayout drawerLayout, @StringRes int openDrawerContentDescRes, @StringRes int closeDrawerContentDescRes) {
super(activity, drawerLayout, openDrawerContentDescRes, closeDrawerContentDescRes);
}

/*public BaseActivityToggle(Activity activity, DrawerLayout drawerLayout, Toolbar toolbar, @StringRes int openDrawerContentDescRes, @StringRes int closeDrawerContentDescRes) {
super(activity, drawerLayout, toolbar, openDrawerContentDescRes, closeDrawerContentDescRes);
}*/

@Override
public void onDrawerOpened(View drawerView) {
super.onDrawerOpened(drawerView);
if (!SyncStatusBroadcastReceiver.getInstance().isSyncing()) {
updateLastSyncText();
}
}

@Override
public void onDrawerClosed(View drawerView) {
super.onDrawerClosed(drawerView);
}
}

}
Loading

0 comments on commit b1dd497

Please sign in to comment.