Skip to content

Commit

Permalink
MI | Updating sync functionality(2) #6
Browse files Browse the repository at this point in the history
Signed-off-by: mib-iqbal <[email protected]>
  • Loading branch information
mib-iqbal committed Nov 16, 2017
1 parent 559e00c commit 67fdde2
Show file tree
Hide file tree
Showing 16 changed files with 114 additions and 73 deletions.
2 changes: 1 addition & 1 deletion opensrp-gizi/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ android {
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"'
resValue "string", 'opensrp_url', '"http://118.91.130.18:9090/opensrp"'
}

dexOptions {
Expand Down
22 changes: 9 additions & 13 deletions opensrp-gizi/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,26 +5,22 @@
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>

<application android:allowBackup="true"
android:label="@string/app_name"
android:name=".application.GiziApplication">
<!-- local key -->
<!-- <meta-data
android:name="io.fabric.ApiKey"
android:value="5bda8a6293b5b89b510a53e5d297d42bdf427e10" />
-->

<!-- sid key -->
<application
android:name=".application.GiziApplication"
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
>
<meta-data
android:name="io.fabric.ApiKey"
android:value="b74c58c94d8965151212e8ecf1f4fdfbf5b7f4e4" />

<activity
android:name=".activity.LoginActivity"
android:theme="@android:style/Theme.Holo"
android:windowSoftInputMode="adjustResize|stateHidden"
android:label="@string/app_name"
android:theme="@style/BidanAppTheme"
android:screenOrientation="landscape"
android:label="@string/app_name" >
android:windowSoftInputMode="stateAlwaysHidden|adjustResize"
>
<intent-filter>
<action android:name="android.intent.action.MAIN" />

Expand Down
6 changes: 0 additions & 6 deletions opensrp-gizi/src/main/assets/ec_client_classification.json
Original file line number Diff line number Diff line change
Expand Up @@ -86,12 +86,6 @@
"rule": {
"type": "event",
"fields": [
{
"field":"obs.fieldCode",
"concept": "159917AAAAAAAAAAAAAAAAAAAAAAAAAA",
"values": ["151849AAAAAAAAAAAAAAAAAAAAAAAAAA"],
"creates_case":["ec_anak"]
},
{
"field":"eventType",
"field_value": "Child Registration",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@
"name": "id",
"shouldLoadValue": true
},
{
"name": "ibu_entity_id",
"source": "kartu_ibu.id",
"shouldLoadValue": true
},
{
"name": "existing_Village",
"bind": "/model/instance/registrasi_anak/Village",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
import org.smartregister.provider.SmartRegisterClientsProvider;
import org.smartregister.service.ZiggyService;
import org.smartregister.gizi.R;
import org.smartregister.sync.ClientProcessor;
import org.smartregister.gizi.sync.ClientProcessor;
import org.smartregister.util.FormUtils;
import org.smartregister.view.activity.SecuredNativeSmartRegisterActivity;
import org.smartregister.view.dialog.DialogOption;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import android.content.pm.PackageManager;
import android.content.res.Resources;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.text.InputType;
import android.util.DisplayMetrics;
import android.view.KeyEvent;
Expand All @@ -23,28 +24,33 @@
import android.widget.ImageView;
import android.widget.TextView;

import com.flurry.android.FlurryAgent;

import org.json.JSONException;
import org.json.JSONObject;
import org.smartregister.Context;
import org.smartregister.gizi.activity.GiziHomeActivity;
import org.smartregister.gizi.application.GiziApplication;
import org.smartregister.gizi.R;
import org.smartregister.gizi.application.GiziApplication;
import org.smartregister.Context;
import org.smartregister.domain.LoginResponse;
import org.smartregister.domain.Response;
import org.smartregister.domain.ResponseStatus;
import org.smartregister.event.Listener;
//import org.smartregister.vaksinator.lib.ErrorReportingFacade;
import org.smartregister.repository.AllSharedPreferences;
import org.smartregister.sync.DrishtiSyncScheduler;
import org.smartregister.util.Log;
import org.smartregister.view.BackgroundAction;
import org.smartregister.view.LockingBackgroundTask;
import org.smartregister.view.ProgressIndicator;
import org.smartregister.gizi.activity.SettingsActivity;

import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Locale;
import java.util.zip.ZipEntry;
import java.util.zip.ZipFile;

//import io.fabric.sdk.android.Fabric;

import static android.preference.PreferenceManager.getDefaultSharedPreferences;
import static android.view.inputmethod.InputMethodManager.HIDE_NOT_ALWAYS;
Expand All @@ -55,7 +61,8 @@
import static org.smartregister.util.Log.logError;
import static org.smartregister.util.Log.logVerbose;

public class LoginActivity extends Activity {
public class LoginActivity extends AppCompatActivity {
private static final String TAG = LoginActivity.class.getSimpleName();
private Context context;
private EditText userNameEditText;
private EditText passwordEditText;
Expand All @@ -69,52 +76,71 @@ public class LoginActivity extends Activity {
public static final String Bengali_LANGUAGE = "Bengali";
public static final String Bahasa_LANGUAGE = "Bahasa";


// public static Generator generator;

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
logVerbose("Initializing ...");
try {

try{
AllSharedPreferences allSharedPreferences = new AllSharedPreferences(getDefaultSharedPreferences(this));
String preferredLocale = allSharedPreferences.fetchLanguagePreference();
Resources res = Context.getInstance().applicationContext().getResources();
Resources res = getOpenSRPContext().applicationContext().getResources();
// Change locale settings in the app.
DisplayMetrics dm = res.getDisplayMetrics();
android.content.res.Configuration conf = res.getConfiguration();
conf.locale = new Locale(preferredLocale);
res.updateConfiguration(conf, dm);
} catch (Exception e) {
}catch(Exception e){

}
setContentView(org.smartregister.R.layout.login);
ImageView loginglogo = (ImageView) findViewById(R.id.login_logo);
loginglogo.setImageDrawable(getResources().getDrawable(R.mipmap.gizilogin));
context = Context.getInstance().updateApplicationContext(this.getApplicationContext());
setContentView(R.layout.login);

positionViews();

initializeLoginFields();
initializeBuildDetails();
setDoneActionHandlerOnPasswordField();
initializeProgressDialog();
getActionBar().setTitle("");
getActionBar().setIcon(getResources().getDrawable(org.smartregister.gizi.R.mipmap.logo));
getActionBar().setBackgroundDrawable(getResources().getDrawable(org.smartregister.gizi.R.color.action_bar_background));
setLanguage();


// debugApp();
// debugApp();

}

private void debugApp(){
/* private void debugApp() {
Config config = new Config();
String uname = "demo1", pwd = "Satu2345";
try {
uname = config.getCredential("uname", getApplicationContext());
pwd = config.getCredential("pwd", getApplicationContext());
} catch (IOException e) {
e.printStackTrace();
}
LayoutInflater layoutInflater = getLayoutInflater();
View view = layoutInflater.inflate(R.layout.login, null);
if (context.userService().hasARegisteredUser()){
// localLogin(view, "demo_test", "Demo@123");
localLogin(view, "user28", "1Sampai8");
localLoginWith(uname, pwd);
//localLogin(view, uname, pwd);
} else {
// remoteLogin(view, "demo_test", "Demo@123");
remoteLogin(view, "user28", "1Sampai8");
remoteLogin(view, uname, pwd);
}
}*/

private void positionViews() {
ImageView loginglogo = (ImageView)findViewById(R.id.login_logo);
loginglogo.setImageDrawable(getResources().getDrawable(R.mipmap.login_logo));
context = Context.getInstance().updateApplicationContext(this.getApplicationContext());
// getActionBar().setTitle("");
// getActionBar().setIcon(getResources().getDrawable(R.mipmap.logo));
// getActionBar().setBackgroundDrawable(getResources().getDrawable(R.color.action_bar_background));

}

public static Context getOpenSRPContext() {
return GiziApplication.getInstance().context();
}

@Override
Expand All @@ -127,7 +153,7 @@ public boolean onCreateOptionsMenu(Menu menu)
@Override
public boolean onOptionsItemSelected(MenuItem item) {
if(item.getTitle().toString().equalsIgnoreCase("Settings")){
startActivity(new Intent(this,SettingsActivity.class));
startActivity(new Intent(this, SettingsActivity.class));
return true;
}
return super.onOptionsItemSelected(item);
Expand All @@ -142,10 +168,6 @@ private void initializeBuildDetails() {
}
}

public static Context getOpenSRPContext() {
return GiziApplication.getInstance().getContext();
}

@Override
protected void onResume() {
super.onResume();
Expand Down Expand Up @@ -183,7 +205,7 @@ private void setDoneActionHandlerOnPasswordField() {
@Override
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
if (actionId == EditorInfo.IME_ACTION_DONE) {
login(findViewById(org.smartregister.R.id.login_loginButton));
login(findViewById(R.id.login_loginButton));
}
return false;
}
Expand All @@ -200,8 +222,10 @@ private void initializeProgressDialog() {
private void localLogin(View view, String userName, String password) {
if (getOpenSRPContext().userService().isUserInValidGroup(userName, password)) {
localLoginWith(userName, password);
// ErrorReportingFacade.setUsername("", userName);
FlurryAgent.setUserId(userName);

// Tracking Error
// ErrorReportingFacade.setUsername("", userName);
// FlurryAgent.setUserId(userName);
} else {
showErrorDialog(getString(org.smartregister.R.string.login_failed_dialog_message));
view.setClickable(true);
Expand All @@ -211,8 +235,8 @@ private void localLogin(View view, String userName, String password) {
private void remoteLogin(final View view, final String userName, final String password) {
tryRemoteLogin(userName, password, new Listener<LoginResponse>() {
public void onEvent(LoginResponse loginResponse) {
// ErrorReportingFacade.setUsername("", userName);
FlurryAgent.setUserId(userName);
// ErrorReportingFacade.setUsername("", userName);
// FlurryAgent.setUserId(userName);
if (loginResponse == SUCCESS) {
remoteLoginWith(userName, password, loginResponse.payload());
} else {
Expand Down Expand Up @@ -328,16 +352,18 @@ private void hideKeyboard() {

private void localLoginWith(String userName, String password) {
context.userService().localLogin(userName, password);
// LoginActivity.generator = new Generator(context,userName,password);
// LoginActivity.generator = new Generator(context, userName, password);
goToHome();
DrishtiSyncScheduler.startOnlyIfConnectedToNetwork(getApplicationContext());
//DrishtiSyncScheduler.startOnlyIfConnectedToNetwork(getApplicationContext());
}

private void remoteLoginWith(String userName, String password, String userInfo) {
context.userService().remoteLogin(userName, password, userInfo);
// LoginActivity.generator = new Generator(context,userName,password);
String locationId = getUserDefaultLocationId(userInfo);
saveDefaultLocationId(userName,locationId);
// LoginActivity.generator = new Generator(context, userName, password);
goToHome();
DrishtiSyncScheduler.startOnlyIfConnectedToNetwork(getApplicationContext());
//DrishtiSyncScheduler.startOnlyIfConnectedToNetwork(getApplicationContext());
}

private void goToHome() {
Expand Down Expand Up @@ -393,6 +419,23 @@ public static String switchLanguagePreference() {
}
}

public String getUserDefaultLocationId(String userInfo) {
try {
JSONObject userLocationJSON = new JSONObject(userInfo);
return userLocationJSON.getJSONObject("team").getJSONArray("location").getJSONObject(0).getString("name");
} catch (JSONException e) {
android.util.Log.v("Error : ", e.getMessage());
}

return null;
}

public void saveDefaultLocationId(String userName, String locationId) {
if (userName != null) {
context.userService().getAllSharedPreferences().savePreference(userName + "-locationid", locationId);
}
}

/* private void tryGetUniqueId(final String username, final String password, final Listener<ResponseStatus> afterGetUniqueId) {
LockingBackgroundTask task = new LockingBackgroundTask(new ProgressIndicator() {
@Override
Expand All @@ -413,7 +456,7 @@ public ResponseStatus actionToDoInBackgroundThread() {
return (LoginActivity.generator.uniqueIdService().getLastUsedId(username, password));
}
@Override
@Override
public void postExecuteInUIThread(ResponseStatus result) {
afterGetUniqueId.onEvent(result);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public void onReceive(Context context, Intent intent) {
new SyncProgressIndicator(),
org.smartregister.Context.getInstance().allFormVersionSyncService());

// updateActionsTask.setAdditionalSyncService(org.ei.opensrp.Context.getInstance().uniqueIdService());
// updateActionsTask.setAdditionalSyncService(org.ei.opensrp.Context.getInstance().uniqueIdService());

updateActionsTask.updateFromServer(new SyncAfterFetchListener());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
import org.smartregister.provider.SmartRegisterClientsProvider;
import org.smartregister.gizi.R;

import org.smartregister.sync.ClientProcessor;
import org.smartregister.gizi.sync.ClientProcessor;
import org.smartregister.util.StringUtil;
import org.smartregister.view.activity.SecuredNativeSmartRegisterActivity;
import org.smartregister.view.contract.ECClient;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,12 +107,14 @@ public void getView(Cursor cursor, SmartRegisterClient client, final View conver
String namaayah = getValue(kiparent.getColumnmaps(), "namaSuami", true);
String namaibu = getValue(kiparent.getColumnmaps(), "namalengkap", true);
fillValue((TextView) convertView.findViewById(R.id.ParentName), namaibu+","+namaayah);

String subVillages = getValue(kiparent.getDetails(), "address1", true);
fillValue((TextView) convertView.findViewById(R.id.txt_child_subVillage), subVillages);
}
String dob= pc.getColumnmaps().get("tanggalLahirAnak").substring(0, pc.getColumnmaps().get("tanggalLahirAnak").indexOf("T"));
String age = ""+monthRangeToToday(dob);
//get child detail value
String subVillages = getValue(kiparent.getDetails(), "address1", true);


// String ages = getValue(pc.getColumnmaps(), "namaBayi", true);
String dateOfBirth = getValue(pc.getColumnmaps(), "tanggalLahirAnak", true);
String gender = getValue(pc.getDetails(), "gender", true);
Expand All @@ -125,7 +127,7 @@ public void getView(Cursor cursor, SmartRegisterClient client, final View conver
String wasting_status = getValue(pc.getDetails(), "wasting", true);

//set child detail value
fillValue((TextView) convertView.findViewById(R.id.txt_child_subVillage), subVillages);

fillValue((TextView) convertView.findViewById(R.id.txt_child_age), age);
fillValue((TextView) convertView.findViewById(R.id.txt_child_date_of_birth), "DOB :"+dob);
fillValue((TextView) convertView.findViewById(R.id.txt_child_gender), gender);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public FetchStatus sync() {
CountDownLatch mCountDownLatch = new CountDownLatch(2);
mCloudantSyncHandler.setCountDownLatch(mCountDownLatch);
mCloudantSyncHandler.startPullReplication();
// mCloudantSyncHandler.startPushReplication();
mCloudantSyncHandler.startPushReplication();

mCountDownLatch.await();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,9 +143,9 @@ public Boolean processEvent(JSONObject event, JSONObject clientClassificationJso
}

// Check if child is deceased and skip
if (client.has("deathdate") && !client.getString("deathdate").isEmpty()) {
/*if (client.has("deathdate") && !client.getString("deathdate").isEmpty()) {
return false;
}
}*/

// Get the client type classification
JSONArray clientClasses = clientClassificationJson
Expand Down
Loading

0 comments on commit 67fdde2

Please sign in to comment.