From 33e6df4819c63200db55ddd3c167e64eac9819fb Mon Sep 17 00:00:00 2001 From: Stefan Niedermann Date: Thu, 21 Jan 2016 20:34:58 +0100 Subject: [PATCH] #45 On initial start, deactivate connect button initially --- app/app.iml | 2 ++ .../android/activity/SettingsActivity.java | 30 ++++++++++++++++++- 2 files changed, 31 insertions(+), 1 deletion(-) diff --git a/app/app.iml b/app/app.iml index 97a66a491..6485ce487 100644 --- a/app/app.iml +++ b/app/app.iml @@ -71,6 +71,7 @@ + @@ -91,6 +92,7 @@ + diff --git a/app/src/main/java/it/niedermann/owncloud/notes/android/activity/SettingsActivity.java b/app/src/main/java/it/niedermann/owncloud/notes/android/activity/SettingsActivity.java index 8841b5fa5..f1d9fb89f 100644 --- a/app/src/main/java/it/niedermann/owncloud/notes/android/activity/SettingsActivity.java +++ b/app/src/main/java/it/niedermann/owncloud/notes/android/activity/SettingsActivity.java @@ -66,7 +66,7 @@ public void beforeTextChanged(CharSequence s, int start, int count, int after) { @Override public void onTextChanged(CharSequence s, int start, int before, int count) { - String url = ((EditText) findViewById(R.id.settings_url)).getText().toString(); + String url = field_url.getText().toString(); if (!url.endsWith("/")) { url += "/"; @@ -81,6 +81,8 @@ public void onTextChanged(CharSequence s, int start, int before, int count) { } else { findViewById(R.id.settings_url_warn_http).setVisibility(View.GONE); } + + handleSubmitButtonEnabled(field_url.getText(), field_username.getText()); } @Override @@ -88,6 +90,23 @@ public void afterTextChanged(Editable s) { } }); + field_username.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) { + handleSubmitButtonEnabled(field_url.getText(), field_username.getText()); + } + + @Override + public void afterTextChanged(Editable s) { + + } + }); + // Load current Preferences field_url.setText(preferences.getString(SETTINGS_URL, DEFAULT_SETTINGS)); field_username.setText(preferences.getString(SETTINGS_USERNAME, DEFAULT_SETTINGS)); @@ -101,6 +120,7 @@ public boolean onEditorAction(TextView v, int actionId, KeyEvent event) { } }); + btn_submit.setEnabled(false); btn_submit.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { @@ -133,6 +153,14 @@ private void login() { new LoginValidatorAsyncTask().execute(url, username, password); } + private void handleSubmitButtonEnabled(Editable url, Editable username) { + if (field_username.getText().length() > 0 && field_url.getText().length() > 0) { + btn_submit.setEnabled(true); + } else { + btn_submit.setEnabled(false); + } + } + /************************************ Async Tasks ************************************/ /**