1
0
mirror of https://codeberg.org/Freeyourgadget/Gadgetbridge synced 2024-11-29 13:26:50 +01:00

Battery info - use Gb DBAccess

This commit is contained in:
vanous 2021-03-04 17:59:51 +01:00
parent 0f5f036057
commit 6aeb297aa5
5 changed files with 36 additions and 36 deletions

View File

@ -69,6 +69,7 @@ public class BatteryInfoActivity extends AbstractGBActivity {
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() {
@Override

View File

@ -53,6 +53,7 @@ import de.greenrobot.dao.query.QueryBuilder;
import nodomain.freeyourgadget.gadgetbridge.GBApplication;
import nodomain.freeyourgadget.gadgetbridge.R;
import nodomain.freeyourgadget.gadgetbridge.activities.charts.AbstractChartFragment;
import nodomain.freeyourgadget.gadgetbridge.database.DBAccess;
import nodomain.freeyourgadget.gadgetbridge.database.DBHandler;
import nodomain.freeyourgadget.gadgetbridge.database.DBHelper;
import nodomain.freeyourgadget.gadgetbridge.entities.BatteryLevel;
@ -79,39 +80,15 @@ public class BatteryInfoChartFragment extends AbstractGBFragment {
this.endTime = (int) endTime;
this.gbDevice = gbDevice;
try {
populate_charts_data();
createRefreshTask("Visualizing data", getActivity()).execute();
} catch (Exception e) {
LOG.debug("Unable to fill charts data right now:", e);
}
}
private void populate_charts_data() {
new Thread(new Runnable() {
@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();
protected RefreshTask createRefreshTask(String task, Context context) {
return new RefreshTask(task, context);
}
private DefaultBatteryChartsData fill_dcd(List<? extends BatteryLevel> samples) {
@ -149,7 +126,6 @@ public class BatteryInfoChartFragment extends AbstractGBFragment {
BATTERY_LABEL = getString(R.string.battery_level);
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
@ -158,7 +134,7 @@ public class BatteryInfoChartFragment extends AbstractGBFragment {
mChart = rootView.findViewById(R.id.activitysleepchart);
if (this.gbDevice != null) {
setupChart();
populate_charts_data();
createRefreshTask("Visualizing data", getActivity()).execute();
}
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 {
public int firstTs;

View File

@ -661,11 +661,6 @@ public abstract class AbstractChartFragment extends AbstractGBFragment {
}
}
@Override
protected void onPreExecute() {
}
@Override
protected void onPostExecute(Object o) {
super.onPostExecute(o);

View File

@ -38,7 +38,7 @@ import nodomain.freeyourgadget.gadgetbridge.util.DateTimeUtils;
import nodomain.freeyourgadget.gadgetbridge.util.DeviceHelper;
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;
ActivityListingAdapter stepListAdapter;
ActivitySession stepSessionsSummary;

View File

@ -39,7 +39,6 @@ public abstract class DBAccess extends AsyncTask {
}
protected abstract void doInBackground(DBHandler handler);
protected abstract void onPreExecute();
@Override
protected Object doInBackground(Object[] params) {