mirror of
https://github.com/KDE/kdeconnect-android
synced 2025-08-23 10:27:57 +00:00
Fixed drawer's updateComputerList not being called when there were changes
Plus removed some unnecessary calls in other places.
This commit is contained in:
parent
a6e22f57f3
commit
b1ef93a90c
@ -61,12 +61,13 @@ public class BackgroundService extends Service {
|
|||||||
|
|
||||||
private final HashSet<Object> discoveryModeAcquisitions = new HashSet<>();
|
private final HashSet<Object> discoveryModeAcquisitions = new HashSet<>();
|
||||||
|
|
||||||
public void acquireDiscoveryMode(Object key) {
|
public boolean acquireDiscoveryMode(Object key) {
|
||||||
boolean wasEmpty = discoveryModeAcquisitions.isEmpty();
|
boolean wasEmpty = discoveryModeAcquisitions.isEmpty();
|
||||||
discoveryModeAcquisitions.add(key);
|
discoveryModeAcquisitions.add(key);
|
||||||
if (wasEmpty) {
|
if (wasEmpty) {
|
||||||
onNetworkChange();
|
onNetworkChange();
|
||||||
}
|
}
|
||||||
|
return wasEmpty;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void releaseDiscoveryMode(Object key) {
|
public void releaseDiscoveryMode(Object key) {
|
||||||
@ -76,11 +77,18 @@ public class BackgroundService extends Service {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void addGuiInUseCounter(final Activity activity) {
|
public static void addGuiInUseCounter(Activity activity) {
|
||||||
|
addGuiInUseCounter(activity, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void addGuiInUseCounter(final Activity activity, final boolean forceNetworkRefresh) {
|
||||||
BackgroundService.RunCommand(activity, new BackgroundService.InstanceCallback() {
|
BackgroundService.RunCommand(activity, new BackgroundService.InstanceCallback() {
|
||||||
@Override
|
@Override
|
||||||
public void onServiceStart(BackgroundService service) {
|
public void onServiceStart(BackgroundService service) {
|
||||||
service.acquireDiscoveryMode(activity);
|
boolean refreshed = service.acquireDiscoveryMode(activity);
|
||||||
|
if (!refreshed && forceNetworkRefresh) {
|
||||||
|
service.onNetworkChange();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -159,21 +159,33 @@ public class MaterialActivity extends AppCompatActivity {
|
|||||||
@Override
|
@Override
|
||||||
protected void onStart() {
|
protected void onStart() {
|
||||||
super.onStart();
|
super.onStart();
|
||||||
BackgroundService.addGuiInUseCounter(this);
|
BackgroundService.addGuiInUseCounter(this, true);
|
||||||
|
BackgroundService.RunCommand(this, new BackgroundService.InstanceCallback() {
|
||||||
|
@Override
|
||||||
|
public void onServiceStart(BackgroundService service) {
|
||||||
|
service.addDeviceListChangedCallback("MaterialActivity", new BackgroundService.DeviceListChangedCallback() {
|
||||||
|
@Override
|
||||||
|
public void onDeviceListChanged() {
|
||||||
|
updateComputerList();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
updateComputerList();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onStop() {
|
protected void onStop() {
|
||||||
BackgroundService.removeGuiInUseCounter(this);
|
BackgroundService.removeGuiInUseCounter(this);
|
||||||
|
BackgroundService.RunCommand(this, new BackgroundService.InstanceCallback() {
|
||||||
|
@Override
|
||||||
|
public void onServiceStart(BackgroundService service) {
|
||||||
|
service.removeDeviceListChangedCallback("MaterialActivity");
|
||||||
|
}
|
||||||
|
});
|
||||||
super.onStop();
|
super.onStop();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void onResume() {
|
|
||||||
super.onResume();
|
|
||||||
updateComputerList();
|
|
||||||
}
|
|
||||||
|
|
||||||
//TODO: Make it accept two parameters, a constant with the type of screen and the device id in
|
//TODO: Make it accept two parameters, a constant with the type of screen and the device id in
|
||||||
//case the screen is for a device, or even three parameters and the third one be the plugin id?
|
//case the screen is for a device, or even three parameters and the third one be the plugin id?
|
||||||
//This way we can keep adding more options with null plugin id (eg: about)
|
//This way we can keep adding more options with null plugin id (eg: about)
|
||||||
|
@ -98,9 +98,10 @@ public class PairingFragment extends Fragment implements PairingDeviceItem.Callb
|
|||||||
public void run() {
|
public void run() {
|
||||||
|
|
||||||
if (listRefreshCalledThisFrame) {
|
if (listRefreshCalledThisFrame) {
|
||||||
return; // This makes sure we don't try to call list.getFirstVisiblePosition()
|
// This makes sure we don't try to call list.getFirstVisiblePosition()
|
||||||
// twice per frame, because the second time the list hasn't been drawn
|
// twice per frame, because the second time the list hasn't been drawn
|
||||||
// yet and it would always return 0.
|
// yet and it would always return 0.
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
listRefreshCalledThisFrame = true;
|
listRefreshCalledThisFrame = true;
|
||||||
|
|
||||||
@ -183,9 +184,9 @@ public class PairingFragment extends Fragment implements PairingDeviceItem.Callb
|
|||||||
updateComputerList();
|
updateComputerList();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
service.onNetworkChange();
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
updateComputerList();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -199,12 +200,6 @@ public class PairingFragment extends Fragment implements PairingDeviceItem.Callb
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onResume() {
|
|
||||||
super.onResume();
|
|
||||||
updateComputerList();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void pairingClicked(Device device) {
|
public void pairingClicked(Device device) {
|
||||||
mActivity.onDeviceSelected(device.getDeviceId(), !device.isPaired() || !device.isReachable());
|
mActivity.onDeviceSelected(device.getDeviceId(), !device.isPaired() || !device.isReachable());
|
||||||
|
Loading…
x
Reference in New Issue
Block a user