diff --git a/opensrp-eusm/build.gradle b/opensrp-eusm/build.gradle index 6f4b7c2..ba7f80a 100644 --- a/opensrp-eusm/build.gradle +++ b/opensrp-eusm/build.gradle @@ -122,26 +122,6 @@ android { buildTypes { - release { - resValue "string", 'opensrp_url', '"https://mg-eusm-staging.smartregister.org/opensrp/"' - buildConfigField "int", "DATABASE_VERSION", '1' - buildConfigField "int", "OPENMRS_UNIQUE_ID_INITIAL_BATCH_SIZE", '250' - buildConfigField "int", "OPENMRS_UNIQUE_ID_BATCH_SIZE", '100' - buildConfigField "int", "OPENMRS_UNIQUE_ID_SOURCE", '2' - buildConfigField "long", "SYNC_INTERVAL_IN_MINUTES", '15' - buildConfigField "long", "PULL_UNIQUE_IDS_MINUTES", '15' - buildConfigField "String", "ADMIN_PASSWORD_NOT_NEAR_STRUCTURES", '"AdminPass1"' - buildConfigField "float", "MY_LOCATION_BUFFER", '25' - buildConfigField "boolean", "VALIDATE_FAR_STRUCTURES", 'false' - buildConfigField "int", "RESOLVE_LOCATION_TIMEOUT_IN_SECONDS", '60' - buildConfigField "boolean", "DISPLAY_OUTSIDE_OPERATIONAL_AREA_MASK", 'false' - buildConfigField "boolean", "DISPLAY_DISTANCE_SCALE", 'true' - buildConfigField "String[]", "FACILITY_LEVELS", '{"Country", "Region", "District"}' - buildConfigField "String[]", "LOCATION_LEVELS", '{"Country", "Region", "District"}' - - testCoverageEnabled true - } - debug { resValue "string", 'opensrp_url', '"https://mg-eusm-staging.smartregister.org/opensrp/"' buildConfigField "int", "DATABASE_VERSION", '1' @@ -243,7 +223,7 @@ dependencies { exclude group: 'org.smartregister', module: 'opensrp-client-native-form' } - api('org.smartregister:opensrp-client-stock:1.2.2-SNAPSHOT') { + api('org.smartregister:opensrp-client-stock:1.2.3-SNAPSHOT') { transitive = true exclude group: 'org.smartregister', module: 'opensrp-client-core' exclude group: 'org.smartregister', module: 'opensrp-client-native-form' diff --git a/opensrp-eusm/src/main/java/org/smartregister/eusm/activity/EusmTaskingMapActivity.java b/opensrp-eusm/src/main/java/org/smartregister/eusm/activity/EusmTaskingMapActivity.java index ef8be9b..a5478d4 100644 --- a/opensrp-eusm/src/main/java/org/smartregister/eusm/activity/EusmTaskingMapActivity.java +++ b/opensrp-eusm/src/main/java/org/smartregister/eusm/activity/EusmTaskingMapActivity.java @@ -38,6 +38,8 @@ import org.smartregister.tasking.presenter.ValidateUserLocationPresenter; import org.smartregister.util.Utils; +import timber.log.Timber; + public class EusmTaskingMapActivity extends TaskingMapActivity { private CardView eusmCardView; @@ -181,6 +183,11 @@ public void displaySelectedFeature(Feature feature, LatLng clickedPoint, double @Override public Location getUserCurrentLocation() { - return super.getUserCurrentLocation(); + try { + return super.getUserCurrentLocation(); + } catch (NullPointerException e) { + Timber.e(e); + return null; + } } } diff --git a/opensrp-eusm/src/main/java/org/smartregister/eusm/presenter/StructureRegisterFragmentPresenter.java b/opensrp-eusm/src/main/java/org/smartregister/eusm/presenter/StructureRegisterFragmentPresenter.java index 3cf95e3..466cf75 100644 --- a/opensrp-eusm/src/main/java/org/smartregister/eusm/presenter/StructureRegisterFragmentPresenter.java +++ b/opensrp-eusm/src/main/java/org/smartregister/eusm/presenter/StructureRegisterFragmentPresenter.java @@ -92,6 +92,7 @@ public void onNextButtonClick() { if ((totalCount - ((currentPageNo) * pageSize)) > pageSize) { getFragment().clientsView.scrollToPosition(0); getFragment().getNextButton().setVisibility(View.VISIBLE); + getFragment().getPreviousButton().setVisibility(View.VISIBLE); } else { getFragment().getNextButton().setVisibility(View.INVISIBLE); } diff --git a/opensrp-eusm/src/main/java/org/smartregister/eusm/repository/AppStructureRepository.java b/opensrp-eusm/src/main/java/org/smartregister/eusm/repository/AppStructureRepository.java index 62ccc96..d023e87 100644 --- a/opensrp-eusm/src/main/java/org/smartregister/eusm/repository/AppStructureRepository.java +++ b/opensrp-eusm/src/main/java/org/smartregister/eusm/repository/AppStructureRepository.java @@ -9,6 +9,7 @@ import net.sqlcipher.SQLException; import net.sqlcipher.database.SQLiteDatabase; +import org.apache.commons.lang3.ArrayUtils; import org.apache.commons.lang3.StringUtils; import org.smartregister.domain.Geometry; import org.smartregister.eusm.application.EusmApplication; @@ -94,7 +95,7 @@ public void addOrUpdate(org.smartregister.domain.Location location) { public int countOfStructures(String nameFilter, String locationParentId, String planId) { SQLiteDatabase sqLiteDatabase = getReadableDatabase(); - String query = "SELECT count(1) from " + STRUCTURE_TABLE; + String query = "SELECT count(DISTINCT structure._id) from " + STRUCTURE_TABLE; String[] args = StringUtils.stripAll(locationParentId, planId); @@ -105,15 +106,15 @@ public int countOfStructures(String nameFilter, String locationParentId, String query += " where location.parent_id = ? AND task.plan_id = ?"; if (StringUtils.isNotBlank(nameFilter)) { - args = StringUtils.stripAll(locationParentId, planId, nameFilter); + args = StringUtils.stripAll(locationParentId, planId, "%" + nameFilter + "%"); - query += " and " + STRUCTURE_TABLE + "." + NAME + " like '%?%'"; + query += " and " + STRUCTURE_TABLE + "." + NAME + " like ? "; } int count = 0; try (Cursor cursor = sqLiteDatabase.rawQuery(query, args)) { - if (cursor != null) { - count = cursor.getCount(); + if (cursor != null && cursor.moveToNext()) { + count = cursor.getInt(0); } } catch (SQLException w) { Timber.e(w); @@ -127,6 +128,9 @@ public List fetchStructureDetails(int pageNo, String locationPa public List fetchStructureDetails(Integer pageNo, String locationParentId, String nameFilter, boolean isForMapping, String planId) { + + Location location = EusmApplication.getInstance().getUserLocation(); + List structureDetails = new ArrayList<>(); SQLiteDatabase sqLiteDatabase = getReadableDatabase(); String[] columns = new String[]{ @@ -139,7 +143,7 @@ public List fetchStructureDetails(Integer pageNo, String locati STRUCTURE_TABLE + "." + "geojson as structureGeoJson", LOCATION_TABLE + "." + "name as locationName", LOCATION_TABLE + "." + "parent_id as locationParentId", - "(((? - longitude)*(? - longitude)) + ((? - latitude)*(? - latitude))) as dist", + location == null ? "0 as dist " : "(((? - longitude)*(? - longitude)) + ((? - latitude)*(? - latitude))) as dist", "case \n" + "\twhen (sum(task.status = 'COMPLETED')*1.0/sum(task.status= 'READY')*1.0) = 0.0 \n" + "\t\tthen sum(task.status= 'READY')\n" + @@ -155,19 +159,7 @@ public List fetchStructureDetails(Integer pageNo, String locati + " join task on task.structure_id = " + StructureRepository.STRUCTURE_TABLE + "._id " + " join location on location._id = " + StructureRepository.STRUCTURE_TABLE + ".parent_id "; - - Location location = EusmApplication.getInstance().getUserLocation(); - if (location == null) { - location = new Location("temp"); - location.setLongitude(0.000); - location.setLatitude(0.000); - } - String[] args = StringUtils.stripAll( - String.valueOf(location.getLongitude()), - String.valueOf(location.getLongitude()), - String.valueOf(location.getLatitude()), - String.valueOf(location.getLatitude()), planId, locationParentId); @@ -175,14 +167,20 @@ public List fetchStructureDetails(Integer pageNo, String locati if (StringUtils.isNotBlank(nameFilter)) { args = StringUtils.stripAll( + planId, + locationParentId, + "%" + nameFilter + "%"); + query += " and structureName like ? "; + } + + if (location != null) { + String[] locationArgsArray = new String[]{ String.valueOf(location.getLongitude()), String.valueOf(location.getLongitude()), String.valueOf(location.getLatitude()), String.valueOf(location.getLatitude()), - planId, - locationParentId, - nameFilter); - query += " and structureName like '%?%'"; + }; + args = ArrayUtils.addAll(locationArgsArray, args); } query += " group by " + STRUCTURE_TABLE + "." + "_id" + " order by case when dist is null then 1 else 0 end, dist" diff --git a/opensrp-eusm/src/main/java/org/smartregister/eusm/service/AppLocationTaskIntentService.java b/opensrp-eusm/src/main/java/org/smartregister/eusm/service/AppLocationTaskIntentService.java index 8d8855f..f2d1e10 100644 --- a/opensrp-eusm/src/main/java/org/smartregister/eusm/service/AppLocationTaskIntentService.java +++ b/opensrp-eusm/src/main/java/org/smartregister/eusm/service/AppLocationTaskIntentService.java @@ -1,7 +1,10 @@ package org.smartregister.eusm.service; +import android.Manifest; import android.content.Intent; +import android.content.pm.PackageManager; +import androidx.core.app.ActivityCompat; import androidx.localbroadcastmanager.content.LocalBroadcastManager; import org.jetbrains.annotations.NotNull; @@ -19,6 +22,8 @@ import java.util.List; import java.util.Set; +import timber.log.Timber; + import static org.smartregister.tasking.util.Constants.Action.STRUCTURE_TASK_SYNCED; public class AppLocationTaskIntentService extends LocationTaskIntentService { @@ -46,7 +51,13 @@ protected List syncStructures(LocationServiceHelper locationServiceHel //initiate Stock And StockType sync after structures have been fetched SyncStockServiceJob.scheduleJobImmediately(SyncStockServiceJob.TAG); - SyncStockTypeServiceJob.scheduleJobImmediately(SyncStockTypeServiceJob.TAG); + if ((ActivityCompat.checkSelfPermission(getApplicationContext(), Manifest.permission.WRITE_EXTERNAL_STORAGE) + + ActivityCompat.checkSelfPermission(getApplicationContext(), Manifest.permission.READ_EXTERNAL_STORAGE)) + == PackageManager.PERMISSION_GRANTED) { + SyncStockTypeServiceJob.scheduleJobImmediately(SyncStockTypeServiceJob.TAG); + } else { + Timber.e("Read and Write Permission Not Granted"); + } } return locationList; } diff --git a/opensrp-eusm/src/main/res/drawable/rounded_blue_outline.xml b/opensrp-eusm/src/main/res/drawable/rounded_blue_outline.xml index 3fcbd7d..afbc031 100644 --- a/opensrp-eusm/src/main/res/drawable/rounded_blue_outline.xml +++ b/opensrp-eusm/src/main/res/drawable/rounded_blue_outline.xml @@ -5,7 +5,7 @@ \ No newline at end of file diff --git a/opensrp-eusm/src/main/res/layout/activity_product_info.xml b/opensrp-eusm/src/main/res/layout/activity_product_info.xml index bcac0da..3971db1 100644 --- a/opensrp-eusm/src/main/res/layout/activity_product_info.xml +++ b/opensrp-eusm/src/main/res/layout/activity_product_info.xml @@ -112,7 +112,7 @@ android:paddingEnd="3dp" android:text="@string/back" android:textColor="@color/customAppThemeBlue" - android:textSize="16dp" + android:textSize="16sp" android:textStyle="bold" /> diff --git a/opensrp-eusm/src/main/res/layout/card_view.xml b/opensrp-eusm/src/main/res/layout/card_view.xml index d895a9a..904a545 100644 --- a/opensrp-eusm/src/main/res/layout/card_view.xml +++ b/opensrp-eusm/src/main/res/layout/card_view.xml @@ -48,7 +48,7 @@ android:layout_height="wrap_content" android:text="Alabsdos sdwewe" android:textColor="@color/text_black" - android:textSize="20dp" + android:textSize="20sp" android:textStyle="bold" /> - - + android:textSize="20sp" /> - + -