add option to enter a WebRTC instance

This commit is contained in:
B. Petersen
2020-07-23 00:46:26 +02:00
parent d6616c8816
commit a7ca3f43ba
5 changed files with 63 additions and 1 deletions
+17
View File
@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">
<EditText
android:id="@+id/input_field"
android:layout_marginBottom="8dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:layout_marginTop="8dp"/>
</FrameLayout>
+5 -1
View File
@@ -49,7 +49,7 @@
</PreferenceCategory>
<PreferenceCategory android:title="Experimental features">
<PreferenceCategory android:title="@string/pref_experimental_features">
<org.thoughtcrime.securesms.components.SwitchPreferenceCompat
android:defaultValue="false"
@@ -61,6 +61,10 @@
android:key="pref_ephemeral_messages"
android:title="Disappearing messages options"/>
<Preference android:key="pref_webrtc_instance"
android:title="WebRTC instance"
android:summary="@string/none"/>
</PreferenceCategory>
@@ -284,6 +284,11 @@ public class ApplicationDcContext extends DcContext {
}
public boolean isWebrtcConfigOk() {
String instance = getConfig(DcHelper.CONFIG_WEBRTC_INSTANCE);
return (instance != null && !instance.isEmpty());
}
/***********************************************************************************************
* create objects compatible to the database model of Signal
**********************************************************************************************/
@@ -30,6 +30,7 @@ public class DcHelper {
public static final String CONFIG_BCC_SELF = "bcc_self";
public static final String CONFIG_SHOW_EMAILS = "show_emails";
public static final String CONFIG_MEDIA_QUALITY = "media_quality";
public static final String CONFIG_WEBRTC_INSTANCE = "webrtc_instance";
public static ApplicationDcContext getContext(Context context) {
return ApplicationContext.getInstance(context).dcContext;
@@ -14,6 +14,7 @@ import androidx.preference.Preference;
import android.util.Log;
import android.view.View;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.Toast;
import com.b44t.messenger.DcContext;
@@ -23,6 +24,7 @@ import org.thoughtcrime.securesms.ApplicationPreferencesActivity;
import org.thoughtcrime.securesms.LogViewActivity;
import org.thoughtcrime.securesms.R;
import org.thoughtcrime.securesms.connect.AccountManager;
import org.thoughtcrime.securesms.connect.DcHelper;
import org.thoughtcrime.securesms.permissions.Permissions;
import org.thoughtcrime.securesms.util.ScreenLockUtil;
import org.thoughtcrime.securesms.util.Util;
@@ -96,6 +98,10 @@ public class AdvancedPreferenceFragment extends ListSummaryPreferenceFragment
Preference submitDebugLog = this.findPreference("pref_view_log");
submitDebugLog.setOnPreferenceClickListener(new ViewLogListener());
Preference webrtcInstance = this.findPreference("pref_webrtc_instance");
webrtcInstance.setOnPreferenceClickListener(new WebrtcInstanceListener());
updateWebrtcSummary();
}
private boolean handleImapCheck(Preference preference, Object newValue, String dc_config_name) {
@@ -173,6 +179,35 @@ public class AdvancedPreferenceFragment extends ListSummaryPreferenceFragment
}
}
private class WebrtcInstanceListener implements Preference.OnPreferenceClickListener {
@Override
public boolean onPreferenceClick(Preference preference) {
View gl = View.inflate(getActivity(), R.layout.single_line_input, null);
EditText inputField = gl.findViewById(R.id.input_field);
inputField.setHint("Your WebRTC instance");
inputField.setText(dcContext.getConfig(DcHelper.CONFIG_WEBRTC_INSTANCE));
inputField.setSelection(inputField.getText().length());
new AlertDialog.Builder(getActivity())
.setTitle("WebRTC instance")
.setMessage("If a WebRTC instance is defined here, you will find a button to start videochats in each one-to-one chat (groups will probably come a bit later :) Videochats require a supported browser.\n\nExamples: https://meet.jit.si/$ROOM or basicwebrtc:https://your-server")
.setView(gl)
.setNegativeButton(android.R.string.cancel, null)
.setPositiveButton(android.R.string.ok, (dialog, which) -> {
dcContext.setConfig(DcHelper.CONFIG_WEBRTC_INSTANCE, inputField.getText().toString());
updateWebrtcSummary();
})
.show();
return true;
}
}
private void updateWebrtcSummary() {
Preference webrtcInstance = this.findPreference("pref_webrtc_instance");
if (webrtcInstance != null) {
webrtcInstance.setSummary(dcContext.isWebrtcConfigOk()?
dcContext.getConfig(DcHelper.CONFIG_WEBRTC_INSTANCE) : getString(R.string.none));
}
}
/***********************************************************************************************
* Autocrypt