Skip to content

Commit

Permalink
WD| Change text on bidan home, fix local and remote login. #4
Browse files Browse the repository at this point in the history
  • Loading branch information
baksosapi committed Nov 10, 2017
1 parent 627e452 commit 64ff9eb
Show file tree
Hide file tree
Showing 11 changed files with 706 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@
import org.joda.time.DateTime;
import org.json.JSONException;
import org.json.JSONObject;
import org.opensrp.api.domain.Location;
import org.opensrp.api.util.EntityUtils;
import org.opensrp.api.util.LocationTree;
import org.opensrp.api.util.TreeNode;
import org.smartregister.AllConstants;
import org.smartregister.Context;
import org.smartregister.bidan.BuildConfig;
import org.smartregister.bidan.application.BidanApplication;
Expand All @@ -50,6 +55,7 @@
import org.smartregister.repository.AllSharedPreferences;
import org.smartregister.sync.DrishtiSyncScheduler;
import org.smartregister.util.Log;
import org.smartregister.util.StringUtil;
import org.smartregister.util.Utils;
import org.smartregister.view.BackgroundAction;
import org.smartregister.view.LockingBackgroundTask;
Expand All @@ -60,12 +66,13 @@
import java.util.ArrayList;
import java.util.Iterator;
import java.util.Locale;
import java.util.Map;
import java.util.TimeZone;
import java.util.zip.ZipEntry;
import java.util.zip.ZipFile;

import util.Config;
import util.PathConstants;
import util.BidanConstants;

import static android.preference.PreferenceManager.getDefaultSharedPreferences;
import static android.view.inputmethod.InputMethodManager.HIDE_NOT_ALWAYS;
Expand Down Expand Up @@ -273,7 +280,7 @@ private void initializeProgressDialog() {
private void localLogin(View view, String userName, String password) {
view.setClickable(true);
if (getOpenSRPContext().userService().isUserInValidGroup(userName, password)
&& (!PathConstants.TIME_CHECK || TimeStatus.OK.equals(getOpenSRPContext().userService().validateStoredServerTimeZone()))) {
&& (!BidanConstants.TIME_CHECK || TimeStatus.OK.equals(getOpenSRPContext().userService().validateStoredServerTimeZone()))) {
localLoginWith(userName, password);
} else {

Expand All @@ -290,8 +297,8 @@ public void onEvent(LoginResponse loginResponse) {
if (loginResponse == SUCCESS) {
if (getOpenSRPContext().userService().isUserInPioneerGroup(userName)) {
TimeStatus timeStatus = getOpenSRPContext().userService().validateDeviceTime(
loginResponse.payload(), PathConstants.MAX_SERVER_TIME_DIFFERENCE);
if (!PathConstants.TIME_CHECK || timeStatus.equals(TimeStatus.OK)) {
loginResponse.payload(), BidanConstants.MAX_SERVER_TIME_DIFFERENCE);
if (!BidanConstants.TIME_CHECK || timeStatus.equals(TimeStatus.OK)) {
remoteLoginWith(userName, password, loginResponse.payload());
Intent intent = new Intent(appContext, PullUniqueIdsIntentService.class);
appContext.startService(intent);
Expand Down Expand Up @@ -443,6 +450,7 @@ private void remoteLoginWith(String userName, String password, String userInfo)
}

private void goToHome(boolean remote) {
android.util.Log.e(TAG, "goToHome: from "+ (remote? "remote" : "lokal") );
if (!remote) {
// startZScoreIntentService();
} else {
Expand All @@ -451,8 +459,6 @@ private void goToHome(boolean remote) {
BidanApplication.setCrashlyticsUser(getOpenSRPContext());
Intent intent = new Intent(this, BidanHomeActivity.class);
// Intent intent = new Intent(this, KIbuSmartRegisterActivity.class);
// Intent intent = new Intent(this, ChildSmartRegisterActivity.class);
// Intent intent = new Intent(this, KIAnakSmartRegisterActivity.class);
intent.putExtra(BaseRegisterActivity.IS_REMOTE_LOGIN, remote);
startActivity(intent);

Expand Down Expand Up @@ -504,29 +510,37 @@ public void onGlobalLayout() {
});
}

private void extractLocations(ArrayList<String> locationList, JSONObject rawLocationData)
throws JSONException {
private void extractLocations(ArrayList<String> locationList, JSONObject rawLocationData) throws JSONException {

final String NODE = "node";
final String CHILDREN = "children";
String name = rawLocationData.getJSONObject(NODE).getString("locationId");
String level = rawLocationData.getJSONObject(NODE).getJSONArray("tags").getString(0);

// Get Village Name
// if (level.equals("Village")){
// locationList.add(rawLocationData.getJSONObject(NODE).getJSONArray("tags").toString());
// return;
// }

if (LocationPickerView.ALLOWED_LEVELS.contains(level)) {
locationList.add(name);
}
if (rawLocationData.has(CHILDREN)) {

if (rawLocationData.has(CHILDREN)) {
Iterator<String> childIterator = rawLocationData.getJSONObject(CHILDREN).keys();
while (childIterator.hasNext()) {

String curChildKey = childIterator.next();
extractLocations(locationList, rawLocationData.getJSONObject(CHILDREN).getJSONObject(curChildKey));
}
} else {
android.util.Log.e(TAG, "extractLocations: NO CHILDREN " );
}

}

////////////////////////////////////////////////////////////////
// Inner classes
////////////////////////////////////////////////////////////////

private class RemoteLoginTask extends AsyncTask<Void, Void, LoginResponse> {
private final String userName;
private final String password;
Expand Down Expand Up @@ -565,19 +579,26 @@ private class SaveTeamLocationsTask extends AsyncTask<Void, Void, Void> {
protected Void doInBackground(Void... params) {
ArrayList<String> locationsCSV = locationsCSV();

android.util.Log.e(TAG, "doInBackground: "+ locationsCSV.toString() );
if (locationsCSV.isEmpty()) {
android.util.Log.e(TAG, "doInBackground: locationCSV empty" );
return null;
}

Utils.writePreference(BidanApplication.getInstance().getApplicationContext(), LocationPickerView.PREF_TEAM_LOCATIONS, StringUtils.join(locationsCSV, ","));
android.util.Log.e(TAG, "doInBackground: write "+ LocationPickerView.PREF_VILLAGE_LOCATIONS );
android.util.Log.e(TAG, "doInBackground: value "+ StringUtils.join(locationsCSV, ",") );

Utils.writePreference(BidanApplication.getInstance().getApplicationContext(), LocationPickerView.PREF_VILLAGE_LOCATIONS, StringUtils.join(locationsCSV, ","));
return null;
}

// TODO Solve Get Location failed
public ArrayList<String> locationsCSV() {
final String LOCATIONS_HIERARCHY = "locationsHierarchy";
final String MAP = "map";
JSONObject locationData;
ArrayList<String> locations = new ArrayList<>();

try {
locationData = new JSONObject(BidanApplication.getInstance().context().anmLocationController().get());
if (locationData.has(LOCATIONS_HIERARCHY) && locationData.getJSONObject(LOCATIONS_HIERARCHY).has(MAP)) {
Expand All @@ -587,10 +608,13 @@ public ArrayList<String> locationsCSV() {
String curKey = keys.next();
extractLocations(locations, map.getJSONObject(curKey));
}
} else {
android.util.Log.e(TAG, "locationsCSV: Not Found" );
}
} catch (Exception e) {
android.util.Log.e(getClass().getCanonicalName(), android.util.Log.getStackTraceString(e));
}
android.util.Log.e(TAG, "locationsCSV: "+ locations );
return locations;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,6 @@

public class BidanHomeFragment extends BaseSmartRegisterFragment implements SyncStatusBroadcastReceiver.SyncStatusListener {
private final ClientActionHandler clientActionHandler = new ClientActionHandler();
private LocationPickerView clinicSelection;
private static final long NO_RESULT_SHOW_DIALOG_DELAY = 1000l;
private Handler showNoResultDialogHandler;
private NotInCatchmentDialogFragment notInCatchmentDialogFragment;
private TextView filterCount;
private View filterSection;
private ImageView backButton;
Expand Down Expand Up @@ -442,7 +438,7 @@ private int count(String mainConditionString) {

try {
SmartRegisterQueryBuilder sqb = new SmartRegisterQueryBuilder(countSelect);
String query = "";
String query;
if (isValidFilterForFts(commonRepository())) {
String sql = sqb.countQueryFts(tablename, "", mainConditionString, "");
List<String> ids = commonRepository().findSearchIds(sql);
Expand Down Expand Up @@ -519,32 +515,28 @@ public void onClick(View view) {
if (view.getTag() != null && view.getTag() instanceof CommonPersonObjectClient) {
client = (CommonPersonObjectClient) view.getTag();
}

RegisterClickables registerClickables = new RegisterClickables();

switch (view.getId()) {
case R.id.child_profile_info_layout:

// ChildImmunizationActivity.launchActivity(getActivity(), client, null);
break;
case R.id.record_weight:
registerClickables.setRecordWeight(true);
// ChildImmunizationActivity.launchActivity(getActivity(), client, registerClickables);
break;

case R.id.record_vaccination:
registerClickables.setRecordAll(true);
// ChildImmunizationActivity.launchActivity(getActivity(), client, registerClickables);
break;
case R.id.filter_selection:
toggleFilterSelection();
break;

case R.id.global_search:
// ((ChildSmartRegisterActivity) getActivity()).startAdvancedSearch();
break;

case R.id.scan_qr_code:
// ((ChildSmartRegisterActivity) getActivity()).startQrCodeScanner();
break;
default:
break;
Expand Down
Loading

0 comments on commit 64ff9eb

Please sign in to comment.