mirror of
https://github.com/KDE/kdeconnect-android
synced 2025-10-17 14:19:33 +00:00
Simplify pairing from notification
Summary: When a pairing is accepted or rejected through notification actions a new DeviceFragment was created but this fragment was never actually attached to the fragment manager so not displayed to the user. Test Plan: Request a pairing from the desktop and Accept or Reject the pairing on Android using the notification Action buttons When you accept the pairing the DeviceFragment should be shown for the device, the action bar title should be set to the devices name and the device should be selected in the NavigationView When you reject the pairing the PairingFragment should be shown Reviewers: #kde_connect, nicolasfella Reviewed By: #kde_connect, nicolasfella Subscribers: nicolasfella, kdeconnect Tags: #kde_connect Differential Revision: https://phabricator.kde.org/D16518
This commit is contained in:
committed by
Nicolas Fella
parent
2bc059c4b6
commit
b54b69032f
@@ -136,7 +136,10 @@ public class MainActivity extends AppCompatActivity {
|
||||
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 @@ public class MainActivity extends AppCompatActivity {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private void onPairResultFromNotification(String deviceId, String pairStatus) {
|
||||
|
||||
private String onPairResultFromNotification(String deviceId, String pairStatus) {
|
||||
assert(deviceId != null);
|
||||
|
||||
mCurrentDevice = deviceId;
|
||||
BackgroundService.RunCommand(this, service -> {
|
||||
Device device = service.getDevice(deviceId);
|
||||
if (device == null) {
|
||||
Log.w("rejectPairing", "Device no longer exists: " + deviceId);
|
||||
return;
|
||||
}
|
||||
|
||||
preferences.edit().putString(STATE_SELECTED_DEVICE, null).apply();
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user