mirror of
https://github.com/KDE/kdeconnect-android
synced 2025-08-31 06:05:12 +00:00
Make tapping on a pair notification work again
Summary: The Simplify pairing from notification patch D16518 broke the functionality that tapping on the notification provided This patch makes tapping on the pairing notification work again as expected Test Plan: Before applying this patch initiate a pairing from kde On android tap on the notification (not the action buttons) and notice that nothing happens Apply the path and repeat the above test. Now the DeviceFragment should be displayed allowing the the pairing to be accepted or rejected Reviewers: #kde_connect, nicolasfella Reviewed By: #kde_connect, nicolasfella Subscribers: nicolasfella, kdeconnect Tags: #kde_connect Differential Revision: https://phabricator.kde.org/D17886
This commit is contained in:
@@ -383,21 +383,19 @@ public class Device implements BaseLink.PacketReceiver {
|
||||
notificationId = (int) System.currentTimeMillis();
|
||||
|
||||
Intent intent = new Intent(getContext(), MainActivity.class);
|
||||
intent.putExtra("deviceId", getDeviceId());
|
||||
intent.putExtra("notificationId", notificationId);
|
||||
PendingIntent pendingIntent = PendingIntent.getActivity(getContext(), 0, intent, PendingIntent.FLAG_CANCEL_CURRENT);
|
||||
intent.putExtra(MainActivity.EXTRA_DEVICE_ID, getDeviceId());
|
||||
intent.putExtra(MainActivity.PAIR_REQUEST_STATUS, MainActivity.PAIRING_PENDING);
|
||||
PendingIntent pendingIntent = PendingIntent.getActivity(getContext(), 1, intent, PendingIntent.FLAG_CANCEL_CURRENT);
|
||||
|
||||
Intent acceptIntent = new Intent(getContext(), MainActivity.class);
|
||||
Intent rejectIntent = new Intent(getContext(), MainActivity.class);
|
||||
|
||||
acceptIntent.putExtra("deviceId", getDeviceId());
|
||||
acceptIntent.putExtra("notificationId", notificationId);
|
||||
acceptIntent.setAction("action " + System.currentTimeMillis());
|
||||
acceptIntent.putExtra(MainActivity.EXTRA_DEVICE_ID, getDeviceId());
|
||||
//acceptIntent.putExtra("notificationId", notificationId);
|
||||
acceptIntent.putExtra(MainActivity.PAIR_REQUEST_STATUS, MainActivity.PAIRING_ACCEPTED);
|
||||
|
||||
rejectIntent.putExtra("deviceId", getDeviceId());
|
||||
rejectIntent.putExtra("notificationId", notificationId);
|
||||
rejectIntent.setAction("action " + System.currentTimeMillis());
|
||||
rejectIntent.putExtra(MainActivity.EXTRA_DEVICE_ID, getDeviceId());
|
||||
//rejectIntent.putExtra("notificationId", notificationId);
|
||||
rejectIntent.putExtra(MainActivity.PAIR_REQUEST_STATUS, MainActivity.PAIRING_REJECTED);
|
||||
|
||||
PendingIntent acceptedPendingIntent = PendingIntent.getActivity(getContext(), 2, acceptIntent, PendingIntent.FLAG_ONE_SHOT);
|
||||
|
@@ -54,6 +54,7 @@ import java.util.ConcurrentModificationException;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.fragment.app.Fragment;
|
||||
import butterknife.BindView;
|
||||
import butterknife.ButterKnife;
|
||||
@@ -70,7 +71,7 @@ public class DeviceFragment extends Fragment {
|
||||
private static final String ARG_FROM_DEVICE_LIST = "fromDeviceList";
|
||||
|
||||
private View rootView;
|
||||
private static String mDeviceId; //Static because if we get here by using the back button in the action bar, the extra deviceId will not be set.
|
||||
private String mDeviceId;
|
||||
private Device device;
|
||||
|
||||
private MainActivity mActivity;
|
||||
@@ -111,6 +112,17 @@ public class DeviceFragment extends Fragment {
|
||||
mActivity = ((MainActivity) getActivity());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreate(@Nullable Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
if (getArguments() == null || !getArguments().containsKey(ARG_DEVICE_ID)) {
|
||||
throw new RuntimeException("You must instantiate a new DeviceFragment using DeviceFragment.newInstance()");
|
||||
}
|
||||
|
||||
mDeviceId = getArguments().getString(ARG_DEVICE_ID);
|
||||
}
|
||||
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
||||
Bundle savedInstanceState) {
|
||||
@@ -118,11 +130,6 @@ public class DeviceFragment extends Fragment {
|
||||
rootView = inflater.inflate(R.layout.activity_device, container, false);
|
||||
unbinder = ButterKnife.bind(this, rootView);
|
||||
|
||||
final String deviceId = getArguments().getString(ARG_DEVICE_ID);
|
||||
if (deviceId != null) {
|
||||
mDeviceId = deviceId;
|
||||
}
|
||||
|
||||
setHasOptionsMenu(true);
|
||||
|
||||
//Log.e("DeviceFragment", "device: " + deviceId);
|
||||
@@ -147,6 +154,8 @@ public class DeviceFragment extends Fragment {
|
||||
return rootView;
|
||||
}
|
||||
|
||||
String getDeviceId() { return mDeviceId; }
|
||||
|
||||
private final Device.PluginsChangedListener pluginsChangedListener = device -> refreshUI();
|
||||
|
||||
@OnClick(R.id.pair_button)
|
||||
|
@@ -53,6 +53,9 @@ public class MainActivity extends AppCompatActivity {
|
||||
public static final String PAIR_REQUEST_STATUS = "pair_req_status";
|
||||
public static final String PAIRING_ACCEPTED = "accepted";
|
||||
public static final String PAIRING_REJECTED = "rejected";
|
||||
public static final String PAIRING_PENDING = "pending";
|
||||
|
||||
public static final String EXTRA_DEVICE_ID = "deviceId";
|
||||
|
||||
@BindView(R.id.navigation_drawer) NavigationView mNavigationView;
|
||||
@BindView(R.id.drawer_layout) DrawerLayout mDrawerLayout;
|
||||
@@ -134,9 +137,9 @@ public class MainActivity extends AppCompatActivity {
|
||||
Log.i("MainActivity", "Requested to start main overview");
|
||||
savedDevice = null;
|
||||
savedMenuEntry = MENU_ENTRY_ADD_DEVICE;
|
||||
} else if (getIntent().hasExtra("deviceId")) {
|
||||
} else if (getIntent().hasExtra(EXTRA_DEVICE_ID)) {
|
||||
Log.i("MainActivity", "Loading selected device from parameter");
|
||||
savedDevice = getIntent().getStringExtra("deviceId");
|
||||
savedDevice = getIntent().getStringExtra(EXTRA_DEVICE_ID);
|
||||
savedMenuEntry = MENU_ENTRY_DEVICE_UNKNOWN;
|
||||
// If pairStatus is not empty, then the user has accepted/reject the pairing from the notification
|
||||
String pairStatus = getIntent().getStringExtra(PAIR_REQUEST_STATUS);
|
||||
@@ -163,7 +166,10 @@ public class MainActivity extends AppCompatActivity {
|
||||
|
||||
//FragmentManager will restore whatever fragment was there
|
||||
if (savedInstanceState != null) {
|
||||
return;
|
||||
Fragment frag = getSupportFragmentManager().findFragmentById(R.id.container);
|
||||
if (!(frag instanceof DeviceFragment) || ((DeviceFragment)frag).getDeviceId().equals(savedDevice)) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// Activate the chosen fragment and select the entry in the menu
|
||||
@@ -181,21 +187,23 @@ public class MainActivity extends AppCompatActivity {
|
||||
private String onPairResultFromNotification(String deviceId, String pairStatus) {
|
||||
assert(deviceId != null);
|
||||
|
||||
BackgroundService.RunCommand(this, service -> {
|
||||
Device device = service.getDevice(deviceId);
|
||||
if (device == null) {
|
||||
Log.w("rejectPairing", "Device no longer exists: " + deviceId);
|
||||
return;
|
||||
}
|
||||
if (!pairStatus.equals(PAIRING_PENDING)) {
|
||||
BackgroundService.RunCommand(this, service -> {
|
||||
Device device = service.getDevice(deviceId);
|
||||
if (device == null) {
|
||||
Log.w("rejectPairing", "Device no longer exists: " + deviceId);
|
||||
return;
|
||||
}
|
||||
|
||||
if (pairStatus.equals(PAIRING_ACCEPTED)) {
|
||||
device.acceptPairing();
|
||||
} else {
|
||||
device.rejectPairing();
|
||||
}
|
||||
});
|
||||
if (pairStatus.equals(PAIRING_ACCEPTED)) {
|
||||
device.acceptPairing();
|
||||
} else if (pairStatus.equals(PAIRING_REJECTED)) {
|
||||
device.rejectPairing();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
if (pairStatus.equals(PAIRING_ACCEPTED)) {
|
||||
if (pairStatus.equals(PAIRING_ACCEPTED) || pairStatus.equals(PAIRING_PENDING)) {
|
||||
return deviceId;
|
||||
} else {
|
||||
return null;
|
||||
|
Reference in New Issue
Block a user