mirror of
https://github.com/KDE/kdeconnect-android
synced 2025-08-29 13:17:43 +00:00
Add a warning if multiple devices have the same name
This commit is contained in:
parent
05e14bb81c
commit
83efd6b355
25
res/layout-v23/pairing_explanation_duplicate_names.xml
Normal file
25
res/layout-v23/pairing_explanation_duplicate_names.xml
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
|
||||||
|
<!--
|
||||||
|
SPDX-FileCopyrightText: 2023 Albert Vaca Cintora <albertvaka@gmail.com>
|
||||||
|
|
||||||
|
SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
|
||||||
|
-->
|
||||||
|
|
||||||
|
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:background="?attr/selectableItemBackground"
|
||||||
|
android:clickable="true"
|
||||||
|
android:focusable="true"
|
||||||
|
android:drawablePadding="8dp"
|
||||||
|
android:paddingTop="16dp"
|
||||||
|
android:paddingBottom="12dp"
|
||||||
|
android:paddingLeft="16dp"
|
||||||
|
android:paddingRight="16dp"
|
||||||
|
android:text="@string/pairing_duplicate_names"
|
||||||
|
app:drawableStartCompat="@drawable/ic_warning"
|
||||||
|
app:drawableTint="?attr/colorControlNormal">
|
||||||
|
|
||||||
|
</TextView>
|
25
res/layout/pairing_explanation_duplicate_names.xml
Normal file
25
res/layout/pairing_explanation_duplicate_names.xml
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
|
||||||
|
<!--
|
||||||
|
SPDX-FileCopyrightText: 2023 Albert Vaca Cintora <albertvaka@gmail.com>
|
||||||
|
|
||||||
|
SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
|
||||||
|
-->
|
||||||
|
|
||||||
|
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:background="?attr/selectableItemBackground"
|
||||||
|
android:clickable="true"
|
||||||
|
android:focusable="true"
|
||||||
|
android:drawablePadding="8dp"
|
||||||
|
android:paddingTop="16dp"
|
||||||
|
android:paddingBottom="12dp"
|
||||||
|
android:paddingLeft="16dp"
|
||||||
|
android:paddingRight="16dp"
|
||||||
|
android:text="@string/pairing_duplicate_names"
|
||||||
|
app:drawableStartCompat="@drawable/ic_warning"
|
||||||
|
app:drawableLeftCompat="@drawable/ic_warning">
|
||||||
|
|
||||||
|
</TextView>
|
@ -227,6 +227,7 @@ SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted
|
|||||||
<string name="middle_click">Send Middle Click</string>
|
<string name="middle_click">Send Middle Click</string>
|
||||||
<string name="show_keyboard">Show Keyboard</string>
|
<string name="show_keyboard">Show Keyboard</string>
|
||||||
<string name="device_not_paired">Device not paired</string>
|
<string name="device_not_paired">Device not paired</string>
|
||||||
|
<string name="pairing_duplicate_names">Caution: There are multiple devices with the same name.</string>
|
||||||
<string name="request_pairing">Request pairing</string>
|
<string name="request_pairing">Request pairing</string>
|
||||||
<string name="pairing_accept">Accept</string>
|
<string name="pairing_accept">Accept</string>
|
||||||
<string name="pairing_reject">Reject</string>
|
<string name="pairing_reject">Reject</string>
|
||||||
|
@ -157,5 +157,5 @@ object DeviceHelper {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@JvmStatic
|
@JvmStatic
|
||||||
fun filterName(input: String): String = input.replace(NAME_INVALID_CHARACTERS_REGEX, "").take(MAX_DEVICE_NAME_LENGTH)
|
fun filterName(input: String): String = input.replace(NAME_INVALID_CHARACTERS_REGEX, "").trim().take(MAX_DEVICE_NAME_LENGTH)
|
||||||
}
|
}
|
||||||
|
@ -39,6 +39,7 @@ import org.kde.kdeconnect.UserInterface.List.PairingDeviceItem;
|
|||||||
import org.kde.kdeconnect.UserInterface.List.SectionItem;
|
import org.kde.kdeconnect.UserInterface.List.SectionItem;
|
||||||
import org.kde.kdeconnect_tp.R;
|
import org.kde.kdeconnect_tp.R;
|
||||||
import org.kde.kdeconnect_tp.databinding.DevicesListBinding;
|
import org.kde.kdeconnect_tp.databinding.DevicesListBinding;
|
||||||
|
import org.kde.kdeconnect_tp.databinding.PairingExplanationDuplicateNamesBinding;
|
||||||
import org.kde.kdeconnect_tp.databinding.PairingExplanationNotTrustedBinding;
|
import org.kde.kdeconnect_tp.databinding.PairingExplanationNotTrustedBinding;
|
||||||
import org.kde.kdeconnect_tp.databinding.PairingExplanationTextBinding;
|
import org.kde.kdeconnect_tp.databinding.PairingExplanationTextBinding;
|
||||||
import org.kde.kdeconnect_tp.databinding.PairingExplanationTextNoNotificationsBinding;
|
import org.kde.kdeconnect_tp.databinding.PairingExplanationTextNoNotificationsBinding;
|
||||||
@ -46,6 +47,7 @@ import org.kde.kdeconnect_tp.databinding.PairingExplanationTextNoWifiBinding;
|
|||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
|
import java.util.HashSet;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -60,6 +62,7 @@ public class PairingFragment extends Fragment implements PairingDeviceItem.Callb
|
|||||||
private PairingExplanationNotTrustedBinding pairingExplanationNotTrustedBinding;
|
private PairingExplanationNotTrustedBinding pairingExplanationNotTrustedBinding;
|
||||||
private PairingExplanationTextBinding pairingExplanationTextBinding;
|
private PairingExplanationTextBinding pairingExplanationTextBinding;
|
||||||
private PairingExplanationTextNoWifiBinding pairingExplanationTextNoWifiBinding;
|
private PairingExplanationTextNoWifiBinding pairingExplanationTextNoWifiBinding;
|
||||||
|
private PairingExplanationDuplicateNamesBinding pairingExplanationDuplicateNamesBinding;
|
||||||
private PairingExplanationTextNoNotificationsBinding pairingExplanationTextNoNotificationsBinding;
|
private PairingExplanationTextNoNotificationsBinding pairingExplanationTextNoNotificationsBinding;
|
||||||
|
|
||||||
private MainActivity mActivity;
|
private MainActivity mActivity;
|
||||||
@ -68,6 +71,7 @@ public class PairingFragment extends Fragment implements PairingDeviceItem.Callb
|
|||||||
|
|
||||||
private TextView headerText;
|
private TextView headerText;
|
||||||
private TextView noWifiHeader;
|
private TextView noWifiHeader;
|
||||||
|
private TextView duplicateNamesHeader;
|
||||||
private TextView noNotificationsHeader;
|
private TextView noNotificationsHeader;
|
||||||
private TextView notTrustedText;
|
private TextView notTrustedText;
|
||||||
|
|
||||||
@ -94,6 +98,9 @@ public class PairingFragment extends Fragment implements PairingDeviceItem.Callb
|
|||||||
noWifiHeader = pairingExplanationTextNoWifiBinding.getRoot();
|
noWifiHeader = pairingExplanationTextNoWifiBinding.getRoot();
|
||||||
noWifiHeader.setOnClickListener(view -> startActivity(new Intent(Settings.ACTION_WIFI_SETTINGS)));
|
noWifiHeader.setOnClickListener(view -> startActivity(new Intent(Settings.ACTION_WIFI_SETTINGS)));
|
||||||
|
|
||||||
|
pairingExplanationDuplicateNamesBinding = PairingExplanationDuplicateNamesBinding.inflate(inflater);
|
||||||
|
duplicateNamesHeader = pairingExplanationDuplicateNamesBinding.getRoot();
|
||||||
|
|
||||||
pairingExplanationTextNoNotificationsBinding = PairingExplanationTextNoNotificationsBinding.inflate(inflater);
|
pairingExplanationTextNoNotificationsBinding = PairingExplanationTextNoNotificationsBinding.inflate(inflater);
|
||||||
noNotificationsHeader = pairingExplanationTextNoNotificationsBinding.getRoot();
|
noNotificationsHeader = pairingExplanationTextNoNotificationsBinding.getRoot();
|
||||||
noNotificationsHeader.setOnClickListener(view -> ActivityCompat.requestPermissions(requireActivity(), new String[]{Manifest.permission.POST_NOTIFICATIONS}, MainActivity.RESULT_NOTIFICATIONS_ENABLED));
|
noNotificationsHeader.setOnClickListener(view -> ActivityCompat.requestPermissions(requireActivity(), new String[]{Manifest.permission.POST_NOTIFICATIONS}, MainActivity.RESULT_NOTIFICATIONS_ENABLED));
|
||||||
@ -162,6 +169,8 @@ public class PairingFragment extends Fragment implements PairingDeviceItem.Callb
|
|||||||
}
|
}
|
||||||
listRefreshCalledThisFrame = true;
|
listRefreshCalledThisFrame = true;
|
||||||
|
|
||||||
|
devicesListBinding.devicesList.removeHeaderView(duplicateNamesHeader);
|
||||||
|
|
||||||
//Check if we're on Wi-Fi/Local network. If we still see a device, don't do anything special
|
//Check if we're on Wi-Fi/Local network. If we still see a device, don't do anything special
|
||||||
BackgroundService service = BackgroundService.getInstance();
|
BackgroundService service = BackgroundService.getInstance();
|
||||||
if (service == null) {
|
if (service == null) {
|
||||||
@ -176,10 +185,20 @@ public class PairingFragment extends Fragment implements PairingDeviceItem.Callb
|
|||||||
SectionItem connectedSection;
|
SectionItem connectedSection;
|
||||||
Resources res = getResources();
|
Resources res = getResources();
|
||||||
|
|
||||||
|
Collection<Device> devices = KdeConnect.getInstance().getDevices().values();
|
||||||
|
|
||||||
|
HashSet<String> seenNames = new HashSet<>();
|
||||||
|
for (Device device : devices) {
|
||||||
|
if (seenNames.contains(device.getName())) {
|
||||||
|
devicesListBinding.devicesList.addHeaderView(duplicateNamesHeader);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
seenNames.add(device.getName());
|
||||||
|
}
|
||||||
|
|
||||||
connectedSection = new SectionItem(res.getString(R.string.category_connected_devices));
|
connectedSection = new SectionItem(res.getString(R.string.category_connected_devices));
|
||||||
items.add(connectedSection);
|
items.add(connectedSection);
|
||||||
|
|
||||||
Collection<Device> devices = KdeConnect.getInstance().getDevices().values();
|
|
||||||
for (Device device : devices) {
|
for (Device device : devices) {
|
||||||
if (device.isReachable() && device.isPaired()) {
|
if (device.isReachable() && device.isPaired()) {
|
||||||
items.add(new PairingDeviceItem(device, PairingFragment.this));
|
items.add(new PairingDeviceItem(device, PairingFragment.this));
|
||||||
|
Loading…
x
Reference in New Issue
Block a user