Skip to content

Commit

Permalink
Merge branch 'release-2.5.3'
Browse files Browse the repository at this point in the history
* release-2.5.3: (22 commits)
  Update versionCode and versionName for 2.5.3 release
  Update translations
  AlarmScheduler: fix crash when alarms are received outside the window
  FingerprintHelper: properly check for Android version
  PinLockActivity: make fingerprint helper start when activity is resumed
  ScheduleTimetableFragment: externalize stray hardcoded string
  MedicinesSearchActivity: show soft keyboard and focus search bar when opening
  Get rid of settings.properties files in favor of build config fields
  Add screenshots for the 2.5 version (english)
  added German metadata (play store description)
  ScheduleTimetableFragment: wrap context for DatePickers
  Add metadata folder with store descriptions.
  proguard: Add rules for JSoup
  Database prefs: Ask for external write permission before download.
  MedicinesSearch: refresh barcode button visibility on resume
  StockCalculatorTest: add another case
  Suppress unchecked cast warnings for attachView on base MVP classes
  Update instance state bundle key
  Add StatefulPresenter and StatefulBaseActivityView
  settings: move common MVP functionality to CalendulaPrefsFragment
  ...
  • Loading branch information
AlvaroBrey committed Mar 6, 2018
2 parents 39e6e96 + b618231 commit c476575
Show file tree
Hide file tree
Showing 55 changed files with 587 additions and 302 deletions.
7 changes: 4 additions & 3 deletions Calendula/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'kotlin-kapt'
apply plugin: 'idea'

// build config fields
apply from: 'config.gradle'


repositories {
Expand Down Expand Up @@ -76,8 +77,8 @@ android {
defaultConfig {
minSdkVersion 16
targetSdkVersion 25
versionCode 33
versionName "2.5.2"
versionCode 34
versionName "2.5.3"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
applicationId "es.usc.citius.servando.calendula"
multiDexEnabled true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,9 @@
* along with this software. If not, see <http://www.gnu.org/licenses/>.
*/

package es.usc.citius.servando.calendula.util;


public class SettingsPropertiesKeys {

public static final String DATABASE_LOCATION = "db.url";
public static final String GENERATE_TEST_DATA = "test.generate.testdata";

private SettingsPropertiesKeys() {
android {
defaultConfig {
buildConfigField 'String', 'DB_DOWNLOAD_URL', '"http://tec.citius.usc.es/calendula/dbs/"'
buildConfigField 'boolean', 'TEST_GENERATE_TESTDATA', 'false'
}
}
}
1 change: 1 addition & 0 deletions Calendula/proguard/proguard-jsoup.pro
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
-keeppackagenames org.jsoup.nodes
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import org.junit.Before;
import org.junit.Test;

import es.usc.citius.servando.calendula.BuildConfig;
import es.usc.citius.servando.calendula.CalendulaApp;
import es.usc.citius.servando.calendula.R;
import es.usc.citius.servando.calendula.database.DB;
Expand Down
4 changes: 2 additions & 2 deletions Calendula/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.VIBRATE"/>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.WAKE_LOCK"/>
Expand Down Expand Up @@ -81,7 +81,7 @@
android:name=".activities.MedicinesSearchActivity"
android:label="@string/title_activity_medicines_search"
android:screenOrientation="portrait"
android:windowSoftInputMode="adjustPan"/>
android:windowSoftInputMode="stateVisible"/>
<activity
android:name=".activities.ScheduleCreationActivity"
android:label="@string/title_activity_schedules"
Expand Down
20 changes: 0 additions & 20 deletions Calendula/src/main/assets/settings.properties

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,12 @@ public void handleDbInstalled(PersistenceEvents.DatabaseInstalledEvent event) {
LogUtil.d(TAG, "handleDbInstalled() called with: event = [" + event + "]");
// enable barcode scan

refreshViews();

}

private void refreshViews() {
// TODO: 23/02/18 the current DBVersionMgr should tell us if the DB can handle barcodes
if (!PreferenceUtils.getString(PreferenceKeys.DRUGDB_CURRENT_DB, CalendulaApp.getContext().getString(R.string.database_none_id))
.equals(CalendulaApp.getContext().getString(R.string.database_none_id))) {
runOnUiThread(new Runnable() {
Expand All @@ -194,7 +200,6 @@ public void run() {
}
});
}

}


Expand Down Expand Up @@ -268,6 +273,7 @@ public void afterTextChanged(Editable s) {
final String search = getIntent().getStringExtra(EXTRA_SEARCH_TERM);
if (search != null) {
searchEditText.setText(search);
searchEditText.setSelection(search.length());
}

searchList.setOnItemClickListener(new AdapterView.OnItemClickListener() {
Expand Down Expand Up @@ -302,10 +308,8 @@ public boolean onTouch(View v, MotionEvent event) {
if (!PreferenceUtils.getString(PreferenceKeys.DRUGDB_CURRENT_DB, CalendulaApp.getContext().getString(R.string.database_none_id))
.equals(CalendulaApp.getContext().getString(R.string.database_none_id))) {
enableBarcodeScan();
} else {
if (!PreferenceUtils.getBoolean(PreferenceKeys.MEDICINES_USE_PRESCRIPTIONS_SHOWN, false)) {
askForDatabase();
}
} else if (!PreferenceUtils.getBoolean(PreferenceKeys.MEDICINES_USE_PRESCRIPTIONS_SHOWN, false)) {
askForDatabase();
}


Expand Down Expand Up @@ -379,6 +383,7 @@ protected void addCustomMed() {
protected void onResume() {
super.onResume();
EventBus.getDefault().register(this);
refreshViews();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,13 @@
import java.util.List;
import java.util.Map;

import es.usc.citius.servando.calendula.BuildConfig;
import es.usc.citius.servando.calendula.R;
import es.usc.citius.servando.calendula.database.DatabaseHelper;
import es.usc.citius.servando.calendula.util.HttpDownloadUtil;
import es.usc.citius.servando.calendula.util.LogUtil;
import es.usc.citius.servando.calendula.util.PreferenceKeys;
import es.usc.citius.servando.calendula.util.PreferenceUtils;
import es.usc.citius.servando.calendula.util.SettingsProperties;
import es.usc.citius.servando.calendula.util.SettingsPropertiesKeys;


public class DBVersionManager {
Expand All @@ -56,7 +55,7 @@ public class DBVersionManager {
* @return the newest working version
*/
public static String getLastDBVersion(String databaseID) {
final String downloadUrl = SettingsProperties.instance().get(SettingsPropertiesKeys.DATABASE_LOCATION);
final String downloadUrl = BuildConfig.DB_DOWNLOAD_URL;
final String url = downloadUrl + VERSION_FILE;

try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,14 @@
import java.io.File;
import java.net.URI;

import es.usc.citius.servando.calendula.BuildConfig;
import es.usc.citius.servando.calendula.R;
import es.usc.citius.servando.calendula.drugdb.DBRegistry;
import es.usc.citius.servando.calendula.drugdb.PrescriptionDBMgr;
import es.usc.citius.servando.calendula.util.LogUtil;
import es.usc.citius.servando.calendula.util.NetworkUtils;
import es.usc.citius.servando.calendula.util.PreferenceKeys;
import es.usc.citius.servando.calendula.util.PreferenceUtils;
import es.usc.citius.servando.calendula.util.SettingsProperties;
import es.usc.citius.servando.calendula.util.SettingsPropertiesKeys;

public class DownloadDatabaseHelper {

Expand Down Expand Up @@ -197,7 +196,7 @@ protected Boolean doInBackground(String... params) {
final DownloadManager manager = (DownloadManager) ctx.getSystemService(Context.DOWNLOAD_SERVICE);


final String downloadUrl = SettingsProperties.instance().get(SettingsPropertiesKeys.DATABASE_LOCATION);
final String downloadUrl = BuildConfig.DB_DOWNLOAD_URL;
final String dbName = mgr.id();

try {//get version
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,21 @@

import android.app.AlertDialog;
import android.app.DatePickerDialog;
import android.content.ContextWrapper;
import android.content.DialogInterface;
import android.content.res.Resources;
import android.graphics.Color;
import android.graphics.Typeface;
import android.graphics.drawable.GradientDrawable;
import android.graphics.drawable.StateListDrawable;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.text.Html;
import android.text.Spanned;
import android.text.format.Time;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
Expand Down Expand Up @@ -66,6 +70,7 @@
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.IllegalFormatConversionException;
import java.util.List;

import es.usc.citius.servando.calendula.R;
Expand Down Expand Up @@ -204,7 +209,7 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container,

setupScheduleSpinner();
setupDaySelectionListeners(rootView);
setupHourlyRepetitionLinsteners();
setupHourlyRepetitionListeners();
setupStartEndDatePickers(rootView);
setupForCurrentSchedule(rootView);
setupCycleSpinner();
Expand Down Expand Up @@ -288,7 +293,7 @@ public void onTimeSet(RadialTimePickerDialogFragment dialog, int hour, int minut
schedule.setStartTime(new LocalTime(hour, minute));
}

void setupHourlyRepetitionLinsteners() {
void setupHourlyRepetitionListeners() {
hourlyIntervalEditText.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Expand Down Expand Up @@ -320,6 +325,38 @@ public void onClick(View v) {

void setupStartEndDatePickers(View rootView) {

/*
* Needed to fix crashes on samsung 5.0 devices.
*
* See: https://stackoverflow.com/q/28618405/4243049
*/
final ContextWrapper datePickerContext = new ContextWrapper(getActivity()) {

private Resources wrappedResources;

@Override
public Resources getResources() {
Resources r = super.getResources();
if(wrappedResources == null) {
wrappedResources = new Resources(r.getAssets(), r.getDisplayMetrics(), r.getConfiguration()) {
@NonNull
@Override
public String getString(int id, Object... formatArgs) throws NotFoundException {
try {
return super.getString(id, formatArgs);
} catch (IllegalFormatConversionException e) {
Log.w(TAG, "Trying to fix resource exception", e);
String template = super.getString(id);
template = template.replaceAll("%" + e.getConversion(), "%s");
return String.format(getConfiguration().locale, template, formatArgs);
}
}
};
}
return wrappedResources;
}
};

if (schedule.start() == null) {
schedule.setStart(LocalDate.now());
}
Expand All @@ -331,7 +368,7 @@ void setupStartEndDatePickers(View rootView) {
public void onClick(View v) {

DatePickerDialog dpd =
new DatePickerDialog(getActivity(), new DatePickerDialog.OnDateSetListener() {
new DatePickerDialog(datePickerContext, new DatePickerDialog.OnDateSetListener() {
@Override
public void onDateSet(DatePicker view, int year, int monthOfYear,
int dayOfMonth) {
Expand All @@ -353,7 +390,7 @@ public void onClick(View v) {
schedule.end() != null ? schedule.end() : scheduleStart.plusMonths(3);

DatePickerDialog dpd =
new DatePickerDialog(getActivity(), new DatePickerDialog.OnDateSetListener() {
new DatePickerDialog(datePickerContext, new DatePickerDialog.OnDateSetListener() {
@Override
public void onDateSet(DatePicker view, int year, int monthOfYear,
int dayOfMonth) {
Expand All @@ -370,7 +407,7 @@ public void onDateSet(DatePicker view, int year, int monthOfYear,
@Override
public boolean onLongClick(View v) {
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
builder.setMessage("Do you want this schedule to continue indefinitely?")
builder.setMessage(R.string.schedule_continue_indefinitely)
.setCancelable(true)
.setPositiveButton(getString(R.string.dialog_yes_option),
new DialogInterface.OnClickListener() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@
import es.usc.citius.servando.calendula.util.PreferenceKeys;
import es.usc.citius.servando.calendula.util.PreferenceUtils;
import es.usc.citius.servando.calendula.util.PresentationsTypeface;
import es.usc.citius.servando.calendula.util.SettingsProperties;


public class BaseModule extends CalendulaModule {
Expand Down Expand Up @@ -97,13 +96,6 @@ public void setupUpdateDailyAgendaAlarm(Context ctx) {
protected void onApplicationStartup(Context ctx) {
PreferenceUtils.init(ctx);


try {
SettingsProperties.init(ctx);
} catch (IOException e) {
LogUtil.e(TAG, "onApplicationStartup: An exception happened when loading settings file");
}

// initialize SQLite engine
initializeDatabase(ctx);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import java.util.Map;
import java.util.concurrent.Callable;

import es.usc.citius.servando.calendula.BuildConfig;
import es.usc.citius.servando.calendula.activities.PatientDetailActivity;
import es.usc.citius.servando.calendula.database.DB;
import es.usc.citius.servando.calendula.modules.CalendulaModule;
Expand All @@ -47,8 +48,6 @@
import es.usc.citius.servando.calendula.util.LogUtil;
import es.usc.citius.servando.calendula.util.PreferenceKeys;
import es.usc.citius.servando.calendula.util.PreferenceUtils;
import es.usc.citius.servando.calendula.util.SettingsProperties;
import es.usc.citius.servando.calendula.util.SettingsPropertiesKeys;

public class TestDataModule extends CalendulaModule {

Expand All @@ -73,7 +72,7 @@ protected void onApplicationStartup(final Context ctx) {
final boolean testDataGenerated = PreferenceUtils.getBoolean(PreferenceKeys.TEST_DATA_GENERATED, false);
if (testDataGenerated) {
LogUtil.d(TAG, "onApplicationStartup: Test data already generated, skipping");
} else if (!SettingsProperties.instance().get(SettingsPropertiesKeys.GENERATE_TEST_DATA).equals("yes")) {
} else if (!BuildConfig.TEST_GENERATE_TESTDATA) {
LogUtil.d(TAG, "onApplicationStartup: GENERATE_TEST_DATA is not set");
} else {
LogUtil.d(TAG, "onApplicationStartup: Generating test data");
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*
* Calendula - An assistant for personal medication management.
* Copyright (C) 2016 CITIUS - USC
*
* Calendula is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this software. If not, see <http://www.gnu.org/licenses/>.
*/

package es.usc.citius.servando.calendula.mvp

import android.os.Bundle
import es.usc.citius.servando.calendula.CalendulaActivity


abstract class BaseActivityView<in V : IView, out P : IPresenter<V>> : CalendulaActivity(), IView {

abstract val presenter: P

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
@Suppress("UNCHECKED_CAST")
presenter.attachView(this as V)
}

override fun onDestroy() {
presenter.detachView()
super.onDestroy()
}
}
Loading

0 comments on commit c476575

Please sign in to comment.