1
0
mirror of https://codeberg.org/Freeyourgadget/Gadgetbridge synced 2024-11-29 05:16:51 +01:00

Activity card: Open specific Charts tab for each activity

This commit is contained in:
vanous 2021-12-04 11:19:59 +01:00
parent 361dcd2eac
commit 50204a956e
4 changed files with 73 additions and 27 deletions

View File

@ -47,13 +47,13 @@ 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;
import nodomain.freeyourgadget.gadgetbridge.activities.AbstractGBFragmentActivity;
import nodomain.freeyourgadget.gadgetbridge.activities.devicesettings.DeviceSettingsPreferenceConst;
import nodomain.freeyourgadget.gadgetbridge.devices.DeviceCoordinator;
import nodomain.freeyourgadget.gadgetbridge.impl.GBDevice;
import nodomain.freeyourgadget.gadgetbridge.model.RecordedDataTypes;
@ -65,6 +65,7 @@ import nodomain.freeyourgadget.gadgetbridge.util.Prefs;
public class ChartsActivity extends AbstractGBFragmentActivity implements ChartsHost {
private static final Logger LOG = LoggerFactory.getLogger(ChartsActivity.class);
public static final String EXTRA_FRAGMENT_ID = "fragment";
private TextView mDateControl;
@ -73,7 +74,7 @@ public class ChartsActivity extends AbstractGBFragmentActivity implements Charts
private SwipeRefreshLayout swipeLayout;
LimitedQueue mActivityAmountCache = new LimitedQueue(60);
List<String> enabledTabsList;
ArrayList<String> enabledTabsList;
public static class ShowDurationDialog extends Dialog {
private final String mDuration;
@ -134,6 +135,7 @@ public class ChartsActivity extends AbstractGBFragmentActivity implements Charts
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_charts);
int tabFragmentToOpen = -1;
initDates();
@ -144,22 +146,12 @@ public class ChartsActivity extends AbstractGBFragmentActivity implements Charts
Bundle extras = getIntent().getExtras();
if (extras != null) {
mGBDevice = extras.getParcelable(GBDevice.EXTRA_DEVICE);
tabFragmentToOpen = extras.getInt(EXTRA_FRAGMENT_ID);
} 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");
}
enabledTabsList = fillChartsTabsList(getDevice(), this);
swipeLayout = findViewById(R.id.activity_swipe_layout);
swipeLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
@ -173,6 +165,10 @@ public class ChartsActivity extends AbstractGBFragmentActivity implements Charts
// Set up the ViewPager with the sections adapter.
NonSwipeableViewPager viewPager = findViewById(R.id.charts_pager);
viewPager.setAdapter(getPagerAdapter());
if (tabFragmentToOpen > -1) {
viewPager.setCurrentItem(tabFragmentToOpen); //open the tab as specified in the intent
}
viewPager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
@Override
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() {
SimpleDateFormat dateFormat = new SimpleDateFormat("dd.MM.yyyy HH:mm");
String dateStringFrom = dateFormat.format(getStartDate());

View File

@ -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_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_DEVICE_CHARTS_TABS = "charts_tabs";
public static final String PREF_SOUNDS = "sounds";
public static final String PREF_AUTH_KEY = "authkey";

View File

@ -704,16 +704,7 @@ public class GBDeviceAdapterv2 extends RecyclerView.Adapter<GBDeviceAdapterv2.Vi
holder.cardViewActivityCardLayout.setVisibility(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()) {
setActivityCard(holder, device, dailyTotals);
}
@ -891,7 +882,7 @@ public class GBDeviceAdapterv2 extends RecyclerView.Adapter<GBDeviceAdapterv2.Vi
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 sleep = (int) dailyTotals[1];
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);
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() {
@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) {

View File

@ -123,7 +123,7 @@ public class CasioGBX100DeviceSupport extends CasioSupport implements SharedPref
SharedPreferences preferences = GBApplication.getDeviceSpecificSharedPrefs(this.getDevice().getAddress());
SharedPreferences.Editor editor = preferences.edit();
editor.putString("charts_tabs", "activity,activitylist,stepsweek");
editor.putString(DeviceSettingsPreferenceConst.PREFS_DEVICE_CHARTS_TABS, "activity,activitylist,stepsweek");
editor.apply();
}