process intents

This commit is contained in:
Daniel Gultsch 2018-02-24 16:22:17 +01:00
parent 4c8cbfe966
commit e68fe13a22
3 changed files with 56 additions and 16 deletions

View file

@ -182,7 +182,7 @@ public class ConversationActivity extends XmppActivity implements OnConversation
} else {
mainNeedsRefresh = true;
}
conversationFragment.reInit(conversation);
conversationFragment.reInit(conversation, extras);
if (mainNeedsRefresh) {
refreshFragment(R.id.main_fragment);
} else {

View file

@ -95,6 +95,7 @@ import eu.siacs.conversations.utils.StylingHelper;
import eu.siacs.conversations.utils.UIHelper;
import eu.siacs.conversations.xmpp.XmppConnection;
import eu.siacs.conversations.xmpp.chatstate.ChatState;
import eu.siacs.conversations.xmpp.jid.InvalidJidException;
import eu.siacs.conversations.xmpp.jid.Jid;
import static eu.siacs.conversations.ui.XmppActivity.EXTRA_ACCOUNT;
@ -128,6 +129,7 @@ public class ConversationFragment extends XmppFragment implements EditMessage.Ke
final protected List<Message> messageList = new ArrayList<>();
private final PendingItem<ActivityResult> postponedActivityResult = new PendingItem<>();
private final PendingItem<String> pendingConversationsUuid = new PendingItem<>();
private final PendingItem<Bundle> pendingExtras = new PendingItem<>();
public Uri mPendingEditorContent = null;
protected MessageAdapter messageListAdapter;
private Conversation conversation;
@ -1485,7 +1487,7 @@ public class ConversationFragment extends XmppFragment implements EditMessage.Ke
conversation.getAccount().getPgpDecryptionService().decrypt(message, false);
}
protected void privateMessageWith(final Jid counterpart) {
private void privateMessageWith(final Jid counterpart) {
if (conversation.setOutgoingChatState(Config.DEFAULT_CHATSTATE)) {
activity.xmppConnectionService.sendChatState(conversation);
}
@ -1508,7 +1510,7 @@ public class ConversationFragment extends XmppFragment implements EditMessage.Ke
}
protected void highlightInConference(String nick) {
private void highlightInConference(String nick) {
final Editable editable = this.binding.textinput.getText();
String oldString = editable.toString().trim();
final int pos = this.binding.textinput.getSelectionStart();
@ -1545,7 +1547,6 @@ public class ConversationFragment extends XmppFragment implements EditMessage.Ke
@Override
public void onActivityCreated(Bundle savedInstanceState) {
Log.d(Config.LOGTAG,"ConversationFragment.onActivityCreated()");
super.onActivityCreated(savedInstanceState);
if (savedInstanceState == null) {
return;
@ -1560,6 +1561,10 @@ public class ConversationFragment extends XmppFragment implements EditMessage.Ke
public void onStart() {
super.onStart();
reInit(conversation);
final Bundle extras = pendingExtras.pop();
if (extras != null) {
processExtras(extras);
}
}
@Override
@ -1586,7 +1591,18 @@ public class ConversationFragment extends XmppFragment implements EditMessage.Ke
}
}
public void reInit(Conversation conversation) {
public void reInit(Conversation conversation, Bundle extras) {
this.reInit(conversation);
if (extras != null) {
if (activity != null) {
processExtras(extras);
} else {
pendingExtras.push(extras);
}
}
}
private void reInit(Conversation conversation) {
Log.d(Config.LOGTAG, "reInit()");
if (conversation == null) {
Log.d(Config.LOGTAG, "conversation was null :(");
@ -1645,6 +1661,32 @@ public class ConversationFragment extends XmppFragment implements EditMessage.Ke
}
}
private void processExtras(Bundle extras) {
final String downloadUuid = extras.getString(ConversationActivity.EXTRA_DOWNLOAD_UUID);
final String text = extras.getString(ConversationActivity.EXTRA_TEXT);
final String nick = extras.getString(ConversationActivity.EXTRA_NICK);
final boolean pm = extras.getBoolean(ConversationActivity.EXTRA_IS_PRIVATE_MESSAGE, false);
if (nick != null) {
if (pm) {
Jid jid = conversation.getJid();
try {
Jid next = Jid.fromParts(jid.getLocalpart(), jid.getDomainpart(), nick);
privateMessageWith(next);
} catch (final InvalidJidException ignored) {
//do nothing
}
} else {
highlightInConference(nick);
}
} else {
appendText(text);
}
final Message message = downloadUuid == null ? null : conversation.findMessageWithFileAndUuid(downloadUuid);
if (message != null) {
startDownloadable(message);
}
}
private boolean showBlockSubmenu(View view) {
final Jid jid = conversation.getJid();
if (jid.isDomainJid()) {

View file

@ -175,7 +175,7 @@ public class ConversationLegacyActivity extends XmppActivity
if (getSelectedConversation() != conversationList.get(position)) {
ConversationLegacyActivity.this.mConversationFragment.stopScrolling();
setSelectedConversation(conversationList.get(position));
ConversationLegacyActivity.this.mConversationFragment.reInit(getSelectedConversation());
//ConversationLegacyActivity.this.mConversationFragment.reInit(getSelectedConversation());
conversationWasSelectedByKeyboard = false;
}
hideConversationsOverview();
@ -206,8 +206,7 @@ public class ConversationLegacyActivity extends XmppActivity
return null;
} else if (formerlySelected) {
setSelectedConversation(listAdapter.getItem(0));
ConversationLegacyActivity.this.mConversationFragment
.reInit(getSelectedConversation());
//ConversationLegacyActivity.this.mConversationFragment.reInit(getSelectedConversation());
}
return new EnhancedListView.Undoable() {
@ -217,8 +216,7 @@ public class ConversationLegacyActivity extends XmppActivity
listAdapter.insert(swipedConversation, position);
if (formerlySelected) {
setSelectedConversation(swipedConversation);
ConversationLegacyActivity.this.mConversationFragment
.reInit(getSelectedConversation());
//ConversationLegacyActivity.this.mConversationFragment.reInit(getSelectedConversation());
}
swipedConversation = null;
listView.setSelectionFromTop(index + (listView.getChildCount() < position ? 1 : 0), top);
@ -294,7 +292,7 @@ public class ConversationLegacyActivity extends XmppActivity
public void switchToConversation(Conversation conversation) {
setSelectedConversation(conversation);
runOnUiThread(() -> {
ConversationLegacyActivity.this.mConversationFragment.reInit(getSelectedConversation());
//ConversationLegacyActivity.this.mConversationFragment.reInit(getSelectedConversation());
openConversation();
});
}
@ -373,7 +371,7 @@ public class ConversationLegacyActivity extends XmppActivity
if (reinit) {
if (conversationList.size() > 0) {
setSelectedConversation(conversationList.get(0));
this.mConversationFragment.reInit(getSelectedConversation());
//this.mConversationFragment.reInit(getSelectedConversation());
} else {
setSelectedConversation(null);
if (mRedirected.compareAndSet(false, true)) {
@ -497,7 +495,7 @@ public class ConversationLegacyActivity extends XmppActivity
this.conversationWasSelectedByKeyboard = true;
this.mConversationFragment.stopScrolling();
setSelectedConversation(this.conversationList.get(index));
this.mConversationFragment.reInit(getSelectedConversation());
//this.mConversationFragment.reInit(getSelectedConversation());
if (index > listView.getLastVisiblePosition() - 1 || index < listView.getFirstVisiblePosition() + 1) {
this.listView.setSelection(index);
}
@ -686,7 +684,7 @@ public class ConversationLegacyActivity extends XmppActivity
showConversationsOverview();
clearPending();
setSelectedConversation(conversationList.get(0));
this.mConversationFragment.reInit(getSelectedConversation());
//this.mConversationFragment.reInit(getSelectedConversation());
}
private void handleViewConversationIntent(final Intent intent) {
@ -697,7 +695,7 @@ public class ConversationLegacyActivity extends XmppActivity
final boolean pm = intent.getBooleanExtra(PRIVATE_MESSAGE, false);
this.mConversationFragment.stopScrolling();
if (selectConversationByUuid(uuid)) {
this.mConversationFragment.reInit(getSelectedConversation());
/*this.mConversationFragment.reInit(getSelectedConversation());
if (nick != null) {
if (pm) {
Jid jid = getSelectedConversation().getJid();
@ -724,7 +722,7 @@ public class ConversationLegacyActivity extends XmppActivity
if (message != null) {
//startDownloadable(message);
}
}
}*/
} else {
mUnprocessedNewIntent = false;
}