Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/registration usability #724

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 2 additions & 9 deletions src/org/thoughtcrime/securesms/CountrySelectionFragment.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import com.actionbarsherlock.app.SherlockListFragment;

import org.thoughtcrime.securesms.database.loaders.CountryListLoader;
import org.thoughtcrime.securesms.util.TextWatcherAfterTextChanged;

import java.util.ArrayList;
import java.util.Map;
Expand Down Expand Up @@ -80,21 +81,13 @@ public interface CountrySelectedListener {
public void countrySelected(String countryName, int countryCode);
}

private class FilterWatcher implements TextWatcher {
private class FilterWatcher extends TextWatcherAfterTextChanged {

@Override
public void afterTextChanged(Editable s) {
if (getListAdapter() != null) {
((SimpleAdapter)getListAdapter()).getFilter().filter(s.toString());
}
}

@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
}

@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
}
}
}
47 changes: 21 additions & 26 deletions src/org/thoughtcrime/securesms/RegistrationActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import com.google.i18n.phonenumbers.Phonenumber;

import org.thoughtcrime.securesms.util.ActionBarUtil;
import org.thoughtcrime.securesms.util.TextWatcherAfterTextChanged;
import org.whispersystems.textsecure.crypto.MasterSecret;
import org.thoughtcrime.securesms.util.TextSecurePreferences;
import org.whispersystems.textsecure.util.PhoneNumberFormatter;
Expand All @@ -49,6 +50,7 @@ public class RegistrationActivity extends SherlockActivity {
private TextView number;
private Button createButton;
private Button skipButton;
private TelephonyManager telephonyManager;

private MasterSecret masterSecret;

Expand All @@ -59,6 +61,8 @@ public void onCreate(Bundle icicle) {

ActionBarUtil.initializeDefaultActionBar(this, getSupportActionBar(), getString(R.string.RegistrationActivity_connect_with_textsecure));

telephonyManager = ((TelephonyManager)getSystemService(Context.TELEPHONY_SERVICE));

initializeResources();
initializeSpinner();
initializeNumber();
Expand All @@ -67,12 +71,16 @@ public void onCreate(Bundle icicle) {
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == PICK_COUNTRY && resultCode == RESULT_OK && data != null) {
this.countryCode.setText(data.getIntExtra("country_code", 1)+"");
setCountryDisplay(data.getStringExtra("country_name"));
setCountryFormatter(data.getIntExtra("country_code", 1));
setCountryCodeAndName(data.getIntExtra("country_code", 1), data.getStringExtra("country_name"));
}
}

private void setCountryCodeAndName(int countryCode, String countryName) {
this.countryCode.setText(countryCode + "");
setCountryDisplay(countryName);
setCountryFormatter(countryCode);
}

private void initializeResources() {
this.masterSecret = getIntent().getParcelableExtra("master_secret");
this.countrySpinner = (Spinner)findViewById(R.id.country_spinner);
Expand All @@ -90,8 +98,13 @@ private void initializeResources() {
private void initializeSpinner() {
this.countrySpinnerAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item);
this.countrySpinnerAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);

setCountryDisplay(getString(R.string.RegistrationActivity_select_your_country));

String simCountryIso = telephonyManager.getSimCountryIso().toUpperCase();

if (simCountryIso != null)
setCountryCodeAndName(PhoneNumberUtil.getInstance().getCountryCodeForRegion(simCountryIso), PhoneNumberFormatter.getRegionDisplayName(simCountryIso));
else
setCountryDisplay(getString(R.string.RegistrationActivity_select_your_country));

this.countrySpinner.setAdapter(this.countrySpinnerAdapter);
this.countrySpinner.setOnTouchListener(new View.OnTouchListener() {
Expand All @@ -107,8 +120,7 @@ public boolean onTouch(View v, MotionEvent event) {
}

private void initializeNumber() {
String localNumber = ((TelephonyManager)getSystemService(Context.TELEPHONY_SERVICE))
.getLine1Number();
String localNumber = telephonyManager.getLine1Number();

if (!Util.isEmpty(localNumber) && !localNumber.startsWith("+")) {
if (localNumber.length() == 10) localNumber = "+1" + localNumber;
Expand Down Expand Up @@ -206,7 +218,7 @@ public void onClick(DialogInterface dialog, int which) {
}
}

private class CountryCodeChangedListener implements TextWatcher {
private class CountryCodeChangedListener extends TextWatcherAfterTextChanged {
@Override
public void afterTextChanged(Editable s) {
if (Util.isEmpty(s)) {
Expand All @@ -225,17 +237,9 @@ public void afterTextChanged(Editable s) {
number.requestFocus();
}
}

@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 class NumberChangedListener implements TextWatcher {
private class NumberChangedListener extends TextWatcherAfterTextChanged {

@Override
public void afterTextChanged(Editable s) {
Expand All @@ -258,15 +262,6 @@ public void afterTextChanged(Editable s) {
s.replace(0, s.length(), formattedNumber);
}
}

@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 class CancelButtonListener implements View.OnClickListener {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package org.thoughtcrime.securesms.util;

import android.text.TextWatcher;

public abstract class TextWatcherAfterTextChanged implements 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) {
}

}