mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge
synced 2024-11-29 05:16:51 +01:00
Improvements to charts
- backward and forward buttons work better - buttons only refresh the current fragment now - activity shows fragment-specific titles
This commit is contained in:
parent
070876db06
commit
e47ebb8f09
@ -0,0 +1,51 @@
|
||||
package nodomain.freeyourgadget.gadgetbridge.activities;
|
||||
|
||||
import android.support.v4.app.FragmentManager;
|
||||
import android.support.v4.app.FragmentStatePagerAdapter;
|
||||
import android.view.ViewGroup;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
public abstract class AbstractFragmentPagerAdapter extends FragmentStatePagerAdapter {
|
||||
private Set<AbstractGBFragment> fragments = new HashSet<>();
|
||||
private Object primaryFragment;
|
||||
|
||||
public AbstractFragmentPagerAdapter(FragmentManager fm) {
|
||||
super(fm);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object instantiateItem(ViewGroup container, int position) {
|
||||
Object fragment = super.instantiateItem(container, position);
|
||||
if (fragment instanceof AbstractGBFragment) {
|
||||
fragments.add((AbstractGBFragment) fragment);
|
||||
}
|
||||
return fragment;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void destroyItem(ViewGroup container, int position, Object object) {
|
||||
super.destroyItem(container, position, object);
|
||||
fragments.remove(object);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setPrimaryItem(ViewGroup container, int position, Object object) {
|
||||
super.setPrimaryItem(container, position, object);
|
||||
if (object != primaryFragment) {
|
||||
primaryFragment = object;
|
||||
setCurrentFragment(primaryFragment);
|
||||
}
|
||||
}
|
||||
|
||||
private void setCurrentFragment(Object newCurrentFragment) {
|
||||
for (AbstractGBFragment frag : fragments) {
|
||||
if (frag != newCurrentFragment) {
|
||||
frag.onMadeInvisibleInActivity();
|
||||
} else {
|
||||
frag.onMadeVisibleInActivityInternal();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,65 @@
|
||||
package nodomain.freeyourgadget.gadgetbridge.activities;
|
||||
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.v4.app.Fragment;
|
||||
import android.support.v4.app.FragmentActivity;
|
||||
|
||||
/**
|
||||
* Abstract base class for fragments. Provides hooks that are called when
|
||||
* the fragment is made visible and invisible in the activity. also allows
|
||||
* the fragment to define the title to be shown in the activity.
|
||||
* @see AbstractGBFragmentActivity
|
||||
*/
|
||||
public abstract class AbstractGBFragment extends Fragment {
|
||||
private boolean mVisibleInactivity;
|
||||
|
||||
/**
|
||||
* Called when this fragment has been fully scrolled into the activity.
|
||||
*
|
||||
* @see #isVisibleInActivity()
|
||||
* @see #onMadeInvisibleInActivity()
|
||||
*/
|
||||
protected void onMadeVisibleInActivity() {
|
||||
updateActivityTitle();
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when this fragment has been scrolled out of the activity.
|
||||
* @see #isVisibleInActivity()
|
||||
* @see #onMadeVisibleInActivity()
|
||||
*/
|
||||
protected void onMadeInvisibleInActivity() {
|
||||
mVisibleInactivity = false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if this fragment is currently visible in the hosting
|
||||
* activity, not taking into account whether the screen is enabled at all.
|
||||
*/
|
||||
public boolean isVisibleInActivity() {
|
||||
return mVisibleInactivity;
|
||||
}
|
||||
|
||||
protected void updateActivityTitle() {
|
||||
FragmentActivity activity = getActivity();
|
||||
if (activity != null && !activity.isFinishing() && !activity.isDestroyed()) {
|
||||
if (getTitle() != null) {
|
||||
activity.setTitle(getTitle());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Nullable
|
||||
protected abstract CharSequence getTitle();
|
||||
|
||||
/**
|
||||
* Internal
|
||||
* @hide
|
||||
*/
|
||||
public void onMadeVisibleInActivityInternal() {
|
||||
mVisibleInactivity = true;
|
||||
if (isVisible()) {
|
||||
onMadeVisibleInActivity();
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,57 @@
|
||||
package nodomain.freeyourgadget.gadgetbridge.activities;
|
||||
|
||||
import android.content.Context;
|
||||
import android.os.Bundle;
|
||||
import android.os.PersistableBundle;
|
||||
import android.support.v4.app.FragmentActivity;
|
||||
import android.support.v4.app.FragmentManager;
|
||||
import android.support.v4.app.FragmentPagerAdapter;
|
||||
import android.support.v4.view.PagerAdapter;
|
||||
import android.util.AttributeSet;
|
||||
import android.view.View;
|
||||
|
||||
/**
|
||||
* A base activity that supports paging through fragments by swiping.
|
||||
* Subclasses will have to add a ViewPager to their layout and add something
|
||||
* like this to hook it to the fragments:
|
||||
*
|
||||
* <pre>
|
||||
* // Set up the ViewPager with the sections adapter.
|
||||
* ViewPager viewPager = (ViewPager) findViewById(R.id.pager);
|
||||
* viewPager.setAdapter(getPagerAdapter());
|
||||
* </pre>
|
||||
*
|
||||
* @see AbstractGBFragment
|
||||
*/
|
||||
public abstract class AbstractGBFragmentActivity extends FragmentActivity {
|
||||
/**
|
||||
* The {@link android.support.v4.view.PagerAdapter} that will provide
|
||||
* fragments for each of the sections. We use a
|
||||
* {@link FragmentPagerAdapter} derivative, which will keep every
|
||||
* loaded fragment in memory. If this becomes too memory intensive, it
|
||||
* may be best to switch to a
|
||||
* {@link android.support.v4.app.FragmentStatePagerAdapter}.
|
||||
*/
|
||||
private AbstractFragmentPagerAdapter mSectionsPagerAdapter;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
// Create the adapter that will return a fragment for each of the three
|
||||
// primary sections of the activity.
|
||||
mSectionsPagerAdapter = createFragmentPagerAdapter(getSupportFragmentManager());
|
||||
}
|
||||
|
||||
public AbstractFragmentPagerAdapter getPagerAdapter() {
|
||||
return mSectionsPagerAdapter;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a PagerAdapter that will create the fragments to be used with this
|
||||
* activity. The fragments should typically extend AbstractGBFragment
|
||||
* @param fragmentManager
|
||||
* @return
|
||||
*/
|
||||
protected abstract AbstractFragmentPagerAdapter createFragmentPagerAdapter(FragmentManager fragmentManager);
|
||||
}
|
@ -6,7 +6,6 @@ import android.content.Intent;
|
||||
import android.content.IntentFilter;
|
||||
import android.graphics.Color;
|
||||
import android.os.Bundle;
|
||||
import android.support.v4.app.Fragment;
|
||||
import android.support.v4.app.FragmentActivity;
|
||||
import android.support.v4.content.LocalBroadcastManager;
|
||||
import android.view.LayoutInflater;
|
||||
@ -33,6 +32,7 @@ import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import nodomain.freeyourgadget.gadgetbridge.R;
|
||||
import nodomain.freeyourgadget.gadgetbridge.activities.AbstractGBFragment;
|
||||
import nodomain.freeyourgadget.gadgetbridge.database.DBAccess;
|
||||
import nodomain.freeyourgadget.gadgetbridge.database.DBHandler;
|
||||
import nodomain.freeyourgadget.gadgetbridge.devices.DeviceCoordinator;
|
||||
@ -43,7 +43,7 @@ import nodomain.freeyourgadget.gadgetbridge.model.ActivitySample;
|
||||
import nodomain.freeyourgadget.gadgetbridge.util.DateTimeUtils;
|
||||
import nodomain.freeyourgadget.gadgetbridge.util.DeviceHelper;
|
||||
|
||||
public abstract class AbstractChartFragment extends Fragment {
|
||||
public abstract class AbstractChartFragment extends AbstractGBFragment {
|
||||
private static final Logger LOG = LoggerFactory.getLogger(ActivitySleepChartFragment.class);
|
||||
|
||||
private final Set<String> mIntentFilterActions;
|
||||
@ -53,6 +53,13 @@ public abstract class AbstractChartFragment extends Fragment {
|
||||
AbstractChartFragment.this.onReceive(context, intent);
|
||||
}
|
||||
};
|
||||
private boolean mChartDirty = true;
|
||||
|
||||
public boolean isChartDirty() {
|
||||
return mChartDirty;
|
||||
}
|
||||
|
||||
public abstract String getTitle();
|
||||
|
||||
protected static final class ActivityConfig {
|
||||
public final int type;
|
||||
@ -102,12 +109,42 @@ public abstract class AbstractChartFragment extends Fragment {
|
||||
}
|
||||
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
||||
View view = super.onCreateView(inflater, container, savedInstanceState);
|
||||
updateDateInfo(mStartDate, mEndDate);
|
||||
return view;
|
||||
public void onHiddenChanged(boolean hidden) {
|
||||
super.onHiddenChanged(hidden);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPause() {
|
||||
super.onPause();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResume() {
|
||||
super.onResume();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStart() {
|
||||
super.onStart();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStop() {
|
||||
super.onStop();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setUserVisibleHint(boolean isVisibleToUser) {
|
||||
super.setUserVisibleHint(isVisibleToUser);
|
||||
}
|
||||
|
||||
// @Override
|
||||
// public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
||||
// View view = super.onCreateView(inflater, container, savedInstanceState);
|
||||
// updateDateInfo(mStartDate, mEndDate);
|
||||
// return view;
|
||||
// }
|
||||
|
||||
public void setStartDate(Date date) {
|
||||
mStartDate = date;
|
||||
}
|
||||
@ -121,6 +158,20 @@ public abstract class AbstractChartFragment extends Fragment {
|
||||
setStartDate(DateTimeUtils.shiftByDays(mEndDate, -1));
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when this fragment has been fully scrolled into the activity.
|
||||
*
|
||||
* @see #isVisibleInActivity()
|
||||
* @see #onMadeInvisibleInActivity()
|
||||
*/
|
||||
@Override
|
||||
protected void onMadeVisibleInActivity() {
|
||||
super.onMadeVisibleInActivity();
|
||||
if (isChartDirty()) {
|
||||
refresh();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDestroy() {
|
||||
super.onDestroy();
|
||||
@ -140,10 +191,20 @@ public abstract class AbstractChartFragment extends Fragment {
|
||||
|
||||
protected void handleDatePrev(Date startDate, Date endDate) {
|
||||
shiftDates(startDate, endDate, -1);
|
||||
refreshIfVisible();
|
||||
}
|
||||
|
||||
protected void handleDateNext(Date startDate, Date endDate) {
|
||||
shiftDates(startDate, endDate, +1);
|
||||
refreshIfVisible();
|
||||
}
|
||||
|
||||
protected void refreshIfVisible() {
|
||||
if (isVisibleInActivity()) {
|
||||
refresh();
|
||||
} else {
|
||||
mChartDirty = true;
|
||||
}
|
||||
}
|
||||
|
||||
protected void shiftDates(Date startDate, Date endDate, int offset) {
|
||||
@ -151,7 +212,6 @@ public abstract class AbstractChartFragment extends Fragment {
|
||||
Date newEnd = DateTimeUtils.shiftByDays(endDate, offset);
|
||||
|
||||
setDateRange(newStart, newEnd);
|
||||
refresh();
|
||||
}
|
||||
|
||||
protected Integer getColorFor(int activityKind) {
|
||||
@ -250,15 +310,19 @@ public abstract class AbstractChartFragment extends Fragment {
|
||||
* #renderCharts
|
||||
*/
|
||||
protected void refresh() {
|
||||
if (getHost().getDevice() != null) {
|
||||
mChartDirty = false;
|
||||
updateDateInfo(mStartDate, mEndDate);
|
||||
createRefreshTask("Visualizing data", getActivity()).execute();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This method reads the data from the database, analyzes and prepares it for
|
||||
* the charts. This will be called from a background task, so there must not be
|
||||
* any UI access. #renderCharts will be automatically called after this method.
|
||||
*/
|
||||
protected abstract void refreshInBackground(DBHandler db);
|
||||
protected abstract void refreshInBackground(DBHandler db, GBDevice device);
|
||||
|
||||
/**
|
||||
* Performs a re-rendering of the chart.
|
||||
@ -267,10 +331,6 @@ public abstract class AbstractChartFragment extends Fragment {
|
||||
protected abstract void renderCharts();
|
||||
|
||||
protected void refresh(GBDevice gbDevice, BarLineChartBase chart, List<ActivitySample> samples) {
|
||||
if (gbDevice == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
Calendar cal = GregorianCalendar.getInstance();
|
||||
cal.clear();
|
||||
Date date;
|
||||
@ -450,7 +510,7 @@ public abstract class AbstractChartFragment extends Fragment {
|
||||
|
||||
@Override
|
||||
protected void doInBackground(DBHandler db) {
|
||||
refreshInBackground(db);
|
||||
refreshInBackground(db, getHost().getDevice());
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -471,7 +531,6 @@ public abstract class AbstractChartFragment extends Fragment {
|
||||
}
|
||||
mStartDate = from;
|
||||
mEndDate = to;
|
||||
updateDateInfo(mStartDate, mEndDate);
|
||||
}
|
||||
|
||||
protected void updateDateInfo(Date from, Date to) {
|
||||
|
@ -34,19 +34,12 @@ public class ActivitySleepChartFragment extends AbstractChartFragment {
|
||||
private int mSmartAlarmTo = -1;
|
||||
private int mTimestampFrom = -1;
|
||||
private int mSmartAlarmGoneOff = -1;
|
||||
private GBDevice mGBDevice = null;
|
||||
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
||||
Bundle savedInstanceState) {
|
||||
View rootView = inflater.inflate(R.layout.fragment_charts, container, false);
|
||||
|
||||
Bundle extras = getActivity().getIntent().getExtras();
|
||||
if (extras != null) {
|
||||
mGBDevice = extras.getParcelable(GBDevice.EXTRA_DEVICE);
|
||||
}
|
||||
|
||||
|
||||
mChart = (BarLineChartBase) rootView.findViewById(R.id.activitysleepchart);
|
||||
|
||||
setupChart();
|
||||
@ -54,6 +47,11 @@ public class ActivitySleepChartFragment extends AbstractChartFragment {
|
||||
return rootView;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getTitle() {
|
||||
return getString(R.string.activity_sleepchart_activity_and_sleep);
|
||||
}
|
||||
|
||||
private void setupChart() {
|
||||
mChart.setBackgroundColor(BACKGROUND_COLOR);
|
||||
mChart.setDescriptionColor(DESCRIPTION_COLOR);
|
||||
@ -85,6 +83,7 @@ public class ActivitySleepChartFragment extends AbstractChartFragment {
|
||||
yAxisRight.setDrawTopYLabelEntry(false);
|
||||
yAxisRight.setTextColor(CHART_TEXT_COLOR);
|
||||
|
||||
// refreshIfVisible();
|
||||
refresh();
|
||||
}
|
||||
|
||||
@ -104,9 +103,9 @@ public class ActivitySleepChartFragment extends AbstractChartFragment {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void refreshInBackground(DBHandler db) {
|
||||
List<ActivitySample> samples = getSamples(db, mGBDevice);
|
||||
refresh(mGBDevice, mChart, samples);
|
||||
protected void refreshInBackground(DBHandler db, GBDevice device) {
|
||||
List<ActivitySample> samples = getSamples(db, device);
|
||||
refresh(device, mChart, samples);
|
||||
|
||||
mChart.getLegend().setTextColor(LEGEND_TEXT_COLOR);
|
||||
}
|
||||
|
@ -6,11 +6,10 @@ import android.content.Intent;
|
||||
import android.content.IntentFilter;
|
||||
import android.os.Bundle;
|
||||
import android.support.v4.app.Fragment;
|
||||
import android.support.v4.app.FragmentActivity;
|
||||
import android.support.v4.app.FragmentManager;
|
||||
import android.support.v4.app.FragmentPagerAdapter;
|
||||
import android.support.v4.app.FragmentStatePagerAdapter;
|
||||
import android.support.v4.content.LocalBroadcastManager;
|
||||
import android.support.v4.view.PagerAdapter;
|
||||
import android.support.v4.view.ViewPager;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuItem;
|
||||
@ -22,32 +21,17 @@ import android.widget.TextView;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.util.Locale;
|
||||
|
||||
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.ControlCenter;
|
||||
import nodomain.freeyourgadget.gadgetbridge.impl.GBDevice;
|
||||
|
||||
public class ChartsActivity extends FragmentActivity implements ChartsHost {
|
||||
public class ChartsActivity extends AbstractGBFragmentActivity implements ChartsHost {
|
||||
|
||||
private static final Logger LOG = LoggerFactory.getLogger(ChartsActivity.class);
|
||||
|
||||
/**
|
||||
* The {@link android.support.v4.view.PagerAdapter} that will provide
|
||||
* fragments for each of the sections. We use a
|
||||
* {@link FragmentPagerAdapter} derivative, which will keep every
|
||||
* loaded fragment in memory. If this becomes too memory intensive, it
|
||||
* may be best to switch to a
|
||||
* {@link android.support.v4.app.FragmentStatePagerAdapter}.
|
||||
*/
|
||||
private SectionsPagerAdapter mSectionsPagerAdapter;
|
||||
|
||||
/**
|
||||
* The {@link ViewPager} that will host the section contents.
|
||||
*/
|
||||
private ViewPager mViewPager;
|
||||
|
||||
private ProgressBar mProgressBar;
|
||||
private Button mPrevButton;
|
||||
private Button mNextButton;
|
||||
@ -61,8 +45,6 @@ public class ChartsActivity extends FragmentActivity implements ChartsHost {
|
||||
case ControlCenter.ACTION_QUIT:
|
||||
finish();
|
||||
break;
|
||||
case ControlCenter.ACTION_REFRESH_DEVICELIST:
|
||||
break;
|
||||
case GBDevice.ACTION_DEVICE_CHANGED:
|
||||
GBDevice dev = intent.getParcelableExtra(GBDevice.EXTRA_DEVICE);
|
||||
refreshBusyState(dev);
|
||||
@ -70,6 +52,7 @@ public class ChartsActivity extends FragmentActivity implements ChartsHost {
|
||||
}
|
||||
}
|
||||
};
|
||||
private GBDevice mGBDevice;
|
||||
|
||||
private void refreshBusyState(GBDevice dev) {
|
||||
if (dev.isBusy()) {
|
||||
@ -90,18 +73,19 @@ public class ChartsActivity extends FragmentActivity implements ChartsHost {
|
||||
|
||||
IntentFilter filterLocal = new IntentFilter();
|
||||
filterLocal.addAction(ControlCenter.ACTION_QUIT);
|
||||
filterLocal.addAction(ControlCenter.ACTION_REFRESH_DEVICELIST);
|
||||
filterLocal.addAction(GBDevice.ACTION_DEVICE_CHANGED);
|
||||
LocalBroadcastManager.getInstance(this).registerReceiver(mReceiver, filterLocal);
|
||||
|
||||
|
||||
// Create the adapter that will return a fragment for each of the three
|
||||
// primary sections of the activity.
|
||||
mSectionsPagerAdapter = new SectionsPagerAdapter(getSupportFragmentManager());
|
||||
Bundle extras = getIntent().getExtras();
|
||||
if (extras != null) {
|
||||
mGBDevice = extras.getParcelable(GBDevice.EXTRA_DEVICE);
|
||||
} else {
|
||||
throw new IllegalArgumentException("Must provide a device when invoking this activity");
|
||||
}
|
||||
|
||||
// Set up the ViewPager with the sections adapter.
|
||||
mViewPager = (ViewPager) findViewById(R.id.pager);
|
||||
mViewPager.setAdapter(mSectionsPagerAdapter);
|
||||
ViewPager viewPager = (ViewPager) findViewById(R.id.pager);
|
||||
viewPager.setAdapter(getPagerAdapter());
|
||||
|
||||
mProgressBar = (ProgressBar) findViewById(R.id.charts_progress);
|
||||
mPrevButton = (Button) findViewById(R.id.charts_previous);
|
||||
@ -122,6 +106,11 @@ public class ChartsActivity extends FragmentActivity implements ChartsHost {
|
||||
mDateControl = (TextView) findViewById(R.id.charts_text_date);
|
||||
}
|
||||
|
||||
@Override
|
||||
public GBDevice getDevice() {
|
||||
return mGBDevice;
|
||||
}
|
||||
|
||||
private void handleNextButtonClicked() {
|
||||
LocalBroadcastManager.getInstance(this).sendBroadcast(new Intent(DATE_NEXT));
|
||||
}
|
||||
@ -161,11 +150,16 @@ public class ChartsActivity extends FragmentActivity implements ChartsHost {
|
||||
mDateControl.setText(dateInfo);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected AbstractFragmentPagerAdapter createFragmentPagerAdapter(FragmentManager fragmentManager) {
|
||||
return new SectionsPagerAdapter(fragmentManager);
|
||||
}
|
||||
|
||||
/**
|
||||
* A {@link FragmentStatePagerAdapter} that returns a fragment corresponding to
|
||||
* one of the sections/tabs/pages.
|
||||
*/
|
||||
public static class SectionsPagerAdapter extends FragmentStatePagerAdapter {
|
||||
public static class SectionsPagerAdapter extends AbstractFragmentPagerAdapter {
|
||||
|
||||
public SectionsPagerAdapter(FragmentManager fm) {
|
||||
super(fm);
|
||||
@ -191,19 +185,5 @@ public class ChartsActivity extends FragmentActivity implements ChartsHost {
|
||||
// Show 3 total pages.
|
||||
return 3;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CharSequence getPageTitle(int position) {
|
||||
Locale l = Locale.getDefault();
|
||||
switch (position) {
|
||||
case 0:
|
||||
return "Today".toUpperCase(l);
|
||||
case 1:
|
||||
return "Week".toUpperCase(l);
|
||||
case 2:
|
||||
return "Month".toUpperCase(l);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,9 +1,13 @@
|
||||
package nodomain.freeyourgadget.gadgetbridge.activities.charts;
|
||||
|
||||
import nodomain.freeyourgadget.gadgetbridge.impl.GBDevice;
|
||||
|
||||
public interface ChartsHost {
|
||||
public static final String DATE_PREV = ChartsActivity.class.getName().concat(".date_prev");
|
||||
public static final String DATE_NEXT = ChartsActivity.class.getName().concat(".date_next");
|
||||
public static final String REFRESH = ChartsActivity.class.getName().concat(".refresh");
|
||||
|
||||
GBDevice getDevice();
|
||||
|
||||
void setDateInfo(String dateInfo);
|
||||
}
|
||||
|
@ -44,17 +44,13 @@ public class SleepChartFragment extends AbstractChartFragment {
|
||||
private int mSmartAlarmTo = -1;
|
||||
private int mTimestampFrom = -1;
|
||||
private int mSmartAlarmGoneOff = -1;
|
||||
private GBDevice mGBDevice = null;
|
||||
|
||||
@Override
|
||||
protected void refreshInBackground(DBHandler db) {
|
||||
List<ActivitySample> samples = getSamples(db);
|
||||
refresh(mGBDevice, mActivityChart, samples);
|
||||
refreshSleepAmounts(mGBDevice, mSleepAmountChart, samples);
|
||||
}
|
||||
protected void refreshInBackground(DBHandler db, GBDevice device) {
|
||||
List<ActivitySample> samples = getSamples(db, device);
|
||||
|
||||
private List<ActivitySample> getSamples(DBHandler db) {
|
||||
return getSamples(db, mGBDevice);
|
||||
refresh(device, mActivityChart, samples);
|
||||
refreshSleepAmounts(device, mSleepAmountChart, samples);
|
||||
}
|
||||
|
||||
private void refreshSleepAmounts(GBDevice mGBDevice, PieChart pieChart, List<ActivitySample> samples) {
|
||||
@ -87,22 +83,23 @@ public class SleepChartFragment extends AbstractChartFragment {
|
||||
//setupLegend(pieChart);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getTitle() {
|
||||
return getString(R.string.sleepchart_your_sleep);
|
||||
}
|
||||
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
||||
Bundle savedInstanceState) {
|
||||
View rootView = inflater.inflate(R.layout.fragment_sleepchart, container, false);
|
||||
|
||||
Bundle extras = getActivity().getIntent().getExtras();
|
||||
if (extras != null) {
|
||||
mGBDevice = extras.getParcelable(GBDevice.EXTRA_DEVICE);
|
||||
}
|
||||
|
||||
mActivityChart = (BarLineChartBase) rootView.findViewById(R.id.sleepchart);
|
||||
mSleepAmountChart = (PieChart) rootView.findViewById(R.id.sleepchart_pie_light_deep);
|
||||
|
||||
setupActivityChart();
|
||||
setupSleepAmountChart();
|
||||
|
||||
// refreshIfVisible();
|
||||
refresh();
|
||||
|
||||
return rootView;
|
||||
|
@ -44,14 +44,12 @@ public class WeekStepsChartFragment extends AbstractChartFragment {
|
||||
private BarLineChartBase mWeekStepsChart;
|
||||
private PieChart mTodayStepsChart;
|
||||
|
||||
private GBDevice mGBDevice = null;
|
||||
|
||||
@Override
|
||||
protected void refreshInBackground(DBHandler db) {
|
||||
protected void refreshInBackground(DBHandler db, GBDevice device) {
|
||||
Calendar day = Calendar.getInstance();
|
||||
//NB: we could have omitted the day, but this way we can move things to the past easily
|
||||
refreshDaySteps(db, mTodayStepsChart, day);
|
||||
refreshWeekBeforeSteps(db, mWeekStepsChart, day);
|
||||
refreshDaySteps(db, mTodayStepsChart, day, device);
|
||||
refreshWeekBeforeSteps(db, mWeekStepsChart, day, device);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -60,7 +58,7 @@ public class WeekStepsChartFragment extends AbstractChartFragment {
|
||||
mTodayStepsChart.invalidate();
|
||||
}
|
||||
|
||||
private void refreshWeekBeforeSteps(DBHandler db, BarLineChartBase barChart, Calendar day) {
|
||||
private void refreshWeekBeforeSteps(DBHandler db, BarLineChartBase barChart, Calendar day, GBDevice device) {
|
||||
|
||||
ActivityAnalysis analysis = new ActivityAnalysis();
|
||||
|
||||
@ -69,7 +67,7 @@ public class WeekStepsChartFragment extends AbstractChartFragment {
|
||||
List<String> labels = new ArrayList<>();
|
||||
|
||||
for (int counter = 0; counter < 7; counter++) {
|
||||
entries.add(new BarEntry(analysis.calculateTotalSteps(getSamplesOfDay(db, day)), counter));
|
||||
entries.add(new BarEntry(analysis.calculateTotalSteps(getSamplesOfDay(db, day, device)), counter));
|
||||
labels.add(day.getDisplayName(Calendar.DAY_OF_WEEK, Calendar.SHORT, mLocale));
|
||||
day.add(Calendar.DATE, 1);
|
||||
}
|
||||
@ -89,10 +87,10 @@ public class WeekStepsChartFragment extends AbstractChartFragment {
|
||||
barChart.getLegend().setEnabled(false);
|
||||
}
|
||||
|
||||
private void refreshDaySteps(DBHandler db, PieChart pieChart, Calendar day) {
|
||||
private void refreshDaySteps(DBHandler db, PieChart pieChart, Calendar day, GBDevice device) {
|
||||
ActivityAnalysis analysis = new ActivityAnalysis();
|
||||
|
||||
int totalSteps = analysis.calculateTotalSteps(getSamplesOfDay(db, day));
|
||||
int totalSteps = analysis.calculateTotalSteps(getSamplesOfDay(db, day, device));
|
||||
|
||||
pieChart.setCenterText(NumberFormat.getNumberInstance(mLocale).format(totalSteps));
|
||||
PieData data = new PieData();
|
||||
@ -128,13 +126,9 @@ public class WeekStepsChartFragment extends AbstractChartFragment {
|
||||
|
||||
View rootView = inflater.inflate(R.layout.fragment_sleepchart, container, false);
|
||||
|
||||
Bundle extras = getActivity().getIntent().getExtras();
|
||||
if (extras != null) {
|
||||
mGBDevice = extras.getParcelable(GBDevice.EXTRA_DEVICE);
|
||||
}
|
||||
|
||||
if(mGBDevice != null) {
|
||||
mTargetSteps = MiBandCoordinator.getFitnessGoal(mGBDevice.getAddress());
|
||||
GBDevice device = getHost().getDevice();
|
||||
if(device != null) {
|
||||
mTargetSteps = MiBandCoordinator.getFitnessGoal(device.getAddress());
|
||||
}
|
||||
|
||||
mWeekStepsChart = (BarLineChartBase) rootView.findViewById(R.id.sleepchart);
|
||||
@ -143,11 +137,17 @@ public class WeekStepsChartFragment extends AbstractChartFragment {
|
||||
setupWeekStepsChart();
|
||||
setupTodayStepsChart();
|
||||
|
||||
// refreshIfVisible();
|
||||
refresh();
|
||||
|
||||
return rootView;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getTitle() {
|
||||
return getString(R.string.weekstepschart_steps_a_week);
|
||||
}
|
||||
|
||||
private void setupTodayStepsChart() {
|
||||
mTodayStepsChart.setBackgroundColor(BACKGROUND_COLOR);
|
||||
mTodayStepsChart.setDescriptionColor(DESCRIPTION_COLOR);
|
||||
@ -196,7 +196,7 @@ public class WeekStepsChartFragment extends AbstractChartFragment {
|
||||
chart.getLegend().setTextColor(LEGEND_TEXT_COLOR);
|
||||
}
|
||||
|
||||
private List<ActivitySample> getSamplesOfDay(DBHandler db, Calendar day) {
|
||||
private List<ActivitySample> getSamplesOfDay(DBHandler db, Calendar day, GBDevice device) {
|
||||
int startTs;
|
||||
int endTs;
|
||||
|
||||
@ -210,7 +210,7 @@ public class WeekStepsChartFragment extends AbstractChartFragment {
|
||||
day.set(Calendar.SECOND, 59);
|
||||
endTs = (int) (day.getTimeInMillis() / 1000);
|
||||
|
||||
return getSamples(db, mGBDevice, startTs, endTs);
|
||||
return getSamples(db, device, startTs, endTs);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -166,4 +166,7 @@
|
||||
<string name="pbw_install_handler_unable_to_install">Unable to install the given file: $1%s</string>
|
||||
<string name="pbw_install_handler_hw_revision_mismatch">Unable to install the given firmware: it doesn\'t match your Pebble\'s hardware revision.</string>
|
||||
<string name="installer_activity_wait_while_determining_status">Please wait while determining the installation status...</string>
|
||||
<string name="sleepchart_your_sleep">Your Sleep</string>
|
||||
<string name="weekstepschart_steps_a_week">Steps a week</string>
|
||||
<string name="activity_sleepchart_activity_and_sleep">Your Activity and Sleep</string>
|
||||
</resources>
|
||||
|
Loading…
Reference in New Issue
Block a user