mirror of
https://github.com/KDE/kdeconnect-android
synced 2025-08-31 14:15:14 +00:00
Accept or reject pair requests from the notification
This commit is contained in:
committed by
Albert Vaca
parent
1179807bcf
commit
89ecdfc363
@@ -84,6 +84,13 @@ public class DeviceFragment extends Fragment {
|
||||
this.setArguments(args);
|
||||
}
|
||||
|
||||
public DeviceFragment(String deviceId, MaterialActivity activity){
|
||||
this.mActivity = activity;
|
||||
Bundle args = new Bundle();
|
||||
args.putString(ARG_DEVICE_ID, deviceId);
|
||||
this.setArguments(args);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAttach(Activity activity) {
|
||||
super.onAttach(activity);
|
||||
@@ -183,7 +190,6 @@ public class DeviceFragment extends Fragment {
|
||||
return rootView;
|
||||
}
|
||||
|
||||
|
||||
private final Device.PluginsChangedListener pluginsChangedListener = new Device.PluginsChangedListener() {
|
||||
@Override
|
||||
public void onPluginsChanged(final Device device) {
|
||||
@@ -460,4 +466,54 @@ public class DeviceFragment extends Fragment {
|
||||
|
||||
};
|
||||
|
||||
public static void acceptPairing(final String devId, final MaterialActivity activity){
|
||||
final DeviceFragment frag = new DeviceFragment(devId, activity);
|
||||
BackgroundService.RunCommand(activity, new BackgroundService.InstanceCallback() {
|
||||
public void onServiceStart(BackgroundService service) {
|
||||
Device dev = service.getDevice(devId);
|
||||
activity.getSupportActionBar().setTitle(dev.getName());
|
||||
|
||||
dev.addPairingCallback(frag.pairingCallback);
|
||||
dev.addPluginsChangedListener(frag.pluginsChangedListener);
|
||||
|
||||
frag.refreshUI();
|
||||
|
||||
frag.device = dev;
|
||||
}
|
||||
});
|
||||
|
||||
BackgroundService.RunCommand(activity, new BackgroundService.InstanceCallback() {
|
||||
@Override
|
||||
public void onServiceStart(BackgroundService service) {
|
||||
frag.device.acceptPairing();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public static void rejectPairing(final String devId, final MaterialActivity activity){
|
||||
final DeviceFragment frag = new DeviceFragment(devId, activity);
|
||||
BackgroundService.RunCommand(activity, new BackgroundService.InstanceCallback() {
|
||||
public void onServiceStart(BackgroundService service) {
|
||||
Device dev = service.getDevice(devId);
|
||||
activity.getSupportActionBar().setTitle(dev.getName());
|
||||
|
||||
dev.addPairingCallback(frag.pairingCallback);
|
||||
dev.addPluginsChangedListener(frag.pluginsChangedListener);
|
||||
|
||||
frag.refreshUI();
|
||||
|
||||
frag.device = dev;
|
||||
}
|
||||
});
|
||||
BackgroundService.RunCommand(activity, new BackgroundService.InstanceCallback() {
|
||||
@Override
|
||||
public void onServiceStart(BackgroundService service) {
|
||||
//Remove listener so buttons don't show for a while before changing the view
|
||||
frag.device.removePluginsChangedListener(frag.pluginsChangedListener);
|
||||
frag.device.removePairingCallback(frag.pairingCallback);
|
||||
frag.device.rejectPairing();
|
||||
activity.onDeviceSelected(null);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user