aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDaniel Gultsch <daniel@gultsch.de>2016-05-26 22:53:55 +0200
committerDaniel Gultsch <daniel@gultsch.de>2016-05-26 22:53:55 +0200
commit21ebb35e44ee2e6a6cffaffee737d537ab1b8d6b (patch)
tree4edf3e780709efdce46ccfe5c7cc92e556d8af83
parentd9ff61ea2e2a54e7ac17f13b56016a75c04fc734 (diff)
add 'create conference' dialog
Diffstat (limited to '')
-rw-r--r--src/main/java/eu/siacs/conversations/entities/Bookmark.java5
-rw-r--r--src/main/java/eu/siacs/conversations/services/XmppConnectionService.java23
-rw-r--r--src/main/java/eu/siacs/conversations/ui/ChooseContactActivity.java4
-rw-r--r--src/main/java/eu/siacs/conversations/ui/ConferenceDetailsActivity.java13
-rw-r--r--src/main/java/eu/siacs/conversations/ui/StartConversationActivity.java117
-rw-r--r--src/main/res/layout/create_conference_dialog.xml42
-rw-r--r--src/main/res/menu/start_conversation.xml14
-rw-r--r--src/main/res/values/strings.xml5
8 files changed, 203 insertions, 20 deletions
diff --git a/src/main/java/eu/siacs/conversations/entities/Bookmark.java b/src/main/java/eu/siacs/conversations/entities/Bookmark.java
index fd6a5dab9..c5c4ff5dd 100644
--- a/src/main/java/eu/siacs/conversations/entities/Bookmark.java
+++ b/src/main/java/eu/siacs/conversations/entities/Bookmark.java
@@ -50,9 +50,8 @@ public class Bookmark extends Element implements ListItem {
@Override
public String getDisplayName() {
- if (this.mJoinedConversation != null
- && (this.mJoinedConversation.getMucOptions().getSubject() != null)) {
- return this.mJoinedConversation.getMucOptions().getSubject();
+ if (this.mJoinedConversation != null) {
+ return this.mJoinedConversation.getName();
} else if (getBookmarkName() != null) {
return getBookmarkName();
} else {
diff --git a/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java b/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java
index 52a2fc221..c05b78aa0 100644
--- a/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java
+++ b/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java
@@ -26,6 +26,7 @@ import android.os.SystemClock;
import android.preference.PreferenceManager;
import android.provider.ContactsContract;
import android.security.KeyChain;
+import android.util.Base64;
import android.util.DisplayMetrics;
import android.util.Log;
import android.util.LruCache;
@@ -2048,8 +2049,7 @@ public class XmppConnectionService extends Service implements OnPhoneContactsLoa
}
return;
}
- String localpart = new BigInteger(75, getRNG()).toString(32);
- Jid jid = Jid.fromParts(localpart, server, null);
+ final Jid jid = Jid.fromParts(new BigInteger(64, getRNG()).toString(Character.MAX_RADIX), server, null);
final Conversation conversation = findOrCreateConversation(account, jid, true);
joinMuc(conversation, new OnConferenceJoined() {
@Override
@@ -2058,7 +2058,7 @@ public class XmppConnectionService extends Service implements OnPhoneContactsLoa
@Override
public void onPushSucceeded() {
if (subject != null && !subject.trim().isEmpty()) {
- pushSubjectToConference(conversation, subject);
+ pushSubjectToConference(conversation, subject.trim());
}
for (Jid invite : jids) {
invite(conversation, invite);
@@ -2066,6 +2066,7 @@ public class XmppConnectionService extends Service implements OnPhoneContactsLoa
if (account.countPresences() > 1) {
directInvite(conversation, account.getJid().toBareJid());
}
+ saveConversationAsBookmark(conversation, subject);
if (callback != null) {
callback.success(conversation);
}
@@ -2073,6 +2074,7 @@ public class XmppConnectionService extends Service implements OnPhoneContactsLoa
@Override
public void onPushFailed() {
+ archiveConversation(conversation);
if (callback != null) {
callback.error(R.string.conference_creation_failed, conversation);
}
@@ -3306,6 +3308,21 @@ public class XmppConnectionService extends Service implements OnPhoneContactsLoa
return templates;
}
+ public void saveConversationAsBookmark(Conversation conversation, String name) {
+ Account account = conversation.getAccount();
+ Bookmark bookmark = new Bookmark(account, conversation.getJid().toBareJid());
+ if (!conversation.getJid().isBareJid()) {
+ bookmark.setNick(conversation.getJid().getResourcepart());
+ }
+ if (name != null && !name.trim().isEmpty()) {
+ bookmark.setBookmarkName(name.trim());
+ }
+ bookmark.setAutojoin(getPreferences().getBoolean("autojoin",true));
+ account.getBookmarks().add(bookmark);
+ pushBookmarks(account);
+ conversation.setBookmark(bookmark);
+ }
+
public interface OnMamPreferencesFetched {
void onPreferencesFetched(Element prefs);
void onPreferencesFetchFailed();
diff --git a/src/main/java/eu/siacs/conversations/ui/ChooseContactActivity.java b/src/main/java/eu/siacs/conversations/ui/ChooseContactActivity.java
index 1698343b0..d930e2398 100644
--- a/src/main/java/eu/siacs/conversations/ui/ChooseContactActivity.java
+++ b/src/main/java/eu/siacs/conversations/ui/ChooseContactActivity.java
@@ -77,6 +77,8 @@ public class ChooseContactActivity extends AbstractSearchableListItemActivity {
String[] selection = getSelectedContactJids();
data.putExtra("contacts", selection);
data.putExtra("multiple", true);
+ data.putExtra(EXTRA_ACCOUNT,request.getStringExtra(EXTRA_ACCOUNT));
+ data.putExtra("subject", request.getStringExtra("subject"));
setResult(RESULT_OK, data);
finish();
return true;
@@ -121,6 +123,7 @@ public class ChooseContactActivity extends AbstractSearchableListItemActivity {
data.putExtra("conversation",
request.getStringExtra("conversation"));
data.putExtra("multiple", false);
+ data.putExtra("subject", request.getStringExtra("subject"));
setResult(RESULT_OK, data);
finish();
}
@@ -194,6 +197,7 @@ public class ChooseContactActivity extends AbstractSearchableListItemActivity {
data.putExtra("conversation",
request.getStringExtra("conversation"));
data.putExtra("multiple", false);
+ data.putExtra("subject", request.getStringExtra("subject"));
setResult(RESULT_OK, data);
finish();
diff --git a/src/main/java/eu/siacs/conversations/ui/ConferenceDetailsActivity.java b/src/main/java/eu/siacs/conversations/ui/ConferenceDetailsActivity.java
index f39883137..80ebb28b4 100644
--- a/src/main/java/eu/siacs/conversations/ui/ConferenceDetailsActivity.java
+++ b/src/main/java/eu/siacs/conversations/ui/ConferenceDetailsActivity.java
@@ -26,7 +26,6 @@ import org.openintents.openpgp.util.OpenPgpUtils;
import java.util.ArrayList;
import java.util.Collections;
-import java.util.Comparator;
import java.util.concurrent.atomic.AtomicInteger;
import eu.siacs.conversations.Config;
@@ -485,16 +484,8 @@ public class ConferenceDetailsActivity extends XmppActivity implements OnConvers
}
protected void saveAsBookmark() {
- Account account = mConversation.getAccount();
- Bookmark bookmark = new Bookmark(account, mConversation.getJid().toBareJid());
- if (!mConversation.getJid().isBareJid()) {
- bookmark.setNick(mConversation.getJid().getResourcepart());
- }
- bookmark.setBookmarkName(mConversation.getMucOptions().getSubject());
- bookmark.setAutojoin(getPreferences().getBoolean("autojoin",true));
- account.getBookmarks().add(bookmark);
- xmppConnectionService.pushBookmarks(account);
- mConversation.setBookmark(bookmark);
+ xmppConnectionService.saveConversationAsBookmark(mConversation,
+ mConversation.getMucOptions().getSubject());
}
protected void deleteBookmark() {
diff --git a/src/main/java/eu/siacs/conversations/ui/StartConversationActivity.java b/src/main/java/eu/siacs/conversations/ui/StartConversationActivity.java
index 3ab6d1d2e..df7b24987 100644
--- a/src/main/java/eu/siacs/conversations/ui/StartConversationActivity.java
+++ b/src/main/java/eu/siacs/conversations/ui/StartConversationActivity.java
@@ -10,6 +10,7 @@ import android.app.AlertDialog;
import android.app.Fragment;
import android.app.FragmentTransaction;
import android.app.ListFragment;
+import android.app.PendingIntent;
import android.content.Context;
import android.content.DialogInterface;
import android.content.DialogInterface.OnClickListener;
@@ -27,6 +28,7 @@ import android.support.v4.view.ViewPager;
import android.text.Editable;
import android.text.TextWatcher;
import android.util.Log;
+import android.util.Pair;
import android.view.ContextMenu;
import android.view.ContextMenu.ContextMenuInfo;
import android.view.KeyEvent;
@@ -54,6 +56,7 @@ import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
+import java.util.concurrent.RunnableFuture;
import java.util.concurrent.atomic.AtomicBoolean;
import eu.siacs.conversations.Config;
@@ -94,6 +97,7 @@ public class StartConversationActivity extends XmppActivity implements OnRosterU
private EditText mSearchEditText;
private AtomicBoolean mRequestedContactsPermission = new AtomicBoolean(false);
private final int REQUEST_SYNC_CONTACTS = 0x3b28cf;
+ private final int REQUEST_CREATE_CONFERENCE = 0x3b39da;
private MenuItem.OnActionExpandListener mOnActionExpandListener = new MenuItem.OnActionExpandListener() {
@@ -201,6 +205,47 @@ public class StartConversationActivity extends XmppActivity implements OnRosterU
}
};
private String mInitialJid;
+ private Pair<Integer, Intent> mPostponedActivityResult;
+ private UiCallback<Conversation> mAdhocConferenceCallback = new UiCallback<Conversation>() {
+ @Override
+ public void success(final Conversation conversation) {
+ runOnUiThread(new Runnable() {
+ @Override
+ public void run() {
+ hideToast();
+ switchToConversation(conversation);
+ }
+ });
+ }
+
+ @Override
+ public void error(final int errorCode, Conversation object) {
+ runOnUiThread(new Runnable() {
+ @Override
+ public void run() {
+ replaceToast(getString(errorCode));
+ }
+ });
+ }
+
+ @Override
+ public void userInputRequried(PendingIntent pi, Conversation object) {
+
+ }
+ };
+ private Toast mToast;
+
+ protected void hideToast() {
+ if (mToast != null) {
+ mToast.cancel();
+ }
+ }
+
+ protected void replaceToast(String msg) {
+ hideToast();
+ mToast = Toast.makeText(this, msg ,Toast.LENGTH_LONG);
+ mToast.show();
+ }
@Override
public void onRosterUpdate() {
@@ -488,6 +533,36 @@ public class StartConversationActivity extends XmppActivity implements OnRosterU
});
}
+ private void showCreateConferenceDialog() {
+ final AlertDialog.Builder builder = new AlertDialog.Builder(this);
+ builder.setTitle(R.string.create_conference);
+ final View dialogView = getLayoutInflater().inflate(R.layout.create_conference_dialog, null);
+ final Spinner spinner = (Spinner) dialogView.findViewById(R.id.account);
+ final EditText subject = (EditText) dialogView.findViewById(R.id.subject);
+ populateAccountSpinner(this, mActivatedAccounts, spinner);
+ builder.setView(dialogView);
+ builder.setPositiveButton(R.string.choose_participants, new OnClickListener() {
+ @Override
+ public void onClick(DialogInterface dialog, int which) {
+ if (!xmppConnectionServiceBound) {
+ return;
+ }
+ final Account account = getSelectedAccount(spinner);
+ if (account == null) {
+ return;
+ }
+ Intent intent = new Intent(getApplicationContext(), ChooseContactActivity.class);
+ intent.putExtra("multiple", true);
+ intent.putExtra("show_enter_jid", true);
+ intent.putExtra("subject", subject.getText().toString());
+ intent.putExtra(EXTRA_ACCOUNT, account.getJid().toBareJid().toString());
+ startActivityForResult(intent, REQUEST_CREATE_CONFERENCE);
+ }
+ });
+ builder.setNegativeButton(R.string.cancel, null);
+ builder.create().show();
+ }
+
private Account getSelectedAccount(Spinner spinner) {
if (!spinner.isEnabled()) {
return null;
@@ -532,7 +607,7 @@ public class StartConversationActivity extends XmppActivity implements OnRosterU
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.start_conversation, menu);
MenuItem menuCreateContact = menu.findItem(R.id.action_create_contact);
- MenuItem menuCreateConference = menu.findItem(R.id.action_join_conference);
+ MenuItem menuCreateConference = menu.findItem(R.id.action_conference);
MenuItem menuHideOffline = menu.findItem(R.id.action_hide_offline);
menuHideOffline.setChecked(this.mHideOfflineContacts);
mMenuSearchView = menu.findItem(R.id.action_search);
@@ -564,6 +639,9 @@ public class StartConversationActivity extends XmppActivity implements OnRosterU
case R.id.action_join_conference:
showJoinConferenceDialog(null);
return true;
+ case R.id.action_create_conference:
+ showCreateConferenceDialog();
+ return true;
case R.id.action_scan_qr_code:
new IntentIntegrator(this).initiateScan();
return true;
@@ -616,6 +694,39 @@ public class StartConversationActivity extends XmppActivity implements OnRosterU
this.mPendingInvite = null;
}
}
+ } else if (resultCode == RESULT_OK) {
+ if (xmppConnectionServiceBound) {
+ this.mPostponedActivityResult = null;
+ if (requestCode == REQUEST_CREATE_CONFERENCE) {
+ Log.d(Config.LOGTAG,"account jid: "+ intent.getStringExtra(EXTRA_ACCOUNT));
+ Account account = extractAccount(intent);
+ final String subject = intent.getStringExtra("subject");
+ List<Jid> jids = new ArrayList<>();
+ if (intent.getBooleanExtra("multiple", false)) {
+ String[] toAdd = intent.getStringArrayExtra("contacts");
+ for (String item : toAdd) {
+ try {
+ jids.add(Jid.fromString(item));
+ } catch (InvalidJidException e) {
+ //ignored
+ }
+ }
+ } else {
+ try {
+ jids.add(Jid.fromString(intent.getStringExtra("contact")));
+ } catch (Exception e) {
+ //ignored
+ }
+ }
+ if (account != null && jids.size() > 1) {
+ xmppConnectionService.createAdhocConference(account, subject, jids, mAdhocConferenceCallback);
+ mToast = Toast.makeText(this, R.string.creating_conference,Toast.LENGTH_LONG);
+ mToast.show();
+ }
+ }
+ } else {
+ this.mPostponedActivityResult = new Pair<>(requestCode, intent);
+ }
}
super.onActivityResult(requestCode, requestCode, intent);
}
@@ -657,6 +768,10 @@ public class StartConversationActivity extends XmppActivity implements OnRosterU
@Override
protected void onBackendConnected() {
+ if (mPostponedActivityResult != null) {
+ onActivityResult(mPostponedActivityResult.first, RESULT_OK, mPostponedActivityResult.second);
+ this.mPostponedActivityResult = null;
+ }
this.mActivatedAccounts.clear();
for (Account account : xmppConnectionService.getAccounts()) {
if (account.getStatus() != Account.State.DISABLED) {
diff --git a/src/main/res/layout/create_conference_dialog.xml b/src/main/res/layout/create_conference_dialog.xml
new file mode 100644
index 000000000..cab2ac578
--- /dev/null
+++ b/src/main/res/layout/create_conference_dialog.xml
@@ -0,0 +1,42 @@
+<?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:paddingBottom="8dp"
+ android:paddingLeft="24dp"
+ android:paddingRight="24dp"
+ android:paddingTop="16dp">
+
+ <TextView
+ android:id="@+id/your_account"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:text="@string/your_account"
+ android:textColor="@color/black87"
+ android:textSize="?attr/TextSizeBody" />
+
+ <Spinner
+ android:id="@+id/account"
+ android:layout_width="fill_parent"
+ android:layout_height="wrap_content" />
+
+ <TextView
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:layout_marginTop="8dp"
+ android:text="@string/conference_subject"
+ android:textColor="@color/black87"
+ android:textSize="?attr/TextSizeBody" />
+
+ <EditText
+ android:id="@+id/subject"
+ android:layout_width="fill_parent"
+ android:layout_height="wrap_content"
+ android:hint="@string/edit_subject_hint"
+ android:inputType="textAutoComplete"
+ android:textColor="@color/black87"
+ android:textColorHint="@color/black54"
+ android:textSize="?attr/TextSizeBody"/>
+
+</LinearLayout> \ No newline at end of file
diff --git a/src/main/res/menu/start_conversation.xml b/src/main/res/menu/start_conversation.xml
index a89d71ffd..327709fa1 100644
--- a/src/main/res/menu/start_conversation.xml
+++ b/src/main/res/menu/start_conversation.xml
@@ -13,10 +13,20 @@
android:showAsAction="always"
android:title="@string/create_contact" />
<item
- android:id="@+id/action_join_conference"
+ android:id="@+id/action_conference"
android:icon="?attr/icon_add_group"
android:showAsAction="always"
- android:title="@string/join_conference" />
+ android:title="@string/join_or_create_conference">
+ <menu>
+ <item
+ android:id="@+id/action_join_conference"
+ android:title="@string/join_conference"/>
+ <item
+ android:id="@+id/action_create_conference"
+ android:title="@string/create_conference"/>
+
+ </menu>
+ </item>
<item
android:id="@+id/action_scan_qr_code"
android:showAsAction="never"
diff --git a/src/main/res/values/strings.xml b/src/main/res/values/strings.xml
index 8a1dc1b3c..da7a60984 100644
--- a/src/main/res/values/strings.xml
+++ b/src/main/res/values/strings.xml
@@ -644,4 +644,9 @@
<string name="device_does_not_support_battery_op">Your device does not support opting out of battery optimization</string>
<string name="show_password">Show password</string>
<string name="registration_please_wait">Registration failed: Try again later</string>
+ <string name="create_conference">Create conference</string>
+ <string name="join_or_create_conference">Join or create conference</string>
+ <string name="conference_subject">Subject</string>
+ <string name="choose_participants">Choose participants</string>
+ <string name="creating_conference">Creating conferenceā€¦</string>
</resources>