1
0
mirror of https://codeberg.org/Freeyourgadget/Gadgetbridge synced 2024-11-23 02:16:48 +01:00

Test device: Add dummy activities

This commit is contained in:
José Rebelo 2024-11-14 23:22:18 +00:00
parent e83555f099
commit f16e2eeabb
4 changed files with 85 additions and 23 deletions

View File

@ -38,7 +38,9 @@ import nodomain.freeyourgadget.gadgetbridge.GBApplication;
import nodomain.freeyourgadget.gadgetbridge.GBException;
import nodomain.freeyourgadget.gadgetbridge.R;
import nodomain.freeyourgadget.gadgetbridge.activities.appmanager.AppManagerActivity;
import nodomain.freeyourgadget.gadgetbridge.activities.devicesettings.DeviceSpecificSettings;
import nodomain.freeyourgadget.gadgetbridge.activities.devicesettings.DeviceSpecificSettingsCustomizer;
import nodomain.freeyourgadget.gadgetbridge.activities.devicesettings.DeviceSpecificSettingsScreen;
import nodomain.freeyourgadget.gadgetbridge.capabilities.HeartRateCapability;
import nodomain.freeyourgadget.gadgetbridge.capabilities.password.PasswordCapabilityImpl;
import nodomain.freeyourgadget.gadgetbridge.capabilities.widgets.WidgetManager;
@ -502,26 +504,26 @@ public class TestDeviceCoordinator extends AbstractDeviceCoordinator {
}
@Override
public int[] getSupportedDeviceSpecificSettings(final GBDevice device) {
final List<Integer> settings = new ArrayList<>();
public DeviceSpecificSettings getDeviceSpecificSettings(final GBDevice device) {
final DeviceSpecificSettings deviceSpecificSettings = new DeviceSpecificSettings();
settings.add(R.xml.devicesettings_header_apps);
settings.add(R.xml.devicesettings_loyalty_cards);
deviceSpecificSettings.addRootScreen(R.xml.devicesettings_loyalty_cards);
if (getWorldClocksSlotCount() > 0) {
settings.add(R.xml.devicesettings_header_time);
settings.add(R.xml.devicesettings_world_clocks);
final List<Integer> dateTime = deviceSpecificSettings.addRootScreen(DeviceSpecificSettingsScreen.DATE_TIME);
dateTime.add(R.xml.devicesettings_world_clocks);
}
if (getContactsSlotCount(device) > 0) {
settings.add(R.xml.devicesettings_header_other);
settings.add(R.xml.devicesettings_contacts);
deviceSpecificSettings.addRootScreen(R.xml.devicesettings_contacts);
}
settings.add(R.xml.devicesettings_header_developer);
settings.add(R.xml.devicesettings_test_features);
deviceSpecificSettings.addRootScreen(R.xml.devicesettings_test_features);
return ArrayUtils.toPrimitive(settings.toArray(new Integer[0]));
final List<Integer> developer = deviceSpecificSettings.addRootScreen(DeviceSpecificSettingsScreen.DEVELOPER);
developer.add(R.xml.devicesettings_developer_add_test_activities);
return deviceSpecificSettings;
}
@Override

View File

@ -17,15 +17,30 @@
package nodomain.freeyourgadget.gadgetbridge.devices.test;
import android.os.Parcel;
import android.widget.Toast;
import androidx.annotation.NonNull;
import androidx.preference.MultiSelectListPreference;
import androidx.preference.Preference;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Date;
import java.util.List;
import java.util.Random;
import java.util.Set;
import nodomain.freeyourgadget.gadgetbridge.GBApplication;
import nodomain.freeyourgadget.gadgetbridge.activities.devicesettings.DeviceSpecificSettingsCustomizer;
import nodomain.freeyourgadget.gadgetbridge.activities.devicesettings.DeviceSpecificSettingsHandler;
import nodomain.freeyourgadget.gadgetbridge.database.DBHandler;
import nodomain.freeyourgadget.gadgetbridge.database.DBHelper;
import nodomain.freeyourgadget.gadgetbridge.entities.BaseActivitySummary;
import nodomain.freeyourgadget.gadgetbridge.entities.DaoSession;
import nodomain.freeyourgadget.gadgetbridge.entities.Device;
import nodomain.freeyourgadget.gadgetbridge.entities.User;
import nodomain.freeyourgadget.gadgetbridge.model.ActivityKind;
import nodomain.freeyourgadget.gadgetbridge.util.GB;
import nodomain.freeyourgadget.gadgetbridge.util.Prefs;
public class TestDeviceSpecificSettingsCustomizer implements DeviceSpecificSettingsCustomizer {
@ -39,20 +54,55 @@ public class TestDeviceSpecificSettingsCustomizer implements DeviceSpecificSetti
@Override
public void customizeSettings(final DeviceSpecificSettingsHandler handler, final Prefs prefs, final String rootKey) {
final Preference pref = handler.findPreference(TestDeviceConst.PREF_TEST_FEATURES);
if (pref == null) {
return;
if (pref != null) {
// Populate the preference directly from the enum
final CharSequence[] entries = new CharSequence[TestFeature.values().length];
final CharSequence[] values = new CharSequence[TestFeature.values().length];
for (int i = 0; i < TestFeature.values().length; i++) {
entries[i] = TestFeature.values()[i].name();
values[i] = TestFeature.values()[i].name();
}
if (pref instanceof MultiSelectListPreference) {
((MultiSelectListPreference) pref).setEntries(entries);
((MultiSelectListPreference) pref).setEntryValues(values);
}
}
// Populate the preference directly from the enum
final CharSequence[] entries = new CharSequence[TestFeature.values().length];
final CharSequence[] values = new CharSequence[TestFeature.values().length];
for (int i = 0; i < TestFeature.values().length; i++) {
entries[i] = TestFeature.values()[i].name();
values[i] = TestFeature.values()[i].name();
}
if (pref instanceof MultiSelectListPreference) {
((MultiSelectListPreference) pref).setEntries(entries);
((MultiSelectListPreference) pref).setEntryValues(values);
final Preference addTestActivities = handler.findPreference("pref_developer_add_test_activities");
if (addTestActivities != null) {
addTestActivities.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
@Override
public boolean onPreferenceClick(@NonNull final Preference preference) {
try (DBHandler dbHandler = GBApplication.acquireDB()) {
final DaoSession session = dbHandler.getDaoSession();
final Device device = DBHelper.getDevice(handler.getDevice(), session);
final User user = DBHelper.getUser(session);
//final QueryBuilder<?> qb = session.getBaseActivitySummaryDao().queryBuilder();
//qb.where(BaseActivitySummaryDao.Properties.DeviceId.eq(device.getId())).buildDelete().executeDeleteWithoutDetachingEntities();
final List<BaseActivitySummary> summaries = new ArrayList<>();
for (final ActivityKind activityKind : ActivityKind.values()) {
final BaseActivitySummary summary = new BaseActivitySummary();
summary.setStartTime(new Date(System.currentTimeMillis() - new Random().nextInt(31 * 24 * 60 * 60) * 1000L));
summary.setEndTime(new Date(summary.getStartTime().getTime() + new Random().nextInt(60 * 60 * 2) * 1000L));
summary.setDevice(device);
summary.setUser(user);
summary.setActivityKind(activityKind.getCode());
// TODO data
summaries.add(summary);
}
session.getBaseActivitySummaryDao().insertOrReplaceInTx(summaries);
} catch (final Exception e) {
GB.toast(handler.getContext(), "Error saving activity summary", Toast.LENGTH_LONG, GB.ERROR, e);
return false;
}
return true;
}
});
}
}

View File

@ -3192,6 +3192,8 @@
<string name="warning_missing_notification_permission">Could not post ongoing notification due to missing permission</string>
<string name="pref_test_features_title">Features</string>
<string name="pref_test_features_summary">Enabled features for this test device</string>
<string name="pref_developer_add_test_activities_title">Add test activities</string>
<string name="pref_developer_add_test_activities_summary">Populate the database with dummy test activities</string>
<string name="device_state_waiting_scan">Waiting for device scan</string>
<string name="auto_reconnect_ble_scan_title">Reconnect by BLE scan</string>
<string name="auto_reconnect_ble_scan_summary">Wait for device scan instead of blind connection attempts</string>

View File

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.preference.PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
<Preference
android:icon="@drawable/ic_auto_awesome"
android:key="pref_developer_add_test_activities"
android:summary="@string/pref_developer_add_test_activities_summary"
android:title="@string/pref_developer_add_test_activities_title" />
</androidx.preference.PreferenceScreen>