Use radio button for SSL/STARTTLS

pull/153/head
M66B 6 years ago
parent f6fde69b4a
commit 310fd98151

@ -53,6 +53,7 @@ import android.widget.CheckBox;
import android.widget.CompoundButton; import android.widget.CompoundButton;
import android.widget.EditText; import android.widget.EditText;
import android.widget.ImageView; import android.widget.ImageView;
import android.widget.RadioGroup;
import android.widget.ScrollView; import android.widget.ScrollView;
import android.widget.Spinner; import android.widget.Spinner;
import android.widget.TextView; import android.widget.TextView;
@ -95,7 +96,7 @@ public class FragmentAccount extends FragmentBase {
private Button btnAuthorize; private Button btnAuthorize;
private EditText etHost; private EditText etHost;
private CheckBox cbStartTls; private RadioGroup rgEncryption;
private CheckBox cbInsecure; private CheckBox cbInsecure;
private EditText etPort; private EditText etPort;
private EditText etUser; private EditText etUser;
@ -173,7 +174,7 @@ public class FragmentAccount extends FragmentBase {
btnAuthorize = view.findViewById(R.id.btnAuthorize); btnAuthorize = view.findViewById(R.id.btnAuthorize);
etHost = view.findViewById(R.id.etHost); etHost = view.findViewById(R.id.etHost);
etPort = view.findViewById(R.id.etPort); etPort = view.findViewById(R.id.etPort);
cbStartTls = view.findViewById(R.id.cbStartTls); rgEncryption = view.findViewById(R.id.rgEncryption);
cbInsecure = view.findViewById(R.id.cbInsecure); cbInsecure = view.findViewById(R.id.cbInsecure);
etUser = view.findViewById(R.id.etUser); etUser = view.findViewById(R.id.etUser);
tilPassword = view.findViewById(R.id.tilPassword); tilPassword = view.findViewById(R.id.tilPassword);
@ -247,7 +248,7 @@ public class FragmentAccount extends FragmentBase {
etHost.setText(provider.imap_host); etHost.setText(provider.imap_host);
etPort.setText(provider.imap_host == null ? null : Integer.toString(provider.imap_port)); etPort.setText(provider.imap_host == null ? null : Integer.toString(provider.imap_port));
cbStartTls.setChecked(provider.imap_starttls); rgEncryption.check(provider.imap_starttls ? R.id.radio_starttls : R.id.radio_ssl);
etUser.setTag(null); etUser.setTag(null);
etUser.setText(null); etUser.setText(null);
@ -290,10 +291,10 @@ public class FragmentAccount extends FragmentBase {
} }
}); });
cbStartTls.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { rgEncryption.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
@Override @Override
public void onCheckedChanged(CompoundButton compoundButton, boolean checked) { public void onCheckedChanged(RadioGroup group, int id) {
etPort.setHint(checked ? "143" : "993"); etPort.setHint(id == R.id.radio_starttls ? "143" : "993");
} }
}); });
@ -433,7 +434,7 @@ public class FragmentAccount extends FragmentBase {
btnAutoConfig.setEnabled(false); btnAutoConfig.setEnabled(false);
btnAuthorize.setVisibility(View.GONE); btnAuthorize.setVisibility(View.GONE);
cbStartTls.setVisibility(View.GONE); rgEncryption.setVisibility(View.GONE);
cbInsecure.setVisibility(View.GONE); cbInsecure.setVisibility(View.GONE);
tilPassword.setPasswordVisibilityToggleEnabled(id < 0); tilPassword.setPasswordVisibilityToggleEnabled(id < 0);
@ -485,7 +486,7 @@ public class FragmentAccount extends FragmentBase {
protected void onExecuted(Bundle args, EmailProvider provider) { protected void onExecuted(Bundle args, EmailProvider provider) {
etHost.setText(provider.imap_host); etHost.setText(provider.imap_host);
etPort.setText(Integer.toString(provider.imap_port)); etPort.setText(Integer.toString(provider.imap_port));
cbStartTls.setChecked(provider.imap_starttls); rgEncryption.check(provider.imap_starttls ? R.id.radio_starttls : R.id.radio_ssl);
} }
@Override @Override
@ -503,7 +504,7 @@ public class FragmentAccount extends FragmentBase {
args.putLong("id", id); args.putLong("id", id);
args.putInt("auth_type", auth_type); args.putInt("auth_type", auth_type);
args.putString("host", etHost.getText().toString()); args.putString("host", etHost.getText().toString());
args.putBoolean("starttls", cbStartTls.isChecked()); args.putBoolean("starttls", rgEncryption.getCheckedRadioButtonId() == R.id.radio_starttls);
args.putBoolean("insecure", cbInsecure.isChecked()); args.putBoolean("insecure", cbInsecure.isChecked());
args.putString("port", etPort.getText().toString()); args.putString("port", etPort.getText().toString());
args.putString("user", etUser.getText().toString()); args.putString("user", etUser.getText().toString());
@ -741,7 +742,7 @@ public class FragmentAccount extends FragmentBase {
args.putInt("auth_type", auth_type); args.putInt("auth_type", auth_type);
args.putString("host", etHost.getText().toString()); args.putString("host", etHost.getText().toString());
args.putBoolean("starttls", cbStartTls.isChecked()); args.putBoolean("starttls", rgEncryption.getCheckedRadioButtonId() == R.id.radio_starttls);
args.putBoolean("insecure", cbInsecure.isChecked()); args.putBoolean("insecure", cbInsecure.isChecked());
args.putString("port", etPort.getText().toString()); args.putString("port", etPort.getText().toString());
args.putString("user", etUser.getText().toString()); args.putString("user", etUser.getText().toString());
@ -1130,7 +1131,7 @@ public class FragmentAccount extends FragmentBase {
etPort.setText(Long.toString(account.port)); etPort.setText(Long.toString(account.port));
} }
cbStartTls.setChecked(account == null ? false : account.starttls); rgEncryption.check(account != null && account.starttls ? R.id.radio_starttls : R.id.radio_ssl);
cbInsecure.setChecked(account == null ? false : account.insecure); cbInsecure.setChecked(account == null ? false : account.insecure);
etUser.setTag(account == null || auth_type == Helper.AUTH_TYPE_PASSWORD ? null : account.user); etUser.setTag(account == null || auth_type == Helper.AUTH_TYPE_PASSWORD ? null : account.user);

@ -43,6 +43,7 @@ import android.widget.CheckBox;
import android.widget.CompoundButton; import android.widget.CompoundButton;
import android.widget.EditText; import android.widget.EditText;
import android.widget.ImageView; import android.widget.ImageView;
import android.widget.RadioGroup;
import android.widget.ScrollView; import android.widget.ScrollView;
import android.widget.Spinner; import android.widget.Spinner;
import android.widget.TextView; import android.widget.TextView;
@ -90,7 +91,7 @@ public class FragmentIdentity extends FragmentBase {
private EditText etDomain; private EditText etDomain;
private Button btnAutoConfig; private Button btnAutoConfig;
private EditText etHost; private EditText etHost;
private CheckBox cbStartTls; private RadioGroup rgEncryption;
private CheckBox cbInsecure; private CheckBox cbInsecure;
private EditText etPort; private EditText etPort;
private EditText etUser; private EditText etUser;
@ -159,7 +160,7 @@ public class FragmentIdentity extends FragmentBase {
btnAutoConfig = view.findViewById(R.id.btnAutoConfig); btnAutoConfig = view.findViewById(R.id.btnAutoConfig);
etHost = view.findViewById(R.id.etHost); etHost = view.findViewById(R.id.etHost);
cbStartTls = view.findViewById(R.id.cbStartTls); rgEncryption = view.findViewById(R.id.rgEncryption);
cbInsecure = view.findViewById(R.id.cbInsecure); cbInsecure = view.findViewById(R.id.cbInsecure);
etPort = view.findViewById(R.id.etPort); etPort = view.findViewById(R.id.etPort);
etUser = view.findViewById(R.id.etUser); etUser = view.findViewById(R.id.etUser);
@ -224,7 +225,7 @@ public class FragmentIdentity extends FragmentBase {
// This is needed because the spinner might be invisible // This is needed because the spinner might be invisible
etHost.setText(provider.smtp_host); etHost.setText(provider.smtp_host);
etPort.setText(Integer.toString(provider.smtp_port)); etPort.setText(Integer.toString(provider.smtp_port));
cbStartTls.setChecked(provider.smtp_starttls); rgEncryption.check(provider.smtp_starttls ? R.id.radio_starttls : R.id.radio_ssl);
break; break;
} }
@ -347,7 +348,7 @@ public class FragmentIdentity extends FragmentBase {
// Set associated host/port/starttls // Set associated host/port/starttls
etHost.setText(provider.smtp_host); etHost.setText(provider.smtp_host);
etPort.setText(position == 0 ? null : Integer.toString(provider.smtp_port)); etPort.setText(position == 0 ? null : Integer.toString(provider.smtp_port));
cbStartTls.setChecked(provider.smtp_starttls); rgEncryption.check(provider.smtp_starttls ? R.id.radio_starttls : R.id.radio_ssl);
} }
@Override @Override
@ -377,10 +378,10 @@ public class FragmentIdentity extends FragmentBase {
} }
}); });
cbStartTls.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { rgEncryption.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
@Override @Override
public void onCheckedChanged(CompoundButton compoundButton, boolean checked) { public void onCheckedChanged(RadioGroup group, int id) {
etPort.setHint(checked ? "587" : "465"); etPort.setHint(id == R.id.radio_starttls ? "587" : "465");
} }
}); });
@ -446,7 +447,7 @@ public class FragmentIdentity extends FragmentBase {
protected void onExecuted(Bundle args, EmailProvider provider) { protected void onExecuted(Bundle args, EmailProvider provider) {
etHost.setText(provider.smtp_host); etHost.setText(provider.smtp_host);
etPort.setText(Integer.toString(provider.smtp_port)); etPort.setText(Integer.toString(provider.smtp_port));
cbStartTls.setChecked(provider.smtp_starttls); rgEncryption.check(provider.smtp_starttls ? R.id.radio_starttls : R.id.radio_ssl);
} }
@Override @Override
@ -484,7 +485,7 @@ public class FragmentIdentity extends FragmentBase {
args.putLong("account", account == null ? -1 : account.id); args.putLong("account", account == null ? -1 : account.id);
args.putInt("auth_type", auth_type); args.putInt("auth_type", auth_type);
args.putString("host", etHost.getText().toString()); args.putString("host", etHost.getText().toString());
args.putBoolean("starttls", cbStartTls.isChecked()); args.putBoolean("starttls", rgEncryption.getCheckedRadioButtonId() == R.id.radio_starttls);
args.putBoolean("insecure", cbInsecure.isChecked()); args.putBoolean("insecure", cbInsecure.isChecked());
args.putString("port", etPort.getText().toString()); args.putString("port", etPort.getText().toString());
args.putString("user", etUser.getText().toString()); args.putString("user", etUser.getText().toString());
@ -754,7 +755,7 @@ public class FragmentIdentity extends FragmentBase {
TextUtils.isEmpty(identity.signature) ? null : HtmlHelper.fromHtml(identity.signature)); TextUtils.isEmpty(identity.signature) ? null : HtmlHelper.fromHtml(identity.signature));
etHost.setText(identity == null ? null : identity.host); etHost.setText(identity == null ? null : identity.host);
cbStartTls.setChecked(identity == null ? false : identity.starttls); rgEncryption.check(identity != null && identity.starttls ? R.id.radio_starttls : R.id.radio_ssl);
cbInsecure.setChecked(identity == null ? false : identity.insecure); cbInsecure.setChecked(identity == null ? false : identity.insecure);
etPort.setText(identity == null ? null : Long.toString(identity.port)); etPort.setText(identity == null ? null : Long.toString(identity.port));
etUser.setTag(identity == null || auth_type == Helper.AUTH_TYPE_PASSWORD ? null : identity.user); etUser.setTag(identity == null || auth_type == Helper.AUTH_TYPE_PASSWORD ? null : identity.user);

@ -121,14 +121,30 @@
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/tvHost" /> app:layout_constraintTop_toBottomOf="@id/tvHost" />
<CheckBox <!-- SSL/STARTTLS -->
android:id="@+id/cbStartTls"
android:layout_width="wrap_content" <RadioGroup
android:id="@+id/rgEncryption"
android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginTop="12dp" android:layout_marginTop="12dp"
android:text="@string/title_starttls" android:orientation="horizontal"
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/etHost" /> app:layout_constraintTop_toBottomOf="@id/etHost">
<RadioButton
android:id="@+id/radio_ssl"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/title_ssl" />
<RadioButton
android:id="@+id/radio_starttls"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="12dp"
android:text="@string/title_starttls" />
</RadioGroup>
<CheckBox <CheckBox
android:id="@+id/cbInsecure" android:id="@+id/cbInsecure"
@ -137,7 +153,7 @@
android:layout_marginTop="12dp" android:layout_marginTop="12dp"
android:text="@string/title_allow_insecure" android:text="@string/title_allow_insecure"
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/cbStartTls" /> app:layout_constraintTop_toBottomOf="@id/rgEncryption" />
<!-- port --> <!-- port -->
@ -697,7 +713,7 @@
android:layout_height="0dp" android:layout_height="0dp"
app:constraint_referenced_ids=" app:constraint_referenced_ids="
tvDomain,tvDomainHint,etDomain,btnAutoConfig, tvDomain,tvDomainHint,etDomain,btnAutoConfig,
tvImap,tvPopSupport,tvHost,etHost,cbStartTls,cbInsecure,tvPort,etPort" /> tvImap,tvPopSupport,tvHost,etHost,rgEncryption,cbInsecure,tvPort,etPort" />
<androidx.constraintlayout.widget.Group <androidx.constraintlayout.widget.Group
android:id="@+id/grpAuthorize" android:id="@+id/grpAuthorize"

@ -274,16 +274,30 @@
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/tvHost" /> app:layout_constraintTop_toBottomOf="@id/tvHost" />
<!-- STARTTLS --> <!-- SSL/STARTTLS -->
<CheckBox <RadioGroup
android:id="@+id/cbStartTls" android:id="@+id/rgEncryption"
android:layout_width="wrap_content" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginTop="12dp" android:layout_marginTop="12dp"
android:text="@string/title_starttls" android:orientation="horizontal"
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/etHost" /> app:layout_constraintTop_toBottomOf="@id/etHost">
<RadioButton
android:id="@+id/radio_ssl"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/title_ssl" />
<RadioButton
android:id="@+id/radio_starttls"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="12dp"
android:text="@string/title_starttls" />
</RadioGroup>
<CheckBox <CheckBox
android:id="@+id/cbInsecure" android:id="@+id/cbInsecure"
@ -292,7 +306,7 @@
android:layout_marginTop="12dp" android:layout_marginTop="12dp"
android:text="@string/title_allow_insecure" android:text="@string/title_allow_insecure"
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/cbStartTls" /> app:layout_constraintTop_toBottomOf="@id/rgEncryption" />
<!-- port --> <!-- port -->
@ -594,7 +608,7 @@
app:constraint_referenced_ids=" app:constraint_referenced_ids="
tvProvider,spProvider, tvProvider,spProvider,
tvDomain,tvDomainHint,etDomain,btnAutoConfig, tvDomain,tvDomainHint,etDomain,btnAutoConfig,
tvSmtp,tvHost,etHost,cbStartTls,cbInsecure,tvPort,etPort, tvSmtp,tvHost,etHost,rgEncryption,cbInsecure,tvPort,etPort,
tvUser,etUser,tvPassword,tilPassword, tvUser,etUser,tvPassword,tilPassword,
tvRealm,etRealm, tvRealm,etRealm,
cbUseIp,tvUseIpHint, cbUseIp,tvUseIpHint,

@ -234,6 +234,7 @@
<string name="title_provider">Provider</string> <string name="title_provider">Provider</string>
<string name="title_custom">Custom</string> <string name="title_custom">Custom</string>
<string name="title_host">Host name</string> <string name="title_host">Host name</string>
<string name="title_ssl" translatable="false">SSL</string>
<string name="title_starttls" translatable="false">STARTTLS</string> <string name="title_starttls" translatable="false">STARTTLS</string>
<string name="title_allow_insecure">Allow insecure connections</string> <string name="title_allow_insecure">Allow insecure connections</string>
<string name="title_port">Port number</string> <string name="title_port">Port number</string>

@ -27,6 +27,7 @@
<item name="android:buttonStyle">@style/buttonStyle</item> <item name="android:buttonStyle">@style/buttonStyle</item>
<item name="android:buttonStyleSmall">@style/buttonStyleSmall</item> <item name="android:buttonStyleSmall">@style/buttonStyleSmall</item>
<item name="android:buttonStyleToggle">@style/buttonStyleToggle</item> <item name="android:buttonStyleToggle">@style/buttonStyleToggle</item>
<item name="android:radioButtonStyle">@style/radioButtonStyle</item>
</style> </style>
<style name="AppThemeDark" parent="Base.Theme.AppCompat"> <style name="AppThemeDark" parent="Base.Theme.AppCompat">
@ -49,6 +50,7 @@
<item name="android:buttonStyle">@style/buttonStyle</item> <item name="android:buttonStyle">@style/buttonStyle</item>
<item name="android:buttonStyleSmall">@style/buttonStyleSmall</item> <item name="android:buttonStyleSmall">@style/buttonStyleSmall</item>
<item name="android:buttonStyleToggle">@style/buttonStyleToggle</item> <item name="android:buttonStyleToggle">@style/buttonStyleToggle</item>
<item name="android:radioButtonStyle">@style/radioButtonStyle</item>
</style> </style>
<style name="AppThemeBlack" parent="AppThemeDark"> <style name="AppThemeBlack" parent="AppThemeDark">
@ -89,4 +91,9 @@
<style name="buttonStyleToggle" parent="Base.Widget.AppCompat.Button"> <style name="buttonStyleToggle" parent="Base.Widget.AppCompat.Button">
<item name="android:textAppearance">@style/TextAppearance.AppCompat.Medium</item> <item name="android:textAppearance">@style/TextAppearance.AppCompat.Medium</item>
</style> </style>
<style name="radioButtonStyle" parent="Base.Widget.AppCompat.CompoundButton.RadioButton">
<item name="android:textAppearance">@style/TextAppearance.AppCompat.Small</item>
<item name="android:textColor">?android:attr/textColorSecondary</item>
</style>
</resources> </resources>

Loading…
Cancel
Save