aboutsummaryrefslogtreecommitdiffstats
path: root/src/eu
diff options
context:
space:
mode:
authoriNPUTmice <daniel@gultsch.de>2014-09-12 17:53:42 +0200
committeriNPUTmice <daniel@gultsch.de>2014-09-12 17:53:42 +0200
commit83c3b33f18429dc8788c2b58a31d150bee553d10 (patch)
treef4451e53a65dd25fd434dcb08bdaad53137e987a /src/eu
parentcee898084ee27592d774c8f62f5be7fd1edf821b (diff)
parent73cba91c9b08ff512104897b32837f9824f1cd3e (diff)
Merge branch 'development'0.7.1
Diffstat (limited to 'src/eu')
-rw-r--r--src/eu/siacs/conversations/parser/MessageParser.java16
-rw-r--r--src/eu/siacs/conversations/services/XmppConnectionService.java11
-rw-r--r--src/eu/siacs/conversations/ui/ContactDetailsActivity.java14
-rw-r--r--src/eu/siacs/conversations/ui/ConversationActivity.java104
-rw-r--r--src/eu/siacs/conversations/ui/ConversationFragment.java57
-rw-r--r--src/eu/siacs/conversations/ui/XmppActivity.java29
-rw-r--r--src/eu/siacs/conversations/ui/adapter/MessageAdapter.java6
-rw-r--r--src/eu/siacs/conversations/xmpp/stanzas/MessagePacket.java5
8 files changed, 172 insertions, 70 deletions
diff --git a/src/eu/siacs/conversations/parser/MessageParser.java b/src/eu/siacs/conversations/parser/MessageParser.java
index bd136a33..534c9dea 100644
--- a/src/eu/siacs/conversations/parser/MessageParser.java
+++ b/src/eu/siacs/conversations/parser/MessageParser.java
@@ -202,7 +202,7 @@ public class MessageParser extends AbstractParser implements
if ((message == null) || (!message.hasChild("body"))) {
if (status == Message.STATUS_RECEIVED
&& message.getAttribute("from") != null) {
- parseNormal(message, account);
+ parseNonMessage(message, account);
}
return null;
}
@@ -256,13 +256,12 @@ public class MessageParser extends AbstractParser implements
packet.getId(), Message.STATUS_SEND_FAILED);
}
- private void parseNormal(Element packet, Account account) {
+ private void parseNonMessage(Element packet, Account account) {
if (packet.hasChild("event", "http://jabber.org/protocol/pubsub#event")) {
Element event = packet.findChild("event",
"http://jabber.org/protocol/pubsub#event");
parseEvent(event, packet.getAttribute("from"), account);
- }
- if (packet.hasChild("displayed", "urn:xmpp:chat-markers:0")) {
+ } else if (packet.hasChild("displayed", "urn:xmpp:chat-markers:0")) {
String id = packet
.findChild("displayed", "urn:xmpp:chat-markers:0")
.getAttribute("id");
@@ -294,7 +293,6 @@ public class MessageParser extends AbstractParser implements
mXmppConnectionService.updateConversationUi();
}
}
-
} else if (packet.hasChild("x", "jabber:x:conference")) {
Element x = packet.findChild("x", "jabber:x:conference");
String jid = x.getAttribute("jid");
@@ -382,7 +380,7 @@ public class MessageParser extends AbstractParser implements
this.parseNick(packet, account);
- if ((packet.getType() == MessagePacket.TYPE_CHAT)) {
+ if ((packet.getType() == MessagePacket.TYPE_CHAT || packet.getType() == MessagePacket.TYPE_NORMAL)) {
if ((packet.getBody() != null)
&& (packet.getBody().startsWith("?OTR"))) {
message = this.parseOtrChat(packet, account);
@@ -407,9 +405,8 @@ public class MessageParser extends AbstractParser implements
}
}
} else {
- parseNormal(packet, account);
+ parseNonMessage(packet, account);
}
-
} else if (packet.getType() == MessagePacket.TYPE_GROUPCHAT) {
message = this.parseGroupchat(packet, account);
if (message != null) {
@@ -424,9 +421,6 @@ public class MessageParser extends AbstractParser implements
} else if (packet.getType() == MessagePacket.TYPE_ERROR) {
this.parseError(packet, account);
return;
- } else if (packet.getType() == MessagePacket.TYPE_NORMAL) {
- this.parseNormal(packet, account);
- return;
} else if (packet.getType() == MessagePacket.TYPE_HEADLINE) {
this.parseHeadline(packet, account);
return;
diff --git a/src/eu/siacs/conversations/services/XmppConnectionService.java b/src/eu/siacs/conversations/services/XmppConnectionService.java
index f272486c..c019682e 100644
--- a/src/eu/siacs/conversations/services/XmppConnectionService.java
+++ b/src/eu/siacs/conversations/services/XmppConnectionService.java
@@ -109,6 +109,7 @@ public class XmppConnectionService extends Service {
private OnAccountUpdate mOnAccountUpdate = null;
private int accountChangedListenerCount = 0;
private OnRosterUpdate mOnRosterUpdate = null;
+ private int rosterChangedListenerCount = 0;
public OnContactStatusChanged onContactStatusChanged = new OnContactStatusChanged() {
@Override
@@ -997,12 +998,16 @@ public class XmppConnectionService extends Service {
switchToForeground();
}
this.mOnRosterUpdate = listener;
+ this.rosterChangedListenerCount++;
}
public void removeOnRosterUpdateListener() {
- this.mOnRosterUpdate = null;
- if (checkListeners()) {
- switchToBackground();
+ this.rosterChangedListenerCount--;
+ if (this.rosterChangedListenerCount == 0) {
+ this.mOnRosterUpdate = null;
+ if (checkListeners()) {
+ switchToBackground();
+ }
}
}
diff --git a/src/eu/siacs/conversations/ui/ContactDetailsActivity.java b/src/eu/siacs/conversations/ui/ContactDetailsActivity.java
index 8de2ce80..9d384c60 100644
--- a/src/eu/siacs/conversations/ui/ContactDetailsActivity.java
+++ b/src/eu/siacs/conversations/ui/ContactDetailsActivity.java
@@ -278,31 +278,31 @@ public class ContactDetailsActivity extends XmppActivity {
switch (contact.getMostAvailableStatus()) {
case Presences.CHAT:
status.setText(R.string.contact_status_free_to_chat);
- status.setTextColor(0xFF83b600);
+ status.setTextColor(mColorGreen);
break;
case Presences.ONLINE:
status.setText(R.string.contact_status_online);
- status.setTextColor(0xFF83b600);
+ status.setTextColor(mColorGreen);
break;
case Presences.AWAY:
status.setText(R.string.contact_status_away);
- status.setTextColor(0xFFffa713);
+ status.setTextColor(mColorOrange);
break;
case Presences.XA:
status.setText(R.string.contact_status_extended_away);
- status.setTextColor(0xFFffa713);
+ status.setTextColor(mColorOrange);
break;
case Presences.DND:
status.setText(R.string.contact_status_do_not_disturb);
- status.setTextColor(0xFFe92727);
+ status.setTextColor(mColorRed);
break;
case Presences.OFFLINE:
status.setText(R.string.contact_status_offline);
- status.setTextColor(0xFFe92727);
+ status.setTextColor(mSecondaryTextColor);
break;
default:
status.setText(R.string.contact_status_offline);
- status.setTextColor(0xFFe92727);
+ status.setTextColor(mSecondaryTextColor);
break;
}
if (contact.getPresences().size() > 1) {
diff --git a/src/eu/siacs/conversations/ui/ConversationActivity.java b/src/eu/siacs/conversations/ui/ConversationActivity.java
index 5eedda1c..40ad0f33 100644
--- a/src/eu/siacs/conversations/ui/ConversationActivity.java
+++ b/src/eu/siacs/conversations/ui/ConversationActivity.java
@@ -7,7 +7,9 @@ import eu.siacs.conversations.R;
import eu.siacs.conversations.entities.Contact;
import eu.siacs.conversations.entities.Conversation;
import eu.siacs.conversations.entities.Message;
+import eu.siacs.conversations.services.XmppConnectionService.OnAccountUpdate;
import eu.siacs.conversations.services.XmppConnectionService.OnConversationUpdate;
+import eu.siacs.conversations.services.XmppConnectionService.OnRosterUpdate;
import eu.siacs.conversations.ui.adapter.ConversationAdapter;
import eu.siacs.conversations.utils.ExceptionHelper;
import eu.siacs.conversations.utils.UIHelper;
@@ -39,7 +41,8 @@ import android.widget.PopupMenu;
import android.widget.PopupMenu.OnMenuItemClickListener;
import android.widget.Toast;
-public class ConversationActivity extends XmppActivity {
+public class ConversationActivity extends XmppActivity implements
+ OnAccountUpdate, OnConversationUpdate, OnRosterUpdate {
public static final String VIEW_CONVERSATION = "viewConversation";
public static final String CONVERSATION = "conversationUuid";
@@ -67,34 +70,6 @@ public class ConversationActivity extends XmppActivity {
private boolean paneShouldBeOpen = true;
private ArrayAdapter<Conversation> listAdapter;
- private OnConversationUpdate onConvChanged = new OnConversationUpdate() {
-
- @Override
- public void onConversationUpdate() {
- runOnUiThread(new Runnable() {
-
- @Override
- public void run() {
- updateConversationList();
- if (paneShouldBeOpen) {
- if (conversationList.size() >= 1) {
- swapConversationFragment();
- } else {
- startActivity(new Intent(getApplicationContext(),
- StartConversationActivity.class));
- finish();
- }
- }
- ConversationFragment selectedFragment = (ConversationFragment) getFragmentManager()
- .findFragmentByTag("conversation");
- if (selectedFragment != null) {
- selectedFragment.updateMessages();
- }
- }
- });
- }
- };
-
protected ConversationActivity activity = this;
private Toast prepareImageToast;
@@ -602,7 +577,7 @@ public class ConversationActivity extends XmppActivity {
this.onBackendConnected();
}
if (conversationList.size() >= 1) {
- onConvChanged.onConversationUpdate();
+ this.onConversationUpdate();
}
}
@@ -610,6 +585,8 @@ public class ConversationActivity extends XmppActivity {
protected void onStop() {
if (xmppConnectionServiceBound) {
xmppConnectionService.removeOnConversationListChangedListener();
+ xmppConnectionService.removeOnAccountListChangedListener();
+ xmppConnectionService.removeOnRosterUpdateListener();
}
super.onStop();
}
@@ -672,8 +649,9 @@ public class ConversationActivity extends XmppActivity {
public void registerListener() {
if (xmppConnectionServiceBound) {
- xmppConnectionService
- .setOnConversationListChangedListener(this.onConvChanged);
+ xmppConnectionService.setOnConversationListChangedListener(this);
+ xmppConnectionService.setOnAccountListChangedListener(this);
+ xmppConnectionService.setOnRosterUpdateListener(this);
}
}
@@ -806,7 +784,65 @@ public class ConversationActivity extends XmppActivity {
}
public boolean forceEncryption() {
- return PreferenceManager.getDefaultSharedPreferences(
- getApplicationContext()).getBoolean("force_encryption", false);
+ return getPreferences().getBoolean("force_encryption", false);
+ }
+
+ public boolean useSendButtonToIndicateStatus() {
+ return getPreferences().getBoolean("send_button_status", false);
+ }
+
+ @Override
+ public void onAccountUpdate() {
+ final ConversationFragment fragment = (ConversationFragment) getFragmentManager()
+ .findFragmentByTag("conversation");
+ if (fragment != null) {
+ runOnUiThread(new Runnable() {
+
+ @Override
+ public void run() {
+ fragment.updateMessages();
+ }
+ });
+ }
+ }
+
+ @Override
+ public void onConversationUpdate() {
+ runOnUiThread(new Runnable() {
+
+ @Override
+ public void run() {
+ updateConversationList();
+ if (paneShouldBeOpen) {
+ if (conversationList.size() >= 1) {
+ swapConversationFragment();
+ } else {
+ startActivity(new Intent(getApplicationContext(),
+ StartConversationActivity.class));
+ finish();
+ }
+ }
+ ConversationFragment selectedFragment = (ConversationFragment) getFragmentManager()
+ .findFragmentByTag("conversation");
+ if (selectedFragment != null) {
+ selectedFragment.updateMessages();
+ }
+ }
+ });
+ }
+
+ @Override
+ public void onRosterUpdate() {
+ final ConversationFragment fragment = (ConversationFragment) getFragmentManager()
+ .findFragmentByTag("conversation");
+ if (fragment != null) {
+ runOnUiThread(new Runnable() {
+
+ @Override
+ public void run() {
+ fragment.updateMessages();
+ }
+ });
+ }
}
}
diff --git a/src/eu/siacs/conversations/ui/ConversationFragment.java b/src/eu/siacs/conversations/ui/ConversationFragment.java
index b73bcadb..e09958cb 100644
--- a/src/eu/siacs/conversations/ui/ConversationFragment.java
+++ b/src/eu/siacs/conversations/ui/ConversationFragment.java
@@ -12,6 +12,7 @@ import eu.siacs.conversations.entities.Contact;
import eu.siacs.conversations.entities.Conversation;
import eu.siacs.conversations.entities.Message;
import eu.siacs.conversations.entities.MucOptions;
+import eu.siacs.conversations.entities.Presences;
import eu.siacs.conversations.services.XmppConnectionService;
import eu.siacs.conversations.ui.EditMessage.OnEnterPressed;
import eu.siacs.conversations.ui.XmppActivity.OnPresenceSelected;
@@ -61,6 +62,7 @@ public class ConversationFragment extends Fragment {
protected String queuedPqpMessage = null;
private EditMessage mEditMessage;
+ private ImageButton mSendButton;
private String pastedText = null;
private RelativeLayout snackbar;
private TextView snackbarMessage;
@@ -255,9 +257,8 @@ public class ConversationFragment extends Fragment {
}
});
- ImageButton sendButton = (ImageButton) view
- .findViewById(R.id.textSendButton);
- sendButton.setOnClickListener(this.mSendButtonListener);
+ mSendButton = (ImageButton) view.findViewById(R.id.textSendButton);
+ mSendButton.setOnClickListener(this.mSendButtonListener);
snackbar = (RelativeLayout) view.findViewById(R.id.snackbar);
snackbarMessage = (TextView) view.findViewById(R.id.snackbar_message);
@@ -485,6 +486,7 @@ public class ConversationFragment extends Fragment {
activity.getConversationList(), null, false);
activity.updateConversationList();
}
+ this.updateSendButton();
}
}
@@ -497,6 +499,55 @@ public class ConversationFragment extends Fragment {
updateChatMsgHint();
}
+ public void updateSendButton() {
+ Conversation c = this.conversation;
+ if (activity.useSendButtonToIndicateStatus() && c != null
+ && c.getAccount().getStatus() == Account.STATUS_ONLINE) {
+ if (c.getMode() == Conversation.MODE_SINGLE) {
+ switch (c.getContact().getMostAvailableStatus()) {
+ case Presences.CHAT:
+ this.mSendButton
+ .setImageResource(R.drawable.ic_action_send_now_online);
+ break;
+ case Presences.ONLINE:
+ this.mSendButton
+ .setImageResource(R.drawable.ic_action_send_now_online);
+ break;
+ case Presences.AWAY:
+ this.mSendButton
+ .setImageResource(R.drawable.ic_action_send_now_away);
+ break;
+ case Presences.XA:
+ this.mSendButton
+ .setImageResource(R.drawable.ic_action_send_now_away);
+ break;
+ case Presences.DND:
+ this.mSendButton
+ .setImageResource(R.drawable.ic_action_send_now_dnd);
+ break;
+ default:
+ this.mSendButton
+ .setImageResource(R.drawable.ic_action_send_now_offline);
+ break;
+ }
+ } else if (c.getMode() == Conversation.MODE_MULTI) {
+ if (c.getMucOptions().online()) {
+ this.mSendButton
+ .setImageResource(R.drawable.ic_action_send_now_online);
+ } else {
+ this.mSendButton
+ .setImageResource(R.drawable.ic_action_send_now_offline);
+ }
+ } else {
+ this.mSendButton
+ .setImageResource(R.drawable.ic_action_send_now_offline);
+ }
+ } else {
+ this.mSendButton
+ .setImageResource(R.drawable.ic_action_send_now_offline);
+ }
+ }
+
protected void updateStatusMessages() {
if (conversation.getMode() == Conversation.MODE_SINGLE) {
for (int i = this.messageList.size() - 1; i >= 0; --i) {
diff --git a/src/eu/siacs/conversations/ui/XmppActivity.java b/src/eu/siacs/conversations/ui/XmppActivity.java
index f13c112a..4ee51580 100644
--- a/src/eu/siacs/conversations/ui/XmppActivity.java
+++ b/src/eu/siacs/conversations/ui/XmppActivity.java
@@ -2,6 +2,7 @@ package eu.siacs.conversations.ui;
import java.io.FileNotFoundException;
import java.lang.ref.WeakReference;
+import java.util.List;
import java.util.concurrent.RejectedExecutionException;
import eu.siacs.conversations.Config;
@@ -24,6 +25,8 @@ import android.content.DialogInterface;
import android.content.SharedPreferences;
import android.content.DialogInterface.OnClickListener;
import android.content.IntentSender.SendIntentException;
+import android.content.pm.PackageManager;
+import android.content.pm.ResolveInfo;
import android.content.res.Resources;
import android.content.Intent;
import android.content.ServiceConnection;
@@ -55,7 +58,9 @@ public abstract class XmppActivity extends Activity {
protected int mPrimaryTextColor;
protected int mSecondaryTextColor;
- protected int mWarningTextColor;
+ protected int mColorRed;
+ protected int mColorOrange;
+ protected int mColorGreen;
protected int mPrimaryColor;
private DisplayMetrics metrics;
@@ -151,8 +156,20 @@ public abstract class XmppActivity extends Activity {
public void onClick(DialogInterface dialog, int which) {
Uri uri = Uri
.parse("market://details?id=org.sufficientlysecure.keychain");
- Intent intent = new Intent(Intent.ACTION_VIEW, uri);
- startActivity(intent);
+ Intent marketIntent = new Intent(Intent.ACTION_VIEW,
+ uri);
+ PackageManager manager = getApplicationContext()
+ .getPackageManager();
+ List<ResolveInfo> infos = manager
+ .queryIntentActivities(marketIntent, 0);
+ if (infos.size() > 0) {
+ startActivity(marketIntent);
+ } else {
+ uri = Uri.parse("http://www.openkeychain.org/");
+ Intent browserIntent = new Intent(
+ Intent.ACTION_VIEW, uri);
+ startActivity(browserIntent);
+ }
finish();
}
});
@@ -183,7 +200,9 @@ public abstract class XmppActivity extends Activity {
ExceptionHelper.init(getApplicationContext());
mPrimaryTextColor = getResources().getColor(R.color.primarytext);
mSecondaryTextColor = getResources().getColor(R.color.secondarytext);
- mWarningTextColor = getResources().getColor(R.color.warningtext);
+ mColorRed = getResources().getColor(R.color.red);
+ mColorOrange = getResources().getColor(R.color.orange);
+ mColorGreen = getResources().getColor(R.color.green);
mPrimaryColor = getResources().getColor(R.color.primary);
if (getPreferences().getBoolean("use_larger_font", false)) {
setTheme(R.style.ConversationsTheme_LargerText);
@@ -475,7 +494,7 @@ public abstract class XmppActivity extends Activity {
}
public int getWarningTextColor() {
- return this.mWarningTextColor;
+ return this.mColorRed;
}
public int getPrimaryColor() {
diff --git a/src/eu/siacs/conversations/ui/adapter/MessageAdapter.java b/src/eu/siacs/conversations/ui/adapter/MessageAdapter.java
index 967042d8..db01eabe 100644
--- a/src/eu/siacs/conversations/ui/adapter/MessageAdapter.java
+++ b/src/eu/siacs/conversations/ui/adapter/MessageAdapter.java
@@ -145,7 +145,7 @@ public class MessageAdapter extends ArrayAdapter<Message> {
break;
}
if (error) {
- viewHolder.time.setTextColor(0xFFe92727);
+ viewHolder.time.setTextColor(activity.getWarningTextColor());
} else {
viewHolder.time.setTextColor(activity.getSecondaryTextColor());
}
@@ -191,7 +191,7 @@ public class MessageAdapter extends ArrayAdapter<Message> {
viewHolder.image.setVisibility(View.GONE);
viewHolder.messageBody.setVisibility(View.VISIBLE);
viewHolder.messageBody.setText(getContext().getString(r));
- viewHolder.messageBody.setTextColor(0xff33B5E5);
+ viewHolder.messageBody.setTextColor(activity.getSecondaryTextColor());
viewHolder.messageBody.setTypeface(null, Typeface.ITALIC);
viewHolder.messageBody.setTextIsSelectable(false);
}
@@ -204,7 +204,7 @@ public class MessageAdapter extends ArrayAdapter<Message> {
viewHolder.messageBody.setVisibility(View.VISIBLE);
viewHolder.messageBody.setText(getContext().getString(
R.string.decryption_failed));
- viewHolder.messageBody.setTextColor(0xFFe92727);
+ viewHolder.messageBody.setTextColor(activity.getWarningTextColor());
viewHolder.messageBody.setTypeface(null, Typeface.NORMAL);
viewHolder.messageBody.setTextIsSelectable(false);
}
diff --git a/src/eu/siacs/conversations/xmpp/stanzas/MessagePacket.java b/src/eu/siacs/conversations/xmpp/stanzas/MessagePacket.java
index 386d9dc8..4e7b532b 100644
--- a/src/eu/siacs/conversations/xmpp/stanzas/MessagePacket.java
+++ b/src/eu/siacs/conversations/xmpp/stanzas/MessagePacket.java
@@ -4,7 +4,6 @@ import eu.siacs.conversations.xml.Element;
public class MessagePacket extends AbstractStanza {
public static final int TYPE_CHAT = 0;
- public static final int TYPE_UNKNOWN = 1;
public static final int TYPE_NORMAL = 2;
public static final int TYPE_GROUPCHAT = 3;
public static final int TYPE_ERROR = 4;
@@ -38,8 +37,6 @@ public class MessagePacket extends AbstractStanza {
case TYPE_GROUPCHAT:
this.setAttribute("type", "groupchat");
break;
- case TYPE_UNKNOWN:
- break;
case TYPE_NORMAL:
break;
default:
@@ -63,7 +60,7 @@ public class MessagePacket extends AbstractStanza {
} else if (type.equals("headline")) {
return TYPE_HEADLINE;
} else {
- return TYPE_UNKNOWN;
+ return TYPE_NORMAL;
}
}
}