mirror of
https://github.com/KDE/kdeconnect-android
synced 2025-08-22 18:07:55 +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<>();
|
||||
|
||||
public void acquireDiscoveryMode(Object key) {
|
||||
public boolean acquireDiscoveryMode(Object key) {
|
||||
boolean wasEmpty = discoveryModeAcquisitions.isEmpty();
|
||||
discoveryModeAcquisitions.add(key);
|
||||
if (wasEmpty) {
|
||||
onNetworkChange();
|
||||
}
|
||||
return wasEmpty;
|
||||
}
|
||||
|
||||
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() {
|
||||
@Override
|
||||
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
|
||||
protected void 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
|
||||
protected void onStop() {
|
||||
BackgroundService.removeGuiInUseCounter(this);
|
||||
BackgroundService.RunCommand(this, new BackgroundService.InstanceCallback() {
|
||||
@Override
|
||||
public void onServiceStart(BackgroundService service) {
|
||||
service.removeDeviceListChangedCallback("MaterialActivity");
|
||||
}
|
||||
});
|
||||
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
|
||||
//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)
|
||||
|
@ -98,9 +98,10 @@ public class PairingFragment extends Fragment implements PairingDeviceItem.Callb
|
||||
public void run() {
|
||||
|
||||
if (listRefreshCalledThisFrame) {
|
||||
return; // This makes sure we don't try to call list.getFirstVisiblePosition()
|
||||
// twice per frame, because the second time the list hasn't been drawn
|
||||
// yet and it would always return 0.
|
||||
// This makes sure we don't try to call list.getFirstVisiblePosition()
|
||||
// twice per frame, because the second time the list hasn't been drawn
|
||||
// yet and it would always return 0.
|
||||
return;
|
||||
}
|
||||
listRefreshCalledThisFrame = true;
|
||||
|
||||
@ -183,9 +184,9 @@ public class PairingFragment extends Fragment implements PairingDeviceItem.Callb
|
||||
updateComputerList();
|
||||
}
|
||||
});
|
||||
service.onNetworkChange();
|
||||
}
|
||||
});
|
||||
updateComputerList();
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -199,12 +200,6 @@ public class PairingFragment extends Fragment implements PairingDeviceItem.Callb
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResume() {
|
||||
super.onResume();
|
||||
updateComputerList();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void pairingClicked(Device device) {
|
||||
mActivity.onDeviceSelected(device.getDeviceId(), !device.isPaired() || !device.isReachable());
|
||||
|
Loading…
x
Reference in New Issue
Block a user