mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge
synced 2024-07-23 07:11:52 +02:00
Also support pulldown to sync in ControlCenter #138
Should factor out some common code between ChartsActivity and ControlCenter, though.
This commit is contained in:
parent
1e56e540fa
commit
b43e96318a
|
@ -13,6 +13,7 @@ import android.content.SharedPreferences;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.preference.PreferenceManager;
|
import android.preference.PreferenceManager;
|
||||||
import android.support.v4.content.LocalBroadcastManager;
|
import android.support.v4.content.LocalBroadcastManager;
|
||||||
|
import android.support.v4.widget.SwipeRefreshLayout;
|
||||||
import android.view.ContextMenu;
|
import android.view.ContextMenu;
|
||||||
import android.view.Menu;
|
import android.view.Menu;
|
||||||
import android.view.MenuItem;
|
import android.view.MenuItem;
|
||||||
|
@ -53,6 +54,7 @@ public class ControlCenter extends Activity {
|
||||||
|
|
||||||
private TextView hintTextView;
|
private TextView hintTextView;
|
||||||
private ListView deviceListView;
|
private ListView deviceListView;
|
||||||
|
private SwipeRefreshLayout swipeLayout;
|
||||||
private GBDeviceAdapter mGBDeviceAdapter;
|
private GBDeviceAdapter mGBDeviceAdapter;
|
||||||
private GBDevice selectedDevice = null;
|
private GBDevice selectedDevice = null;
|
||||||
|
|
||||||
|
@ -80,15 +82,41 @@ public class ControlCenter extends Activity {
|
||||||
deviceList.add(dev);
|
deviceList.add(dev);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
updateSelectedDevice(dev);
|
||||||
refreshPairedDevices();
|
refreshPairedDevices();
|
||||||
|
|
||||||
refreshBusyState(dev);
|
refreshBusyState(dev);
|
||||||
|
enableSwipeRefresh(selectedDevice);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
private void updateSelectedDevice(GBDevice dev) {
|
||||||
|
if (selectedDevice == null) {
|
||||||
|
selectedDevice = dev;
|
||||||
|
} else {
|
||||||
|
if (!selectedDevice.equals(dev)) {
|
||||||
|
if (selectedDevice.isConnected() && dev.isConnected()) {
|
||||||
|
LOG.warn("multiple connected devices -- this is currently not really supported");
|
||||||
|
selectedDevice = dev; // use the last one that changed
|
||||||
|
}
|
||||||
|
if (!selectedDevice.isConnected()) {
|
||||||
|
selectedDevice = dev; // use the last one that changed
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void refreshBusyState(GBDevice dev) {
|
private void refreshBusyState(GBDevice dev) {
|
||||||
|
if (dev.isBusy()) {
|
||||||
|
swipeLayout.setRefreshing(true);
|
||||||
|
} else {
|
||||||
|
boolean wasBusy = swipeLayout.isRefreshing();
|
||||||
|
if (wasBusy) {
|
||||||
|
swipeLayout.setRefreshing(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
mGBDeviceAdapter.notifyDataSetChanged();
|
mGBDeviceAdapter.notifyDataSetChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -118,6 +146,14 @@ public class ControlCenter extends Activity {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
swipeLayout = (SwipeRefreshLayout) findViewById(R.id.controlcenter_swipe_layout);
|
||||||
|
swipeLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
|
||||||
|
@Override
|
||||||
|
public void onRefresh() {
|
||||||
|
fetchActivityData();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
registerForContextMenu(deviceListView);
|
registerForContextMenu(deviceListView);
|
||||||
|
|
||||||
IntentFilter filterLocal = new IntentFilter();
|
IntentFilter filterLocal = new IntentFilter();
|
||||||
|
@ -141,7 +177,7 @@ public class ControlCenter extends Activity {
|
||||||
}
|
}
|
||||||
GBApplication.deviceService().start();
|
GBApplication.deviceService().start();
|
||||||
|
|
||||||
|
enableSwipeRefresh(selectedDevice);
|
||||||
if (GB.isBluetoothEnabled() && deviceList.isEmpty()) {
|
if (GB.isBluetoothEnabled() && deviceList.isEmpty()) {
|
||||||
// start discovery when no devices are present
|
// start discovery when no devices are present
|
||||||
startActivity(new Intent(this, DiscoveryActivity.class));
|
startActivity(new Intent(this, DiscoveryActivity.class));
|
||||||
|
@ -180,6 +216,23 @@ public class ControlCenter extends Activity {
|
||||||
menu.setHeaderTitle(selectedDevice.getName());
|
menu.setHeaderTitle(selectedDevice.getName());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void enableSwipeRefresh(GBDevice device) {
|
||||||
|
boolean enable = device != null && device.isInitialized() && !device.isBusy();
|
||||||
|
swipeLayout.setEnabled(enable);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void fetchActivityData() {
|
||||||
|
if (selectedDevice == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (selectedDevice.isInitialized()) {
|
||||||
|
GBApplication.deviceService().onFetchActivityData();
|
||||||
|
} else {
|
||||||
|
swipeLayout.setRefreshing(false);
|
||||||
|
GB.toast(this, getString(R.string.device_not_connected), Toast.LENGTH_SHORT, GB.ERROR);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onContextItemSelected(MenuItem item) {
|
public boolean onContextItemSelected(MenuItem item) {
|
||||||
switch (item.getItemId()) {
|
switch (item.getItemId()) {
|
||||||
|
@ -192,9 +245,7 @@ public class ControlCenter extends Activity {
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
case R.id.controlcenter_fetch_activity_data:
|
case R.id.controlcenter_fetch_activity_data:
|
||||||
if (selectedDevice != null) {
|
fetchActivityData();
|
||||||
GBApplication.deviceService().onFetchActivityData();
|
|
||||||
}
|
|
||||||
return true;
|
return true;
|
||||||
case R.id.controlcenter_disconnect:
|
case R.id.controlcenter_disconnect:
|
||||||
if (selectedDevice != null) {
|
if (selectedDevice != null) {
|
||||||
|
|
|
@ -6,6 +6,15 @@
|
||||||
android:paddingBottom="@dimen/activity_vertical_margin"
|
android:paddingBottom="@dimen/activity_vertical_margin"
|
||||||
tools:context="nodomain.freeyourgadget.gadgetbridge.activities.ControlCenter">
|
tools:context="nodomain.freeyourgadget.gadgetbridge.activities.ControlCenter">
|
||||||
|
|
||||||
|
<android.support.v4.widget.SwipeRefreshLayout
|
||||||
|
android:id="@+id/controlcenter_swipe_layout"
|
||||||
|
android:paddingLeft="0px"
|
||||||
|
android:paddingRight="0px"
|
||||||
|
android:paddingTop="0px"
|
||||||
|
android:paddingBottom="0px"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent">
|
||||||
|
|
||||||
<ListView
|
<ListView
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
|
@ -13,6 +22,7 @@
|
||||||
android:layout_alignParentTop="true"
|
android:layout_alignParentTop="true"
|
||||||
android:layout_centerHorizontal="true"
|
android:layout_centerHorizontal="true"
|
||||||
android:layout_above="@+id/hintTextView" />
|
android:layout_above="@+id/hintTextView" />
|
||||||
|
</android.support.v4.widget.SwipeRefreshLayout>
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
|
|
Loading…
Reference in New Issue
Block a user