diff options
Diffstat (limited to 'src/main/java')
6 files changed, 178 insertions, 31 deletions
diff --git a/src/main/java/eu/siacs/conversations/Config.java b/src/main/java/eu/siacs/conversations/Config.java index 8eca26e04..2fee7211d 100644 --- a/src/main/java/eu/siacs/conversations/Config.java +++ b/src/main/java/eu/siacs/conversations/Config.java @@ -37,6 +37,7 @@ public final class Config { public static final String LOGTAG = "conversations"; public static final String DOMAIN_LOCK = "pix-art.de"; //only allow account creation for this domain + public static final String MAGIC_CREATE_DOMAIN = "pix-art.de"; public static final String CONFERENCE_DOMAIN_LOCK = null; //only allow conference creation for this domain public static final boolean LOCK_DOMAINS_IN_CONVERSATIONS = false; //only add contacts and conferences for own domains public static final boolean LOCK_SETTINGS = false; //set to true to disallow account and settings editing diff --git a/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java b/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java index 6b7bf001f..82fe4a4e2 100644 --- a/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java +++ b/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java @@ -3213,6 +3213,18 @@ public class XmppConnectionService extends Service implements OnPhoneContactsLoa return mPushManagementService; } + public Account getPendingAccount() { + Account pending = null; + for(Account account : getAccounts()) { + if (account.isOptionSet(Account.OPTION_REGISTER)) { + pending = account; + } else { + return null; + } + } + return pending; + } + public interface OnMamPreferencesFetched { void onPreferencesFetched(Element prefs); void onPreferencesFetchFailed(); diff --git a/src/main/java/eu/siacs/conversations/ui/ConversationActivity.java b/src/main/java/eu/siacs/conversations/ui/ConversationActivity.java index ea3cf627a..a7f0f8d72 100644 --- a/src/main/java/eu/siacs/conversations/ui/ConversationActivity.java +++ b/src/main/java/eu/siacs/conversations/ui/ConversationActivity.java @@ -1222,6 +1222,8 @@ public class ConversationActivity extends XmppActivity if (mRedirected.compareAndSet(false, true)) { if (Config.X509_VERIFICATION) { startActivity(new Intent(this, ManageAccountActivity.class)); + } else if (Config.MAGIC_CREATE_DOMAIN != null) { + startActivity(new Intent(this, WelcomeActivity.class)); } else { startActivity(new Intent(this, EditAccountActivity.class)); } @@ -1229,9 +1231,14 @@ public class ConversationActivity extends XmppActivity } } else if (conversationList.size() <= 0) { if (mRedirected.compareAndSet(false, true)) { - Intent intent = new Intent(this, StartConversationActivity.class); - intent.putExtra("init", true); - startActivity(intent); + Account pendingAccount = xmppConnectionService.getPendingAccount(); + if (pendingAccount == null) { + Intent intent = new Intent(this, StartConversationActivity.class); + intent.putExtra("init", true); + startActivity(intent); + } else { + switchToAccount(pendingAccount, true); + } finish(); } } else if (getIntent() != null && VIEW_CONVERSATION.equals(getIntent().getType())) { diff --git a/src/main/java/eu/siacs/conversations/ui/EditAccountActivity.java b/src/main/java/eu/siacs/conversations/ui/EditAccountActivity.java index a8b667cee..c9082f170 100644 --- a/src/main/java/eu/siacs/conversations/ui/EditAccountActivity.java +++ b/src/main/java/eu/siacs/conversations/ui/EditAccountActivity.java @@ -62,13 +62,11 @@ public class EditAccountActivity extends XmppActivity implements OnAccountUpdate private AutoCompleteTextView mAccountJid; private EditText mPassword; - private EditText mPasswordConfirm; private CheckBox mRegisterNew; private Button mCancelButton; private Button mSaveButton; private Button mDisableBatterOptimizations; private TableLayout mMoreTable; - private LinearLayout mStats; private RelativeLayout mBatteryOptimizations; private TextView mServerInfoSm; @@ -174,20 +172,12 @@ public class EditAccountActivity extends XmppActivity implements OnAccountUpdate return; } final String password = mPassword.getText().toString(); - final String passwordConfirm = mPasswordConfirm.getText().toString(); - if (registerNewAccount) { - if (!password.equals(passwordConfirm)) { - mPasswordConfirm.setError(getString(R.string.passwords_do_not_match)); - mPasswordConfirm.requestFocus(); - return; - } - } + if (mAccount != null) { mAccount.setJid(jid); mAccount.setPort(numericPort); mAccount.setHostname(hostname); mAccountJid.setError(null); - mPasswordConfirm.setError(null); mAccount.setPassword(password); mAccount.setOption(Account.OPTION_REGISTER, registerNewAccount); xmppConnectionService.updateAccount(mAccount); @@ -400,7 +390,6 @@ public class EditAccountActivity extends XmppActivity implements OnAccountUpdate } this.mPassword = (EditText) findViewById(R.id.account_password); this.mPassword.addTextChangedListener(this.mTextWatcher); - this.mPasswordConfirm = (EditText) findViewById(R.id.account_password_confirm); this.mAvatar = (ImageView) findViewById(R.id.avater); this.mAvatar.setOnClickListener(this.mAvatarClickListener); this.mRegisterNew = (CheckBox) findViewById(R.id.account_register_new); @@ -447,19 +436,7 @@ public class EditAccountActivity extends XmppActivity implements OnAccountUpdate this.mSaveButton.setOnClickListener(this.mSaveButtonClickListener); this.mCancelButton.setOnClickListener(this.mCancelButtonClickListener); this.mMoreTable = (TableLayout) findViewById(R.id.server_info_more); - final OnCheckedChangeListener OnCheckedShowConfirmPassword = new OnCheckedChangeListener() { - @Override - public void onCheckedChanged(final CompoundButton buttonView, - final boolean isChecked) { - if (isChecked) { - mPasswordConfirm.setVisibility(View.VISIBLE); - } else { - mPasswordConfirm.setVisibility(View.GONE); - } - updateSaveButton(); - } - }; - this.mRegisterNew.setOnCheckedChangeListener(OnCheckedShowConfirmPassword); + if (Config.DISALLOW_REGISTRATION_IN_UI) { this.mRegisterNew.setVisibility(View.GONE); } @@ -546,7 +523,9 @@ public class EditAccountActivity extends XmppActivity implements OnAccountUpdate } updateAccountInformation(true); } - } else if (this.xmppConnectionService.getAccounts().size() == 0) { + } + if (this.xmppConnectionService.getAccounts().size() == 0 + || this.mAccount == xmppConnectionService.getPendingAccount()) { if (getActionBar() != null) { getActionBar().setDisplayHomeAsUpEnabled(false); getActionBar().setDisplayShowHomeEnabled(false); @@ -626,7 +605,6 @@ public class EditAccountActivity extends XmppActivity implements OnAccountUpdate mAccountJid.setEnabled(!Config.LOCK_SETTINGS); mHostname.setEnabled(!Config.LOCK_SETTINGS); mPort.setEnabled(!Config.LOCK_SETTINGS); - mPasswordConfirm.setEnabled(!Config.LOCK_SETTINGS); mRegisterNew.setEnabled(!Config.LOCK_SETTINGS); if (!mInitMode) { @@ -638,7 +616,6 @@ public class EditAccountActivity extends XmppActivity implements OnAccountUpdate if (this.mAccount.isOptionSet(Account.OPTION_REGISTER)) { this.mRegisterNew.setVisibility(View.VISIBLE); this.mRegisterNew.setChecked(true); - this.mPasswordConfirm.setText(this.mAccount.getPassword()); } else { this.mRegisterNew.setVisibility(View.GONE); this.mRegisterNew.setChecked(false); diff --git a/src/main/java/eu/siacs/conversations/ui/MagicCreateActivity.java b/src/main/java/eu/siacs/conversations/ui/MagicCreateActivity.java new file mode 100644 index 000000000..6b32bdc28 --- /dev/null +++ b/src/main/java/eu/siacs/conversations/ui/MagicCreateActivity.java @@ -0,0 +1,113 @@ +package eu.siacs.conversations.ui; + +import android.content.Intent; +import android.os.Bundle; +import android.text.Editable; +import android.text.TextWatcher; +import android.view.View; +import android.widget.Button; +import android.widget.EditText; +import android.widget.TextView; + +import java.security.SecureRandom; + +import eu.siacs.conversations.Config; +import eu.siacs.conversations.R; +import eu.siacs.conversations.entities.Account; +import eu.siacs.conversations.xmpp.jid.InvalidJidException; +import eu.siacs.conversations.xmpp.jid.Jid; + +public class MagicCreateActivity extends XmppActivity implements TextWatcher { + + private TextView mFullJidDisplay; + private EditText mUsername; + private SecureRandom mRandom; + + private static final String CHARS = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456780+-/#$!?"; + private static final int PW_LENGTH = 10; + + @Override + protected void refreshUiReal() { + + } + + @Override + void onBackendConnected() { + + } + + @Override + protected void onCreate(final Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.magic_create); + mFullJidDisplay = (TextView) findViewById(R.id.full_jid); + mUsername = (EditText) findViewById(R.id.username); + mRandom = new SecureRandom(); + Button next = (Button) findViewById(R.id.create_account); + next.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + String username = mUsername.getText().toString(); + if (username.contains("@") || username.length() < 3) { + mUsername.setError(getString(R.string.invalid_username)); + mUsername.requestFocus(); + } else { + mUsername.setError(null); + try { + Jid jid = Jid.fromParts(username.toLowerCase(), Config.MAGIC_CREATE_DOMAIN, null); + Account account = xmppConnectionService.findAccountByJid(jid); + if (account == null) { + account = new Account(jid, createPassword()); + account.setOption(Account.OPTION_REGISTER, true); + account.setOption(Account.OPTION_DISABLED, true); + xmppConnectionService.createAccount(account); + } + Intent intent = new Intent(MagicCreateActivity.this, EditAccountActivity.class); + intent.putExtra("jid", account.getJid().toBareJid().toString()); + intent.putExtra("init", true); + intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK); + startActivity(intent); + } catch (InvalidJidException e) { + mUsername.setError(getString(R.string.invalid_username)); + mUsername.requestFocus(); + } + } + } + }); + mUsername.addTextChangedListener(this); + } + + private String createPassword() { + StringBuilder builder = new StringBuilder(PW_LENGTH); + for(int i = 0; i < PW_LENGTH; ++i) { + builder.append(CHARS.charAt(mRandom.nextInt(CHARS.length() - 1))); + } + return builder.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) { + + } + + @Override + public void afterTextChanged(Editable s) { + if (s.toString().trim().length() > 0) { + try { + mFullJidDisplay.setVisibility(View.VISIBLE); + Jid jid = Jid.fromParts(s.toString().toLowerCase(), Config.MAGIC_CREATE_DOMAIN, null); + mFullJidDisplay.setText(getString(R.string.your_full_jid_will_be, jid.toString())); + } catch (InvalidJidException e) { + mFullJidDisplay.setVisibility(View.INVISIBLE); + } + + } else { + mFullJidDisplay.setVisibility(View.INVISIBLE); + } + } +} diff --git a/src/main/java/eu/siacs/conversations/ui/WelcomeActivity.java b/src/main/java/eu/siacs/conversations/ui/WelcomeActivity.java new file mode 100644 index 000000000..ad6f7ba77 --- /dev/null +++ b/src/main/java/eu/siacs/conversations/ui/WelcomeActivity.java @@ -0,0 +1,37 @@ +package eu.siacs.conversations.ui; + +import android.app.Activity; +import android.content.Intent; +import android.os.Bundle; +import android.view.View; +import android.widget.Button; + +import eu.siacs.conversations.R; + +public class WelcomeActivity extends Activity { + + @Override + protected void onCreate(final Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.welcome); + final Button createAccount = (Button) findViewById(R.id.create_account); + createAccount.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + Intent intent = new Intent(WelcomeActivity.this, MagicCreateActivity.class); + intent.addFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION); + startActivity(intent); + } + }); + final Button useOwnProvider = (Button) findViewById(R.id.use_existing_account); + useOwnProvider.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + startActivity(new Intent(WelcomeActivity.this, EditAccountActivity.class)); + finish(); + } + }); + + } + +} |