diff options
4 files changed, 53 insertions, 32 deletions
diff --git a/src/main/AndroidManifest.xml b/src/main/AndroidManifest.xml index 937b6813..8fdfa85b 100644 --- a/src/main/AndroidManifest.xml +++ b/src/main/AndroidManifest.xml @@ -114,7 +114,7 @@ <category android:name="android.intent.category.DEFAULT" /> - <data android:mimeType="image/*" /> + <data android:mimeType="*/*" /> </intent-filter> </activity> <activity diff --git a/src/main/java/eu/siacs/conversations/parser/MessageParser.java b/src/main/java/eu/siacs/conversations/parser/MessageParser.java index e55a4a28..a395be78 100644 --- a/src/main/java/eu/siacs/conversations/parser/MessageParser.java +++ b/src/main/java/eu/siacs/conversations/parser/MessageParser.java @@ -278,6 +278,10 @@ public class MessageParser extends AbstractParser implements if (result == null ) { return null; } + final MessageArchiveService.Query query = this.mXmppConnectionService.getMessageArchiveService().findQuery(result.getAttribute("queryid")); + if (query!=null) { + query.incrementTotalCount(); + } final Element forwarded = result.findChild("forwarded","urn:xmpp:forward:0"); if (forwarded == null) { return null; @@ -304,7 +308,6 @@ public class MessageParser extends AbstractParser implements final long timestamp = getTimestamp(forwarded); final Jid to = message.getAttributeAsJid("to"); final Jid from = message.getAttributeAsJid("from"); - final MessageArchiveService.Query query = this.mXmppConnectionService.getMessageArchiveService().findQuery(result.getAttribute("queryid")); Jid counterpart; int status; Conversation conversation; @@ -324,8 +327,11 @@ public class MessageParser extends AbstractParser implements finishedMessage.setCounterpart(counterpart); finishedMessage.setRemoteMsgId(message.getAttribute("id")); finishedMessage.setServerMsgId(result.getAttribute("id")); + if (conversation.hasDuplicateMessage(finishedMessage)) { + return null; + } if (query!=null) { - query.incrementCount(); + query.incrementMessageCount(); } return finishedMessage; } diff --git a/src/main/java/eu/siacs/conversations/services/MessageArchiveService.java b/src/main/java/eu/siacs/conversations/services/MessageArchiveService.java index 66a2d48a..27689027 100644 --- a/src/main/java/eu/siacs/conversations/services/MessageArchiveService.java +++ b/src/main/java/eu/siacs/conversations/services/MessageArchiveService.java @@ -311,11 +311,14 @@ public class MessageArchiveService implements OnAdvancedStreamFeaturesLoaded { return this.account; } - public void incrementCount() { - this.count++; + public void incrementTotalCount() { this.totalCount++; } + public void incrementMessageCount() { + this.count++; + } + public int getTotalCount() { return this.totalCount; } diff --git a/src/main/java/eu/siacs/conversations/ui/ShareWithActivity.java b/src/main/java/eu/siacs/conversations/ui/ShareWithActivity.java index 609dc280..be5eee99 100644 --- a/src/main/java/eu/siacs/conversations/ui/ShareWithActivity.java +++ b/src/main/java/eu/siacs/conversations/ui/ShareWithActivity.java @@ -1,17 +1,5 @@ package eu.siacs.conversations.ui; -import java.util.ArrayList; -import java.util.List; - -import eu.siacs.conversations.Config; -import eu.siacs.conversations.R; -import eu.siacs.conversations.entities.Account; -import eu.siacs.conversations.entities.Conversation; -import eu.siacs.conversations.entities.Message; -import eu.siacs.conversations.ui.adapter.ConversationAdapter; -import eu.siacs.conversations.xmpp.jid.InvalidJidException; -import eu.siacs.conversations.xmpp.jid.Jid; - import android.app.PendingIntent; import android.content.Intent; import android.net.Uri; @@ -25,10 +13,24 @@ import android.widget.AdapterView.OnItemClickListener; import android.widget.ListView; import android.widget.Toast; +import java.net.URLConnection; +import java.util.ArrayList; +import java.util.List; + +import eu.siacs.conversations.Config; +import eu.siacs.conversations.R; +import eu.siacs.conversations.entities.Account; +import eu.siacs.conversations.entities.Conversation; +import eu.siacs.conversations.entities.Message; +import eu.siacs.conversations.ui.adapter.ConversationAdapter; +import eu.siacs.conversations.xmpp.jid.InvalidJidException; +import eu.siacs.conversations.xmpp.jid.Jid; + public class ShareWithActivity extends XmppActivity { private class Share { public Uri uri; + public boolean image; public String account; public String contact; public String text; @@ -38,9 +40,9 @@ public class ShareWithActivity extends XmppActivity { private static final int REQUEST_START_NEW_CONVERSATION = 0x0501; private ListView mListView; - private List<Conversation> mConversations = new ArrayList<Conversation>(); + private List<Conversation> mConversations = new ArrayList<>(); - private UiCallback<Message> attachImageCallback = new UiCallback<Message>() { + private UiCallback<Message> attachFileCallback = new UiCallback<Message>() { @Override public void userInputRequried(PendingIntent pi, Message object) { @@ -78,11 +80,12 @@ public class ShareWithActivity extends XmppActivity { @Override protected void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - getActionBar().setDisplayHomeAsUpEnabled(false); - getActionBar().setHomeButtonEnabled(false); + if (getActionBar() != null) { + getActionBar().setDisplayHomeAsUpEnabled(false); + getActionBar().setHomeButtonEnabled(false); + } setContentView(R.layout.share_with); setTitle(getString(R.string.title_activity_sharewith)); @@ -127,10 +130,10 @@ public class ShareWithActivity extends XmppActivity { @Override public void onStart() { - if (getIntent().getType() != null - && getIntent().getType().startsWith("image/")) { - this.share.uri = (Uri) getIntent().getParcelableExtra( - Intent.EXTRA_STREAM); + final String type = getIntent().getType(); + if (type != null && !type.startsWith("text/")) { + this.share.uri = (Uri) getIntent().getParcelableExtra(Intent.EXTRA_STREAM); + this.share.image = type.startsWith("image/") || URLConnection.guessContentTypeFromName(share.uri.getPath()).startsWith("image/"); } else { this.share.text = getIntent().getStringExtra(Intent.EXTRA_TEXT); } @@ -177,12 +180,21 @@ public class ShareWithActivity extends XmppActivity { selectPresence(conversation, new OnPresenceSelected() { @Override public void onPresenceSelected() { - Toast.makeText(getApplicationContext(), - getText(R.string.preparing_image), - Toast.LENGTH_LONG).show(); - ShareWithActivity.this.xmppConnectionService + if (share.image) { + Toast.makeText(getApplicationContext(), + getText(R.string.preparing_image), + Toast.LENGTH_LONG).show(); + ShareWithActivity.this.xmppConnectionService .attachImageToConversation(conversation, share.uri, - attachImageCallback); + attachFileCallback); + } else { + Toast.makeText(getApplicationContext(), + getText(R.string.preparing_file), + Toast.LENGTH_LONG).show(); + ShareWithActivity.this.xmppConnectionService + .attachFileToConversation(conversation, share.uri, + attachFileCallback); + } switchToConversation(conversation, null, true); finish(); } @@ -195,4 +207,4 @@ public class ShareWithActivity extends XmppActivity { } -}
\ No newline at end of file +} |