diff options
author | Fup Duck <fupduck@sacknagel.com> | 2018-01-19 17:34:45 +0100 |
---|---|---|
committer | Fup Duck <fupduck@sacknagel.com> | 2018-01-19 17:34:45 +0100 |
commit | b065fa48e802487198ad73915dd017c4464e8c62 (patch) | |
tree | df48491884de8e29c52db4794a3233fa34a4a6ff /app/src/main/java/se | |
parent | 1ccb2f9e1bcfaf8279ef9576b3bca233e37af61b (diff) |
improve layout
* improve layout
* gracefully handle orientation changes
* respect small devices
* set correct colors for buttons, error messages...
Diffstat (limited to 'app/src/main/java/se')
7 files changed, 373 insertions, 119 deletions
diff --git a/app/src/main/java/se/leap/bitmaskclient/AbstractProviderDetailActivity.java b/app/src/main/java/se/leap/bitmaskclient/AbstractProviderDetailActivity.java index c5a74490..cb5f334b 100644 --- a/app/src/main/java/se/leap/bitmaskclient/AbstractProviderDetailActivity.java +++ b/app/src/main/java/se/leap/bitmaskclient/AbstractProviderDetailActivity.java @@ -35,7 +35,7 @@ public abstract class AbstractProviderDetailActivity extends ConfigWizardBaseAct @Override protected void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); - setContentView(R.layout.provider_detail_fragment); + setContentView(R.layout.a_provider_detail); try { JSONObject providerJson = new JSONObject(preferences.getString(Provider.KEY, "")); @@ -73,6 +73,7 @@ public abstract class AbstractProviderDetailActivity extends ConfigWizardBaseAct Log.d(TAG, "use anonymously selected"); intent = new Intent(getApplicationContext(), MainActivity.class); } + intent.putExtra(PROVIDER_KEY, provider); intent.setFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION); startActivity(intent); } @@ -82,6 +83,12 @@ public abstract class AbstractProviderDetailActivity extends ConfigWizardBaseAct } } + @Override + protected void onNewIntent(Intent intent) { + super.onNewIntent(intent); + provider = intent.getParcelableExtra(PROVIDER_KEY); + } + private boolean anonAllowed(JSONObject providerJson) { try { JSONObject serviceDescription = providerJson.getJSONObject(Provider.SERVICE); diff --git a/app/src/main/java/se/leap/bitmaskclient/BaseConfigurationWizard.java b/app/src/main/java/se/leap/bitmaskclient/BaseConfigurationWizard.java index 8e4f1607..1025a64e 100644 --- a/app/src/main/java/se/leap/bitmaskclient/BaseConfigurationWizard.java +++ b/app/src/main/java/se/leap/bitmaskclient/BaseConfigurationWizard.java @@ -80,10 +80,11 @@ public abstract class BaseConfigurationWizard extends ConfigWizardBaseActivity private ProviderManager providerManager; protected Intent mConfigState = new Intent(PROVIDER_NOT_SET); - protected Provider selectedProvider; final public static String TAG = ConfigurationWizard.class.getSimpleName(); + final private static String ACTIVITY_STATE = "ACTIVITY STATE"; + final protected static String PROVIDER_NOT_SET = "PROVIDER NOT SET"; final protected static String SETTING_UP_PROVIDER = "PROVIDER GETS SET"; final private static String SHOWING_PROVIDER_DETAILS = "SHOWING PROVIDER DETAILS"; @@ -91,8 +92,6 @@ public abstract class BaseConfigurationWizard extends ConfigWizardBaseActivity final private static String REASON_TO_FAIL = "REASON TO FAIL"; final protected static String SERVICES_RETRIEVED = "SERVICES RETRIEVED"; - final private static String ACTIVITY_STATE = "ACTIVITY STATE"; - public ProviderAPIResultReceiver providerAPIResultReceiver; private ProviderAPIBroadcastReceiver providerAPIBroadcastReceiver; @@ -119,7 +118,7 @@ public abstract class BaseConfigurationWizard extends ConfigWizardBaseActivity //if (progressbarDescription != null) // outState.putString(PROGRESSBAR_TEXT, progressbarDescription.getText().toString()); outState.putString(ACTIVITY_STATE, mConfigState.getAction()); - outState.putParcelable(Provider.KEY, selectedProvider); + outState.putParcelable(Provider.KEY, provider); DialogFragment dialogFragment = (DialogFragment) fragmentManager.findFragmentByTag(DownloadFailedDialog.TAG); if (dialogFragment != null) { @@ -147,7 +146,7 @@ public abstract class BaseConfigurationWizard extends ConfigWizardBaseActivity private void restoreState(Bundle savedInstanceState) { - selectedProvider = savedInstanceState.getParcelable(Provider.KEY); + provider = savedInstanceState.getParcelable(Provider.KEY); mConfigState.setAction(savedInstanceState.getString(ACTIVITY_STATE, PROVIDER_NOT_SET)); reasonToFail = savedInstanceState.getString(REASON_TO_FAIL); @@ -170,7 +169,7 @@ public abstract class BaseConfigurationWizard extends ConfigWizardBaseActivity isActivityShowing = true; if (SETTING_UP_PROVIDER.equals(mConfigState.getAction())) { showProgressBar(); - adapter.hideAllBut(adapter.indexOf(selectedProvider)); + adapter.hideAllBut(adapter.indexOf(provider)); checkProviderSetUp(); } else if (PENDING_SHOW_FAILED_DIALOG.equals(mConfigState.getAction())) { showDownloadFailedDialog(); @@ -212,9 +211,9 @@ public abstract class BaseConfigurationWizard extends ConfigWizardBaseActivity try { String providerJsonString = preferences.getString(Provider.KEY, ""); if (!providerJsonString.isEmpty()) - selectedProvider.define(new JSONObject(providerJsonString)); + provider.define(new JSONObject(providerJsonString)); String caCert = preferences.getString(Provider.CA_CERT, ""); - selectedProvider.setCACert(caCert); + provider.setCACert(caCert); } catch (JSONException e) { e.printStackTrace(); } @@ -267,7 +266,7 @@ public abstract class BaseConfigurationWizard extends ConfigWizardBaseActivity //TODO Code 2 pane view mConfigState.setAction(SETTING_UP_PROVIDER); - selectedProvider = adapter.getItem(position); + provider = adapter.getItem(position); showProgressBar(); onItemSelectedLogic(); } @@ -305,7 +304,7 @@ public abstract class BaseConfigurationWizard extends ConfigWizardBaseActivity providerAPICommand.setAction(ProviderAPI.UPDATE_PROVIDER_DETAILS); Bundle parameters = new Bundle(); - parameters.putString(Provider.MAIN_URL, selectedProvider.getMainUrl().toString()); + parameters.putString(Provider.MAIN_URL, provider.getMainUrl().toString()); providerAPICommand.putExtra(ProviderAPI.PARAMETERS, parameters); startService(providerAPICommand); @@ -391,6 +390,7 @@ public abstract class BaseConfigurationWizard extends ConfigWizardBaseActivity mConfigState.setAction(SHOWING_PROVIDER_DETAILS); Intent intent = new Intent(this, ProviderDetailActivity.class); intent.setFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION); + intent.putExtra(PROVIDER_KEY, provider); startActivity(intent); } } @@ -417,38 +417,42 @@ public abstract class BaseConfigurationWizard extends ConfigWizardBaseActivity public void cancelAndShowAllProviders() { mConfigState.setAction(PROVIDER_NOT_SET); - selectedProvider = null; + provider = null; adapter.showAllProviders(); } public class ProviderAPIBroadcastReceiver extends BroadcastReceiver { @Override public void onReceive(Context context, Intent intent) { - String action = intent.getAction(); + Log.d(TAG, "received Broadcast"); - if (action == null) { + String action = intent.getAction(); + if (action == null || !action.equalsIgnoreCase(PROVIDER_API_EVENT)) { return; } - // TODO check if correct provider given - if (action.equalsIgnoreCase(PROVIDER_API_EVENT) && mConfigState.getAction() != null && + if (mConfigState.getAction() != null && mConfigState.getAction().equalsIgnoreCase(SETTING_UP_PROVIDER)) { int resultCode = intent.getIntExtra(RESULT_CODE, -1); - - switch (resultCode) { - case PROVIDER_OK: - handleProviderSetUp(); - break; - case PROVIDER_NOK: - handleProviderSetupFailed((Bundle) intent.getParcelableExtra(RESULT_KEY)); - break; - case CORRECTLY_DOWNLOADED_CERTIFICATE: - handleCorrectlyDownloadedCertificate(); - break; - case INCORRECTLY_DOWNLOADED_CERTIFICATE: - handleIncorrectlyDownloadedCertificate(); - break; - + Log.d(TAG, "Broadcast resultCode: " + Integer.toString(resultCode)); + + + if (getProviderName().equalsIgnoreCase(provider.getName()) && + getProviderDomain().equalsIgnoreCase(provider.getDomain())) { + switch (resultCode) { + case PROVIDER_OK: + handleProviderSetUp(); + break; + case PROVIDER_NOK: + handleProviderSetupFailed((Bundle) intent.getParcelableExtra(RESULT_KEY)); + break; + case CORRECTLY_DOWNLOADED_CERTIFICATE: + handleCorrectlyDownloadedCertificate(); + break; + case INCORRECTLY_DOWNLOADED_CERTIFICATE: + handleIncorrectlyDownloadedCertificate(); + break; + } } } } diff --git a/app/src/main/java/se/leap/bitmaskclient/ConfigWizardBaseActivity.java b/app/src/main/java/se/leap/bitmaskclient/ConfigWizardBaseActivity.java index 3e83d9bc..98715c1a 100644 --- a/app/src/main/java/se/leap/bitmaskclient/ConfigWizardBaseActivity.java +++ b/app/src/main/java/se/leap/bitmaskclient/ConfigWizardBaseActivity.java @@ -5,6 +5,7 @@ import android.os.Bundle; import android.support.annotation.DrawableRes; import android.support.annotation.Nullable; import android.support.annotation.StringRes; +import android.support.v4.app.FragmentTransaction; import android.support.v7.widget.AppCompatImageView; import android.support.v7.widget.AppCompatTextView; import android.view.View; @@ -14,10 +15,14 @@ import android.widget.LinearLayout; import org.json.JSONException; import org.json.JSONObject; +import java.util.Locale; + import butterknife.InjectView; +import se.leap.bitmaskclient.userstatus.SessionDialog; import static android.view.View.GONE; import static android.view.View.VISIBLE; +import static se.leap.bitmaskclient.Constants.PROVIDER_KEY; import static se.leap.bitmaskclient.Constants.SHARED_PREFERENCES; /** @@ -45,10 +50,14 @@ public abstract class ConfigWizardBaseActivity extends ButterKnifeActivity { @InjectView(R.id.content) protected LinearLayout content; + protected Provider provider; + @Override protected void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); preferences = getSharedPreferences(SHARED_PREFERENCES, MODE_PRIVATE); + + provider = getIntent().getParcelableExtra(PROVIDER_KEY); } @Override @@ -84,12 +93,26 @@ public abstract class ConfigWizardBaseActivity extends ButterKnifeActivity { protected String getProviderName() { try { JSONObject providerJson = new JSONObject(preferences.getString(Provider.KEY, "")); - return providerJson.getJSONObject(Provider.NAME).getString("en"); + String lang = Locale.getDefault().getLanguage(); + return providerJson.getJSONObject(Provider.NAME).getString(lang); } catch (JSONException e) { - return null; + try { + JSONObject providerJson = new JSONObject(preferences.getString(Provider.KEY, "")); + return providerJson.getJSONObject(Provider.NAME).getString("en"); + } catch (JSONException e2) { + return null; + } } } + protected String getProviderDomain() { + try { + JSONObject providerJson = new JSONObject(preferences.getString(Provider.KEY, "")); + return providerJson.getString(Provider.DOMAIN); + } catch (JSONException e) { + return null; + } + } protected void hideProgressBar() { loadingScreen.setVisibility(GONE); content.setVisibility(VISIBLE); diff --git a/app/src/main/java/se/leap/bitmaskclient/LoginActivity.java b/app/src/main/java/se/leap/bitmaskclient/LoginActivity.java index 06cf5b89..6ae288c2 100644 --- a/app/src/main/java/se/leap/bitmaskclient/LoginActivity.java +++ b/app/src/main/java/se/leap/bitmaskclient/LoginActivity.java @@ -16,7 +16,6 @@ public class LoginActivity extends ProviderCredentialsBaseActivity { @Override protected void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); - setContentView(R.layout.a_login); setProgressbarText(R.string.logging_in); setProviderHeaderLogo(R.drawable.mask); setProviderHeaderText(R.string.login_to_profile); @@ -30,6 +29,7 @@ public class LoginActivity extends ProviderCredentialsBaseActivity { @Override @OnClick(R.id.button) void handleButton() { + super.handleButton(); login(getUsername(), getPassword()); } diff --git a/app/src/main/java/se/leap/bitmaskclient/Provider.java b/app/src/main/java/se/leap/bitmaskclient/Provider.java index 60b1b93c..95daccc6 100644 --- a/app/src/main/java/se/leap/bitmaskclient/Provider.java +++ b/app/src/main/java/se/leap/bitmaskclient/Provider.java @@ -158,9 +158,13 @@ public final class Provider implements Parcelable { name = definition.getJSONObject(API_TERM_NAME).getString(lang); else throw new JSONException("Provider not defined"); } catch (JSONException e) { - if (mainUrl != null) { - String host = mainUrl.getDomain(); - name = host.substring(0, host.indexOf(".")); + try { + name = definition.getJSONObject(API_TERM_NAME).getString("en"); + } catch (JSONException e2) { + if (mainUrl != null) { + String host = mainUrl.getDomain(); + name = host.substring(0, host.indexOf(".")); + } } } diff --git a/app/src/main/java/se/leap/bitmaskclient/ProviderCredentialsBaseActivity.java b/app/src/main/java/se/leap/bitmaskclient/ProviderCredentialsBaseActivity.java index c15481e5..1d1908a6 100644 --- a/app/src/main/java/se/leap/bitmaskclient/ProviderCredentialsBaseActivity.java +++ b/app/src/main/java/se/leap/bitmaskclient/ProviderCredentialsBaseActivity.java @@ -1,18 +1,36 @@ package se.leap.bitmaskclient; +import android.content.BroadcastReceiver; +import android.content.Context; import android.content.Intent; +import android.content.IntentFilter; import android.os.Bundle; -import android.os.Handler; import android.support.annotation.Nullable; import android.support.annotation.StringRes; import android.support.design.widget.TextInputEditText; +import android.support.design.widget.TextInputLayout; import android.support.v7.widget.AppCompatButton; +import android.support.v7.widget.AppCompatTextView; +import android.text.Editable; +import android.text.TextWatcher; +import android.util.Log; +import android.view.KeyEvent; +import android.widget.TextView; import butterknife.InjectView; import butterknife.OnClick; import se.leap.bitmaskclient.userstatus.SessionDialog; +import se.leap.bitmaskclient.userstatus.SessionDialog.ERRORS; import se.leap.bitmaskclient.userstatus.User; +import static android.view.View.GONE; +import static android.view.View.VISIBLE; +import static android.view.inputmethod.EditorInfo.IME_ACTION_DONE; +import static se.leap.bitmaskclient.ProviderAPI.PROVIDER_API_EVENT; +import static se.leap.bitmaskclient.ProviderAPI.RESULT_CODE; +import static se.leap.bitmaskclient.ProviderAPI.RESULT_KEY; +import static se.leap.bitmaskclient.userstatus.SessionDialog.USERNAME; + /** * Base Activity for activities concerning a provider interaction * @@ -21,56 +39,168 @@ import se.leap.bitmaskclient.userstatus.User; public abstract class ProviderCredentialsBaseActivity extends ConfigWizardBaseActivity { - protected ProviderAPIResultReceiver providerAPIResultReceiver; + final protected static String TAG = ProviderCredentialsBaseActivity.class.getName(); + + final private static String ACTIVITY_STATE = "ACTIVITY STATE"; + + final private static String SHOWING_FORM = "SHOWING_FORM"; + final private static String PERFORMING_ACTION = "PERFORMING_ACTION"; + final private static String USER_MESSAGE = "USER_MESSAGE"; + final private static String USERNAME_ERROR = "USERNAME_ERROR"; + final private static String PASSWORD_ERROR = "PASSWORD_ERROR"; + final private static String PASSWORD_VERIFICATION_ERROR = "PASSWORD_VERIFICATION_ERROR"; + + protected Intent mConfigState = new Intent(SHOWING_FORM); + protected ProviderAPIBroadcastReceiver providerAPIBroadcastReceiver; + + @InjectView(R.id.provider_credentials_user_message) + AppCompatTextView userMessage; @InjectView(R.id.provider_credentials_username) - TextInputEditText providerCredentialsUsername; + TextInputEditText usernameField; @InjectView(R.id.provider_credentials_password) - TextInputEditText providerCredentialsPassword; + TextInputEditText passwordField; + + @InjectView(R.id.provider_credentials_password_verification) + TextInputEditText passwordVerificationField; + + @InjectView(R.id.provider_credentials_username_error) + TextInputLayout usernameError; + + @InjectView(R.id.provider_credentials_password_error) + TextInputLayout passwordError; + + @InjectView(R.id.provider_credentials_password_verification_error) + TextInputLayout passwordVerificationError; @InjectView(R.id.button) - AppCompatButton providerCredentialsButton; + AppCompatButton button; @Override protected void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); - providerAPIResultReceiver = new ProviderAPIResultReceiver(new Handler(), new ProviderCredentialsReceiver(this)); + setContentView(R.layout.a_provider_credentials); + providerAPIBroadcastReceiver = new ProviderAPIBroadcastReceiver(); + + IntentFilter updateIntentFilter = new IntentFilter(PROVIDER_API_EVENT); + updateIntentFilter.addCategory(Intent.CATEGORY_DEFAULT); + registerReceiver(providerAPIBroadcastReceiver, updateIntentFilter); + + setUpListeners(); + if(savedInstanceState != null) { + restoreState(savedInstanceState); + } + } + + @Override + protected void onResume() { + super.onResume(); + + String action = mConfigState.getAction(); + if (action == null) { + return; + } + + if(action.equalsIgnoreCase(PERFORMING_ACTION)) { + showProgressBar(); + } + } + + private void restoreState(Bundle savedInstance) { + if (savedInstance.getString(USER_MESSAGE) != null) { + userMessage.setText(savedInstance.getString(USER_MESSAGE)); + userMessage.setVisibility(VISIBLE); + } + usernameError.setError(savedInstance.getString(USERNAME_ERROR)); + passwordError.setError(savedInstance.getString(PASSWORD_ERROR)); + passwordVerificationError.setError(savedInstance.getString(PASSWORD_VERIFICATION_ERROR)); + if (savedInstance.getString(ACTIVITY_STATE) != null) { + mConfigState.setAction(savedInstance.getString(ACTIVITY_STATE)); + } + } + + @Override + public void onSaveInstanceState(Bundle outState) { + outState.putString(ACTIVITY_STATE, mConfigState.getAction()); + if (userMessage.getText() != null && userMessage.getVisibility() == VISIBLE) { + outState.putString(USER_MESSAGE, userMessage.getText().toString()); + } + if (usernameError.getError() != null) { + outState.putString(USERNAME_ERROR, usernameError.getError().toString()); + } + if (passwordError.getError() != null) { + outState.putString(PASSWORD_ERROR, passwordError.getError().toString()); + } + if (passwordVerificationError.getError() != null) { + outState.putString(PASSWORD_VERIFICATION_ERROR, passwordVerificationError.getError().toString()); + } + + super.onSaveInstanceState(outState); + } + + @Override + protected void onDestroy() { + super.onDestroy(); + if (providerAPIBroadcastReceiver != null) + unregisterReceiver(providerAPIBroadcastReceiver); } @OnClick(R.id.button) - abstract void handleButton(); + void handleButton() { + mConfigState.setAction(PERFORMING_ACTION); + } protected void setButtonText(@StringRes int buttonText) { - providerCredentialsButton.setText(buttonText); + button.setText(buttonText); } String getUsername() { - return providerCredentialsUsername.getText().toString(); + String username = usernameField.getText().toString(); + String providerDomain = provider.getDomain(); + if (username.endsWith(providerDomain)) { + return username.split("@" + providerDomain)[0]; + } + return username; } String getPassword() { - return providerCredentialsPassword.getText().toString(); + return passwordField.getText().toString(); + } + + String getPasswordVerification() { + return passwordVerificationField.getText().toString(); } void login(String username, String password) { showProgressBar(); + User.setUserName(username); - Bundle parameters = bundlePassword(password); - ProviderAPICommand.execute(parameters, ProviderAPI.LOG_IN, providerAPIResultReceiver); - } - void downloadVpnCertificate() { Intent providerAPICommand = new Intent(this, ProviderAPI.class); - ProviderAPICommand.execute(Bundle.EMPTY, ProviderAPI.DOWNLOAD_CERTIFICATE, providerAPIResultReceiver); + Bundle parameters = bundlePassword(password); + providerAPICommand.setAction(ProviderAPI.LOG_IN); + providerAPICommand.putExtra(ProviderAPI.PARAMETERS, parameters); + startService(providerAPICommand); } - public void signUp(String username, String password) { showProgressBar(); + User.setUserName(username); + + Intent providerAPICommand = new Intent(this, ProviderAPI.class); Bundle parameters = bundlePassword(password); - ProviderAPICommand.execute(parameters, ProviderAPI.SIGN_UP, providerAPIResultReceiver); + providerAPICommand.setAction(ProviderAPI.SIGN_UP); + providerAPICommand.putExtra(ProviderAPI.PARAMETERS, parameters); + startService(providerAPICommand); + } + + void downloadVpnCertificate() { + Intent providerAPICommand = new Intent(this, ProviderAPI.class); + providerAPICommand.setAction(ProviderAPI.DOWNLOAD_CERTIFICATE); + providerAPICommand.putExtra(ProviderAPI.PARAMETERS, Bundle.EMPTY); + startService(providerAPICommand); } protected Bundle bundlePassword(String password) { @@ -80,42 +210,162 @@ public abstract class ProviderCredentialsBaseActivity extends ConfigWizardBaseAc return parameters; } - public static class ProviderCredentialsReceiver implements ProviderAPIResultReceiver.Receiver{ + private void setUpListeners() { + usernameField.addTextChangedListener(new TextWatcher() { + @Override + public void beforeTextChanged(CharSequence s, int start, int count, int after) { + } - private ProviderCredentialsBaseActivity activity; + @Override + public void onTextChanged(CharSequence s, int start, int before, int count) { + } + + @Override + public void afterTextChanged(Editable s) { + if (getUsername().equalsIgnoreCase("")) { + usernameError.setError(getString(R.string.username_ask)); + } else { + usernameError.setError(null); + } + } + }); + usernameField.setOnEditorActionListener(new TextView.OnEditorActionListener() { + @Override + public boolean onEditorAction(TextView v, int actionId, KeyEvent event) { + if (actionId == IME_ACTION_DONE + || event != null && event.getAction() == KeyEvent.ACTION_DOWN + && event.getKeyCode() == KeyEvent.KEYCODE_ENTER) { + passwordField.requestFocus(); + return true; + } + return false; + } + }); + + passwordField.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) { + } - ProviderCredentialsReceiver(ProviderCredentialsBaseActivity activity) { - this.activity = activity; + @Override + public void afterTextChanged(Editable s) { + if(getPassword().length() < 8) { + passwordError.setError(getString(R.string.error_not_valid_password_user_message)); + } else { + passwordError.setError(null); + } + } + }); + passwordField.setOnEditorActionListener(new TextView.OnEditorActionListener() { + @Override + public boolean onEditorAction(TextView v, int actionId, KeyEvent event) { + if (actionId == IME_ACTION_DONE + || event != null && event.getAction() == KeyEvent.ACTION_DOWN + && event.getKeyCode() == KeyEvent.KEYCODE_ENTER) { + if (passwordVerificationField.getVisibility() == VISIBLE) { + passwordVerificationField.requestFocus(); + } else { + button.performClick(); + } + return true; + } + return false; + } + }); + + passwordVerificationField.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) { + } + + @Override + public void afterTextChanged(Editable s) { + if(getPassword().equals(getPasswordVerification())) { + passwordVerificationError.setError(null); + } else { + passwordVerificationError.setError(getString(R.string.password_mismatch)); + } + } + }); + passwordVerificationField.setOnEditorActionListener(new TextView.OnEditorActionListener() { + @Override + public boolean onEditorAction(TextView v, int actionId, KeyEvent event) { + if (actionId == IME_ACTION_DONE + || event != null && event.getAction() == KeyEvent.ACTION_DOWN + && event.getKeyCode() == KeyEvent.KEYCODE_ENTER) { + button.performClick(); + return true; + } + return false; + } + }); + } + + private void handleReceivedErrors(Bundle arguments) { + if (arguments.containsKey(ERRORS.PASSWORD_INVALID_LENGTH.toString())) + passwordError.setError(getString(R.string.error_not_valid_password_user_message)); + else if (arguments.containsKey(ERRORS.RISEUP_WARNING.toString())) { + userMessage.setVisibility(VISIBLE); + userMessage.setText(R.string.login_riseup_warning); + } + if (arguments.containsKey(USERNAME)) { + String username = arguments.getString(USERNAME); + usernameField.setText(username); } + if (arguments.containsKey(ERRORS.USERNAME_MISSING.toString())) { + usernameError.setError(getString(R.string.username_ask)); + } + if (arguments.containsKey(getString(R.string.user_message))) { + userMessage.setText(arguments.getString(getString(R.string.user_message))); + userMessage.setVisibility(VISIBLE); + } else if (userMessage.getVisibility() != VISIBLE) { + userMessage.setVisibility(GONE); + } + + if (!usernameField.getText().toString().isEmpty() && passwordField.isFocusable()) + passwordField.requestFocus(); + + hideProgressBar(); + } + public class ProviderAPIBroadcastReceiver extends BroadcastReceiver { @Override - public void onReceiveResult(int resultCode, Bundle resultData) { - if (resultCode == ProviderAPI.SUCCESSFUL_SIGNUP) { - activity.downloadVpnCertificate(); - } else if (resultCode == ProviderAPI.FAILED_SIGNUP) { - //MainActivity.sessionDialog(resultData); - } else if (resultCode == ProviderAPI.SUCCESSFUL_LOGIN) { - activity.downloadVpnCertificate(); - } else if (resultCode == ProviderAPI.FAILED_LOGIN) { - //MainActivity.sessionDialog(resultData); -// TODO MOVE -// } else if (resultCode == ProviderAPI.SUCCESSFUL_LOGOUT) { -// if (switching_provider) activity.switchProvider(); -// } else if (resultCode == ProviderAPI.LOGOUT_FAILED) { -// activity.setResult(RESULT_CANCELED); - } else if (resultCode == ProviderAPI.CORRECTLY_DOWNLOADED_CERTIFICATE) { - Intent intent = new Intent(activity, MainActivity.class); - activity.startActivity(intent); - //activity.eip_fragment.updateEipService(); - } else if (resultCode == ProviderAPI.INCORRECTLY_DOWNLOADED_CERTIFICATE) { - // TODO activity.setResult(RESULT_CANCELED); -// } else if (resultCode == ProviderAPI.CORRECTLY_DOWNLOADED_EIP_SERVICE) { -// activity.eip_fragment.updateEipService(); -// activity.setResult(RESULT_OK); -// } else if (resultCode == ProviderAPI.INCORRECTLY_DOWNLOADED_EIP_SERVICE) { -// activity.setResult(RESULT_CANCELED); + public void onReceive(Context context, Intent intent) { + Log.d(TAG, "received Broadcast"); + + String action = intent.getAction(); + if (action == null || !action.equalsIgnoreCase(PROVIDER_API_EVENT)) { + return; + } + + int resultCode = intent.getIntExtra(RESULT_CODE, -1); + switch (resultCode) { + case ProviderAPI.SUCCESSFUL_SIGNUP: + case ProviderAPI.SUCCESSFUL_LOGIN: + downloadVpnCertificate(); + break; + case ProviderAPI.FAILED_LOGIN: + case ProviderAPI.FAILED_SIGNUP: + handleReceivedErrors((Bundle) intent.getParcelableExtra(RESULT_KEY)); + break; + + case ProviderAPI.CORRECTLY_DOWNLOADED_CERTIFICATE: + intent = new Intent(ProviderCredentialsBaseActivity.this, MainActivity.class); + startActivity(intent); + //activity.eip_fragment.updateEipService(); + break; + case ProviderAPI.INCORRECTLY_DOWNLOADED_CERTIFICATE: + // TODO activity.setResult(RESULT_CANCELED); + break; } } } - } diff --git a/app/src/main/java/se/leap/bitmaskclient/SignupActivity.java b/app/src/main/java/se/leap/bitmaskclient/SignupActivity.java index 448eba52..151e6cdf 100644 --- a/app/src/main/java/se/leap/bitmaskclient/SignupActivity.java +++ b/app/src/main/java/se/leap/bitmaskclient/SignupActivity.java @@ -2,12 +2,7 @@ package se.leap.bitmaskclient; import android.os.Bundle; import android.support.annotation.Nullable; -import android.support.design.widget.TextInputEditText; -import android.support.design.widget.TextInputLayout; -import android.text.Editable; -import android.text.TextWatcher; -import butterknife.InjectView; import butterknife.OnClick; /** @@ -16,52 +11,23 @@ import butterknife.OnClick; public class SignupActivity extends ProviderCredentialsBaseActivity { - @InjectView(R.id.provider_credentials_password_verification) - TextInputEditText providerCredentialsPasswordVerification; - - @InjectView(R.id.provider_credentials_password_verification_layout) - TextInputLayout providerCredentialsPasswordVerificationLayout; - @Override protected void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); - setContentView(R.layout.a_signup); setProviderHeaderLogo(R.drawable.mask); setProviderHeaderText(R.string.create_profile); setProgressbarText(R.string.signing_up); setButtonText(R.string.signup_button); - - providerCredentialsPasswordVerification.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) { - } - - @Override - public void afterTextChanged(Editable s) { - if(getPassword().equals(getPasswordVerification())) { - providerCredentialsPasswordVerificationLayout.setError(null); - } else { - providerCredentialsPasswordVerificationLayout.setError(getString(R.string.password_mismatch)); - } - } - }); } @Override @OnClick(R.id.button) void handleButton() { + super.handleButton(); if (getPassword().equals(getPasswordVerification())) { signUp(getUsername(), getPassword()); } } - - private String getPasswordVerification() { - return providerCredentialsPasswordVerification.getText().toString(); - } } |