mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge
synced 2024-12-28 03:25:49 +01:00
Make charts tabs selectable sortable
This commit is contained in:
parent
bd23a8da4a
commit
98bb01dfa1
@ -33,16 +33,23 @@ import android.widget.Button;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
import java.util.Objects;
|
||||
|
||||
import androidx.fragment.app.Fragment;
|
||||
import androidx.fragment.app.FragmentManager;
|
||||
import androidx.fragment.app.FragmentStatePagerAdapter;
|
||||
import androidx.localbroadcastmanager.content.LocalBroadcastManager;
|
||||
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout;
|
||||
import androidx.viewpager.widget.ViewPager;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
import nodomain.freeyourgadget.gadgetbridge.GBApplication;
|
||||
import nodomain.freeyourgadget.gadgetbridge.R;
|
||||
import nodomain.freeyourgadget.gadgetbridge.activities.AbstractFragmentPagerAdapter;
|
||||
@ -54,8 +61,10 @@ import nodomain.freeyourgadget.gadgetbridge.util.DateTimeUtils;
|
||||
import nodomain.freeyourgadget.gadgetbridge.util.DeviceHelper;
|
||||
import nodomain.freeyourgadget.gadgetbridge.util.GB;
|
||||
import nodomain.freeyourgadget.gadgetbridge.util.LimitedQueue;
|
||||
import nodomain.freeyourgadget.gadgetbridge.util.Prefs;
|
||||
|
||||
public class ChartsActivity extends AbstractGBFragmentActivity implements ChartsHost {
|
||||
private static final Logger LOG = LoggerFactory.getLogger(ChartsActivity.class);
|
||||
|
||||
private TextView mDateControl;
|
||||
|
||||
@ -64,6 +73,7 @@ public class ChartsActivity extends AbstractGBFragmentActivity implements Charts
|
||||
private SwipeRefreshLayout swipeLayout;
|
||||
|
||||
LimitedQueue mActivityAmountCache = new LimitedQueue(60);
|
||||
List<String> enabledTabsList;
|
||||
|
||||
public static class ShowDurationDialog extends Dialog {
|
||||
private final String mDuration;
|
||||
@ -137,6 +147,19 @@ public class ChartsActivity extends AbstractGBFragmentActivity implements Charts
|
||||
} else {
|
||||
throw new IllegalArgumentException("Must provide a device when invoking this activity");
|
||||
}
|
||||
Prefs prefs = new Prefs(GBApplication.getDeviceSpecificSharedPrefs(getDevice().getAddress()));
|
||||
String myTabs = prefs.getString("charts_tabs", null);
|
||||
|
||||
if (myTabs == null) {
|
||||
//make list mutable to be able to remove items later
|
||||
enabledTabsList = new ArrayList<String>(Arrays.asList(this.getResources().getStringArray(R.array.pref_charts_tabs_items_default)));
|
||||
} else {
|
||||
enabledTabsList = new ArrayList<String>(Arrays.asList(myTabs.split(",")));
|
||||
}
|
||||
DeviceCoordinator coordinator = DeviceHelper.getInstance().getCoordinator(mGBDevice);
|
||||
if (!coordinator.supportsRealtimeData()) {
|
||||
enabledTabsList.remove("livestats");
|
||||
}
|
||||
|
||||
swipeLayout = findViewById(R.id.activity_swipe_layout);
|
||||
swipeLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
|
||||
@ -339,33 +362,35 @@ public class ChartsActivity extends AbstractGBFragmentActivity implements Charts
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* A {@link FragmentStatePagerAdapter} that returns a fragment corresponding to
|
||||
* one of the sections/tabs/pages.
|
||||
*/
|
||||
public class SectionsPagerAdapter extends AbstractFragmentPagerAdapter {
|
||||
|
||||
SectionsPagerAdapter(FragmentManager fm) {
|
||||
super(fm);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Fragment getItem(int position) {
|
||||
// getItem is called to instantiate the fragment for the given page.
|
||||
switch (position) {
|
||||
case 0:
|
||||
switch (enabledTabsList.get(position)) {
|
||||
case "activity":
|
||||
return new ActivitySleepChartFragment();
|
||||
case 1:
|
||||
case "activitylist":
|
||||
return new ActivityListingChartFragment();
|
||||
case 2:
|
||||
case "sleep":
|
||||
return new SleepChartFragment();
|
||||
case 3:
|
||||
case "sleepweek":
|
||||
return new WeekSleepChartFragment();
|
||||
case 4:
|
||||
case "stepsweek":
|
||||
return new WeekStepsChartFragment();
|
||||
case 5:
|
||||
case "speedzones":
|
||||
return new SpeedZonesFragment();
|
||||
case 6:
|
||||
case "livestats":
|
||||
return new LiveActivityFragment();
|
||||
}
|
||||
return null;
|
||||
@ -373,12 +398,7 @@ public class ChartsActivity extends AbstractGBFragmentActivity implements Charts
|
||||
|
||||
@Override
|
||||
public int getCount() {
|
||||
// Show 5 or 6 total pages.
|
||||
DeviceCoordinator coordinator = DeviceHelper.getInstance().getCoordinator(mGBDevice);
|
||||
if (coordinator.supportsRealtimeData()) {
|
||||
return 7;
|
||||
}
|
||||
return 6;
|
||||
return enabledTabsList.toArray().length;
|
||||
}
|
||||
|
||||
private String getSleepTitle() {
|
||||
@ -401,20 +421,21 @@ public class ChartsActivity extends AbstractGBFragmentActivity implements Charts
|
||||
|
||||
@Override
|
||||
public CharSequence getPageTitle(int position) {
|
||||
switch (position) {
|
||||
case 0:
|
||||
|
||||
switch (enabledTabsList.get(position)) {
|
||||
case "activity":
|
||||
return getString(R.string.activity_sleepchart_activity_and_sleep);
|
||||
case 1:
|
||||
case "activitylist":
|
||||
return getString(R.string.charts_activity_list);
|
||||
case 2:
|
||||
case "sleep":
|
||||
return getString(R.string.sleepchart_your_sleep);
|
||||
case 3:
|
||||
case "sleepweek":
|
||||
return getSleepTitle();
|
||||
case 4:
|
||||
case "stepsweek":
|
||||
return getStepsTitle();
|
||||
case 5:
|
||||
case "speedzones":
|
||||
return getString(R.string.stats_title);
|
||||
case 6:
|
||||
case "livestats":
|
||||
return getString(R.string.liveactivity_live_activity);
|
||||
}
|
||||
return super.getPageTitle(position);
|
||||
|
@ -19,10 +19,10 @@ package nodomain.freeyourgadget.gadgetbridge.activities.devicesettings;
|
||||
import android.os.Bundle;
|
||||
|
||||
import androidx.fragment.app.Fragment;
|
||||
import androidx.fragment.app.FragmentTransaction;
|
||||
import androidx.preference.PreferenceFragmentCompat;
|
||||
import androidx.preference.PreferenceScreen;
|
||||
|
||||
import org.apache.commons.lang3.ArrayUtils;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
@ -49,7 +49,11 @@ public class DeviceSettingsActivity extends AbstractGBActivity implements
|
||||
Fragment fragment = getSupportFragmentManager().findFragmentByTag(DeviceSpecificSettingsFragment.FRAGMENT_TAG);
|
||||
if (fragment == null) {
|
||||
DeviceCoordinator coordinator = DeviceHelper.getInstance().getCoordinator(device);
|
||||
fragment = DeviceSpecificSettingsFragment.newInstance(device.getAddress(), coordinator.getSupportedDeviceSpecificSettings(device));
|
||||
int[] supportedSettings = coordinator.getSupportedDeviceSpecificSettings(device);
|
||||
if (coordinator.supportsActivityTracking()) {
|
||||
supportedSettings = ArrayUtils.addAll(supportedSettings, R.xml.devicesettings_chartstabs);
|
||||
}
|
||||
fragment = DeviceSpecificSettingsFragment.newInstance(device.getAddress(), supportedSettings);
|
||||
}
|
||||
getSupportFragmentManager()
|
||||
.beginTransaction()
|
||||
@ -62,8 +66,12 @@ public class DeviceSettingsActivity extends AbstractGBActivity implements
|
||||
@Override
|
||||
public boolean onPreferenceStartScreen(PreferenceFragmentCompat caller, PreferenceScreen preferenceScreen) {
|
||||
DeviceCoordinator coordinator = DeviceHelper.getInstance().getCoordinator(device);
|
||||
int[] supportedSettings = coordinator.getSupportedDeviceSpecificSettings(device);
|
||||
if (coordinator.supportsActivityTracking()) {
|
||||
supportedSettings = ArrayUtils.addAll(supportedSettings, R.xml.devicesettings_chartstabs);
|
||||
}
|
||||
|
||||
PreferenceFragmentCompat fragment = DeviceSpecificSettingsFragment.newInstance(device.getAddress(), coordinator.getSupportedDeviceSpecificSettings(device));
|
||||
PreferenceFragmentCompat fragment = DeviceSpecificSettingsFragment.newInstance(device.getAddress(), supportedSettings);
|
||||
Bundle args = fragment.getArguments();
|
||||
args.putString(PreferenceFragmentCompat.ARG_PREFERENCE_ROOT, preferenceScreen.getKey());
|
||||
fragment.setArguments(args);
|
||||
|
@ -16,7 +16,9 @@
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>. */
|
||||
package nodomain.freeyourgadget.gadgetbridge.util;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
public class ArrayUtils {
|
||||
/**
|
||||
|
@ -1162,4 +1162,36 @@
|
||||
<item>50</item>
|
||||
<item>60</item>
|
||||
</string-array>
|
||||
|
||||
<string-array name="pref_charts_tabs_items">
|
||||
<item>@string/activity_sleepchart_activity_and_sleep</item>
|
||||
<item>@string/charts_activity_list</item>
|
||||
<item>@string/weeksleepchart_sleep_a_week</item>
|
||||
<item>@string/weeksleepchart_sleep_a_month</item>
|
||||
<item>@string/weekstepschart_steps_a_month</item>
|
||||
<item>@string/stats_title</item>
|
||||
<item>@string/liveactivity_live_activity</item>
|
||||
</string-array>
|
||||
|
||||
<string-array name="pref_charts_tabs_values">
|
||||
<item>@string/p_activity</item>
|
||||
<item>@string/p_activity_list</item>
|
||||
<item>@string/p_sleep</item>
|
||||
<item>@string/p_sleep_week</item>
|
||||
<item>@string/p_steps_week</item>
|
||||
<item>@string/p_speed_zones</item>
|
||||
<item>@string/p_live_stats</item>
|
||||
</string-array>
|
||||
|
||||
<string-array name="pref_charts_tabs_items_default">
|
||||
<item>@string/p_activity</item>
|
||||
<item>@string/p_activity_list</item>
|
||||
<item>@string/p_sleep</item>
|
||||
<item>@string/p_sleep_week</item>
|
||||
<item>@string/p_steps_week</item>
|
||||
<item>@string/p_speed_zones</item>
|
||||
<item>@string/p_live_stats</item>
|
||||
</string-array>
|
||||
|
||||
|
||||
</resources>
|
@ -437,6 +437,8 @@
|
||||
<string name="notif_battery_low">%1$s battery low</string>
|
||||
<string name="notif_battery_low_extended">%1$s battery low: %2$s</string>
|
||||
<string name="notif_export_failed_title">Export database failed! Please check your settings.</string>
|
||||
<string name="prefs_charts_tabs">Charts tabs</string>
|
||||
<string name="prefs_charts_tabs_summary">Visible charts tabs</string>
|
||||
<string name="sleepchart_your_sleep">Sleep</string>
|
||||
<string name="weeksleepchart_sleep_a_week">Sleep per week</string>
|
||||
<string name="weeksleepchart_today_sleep_description">Sleep today, target: %1$s</string>
|
||||
|
@ -69,4 +69,13 @@
|
||||
<item name="p_call_privacy_mode_name" type="string">name</item>
|
||||
<item name="p_call_privacy_mode_number" type="string">number</item>
|
||||
<item name="p_call_privacy_mode_complete" type="string">complete</item>
|
||||
|
||||
<item name="p_activity" type="string">activity</item>
|
||||
<item name="p_activity_list" type="string">activitylist</item>
|
||||
<item name="p_sleep" type="string">sleep</item>
|
||||
<item name="p_sleep_week" type="string">sleepweek</item>
|
||||
<item name="p_steps_week" type="string">stepsweek</item>
|
||||
<item name="p_speed_zones" type="string">speedzones</item>
|
||||
<item name="p_live_stats" type="string">livestats</item>
|
||||
|
||||
</resources>
|
||||
|
14
app/src/main/res/xml/devicesettings_chartstabs.xml
Normal file
14
app/src/main/res/xml/devicesettings_chartstabs.xml
Normal file
@ -0,0 +1,14 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<androidx.preference.PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<com.mobeta.android.dslv.DragSortListPreference
|
||||
android:icon="@drawable/ic_activity_graphs"
|
||||
android:defaultValue="@array/pref_charts_tabs_items_default"
|
||||
android:dialogTitle="@string/mi2_prefs_display_items"
|
||||
android:entries="@array/pref_charts_tabs_items"
|
||||
android:entryValues="@array/pref_charts_tabs_values"
|
||||
android:key="charts_tabs"
|
||||
android:persistent="true"
|
||||
android:summary="@string/prefs_charts_tabs_summary"
|
||||
android:title="@string/prefs_charts_tabs" />
|
||||
</androidx.preference.PreferenceScreen>
|
||||
|
Loading…
Reference in New Issue
Block a user