diff options
author | Christian Schneppe <christian@pix-art.de> | 2018-05-16 21:31:15 +0200 |
---|---|---|
committer | Christian Schneppe <christian@pix-art.de> | 2018-05-16 21:31:15 +0200 |
commit | 5ca356e4355c286a31a585481d49bd36e83cbfe4 (patch) | |
tree | b5628648f9ea268a3b2b4912950fb71076e405f2 | |
parent | ac3a2c0cb85f32150da93c5d992f71661746e59e (diff) |
add spinner to select jabber provider for creating new accounts
-rw-r--r-- | src/main/java/de/pixart/messenger/ui/MagicCreateActivity.java | 50 | ||||
-rw-r--r-- | src/main/java/de/pixart/messenger/ui/WelcomeActivity.java | 9 | ||||
-rw-r--r-- | src/main/res/layout/activity_magic_create.xml (renamed from src/main/res/layout/magic_create.xml) | 33 | ||||
-rw-r--r-- | src/main/res/values/defaults.xml | 119 | ||||
-rw-r--r-- | src/main/res/values/strings.xml | 2 |
5 files changed, 194 insertions, 19 deletions
diff --git a/src/main/java/de/pixart/messenger/ui/MagicCreateActivity.java b/src/main/java/de/pixart/messenger/ui/MagicCreateActivity.java index b05a43226..76dc84499 100644 --- a/src/main/java/de/pixart/messenger/ui/MagicCreateActivity.java +++ b/src/main/java/de/pixart/messenger/ui/MagicCreateActivity.java @@ -6,23 +6,31 @@ import android.os.Bundle; import android.text.Editable; import android.text.TextWatcher; import android.view.View; +import android.widget.AdapterView; +import android.widget.ArrayAdapter; import android.widget.Button; import android.widget.EditText; +import android.widget.Spinner; import android.widget.TextView; import android.widget.Toast; import java.security.SecureRandom; +import java.util.Arrays; +import java.util.Collections; +import java.util.List; import de.pixart.messenger.Config; import de.pixart.messenger.R; import de.pixart.messenger.entities.Account; import rocks.xmpp.addr.Jid; -public class MagicCreateActivity extends XmppActivity implements TextWatcher { +public class MagicCreateActivity extends XmppActivity implements TextWatcher, AdapterView.OnItemSelectedListener { private TextView mFullJidDisplay; private EditText mUsername; + private Spinner mServer; private SecureRandom mRandom; + String domain = null; private static final String CHARS = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456780+-/#$!?"; private static final int PW_LENGTH = 10; @@ -52,17 +60,27 @@ public class MagicCreateActivity extends XmppActivity implements TextWatcher { setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); } super.onCreate(savedInstanceState); - setContentView(R.layout.magic_create); + setContentView(R.layout.activity_magic_create); setSupportActionBar(findViewById(R.id.toolbar)); configureActionBar(getSupportActionBar()); mFullJidDisplay = findViewById(R.id.full_jid); + final List<String> domains = Arrays.asList(getResources().getStringArray(R.array.domains)); + Collections.sort(domains, String::compareToIgnoreCase); + final ArrayAdapter<String> adapter = new ArrayAdapter<>(this, android.R.layout.simple_selectable_list_item, domains); mUsername = findViewById(R.id.username); + mServer = findViewById(R.id.server); + mServer.setAdapter(adapter); + mServer.setOnItemSelectedListener(this); + adapter.setDropDownViewResource(android.R.layout.select_dialog_singlechoice); mRandom = new SecureRandom(); Button next = findViewById(R.id.create_account); next.setOnClickListener(v -> { try { String username = mUsername.getText().toString(); - Jid jid = Jid.of(username.toLowerCase(), Config.MAGIC_CREATE_DOMAIN, null); + if (domain == null) { + domain = Config.MAGIC_CREATE_DOMAIN; + } + Jid jid = Jid.of(username.toLowerCase(), domain, null); if (!jid.getEscapedLocal().equals(jid.getLocal()) || username.length() < 3) { mUsername.setError(getString(R.string.invalid_username)); mUsername.requestFocus(); @@ -80,10 +98,12 @@ public class MagicCreateActivity extends XmppActivity implements TextWatcher { intent.putExtra("jid", account.getJid().asBareJid().toString()); intent.putExtra("init", true); intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK); - Toast.makeText(MagicCreateActivity.this, R.string.secure_password_generated, Toast.LENGTH_SHORT).show(); + Toast.makeText(MagicCreateActivity.this, R.string.secure_password_generated, Toast.LENGTH_LONG).show(); WelcomeActivity.addInviteUri(intent, getIntent()); startActivity(intent); overridePendingTransition(R.animator.fade_in, R.animator.fade_out); + finish(); + overridePendingTransition(R.animator.fade_in, R.animator.fade_out); } } catch (IllegalArgumentException e) { mUsername.setError(getString(R.string.invalid_username)); @@ -113,10 +133,28 @@ public class MagicCreateActivity extends XmppActivity implements TextWatcher { @Override public void afterTextChanged(Editable s) { - if (s.toString().trim().length() > 0) { + generateJID(s.toString()); + } + + @Override + public void onItemSelected(AdapterView<?> adapterView, View view, int i, long l) { + generateJID(mUsername.getText().toString()); + } + + @Override + public void onNothingSelected(AdapterView<?> adapterView) { + generateJID(mUsername.getText().toString()); + } + + private void generateJID (String s) { + domain = mServer.getSelectedItem().toString(); + if (s.trim().length() > 0) { try { mFullJidDisplay.setVisibility(View.VISIBLE); - Jid jid = Jid.of(s.toString().toLowerCase(), Config.MAGIC_CREATE_DOMAIN, null); + if (domain == null) { + domain = Config.MAGIC_CREATE_DOMAIN; + } + Jid jid = Jid.of(s.toLowerCase(), domain, null); mFullJidDisplay.setText(getString(R.string.your_full_jid_will_be, jid.toEscapedString())); } catch (IllegalArgumentException e) { mFullJidDisplay.setVisibility(View.INVISIBLE); diff --git a/src/main/java/de/pixart/messenger/ui/WelcomeActivity.java b/src/main/java/de/pixart/messenger/ui/WelcomeActivity.java index d9930ca28..052abaf33 100644 --- a/src/main/java/de/pixart/messenger/ui/WelcomeActivity.java +++ b/src/main/java/de/pixart/messenger/ui/WelcomeActivity.java @@ -100,12 +100,7 @@ public class WelcomeActivity extends XmppActivity { ImportText.setVisibility(View.VISIBLE); } - ImportDatabase.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - enterPasswordDialog(); - } - }); + ImportDatabase.setOnClickListener(v -> enterPasswordDialog()); final Button createAccount = findViewById(R.id.create_account); createAccount.setOnClickListener(v -> { @@ -127,6 +122,8 @@ public class WelcomeActivity extends XmppActivity { addInviteUri(intent); startActivity(intent); overridePendingTransition(R.animator.fade_in, R.animator.fade_out); + finish(); + overridePendingTransition(R.animator.fade_in, R.animator.fade_out); }); } diff --git a/src/main/res/layout/magic_create.xml b/src/main/res/layout/activity_magic_create.xml index 8d2b811f0..8eb312ace 100644 --- a/src/main/res/layout/magic_create.xml +++ b/src/main/res/layout/activity_magic_create.xml @@ -1,5 +1,7 @@ <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" + xmlns:app="http://schemas.android.com/apk/res-auto" + xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical"> @@ -37,23 +39,40 @@ <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" - android:text="@string/pick_your_username" - android:textAppearance="@style/TextAppearance.Conversations.Title" /> + android:layout_marginTop="8dp" + android:text="@string/magic_create_text" + android:textAppearance="@style/TextAppearance.Conversations.Body1" /> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" - android:layout_marginTop="8dp" - android:text="@string/magic_create_text" - android:textAppearance="@style/TextAppearance.Conversations.Body1" /> + android:text="@string/pick_your_username" + android:textAppearance="@style/TextAppearance.Conversations.Title" /> <EditText android:id="@+id/username" + style="@style/Widget.Conversations.EditText" android:layout_width="match_parent" android:layout_height="wrap_content" - android:layout_gravity="center_horizontal" + android:imeOptions="actionNext" + android:inputType="text" android:hint="@string/username_hint" - android:inputType="textNoSuggestions" /> + android:textColor="?attr/text_Color_Main" /> + + <TextView + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:text="@string/choose_your_server" + android:textAppearance="@style/TextAppearance.Conversations.Title" /> + + <Spinner + android:id="@+id/server" + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:layout_gravity="center_horizontal" + android:hint="@string/server_hint" + android:prompt="@string/server_hint" + android:spinnerMode="dialog" /> <TextView android:id="@+id/full_jid" diff --git a/src/main/res/values/defaults.xml b/src/main/res/values/defaults.xml index 007ea6994..7ffb13a9a 100644 --- a/src/main/res/values/defaults.xml +++ b/src/main/res/values/defaults.xml @@ -104,5 +104,124 @@ <string name="omemo_setting_default">default_off</string> <string name="theme">light</string> <string name="default_font_size">small</string> + + <string-array name="domains"> + <item>pix-art.de</item> + <item>conversations.im</item> + <item>jabber.cat</item> + <item>jabjab.de</item> + <item>im.koderoot.net</item> + <item>riotcat.org</item> + <item>magicbroccoli.de</item> + <item>kode.im</item> + <item>jabber-germany.de</item> + <item>simplewire.de</item> + <item>suchat.org</item> + <item>jabber.at</item> + <item>trashserver.net</item> + <item>wiuwiu.de</item> + <item>5222.de</item> + <item>dismail.de</item> + <item>chat.sum7.eu</item> + <item>xmpp.zone</item> + <item>libranet.de</item> + <item>laborversuch.de</item> + <item>creep.im</item> + <item>jabber.systemausfall.org</item> + <item>jabber.hot-chilli.net</item> + <item>jabber.fr</item> + <item>jabber.de</item> + <item>draugr.de</item> + <item>elaon.de</item> + <item>high-way.me</item> + <item>jabber.rwth-aachen.de</item> + <item>deshalbfrei.org</item> + <item>mail.de</item> + <item>bommboo.de</item> + <item>jabber.systemli.org</item> + <item>jabb.im</item> + <item>mailbox.org</item> + <item>hot-chilli.net</item> + <item>jabberpl.org</item> + <item>chinwag.im</item> + <item>tchncs.de</item> + <item>zsim.de</item> + <item>patchcord.be</item> + <item>gajim.org</item> + <item>talker.to</item> + <item>pimux.de</item> + <item>jabber.home.vdlinde.org</item> + <item>im.apinc.org</item> + <item>chatme.im</item> + <item>fusselkater.org</item> + <item>datenknoten.me</item> + <item>fysh.in</item> + <item>jabber.chaos-darmstadt.de</item> + <item>yax.im</item> + <item>neko.im</item> + <item>jabberzac.org</item> + <item>xmpp.is</item> + <item>home.zom.im</item> + <item>jabber.ccc.de</item> + <item>jwchat.org</item> + <item>kdetalk.net</item> + <item>kde.org</item> + <item>riseup.net</item> + <item>ruhr-uni-bochum.de</item> + <item>njs.netlab.cz</item> + <item>schokokeks.org</item> + <item>jabber.cz</item> + <item>ubuntu-jabber.de</item> + <item>xabber.de</item> + <item>ubuntu-jabber.net</item> + <item>jabber.ru</item> + <item>darknet.nz</item> + <item>movim.eu</item> + <item>404.city</item> + <item>igniterealtime.org</item> + <item>kapsi.fi</item> + <item>jabbel.net</item> + <item>joindiaspora.com</item> + <item>alpha-labs.net</item> + <item>xmppnet.de</item> + <item>hoth.one</item> + <item>blah.im</item> + <item>xmpp.jp</item> + <item>jabber.uni-mainz.de</item> + <item>richim.org</item> + <item>tigase.im</item> + <item>jappix.com</item> + <item>member.fsf.org</item> + <item>jabber.rueckgr.at</item> + <item>swissjabber.ch</item> + <item>twattle.net</item> + <item>jabber.calyxinstitute.org</item> + <item>sapo.pt</item> + <item>uprod.biz</item> + <item>krautspace.de</item> + <item>kraut.space</item> + <item>null.pm</item> + <item>anonymitaet-im-inter.net</item> + <item>linuxlovers.at</item> + <item>jabber.org</item> + <item>jabber.no-sense.net</item> + <item>swissjabber.eu</item> + <item>swissjabber.org</item> + <item>swissjabber.de</item> + <item>swissjabber.li</item> + <item>jabber.no</item> + <item>cypherpunks.it</item> + <item>adastra.re</item> + <item>jabber-br.org</item> + <item>einfachjabber.de</item> + <item>jabber.smash-net.org</item> + <item>freifunk.im</item> + <item>openmailbox.org</item> + <item>jabber.otr.im</item> + <item>evil.im</item> + <item>xmpp.slack.com</item> + <item>chat.hipchat.com</item> + <item>googlemail.com</item> + </string-array> </resources> diff --git a/src/main/res/values/strings.xml b/src/main/res/values/strings.xml index 2351318f3..c3dea8e4c 100644 --- a/src/main/res/values/strings.xml +++ b/src/main/res/values/strings.xml @@ -788,4 +788,6 @@ <string name="jabber_id_copied_to_clipboard">Copied JID to clipboard</string> <string name="copy_jabber_id">Copy JID</string> <string name="copy_link">Copy web address</string> + <string name="server_hint">Choose provide</string> + <string name="choose_your_server">Choose your jabber provider</string> </resources> |