cleaned up shared text

This commit is contained in:
Daniel Gultsch 2014-05-21 16:43:19 +02:00
parent 9d2ce5ff98
commit 0de9d57420
6 changed files with 41 additions and 26 deletions

View file

@ -508,7 +508,7 @@ public class XmppConnectionService extends Service {
@Override @Override
public int onStartCommand(Intent intent, int flags, int startId) { public int onStartCommand(Intent intent, int flags, int startId) {
this.wakeLock.acquire(); this.wakeLock.acquire();
if ((intent.getAction()!=null)&&(intent.getAction().equals(ACTION_MERGE_PHONE_CONTACTS))) { if ((intent!=null)&&(intent.getAction()!=null)&&(intent.getAction().equals(ACTION_MERGE_PHONE_CONTACTS))) {
mergePhoneContactsWithRoster(); mergePhoneContactsWithRoster();
} }
ConnectivityManager cm = (ConnectivityManager) getApplicationContext() ConnectivityManager cm = (ConnectivityManager) getApplicationContext()
@ -1209,42 +1209,34 @@ public class XmppConnectionService extends Service {
} }
public void requestPresenceUpdatesFrom(Contact contact) { public void requestPresenceUpdatesFrom(Contact contact) {
// Requesting a Subscription type=subscribe
PresencePacket packet = new PresencePacket(); PresencePacket packet = new PresencePacket();
packet.setAttribute("type", "subscribe"); packet.setAttribute("type", "subscribe");
packet.setAttribute("to", contact.getJid()); packet.setAttribute("to", contact.getJid());
packet.setAttribute("from", contact.getAccount().getJid()); packet.setAttribute("from", contact.getAccount().getJid());
Log.d(LOGTAG, packet.toString());
contact.getAccount().getXmppConnection().sendPresencePacket(packet); contact.getAccount().getXmppConnection().sendPresencePacket(packet);
} }
public void stopPresenceUpdatesFrom(Contact contact) { public void stopPresenceUpdatesFrom(Contact contact) {
// Unsubscribing type='unsubscribe'
PresencePacket packet = new PresencePacket(); PresencePacket packet = new PresencePacket();
packet.setAttribute("type", "unsubscribe"); packet.setAttribute("type", "unsubscribe");
packet.setAttribute("to", contact.getJid()); packet.setAttribute("to", contact.getJid());
packet.setAttribute("from", contact.getAccount().getJid()); packet.setAttribute("from", contact.getAccount().getJid());
Log.d(LOGTAG, packet.toString());
contact.getAccount().getXmppConnection().sendPresencePacket(packet); contact.getAccount().getXmppConnection().sendPresencePacket(packet);
} }
public void stopPresenceUpdatesTo(Contact contact) { public void stopPresenceUpdatesTo(Contact contact) {
// Canceling a Subscription type=unsubscribed
PresencePacket packet = new PresencePacket(); PresencePacket packet = new PresencePacket();
packet.setAttribute("type", "unsubscribed"); packet.setAttribute("type", "unsubscribed");
packet.setAttribute("to", contact.getJid()); packet.setAttribute("to", contact.getJid());
packet.setAttribute("from", contact.getAccount().getJid()); packet.setAttribute("from", contact.getAccount().getJid());
Log.d(LOGTAG, packet.toString());
contact.getAccount().getXmppConnection().sendPresencePacket(packet); contact.getAccount().getXmppConnection().sendPresencePacket(packet);
} }
public void sendPresenceUpdatesTo(Contact contact) { public void sendPresenceUpdatesTo(Contact contact) {
// type='subscribed'
PresencePacket packet = new PresencePacket(); PresencePacket packet = new PresencePacket();
packet.setAttribute("type", "subscribed"); packet.setAttribute("type", "subscribed");
packet.setAttribute("to", contact.getJid()); packet.setAttribute("to", contact.getJid());
packet.setAttribute("from", contact.getAccount().getJid()); packet.setAttribute("from", contact.getAccount().getJid());
Log.d(LOGTAG, packet.toString());
contact.getAccount().getXmppConnection().sendPresencePacket(packet); contact.getAccount().getXmppConnection().sendPresencePacket(packet);
contact.resetOption(Contact.Options.PENDING_SUBSCRIPTION_REQUEST); contact.resetOption(Contact.Options.PENDING_SUBSCRIPTION_REQUEST);
} }

View file

@ -258,7 +258,7 @@ public class ContactsActivity extends XmppActivity {
conversation, subject.toString()); conversation, subject.toString());
xmppConnectionService.inviteToConference(conversation, xmppConnectionService.inviteToConference(conversation,
selectedContacts); selectedContacts);
switchToConversation(conversation, null); switchToConversation(conversation, null,false);
} }
}); });
builder.create().show(); builder.create().show();
@ -467,7 +467,7 @@ public class ContactsActivity extends XmppActivity {
Conversation conversation = xmppConnectionService Conversation conversation = xmppConnectionService
.findOrCreateConversation(account, contact.getJid(), muc); .findOrCreateConversation(account, contact.getJid(), muc);
switchToConversation(conversation, null); switchToConversation(conversation, null,false);
} }
@Override @Override
@ -494,7 +494,7 @@ public class ContactsActivity extends XmppActivity {
.findOrCreateConversation( .findOrCreateConversation(
accounts.get(which), finalJid, accounts.get(which), finalJid,
false); false);
switchToConversation(conversation, null); switchToConversation(conversation, null,false);
finish(); finish();
} }
}).show(); }).show();
@ -502,7 +502,7 @@ public class ContactsActivity extends XmppActivity {
Conversation conversation = xmppConnectionService Conversation conversation = xmppConnectionService
.findOrCreateConversation(this.accounts.get(0), .findOrCreateConversation(this.accounts.get(0),
jid, false); jid, false);
switchToConversation(conversation, null); switchToConversation(conversation, null,false);
finish(); finish();
} }
} }

View file

@ -621,6 +621,23 @@ public class ConversationActivity extends XmppActivity {
return super.onKeyDown(keyCode, event); return super.onKeyDown(keyCode, event);
} }
@Override
protected void onNewIntent (Intent intent) {
if ((Intent.ACTION_VIEW.equals(intent.getAction())&&(VIEW_CONVERSATION.equals(intent.getType())))) {
String convToView = (String) intent.getExtras().get(
CONVERSATION);
for (int i = 0; i < conversationList.size(); ++i) {
if (conversationList.get(i).getUuid().equals(convToView)) {
setSelectedConversation(conversationList.get(i));
}
}
paneShouldBeOpen = false;
String text = intent.getExtras().getString(TEXT, null);
swapConversationFragment().setText(text);
}
}
@Override @Override
public void onStart() { public void onStart() {
super.onStart(); super.onStart();

View file

@ -459,15 +459,11 @@ public class ConversationFragment extends Fragment {
} }
protected void highlightInConference(String nick) { protected void highlightInConference(String nick) {
if (chatMsg.getText().toString().isEmpty()) { String oldString = chatMsg.getText().toString().trim();
if (oldString.isEmpty()) {
chatMsg.setText(nick+": "); chatMsg.setText(nick+": ");
} else { } else {
String oldString = chatMsg.getText().toString(); chatMsg.setText(oldString+" "+nick+" ");
if (oldString.endsWith(" ")) {
chatMsg.setText(oldString+nick+" ");
} else {
chatMsg.setText(oldString+" "+nick+" ");
}
} }
int position = chatMsg.length(); int position = chatMsg.length();
Editable etext = chatMsg.getText(); Editable etext = chatMsg.getText();
@ -510,10 +506,16 @@ public class ConversationFragment extends Fragment {
if (this.conversation == null) { if (this.conversation == null) {
return; return;
} }
String oldString = conversation.getNextMessage().trim();
if (this.pastedText == null) { if (this.pastedText == null) {
this.chatMsg.setText(conversation.getNextMessage()); this.chatMsg.setText(oldString);
} else { } else {
chatMsg.setText(conversation.getNextMessage() + " " + pastedText);
if (oldString.isEmpty()) {
chatMsg.setText(pastedText);
} else {
chatMsg.setText(oldString + " " + pastedText);
}
pastedText = null; pastedText = null;
} }
int position = chatMsg.length(); int position = chatMsg.length();

View file

@ -80,7 +80,7 @@ public class ShareWithActivity extends XmppActivity {
@Override @Override
public void onClick(View v) { public void onClick(View v) {
String sharedText = getIntent().getStringExtra(Intent.EXTRA_TEXT); String sharedText = getIntent().getStringExtra(Intent.EXTRA_TEXT);
switchToConversation(conversation, sharedText); switchToConversation(conversation, sharedText,true);
finish(); finish();
} }
}); });
@ -114,7 +114,7 @@ public class ShareWithActivity extends XmppActivity {
public void onClick(View v) { public void onClick(View v) {
String sharedText = getIntent().getStringExtra(Intent.EXTRA_TEXT); String sharedText = getIntent().getStringExtra(Intent.EXTRA_TEXT);
Conversation conversation = xmppConnectionService.findOrCreateConversation(con.getAccount(), con.getJid(), false); Conversation conversation = xmppConnectionService.findOrCreateConversation(con.getAccount(), con.getJid(), false);
switchToConversation(conversation, sharedText); switchToConversation(conversation, sharedText,true);
finish(); finish();
} }
}); });

View file

@ -145,7 +145,7 @@ public abstract class XmppActivity extends Activity {
ExceptionHelper.init(getApplicationContext()); ExceptionHelper.init(getApplicationContext());
} }
public void switchToConversation(Conversation conversation, String text) { public void switchToConversation(Conversation conversation, String text, boolean newTask) {
Intent viewConversationIntent = new Intent(this, Intent viewConversationIntent = new Intent(this,
ConversationActivity.class); ConversationActivity.class);
viewConversationIntent.setAction(Intent.ACTION_VIEW); viewConversationIntent.setAction(Intent.ACTION_VIEW);
@ -155,8 +155,12 @@ public abstract class XmppActivity extends Activity {
viewConversationIntent.putExtra(ConversationActivity.TEXT, text); viewConversationIntent.putExtra(ConversationActivity.TEXT, text);
} }
viewConversationIntent.setType(ConversationActivity.VIEW_CONVERSATION); viewConversationIntent.setType(ConversationActivity.VIEW_CONVERSATION);
viewConversationIntent.setFlags(viewConversationIntent.getFlags() if (newTask) {
viewConversationIntent.setFlags(viewConversationIntent.getFlags() | Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_TASK_ON_HOME );
} else {
viewConversationIntent.setFlags(viewConversationIntent.getFlags()
| Intent.FLAG_ACTIVITY_CLEAR_TOP); | Intent.FLAG_ACTIVITY_CLEAR_TOP);
}
startActivity(viewConversationIntent); startActivity(viewConversationIntent);
} }