From cd6e988f6437e2b24731904d2f47592e504002b6 Mon Sep 17 00:00:00 2001 From: vend Date: Mon, 25 Apr 2022 15:38:35 +0500 Subject: [PATCH] Attention flags issue #811 done pdf nameing issue #820 done --- opensrp-anc/build.gradle | 2 +- .../main/assets/config/attention-flags.yml | 2 +- .../ContactSummaryFinishActivity.java | 24 ++++++++++++------- .../anc/library/activity/ProfileActivity.java | 2 +- .../anc/library/contract/ProfileContract.java | 4 ++-- .../library/presenter/ProfilePresenter.java | 4 ++-- .../task/LoadContactSummaryDataTask.java | 5 +++- .../smartregister/anc/library/util/Utils.java | 6 ++--- opensrp-anc/src/main/res/values/strings.xml | 2 +- reference-app/build.gradle | 2 +- 10 files changed, 32 insertions(+), 21 deletions(-) diff --git a/opensrp-anc/build.gradle b/opensrp-anc/build.gradle index bac75e224..8d381ce8d 100644 --- a/opensrp-anc/build.gradle +++ b/opensrp-anc/build.gradle @@ -178,7 +178,7 @@ tasks.withType(Test) { dependencies { implementation 'androidx.appcompat:appcompat:1.3.1' - implementation('org.smartregister:opensrp-client-native-form:2.1.17-SNAPSHOT@aar') { + implementation('org.smartregister:opensrp-client-native-form:2.1.16-PREVIEW-SNAPSHOT@aar') { transitive = true exclude group: 'com.android.support', module: 'recyclerview-v7' exclude group: 'com.android.support', module: 'appcompat-v7' diff --git a/opensrp-anc/src/main/assets/config/attention-flags.yml b/opensrp-anc/src/main/assets/config/attention-flags.yml index 40b825a48..abd66cb88 100644 --- a/opensrp-anc/src/main/assets/config/attention-flags.yml +++ b/opensrp-anc/src/main/assets/config/attention-flags.yml @@ -64,7 +64,7 @@ group: red_attention_flag fields: - template: "{{attention_flags.red.danger_sign}}: {danger_signs_value}" - relevance: "!danger_signs.isEmpty() && !danger_signs.contains('danger_none')" + relevance: "!danger_signs.isEmpty() && !danger_signs.contains('none') || !danger_signs.isEmpty() && !danger_signs.contains('danger_none')" - template: "{{attention_flags.red.occupation_informal_employment_sex_worker}}" relevance: "occupation.contains('informal_employment_sex_worker')" diff --git a/opensrp-anc/src/main/java/org/smartregister/anc/library/activity/ContactSummaryFinishActivity.java b/opensrp-anc/src/main/java/org/smartregister/anc/library/activity/ContactSummaryFinishActivity.java index 4413fb925..13c9c8b52 100644 --- a/opensrp-anc/src/main/java/org/smartregister/anc/library/activity/ContactSummaryFinishActivity.java +++ b/opensrp-anc/src/main/java/org/smartregister/anc/library/activity/ContactSummaryFinishActivity.java @@ -72,7 +72,7 @@ protected void onCreate(Bundle savedInstanceState) { mProfilePresenter = new ProfilePresenter(this); imageRenderHelper = new ImageRenderHelper(this); - loadContactSummaryData(); + } @@ -107,9 +107,17 @@ protected void loadContactSummaryData() { @Override public void onResume() { super.onResume(); - if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.R && Environment.isExternalStorageManager()) + if(isPermissionGranted()) + { + loadContactSummaryData(); + } + else if(!isPermissionGranted() && Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) { - generateFileinStorage(); + Intent intent = new Intent(); + intent.setAction(Settings.ACTION_MANAGE_APP_ALL_FILES_ACCESS_PERMISSION); + Uri uri = Uri.fromParts("package", this.getPackageName(), null); + intent.setData(uri); + startActivity(intent); } } @@ -239,10 +247,10 @@ public void setTaskCount(String taskCount) { } @Override - public void createContactSummaryPdf() { + public void createContactSummaryPdf(String womanName) { if (isPermissionGranted() && (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT)) { - generateFileinStorage(); + generateFileinStorage(womanName); } else if (!isPermissionGranted() && Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) { @@ -254,10 +262,10 @@ else if (!isPermissionGranted() && Build.VERSION.SDK_INT >= Build.VERSION_CODES. } } - public void generateFileinStorage() + public void generateFileinStorage(String womanName) { try { - new Utils().createSavePdf(this, yamlConfigList, facts); + new Utils().createSavePdf(this, yamlConfigList, facts,womanName); } catch (FileNotFoundException e) { Timber.e(e, "%s createContactSummaryPdf()", this.getClass().getCanonicalName()); } @@ -279,7 +287,7 @@ public void onRequestPermissionsResult(int requestCode, String[] permissions, in super.onRequestPermissionsResult(requestCode, permissions, grantResults); if (requestCode == PermissionUtils.WRITE_EXTERNAL_STORAGE_REQUEST_CODE) { if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) { - createContactSummaryPdf(); + loadContactSummaryData(); } else { displayToast(R.string.allow_phone_call_management); } diff --git a/opensrp-anc/src/main/java/org/smartregister/anc/library/activity/ProfileActivity.java b/opensrp-anc/src/main/java/org/smartregister/anc/library/activity/ProfileActivity.java index 4fafc6958..d8c242aa2 100644 --- a/opensrp-anc/src/main/java/org/smartregister/anc/library/activity/ProfileActivity.java +++ b/opensrp-anc/src/main/java/org/smartregister/anc/library/activity/ProfileActivity.java @@ -379,7 +379,7 @@ public void setTaskCount(String taskCount) { } @Override - public void createContactSummaryPdf() { + public void createContactSummaryPdf(String womanName) { //overridden } diff --git a/opensrp-anc/src/main/java/org/smartregister/anc/library/contract/ProfileContract.java b/opensrp-anc/src/main/java/org/smartregister/anc/library/contract/ProfileContract.java index 6ba0c5c8e..a58528915 100644 --- a/opensrp-anc/src/main/java/org/smartregister/anc/library/contract/ProfileContract.java +++ b/opensrp-anc/src/main/java/org/smartregister/anc/library/contract/ProfileContract.java @@ -29,7 +29,7 @@ interface Presenter extends BaseProfileContract.Presenter { void getTaskCount(String baseEntityId); - void createContactSummaryPdf(); + void createContactSummaryPdf(String womanName); } interface View extends BaseProfileContract.View { @@ -48,7 +48,7 @@ interface View extends BaseProfileContract.View { void setTaskCount(String taskCount); - void createContactSummaryPdf(); + void createContactSummaryPdf(String womanName); } diff --git a/opensrp-anc/src/main/java/org/smartregister/anc/library/presenter/ProfilePresenter.java b/opensrp-anc/src/main/java/org/smartregister/anc/library/presenter/ProfilePresenter.java index f4dac72ff..51d045624 100644 --- a/opensrp-anc/src/main/java/org/smartregister/anc/library/presenter/ProfilePresenter.java +++ b/opensrp-anc/src/main/java/org/smartregister/anc/library/presenter/ProfilePresenter.java @@ -168,7 +168,7 @@ public void getTaskCount(String baseEntityId) { } @Override - public void createContactSummaryPdf() { - getProfileView().createContactSummaryPdf(); + public void createContactSummaryPdf(String womanName) { + getProfileView().createContactSummaryPdf(womanName); } } \ No newline at end of file diff --git a/opensrp-anc/src/main/java/org/smartregister/anc/library/task/LoadContactSummaryDataTask.java b/opensrp-anc/src/main/java/org/smartregister/anc/library/task/LoadContactSummaryDataTask.java index 72b8f3cce..972a16fde 100644 --- a/opensrp-anc/src/main/java/org/smartregister/anc/library/task/LoadContactSummaryDataTask.java +++ b/opensrp-anc/src/main/java/org/smartregister/anc/library/task/LoadContactSummaryDataTask.java @@ -90,8 +90,11 @@ protected void onPostExecute(Void result) { //load profile details mProfilePresenter.refreshProfileView(baseEntityId); + String name = clientDetails.get(DBConstantsUtils.KeyUtils.FIRST_NAME); + if(clientDetails.get(DBConstantsUtils.KeyUtils.LAST_NAME)!= null) + name = name +" "+ clientDetails.get(DBConstantsUtils.KeyUtils.LAST_NAME); //Create PDF file stuff - mProfilePresenter.createContactSummaryPdf(); + mProfilePresenter.createContactSummaryPdf(name); } } diff --git a/opensrp-anc/src/main/java/org/smartregister/anc/library/util/Utils.java b/opensrp-anc/src/main/java/org/smartregister/anc/library/util/Utils.java index 8fa17a64f..c443c1315 100644 --- a/opensrp-anc/src/main/java/org/smartregister/anc/library/util/Utils.java +++ b/opensrp-anc/src/main/java/org/smartregister/anc/library/util/Utils.java @@ -990,9 +990,9 @@ public String getManifestVersion(Context context) { } } - public void createSavePdf(Context context, List yamlConfigList, Facts facts) throws FileNotFoundException { + public void createSavePdf(Context context, List yamlConfigList, Facts facts,String womanName) throws FileNotFoundException { - String FILENAME = context.getResources().getString(R.string.contact_summary_data_file); + String FILENAME = womanName+"_"+context.getResources().getString(R.string.contact_summary_data_file); String filePath = getAppPath(context) + FILENAME; if ((new File(filePath)).exists()) { @@ -1004,7 +1004,7 @@ public void createSavePdf(Context context, List yamlConfigList, Fact Document layoutDocument = new Document(pdfDocument); - addTitle(layoutDocument, context.getResources().getString(R.string.contact_summary_data, getTodaysDate())); + addTitle(layoutDocument, context.getResources().getString(R.string.contact_summary_data, getTodaysDate(),womanName)); for (YamlConfig yamlConfig : yamlConfigList) { diff --git a/opensrp-anc/src/main/res/values/strings.xml b/opensrp-anc/src/main/res/values/strings.xml index 91b5144c3..7b171e9cb 100644 --- a/opensrp-anc/src/main/res/values/strings.xml +++ b/opensrp-anc/src/main/res/values/strings.xml @@ -438,7 +438,7 @@ Partner HIV test Blood Glucose test Other test - Contact Summary Data - %1$s + Contact Summary Data - %1$s \n %2$s \"Pdf saved successfully to location \" contactSummaryData.pdf diff --git a/reference-app/build.gradle b/reference-app/build.gradle index dd35b5224..8fe9a2f70 100644 --- a/reference-app/build.gradle +++ b/reference-app/build.gradle @@ -230,7 +230,7 @@ dependencies { coreLibraryDesugaring 'com.android.tools:desugar_jdk_libs:1.1.5' def powerMockVersion = '2.0.7' implementation project(":opensrp-anc") - implementation('org.smartregister:opensrp-client-native-form:2.1.17-SNAPSHOT@aar') { + implementation('org.smartregister:opensrp-client-native-form:2.1.16-PREVIEW-SNAPSHOT@aar') { transitive = true exclude group: 'com.android.support', module: 'recyclerview-v7' exclude group: 'com.android.support', module: 'appcompat-v7'