mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge
synced 2024-11-25 11:26:47 +01:00
Start and end dates now work properly across charts
They are now managed by the Activity, because the fragments may be created and destroyed at any time and hece cannot synchronize their date-state all the time. Open issue: moving across the borders (first day with data, current day)
This commit is contained in:
parent
e47ebb8f09
commit
0bb3188bc8
@ -8,9 +8,6 @@ import android.graphics.Color;
|
|||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.support.v4.app.FragmentActivity;
|
import android.support.v4.app.FragmentActivity;
|
||||||
import android.support.v4.content.LocalBroadcastManager;
|
import android.support.v4.content.LocalBroadcastManager;
|
||||||
import android.view.LayoutInflater;
|
|
||||||
import android.view.View;
|
|
||||||
import android.view.ViewGroup;
|
|
||||||
|
|
||||||
import com.github.mikephil.charting.charts.BarLineChartBase;
|
import com.github.mikephil.charting.charts.BarLineChartBase;
|
||||||
import com.github.mikephil.charting.charts.Chart;
|
import com.github.mikephil.charting.charts.Chart;
|
||||||
@ -73,9 +70,6 @@ public abstract class AbstractChartFragment extends AbstractGBFragment {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private Date mStartDate;
|
|
||||||
private Date mEndDate;
|
|
||||||
|
|
||||||
protected ActivityConfig akActivity = new ActivityConfig(ActivityKind.TYPE_ACTIVITY, "Activity", Color.rgb(89, 178, 44));
|
protected ActivityConfig akActivity = new ActivityConfig(ActivityKind.TYPE_ACTIVITY, "Activity", Color.rgb(89, 178, 44));
|
||||||
protected ActivityConfig akLightSleep = new ActivityConfig(ActivityKind.TYPE_LIGHT_SLEEP, "Light Sleep", Color.rgb(182, 191, 255));
|
protected ActivityConfig akLightSleep = new ActivityConfig(ActivityKind.TYPE_LIGHT_SLEEP, "Light Sleep", Color.rgb(182, 191, 255));
|
||||||
protected ActivityConfig akDeepSleep = new ActivityConfig(ActivityKind.TYPE_DEEP_SLEEP, "Deep Sleep", Color.rgb(76, 90, 255));
|
protected ActivityConfig akDeepSleep = new ActivityConfig(ActivityKind.TYPE_DEEP_SLEEP, "Deep Sleep", Color.rgb(76, 90, 255));
|
||||||
@ -99,8 +93,6 @@ public abstract class AbstractChartFragment extends AbstractGBFragment {
|
|||||||
public void onCreate(Bundle savedInstanceState) {
|
public void onCreate(Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
|
|
||||||
initDates();
|
|
||||||
|
|
||||||
IntentFilter filter = new IntentFilter();
|
IntentFilter filter = new IntentFilter();
|
||||||
for (String action : mIntentFilterActions) {
|
for (String action : mIntentFilterActions) {
|
||||||
filter.addAction(action);
|
filter.addAction(action);
|
||||||
@ -145,17 +137,20 @@ public abstract class AbstractChartFragment extends AbstractGBFragment {
|
|||||||
// return view;
|
// return view;
|
||||||
// }
|
// }
|
||||||
|
|
||||||
public void setStartDate(Date date) {
|
private void setStartDate(Date date) {
|
||||||
mStartDate = date;
|
getHost().setStartDate(date);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setEndDate(Date endDate) {
|
private void setEndDate(Date date) {
|
||||||
mEndDate = endDate;
|
getHost().setEndDate(date);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void initDates() {
|
public Date getStartDate() {
|
||||||
setEndDate(new Date());
|
return getHost().getStartDate();
|
||||||
setStartDate(DateTimeUtils.shiftByDays(mEndDate, -1));
|
}
|
||||||
|
|
||||||
|
public Date getEndDate() {
|
||||||
|
return getHost().getEndDate();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -183,19 +178,23 @@ public abstract class AbstractChartFragment extends AbstractGBFragment {
|
|||||||
if (ChartsHost.REFRESH.equals(action)) {
|
if (ChartsHost.REFRESH.equals(action)) {
|
||||||
refresh();
|
refresh();
|
||||||
} else if (ChartsHost.DATE_NEXT.equals(action)) {
|
} else if (ChartsHost.DATE_NEXT.equals(action)) {
|
||||||
handleDateNext(mStartDate, mEndDate);
|
handleDateNext(getStartDate(), getEndDate());
|
||||||
} else if (ChartsHost.DATE_PREV.equals(action)) {
|
} else if (ChartsHost.DATE_PREV.equals(action)) {
|
||||||
handleDatePrev(mStartDate, mEndDate);
|
handleDatePrev(getStartDate(), getEndDate());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void handleDatePrev(Date startDate, Date endDate) {
|
protected void handleDatePrev(Date startDate, Date endDate) {
|
||||||
|
if (isVisibleInActivity()) {
|
||||||
shiftDates(startDate, endDate, -1);
|
shiftDates(startDate, endDate, -1);
|
||||||
|
}
|
||||||
refreshIfVisible();
|
refreshIfVisible();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void handleDateNext(Date startDate, Date endDate) {
|
protected void handleDateNext(Date startDate, Date endDate) {
|
||||||
|
if (isVisibleInActivity()) {
|
||||||
shiftDates(startDate, endDate, +1);
|
shiftDates(startDate, endDate, +1);
|
||||||
|
}
|
||||||
refreshIfVisible();
|
refreshIfVisible();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -312,7 +311,7 @@ public abstract class AbstractChartFragment extends AbstractGBFragment {
|
|||||||
protected void refresh() {
|
protected void refresh() {
|
||||||
if (getHost().getDevice() != null) {
|
if (getHost().getDevice() != null) {
|
||||||
mChartDirty = false;
|
mChartDirty = false;
|
||||||
updateDateInfo(mStartDate, mEndDate);
|
updateDateInfo(getStartDate(), getEndDate());
|
||||||
createRefreshTask("Visualizing data", getActivity()).execute();
|
createRefreshTask("Visualizing data", getActivity()).execute();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -529,8 +528,8 @@ public abstract class AbstractChartFragment extends AbstractGBFragment {
|
|||||||
if (from.compareTo(to) > 0) {
|
if (from.compareTo(to) > 0) {
|
||||||
throw new IllegalArgumentException("Bad date range: " +from + ".." + to);
|
throw new IllegalArgumentException("Bad date range: " +from + ".." + to);
|
||||||
}
|
}
|
||||||
mStartDate = from;
|
setStartDate(from);
|
||||||
mEndDate = to;
|
setEndDate(to);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void updateDateInfo(Date from, Date to) {
|
protected void updateDateInfo(Date from, Date to) {
|
||||||
@ -546,11 +545,11 @@ public abstract class AbstractChartFragment extends AbstractGBFragment {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private int getTSEnd() {
|
private int getTSEnd() {
|
||||||
return toTimestamp(mEndDate);
|
return toTimestamp(getEndDate());
|
||||||
}
|
}
|
||||||
|
|
||||||
private int getTSStart() {
|
private int getTSStart() {
|
||||||
return toTimestamp(mStartDate);
|
return toTimestamp(getStartDate());
|
||||||
}
|
}
|
||||||
|
|
||||||
private int toTimestamp(Date date) {
|
private int toTimestamp(Date date) {
|
||||||
|
@ -21,12 +21,15 @@ import android.widget.TextView;
|
|||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
import java.util.Date;
|
||||||
|
|
||||||
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.ControlCenter;
|
import nodomain.freeyourgadget.gadgetbridge.activities.ControlCenter;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.impl.GBDevice;
|
import nodomain.freeyourgadget.gadgetbridge.impl.GBDevice;
|
||||||
|
import nodomain.freeyourgadget.gadgetbridge.util.DateTimeUtils;
|
||||||
|
|
||||||
public class ChartsActivity extends AbstractGBFragmentActivity implements ChartsHost {
|
public class ChartsActivity extends AbstractGBFragmentActivity implements ChartsHost {
|
||||||
|
|
||||||
@ -37,6 +40,10 @@ public class ChartsActivity extends AbstractGBFragmentActivity implements Charts
|
|||||||
private Button mNextButton;
|
private Button mNextButton;
|
||||||
private TextView mDateControl;
|
private TextView mDateControl;
|
||||||
|
|
||||||
|
private Date mStartDate;
|
||||||
|
private Date mEndDate;
|
||||||
|
|
||||||
|
|
||||||
private BroadcastReceiver mReceiver = new BroadcastReceiver() {
|
private BroadcastReceiver mReceiver = new BroadcastReceiver() {
|
||||||
@Override
|
@Override
|
||||||
public void onReceive(Context context, Intent intent) {
|
public void onReceive(Context context, Intent intent) {
|
||||||
@ -71,6 +78,8 @@ public class ChartsActivity extends AbstractGBFragmentActivity implements Charts
|
|||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
setContentView(R.layout.activity_charts);
|
setContentView(R.layout.activity_charts);
|
||||||
|
|
||||||
|
initDates();
|
||||||
|
|
||||||
IntentFilter filterLocal = new IntentFilter();
|
IntentFilter filterLocal = new IntentFilter();
|
||||||
filterLocal.addAction(ControlCenter.ACTION_QUIT);
|
filterLocal.addAction(ControlCenter.ACTION_QUIT);
|
||||||
filterLocal.addAction(GBDevice.ACTION_DEVICE_CHANGED);
|
filterLocal.addAction(GBDevice.ACTION_DEVICE_CHANGED);
|
||||||
@ -106,11 +115,36 @@ public class ChartsActivity extends AbstractGBFragmentActivity implements Charts
|
|||||||
mDateControl = (TextView) findViewById(R.id.charts_text_date);
|
mDateControl = (TextView) findViewById(R.id.charts_text_date);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected void initDates() {
|
||||||
|
setEndDate(new Date());
|
||||||
|
setStartDate(DateTimeUtils.shiftByDays(getEndDate(), -1));
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public GBDevice getDevice() {
|
public GBDevice getDevice() {
|
||||||
return mGBDevice;
|
return mGBDevice;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setStartDate(Date startDate) {
|
||||||
|
mStartDate = startDate;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setEndDate(Date endDate) {
|
||||||
|
mEndDate = endDate;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Date getStartDate() {
|
||||||
|
return mStartDate;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Date getEndDate() {
|
||||||
|
return mEndDate;
|
||||||
|
}
|
||||||
|
|
||||||
private void handleNextButtonClicked() {
|
private void handleNextButtonClicked() {
|
||||||
LocalBroadcastManager.getInstance(this).sendBroadcast(new Intent(DATE_NEXT));
|
LocalBroadcastManager.getInstance(this).sendBroadcast(new Intent(DATE_NEXT));
|
||||||
}
|
}
|
||||||
|
@ -1,13 +1,20 @@
|
|||||||
package nodomain.freeyourgadget.gadgetbridge.activities.charts;
|
package nodomain.freeyourgadget.gadgetbridge.activities.charts;
|
||||||
|
|
||||||
|
import java.util.Date;
|
||||||
|
|
||||||
import nodomain.freeyourgadget.gadgetbridge.impl.GBDevice;
|
import nodomain.freeyourgadget.gadgetbridge.impl.GBDevice;
|
||||||
|
|
||||||
public interface ChartsHost {
|
public interface ChartsHost {
|
||||||
public static final String DATE_PREV = ChartsActivity.class.getName().concat(".date_prev");
|
static final String DATE_PREV = ChartsActivity.class.getName().concat(".date_prev");
|
||||||
public static final String DATE_NEXT = ChartsActivity.class.getName().concat(".date_next");
|
static final String DATE_NEXT = ChartsActivity.class.getName().concat(".date_next");
|
||||||
public static final String REFRESH = ChartsActivity.class.getName().concat(".refresh");
|
static final String REFRESH = ChartsActivity.class.getName().concat(".refresh");
|
||||||
|
|
||||||
GBDevice getDevice();
|
GBDevice getDevice();
|
||||||
|
|
||||||
|
void setStartDate(Date startDate);
|
||||||
|
void setEndDate(Date endDate);
|
||||||
|
|
||||||
|
Date getStartDate();
|
||||||
|
Date getEndDate();
|
||||||
void setDateInfo(String dateInfo);
|
void setDateInfo(String dateInfo);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user