summaryrefslogtreecommitdiff
path: root/app/src/insecure/java/se/leap/bitmaskclient/AddProviderActivity.java
diff options
context:
space:
mode:
Diffstat (limited to 'app/src/insecure/java/se/leap/bitmaskclient/AddProviderActivity.java')
-rw-r--r--app/src/insecure/java/se/leap/bitmaskclient/AddProviderActivity.java127
1 files changed, 45 insertions, 82 deletions
diff --git a/app/src/insecure/java/se/leap/bitmaskclient/AddProviderActivity.java b/app/src/insecure/java/se/leap/bitmaskclient/AddProviderActivity.java
index a63174c8..10608a14 100644
--- a/app/src/insecure/java/se/leap/bitmaskclient/AddProviderActivity.java
+++ b/app/src/insecure/java/se/leap/bitmaskclient/AddProviderActivity.java
@@ -1,126 +1,89 @@
package se.leap.bitmaskclient;
-import android.content.Intent;
import android.os.Bundle;
-import android.support.design.widget.TextInputEditText;
-import android.support.design.widget.TextInputLayout;
-import android.text.Editable;
-import android.text.TextWatcher;
import android.view.View;
import android.widget.Button;
import android.widget.CheckBox;
-
-import javax.inject.Inject;
+import android.widget.LinearLayout;
+import android.widget.RelativeLayout;
import butterknife.InjectView;
+import butterknife.Optional;
import se.leap.bitmaskclient.ProviderListContent.ProviderItem;
-public class AddProviderActivity extends ConfigWizardBaseActivity {
-
- final public static String TAG = "AddProviderActivity";
- final public static String EXTRAS_KEY_NEW_URL = "NEW_URL";
+import static android.widget.RelativeLayout.BELOW;
+import static android.widget.RelativeLayout.LEFT_OF;
- @InjectView(R.id.text_uri_error)
- TextInputLayout urlError;
+public class AddProviderActivity extends AddProviderBaseActivity {
- @InjectView(R.id.text_uri)
- TextInputEditText editUrl;
+ final public static String TAG = "AddProviderActivity";
@InjectView(R.id.danger_checkbox)
CheckBox checkboxDanger;
+ @InjectView(R.id.button_save)
+ Button saveButton;
+
+ @Optional
+ @InjectView(R.id.button_container)
+ LinearLayout buttonContainer;
+
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
-
setContentView(R.layout.a_add_provider);
- if (this.getIntent().getExtras() != null) {
- editUrl.setText(this.getIntent().getExtras().getString(ProviderListBaseActivity.EXTRAS_KEY_INVALID_URL));
- }
+ init();
checkboxDanger.setVisibility(View.VISIBLE);
checkboxDanger.setText(R.string.danger_checkbox);
checkboxDanger.setChecked(preferences.getBoolean(ProviderItem.DANGER_ON, false));
+ }
- final Button saveButton = findViewById(R.id.button_save);
+ @Override
+ public void setupSaveButton() {
saveButton.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
preferences.edit().putBoolean(ProviderItem.DANGER_ON, checkboxDanger.isChecked()).apply();
saveProvider();
}
});
-
- final Button cancelButton = findViewById(R.id.button_cancel);
- cancelButton.setOnClickListener(new View.OnClickListener() {
- public void onClick(View v) {
- finish();
- }
- });
- setUpListeners();
- setUpInitialUI();
}
- private void setUpInitialUI() {
- setProviderHeaderText(R.string.add_provider);
- hideProgressBar();
+ @Override
+ protected void showCompactLayout() {
+ if (isCompactLayout) {
+ return;
+ }
+ super.showCompactLayout();
+ showCompactButtonLayout();
}
- private void saveProvider() {
- String entered_url = getURL();
- if (validURL(entered_url)) {
- Intent intent = this.getIntent();
- intent.putExtra(EXTRAS_KEY_NEW_URL, entered_url);
- setResult(RESULT_OK, intent);
- finish();
- } else {
- editUrl.setText("");
- urlError.setError(getString(R.string.not_valid_url_entered));
+ @Override
+ protected void showStandardLayout() {
+ if (!isCompactLayout) {
+ return;
}
+ super.showStandardLayout();
+ showStandardButtonLayout();
}
- private void setUpListeners() {
-
- editUrl.addTextChangedListener(new TextWatcher() {
- @Override
- public void beforeTextChanged(CharSequence s, int start, int count, int after) {
- }
-
- @Override
- public void onTextChanged(CharSequence s, int start, int before, int count) {
- }
+ private void showCompactButtonLayout() {
+ RelativeLayout.LayoutParams phoneButtonContainerParams = (RelativeLayout.LayoutParams) buttonContainer.getLayoutParams();
+ phoneButtonContainerParams.addRule(BELOW, 0);
+ buttonContainer.setLayoutParams(phoneButtonContainerParams);
- @Override
- public void afterTextChanged(Editable s) {
- if (!validURL(getURL())) {
- urlError.setError(getString(R.string.not_valid_url_entered));
- } else {
- urlError.setError(null);
- }
- }
- });
+ RelativeLayout.LayoutParams checkBoxParams = (RelativeLayout.LayoutParams) checkboxDanger.getLayoutParams();
+ checkBoxParams.addRule(LEFT_OF, R.id.button_container);
+ checkboxDanger.setLayoutParams(checkBoxParams);
}
- private String getURL() {
- String entered_url = editUrl.getText().toString().trim();
- if (entered_url.contains("www.")) entered_url = entered_url.replaceFirst("www.", "");
- if (!entered_url.startsWith("https://")) {
- if (entered_url.startsWith("http://")) {
- entered_url = entered_url.substring("http://".length());
- }
- entered_url = "https://".concat(entered_url);
- }
- return entered_url;
- }
+ private void showStandardButtonLayout() {
+ RelativeLayout.LayoutParams phoneButtonContainerParams = (RelativeLayout.LayoutParams) buttonContainer.getLayoutParams();
+ phoneButtonContainerParams.addRule(BELOW, R.id.danger_checkbox);
+ buttonContainer.setLayoutParams(phoneButtonContainerParams);
- /**
- * Checks if the entered url is valid or not.
- *
- * @param enteredUrl
- * @return true if it's not empty nor contains only the protocol.
- */
- boolean validURL(String enteredUrl) {
- return android.util.Patterns.WEB_URL.matcher(enteredUrl).matches();
+ RelativeLayout.LayoutParams checkBoxParams = (RelativeLayout.LayoutParams) checkboxDanger.getLayoutParams();
+ checkBoxParams.addRule(LEFT_OF, 0);
+ checkboxDanger.setLayoutParams(checkBoxParams);
}
-
-
}