Use an dialog to show advanced settings
This commit is contained in:
committed by
Galen Abell
parent
78a7f1319e
commit
bcfa8ac221
@@ -0,0 +1,96 @@
|
||||
package com.github.gotify.login;
|
||||
|
||||
import android.app.AlertDialog;
|
||||
import android.content.Context;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.widget.Button;
|
||||
import android.widget.CheckBox;
|
||||
import android.widget.CompoundButton;
|
||||
import android.widget.TextView;
|
||||
import androidx.annotation.Nullable;
|
||||
import butterknife.BindView;
|
||||
import butterknife.ButterKnife;
|
||||
import com.github.gotify.R;
|
||||
|
||||
class AdvancedDialog {
|
||||
|
||||
private Context context;
|
||||
private ViewHolder holder;
|
||||
private CompoundButton.OnCheckedChangeListener onCheckedChangeListener;
|
||||
private Runnable onClickSelectCaCertificate;
|
||||
private Runnable onClickRemoveCaCertificate;
|
||||
|
||||
AdvancedDialog(Context context) {
|
||||
this.context = context;
|
||||
}
|
||||
|
||||
AdvancedDialog onDisableSSLChanged(
|
||||
CompoundButton.OnCheckedChangeListener onCheckedChangeListener) {
|
||||
this.onCheckedChangeListener = onCheckedChangeListener;
|
||||
return this;
|
||||
}
|
||||
|
||||
AdvancedDialog onClickSelectCaCertificate(Runnable onClickSelectCaCertificate) {
|
||||
this.onClickSelectCaCertificate = onClickSelectCaCertificate;
|
||||
return this;
|
||||
}
|
||||
|
||||
AdvancedDialog onClickRemoveCaCertificate(Runnable onClickRemoveCaCertificate) {
|
||||
this.onClickRemoveCaCertificate = onClickRemoveCaCertificate;
|
||||
return this;
|
||||
}
|
||||
|
||||
AdvancedDialog show(boolean disableSSL, @Nullable String selectedCertificate) {
|
||||
|
||||
View dialogView =
|
||||
LayoutInflater.from(context).inflate(R.layout.advanced_settings_dialog, null);
|
||||
holder = new ViewHolder(dialogView);
|
||||
holder.disableSSL.setChecked(disableSSL);
|
||||
holder.disableSSL.setOnCheckedChangeListener(onCheckedChangeListener);
|
||||
|
||||
if (selectedCertificate == null) {
|
||||
showSelectCACertificate();
|
||||
} else {
|
||||
showRemoveCACertificate(selectedCertificate);
|
||||
}
|
||||
|
||||
new AlertDialog.Builder(context)
|
||||
.setView(dialogView)
|
||||
.setTitle("Advanced Settings")
|
||||
.setPositiveButton("Done", (ignored, ignored2) -> {})
|
||||
.show();
|
||||
return this;
|
||||
}
|
||||
|
||||
private void showSelectCACertificate() {
|
||||
holder.toggleCaCert.setText("Select CA Certificate");
|
||||
holder.toggleCaCert.setOnClickListener((a) -> onClickSelectCaCertificate.run());
|
||||
holder.selectedCaCertificate.setText("No certificate selected");
|
||||
}
|
||||
|
||||
void showRemoveCACertificate(String certificate) {
|
||||
holder.toggleCaCert.setText("Remove CA Certificate");
|
||||
holder.toggleCaCert.setOnClickListener(
|
||||
(a) -> {
|
||||
showSelectCACertificate();
|
||||
onClickRemoveCaCertificate.run();
|
||||
});
|
||||
holder.selectedCaCertificate.setText(certificate);
|
||||
}
|
||||
|
||||
class ViewHolder {
|
||||
@BindView(R.id.disableSSL)
|
||||
CheckBox disableSSL;
|
||||
|
||||
@BindView(R.id.toggle_ca_cert)
|
||||
Button toggleCaCert;
|
||||
|
||||
@BindView(R.id.seleceted_ca_cert)
|
||||
TextView selectedCaCertificate;
|
||||
|
||||
ViewHolder(View view) {
|
||||
ButterKnife.bind(this, view);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user