mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge
synced 2024-11-29 21:32:57 +01:00
Battery info - use Gb DBAccess
This commit is contained in:
parent
0f5f036057
commit
6aeb297aa5
@ -69,6 +69,7 @@ public class BatteryInfoActivity extends AbstractGBActivity {
|
|||||||
|
|
||||||
LinearLayout battery_status_date_to_layout = (LinearLayout) findViewById(R.id.battery_status_date_to_layout);
|
LinearLayout battery_status_date_to_layout = (LinearLayout) findViewById(R.id.battery_status_date_to_layout);
|
||||||
|
|
||||||
|
battery_status_time_span_seekbar.setMax(5);
|
||||||
battery_status_time_span_seekbar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
|
battery_status_time_span_seekbar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -53,6 +53,7 @@ import de.greenrobot.dao.query.QueryBuilder;
|
|||||||
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.charts.AbstractChartFragment;
|
import nodomain.freeyourgadget.gadgetbridge.activities.charts.AbstractChartFragment;
|
||||||
|
import nodomain.freeyourgadget.gadgetbridge.database.DBAccess;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.database.DBHandler;
|
import nodomain.freeyourgadget.gadgetbridge.database.DBHandler;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.database.DBHelper;
|
import nodomain.freeyourgadget.gadgetbridge.database.DBHelper;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.entities.BatteryLevel;
|
import nodomain.freeyourgadget.gadgetbridge.entities.BatteryLevel;
|
||||||
@ -79,39 +80,15 @@ public class BatteryInfoChartFragment extends AbstractGBFragment {
|
|||||||
this.endTime = (int) endTime;
|
this.endTime = (int) endTime;
|
||||||
this.gbDevice = gbDevice;
|
this.gbDevice = gbDevice;
|
||||||
try {
|
try {
|
||||||
populate_charts_data();
|
createRefreshTask("Visualizing data", getActivity()).execute();
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
LOG.debug("Unable to fill charts data right now:", e);
|
LOG.debug("Unable to fill charts data right now:", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private void populate_charts_data() {
|
protected RefreshTask createRefreshTask(String task, Context context) {
|
||||||
new Thread(new Runnable() {
|
return new RefreshTask(task, context);
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
try (DBHandler handler = GBApplication.acquireDB()) {
|
|
||||||
List<? extends BatteryLevel> samples = getBatteryLevels(handler, gbDevice, startTime, endTime);
|
|
||||||
DefaultBatteryChartsData dcd = null;
|
|
||||||
try {
|
|
||||||
dcd = fill_dcd(samples);
|
|
||||||
} catch (Exception e) {
|
|
||||||
LOG.debug("Unable to get charts data right now:", e);
|
|
||||||
}
|
|
||||||
if (dcd != null && mChart != null) {
|
|
||||||
mChart.setTouchEnabled(true);
|
|
||||||
mChart.setMarker(new batteryValuesAndDateMarker(getContext(), R.layout.custom_chart_marker, dcd.firstTs));
|
|
||||||
mChart.getXAxis().setValueFormatter(dcd.getXValueFormatter());
|
|
||||||
mChart.setData((LineData) dcd.getData());
|
|
||||||
mChart.invalidate();
|
|
||||||
}
|
|
||||||
} catch (Exception e) {
|
|
||||||
LOG.error("Unable to get charts data:", e);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
}).start();
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private DefaultBatteryChartsData fill_dcd(List<? extends BatteryLevel> samples) {
|
private DefaultBatteryChartsData fill_dcd(List<? extends BatteryLevel> samples) {
|
||||||
@ -149,7 +126,6 @@ public class BatteryInfoChartFragment extends AbstractGBFragment {
|
|||||||
BATTERY_LABEL = getString(R.string.battery_level);
|
BATTERY_LABEL = getString(R.string.battery_level);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
||||||
Bundle savedInstanceState) {
|
Bundle savedInstanceState) {
|
||||||
@ -158,7 +134,7 @@ public class BatteryInfoChartFragment extends AbstractGBFragment {
|
|||||||
mChart = rootView.findViewById(R.id.activitysleepchart);
|
mChart = rootView.findViewById(R.id.activitysleepchart);
|
||||||
if (this.gbDevice != null) {
|
if (this.gbDevice != null) {
|
||||||
setupChart();
|
setupChart();
|
||||||
populate_charts_data();
|
createRefreshTask("Visualizing data", getActivity()).execute();
|
||||||
}
|
}
|
||||||
return rootView;
|
return rootView;
|
||||||
}
|
}
|
||||||
@ -231,6 +207,35 @@ public class BatteryInfoChartFragment extends AbstractGBFragment {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public class RefreshTask extends DBAccess {
|
||||||
|
|
||||||
|
public RefreshTask(String task, Context context) {
|
||||||
|
super(task, context);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void doInBackground(DBHandler handler) {
|
||||||
|
List<? extends BatteryLevel> samples = getBatteryLevels(handler, gbDevice, startTime, endTime);
|
||||||
|
DefaultBatteryChartsData dcd = null;
|
||||||
|
try {
|
||||||
|
dcd = fill_dcd(samples);
|
||||||
|
} catch (Exception e) {
|
||||||
|
LOG.debug("Unable to get charts data right now:", e);
|
||||||
|
}
|
||||||
|
if (dcd != null && mChart != null) {
|
||||||
|
mChart.setTouchEnabled(true);
|
||||||
|
mChart.setMarker(new batteryValuesAndDateMarker(getContext(), R.layout.custom_chart_marker, dcd.firstTs));
|
||||||
|
mChart.getXAxis().setValueFormatter(dcd.getXValueFormatter());
|
||||||
|
mChart.setData((LineData) dcd.getData());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onPostExecute(Object o) {
|
||||||
|
mChart.invalidate();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private class DefaultBatteryChartsData extends AbstractChartFragment.DefaultChartsData {
|
private class DefaultBatteryChartsData extends AbstractChartFragment.DefaultChartsData {
|
||||||
public int firstTs;
|
public int firstTs;
|
||||||
|
|
||||||
|
@ -661,11 +661,6 @@ public abstract class AbstractChartFragment extends AbstractGBFragment {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void onPreExecute() {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onPostExecute(Object o) {
|
protected void onPostExecute(Object o) {
|
||||||
super.onPostExecute(o);
|
super.onPostExecute(o);
|
||||||
|
@ -38,7 +38,7 @@ import nodomain.freeyourgadget.gadgetbridge.util.DateTimeUtils;
|
|||||||
import nodomain.freeyourgadget.gadgetbridge.util.DeviceHelper;
|
import nodomain.freeyourgadget.gadgetbridge.util.DeviceHelper;
|
||||||
|
|
||||||
public class ActivityListingDashboard extends DialogFragment {
|
public class ActivityListingDashboard extends DialogFragment {
|
||||||
protected static final Logger LOG = LoggerFactory.getLogger(AbstractWeekChartFragment.class);
|
protected static final Logger LOG = LoggerFactory.getLogger(ActivityListingDashboard.class);
|
||||||
GBDevice gbDevice;
|
GBDevice gbDevice;
|
||||||
ActivityListingAdapter stepListAdapter;
|
ActivityListingAdapter stepListAdapter;
|
||||||
ActivitySession stepSessionsSummary;
|
ActivitySession stepSessionsSummary;
|
||||||
|
@ -39,7 +39,6 @@ public abstract class DBAccess extends AsyncTask {
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected abstract void doInBackground(DBHandler handler);
|
protected abstract void doInBackground(DBHandler handler);
|
||||||
protected abstract void onPreExecute();
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected Object doInBackground(Object[] params) {
|
protected Object doInBackground(Object[] params) {
|
||||||
|
Loading…
Reference in New Issue
Block a user