diff --git a/gradle.properties b/gradle.properties index ab52d5fa0..adc40ab8b 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,4 +1,4 @@ -VERSION_NAME=6.1.0-SNAPSHOT +VERSION_NAME=6.1.1-SNAPSHOT VERSION_CODE=1 GROUP=org.smartregister POM_SETTING_DESCRIPTION=OpenSRP Client Core Application diff --git a/opensrp-core/src/main/java/org/smartregister/util/StatsUtils.java b/opensrp-core/src/main/java/org/smartregister/util/StatsUtils.java index 1b2af7776..7e733aeae 100644 --- a/opensrp-core/src/main/java/org/smartregister/util/StatsUtils.java +++ b/opensrp-core/src/main/java/org/smartregister/util/StatsUtils.java @@ -61,6 +61,8 @@ public Map fetchStatsInfo() { } private void populateSyncStatistics() { + Cursor cursor = null; + try { syncInfoMap.put(SYNCED_EVENTS, "-"); syncInfoMap.put(SYNCED_CLIENTS, "-"); @@ -86,8 +88,6 @@ private void populateSyncStatistics() { String unsyncedWeightEventsSQL = "SELECT COUNT(*) FROM weights WHERE sync_status = 'Unsynced'"; String unsyncedHeightEventsSQL = "SELECT COUNT(*) FROM heights WHERE sync_status = 'Unsynced'"; - Cursor cursor; - cursor = database.rawQuery(eventSyncSql, new String[]{}); while (cursor.moveToNext()) { populateEventSyncInfo(cursor); @@ -110,26 +110,33 @@ private void populateSyncStatistics() { while (cursor.moveToNext()) { populateValidatedClientsInfo(cursor); } + cursor.close(); cursor = database.rawQuery(unsyncedVaccineEventsSQL, new String[]{}); while (cursor.moveToNext()) { syncInfoMap.put(UNSYNCED_VACCINE_EVENTS, String.valueOf(cursor.getInt(0))); } + cursor.close(); cursor = database.rawQuery(unsyncedWeightEventsSQL, new String[]{}); while (cursor.moveToNext()) { syncInfoMap.put(UNSYNCED_WEIGHT_EVENTS, String.valueOf(cursor.getInt(0))); } + cursor.close(); + if (CoreLibrary.getInstance().context().getAppProperties().isTrue("monitor.height")) { // Constant is defined in growth-monitoring module cursor = database.rawQuery(unsyncedHeightEventsSQL, new String[]{}); while (cursor.moveToNext()) { syncInfoMap.put(UNSYNCED_HEIGHT_EVENTS, String.valueOf(cursor.getInt(0))); } + cursor.close(); } - - cursor.close(); } catch (Exception e) { Timber.e(e); + } finally { + if (cursor != null) { + cursor.close(); + } } } @@ -183,7 +190,6 @@ public void populateUserInfo() { syncInfoMap.put(USER_LOCALITY, StringUtils.isNotBlank(userLocality) ? userLocality : "-"); } - private void populateBuildInfo() { try { syncInfoMap.put(APP_VERSION_NAME, Utils.getVersion(CoreLibrary.getInstance().context().applicationContext())); @@ -216,6 +222,5 @@ private void populateDeviceInfo() { } catch (Exception e) { Timber.e(e); } - } } diff --git a/sample/src/main/java/org/smartregister/sample/MainActivity.java b/sample/src/main/java/org/smartregister/sample/MainActivity.java index 183f39d70..2d73d69c5 100644 --- a/sample/src/main/java/org/smartregister/sample/MainActivity.java +++ b/sample/src/main/java/org/smartregister/sample/MainActivity.java @@ -69,16 +69,14 @@ protected void onCreate(Bundle savedInstanceState) { encDecTextView = (TextView) findViewById(R.id.encrypt_decrypt_tv); picker.setMinDate(new LocalDate().minusYears(2).toDate().getTime()); - picker.setMaxDate(new LocalDate().plusYears(3).toDate().getTime()); - picker.updateDate(2019, 5, 22); btnGet = (Button) findViewById(R.id.button1); btnGet.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { - tvw.setText("Selected Date: " + picker.getDayOfMonth() + "/" + (picker.getMonth() + 1) + "/" + picker.getYear()); + tvw.setText(getString(R.string.selected_date_format, picker.getDayOfMonth(), (picker.getMonth() + 1), picker.getYear())); } }); @@ -87,7 +85,8 @@ public void onClick(View v) { @Override public void onClick(View view) { Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG) - .setAction("Action", null).show(); + .setAction("Action", null) + .show(); } }); SmartRegisterQueryBuilder srqb = new SmartRegisterQueryBuilder(); @@ -108,7 +107,6 @@ public void onClick(View view) { // set language from preferences String langPref = LangUtils.getLanguage(activity.getApplicationContext()); for (int i = 0; i < langArray.size(); i++) { - if (langPref != null && langArray.get(i).toLowerCase().startsWith(langPref)) { languageSpinner.setSelection(i); break; @@ -169,12 +167,11 @@ public void onNothingSelected(AdapterView parent) { fos.write(contents.getBytes()); fos.flush(); } catch (FileNotFoundException e) { - e.printStackTrace(); + Timber.e(e); } catch (IOException e) { - e.printStackTrace(); + Timber.e(e); } - toggle.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { String keyAlias = "sample"; @@ -184,53 +181,81 @@ public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { Timber.i("key with alias %s generated", keyAlias); } - if (isChecked) { + FileInputStream inputStream = null; + FileOutputStream fileOutputStream = null; + if (isChecked) { try { // read the text.txt while it is in plain text and write to file - FileInputStream inputStream = openFileInput(filename); + inputStream = openFileInput(filename); byte[] inputBytes = new byte[inputStream.available()]; inputStream.read(inputBytes); byte[] encryptedContents = CryptographicHelper.encrypt(inputBytes, keyAlias); - FileOutputStream fileOutputStream = openFileOutput(filename, Context.MODE_PRIVATE); + Timber.i("encrypted stuff to write %S ", new String(encryptedContents)); + encDecTextView.setText(new String(encryptedContents)); + + fileOutputStream = openFileOutput(filename, Context.MODE_PRIVATE); fileOutputStream.write((encryptedContents)); fileOutputStream.flush(); - - } catch (IOException e) { - e.printStackTrace(); + Timber.e(e); + } finally { + if (inputStream != null) { + try { + inputStream.close(); + } catch (IOException e) { + Timber.e(e); + } + } + + if (fileOutputStream != null) { + try { + fileOutputStream.close(); + } catch (IOException e) { + Timber.e(e); + } + } } - } else { try { - // - FileInputStream inputStream = openFileInput(filename); + inputStream = openFileInput(filename); byte[] inputBytes = new byte[inputStream.available()]; inputStream.read(inputBytes); + Timber.i("before decryption %s", new String(inputBytes)); byte[] decryptedStuff = CryptographicHelper.decrypt(inputBytes, keyAlias); encDecTextView.setText(new String(decryptedStuff)); + Timber.i("decrypted content %s", new String(decryptedStuff)); - FileOutputStream fileOutputStream = openFileOutput(filename, Context.MODE_PRIVATE); + fileOutputStream = openFileOutput(filename, Context.MODE_PRIVATE); fileOutputStream.write((decryptedStuff)); fileOutputStream.flush(); - - } catch (IOException e) { - e.printStackTrace(); - // Error occurred when opening raw file for reading. + Timber.e(e); + } finally { + if (inputStream != null) { + try { + inputStream.close(); + } catch (IOException e) { + Timber.e(e); + } + } + + if (fileOutputStream != null) { + try { + fileOutputStream.close(); + } catch (IOException e) { + Timber.e(e); + } + } } - - } } }); - - } @Override diff --git a/sample/src/main/res/values/strings.xml b/sample/src/main/res/values/strings.xml index 6c38a7759..c72323e99 100644 --- a/sample/src/main/res/values/strings.xml +++ b/sample/src/main/res/values/strings.xml @@ -5,6 +5,7 @@ Night gathers, and now my watch begins Select Language Sample Reports + Selected Date: %1$d/%2$d/%3$d Sync Statistics Show Sync Stats (Long Press for Dialog) Please encrypt or decrypt me by hitting clicking on the switch below