mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge
synced 2024-11-04 01:09:47 +01:00
Activity card: React to Charts settings, refactoring
This commit is contained in:
parent
50204a956e
commit
4398076ecc
@ -156,6 +156,7 @@ import static nodomain.freeyourgadget.gadgetbridge.activities.devicesettings.Dev
|
||||
import static nodomain.freeyourgadget.gadgetbridge.activities.devicesettings.DeviceSettingsPreferenceConst.PREFS_ACTIVITY_IN_DEVICE_CARD_DISTANCE;
|
||||
import static nodomain.freeyourgadget.gadgetbridge.activities.devicesettings.DeviceSettingsPreferenceConst.PREFS_ACTIVITY_IN_DEVICE_CARD_SLEEP;
|
||||
import static nodomain.freeyourgadget.gadgetbridge.activities.devicesettings.DeviceSettingsPreferenceConst.PREFS_ACTIVITY_IN_DEVICE_CARD_STEPS;
|
||||
import static nodomain.freeyourgadget.gadgetbridge.activities.devicesettings.DeviceSettingsPreferenceConst.PREFS_DEVICE_CHARTS_TABS;
|
||||
|
||||
import static nodomain.freeyourgadget.gadgetbridge.devices.huami.HuamiConst.PREF_ACTIVATE_DISPLAY_ON_LIFT;
|
||||
import static nodomain.freeyourgadget.gadgetbridge.devices.huami.HuamiConst.PREF_DEVICE_ACTION_FELL_SLEEP_BROADCAST;
|
||||
@ -524,6 +525,7 @@ public class DeviceSpecificSettingsFragment extends PreferenceFragmentCompat {
|
||||
addPreferenceHandlerFor(PREF_GALAXY_BUDS_TOUCH_RIGHT);
|
||||
addPreferenceHandlerFor(PREF_GALAXY_BUDS_LIVE_ANC);
|
||||
addPreferenceHandlerFor(PREF_GALAXY_BUDS_PRESSURE_RELIEF);
|
||||
addPreferenceHandlerFor(PREFS_DEVICE_CHARTS_TABS);
|
||||
|
||||
|
||||
addPreferenceHandlerFor(PREF_SONY_AMBIENT_SOUND_CONTROL);
|
||||
@ -787,11 +789,12 @@ public class DeviceSpecificSettingsFragment extends PreferenceFragmentCompat {
|
||||
deviceActionsStartNonWearBroadcast.setEnabled(deviceActionsStartNonWearSelectionBroadcast);
|
||||
}
|
||||
|
||||
|
||||
// this is to ensure that Control Center device cards are refreshed on preference changes
|
||||
final Preference activityInDeviceCard = findPreference(PREFS_ACTIVITY_IN_DEVICE_CARD);
|
||||
final Preference activityInDeviceSteps = findPreference(PREFS_ACTIVITY_IN_DEVICE_CARD_STEPS);
|
||||
final Preference activityInDeviceSleep = findPreference(PREFS_ACTIVITY_IN_DEVICE_CARD_SLEEP);
|
||||
final Preference activityInDeviceDistance = findPreference(PREFS_ACTIVITY_IN_DEVICE_CARD_DISTANCE);
|
||||
final Preference chartsTabsOrderSelection = findPreference(PREFS_DEVICE_CHARTS_TABS);
|
||||
|
||||
Preference.OnPreferenceClickListener sendIntentRefreshDeviceListListener = new Preference.OnPreferenceClickListener() {
|
||||
@Override
|
||||
@ -802,19 +805,19 @@ public class DeviceSpecificSettingsFragment extends PreferenceFragmentCompat {
|
||||
}
|
||||
};
|
||||
|
||||
if (activityInDeviceCard != null) {
|
||||
activityInDeviceCard.setOnPreferenceClickListener(sendIntentRefreshDeviceListListener);
|
||||
}
|
||||
if (activityInDeviceSteps != null) {
|
||||
activityInDeviceSteps.setOnPreferenceClickListener(sendIntentRefreshDeviceListListener);
|
||||
}
|
||||
if (activityInDeviceSleep != null) {
|
||||
activityInDeviceSleep.setOnPreferenceClickListener(sendIntentRefreshDeviceListListener);
|
||||
}
|
||||
if (activityInDeviceDistance != null) {
|
||||
activityInDeviceDistance.setOnPreferenceClickListener(sendIntentRefreshDeviceListListener);
|
||||
}
|
||||
Preference[] preferencesInControlCenter = {
|
||||
activityInDeviceCard,
|
||||
activityInDeviceSteps,
|
||||
activityInDeviceSleep,
|
||||
activityInDeviceDistance,
|
||||
chartsTabsOrderSelection
|
||||
};
|
||||
|
||||
for (Preference preferenceInControlCenter : preferencesInControlCenter) {
|
||||
if (preferenceInControlCenter != null) {
|
||||
preferenceInControlCenter.setOnPreferenceClickListener(sendIntentRefreshDeviceListListener);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static DeviceSpecificSettingsFragment newInstance(String settingsFileSuffix, @NonNull int[] supportedSettings, String[] supportedLanguages) {
|
||||
|
@ -27,6 +27,7 @@ import android.graphics.Color;
|
||||
import android.graphics.drawable.GradientDrawable;
|
||||
import android.text.InputType;
|
||||
import android.transition.TransitionManager;
|
||||
import android.util.Pair;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
@ -63,8 +64,10 @@ import org.slf4j.LoggerFactory;
|
||||
import java.text.DecimalFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.Hashtable;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import nodomain.freeyourgadget.gadgetbridge.GBApplication;
|
||||
@ -925,48 +928,32 @@ public class GBDeviceAdapterv2 extends RecyclerView.Adapter<GBDeviceAdapterv2.Vi
|
||||
holder.cardViewActivityCardLayout.setVisibility(showActivityCard ? View.VISIBLE : View.GONE);
|
||||
|
||||
boolean showActivitySteps = GBApplication.getDeviceSpecificSharedPrefs(device.getAddress()).getBoolean(DeviceSettingsPreferenceConst.PREFS_ACTIVITY_IN_DEVICE_CARD_STEPS, true);
|
||||
holder.TotalStepsChart.setVisibility((showActivitySteps && steps > 0) ? View.VISIBLE : View.GONE);
|
||||
holder.TotalStepsChart.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
Intent startIntent;
|
||||
startIntent = new Intent(context, ChartsActivity.class);
|
||||
startIntent.putExtra(GBDevice.EXTRA_DEVICE, device);
|
||||
startIntent.putExtra(ChartsActivity.EXTRA_FRAGMENT_ID, ChartsActivity.getChartsTabIndex("stepsweek", device, context));
|
||||
context.startActivity(startIntent);
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
boolean showActivitySleep = GBApplication.getDeviceSpecificSharedPrefs(device.getAddress()).getBoolean(DeviceSettingsPreferenceConst.PREFS_ACTIVITY_IN_DEVICE_CARD_SLEEP, true);
|
||||
holder.SleepTimeChart.setVisibility((showActivitySleep && sleep > 0) ? View.VISIBLE : View.GONE);
|
||||
holder.SleepTimeChart.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
Intent startIntent;
|
||||
startIntent = new Intent(context, ChartsActivity.class);
|
||||
startIntent.putExtra(GBDevice.EXTRA_DEVICE, device);
|
||||
startIntent.putExtra(ChartsActivity.EXTRA_FRAGMENT_ID, ChartsActivity.getChartsTabIndex("sleep", device, context));
|
||||
context.startActivity(startIntent);
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
|
||||
boolean showActivityDistance = GBApplication.getDeviceSpecificSharedPrefs(device.getAddress()).getBoolean(DeviceSettingsPreferenceConst.PREFS_ACTIVITY_IN_DEVICE_CARD_DISTANCE, true);
|
||||
holder.TotalDistanceChart.setVisibility((showActivityDistance && steps > 0) ? View.VISIBLE : View.GONE);
|
||||
holder.TotalDistanceChart.setOnClickListener(new View.OnClickListener() {
|
||||
|
||||
//do the multiple mini-charts for activities in a loop
|
||||
Hashtable<PieChart, Pair<Boolean, Integer>> activitiesStatusMiniCharts = new Hashtable<>();
|
||||
activitiesStatusMiniCharts.put(holder.TotalStepsChart, new Pair<>(showActivitySteps && steps > 0, ChartsActivity.getChartsTabIndex("stepsweek", device, context)));
|
||||
activitiesStatusMiniCharts.put(holder.SleepTimeChart, new Pair<>(showActivitySleep && sleep > 0, ChartsActivity.getChartsTabIndex("sleep", device, context)));
|
||||
activitiesStatusMiniCharts.put(holder.TotalDistanceChart, new Pair<>(showActivityDistance && steps > 0, ChartsActivity.getChartsTabIndex("activity", device, context)));
|
||||
|
||||
for (Map.Entry<PieChart, Pair<Boolean, Integer>> miniCharts : activitiesStatusMiniCharts.entrySet()) {
|
||||
PieChart miniChart = miniCharts.getKey();
|
||||
final Pair<Boolean, Integer> parameters = miniCharts.getValue();
|
||||
miniChart.setVisibility(parameters.first ? View.VISIBLE : View.GONE);
|
||||
miniChart.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
Intent startIntent;
|
||||
startIntent = new Intent(context, ChartsActivity.class);
|
||||
startIntent.putExtra(GBDevice.EXTRA_DEVICE, device);
|
||||
startIntent.putExtra(ChartsActivity.EXTRA_FRAGMENT_ID, ChartsActivity.getChartsTabIndex("activity", device, context));
|
||||
startIntent.putExtra(ChartsActivity.EXTRA_FRAGMENT_ID, parameters.second);
|
||||
context.startActivity(startIntent);
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
private String getHM(long value) {
|
||||
return DateTimeUtils.formatDurationHoursMinutes(value, TimeUnit.MINUTES);
|
||||
|
Loading…
Reference in New Issue
Block a user