mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge.git
synced 2025-02-05 05:24:12 +01:00
multi-device: added MDS to widget
This commit is contained in:
parent
d37c832c1b
commit
4d12128484
@ -100,7 +100,7 @@ public class Widget extends AppWidgetProvider {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private long[] getSteps() {
|
private long[] getSteps(int appWidgetId) {
|
||||||
Context context = GBApplication.getContext();
|
Context context = GBApplication.getContext();
|
||||||
Calendar day = GregorianCalendar.getInstance();
|
Calendar day = GregorianCalendar.getInstance();
|
||||||
|
|
||||||
@ -108,8 +108,20 @@ public class Widget extends AppWidgetProvider {
|
|||||||
return new long[]{0, 0, 0};
|
return new long[]{0, 0, 0};
|
||||||
}
|
}
|
||||||
DailyTotals ds = new DailyTotals();
|
DailyTotals ds = new DailyTotals();
|
||||||
// TODO: handle multiple
|
|
||||||
GBDevice selectedDevice = selectedDevices.get(0);
|
WidgetPreferenceStorage widgetPreferenceStorage = new WidgetPreferenceStorage();
|
||||||
|
String savedDeviceAddress = widgetPreferenceStorage.getSavedDeviceAddress(context, appWidgetId);
|
||||||
|
if (savedDeviceAddress == null) {
|
||||||
|
GB.toast("no device configured", Toast.LENGTH_SHORT, GB.ERROR);
|
||||||
|
return new long[]{0, 0, 0};
|
||||||
|
}
|
||||||
|
GBDevice selectedDevice = getDeviceByMAC(context.getApplicationContext(), savedDeviceAddress);
|
||||||
|
|
||||||
|
if (selectedDevice == null || !selectedDevice.isInitialized()) {
|
||||||
|
GB.toast(context.getString(R.string.device_not_connected), Toast.LENGTH_SHORT, GB.ERROR);
|
||||||
|
return new long[]{0, 0, 0};
|
||||||
|
}
|
||||||
|
|
||||||
return ds.getDailyTotalsForDevice(selectedDevice, day);
|
return ds.getDailyTotalsForDevice(selectedDevice, day);
|
||||||
//return ds.getDailyTotalsForAllDevices(day);
|
//return ds.getDailyTotalsForAllDevices(day);
|
||||||
}
|
}
|
||||||
@ -122,13 +134,21 @@ public class Widget extends AppWidgetProvider {
|
|||||||
int appWidgetId) {
|
int appWidgetId) {
|
||||||
|
|
||||||
selectedDevices = getSelectedDevices();
|
selectedDevices = getSelectedDevices();
|
||||||
// TODO: handle multiple devices
|
GBDevice selectedDevice = null;
|
||||||
GBDevice selectedDevice = selectedDevices.get(0);
|
if(selectedDevices.size() > 0){
|
||||||
|
selectedDevice = selectedDevices.get(0);
|
||||||
|
}
|
||||||
WidgetPreferenceStorage widgetPreferenceStorage = new WidgetPreferenceStorage();
|
WidgetPreferenceStorage widgetPreferenceStorage = new WidgetPreferenceStorage();
|
||||||
String savedDeviceAddress = widgetPreferenceStorage.getSavedDeviceAddress(context, appWidgetId);
|
String savedDeviceAddress = widgetPreferenceStorage.getSavedDeviceAddress(context, appWidgetId);
|
||||||
if (savedDeviceAddress != null) {
|
if (savedDeviceAddress != null) {
|
||||||
// TODO: handle or delete this
|
selectedDevice = getDeviceByMAC(context.getApplicationContext(), savedDeviceAddress);
|
||||||
// selectedDevice = getDeviceByMAC(context.getApplicationContext(), savedDeviceAddress); //this would probably only happen if device no longer exists in GB
|
}
|
||||||
|
|
||||||
|
if (selectedDevice == null || !selectedDevice.isInitialized()) {
|
||||||
|
GB.toast(context,
|
||||||
|
context.getString(R.string.device_not_connected),
|
||||||
|
Toast.LENGTH_SHORT, GB.ERROR);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.widget);
|
RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.widget);
|
||||||
@ -158,7 +178,7 @@ public class Widget extends AppWidgetProvider {
|
|||||||
PendingIntent startChartsPIntent = PendingIntent.getActivity(context, appWidgetId, startChartsIntent, PendingIntent.FLAG_CANCEL_CURRENT);
|
PendingIntent startChartsPIntent = PendingIntent.getActivity(context, appWidgetId, startChartsIntent, PendingIntent.FLAG_CANCEL_CURRENT);
|
||||||
views.setOnClickPendingIntent(R.id.todaywidget_bottom_layout, startChartsPIntent);
|
views.setOnClickPendingIntent(R.id.todaywidget_bottom_layout, startChartsPIntent);
|
||||||
|
|
||||||
long[] dailyTotals = getSteps();
|
long[] dailyTotals = getSteps(appWidgetId);
|
||||||
int steps = (int) dailyTotals[0];
|
int steps = (int) dailyTotals[0];
|
||||||
int sleep = (int) dailyTotals[1];
|
int sleep = (int) dailyTotals[1];
|
||||||
ActivityUser activityUser = new ActivityUser();
|
ActivityUser activityUser = new ActivityUser();
|
||||||
@ -214,11 +234,19 @@ public class Widget extends AppWidgetProvider {
|
|||||||
appWidgetManager.updateAppWidget(appWidgetId, views);
|
appWidgetManager.updateAppWidget(appWidgetId, views);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void refreshData() {
|
public void refreshData(int appWidgetId) {
|
||||||
Context context = GBApplication.getContext();
|
Context context = GBApplication.getContext();
|
||||||
List<GBDevice> devices = getSelectedDevices();
|
|
||||||
// TODO: handle multiple
|
GBDevice device = null;
|
||||||
GBDevice device = devices.get(0);
|
if(selectedDevices.size() > 0){
|
||||||
|
device = selectedDevices.get(0); // fallback
|
||||||
|
}
|
||||||
|
WidgetPreferenceStorage widgetPreferenceStorage = new WidgetPreferenceStorage();
|
||||||
|
String savedDeviceAddress = widgetPreferenceStorage.getSavedDeviceAddress(context, appWidgetId);
|
||||||
|
if (savedDeviceAddress != null) {
|
||||||
|
device = getDeviceByMAC(context.getApplicationContext(), savedDeviceAddress);
|
||||||
|
}
|
||||||
|
|
||||||
if (device == null || !device.isInitialized()) {
|
if (device == null || !device.isInitialized()) {
|
||||||
GB.toast(context,
|
GB.toast(context,
|
||||||
context.getString(R.string.device_not_connected),
|
context.getString(R.string.device_not_connected),
|
||||||
@ -289,19 +317,24 @@ public class Widget extends AppWidgetProvider {
|
|||||||
super.onReceive(context, intent);
|
super.onReceive(context, intent);
|
||||||
LOG.debug("gbwidget LOCAL onReceive, action: " + intent.getAction() + intent);
|
LOG.debug("gbwidget LOCAL onReceive, action: " + intent.getAction() + intent);
|
||||||
Bundle extras = intent.getExtras();
|
Bundle extras = intent.getExtras();
|
||||||
int appWidgetId = -1;
|
int appWidgetId = AppWidgetManager.INVALID_APPWIDGET_ID;
|
||||||
if (extras != null) {
|
if (extras != null) {
|
||||||
appWidgetId = extras.getInt(
|
appWidgetId = extras.getInt(
|
||||||
AppWidgetManager.EXTRA_APPWIDGET_ID,
|
AppWidgetManager.EXTRA_APPWIDGET_ID,
|
||||||
AppWidgetManager.INVALID_APPWIDGET_ID);
|
AppWidgetManager.INVALID_APPWIDGET_ID);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(appWidgetId == AppWidgetManager.INVALID_APPWIDGET_ID){
|
||||||
|
GB.toast("invalid widget id", Toast.LENGTH_LONG, GB.ERROR);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
//this handles widget re-connection after apk updates
|
//this handles widget re-connection after apk updates
|
||||||
if (WIDGET_CLICK.equals(intent.getAction())) {
|
if (WIDGET_CLICK.equals(intent.getAction())) {
|
||||||
if (broadcastReceiver == null) {
|
if (broadcastReceiver == null) {
|
||||||
onEnabled(context);
|
onEnabled(context);
|
||||||
}
|
}
|
||||||
refreshData();
|
refreshData(appWidgetId);
|
||||||
//updateWidget();
|
//updateWidget();
|
||||||
} else if (APPWIDGET_DELETED.equals(intent.getAction())) {
|
} else if (APPWIDGET_DELETED.equals(intent.getAction())) {
|
||||||
onDisabled(context);
|
onDisabled(context);
|
||||||
|
Loading…
Reference in New Issue
Block a user