diff options
Diffstat (limited to 'src/main/java')
3 files changed, 77 insertions, 39 deletions
diff --git a/src/main/java/de/pixart/messenger/ui/EnterJidDialog.java b/src/main/java/de/pixart/messenger/ui/EnterJidDialog.java index b9ffcb35d..2f3315d22 100644 --- a/src/main/java/de/pixart/messenger/ui/EnterJidDialog.java +++ b/src/main/java/de/pixart/messenger/ui/EnterJidDialog.java @@ -15,6 +15,7 @@ import java.util.List; import de.pixart.messenger.Config; import de.pixart.messenger.R; import de.pixart.messenger.ui.adapter.KnownHostsAdapter; +import de.pixart.messenger.ui.util.DelayedHintHelper; import de.pixart.messenger.xmpp.jid.InvalidJidException; import de.pixart.messenger.xmpp.jid.Jid; @@ -47,8 +48,6 @@ public class EnterJidDialog { final AlertDialog.Builder builder = new AlertDialog.Builder(context); builder.setTitle(title); final View dialogView = LayoutInflater.from(context).inflate(R.layout.enter_jid_dialog, null); - final TextView jabberIdDesc = dialogView.findViewById(R.id.jabber_id); - jabberIdDesc.setText(R.string.account_settings_jabber_id); final TextView yourAccount = dialogView.findViewById(R.id.your_account); final Spinner spinner = dialogView.findViewById(R.id.account); final AutoCompleteTextView jid = dialogView.findViewById(R.id.jid); @@ -63,7 +62,7 @@ public class EnterJidDialog { } } - jid.setHint(R.string.account_settings_example_jabber_id); + DelayedHintHelper.setHint(R.string.account_settings_example_jabber_id, jid); if (multipleAccounts) { yourAccount.setVisibility(View.VISIBLE); @@ -89,42 +88,35 @@ public class EnterJidDialog { builder.setPositiveButton(positiveButton, null); this.dialog = builder.create(); - this.dialogOnClick = new View.OnClickListener() { - @Override - public void onClick(final View v) { - final Jid accountJid; - if (!spinner.isEnabled() && account == null) { - return; - } - try { - if (Config.DOMAIN_LOCK != null) { - if (spinner.getSelectedItem().toString().contains("@")) { - accountJid = Jid.fromString((String) spinner.getSelectedItem()); - } else { - accountJid = Jid.fromParts(String.valueOf(spinner.getSelectedItem()), Config.DOMAIN_LOCK, null); - } - } else { - accountJid = Jid.fromString((String) spinner.getSelectedItem()); - } - } catch (final InvalidJidException e) { - return; - } - final Jid contactJid; - try { - contactJid = Jid.fromString(jid.getText().toString()); - } catch (final InvalidJidException e) { - jid.setError(context.getString(R.string.invalid_jid)); - return; + this.dialogOnClick = v -> { + final Jid accountJid; + if (!spinner.isEnabled() && account == null) { + return; + } + try { + if (Config.DOMAIN_LOCK != null) { + accountJid = Jid.fromParts((String) spinner.getSelectedItem(), Config.DOMAIN_LOCK, null); + } else { + accountJid = Jid.fromString((String) spinner.getSelectedItem()); } + } catch (final InvalidJidException e) { + return; + } + final Jid contactJid; + try { + contactJid = Jid.fromString(jid.getText().toString()); + } catch (final InvalidJidException e) { + jid.setError(context.getString(R.string.invalid_jid)); + return; + } - if (listener != null) { - try { - if (listener.onEnterJidDialogPositive(accountJid, contactJid)) { - dialog.dismiss(); - } - } catch (JidError error) { - jid.setError(error.toString()); + if(listener != null) { + try { + if(listener.onEnterJidDialogPositive(accountJid, contactJid)) { + dialog.dismiss(); } + } catch(JidError error) { + jid.setError(error.toString()); } } }; diff --git a/src/main/java/de/pixart/messenger/ui/StartConversationActivity.java b/src/main/java/de/pixart/messenger/ui/StartConversationActivity.java index 04b3d860a..685632e11 100644 --- a/src/main/java/de/pixart/messenger/ui/StartConversationActivity.java +++ b/src/main/java/de/pixart/messenger/ui/StartConversationActivity.java @@ -70,6 +70,7 @@ import de.pixart.messenger.services.EmojiService; import de.pixart.messenger.services.XmppConnectionService.OnRosterUpdate; import de.pixart.messenger.ui.adapter.KnownHostsAdapter; import de.pixart.messenger.ui.adapter.ListItemAdapter; +import de.pixart.messenger.ui.util.DelayedHintHelper; import de.pixart.messenger.utils.XmppUri; import de.pixart.messenger.xmpp.OnUpdateBlocklist; import de.pixart.messenger.xmpp.XmppConnection; @@ -478,9 +479,7 @@ public class StartConversationActivity extends XmppActivity implements OnRosterU final TextView yourAccount = dialogView.findViewById(R.id.your_account); final Spinner spinner = dialogView.findViewById(R.id.account); final AutoCompleteTextView jid = dialogView.findViewById(R.id.jid); - final TextView jabberIdDesc = dialogView.findViewById(R.id.jabber_id); - jabberIdDesc.setText(R.string.conference_address); - jid.setHint(R.string.conference_address_example); + DelayedHintHelper.setHint(R.string.conference_address_example, jid); jid.setAdapter(new KnownHostsAdapter(this, R.layout.simple_list_item, mKnownConferenceHosts)); if (prefilledJid != null) { jid.append(prefilledJid); diff --git a/src/main/java/de/pixart/messenger/ui/util/DelayedHintHelper.java b/src/main/java/de/pixart/messenger/ui/util/DelayedHintHelper.java new file mode 100644 index 000000000..c289b6673 --- /dev/null +++ b/src/main/java/de/pixart/messenger/ui/util/DelayedHintHelper.java @@ -0,0 +1,47 @@ +/* + * Copyright (c) 2018, Daniel Gultsch All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation and/or + * other materials provided with the distribution. + * + * 3. Neither the name of the copyright holder nor the names of its contributors + * may be used to endorse or promote products derived from this software without + * specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +package de.pixart.messenger.ui.util; + +import android.os.Handler; +import android.support.annotation.StringRes; +import android.widget.EditText; + +public class DelayedHintHelper { + + public static void setHint(@StringRes final int res, EditText editText) { + editText.setOnFocusChangeListener((v, hasFocus) -> { + if (hasFocus) { + new Handler().postDelayed(() -> editText.setHint(res), 200); + } else { + editText.setHint(null); + } + }); + } +}
\ No newline at end of file |