aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--res/layout/create_contact_dialog.xml37
-rw-r--r--res/values/strings.xml8
-rw-r--r--src/eu/siacs/conversations/ui/StartConversation.java65
3 files changed, 106 insertions, 4 deletions
diff --git a/res/layout/create_contact_dialog.xml b/res/layout/create_contact_dialog.xml
new file mode 100644
index 00000000..45007ef2
--- /dev/null
+++ b/res/layout/create_contact_dialog.xml
@@ -0,0 +1,37 @@
+<?xml version="1.0" encoding="utf-8"?>
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent"
+ android:orientation="vertical"
+ android:padding="16dp">
+
+ <TextView
+ android:id="@+id/your_account"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:textSize="14sp"
+ android:textColor="@color/primarytext"
+ android:text="@string/your_account" />
+ <Spinner
+ android:id="@+id/account"
+ android:layout_width="fill_parent"
+ android:layout_height="wrap_content" />
+
+ <TextView
+ android:id="@+id/jabber_id"
+ android:paddingTop="8dp"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:textSize="14sp"
+ android:textColor="@color/primarytext"
+ android:text="@string/account_settings_jabber_id" />
+
+ <EditText
+ android:id="@+id/jid"
+ android:paddingTop="8dp"
+ android:layout_width="fill_parent"
+ android:layout_height="wrap_content"
+ android:inputType="textEmailAddress"
+ android:hint="@string/account_settings_example_jabber_id"
+ />
+</LinearLayout>
diff --git a/res/values/strings.xml b/res/values/strings.xml
index 8d66125e..ebfaaa17 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -201,10 +201,10 @@
<string name="mgmt_account_account_offline">Account is offline</string>
<string name="attach_record_voice">Record voice</string>
<string name="account_settings">Account Settings</string>
- <string name="account_settings_jabber_id">Jabber ID:</string>
- <string name="account_settings_password">Password:</string>
+ <string name="account_settings_jabber_id">Jabber ID</string>
+ <string name="account_settings_password">Password</string>
<string name="account_settings_example_jabber_id">username@example.com</string>
- <string name="account_settings_confirm_password">Confirm password:</string>
+ <string name="account_settings_confirm_password">Confirm password</string>
<string name="password">Password</string>
<string name="confirm_password">Confirm password</string>
<string name="passwords_do_not_match">Passwords do not match</string>
@@ -261,4 +261,6 @@
<string name="create_conference">Create Conference</string>
<string name="delete_contact">Delete Contact</string>
<string name="view_contact_details">View contact details</string>
+ <string name="create">Create</string>
+ <string name="contact_already_exists">The contact already exists</string>
</resources> \ No newline at end of file
diff --git a/src/eu/siacs/conversations/ui/StartConversation.java b/src/eu/siacs/conversations/ui/StartConversation.java
index 45d61491..880b4a9b 100644
--- a/src/eu/siacs/conversations/ui/StartConversation.java
+++ b/src/eu/siacs/conversations/ui/StartConversation.java
@@ -7,10 +7,13 @@ import java.util.List;
import android.app.ActionBar;
import android.app.ActionBar.Tab;
import android.app.ActionBar.TabListener;
+import android.app.AlertDialog;
import android.app.Fragment;
import android.app.FragmentTransaction;
import android.app.ListFragment;
import android.content.Context;
+import android.content.DialogInterface;
+import android.database.DataSetObserver;
import android.graphics.Color;
import android.os.Bundle;
import android.support.v13.app.FragmentPagerAdapter;
@@ -26,10 +29,13 @@ import android.widget.AdapterView;
import android.widget.AdapterView.AdapterContextMenuInfo;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ArrayAdapter;
+import android.widget.EditText;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.SearchView;
+import android.widget.SpinnerAdapter;
import android.widget.SearchView.OnQueryTextListener;
+import android.widget.Spinner;
import android.widget.TextView;
import eu.siacs.conversations.R;
import eu.siacs.conversations.entities.Account;
@@ -37,6 +43,7 @@ import eu.siacs.conversations.entities.Contact;
import eu.siacs.conversations.entities.Conversation;
import eu.siacs.conversations.entities.ListItem;
import eu.siacs.conversations.utils.UIHelper;
+import eu.siacs.conversations.utils.Validator;
public class StartConversation extends XmppActivity {
@@ -52,6 +59,8 @@ public class StartConversation extends XmppActivity {
private MyListFragment mConferenceListFragment = new MyListFragment();
private List<ListItem> conferences = new ArrayList<ListItem>();
private ArrayAdapter<ListItem> mConferenceAdapter;
+
+ private List<String> mActivatedAccounts = new ArrayList<String>();
private TabListener mTabListener = new TabListener() {
@@ -161,6 +170,53 @@ public class StartConversation extends XmppActivity {
xmppConnectionService.deleteContactOnServer(contact);
filterContacts(null);
}
+
+ protected void showCreateContactDialog() {
+ AlertDialog.Builder builder = new AlertDialog.Builder(this);
+ builder.setTitle(R.string.create_contact);
+ View dialogView = getLayoutInflater().inflate(R.layout.create_contact_dialog, null);
+ final Spinner spinner = (Spinner) dialogView.findViewById(R.id.account);
+ final EditText jid = (EditText) dialogView.findViewById(R.id.jid);
+ populateAccountSpinner(spinner);
+ builder.setView(dialogView);
+ builder.setNegativeButton(R.string.cancel, null);
+ builder.setPositiveButton(R.string.create, null);
+ final AlertDialog dialog = builder.create();
+ dialog.show();
+ dialog.getButton(AlertDialog.BUTTON_POSITIVE).setOnClickListener(new View.OnClickListener() {
+
+ @Override
+ public void onClick(View v) {
+ if (Validator.isValidJid(jid.getText().toString())) {
+ String accountJid = (String) spinner.getSelectedItem();
+ String contactJid = jid.getText().toString();
+ Account account = xmppConnectionService.findAccountByJid(accountJid);
+ Contact contact = account.getRoster().getContact(contactJid);
+ if (contact.showInRoster()) {
+ jid.setError(getString(R.string.contact_already_exists));
+ } else {
+ xmppConnectionService.createContact(contact);
+ switchToConversation(contact);
+ dialog.dismiss();
+ }
+ } else {
+ jid.setError(getString(R.string.invalid_jid));
+ }
+ }
+ });
+
+ }
+
+ protected void switchToConversation(Contact contact) {
+ Conversation conversation = xmppConnectionService.findOrCreateConversation(contact.getAccount(), contact.getJid(), false);
+ switchToConversation(conversation, null, false);
+ }
+
+ private void populateAccountSpinner(Spinner spinner) {
+ ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, mActivatedAccounts);
+ adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
+ spinner.setAdapter(adapter);
+ }
@Override
public boolean onCreateOptionsMenu(Menu menu) {
@@ -187,7 +243,8 @@ public class StartConversation extends XmppActivity {
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
- default:
+ case R.id.action_create_contact:
+ showCreateContactDialog();
break;
}
return super.onOptionsItemSelected(item);
@@ -196,6 +253,12 @@ public class StartConversation extends XmppActivity {
@Override
void onBackendConnected() {
filterContacts(null);
+ this.mActivatedAccounts.clear();
+ for (Account account : xmppConnectionService.getAccounts()) {
+ if (account.getStatus() != Account.STATUS_DISABLED) {
+ this.mActivatedAccounts.add(account.getJid());
+ }
+ }
}
protected void filterContacts(String needle) {