From 77c0fb0b2ae257b7bf257417ed689f2334507f2c Mon Sep 17 00:00:00 2001 From: Daniel Gultsch Date: Fri, 22 Jan 2016 11:14:56 +0100 Subject: changed spacing in create dialogs and notify user when no accounts are activated --- .../eu/siacs/conversations/ui/EnterJidDialog.java | 23 ++++++++++--------- .../ui/StartConversationActivity.java | 26 ++++++++++++++++------ 2 files changed, 32 insertions(+), 17 deletions(-) (limited to 'src/main/java') diff --git a/src/main/java/eu/siacs/conversations/ui/EnterJidDialog.java b/src/main/java/eu/siacs/conversations/ui/EnterJidDialog.java index a9bffb55..bb55420d 100644 --- a/src/main/java/eu/siacs/conversations/ui/EnterJidDialog.java +++ b/src/main/java/eu/siacs/conversations/ui/EnterJidDialog.java @@ -19,8 +19,8 @@ import eu.siacs.conversations.xmpp.jid.InvalidJidException; import eu.siacs.conversations.xmpp.jid.Jid; public class EnterJidDialog { - public static interface OnEnterJidDialogPositiveListener { - public boolean onEnterJidDialogPositive(Jid account, Jid contact) throws EnterJidDialog.JidError; + public interface OnEnterJidDialogPositiveListener { + boolean onEnterJidDialogPositive(Jid account, Jid contact) throws EnterJidDialog.JidError; } public static class JidError extends Exception { @@ -40,7 +40,7 @@ public class EnterJidDialog { protected OnEnterJidDialogPositiveListener listener = null; public EnterJidDialog( - final Context context, List knownHosts, List activatedAccounts, + final Context context, List knownHosts, final List activatedAccounts, final String title, final String positiveButton, final String prefilledJid, final String account, boolean allowEditJid ) { @@ -60,17 +60,17 @@ public class EnterJidDialog { } } - ArrayAdapter adapter; + if (account == null) { - adapter = new ArrayAdapter<>(context, - android.R.layout.simple_spinner_item, activatedAccounts); + StartConversationActivity.populateAccountSpinner(context, activatedAccounts, spinner); } else { - adapter = new ArrayAdapter<>(context, - android.R.layout.simple_spinner_item, new String[] { account }); + ArrayAdapter adapter = new ArrayAdapter<>(context, + android.R.layout.simple_spinner_item, + new String[] { account }); spinner.setEnabled(false); + adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); + spinner.setAdapter(adapter); } - adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); - spinner.setAdapter(adapter); builder.setView(dialogView); builder.setNegativeButton(R.string.cancel, null); @@ -81,6 +81,9 @@ public class EnterJidDialog { @Override public void onClick(final View 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); diff --git a/src/main/java/eu/siacs/conversations/ui/StartConversationActivity.java b/src/main/java/eu/siacs/conversations/ui/StartConversationActivity.java index 0bf4178f..00a501f3 100644 --- a/src/main/java/eu/siacs/conversations/ui/StartConversationActivity.java +++ b/src/main/java/eu/siacs/conversations/ui/StartConversationActivity.java @@ -393,7 +393,7 @@ public class StartConversationActivity extends XmppActivity implements OnRosterU if (prefilledJid != null) { jid.append(prefilledJid); } - populateAccountSpinner(spinner); + populateAccountSpinner(this, mActivatedAccounts, spinner); final Checkable bookmarkCheckBox = (CheckBox) dialogView .findViewById(R.id.bookmark); builder.setView(dialogView); @@ -411,7 +411,6 @@ public class StartConversationActivity extends XmppActivity implements OnRosterU } final Account account = getSelectedAccount(spinner); if (account == null) { - dialog.dismiss(); return; } final Jid conferenceJid; @@ -459,6 +458,9 @@ public class StartConversationActivity extends XmppActivity implements OnRosterU } private Account getSelectedAccount(Spinner spinner) { + if (!spinner.isEnabled()) { + return null; + } Jid jid; try { if (Config.DOMAIN_LOCK != null) { @@ -479,11 +481,21 @@ public class StartConversationActivity extends XmppActivity implements OnRosterU switchToConversation(conversation); } - private void populateAccountSpinner(Spinner spinner) { - ArrayAdapter adapter = new ArrayAdapter<>(this, - android.R.layout.simple_spinner_item, mActivatedAccounts); - adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); - spinner.setAdapter(adapter); + public static void populateAccountSpinner(Context context, List accounts, Spinner spinner) { + if (accounts.size() > 0) { + ArrayAdapter adapter = new ArrayAdapter<>(context, + android.R.layout.simple_spinner_item, accounts); + adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); + spinner.setAdapter(adapter); + spinner.setEnabled(true); + } else { + ArrayAdapter adapter = new ArrayAdapter<>(context, + android.R.layout.simple_spinner_item, + Arrays.asList(new String[]{context.getString(R.string.no_accounts)})); + adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); + spinner.setAdapter(adapter); + spinner.setEnabled(false); + } } @Override -- cgit v1.2.3