1
0
mirror of https://github.com/oliexdev/openScale.git synced 2025-08-30 03:30:30 +02:00

Merge pull request #197 from erijo/measurements

Measurements
This commit is contained in:
OliE
2018-02-20 17:03:27 +01:00
committed by GitHub
18 changed files with 110 additions and 66 deletions

View File

@@ -17,7 +17,6 @@
package com.health.openscale;
import android.arch.persistence.db.SupportSQLiteDatabase;
import android.arch.persistence.db.SupportSQLiteOpenHelper;
import android.arch.persistence.db.framework.FrameworkSQLiteOpenHelperFactory;
import android.arch.persistence.room.testing.MigrationTestHelper;
import android.content.ContentValues;

View File

@@ -19,8 +19,6 @@ package com.health.openscale.core.bluetooth;
import android.bluetooth.BluetoothGatt;
import android.bluetooth.BluetoothGattCharacteristic;
import android.content.Context;
import android.content.SharedPreferences;
import android.preference.PreferenceManager;
import com.health.openscale.core.OpenScale;
import com.health.openscale.core.datatypes.ScaleMeasurement;

View File

@@ -26,7 +26,6 @@ import android.util.Log;
import com.health.openscale.core.OpenScale;
import com.health.openscale.core.datatypes.ScaleMeasurement;
import com.health.openscale.core.datatypes.ScaleUser;
import com.health.openscale.core.utils.Converters;
import java.text.ParseException;
import java.text.SimpleDateFormat;

View File

@@ -64,7 +64,8 @@ import java.lang.reflect.Field;
import cat.ereza.customactivityoncrash.config.CaocConfig;
public class MainActivity extends AppCompatActivity {
public class MainActivity extends AppCompatActivity
implements SharedPreferences.OnSharedPreferenceChangeListener{
private static boolean firstAppStart = true;
private static boolean valueOfCountModified = false;
private static int bluetoothStatusIcon = R.drawable.ic_bluetooth_disabled;
@@ -79,7 +80,9 @@ public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
String app_theme = PreferenceManager.getDefaultSharedPreferences(this).getString("app_theme", "Light");
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
String app_theme = prefs.getString("app_theme", "Light");
if (app_theme.equals("Dark")) {
setTheme(R.style.AppTheme_Dark);
@@ -137,8 +140,6 @@ public class MainActivity extends AppCompatActivity {
// Setup drawer view
setupDrawerContent(navDrawer);
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
selectDrawerItem(prefs.getInt("lastFragmentId", R.id.nav_overview));
navBottomDrawer.setSelectedItemId(prefs.getInt("lastFragmentId", R.id.nav_overview));
@@ -182,6 +183,35 @@ public class MainActivity extends AppCompatActivity {
}
}
private void registerOnSharedPreferenceChangeListener() {
PreferenceManager.getDefaultSharedPreferences(this)
.registerOnSharedPreferenceChangeListener(this);
}
private void unregisterOnSharedPreferenceChangeListener() {
PreferenceManager.getDefaultSharedPreferences(this)
.unregisterOnSharedPreferenceChangeListener(this);
}
@Override
public void onResume() {
super.onResume();
// Stop listening when returning from settings
unregisterOnSharedPreferenceChangeListener();
}
@Override
public void onDestroy() {
// Clean up when shutting down
unregisterOnSharedPreferenceChangeListener();
super.onDestroy();
}
@Override
public void onSharedPreferenceChanged(SharedPreferences preferences, String key) {
recreate();
}
private void positiveFeedbackDialog() {
AlertDialog.Builder builder = new AlertDialog.Builder(this);
@@ -277,12 +307,15 @@ public class MainActivity extends AppCompatActivity {
prefs.edit().putInt("lastFragmentId", menuItemId).commit();
break;
case R.id.nav_settings:
registerOnSharedPreferenceChangeListener();
Intent settingsIntent = new Intent(this, SettingsActivity.class);
settingsIntent.putExtra(SettingsActivity.EXTRA_TINT_COLOR, navDrawer.getItemTextColor().getDefaultColor());
startActivity(settingsIntent);
drawerLayout.closeDrawers();
return;
case R.id.nav_help:
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("https://github.com/oliexdev/openScale/wiki")));
drawerLayout.closeDrawers();
return;
default:
fragmentClass = OverviewFragment.class;
@@ -511,7 +544,7 @@ public class MainActivity extends AppCompatActivity {
item.setPadding(0, 20, 0, 0);
// set once again checked value, so view will be updated
//noinspection RestrictedApi
//item.setChecked(item.getItemData().isChecked());
item.setChecked(item.getItemData().isChecked());
}
} catch (NoSuchFieldException e) {
Log.e("BNVHelper", "Unable to get shift mode field", e);

View File

@@ -31,6 +31,7 @@ import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.TableLayout;
import android.widget.TextView;
import android.widget.Toast;
@@ -72,6 +73,10 @@ public class DataEntryActivity extends AppCompatActivity {
private Context context;
private boolean isAddActivity() {
return !getIntent().hasExtra(EXTRA_ID);
}
@Override
protected void onCreate(Bundle savedInstanceState) {
String app_theme = PreferenceManager.getDefaultSharedPreferences(this).getString("app_theme", "Light");
@@ -94,7 +99,8 @@ public class DataEntryActivity extends AppCompatActivity {
tableLayoutDataEntry = (TableLayout) findViewById(R.id.tableLayoutDataEntry);
dataEntryMeasurements = MeasurementView.getMeasurementList(context);
dataEntryMeasurements = MeasurementView.getMeasurementList(
context, MeasurementView.DateTimeOrder.LAST);
txtDataNr = (TextView) findViewById(R.id.txtDataNr);
btnLeft = (Button) findViewById(R.id.btnLeft);
@@ -116,12 +122,19 @@ public class DataEntryActivity extends AppCompatActivity {
}
});
final MeasurementView.MeasurementViewMode mode = isAddActivity()
? MeasurementView.MeasurementViewMode.ADD
: MeasurementView.MeasurementViewMode.VIEW;
for (MeasurementView measurement : dataEntryMeasurements) {
measurement.setEditMode(mode);
}
updateOnView();
onMeasurementViewUpdateListener updateListener = new onMeasurementViewUpdateListener();
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
final boolean expand = getIntent().hasExtra(EXTRA_ID)
? prefs.getBoolean(PREF_EXPAND, true) : false;
final boolean expand = isAddActivity()
? false : prefs.getBoolean(PREF_EXPAND, true);
for (MeasurementView measurement : dataEntryMeasurements) {
tableLayoutDataEntry.addView(measurement);
@@ -182,11 +195,11 @@ public class DataEntryActivity extends AppCompatActivity {
deleteButton = menu.findItem(R.id.deleteButton);
// Hide/show icons as appropriate for the view mode
if (getIntent().hasExtra(EXTRA_ID)) {
setViewMode(MeasurementView.MeasurementViewMode.VIEW);
if (isAddActivity()) {
setViewMode(MeasurementView.MeasurementViewMode.ADD);
}
else {
setViewMode(MeasurementView.MeasurementViewMode.ADD);
setViewMode(MeasurementView.MeasurementViewMode.VIEW);
}
return super.onCreateOptionsMenu(menu);
@@ -248,12 +261,6 @@ public class DataEntryActivity extends AppCompatActivity {
}
private void updateOnView() {
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
for (MeasurementView measurement : dataEntryMeasurements) {
measurement.updatePreferences(prefs);
}
int id = 0;
if (getIntent().hasExtra(EXTRA_ID)) {
id = getIntent().getExtras().getInt(EXTRA_ID);
@@ -316,6 +323,7 @@ public class DataEntryActivity extends AppCompatActivity {
expandButton.setVisible(true);
deleteButton.setVisible(true);
((LinearLayout)txtDataNr.getParent()).setVisibility(View.VISIBLE);
btnLeft.setVisibility(View.VISIBLE);
btnRight.setVisibility(View.VISIBLE);
btnLeft.setEnabled(previousMeasurement != null);
@@ -329,6 +337,7 @@ public class DataEntryActivity extends AppCompatActivity {
expandButton.setVisible(true);
deleteButton.setVisible(true);
((LinearLayout)txtDataNr.getParent()).setVisibility(View.VISIBLE);
btnLeft.setVisibility(View.VISIBLE);
btnRight.setVisibility(View.VISIBLE);
btnLeft.setEnabled(false);
@@ -340,8 +349,7 @@ public class DataEntryActivity extends AppCompatActivity {
expandButton.setVisible(false);
deleteButton.setVisible(false);
btnLeft.setVisibility(View.GONE);
btnRight.setVisibility(View.GONE);
((LinearLayout)txtDataNr.getParent()).setVisibility(View.GONE);
break;
}

View File

@@ -16,6 +16,7 @@
package com.health.openscale.gui.activities;
import android.app.Fragment;
import android.content.SharedPreferences;
import android.graphics.PorterDuff;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
@@ -30,7 +31,8 @@ import com.health.openscale.gui.utils.PermissionHelper;
import java.util.ArrayList;
import java.util.List;
public class SettingsActivity extends PreferenceActivity {
public class SettingsActivity extends PreferenceActivity
implements SharedPreferences.OnSharedPreferenceChangeListener {
public static String EXTRA_TINT_COLOR = "tintColor";
private static List<String> fragments = new ArrayList<String>();
private Fragment currentFragment;
@@ -46,6 +48,28 @@ public class SettingsActivity extends PreferenceActivity {
super.onCreate(savedInstanceState);
}
@Override
public void onResume() {
super.onResume();
PreferenceManager.getDefaultSharedPreferences(this)
.registerOnSharedPreferenceChangeListener(this);
}
@Override
public void onPause() {
PreferenceManager.getDefaultSharedPreferences(this)
.unregisterOnSharedPreferenceChangeListener(this);
super.onPause();
}
@Override
public void onSharedPreferenceChanged(SharedPreferences preferences, String key) {
if (key.equals("app_theme")) {
recreate();
}
}
@Override
public void onBuildHeaders(List<Header> target) {
loadHeadersFromResource(R.xml.header_preferences, target);

View File

@@ -174,14 +174,14 @@ public class GraphFragment extends Fragment implements FragmentUpdateListener {
}
});
measurementViews = MeasurementView.getMeasurementList(getContext());
measurementViews = MeasurementView.getMeasurementList(
getContext(), MeasurementView.DateTimeOrder.NONE);
popup = new PopupMenu(getContext(), optionMenu);
popup.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem item) {
switch (item.getItemId()) {
case R.id.enableMonth:
if (item.isChecked()) {
@@ -315,7 +315,6 @@ public class GraphFragment extends Fragment implements FragmentUpdateListener {
continue;
}
measurementView.updatePreferences(prefs);
Stack<PointValue> valuesStack = new Stack<PointValue>();
for (ScaleMeasurement measurement : scaleMeasurementList) {

View File

@@ -38,10 +38,8 @@ import com.health.openscale.core.datatypes.ScaleMeasurement;
import com.health.openscale.core.datatypes.ScaleUser;
import com.health.openscale.core.utils.Converters;
import com.health.openscale.core.utils.DateTimeHelpers;
import com.health.openscale.gui.views.DateMeasurementView;
import com.health.openscale.gui.views.FloatMeasurementView;
import com.health.openscale.gui.views.MeasurementView;
import com.health.openscale.gui.views.TimeMeasurementView;
import java.text.DateFormat;
import java.util.ArrayList;
@@ -120,13 +118,10 @@ public class OverviewFragment extends Fragment implements FragmentUpdateListener
pieChartLast.setOnValueTouchListener(new PieChartLastTouchListener());
pieChartLast.setChartRotationEnabled(false);
measurementViews = MeasurementView.getMeasurementList(getContext());
measurementViews = MeasurementView.getMeasurementList(
getContext(), MeasurementView.DateTimeOrder.NONE);
for (MeasurementView measurement : measurementViews) {
if (measurement instanceof DateMeasurementView || measurement instanceof TimeMeasurementView) {
continue;
}
tableOverviewLayout.addView(measurement);
}
@@ -171,11 +166,6 @@ public class OverviewFragment extends Fragment implements FragmentUpdateListener
updateLastLineChart(scaleMeasurementList);
for (MeasurementView measurement : measurementViews) {
if (measurement instanceof DateMeasurementView || measurement instanceof TimeMeasurementView) {
continue;
}
measurement.updatePreferences(prefs);
measurement.loadFrom(lastScaleMeasurement, prevScaleMeasurement);
}
}
@@ -230,8 +220,6 @@ public class OverviewFragment extends Fragment implements FragmentUpdateListener
continue;
}
measurementView.updatePreferences(prefs);
Stack<PointValue> valuesStack = new Stack<PointValue>();
scaleMeasurementLastDays = new ArrayList<>();
@@ -292,7 +280,6 @@ public class OverviewFragment extends Fragment implements FragmentUpdateListener
continue;
}
measurementView.updatePreferences(prefs);
measurementView.loadFrom(lastScaleMeasurement, null);
if (measurementView.getValue() != 0) {

View File

@@ -112,7 +112,8 @@ public class TableFragment extends Fragment implements FragmentUpdateListener {
selectedSubpageNr = savedInstanceState.getInt(SELECTED_SUBPAGE_NR_KEY);
}
measurementViews = MeasurementView.getMeasurementList(getContext());
measurementViews = MeasurementView.getMeasurementList(
getContext(), MeasurementView.DateTimeOrder.FIRST);
for (MeasurementView measurement : measurementViews) {
measurement.setUpdateViews(false);
@@ -218,7 +219,6 @@ public class TableFragment extends Fragment implements FragmentUpdateListener {
ArrayList<MeasurementView> visibleMeasurements = new ArrayList<>();
for (MeasurementView measurement : measurementViews) {
measurement.updatePreferences(prefs);
if (measurement.isVisible()) {
ImageView headerIcon = new ImageView(tableView.getContext());

View File

@@ -44,16 +44,6 @@ public class GeneralPreferences extends PreferenceFragment implements SharedPref
appThemeList = (ListPreference)findPreference(PREFERENCE_KEY_APP_THEME);
appThemeList.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
@Override
public boolean onPreferenceChange(Preference preference, Object o) {
Toast.makeText(getActivity().getApplicationContext(), getResources().getString(R.string.info_app_restart_required), Toast.LENGTH_LONG).show();
return true;
}
});
initSummary(getPreferenceScreen());
}

View File

@@ -26,7 +26,6 @@ import android.preference.MultiSelectListPreference;
import android.preference.Preference;
import android.preference.PreferenceFragment;
import android.preference.PreferenceGroup;
import android.preference.PreferenceManager;
import android.preference.SwitchPreference;
import android.widget.Toast;

View File

@@ -16,11 +16,9 @@
package com.health.openscale.gui.preferences;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.preference.Preference;
import android.preference.PreferenceFragment;
import android.preference.PreferenceManager;
import com.health.openscale.R;
import com.health.openscale.core.OpenScale;

View File

@@ -22,6 +22,7 @@ import android.content.SharedPreferences;
import android.graphics.Color;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.support.v4.content.ContextCompat;
import android.text.SpannableStringBuilder;
import android.util.TypedValue;
@@ -80,11 +81,15 @@ public abstract class MeasurementView extends TableLayout {
iconView.setImageDrawable(icon);
}
public static final List<MeasurementView> getMeasurementList(Context context) {
public enum DateTimeOrder { FIRST, LAST, NONE }
public static final List<MeasurementView> getMeasurementList(Context context, DateTimeOrder order) {
final List<MeasurementView> measurementViews = new ArrayList<>();
measurementViews.add(new DateMeasurementView(context));
measurementViews.add(new TimeMeasurementView(context));
if (order == DateTimeOrder.FIRST) {
measurementViews.add(new DateMeasurementView(context));
measurementViews.add(new TimeMeasurementView(context));
}
measurementViews.add(new WeightMeasurementView(context));
measurementViews.add(new BMIMeasurementView(context));
measurementViews.add(new WaterMeasurementView(context));
@@ -98,6 +103,16 @@ public abstract class MeasurementView extends TableLayout {
measurementViews.add(new WHRMeasurementView(context));
measurementViews.add(new BMRMeasurementView(context));
measurementViews.add(new CommentMeasurementView(context));
if (order == DateTimeOrder.LAST) {
measurementViews.add(new DateMeasurementView(context));
measurementViews.add(new TimeMeasurementView(context));
}
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
for (MeasurementView measurement : measurementViews) {
measurement.updatePreferences(prefs);
}
return measurementViews;
}

View File

@@ -40,7 +40,7 @@
<item quantity="one">%d den</item>
<item quantity="few">%d dny</item>
<item quantity="other">%d dnů</item>
</plurals>
</plurals>
<string name="label_last_week">Uplynulých 7 dnů</string>
<string name="label_last_month">Uplynulých 30 dnů</string>
<string name="label_weight_difference">Rozdíl hmotnosti</string>
@@ -118,7 +118,6 @@
<string name="label_automatic">automaticky</string>
<string name="label_theme">Téma vzhledu</string>
<string name="info_app_restart_required">Aby se změny projevily, je třeba aplikaci restartovat</string>
<string name="label_reminder">Připomínání</string>
<string name="label_reminder_weekdays">Dny v týdnu</string>

View File

@@ -180,7 +180,6 @@
<string name="customactivityoncrash_error_activity_error_details_clipboard_label">Fehlerinformationen</string>
<string name="title_general">Allgmein</string>
<string name="label_theme">Theme</string>
<string name="info_app_restart_required">Um die Änderungen zu übernehmen, ist ein App Neustart erforderlich</string>
<string name="label_share">Teilen</string>
<string name="label_bluetooth_searching_finished">Suche beendet nach Bluetooth Waagen</string>
<string name="label_help">Hilfe</string>

View File

@@ -197,7 +197,6 @@
<string name="label_bluetooth_searching_finished">Finalizada la búsqueda de básculas Bluetooth</string>
<string name="label_theme">Tema</string>
<string name="info_app_restart_required">Para aplicar los cambios se requiere un reinicio de la aplicación</string>
<string name="label_help">Ayuda</string>

View File

@@ -164,7 +164,6 @@
<string name="title_general">Allmänt</string>
<string name="error_user_name_too_short">Fel: namnet måste vara minst 3 tecken</string>
<string name="label_theme">Tema</string>
<string name="info_app_restart_required">En app-omstart krävs för att applicera ändringarna</string>
<string name="label_feedback_message_enjoying">Uppskattar du openScale?</string>
<string name="label_feedback_message_rate_app">Vad sägs om ett betyg på GooglePlay eller på GitHub?</string>
<string name="label_feedback_message_issue">Skulle du ha något emot att ge oss lite återkoppling?</string>

View File

@@ -155,7 +155,6 @@
<string name="label_automatic">auto</string>
<string name="label_theme">Theme</string>
<string name="info_app_restart_required">To apply changes an app restart is required</string>
<string name="label_reminder">Reminder</string>
<string name="label_reminder_weekdays">Weekdays</string>