Skip to content
Snippets Groups Projects
Commit 2a3e4a39 authored by Adrien Béraud's avatar Adrien Béraud
Browse files

config: add peer discovery

Change-Id: Ieb99fcd191a1cbfa64290deceb9de444be2f0e67
parent 24973fe8
Branches
Tags
No related merge requests found
...@@ -20,6 +20,8 @@ ...@@ -20,6 +20,8 @@
package cx.ring.fragments; package cx.ring.fragments;
import android.os.Bundle; import android.os.Bundle;
import androidx.fragment.app.FragmentManager;
import androidx.preference.EditTextPreference; import androidx.preference.EditTextPreference;
import androidx.preference.ListPreference; import androidx.preference.ListPreference;
import androidx.preference.Preference; import androidx.preference.Preference;
...@@ -41,32 +43,34 @@ import cx.ring.views.PasswordPreference; ...@@ -41,32 +43,34 @@ import cx.ring.views.PasswordPreference;
public class AdvancedAccountFragment extends BasePreferenceFragment<AdvancedAccountPresenter> implements AdvancedAccountView, Preference.OnPreferenceChangeListener { public class AdvancedAccountFragment extends BasePreferenceFragment<AdvancedAccountPresenter> implements AdvancedAccountView, Preference.OnPreferenceChangeListener {
private static final String DIALOG_FRAGMENT_TAG = "android.support.v14.preference.PreferenceFragment.DIALOG"; private static final String DIALOG_FRAGMENT_TAG = "androidx.preference.PreferenceFragment.DIALOG";
@Override @Override
public void onCreatePreferences(Bundle bundle, String s) { public void onCreatePreferences(Bundle bundle, String s) {
((JamiApplication) getActivity().getApplication()).getRingInjectionComponent().inject(this); ((JamiApplication) requireActivity().getApplication()).getRingInjectionComponent().inject(this);
super.onCreatePreferences(bundle, s); super.onCreatePreferences(bundle, s);
// Load the preferences from an XML resource // Load the preferences from an XML resource
addPreferencesFromResource(R.xml.account_advanced_prefs); addPreferencesFromResource(R.xml.account_advanced_prefs);
presenter.init(getArguments().getString(AccountEditionActivity.ACCOUNT_ID_KEY)); Bundle args = getArguments();
presenter.init(args == null ? null : args.getString(AccountEditionActivity.ACCOUNT_ID_KEY));
} }
@Override @Override
public void onDisplayPreferenceDialog(Preference preference) { public void onDisplayPreferenceDialog(Preference preference) {
if (getFragmentManager().findFragmentByTag(DIALOG_FRAGMENT_TAG) != null) { FragmentManager fragmentManager = requireFragmentManager();
if (fragmentManager.findFragmentByTag(DIALOG_FRAGMENT_TAG) != null) {
return; return;
} }
if (preference instanceof EditTextIntegerPreference) { if (preference instanceof EditTextIntegerPreference) {
EditTextPreferenceDialog f = EditTextPreferenceDialog.newInstance(preference.getKey(), EditorInfo.TYPE_CLASS_NUMBER); EditTextPreferenceDialog f = EditTextPreferenceDialog.newInstance(preference.getKey(), EditorInfo.TYPE_CLASS_NUMBER);
f.setTargetFragment(this, 0); f.setTargetFragment(this, 0);
f.show(getFragmentManager(), DIALOG_FRAGMENT_TAG); f.show(fragmentManager, DIALOG_FRAGMENT_TAG);
} else if (preference instanceof PasswordPreference) { } else if (preference instanceof PasswordPreference) {
EditTextPreferenceDialog f = EditTextPreferenceDialog.newInstance(preference.getKey(), EditorInfo.TYPE_CLASS_TEXT | EditorInfo.TYPE_TEXT_VARIATION_PASSWORD); EditTextPreferenceDialog f = EditTextPreferenceDialog.newInstance(preference.getKey(), EditorInfo.TYPE_CLASS_TEXT | EditorInfo.TYPE_TEXT_VARIATION_PASSWORD);
f.setTargetFragment(this, 0); f.setTargetFragment(this, 0);
f.show(getFragmentManager(), DIALOG_FRAGMENT_TAG); f.show(fragmentManager, DIALOG_FRAGMENT_TAG);
} else { } else {
super.onDisplayPreferenceDialog(preference); super.onDisplayPreferenceDialog(preference);
} }
...@@ -104,8 +108,6 @@ public class AdvancedAccountFragment extends BasePreferenceFragment<AdvancedAcco ...@@ -104,8 +108,6 @@ public class AdvancedAccountFragment extends BasePreferenceFragment<AdvancedAcco
final ConfigKey key = ConfigKey.fromString(preference.getKey()); final ConfigKey key = ConfigKey.fromString(preference.getKey());
presenter.preferenceChanged(key, newValue); presenter.preferenceChanged(key, newValue);
if (preference instanceof TwoStatePreference) { if (preference instanceof TwoStatePreference) {
presenter.twoStatePreferenceChanged(key, newValue); presenter.twoStatePreferenceChanged(key, newValue);
} else if (preference instanceof PasswordPreference) { } else if (preference instanceof PasswordPreference) {
......
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24.0"
android:viewportHeight="24.0"
android:tint="?attr/colorControlNormal">
<path
android:fillColor="@android:color/white"
android:pathData="M19.35,10.04C18.67,6.59 15.64,4 12,4 9.11,4 6.6,5.64 5.35,8.04 2.34,8.36 0,10.91 0,14c0,3.31 2.69,6 6,6h13c2.76,0 5,-2.24 5,-5 0,-2.64 -2.05,-4.78 -4.65,-4.96z"/>
</vector>
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24.0"
android:viewportHeight="24.0"
android:tint="?attr/colorControlNormal">
<path
android:fillColor="@android:color/white"
android:pathData="M10,12c-1.1,0 -2,0.9 -2,2s0.9,2 2,2 2,-0.9 2,-2 -0.9,-2 -2,-2zM6,8c-1.1,0 -2,0.9 -2,2s0.9,2 2,2 2,-0.9 2,-2 -0.9,-2 -2,-2zM6,16c-1.1,0 -2,0.9 -2,2s0.9,2 2,2 2,-0.9 2,-2 -0.9,-2 -2,-2zM18,8c1.1,0 2,-0.9 2,-2s-0.9,-2 -2,-2 -2,0.9 -2,2 0.9,2 2,2zM14,16c-1.1,0 -2,0.9 -2,2s0.9,2 2,2 2,-0.9 2,-2 -0.9,-2 -2,-2zM18,12c-1.1,0 -2,0.9 -2,2s0.9,2 2,2 2,-0.9 2,-2 -0.9,-2 -2,-2zM14,8c-1.1,0 -2,0.9 -2,2s0.9,2 2,2 2,-0.9 2,-2 -0.9,-2 -2,-2zM10,4c-1.1,0 -2,0.9 -2,2s0.9,2 2,2 2,-0.9 2,-2 -0.9,-2 -2,-2z"/>
</vector>
...@@ -131,6 +131,10 @@ along with this program; if not, write to the Free Software ...@@ -131,6 +131,10 @@ along with this program; if not, write to the Free Software
<string name="account_proxy_enable_label">Use DHT proxy</string> <string name="account_proxy_enable_label">Use DHT proxy</string>
<string name="account_proxy_server_label">DHT proxy address</string> <string name="account_proxy_server_label">DHT proxy address</string>
<string name="account_peer_discovery_label">Local peer discovery</string>
<string name="account_peer_discovery_enable_label">Enable local peer discovery</string>
<string name="account_peer_discovery_enable_summary">Connect to other DHT nodes advertising on our local network</string>
<!-- Security Details --> <!-- Security Details -->
<string name="account_credentials_label">Credentials</string> <string name="account_credentials_label">Credentials</string>
<string name="account_credentials_edit">Edit credentials</string> <string name="account_credentials_edit">Edit credentials</string>
......
...@@ -49,6 +49,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. ...@@ -49,6 +49,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
<PreferenceCategory android:title="@string/account_proxy_label"> <PreferenceCategory android:title="@string/account_proxy_label">
<SwitchPreference <SwitchPreference
android:icon="@drawable/baseline_cloud_24"
android:key="Account.proxyEnabled" android:key="Account.proxyEnabled"
android:persistent="false" android:persistent="false"
android:summaryOff="Disabled" android:summaryOff="Disabled"
...@@ -64,6 +65,16 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. ...@@ -64,6 +65,16 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
android:title="@string/account_proxy_server_label" /> android:title="@string/account_proxy_server_label" />
</PreferenceCategory> </PreferenceCategory>
<PreferenceCategory android:title="@string/account_peer_discovery_label">
<SwitchPreference
android:icon="@drawable/baseline_grain_24"
android:key="Account.peerDiscovery"
android:persistent="false"
android:summary="@string/account_peer_discovery_enable_summary"
android:title="@string/account_peer_discovery_enable_label" />
</PreferenceCategory>
<PreferenceCategory android:title="@string/account_published_address_label"> <PreferenceCategory android:title="@string/account_published_address_label">
<SwitchPreference <SwitchPreference
......
...@@ -60,6 +60,9 @@ public enum ConfigKey { ...@@ -60,6 +60,9 @@ public enum ConfigKey {
ACCOUNT_ACTIVE("Account.active"), ACCOUNT_ACTIVE("Account.active"),
ACCOUNT_DEVICE_ID("Account.deviceID"), ACCOUNT_DEVICE_ID("Account.deviceID"),
ACCOUNT_DEVICE_NAME("Account.deviceName"), ACCOUNT_DEVICE_NAME("Account.deviceName"),
ACCOUNT_PEER_DISCOVERY("Account.peerDiscovery"),
ACCOUNT_DISCOVERY("Account.accountDiscovery"),
ACCOUNT_PUBLISH("Account.accountPublish"),
VIDEO_ENABLED("Account.videoEnabled"), VIDEO_ENABLED("Account.videoEnabled"),
VIDEO_PORT_MIN("Account.videoPortMin"), VIDEO_PORT_MIN("Account.videoPortMin"),
VIDEO_PORT_MAX("Account.videoPortMax"), VIDEO_PORT_MAX("Account.videoPortMax"),
...@@ -112,7 +115,10 @@ public enum ConfigKey { ...@@ -112,7 +115,10 @@ public enum ConfigKey {
ACCOUNT_AUTOANSWER, ACCOUNT_AUTOANSWER,
ACCOUNT_UPNP_ENABLE, ACCOUNT_UPNP_ENABLE,
DHT_PUBLIC_IN, DHT_PUBLIC_IN,
PROXY_ENABLED)); PROXY_ENABLED,
ACCOUNT_PEER_DISCOVERY,
ACCOUNT_DISCOVERY,
ACCOUNT_PUBLISH));
private final String mKey; private final String mKey;
......
...@@ -58,6 +58,7 @@ import cx.ring.model.TrustRequest; ...@@ -58,6 +58,7 @@ import cx.ring.model.TrustRequest;
import cx.ring.model.Uri; import cx.ring.model.Uri;
import cx.ring.utils.FileUtils; import cx.ring.utils.FileUtils;
import cx.ring.utils.Log; import cx.ring.utils.Log;
import cx.ring.utils.StringUtils;
import cx.ring.utils.SwigNativeConverter; import cx.ring.utils.SwigNativeConverter;
import cx.ring.utils.VCardUtils; import cx.ring.utils.VCardUtils;
import ezvcard.VCard; import ezvcard.VCard;
...@@ -395,12 +396,14 @@ public class AccountService { ...@@ -395,12 +396,14 @@ public class AccountService {
* @return the Account from the local cache that matches the accountId * @return the Account from the local cache that matches the accountId
*/ */
public Account getAccount(String accountId) { public Account getAccount(String accountId) {
if (!StringUtils.isEmpty(accountId)) {
for (Account account : mAccountList) { for (Account account : mAccountList) {
String accountID = account.getAccountID(); String accountID = account.getAccountID();
if (accountID.equals(accountId)) { if (accountID.equals(accountId)) {
return account; return account;
} }
} }
}
return null; return null;
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment