use conference subject to identiy room

This commit is contained in:
Daniel Gultsch 2014-03-14 22:40:56 +01:00
parent 4e4a767743
commit b1a3d09ca6
11 changed files with 119 additions and 69 deletions

View File

@ -10,7 +10,6 @@
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:textSize="20sp" android:textSize="20sp"
android:textStyle="bold"
android:typeface="monospace" android:typeface="monospace"
android:text="@string/no_otr_fingerprint"/> android:text="@string/no_otr_fingerprint"/>

View File

@ -49,5 +49,10 @@
android:title="Use Phones self contact picture" android:title="Use Phones self contact picture"
android:summary="You may no longer be able to distinguish which account you are using in a conversation" android:summary="You may no longer be able to distinguish which account you are using in a conversation"
android:defaultValue="true"/> android:defaultValue="true"/>
<CheckBoxPreference
android:key="use_subject_in_muc"
android:title="Conference Name"
android:summary="Use rooms subject to identify Conferences"
android:defaultValue="true"/>
</PreferenceCategory> </PreferenceCategory>
</PreferenceScreen> </PreferenceScreen>

View File

@ -4,9 +4,6 @@ import java.security.interfaces.DSAPublicKey;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import eu.siacs.conversations.crypto.OtrEngine;
import eu.siacs.conversations.xmpp.XmppConnection;
import net.java.otr4j.OtrException; import net.java.otr4j.OtrException;
import net.java.otr4j.crypto.OtrCryptoEngineImpl; import net.java.otr4j.crypto.OtrCryptoEngineImpl;
import net.java.otr4j.crypto.OtrCryptoException; import net.java.otr4j.crypto.OtrCryptoException;
@ -61,15 +58,17 @@ public class Conversation extends AbstractEntity {
private transient MucOptions mucOptions = null; private transient MucOptions mucOptions = null;
public Conversation(String name, Account account, public Conversation(String name, Account account, String contactJid,
String contactJid, int mode) { int mode) {
this(java.util.UUID.randomUUID().toString(), name, null, account.getUuid(), contactJid, System this(java.util.UUID.randomUUID().toString(), name, null, account
.currentTimeMillis(), STATUS_AVAILABLE,mode); .getUuid(), contactJid, System.currentTimeMillis(),
STATUS_AVAILABLE, mode);
this.account = account; this.account = account;
} }
public Conversation(String uuid, String name, String contactUuid, public Conversation(String uuid, String name, String contactUuid,
String accountUuid, String contactJid, long created, int status, int mode) { String accountUuid, String contactJid, long created, int status,
int mode) {
this.uuid = uuid; this.uuid = uuid;
this.name = name; this.name = name;
this.contactUuid = contactUuid; this.contactUuid = contactUuid;
@ -81,11 +80,12 @@ public class Conversation extends AbstractEntity {
} }
public List<Message> getMessages() { public List<Message> getMessages() {
if (messages == null) this.messages = new ArrayList<Message>(); //prevent null pointer if (messages == null)
this.messages = new ArrayList<Message>(); // prevent null pointer
//populate with Conversation (this) // populate with Conversation (this)
for(Message msg : messages) { for (Message msg : messages) {
msg.setConversation(this); msg.setConversation(this);
} }
@ -93,21 +93,24 @@ public class Conversation extends AbstractEntity {
} }
public boolean isRead() { public boolean isRead() {
if ((this.messages == null)||(this.messages.size() == 0)) return true; if ((this.messages == null) || (this.messages.size() == 0))
return true;
return this.messages.get(this.messages.size() - 1).isRead(); return this.messages.get(this.messages.size() - 1).isRead();
} }
public void markRead() { public void markRead() {
if (this.messages == null) return; if (this.messages == null)
for(int i = this.messages.size() -1; i >= 0; --i) { return;
if (messages.get(i).isRead()) return; for (int i = this.messages.size() - 1; i >= 0; --i) {
if (messages.get(i).isRead())
return;
this.messages.get(i).markRead(); this.messages.get(i).markRead();
} }
} }
public Message getLatestMessage() { public Message getLatestMessage() {
if ((this.messages == null)||(this.messages.size()==0)) { if ((this.messages == null) || (this.messages.size() == 0)) {
Message message = new Message(this,"",Message.ENCRYPTION_NONE); Message message = new Message(this, "", Message.ENCRYPTION_NONE);
message.setTime(getCreated()); message.setTime(getCreated());
return message; return message;
} else { } else {
@ -119,8 +122,10 @@ public class Conversation extends AbstractEntity {
this.messages = msgs; this.messages = msgs;
} }
public String getName() { public String getName(boolean useSubject) {
if (this.contact!=null) { if ((getMode() == MODE_MULTI) && (getMucOptions().getSubject() != null) && useSubject) {
return getMucOptions().getSubject();
} else if (this.contact != null) {
return this.contact.getDisplayName(); return this.contact.getDisplayName();
} else { } else {
return this.name; return this.name;
@ -128,7 +133,7 @@ public class Conversation extends AbstractEntity {
} }
public String getProfilePhotoString() { public String getProfilePhotoString() {
if (this.contact==null) { if (this.contact == null) {
return null; return null;
} else { } else {
return this.contact.getProfilePhoto(); return this.contact.getProfilePhoto();
@ -149,7 +154,7 @@ public class Conversation extends AbstractEntity {
public void setContact(Contact contact) { public void setContact(Contact contact) {
this.contact = contact; this.contact = contact;
if (contact!=null) { if (contact != null) {
this.contactUuid = contact.getUuid(); this.contactUuid = contact.getUuid();
} }
} }
@ -186,7 +191,7 @@ public class Conversation extends AbstractEntity {
values.put(CONTACTJID, contactJid); values.put(CONTACTJID, contactJid);
values.put(CREATED, created); values.put(CREATED, created);
values.put(STATUS, status); values.put(STATUS, status);
values.put(MODE,mode); values.put(MODE, mode);
return values; return values;
} }
@ -214,13 +219,15 @@ public class Conversation extends AbstractEntity {
} }
public void startOtrSession(Context context, String presence) { public void startOtrSession(Context context, String presence) {
Log.d("xmppService","starting otr session with "+presence); Log.d("xmppService", "starting otr session with " + presence);
SessionID sessionId = new SessionID(this.getContactJid(),presence,"xmpp"); SessionID sessionId = new SessionID(this.getContactJid(), presence,
this.otrSession = new SessionImpl(sessionId, getAccount().getOtrEngine(context)); "xmpp");
this.otrSession = new SessionImpl(sessionId, getAccount().getOtrEngine(
context));
try { try {
this.otrSession.startSession(); this.otrSession.startSession();
} catch (OtrException e) { } catch (OtrException e) {
Log.d("xmppServic","couldnt start otr"); Log.d("xmppServic", "couldnt start otr");
} }
} }
@ -233,7 +240,7 @@ public class Conversation extends AbstractEntity {
} }
public void endOtrIfNeeded() { public void endOtrIfNeeded() {
if (this.otrSession!=null) { if (this.otrSession != null) {
if (this.otrSession.getSessionStatus() == SessionStatus.ENCRYPTED) { if (this.otrSession.getSessionStatus() == SessionStatus.ENCRYPTED) {
try { try {
this.otrSession.endSession(); this.otrSession.endSession();
@ -261,8 +268,10 @@ public class Conversation extends AbstractEntity {
public String getOtrFingerprint() { public String getOtrFingerprint() {
if (this.otrFingerprint == null) { if (this.otrFingerprint == null) {
try { try {
DSAPublicKey remotePubKey = (DSAPublicKey) getOtrSession().getRemotePublicKey(); DSAPublicKey remotePubKey = (DSAPublicKey) getOtrSession()
StringBuilder builder = new StringBuilder(new OtrCryptoEngineImpl().getFingerprint(remotePubKey)); .getRemotePublicKey();
StringBuilder builder = new StringBuilder(
new OtrCryptoEngineImpl().getFingerprint(remotePubKey));
builder.insert(8, " "); builder.insert(8, " ");
builder.insert(17, " "); builder.insert(17, " ");
builder.insert(26, " "); builder.insert(26, " ");
@ -280,7 +289,7 @@ public class Conversation extends AbstractEntity {
this.mucOptions = new MucOptions(); this.mucOptions = new MucOptions();
} }
this.mucOptions.setConversation(this); this.mucOptions.setConversation(this);
return this.mucOptions ; return this.mucOptions;
} }
public void resetMucOptions() { public void resetMucOptions() {

View File

@ -77,6 +77,7 @@ public class MucOptions {
private int error = 0; private int error = 0;
private OnRenameListener renameListener = null; private OnRenameListener renameListener = null;
private User self = new User(); private User self = new User();
private String subject = null;
public void deleteUser(String name) { public void deleteUser(String name) {
@ -186,4 +187,12 @@ public class MucOptions {
public User getSelf() { public User getSelf() {
return self; return self;
} }
public void setSubject(String content) {
this.subject = content;
}
public String getSubject() {
return this.subject;
}
} }

View File

@ -1225,4 +1225,10 @@ public class XmppConnectionService extends Service {
} }
}).start(); }).start();
} }
public void updateConversationInGui() {
if (convChangedListener!=null) {
convChangedListener.onConversationListChanged();
}
}
} }

View File

@ -12,11 +12,13 @@ import eu.siacs.conversations.entities.Conversation;
import eu.siacs.conversations.entities.Message; import eu.siacs.conversations.entities.Message;
import eu.siacs.conversations.utils.UIHelper; import eu.siacs.conversations.utils.UIHelper;
import android.os.Bundle; import android.os.Bundle;
import android.preference.PreferenceManager;
import android.app.AlertDialog; import android.app.AlertDialog;
import android.app.FragmentTransaction; import android.app.FragmentTransaction;
import android.content.Context; import android.content.Context;
import android.content.DialogInterface; import android.content.DialogInterface;
import android.content.Intent; import android.content.Intent;
import android.content.SharedPreferences;
import android.graphics.Color; import android.graphics.Color;
import android.graphics.Typeface; import android.graphics.Typeface;
import android.support.v4.widget.SlidingPaneLayout; import android.support.v4.widget.SlidingPaneLayout;
@ -53,6 +55,7 @@ public class ConversationActivity extends XmppActivity {
private ListView listView; private ListView listView;
private boolean paneShouldBeOpen = true; private boolean paneShouldBeOpen = true;
private boolean useSubject = true;
private ArrayAdapter<Conversation> listAdapter; private ArrayAdapter<Conversation> listAdapter;
private OnConversationListChangedListener onConvChanged = new OnConversationListChangedListener() { private OnConversationListChangedListener onConvChanged = new OnConversationListChangedListener() {
@ -163,7 +166,7 @@ public class ConversationActivity extends XmppActivity {
view.setBackgroundColor(Color.TRANSPARENT); view.setBackgroundColor(Color.TRANSPARENT);
} }
TextView convName = (TextView) view.findViewById(R.id.conversation_name); TextView convName = (TextView) view.findViewById(R.id.conversation_name);
convName.setText(conv.getName()); convName.setText(conv.getName(useSubject));
TextView convLastMsg = (TextView) view.findViewById(R.id.conversation_lastmsg); TextView convLastMsg = (TextView) view.findViewById(R.id.conversation_lastmsg);
convLastMsg.setText(conv.getLatestMessage().getBody()); convLastMsg.setText(conv.getLatestMessage().getBody());
@ -179,7 +182,7 @@ public class ConversationActivity extends XmppActivity {
.setText(UIHelper.readableTimeDifference(conv.getLatestMessage().getTimeSent())); .setText(UIHelper.readableTimeDifference(conv.getLatestMessage().getTimeSent()));
ImageView imageView = (ImageView) view.findViewById(R.id.conversation_image); ImageView imageView = (ImageView) view.findViewById(R.id.conversation_image);
imageView.setImageBitmap(UIHelper.getContactPicture(conv.getContact(), conv.getName(),200, activity.getApplicationContext())); imageView.setImageBitmap(UIHelper.getContactPicture(conv.getContact(), conv.getName(useSubject),200, activity.getApplicationContext()));
return view; return view;
} }
@ -221,7 +224,7 @@ public class ConversationActivity extends XmppActivity {
paneShouldBeOpen = false; paneShouldBeOpen = false;
if (conversationList.size() > 0) { if (conversationList.size() > 0) {
getActionBar().setDisplayHomeAsUpEnabled(true); getActionBar().setDisplayHomeAsUpEnabled(true);
getActionBar().setTitle(getSelectedConversation().getName()); getActionBar().setTitle(getSelectedConversation().getName(useSubject));
invalidateOptionsMenu(); invalidateOptionsMenu();
if (!getSelectedConversation().isRead()) { if (!getSelectedConversation().isRead()) {
getSelectedConversation().markRead(); getSelectedConversation().markRead();
@ -399,6 +402,8 @@ public class ConversationActivity extends XmppActivity {
public void onStart() { public void onStart() {
super.onStart(); super.onStart();
this.registerListener(); this.registerListener();
SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this);
this.useSubject = preferences.getBoolean("use_subject_in_muc", true);
if (conversationList.size()>=1) { if (conversationList.size()>=1) {
onConvChanged.onConversationListChanged(); onConvChanged.onConversationListChanged();
} }

View File

@ -63,6 +63,8 @@ public class ConversationFragment extends Fragment {
protected Bitmap selfBitmap; protected Bitmap selfBitmap;
private boolean useSubject = true;
private IntentSender askForPassphraseIntent = null; private IntentSender askForPassphraseIntent = null;
private OnClickListener sendMsgListener = new OnClickListener() { private OnClickListener sendMsgListener = new OnClickListener() {
@ -214,7 +216,7 @@ public class ConversationFragment extends Fragment {
if (item.getConversation().getMode() == Conversation.MODE_SINGLE) { if (item.getConversation().getMode() == Conversation.MODE_SINGLE) {
viewHolder.imageView.setImageBitmap(mBitmapCache viewHolder.imageView.setImageBitmap(mBitmapCache
.get(item.getConversation().getName(), item .get(item.getConversation().getName(useSubject), item
.getConversation().getContact(), .getConversation().getContact(),
getActivity() getActivity()
.getApplicationContext())); .getApplicationContext()));
@ -250,7 +252,7 @@ public class ConversationFragment extends Fragment {
.getApplicationContext())); .getApplicationContext()));
} else { } else {
viewHolder.imageView.setImageBitmap(mBitmapCache viewHolder.imageView.setImageBitmap(mBitmapCache
.get(item.getConversation().getName(), .get(item.getConversation().getName(useSubject),
null, getActivity() null, getActivity()
.getApplicationContext())); .getApplicationContext()));
} }
@ -330,7 +332,7 @@ public class ConversationFragment extends Fragment {
if (!activity.shouldPaneBeOpen()) { if (!activity.shouldPaneBeOpen()) {
activity.getSlidingPaneLayout().closePane(); activity.getSlidingPaneLayout().closePane();
activity.getActionBar().setDisplayHomeAsUpEnabled(true); activity.getActionBar().setDisplayHomeAsUpEnabled(true);
activity.getActionBar().setTitle(conversation.getName()); activity.getActionBar().setTitle(conversation.getName(useSubject));
activity.invalidateOptionsMenu(); activity.invalidateOptionsMenu();
} }

View File

@ -9,7 +9,9 @@ import eu.siacs.conversations.entities.MucOptions;
import eu.siacs.conversations.entities.MucOptions.User; import eu.siacs.conversations.entities.MucOptions.User;
import eu.siacs.conversations.utils.UIHelper; import eu.siacs.conversations.utils.UIHelper;
import android.content.Context; import android.content.Context;
import android.content.SharedPreferences;
import android.os.Bundle; import android.os.Bundle;
import android.preference.PreferenceManager;
import android.util.Log; import android.util.Log;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.Menu; import android.view.Menu;
@ -99,6 +101,8 @@ public class MucDetailsActivity extends XmppActivity {
@Override @Override
void onBackendConnected() { void onBackendConnected() {
SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this);
boolean useSubject = preferences.getBoolean("use_subject_in_muc", true);
if (uuid != null) { if (uuid != null) {
for (Conversation mConv : xmppConnectionService.getConversations()) { for (Conversation mConv : xmppConnectionService.getConversations()) {
if (mConv.getUuid().equals(uuid)) { if (mConv.getUuid().equals(uuid)) {
@ -106,7 +110,7 @@ public class MucDetailsActivity extends XmppActivity {
} }
} }
if (this.conversation != null) { if (this.conversation != null) {
setTitle(conversation.getName()); setTitle(conversation.getName(useSubject));
mFullJid.setText(conversation.getContactJid().split("/")[0]); mFullJid.setText(conversation.getContactJid().split("/")[0]);
mYourNick.setText(conversation.getMucOptions().getNick()); mYourNick.setText(conversation.getMucOptions().getNick());
mRoleAffiliaton = (TextView) findViewById(R.id.muc_role); mRoleAffiliaton = (TextView) findViewById(R.id.muc_role);

View File

@ -13,8 +13,10 @@ import eu.siacs.conversations.entities.Contact;
import eu.siacs.conversations.entities.Conversation; import eu.siacs.conversations.entities.Conversation;
import eu.siacs.conversations.utils.UIHelper; import eu.siacs.conversations.utils.UIHelper;
import android.content.Intent; import android.content.Intent;
import android.content.SharedPreferences;
import android.graphics.Bitmap; import android.graphics.Bitmap;
import android.os.Bundle; import android.os.Bundle;
import android.preference.PreferenceManager;
import android.util.Log; import android.util.Log;
import android.view.View; import android.view.View;
import android.view.View.OnClickListener; import android.view.View.OnClickListener;
@ -66,6 +68,9 @@ public class ShareWithActivity extends XmppActivity {
@Override @Override
void onBackendConnected() { void onBackendConnected() {
SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this);
boolean useSubject = preferences.getBoolean("use_subject_in_muc", true);
Set<String> displayedContacts = new HashSet<String>(); Set<String> displayedContacts = new HashSet<String>();
conversations.removeAllViews(); conversations.removeAllViews();
List<Conversation> convList = xmppConnectionService.getConversations(); List<Conversation> convList = xmppConnectionService.getConversations();
@ -76,7 +81,7 @@ public class ShareWithActivity extends XmppActivity {
} }
}); });
for(final Conversation conversation : convList) { for(final Conversation conversation : convList) {
View view = createContactView(conversation.getName(), conversation.getLatestMessage().getBody().trim(), UIHelper.getContactPicture(conversation.getContact(),conversation.getName(), 90,this.getApplicationContext())); View view = createContactView(conversation.getName(useSubject), conversation.getLatestMessage().getBody().trim(), UIHelper.getContactPicture(conversation.getContact(),conversation.getName(useSubject), 90,this.getApplicationContext()));
view.setOnClickListener(new OnClickListener() { view.setOnClickListener(new OnClickListener() {
@Override @Override

View File

@ -96,7 +96,12 @@ public class MessageParser {
int status; int status;
String[] fromParts = packet.getFrom().split("/"); String[] fromParts = packet.getFrom().split("/");
Conversation conversation = service.findOrCreateConversation(account, fromParts[0],true); Conversation conversation = service.findOrCreateConversation(account, fromParts[0],true);
if ((fromParts.length == 1) || (packet.hasChild("subject"))) { if (packet.hasChild("subject")) {
conversation.getMucOptions().setSubject(packet.findChild("subject").getContent());
service.updateConversationInGui();
return null;
}
if ((fromParts.length == 1)) {
return null; return null;
} }
String counterPart = fromParts[1]; String counterPart = fromParts[1];

View File

@ -133,6 +133,7 @@ public class UIHelper {
.getSystemService(Context.NOTIFICATION_SERVICE); .getSystemService(Context.NOTIFICATION_SERVICE);
SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context); SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);
boolean useSubject = preferences.getBoolean("use_subject_in_muc", true);
boolean showNofifications = preferences.getBoolean("show_notification",true); boolean showNofifications = preferences.getBoolean("show_notification",true);
boolean vibrate = preferences.getBoolean("vibrate_on_notification", true); boolean vibrate = preferences.getBoolean("vibrate_on_notification", true);
boolean alwaysNotify = preferences.getBoolean("notify_in_conversation_when_highlighted", false); boolean alwaysNotify = preferences.getBoolean("notify_in_conversation_when_highlighted", false);
@ -171,9 +172,9 @@ public class UIHelper {
conversation.getName(), conversation.getName(),
(int) res (int) res
.getDimension(android.R.dimen.notification_large_icon_width)));*/ .getDimension(android.R.dimen.notification_large_icon_width)));*/
mBuilder.setLargeIcon(UIHelper.getContactPicture(conversation.getContact(), conversation.getName(), (int) res mBuilder.setLargeIcon(UIHelper.getContactPicture(conversation.getContact(), conversation.getName(useSubject), (int) res
.getDimension(android.R.dimen.notification_large_icon_width), context)); .getDimension(android.R.dimen.notification_large_icon_width), context));
mBuilder.setContentTitle(conversation.getName()); mBuilder.setContentTitle(conversation.getName(useSubject));
if (notify) { if (notify) {
mBuilder.setTicker(conversation.getLatestMessage().getBody().trim()); mBuilder.setTicker(conversation.getLatestMessage().getBody().trim());
} }
@ -203,11 +204,11 @@ public class UIHelper {
for (int i = 0; i < unread.size(); ++i) { for (int i = 0; i < unread.size(); ++i) {
targetUuid = unread.get(i).getUuid(); targetUuid = unread.get(i).getUuid();
if (i < unread.size() - 1) { if (i < unread.size() - 1) {
names.append(unread.get(i).getName() + ", "); names.append(unread.get(i).getName(useSubject) + ", ");
} else { } else {
names.append(unread.get(i).getName()); names.append(unread.get(i).getName(useSubject));
} }
style.addLine(Html.fromHtml("<b>" + unread.get(i).getName() style.addLine(Html.fromHtml("<b>" + unread.get(i).getName(useSubject)
+ "</b> " + unread.get(i).getLatestMessage().getBody().trim())); + "</b> " + unread.get(i).getLatestMessage().getBody().trim()));
} }
mBuilder.setContentTitle(unread.size() + " unread Conversations"); mBuilder.setContentTitle(unread.size() + " unread Conversations");