diff --git a/src/org/kde/kdeconnect/UserInterface/DeviceFragment.java b/src/org/kde/kdeconnect/UserInterface/DeviceFragment.java --- a/src/org/kde/kdeconnect/UserInterface/DeviceFragment.java +++ b/src/org/kde/kdeconnect/UserInterface/DeviceFragment.java @@ -361,52 +361,6 @@ }; - public static void acceptPairing(final String devId, final MainActivity activity) { - final DeviceFragment frag = new DeviceFragment(devId, activity); - BackgroundService.RunCommand(activity, service -> { - Device dev = service.getDevice(devId); - if (dev == null) { - Log.w("rejectPairing", "Device no longer exists: " + devId); - return; - } - activity.getSupportActionBar().setTitle(dev.getName()); - - dev.addPairingCallback(frag.pairingCallback); - dev.addPluginsChangedListener(frag.pluginsChangedListener); - - frag.device = dev; - frag.device.acceptPairing(); - - frag.refreshUI(); - - }); - } - - public static void rejectPairing(final String devId, final MainActivity activity) { - final DeviceFragment frag = new DeviceFragment(devId, activity); - BackgroundService.RunCommand(activity, service -> { - Device dev = service.getDevice(devId); - if (dev == null) { - Log.w("rejectPairing", "Device no longer exists: " + devId); - return; - } - activity.getSupportActionBar().setTitle(dev.getName()); - - dev.addPairingCallback(frag.pairingCallback); - dev.addPluginsChangedListener(frag.pluginsChangedListener); - - frag.device = dev; - - //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); - - frag.refreshUI(); - }); - } - private void createPluginsList(ConcurrentHashMap plugins, int headerText, FailedPluginListItem.Action action) { if (!plugins.isEmpty()) { diff --git a/src/org/kde/kdeconnect/UserInterface/MainActivity.java b/src/org/kde/kdeconnect/UserInterface/MainActivity.java --- a/src/org/kde/kdeconnect/UserInterface/MainActivity.java +++ b/src/org/kde/kdeconnect/UserInterface/MainActivity.java @@ -136,7 +136,10 @@ String pairStatus = getIntent().getStringExtra(PAIR_REQUEST_STATUS); if (pairStatus != null) { Log.i("MainActivity", "pair status is " + pairStatus); - onPairResultFromNotification(savedDevice, pairStatus); + savedDevice = onPairResultFromNotification(savedDevice, pairStatus); + if (savedDevice == null) { + savedMenuEntry = MENU_ENTRY_ADD_DEVICE; + } } } else if (savedInstanceState != null) { Log.i("MainActivity", "Loading selected device from saved activity state"); @@ -164,22 +167,27 @@ } } - - private void onPairResultFromNotification(String deviceId, String pairStatus) { - + private String onPairResultFromNotification(String deviceId, String pairStatus) { assert(deviceId != null); - mCurrentDevice = deviceId; - - preferences.edit().putString(STATE_SELECTED_DEVICE, null).apply(); + BackgroundService.RunCommand(this, service -> { + Device device = service.getDevice(deviceId); + if (device == null) { + Log.w("rejectPairing", "Device no longer exists: " + deviceId); + return; + } - mCurrentMenuEntry = deviceIdToMenuEntryId(mCurrentDevice); - mNavigationView.setCheckedItem(mCurrentMenuEntry); + if (pairStatus.equals(PAIRING_ACCEPTED)) { + device.acceptPairing(); + } else { + device.rejectPairing(); + } + }); if (pairStatus.equals(PAIRING_ACCEPTED)) { - DeviceFragment.acceptPairing(mCurrentDevice, this); + return deviceId; } else { - DeviceFragment.rejectPairing(mCurrentDevice, this); + return null; } }