mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge
synced 2024-11-25 19:36:50 +01:00
Activity card: Open specific Charts tab for each activity
This commit is contained in:
parent
361dcd2eac
commit
50204a956e
@ -47,13 +47,13 @@ import java.text.SimpleDateFormat;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.List;
|
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
|
||||||
import nodomain.freeyourgadget.gadgetbridge.GBApplication;
|
import nodomain.freeyourgadget.gadgetbridge.GBApplication;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.R;
|
import nodomain.freeyourgadget.gadgetbridge.R;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.activities.AbstractFragmentPagerAdapter;
|
import nodomain.freeyourgadget.gadgetbridge.activities.AbstractFragmentPagerAdapter;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.activities.AbstractGBFragmentActivity;
|
import nodomain.freeyourgadget.gadgetbridge.activities.AbstractGBFragmentActivity;
|
||||||
|
import nodomain.freeyourgadget.gadgetbridge.activities.devicesettings.DeviceSettingsPreferenceConst;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.devices.DeviceCoordinator;
|
import nodomain.freeyourgadget.gadgetbridge.devices.DeviceCoordinator;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.impl.GBDevice;
|
import nodomain.freeyourgadget.gadgetbridge.impl.GBDevice;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.model.RecordedDataTypes;
|
import nodomain.freeyourgadget.gadgetbridge.model.RecordedDataTypes;
|
||||||
@ -65,6 +65,7 @@ import nodomain.freeyourgadget.gadgetbridge.util.Prefs;
|
|||||||
|
|
||||||
public class ChartsActivity extends AbstractGBFragmentActivity implements ChartsHost {
|
public class ChartsActivity extends AbstractGBFragmentActivity implements ChartsHost {
|
||||||
private static final Logger LOG = LoggerFactory.getLogger(ChartsActivity.class);
|
private static final Logger LOG = LoggerFactory.getLogger(ChartsActivity.class);
|
||||||
|
public static final String EXTRA_FRAGMENT_ID = "fragment";
|
||||||
|
|
||||||
private TextView mDateControl;
|
private TextView mDateControl;
|
||||||
|
|
||||||
@ -73,7 +74,7 @@ public class ChartsActivity extends AbstractGBFragmentActivity implements Charts
|
|||||||
private SwipeRefreshLayout swipeLayout;
|
private SwipeRefreshLayout swipeLayout;
|
||||||
|
|
||||||
LimitedQueue mActivityAmountCache = new LimitedQueue(60);
|
LimitedQueue mActivityAmountCache = new LimitedQueue(60);
|
||||||
List<String> enabledTabsList;
|
ArrayList<String> enabledTabsList;
|
||||||
|
|
||||||
public static class ShowDurationDialog extends Dialog {
|
public static class ShowDurationDialog extends Dialog {
|
||||||
private final String mDuration;
|
private final String mDuration;
|
||||||
@ -134,6 +135,7 @@ public class ChartsActivity extends AbstractGBFragmentActivity implements Charts
|
|||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
setContentView(R.layout.activity_charts);
|
setContentView(R.layout.activity_charts);
|
||||||
|
int tabFragmentToOpen = -1;
|
||||||
|
|
||||||
initDates();
|
initDates();
|
||||||
|
|
||||||
@ -144,22 +146,12 @@ public class ChartsActivity extends AbstractGBFragmentActivity implements Charts
|
|||||||
Bundle extras = getIntent().getExtras();
|
Bundle extras = getIntent().getExtras();
|
||||||
if (extras != null) {
|
if (extras != null) {
|
||||||
mGBDevice = extras.getParcelable(GBDevice.EXTRA_DEVICE);
|
mGBDevice = extras.getParcelable(GBDevice.EXTRA_DEVICE);
|
||||||
|
tabFragmentToOpen = extras.getInt(EXTRA_FRAGMENT_ID);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
throw new IllegalArgumentException("Must provide a device when invoking this activity");
|
throw new IllegalArgumentException("Must provide a device when invoking this activity");
|
||||||
}
|
}
|
||||||
Prefs prefs = new Prefs(GBApplication.getDeviceSpecificSharedPrefs(getDevice().getAddress()));
|
enabledTabsList = fillChartsTabsList(getDevice(), this);
|
||||||
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 = findViewById(R.id.activity_swipe_layout);
|
||||||
swipeLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
|
swipeLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
|
||||||
@ -173,6 +165,10 @@ public class ChartsActivity extends AbstractGBFragmentActivity implements Charts
|
|||||||
// Set up the ViewPager with the sections adapter.
|
// Set up the ViewPager with the sections adapter.
|
||||||
NonSwipeableViewPager viewPager = findViewById(R.id.charts_pager);
|
NonSwipeableViewPager viewPager = findViewById(R.id.charts_pager);
|
||||||
viewPager.setAdapter(getPagerAdapter());
|
viewPager.setAdapter(getPagerAdapter());
|
||||||
|
if (tabFragmentToOpen > -1) {
|
||||||
|
viewPager.setCurrentItem(tabFragmentToOpen); //open the tab as specified in the intent
|
||||||
|
}
|
||||||
|
|
||||||
viewPager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
|
viewPager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
|
public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
|
||||||
@ -246,6 +242,30 @@ public class ChartsActivity extends AbstractGBFragmentActivity implements Charts
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static ArrayList<String> fillChartsTabsList(GBDevice device, Context context) {
|
||||||
|
ArrayList<String> arrayList = new ArrayList();
|
||||||
|
Prefs prefs = new Prefs(GBApplication.getDeviceSpecificSharedPrefs(device.getAddress()));
|
||||||
|
String myTabs = prefs.getString(DeviceSettingsPreferenceConst.PREFS_DEVICE_CHARTS_TABS, null);
|
||||||
|
|
||||||
|
if (myTabs == null) {
|
||||||
|
//make list mutable to be able to remove items later
|
||||||
|
arrayList = new ArrayList<String>(Arrays.asList(context.getResources().getStringArray(R.array.pref_charts_tabs_items_default)));
|
||||||
|
} else {
|
||||||
|
arrayList = new ArrayList<String>(Arrays.asList(myTabs.split(",")));
|
||||||
|
}
|
||||||
|
DeviceCoordinator coordinator = DeviceHelper.getInstance().getCoordinator(device);
|
||||||
|
if (!coordinator.supportsRealtimeData()) {
|
||||||
|
arrayList.remove("livestats");
|
||||||
|
}
|
||||||
|
return arrayList;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static int getChartsTabIndex(String tab, GBDevice device, Context context) {
|
||||||
|
ArrayList<String> enabledTabsList = new ArrayList();
|
||||||
|
enabledTabsList = fillChartsTabsList(device, context);
|
||||||
|
return enabledTabsList.indexOf(tab);
|
||||||
|
}
|
||||||
|
|
||||||
private String formatDetailedDuration() {
|
private String formatDetailedDuration() {
|
||||||
SimpleDateFormat dateFormat = new SimpleDateFormat("dd.MM.yyyy HH:mm");
|
SimpleDateFormat dateFormat = new SimpleDateFormat("dd.MM.yyyy HH:mm");
|
||||||
String dateStringFrom = dateFormat.format(getStartDate());
|
String dateStringFrom = dateFormat.format(getStartDate());
|
||||||
|
@ -144,6 +144,7 @@ public class DeviceSettingsPreferenceConst {
|
|||||||
public static final String PREFS_ACTIVITY_IN_DEVICE_CARD_STEPS = "prefs_activity_in_device_card_steps";
|
public static final String PREFS_ACTIVITY_IN_DEVICE_CARD_STEPS = "prefs_activity_in_device_card_steps";
|
||||||
public static final String PREFS_ACTIVITY_IN_DEVICE_CARD_SLEEP = "prefs_activity_in_device_card_sleep";
|
public static final String PREFS_ACTIVITY_IN_DEVICE_CARD_SLEEP = "prefs_activity_in_device_card_sleep";
|
||||||
public static final String PREFS_ACTIVITY_IN_DEVICE_CARD_DISTANCE = "prefs_activity_in_device_card_distance";
|
public static final String PREFS_ACTIVITY_IN_DEVICE_CARD_DISTANCE = "prefs_activity_in_device_card_distance";
|
||||||
|
public static final String PREFS_DEVICE_CHARTS_TABS = "charts_tabs";
|
||||||
|
|
||||||
public static final String PREF_SOUNDS = "sounds";
|
public static final String PREF_SOUNDS = "sounds";
|
||||||
public static final String PREF_AUTH_KEY = "authkey";
|
public static final String PREF_AUTH_KEY = "authkey";
|
||||||
|
@ -704,16 +704,7 @@ public class GBDeviceAdapterv2 extends RecyclerView.Adapter<GBDeviceAdapterv2.Vi
|
|||||||
|
|
||||||
holder.cardViewActivityCardLayout.setVisibility(coordinator.supportsActivityTracking() ? View.VISIBLE : View.GONE);
|
holder.cardViewActivityCardLayout.setVisibility(coordinator.supportsActivityTracking() ? View.VISIBLE : View.GONE);
|
||||||
holder.cardViewActivityCardLayout.setMinimumWidth(coordinator.supportsActivityTracking() ? View.VISIBLE : View.GONE);
|
holder.cardViewActivityCardLayout.setMinimumWidth(coordinator.supportsActivityTracking() ? View.VISIBLE : View.GONE);
|
||||||
holder.cardViewActivityCardLayout.setOnClickListener(new View.OnClickListener() {
|
|
||||||
@Override
|
|
||||||
public void onClick(View v) {
|
|
||||||
Intent startIntent;
|
|
||||||
startIntent = new Intent(context, ChartsActivity.class);
|
|
||||||
startIntent.putExtra(GBDevice.EXTRA_DEVICE, device);
|
|
||||||
context.startActivity(startIntent);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
);
|
|
||||||
if (coordinator.supportsActivityTracking()) {
|
if (coordinator.supportsActivityTracking()) {
|
||||||
setActivityCard(holder, device, dailyTotals);
|
setActivityCard(holder, device, dailyTotals);
|
||||||
}
|
}
|
||||||
@ -891,7 +882,7 @@ public class GBDeviceAdapterv2 extends RecyclerView.Adapter<GBDeviceAdapterv2.Vi
|
|||||||
snackbar.show();
|
snackbar.show();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setActivityCard(ViewHolder holder, GBDevice device, long[] dailyTotals) {
|
private void setActivityCard(ViewHolder holder, final GBDevice device, long[] dailyTotals) {
|
||||||
int steps = (int) dailyTotals[0];
|
int steps = (int) dailyTotals[0];
|
||||||
int sleep = (int) dailyTotals[1];
|
int sleep = (int) dailyTotals[1];
|
||||||
ActivityUser activityUser = new ActivityUser();
|
ActivityUser activityUser = new ActivityUser();
|
||||||
@ -935,12 +926,46 @@ public class GBDeviceAdapterv2 extends RecyclerView.Adapter<GBDeviceAdapterv2.Vi
|
|||||||
|
|
||||||
boolean showActivitySteps = GBApplication.getDeviceSpecificSharedPrefs(device.getAddress()).getBoolean(DeviceSettingsPreferenceConst.PREFS_ACTIVITY_IN_DEVICE_CARD_STEPS, true);
|
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.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);
|
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.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);
|
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.setVisibility((showActivityDistance && steps > 0) ? View.VISIBLE : View.GONE);
|
||||||
|
holder.TotalDistanceChart.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));
|
||||||
|
context.startActivity(startIntent);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
private String getHM(long value) {
|
private String getHM(long value) {
|
||||||
|
@ -123,7 +123,7 @@ public class CasioGBX100DeviceSupport extends CasioSupport implements SharedPref
|
|||||||
SharedPreferences preferences = GBApplication.getDeviceSpecificSharedPrefs(this.getDevice().getAddress());
|
SharedPreferences preferences = GBApplication.getDeviceSpecificSharedPrefs(this.getDevice().getAddress());
|
||||||
SharedPreferences.Editor editor = preferences.edit();
|
SharedPreferences.Editor editor = preferences.edit();
|
||||||
|
|
||||||
editor.putString("charts_tabs", "activity,activitylist,stepsweek");
|
editor.putString(DeviceSettingsPreferenceConst.PREFS_DEVICE_CHARTS_TABS, "activity,activitylist,stepsweek");
|
||||||
editor.apply();
|
editor.apply();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user