mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge
synced 2025-01-13 11:17:33 +01:00
Allow the user to set the target number of steps for each day (fitness goal), both in the sharedpreferences and in the MiBand.
The value is then used in the graphs. #31 #44
This commit is contained in:
parent
27669761bf
commit
878afd79df
@ -37,6 +37,7 @@ import nodomain.freeyourgadget.gadgetbridge.ControlCenter;
|
||||
import nodomain.freeyourgadget.gadgetbridge.GBDevice;
|
||||
import nodomain.freeyourgadget.gadgetbridge.R;
|
||||
import nodomain.freeyourgadget.gadgetbridge.charts.ActivityAnalysis;
|
||||
import nodomain.freeyourgadget.gadgetbridge.miband.MiBandCoordinator;
|
||||
import nodomain.freeyourgadget.gadgetbridge.model.ActivitySample;
|
||||
|
||||
|
||||
@ -44,7 +45,7 @@ public class WeekStepsChartFragment extends AbstractChartFragment {
|
||||
protected static final Logger LOG = LoggerFactory.getLogger(WeekStepsChartFragment.class);
|
||||
|
||||
private Locale mLocale;
|
||||
private int mTargetSteps;
|
||||
private int mTargetSteps = 10000;
|
||||
|
||||
private BarLineChartBase mWeekStepsChart;
|
||||
private PieChart mTodayStepsChart;
|
||||
@ -138,10 +139,6 @@ public class WeekStepsChartFragment extends AbstractChartFragment {
|
||||
Bundle savedInstanceState) {
|
||||
mLocale = getResources().getConfiguration().locale;
|
||||
|
||||
//TODO: through mGBDevice we should be able to retrieve the steps goal set by the user
|
||||
mTargetSteps = 10000;
|
||||
|
||||
|
||||
View rootView = inflater.inflate(R.layout.fragment_sleepchart, container, false);
|
||||
|
||||
Bundle extras = getActivity().getIntent().getExtras();
|
||||
@ -149,6 +146,10 @@ public class WeekStepsChartFragment extends AbstractChartFragment {
|
||||
mGBDevice = extras.getParcelable(GBDevice.EXTRA_DEVICE);
|
||||
}
|
||||
|
||||
if(mGBDevice != null) {
|
||||
mTargetSteps = MiBandCoordinator.getFitnessGoal(mGBDevice.getAddress());
|
||||
}
|
||||
|
||||
IntentFilter filter = new IntentFilter();
|
||||
filter.addAction(ControlCenter.ACTION_QUIT);
|
||||
filter.addAction(ACTION_REFRESH);
|
||||
|
@ -16,6 +16,7 @@ public final class MiBandConst {
|
||||
public static final String PREF_MIBAND_WEARSIDE = "mi_wearside";
|
||||
public static final String PREF_MIBAND_ADDRESS = "development_miaddr"; // FIXME: should be prefixed mi_
|
||||
public static final String PREF_MIBAND_ALARMS = "mi_alarms";
|
||||
public static final String PREF_MIBAND_FITNESS_GOAL = "mi_fitness_goal";
|
||||
|
||||
public static final String ORIGIN_SMS = "sms";
|
||||
public static final String ORIGIN_INCOMING_CALL = "incoming_call";
|
||||
|
@ -106,4 +106,9 @@ public class MiBandCoordinator implements DeviceCoordinator {
|
||||
);
|
||||
return info;
|
||||
}
|
||||
|
||||
public static int getFitnessGoal(String miBandAddress) throws IllegalArgumentException {
|
||||
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(GBApplication.getContext());
|
||||
return Integer.parseInt(prefs.getString(MiBandConst.PREF_MIBAND_FITNESS_GOAL, "10000"));
|
||||
}
|
||||
}
|
||||
|
@ -15,6 +15,7 @@ import static nodomain.freeyourgadget.gadgetbridge.miband.MiBandConst.ORIGIN_K9M
|
||||
import static nodomain.freeyourgadget.gadgetbridge.miband.MiBandConst.ORIGIN_PEBBLEMSG;
|
||||
import static nodomain.freeyourgadget.gadgetbridge.miband.MiBandConst.ORIGIN_SMS;
|
||||
import static nodomain.freeyourgadget.gadgetbridge.miband.MiBandConst.PREF_MIBAND_ADDRESS;
|
||||
import static nodomain.freeyourgadget.gadgetbridge.miband.MiBandConst.PREF_MIBAND_FITNESS_GOAL;
|
||||
import static nodomain.freeyourgadget.gadgetbridge.miband.MiBandConst.PREF_MIBAND_WEARSIDE;
|
||||
import static nodomain.freeyourgadget.gadgetbridge.miband.MiBandConst.PREF_USER_ALIAS;
|
||||
import static nodomain.freeyourgadget.gadgetbridge.miband.MiBandConst.PREF_USER_GENDER;
|
||||
@ -56,6 +57,7 @@ public class MiBandPreferencesActivity extends AbstractSettingsActivity {
|
||||
PREF_USER_WEIGHT_KG,
|
||||
PREF_MIBAND_WEARSIDE,
|
||||
PREF_MIBAND_ADDRESS,
|
||||
PREF_MIBAND_FITNESS_GOAL,
|
||||
getNotificationPrefKey(VIBRATION_PROFILE, ORIGIN_SMS),
|
||||
getNotificationPrefKey(VIBRATION_COUNT, ORIGIN_SMS),
|
||||
getNotificationPrefKey(VIBRATION_PROFILE, ORIGIN_INCOMING_CALL),
|
||||
|
@ -141,6 +141,7 @@ public class MiBandService {
|
||||
|
||||
public static final byte COMMAND_SYNC = 0xb;
|
||||
|
||||
public static final byte COMMAND_SET_FITNESS_GOAL = 0x5;
|
||||
|
||||
/*
|
||||
|
||||
@ -153,8 +154,6 @@ public class MiBandService {
|
||||
|
||||
public static final int COMMAND_SET_COLOR_THEME = et;
|
||||
|
||||
public static final COMMAND_SET_FITNESS_GOAL = 0x5t
|
||||
|
||||
public static final COMMAND_SET_REALTIME_STEP = 0x10t
|
||||
|
||||
public static final COMMAND_SET_REALTIME_STEPS_NOTIFICATION = 0x3t
|
||||
|
@ -93,6 +93,7 @@ public class MiBandSupport extends AbstractBTLEDeviceSupport {
|
||||
builder.add(new SetDeviceStateAction(getDevice(), State.INITIALIZING, getContext()));
|
||||
pair(builder)
|
||||
.sendUserInfo(builder)
|
||||
.setFitnessGoal(builder)
|
||||
.enableNotifications(builder, true)
|
||||
.setCurrentTime(builder)
|
||||
.requestBatteryInfo(builder)
|
||||
@ -263,7 +264,29 @@ public class MiBandSupport extends AbstractBTLEDeviceSupport {
|
||||
}
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* Part of device initialization process. Do not call manually.
|
||||
*
|
||||
* @param transaction
|
||||
* @return
|
||||
*/
|
||||
|
||||
private MiBandSupport setFitnessGoal(TransactionBuilder transaction) {
|
||||
LOG.info("Attempting to set Fitness Goal...");
|
||||
BluetoothGattCharacteristic characteristic = getCharacteristic(MiBandService.UUID_CHARACTERISTIC_CONTROL_POINT);
|
||||
if (characteristic != null) {
|
||||
int fitnessGoal = MiBandCoordinator.getFitnessGoal(getDevice().getAddress());
|
||||
transaction.write(characteristic, new byte[]{
|
||||
MiBandService.COMMAND_SET_FITNESS_GOAL,
|
||||
0,
|
||||
(byte) (fitnessGoal & 0xff),
|
||||
(byte) ((fitnessGoal >>> 8) & 0xff)
|
||||
});
|
||||
} else {
|
||||
LOG.info("Unable to set Fitness Goal");
|
||||
}
|
||||
return this;
|
||||
}
|
||||
private void performDefaultNotification(String task, short repeat, BtLEAction extraAction) {
|
||||
try {
|
||||
TransactionBuilder builder = performInitialized(task);
|
||||
|
@ -157,4 +157,5 @@
|
||||
<string name="user_feedback_miband_set_alarms_ok">Alarms sent to device!</string>
|
||||
<string name="chart_no_data_synchronize">No data. Synchronize device?</string>
|
||||
<string name="user_feedback_miband_activity_data_transfer">About to transfer %1$s of data starting from %2$s</string>
|
||||
<string name="miband_prefs_fitness_goal">Target steps for each day</string>
|
||||
</resources>
|
||||
|
@ -40,6 +40,14 @@
|
||||
android:entryValues="@array/wearside_values"
|
||||
android:key="mi_wearside"
|
||||
android:title="@string/miband_prefs_wearside" />
|
||||
|
||||
<EditTextPreference
|
||||
android:defaultValue="10000"
|
||||
android:inputType="number"
|
||||
android:key="mi_fitness_goal"
|
||||
android:maxLength="5"
|
||||
android:title="@string/miband_prefs_fitness_goal" />
|
||||
|
||||
</PreferenceCategory>
|
||||
|
||||
<PreferenceCategory
|
||||
|
Loading…
x
Reference in New Issue
Block a user