mirror of
https://github.com/KDE/kdeconnect-android
synced 2025-08-23 10:27:57 +00:00
Show number of custom devices in settings fragment
This commit is contained in:
parent
172822239c
commit
0923c8ecda
@ -269,6 +269,7 @@ SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted
|
|||||||
<string name="invalid_device_name">Invalid device name</string>
|
<string name="invalid_device_name">Invalid device name</string>
|
||||||
<string name="shareplugin_text_saved">Received text, saved to clipboard</string>
|
<string name="shareplugin_text_saved">Received text, saved to clipboard</string>
|
||||||
<string name="custom_devices_settings">Custom device list</string>
|
<string name="custom_devices_settings">Custom device list</string>
|
||||||
|
<string name="custom_devices_settings_summary">%d devices added manually</string>
|
||||||
<string name="custom_device_list">Add devices by IP</string>
|
<string name="custom_device_list">Add devices by IP</string>
|
||||||
<string name="custom_device_deleted">Custom device deleted</string>
|
<string name="custom_device_deleted">Custom device deleted</string>
|
||||||
<string name="custom_device_list_help">If your device is not automatically detected you can add its IP address or hostname by clicking on the Floating Action Button</string>
|
<string name="custom_device_list_help">If your device is not automatically detected you can add its IP address or hostname by clicking on the Floating Action Button</string>
|
||||||
|
@ -386,7 +386,7 @@ public class LanLinkProvider extends BaseLinkProvider {
|
|||||||
|
|
||||||
ThreadHelper.execute(() -> {
|
ThreadHelper.execute(() -> {
|
||||||
List<DeviceHost> hostList = CustomDevicesActivity
|
List<DeviceHost> hostList = CustomDevicesActivity
|
||||||
.getCustomDeviceList(PreferenceManager.getDefaultSharedPreferences(context));
|
.getCustomDeviceList(context);
|
||||||
|
|
||||||
if (TrustedNetworkHelper.isTrustedNetwork(context)) {
|
if (TrustedNetworkHelper.isTrustedNetwork(context)) {
|
||||||
hostList.add(DeviceHost.BROADCAST); //Default: broadcast.
|
hostList.add(DeviceHost.BROADCAST); //Default: broadcast.
|
||||||
|
@ -7,6 +7,7 @@
|
|||||||
|
|
||||||
package org.kde.kdeconnect.UserInterface;
|
package org.kde.kdeconnect.UserInterface;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
import android.content.SharedPreferences;
|
import android.content.SharedPreferences;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.preference.PreferenceManager;
|
import android.preference.PreferenceManager;
|
||||||
@ -48,7 +49,6 @@ public class CustomDevicesActivity extends AppCompatActivity implements CustomDe
|
|||||||
|
|
||||||
private ArrayList<DeviceHost> customDeviceList;
|
private ArrayList<DeviceHost> customDeviceList;
|
||||||
private EditTextAlertDialogFragment addDeviceDialog;
|
private EditTextAlertDialogFragment addDeviceDialog;
|
||||||
private SharedPreferences sharedPreferences;
|
|
||||||
private CustomDevicesAdapter customDevicesAdapter;
|
private CustomDevicesAdapter customDevicesAdapter;
|
||||||
private DeletedCustomDevice lastDeletedCustomDevice;
|
private DeletedCustomDevice lastDeletedCustomDevice;
|
||||||
private int editingDeviceAtPosition;
|
private int editingDeviceAtPosition;
|
||||||
@ -70,9 +70,7 @@ public class CustomDevicesActivity extends AppCompatActivity implements CustomDe
|
|||||||
|
|
||||||
fab.setOnClickListener(v -> showEditTextDialog(null));
|
fab.setOnClickListener(v -> showEditTextDialog(null));
|
||||||
|
|
||||||
sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this);
|
customDeviceList = getCustomDeviceList(this);
|
||||||
|
|
||||||
customDeviceList = getCustomDeviceList(sharedPreferences);
|
|
||||||
customDeviceList.forEach(host -> host.checkReachable(() -> {
|
customDeviceList.forEach(host -> host.checkReachable(() -> {
|
||||||
runOnUiThread(() -> customDevicesAdapter.notifyDataSetChanged());
|
runOnUiThread(() -> customDevicesAdapter.notifyDataSetChanged());
|
||||||
return Unit.INSTANCE;
|
return Unit.INSTANCE;
|
||||||
@ -131,6 +129,7 @@ public class CustomDevicesActivity extends AppCompatActivity implements CustomDe
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void saveList() {
|
private void saveList() {
|
||||||
|
SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this);
|
||||||
String serialized = TextUtils.join(IP_DELIM, customDeviceList);
|
String serialized = TextUtils.join(IP_DELIM, customDeviceList);
|
||||||
sharedPreferences
|
sharedPreferences
|
||||||
.edit()
|
.edit()
|
||||||
@ -154,7 +153,8 @@ public class CustomDevicesActivity extends AppCompatActivity implements CustomDe
|
|||||||
return ipList;
|
return ipList;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static ArrayList<DeviceHost> getCustomDeviceList(SharedPreferences sharedPreferences) {
|
public static ArrayList<DeviceHost> getCustomDeviceList(Context context) {
|
||||||
|
SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context);
|
||||||
String deviceListPrefs = sharedPreferences.getString(KEY_CUSTOM_DEVLIST_PREFERENCE, "");
|
String deviceListPrefs = sharedPreferences.getString(KEY_CUSTOM_DEVLIST_PREFERENCE, "");
|
||||||
ArrayList<DeviceHost> list = deserializeIpList(deviceListPrefs);
|
ArrayList<DeviceHost> list = deserializeIpList(deviceListPrefs);
|
||||||
list.sort(Comparator.comparing(DeviceHost::toString));
|
list.sort(Comparator.comparing(DeviceHost::toString));
|
||||||
|
@ -6,6 +6,7 @@
|
|||||||
package org.kde.kdeconnect.UserInterface
|
package org.kde.kdeconnect.UserInterface
|
||||||
|
|
||||||
import android.Manifest
|
import android.Manifest
|
||||||
|
import android.app.Activity
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
import android.content.pm.PackageManager
|
import android.content.pm.PackageManager
|
||||||
@ -151,16 +152,37 @@ class SettingsFragment : PreferenceFragmentCompat() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private val REQUEST_REFRESH_DEVICES_BY_IP = 1
|
||||||
|
|
||||||
|
private lateinit var devicesByIpPref : Preference
|
||||||
|
|
||||||
/** Opens activity to configure device by IP when clicked */
|
/** Opens activity to configure device by IP when clicked */
|
||||||
private fun devicesByIpPref(context: Context) = Preference(context).apply {
|
private fun devicesByIpPref(context: Context) = Preference(context).apply {
|
||||||
|
devicesByIpPref = this
|
||||||
isPersistent = false
|
isPersistent = false
|
||||||
setTitle(R.string.custom_device_list)
|
setTitle(R.string.custom_device_list)
|
||||||
|
updateDevicesByIpSummary()
|
||||||
onPreferenceClickListener = Preference.OnPreferenceClickListener {
|
onPreferenceClickListener = Preference.OnPreferenceClickListener {
|
||||||
startActivity(Intent(context, CustomDevicesActivity::class.java))
|
startActivityForResult(Intent(context, CustomDevicesActivity::class.java), REQUEST_REFRESH_DEVICES_BY_IP)
|
||||||
true
|
true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
|
||||||
|
if (requestCode == REQUEST_REFRESH_DEVICES_BY_IP) {
|
||||||
|
updateDevicesByIpSummary()
|
||||||
|
} else {
|
||||||
|
super.onActivityResult(requestCode, resultCode, data)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun updateDevicesByIpSummary() {
|
||||||
|
devicesByIpPref.setSummary(getString(
|
||||||
|
R.string.custom_devices_settings_summary,
|
||||||
|
CustomDevicesActivity.getCustomDeviceList(context).size
|
||||||
|
))
|
||||||
|
}
|
||||||
|
|
||||||
private fun udpBroadcastPref(context: Context) = SwitchPreference(context).apply {
|
private fun udpBroadcastPref(context: Context) = SwitchPreference(context).apply {
|
||||||
setDefaultValue(true)
|
setDefaultValue(true)
|
||||||
key = KEY_UDP_BROADCAST_ENABLED
|
key = KEY_UDP_BROADCAST_ENABLED
|
||||||
|
Loading…
x
Reference in New Issue
Block a user