diff options
Diffstat (limited to 'src/main/java/de/pixart')
11 files changed, 312 insertions, 71 deletions
diff --git a/src/main/java/de/pixart/messenger/entities/IndividualMessage.java b/src/main/java/de/pixart/messenger/entities/IndividualMessage.java index 7a1030fef..f8d0b7938 100644 --- a/src/main/java/de/pixart/messenger/entities/IndividualMessage.java +++ b/src/main/java/de/pixart/messenger/entities/IndividualMessage.java @@ -32,15 +32,27 @@ import android.database.Cursor; import java.util.Set; +import de.pixart.messenger.ui.adapter.MessageAdapter; import rocks.xmpp.addr.Jid; public class IndividualMessage extends Message { + private IndividualMessage(Conversational conversation) { + super(conversation); + } private IndividualMessage(Conversational conversation, String uuid, String conversationUUid, Jid counterpart, Jid trueCounterpart, String body, long timeSent, int encryption, int status, int type, boolean carbon, String remoteMsgId, String relativeFilePath, String serverMsgId, String fingerprint, boolean read, String edited, boolean oob, String errorMessage, Set<ReadByMarker> readByMarkers, boolean markable) { super(conversation, uuid, conversationUUid, counterpart, trueCounterpart, body, timeSent, encryption, status, type, carbon, remoteMsgId, relativeFilePath, serverMsgId, fingerprint, read, edited, oob, errorMessage, readByMarkers, markable); } + public static Message createDateSeparator(Message message) { + final Message separator = new IndividualMessage(message.getConversation()); + separator.setType(Message.TYPE_STATUS); + separator.body = MessageAdapter.DATE_SEPARATOR_BODY; + separator.setTime(message.getTimeSent()); + return separator; + } + public static Message fromCursor(Cursor cursor, Conversational conversation) { Jid jid; try { diff --git a/src/main/java/de/pixart/messenger/entities/Message.java b/src/main/java/de/pixart/messenger/entities/Message.java index 605fa0001..cfe3c7fb8 100644 --- a/src/main/java/de/pixart/messenger/entities/Message.java +++ b/src/main/java/de/pixart/messenger/entities/Message.java @@ -17,7 +17,6 @@ import java.util.Set; import de.pixart.messenger.Config; import de.pixart.messenger.crypto.axolotl.FingerprintStatus; import de.pixart.messenger.http.AesGcmURLStreamHandler; -import de.pixart.messenger.ui.adapter.MessageAdapter; import de.pixart.messenger.utils.CryptoHelper; import de.pixart.messenger.utils.Emoticons; import de.pixart.messenger.utils.GeoHelper; @@ -108,7 +107,7 @@ public class Message extends AbstractEntity { private List<MucOptions.User> counterparts; private WeakReference<MucOptions.User> user; - private Message(Conversational conversation) { + protected Message(Conversational conversation) { this.conversation = conversation; } @@ -232,14 +231,6 @@ public class Message extends AbstractEntity { return message; } - public static Message createDateSeparator(Message message) { - final Message separator = new Message(message.getConversation()); - separator.setType(Message.TYPE_STATUS); - separator.body = MessageAdapter.DATE_SEPARATOR_BODY; - separator.setTime(message.getTimeSent()); - return separator; - } - @Override public ContentValues getContentValues() { ContentValues values = new ContentValues(); diff --git a/src/main/java/de/pixart/messenger/ui/ConversationFragment.java b/src/main/java/de/pixart/messenger/ui/ConversationFragment.java index bfdd15b03..1f39276e2 100644 --- a/src/main/java/de/pixart/messenger/ui/ConversationFragment.java +++ b/src/main/java/de/pixart/messenger/ui/ConversationFragment.java @@ -5,7 +5,6 @@ import android.annotation.SuppressLint; import android.app.Activity; import android.app.Fragment; import android.app.PendingIntent; -import android.content.ActivityNotFoundException; import android.content.Context; import android.content.DialogInterface; import android.content.Intent; @@ -97,12 +96,14 @@ import de.pixart.messenger.ui.adapter.MessageAdapter; import de.pixart.messenger.ui.util.ActivityResult; import de.pixart.messenger.ui.util.AttachmentTool; import de.pixart.messenger.ui.util.ConversationMenuConfigurator; +import de.pixart.messenger.ui.util.DateSeparator; import de.pixart.messenger.ui.util.ListViewUtils; import de.pixart.messenger.ui.util.PendingItem; import de.pixart.messenger.ui.util.PresenceSelector; import de.pixart.messenger.ui.util.ScrollState; import de.pixart.messenger.ui.util.SendButtonAction; import de.pixart.messenger.ui.util.SendButtonTool; +import de.pixart.messenger.ui.util.ShareUtil; import de.pixart.messenger.ui.widget.EditMessage; import de.pixart.messenger.utils.FileUtils; import de.pixart.messenger.utils.MenuDoubleTabUtil; @@ -1382,13 +1383,13 @@ public class ConversationFragment extends XmppFragment implements EditMessage.Ke public boolean onContextItemSelected(MenuItem item) { switch (item.getItemId()) { case R.id.share_with: - shareWith(selectedMessage); + ShareUtil.share(activity, selectedMessage); return true; case R.id.correct_message: correctMessage(selectedMessage); return true; case R.id.copy_message: - copyMessage(selectedMessage); + ShareUtil.copyToClipboard(activity, selectedMessage); return true; case R.id.quote_message: quoteMessage(selectedMessage); @@ -1397,7 +1398,7 @@ public class ConversationFragment extends XmppFragment implements EditMessage.Ke resendMessage(selectedMessage); return true; case R.id.copy_url: - copyUrl(selectedMessage); + ShareUtil.copyUrlToClipboard(activity, selectedMessage); return true; case R.id.download_file: startDownloadable(selectedMessage); @@ -1834,44 +1835,6 @@ public class ConversationFragment extends XmppFragment implements EditMessage.Ke builder.create().show(); } - private void shareWith(Message message) { - Intent shareIntent = new Intent(); - shareIntent.setAction(Intent.ACTION_SEND); - if (message.isGeoUri() || message.isXmppUri()) { - shareIntent.putExtra(Intent.EXTRA_TEXT, message.getBody()); - shareIntent.setType("text/plain"); - } else if (!message.isFileOrImage()) { - shareIntent.putExtra(Intent.EXTRA_TEXT, message.getMergedBody().toString()); - shareIntent.setType("text/plain"); - } else { - final DownloadableFile file = activity.xmppConnectionService.getFileBackend().getFile(message); - try { - shareIntent.putExtra(Intent.EXTRA_STREAM, FileBackend.getUriForFile(getActivity(), file)); - } catch (SecurityException e) { - Toast.makeText(getActivity(), activity.getString(R.string.no_permission_to_access_x, file.getAbsolutePath()), Toast.LENGTH_SHORT).show(); - return; - } - shareIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); - String mime = message.getMimeType(); - if (mime == null) { - mime = "*/*"; - } - shareIntent.setType(mime); - } - try { - startActivity(Intent.createChooser(shareIntent, getText(R.string.share_with))); - } catch (ActivityNotFoundException e) { - //This should happen only on faulty androids because normally chooser is always available - Toast.makeText(getActivity(), R.string.no_application_found_to_open_file, Toast.LENGTH_SHORT).show(); - } - } - - private void copyMessage(Message message) { - if (activity.copyTextToClipboard(message.getMergedBody().toString(), R.string.message)) { - Toast.makeText(getActivity(), R.string.message_copied_to_clipboard, Toast.LENGTH_SHORT).show(); - } - } - private void deleteFile(Message message) { if (activity.xmppConnectionService.getFileBackend().deleteFile(message)) { message.setTransferable(new TransferablePlaceholder(Transferable.STATUS_DELETED)); @@ -2249,6 +2212,7 @@ public class ConversationFragment extends XmppFragment implements EditMessage.Ke final String downloadUuid = extras.getString(ConversationsActivity.EXTRA_DOWNLOAD_UUID); final String text = extras.getString(ConversationsActivity.EXTRA_TEXT); final String nick = extras.getString(ConversationsActivity.EXTRA_NICK); + final boolean asQuote = extras.getBoolean(ConversationsActivity.EXTRA_AS_QUOTE); final boolean pm = extras.getBoolean(ConversationsActivity.EXTRA_IS_PRIVATE_MESSAGE, false); if (nick != null) { if (pm) { @@ -2266,7 +2230,11 @@ public class ConversationFragment extends XmppFragment implements EditMessage.Ke } } } else { - appendText(text); + if (text != null && asQuote) { + quoteText(text); + } else { + appendText(text); + } } final Message message = downloadUuid == null ? null : conversation.findMessageWithFileAndUuid(downloadUuid); if (message != null) { @@ -2560,13 +2528,7 @@ public class ConversationFragment extends XmppFragment implements EditMessage.Ke protected void updateDateBubbles() { synchronized (this.messageList) { - for (int i = 0; i < this.messageList.size(); ++i) { - final Message current = this.messageList.get(i); - if (i == 0 || !UIHelper.sameDay(this.messageList.get(i - 1).getTimeSent(), current.getTimeSent())) { - this.messageList.add(i, Message.createDateSeparator(current)); - i++; - } - } + DateSeparator.addAll(this.messageList); } } diff --git a/src/main/java/de/pixart/messenger/ui/ConversationsActivity.java b/src/main/java/de/pixart/messenger/ui/ConversationsActivity.java index d7f4bd88e..c49e78d81 100644 --- a/src/main/java/de/pixart/messenger/ui/ConversationsActivity.java +++ b/src/main/java/de/pixart/messenger/ui/ConversationsActivity.java @@ -99,6 +99,7 @@ public class ConversationsActivity extends XmppActivity implements OnConversatio public static final String EXTRA_CONVERSATION = "conversationUuid"; public static final String EXTRA_DOWNLOAD_UUID = "de.pixart.messenger.download_uuid"; public static final String EXTRA_TEXT = "text"; + public static final String EXTRA_AS_QUOTE = "as_quote"; public static final String EXTRA_NICK = "nick"; public static final String EXTRA_IS_PRIVATE_MESSAGE = "pm"; public static final String ACTION_DESTROY_MUC = "de.pixart.messenger.DESTROY_MUC"; diff --git a/src/main/java/de/pixart/messenger/ui/SearchActivity.java b/src/main/java/de/pixart/messenger/ui/SearchActivity.java index d90f5e10a..54c5ef5e4 100644 --- a/src/main/java/de/pixart/messenger/ui/SearchActivity.java +++ b/src/main/java/de/pixart/messenger/ui/SearchActivity.java @@ -35,32 +35,44 @@ import android.support.v7.widget.Toolbar; import android.text.Editable; import android.text.InputType; import android.text.TextWatcher; +import android.view.ContextMenu; import android.view.Menu; import android.view.MenuItem; +import android.view.View; +import android.widget.AdapterView; import android.widget.EditText; +import java.lang.ref.WeakReference; import java.util.ArrayList; import java.util.List; import de.pixart.messenger.R; import de.pixart.messenger.databinding.ActivitySearchBinding; import de.pixart.messenger.entities.Contact; +import de.pixart.messenger.entities.Conversation; +import de.pixart.messenger.entities.Conversational; import de.pixart.messenger.entities.Message; import de.pixart.messenger.services.MessageSearchTask; import de.pixart.messenger.ui.adapter.MessageAdapter; import de.pixart.messenger.ui.interfaces.OnSearchResultsAvailable; +import de.pixart.messenger.ui.util.ChangeWatcher; import de.pixart.messenger.ui.util.Color; +import de.pixart.messenger.ui.util.DateSeparator; import de.pixart.messenger.ui.util.Drawable; import de.pixart.messenger.ui.util.ListViewUtils; +import de.pixart.messenger.ui.util.ShareUtil; +import de.pixart.messenger.utils.MessageUtils; import static de.pixart.messenger.ui.util.SoftKeyboardUtils.hideSoftKeyboard; import static de.pixart.messenger.ui.util.SoftKeyboardUtils.showKeyboard; public class SearchActivity extends XmppActivity implements TextWatcher, OnSearchResultsAvailable, MessageAdapter.OnContactPictureClicked { - private final List<Message> messages = new ArrayList<>(); private ActivitySearchBinding binding; private MessageAdapter messageListAdapter; + private final List<Message> messages = new ArrayList<>(); + private WeakReference<Message> selectedMessageReference = new WeakReference<>(null); + private final ChangeWatcher<String> currentSearch = new ChangeWatcher<>(); @Override public void onCreate(final Bundle savedInstanceState) { @@ -71,6 +83,7 @@ public class SearchActivity extends XmppActivity implements TextWatcher, OnSearc this.messageListAdapter = new MessageAdapter(this, this.messages); this.messageListAdapter.setOnContactPictureClicked(this); this.binding.searchResults.setAdapter(messageListAdapter); + registerForContextMenu(this.binding.searchResults); } @Override @@ -86,6 +99,24 @@ public class SearchActivity extends XmppActivity implements TextWatcher, OnSearc } @Override + public void onCreateContextMenu(ContextMenu menu, View v, ContextMenu.ContextMenuInfo menuInfo) { + AdapterView.AdapterContextMenuInfo acmi = (AdapterView.AdapterContextMenuInfo) menuInfo; + final Message message = this.messages.get(acmi.position); + this.selectedMessageReference = new WeakReference<>(message); + getMenuInflater().inflate(R.menu.search_result_context, menu); + MenuItem copy = menu.findItem(R.id.copy_message); + MenuItem quote = menu.findItem(R.id.quote_message); + MenuItem copyUrl = menu.findItem(R.id.copy_url); + if (message.isGeoUri()) { + copy.setVisible(false); + quote.setVisible(false); + } else { + copyUrl.setVisible(false); + } + super.onCreateContextMenu(menu, v, menuInfo); + } + + @Override public boolean onOptionsItemSelected(MenuItem item) { if (item.getItemId() == android.R.id.home) { hideSoftKeyboard(this); @@ -94,6 +125,43 @@ public class SearchActivity extends XmppActivity implements TextWatcher, OnSearc } @Override + public boolean onContextItemSelected(MenuItem item) { + final Message message = selectedMessageReference.get(); + if (message != null) { + switch (item.getItemId()) { + case R.id.share_with: + ShareUtil.share(this, message); + break; + case R.id.copy_message: + ShareUtil.copyToClipboard(this, message); + break; + case R.id.copy_url: + ShareUtil.copyUrlToClipboard(this, message); + break; + case R.id.quote_message: + quote(message); + } + } + return super.onContextItemSelected(item); + } + + private void quote(Message message) { + String text = MessageUtils.prepareQuote(message); + final Conversational conversational = message.getConversation(); + final Conversation conversation; + if (conversational instanceof Conversation) { + conversation = (Conversation) conversational; + } else { + conversation = xmppConnectionService.findOrCreateConversation(conversational.getAccount(), + conversational.getJid(), + conversational.getMode() == Conversational.MODE_MULTI, + true, + true); + } + switchToConversationAndQuote(conversation, text); + } + + @Override protected void refreshUiReal() { } @@ -127,7 +195,10 @@ public class SearchActivity extends XmppActivity implements TextWatcher, OnSearc @Override public void afterTextChanged(Editable s) { - String term = s.toString().trim(); + final String term = s.toString().trim(); + if (!currentSearch.watch(term)) { + return; + } if (term.length() > 0) { xmppConnectionService.search(s.toString().trim(), this); } else { @@ -142,6 +213,7 @@ public class SearchActivity extends XmppActivity implements TextWatcher, OnSearc public void onSearchResultsAvailable(String term, List<Message> messages) { runOnUiThread(() -> { this.messages.clear(); + DateSeparator.addAll(messages); this.messages.addAll(messages); messageListAdapter.notifyDataSetChanged(); changeBackground(true, messages.size() > 0); diff --git a/src/main/java/de/pixart/messenger/ui/ShareLocationActivity.java b/src/main/java/de/pixart/messenger/ui/ShareLocationActivity.java index bb07a0885..2b73e3bc2 100644 --- a/src/main/java/de/pixart/messenger/ui/ShareLocationActivity.java +++ b/src/main/java/de/pixart/messenger/ui/ShareLocationActivity.java @@ -87,7 +87,7 @@ public class ShareLocationActivity extends LocationActivity implements LocationL setResult(RESULT_CANCELED); finish(); }); - ThemeHelper.fixTextSize(this.snackBar); + ThemeHelper.fix(this.snackBar); mShareButton = findViewById(R.id.share_button); mShareButton.setOnClickListener(view -> { if (mLastLocation != null) { diff --git a/src/main/java/de/pixart/messenger/ui/XmppActivity.java b/src/main/java/de/pixart/messenger/ui/XmppActivity.java index d580b05db..c77545be6 100644 --- a/src/main/java/de/pixart/messenger/ui/XmppActivity.java +++ b/src/main/java/de/pixart/messenger/ui/XmppActivity.java @@ -465,25 +465,31 @@ public abstract class XmppActivity extends ActionBarActivity { switchToConversation(conversation, null, false); } - public void switchToConversation(Conversation conversation, String text, - boolean newTask) { - switchToConversation(conversation, text, null, false, newTask); + public void switchToConversationAndQuote(Conversation conversation, String text) { + switchToConversation(conversation, text, true, null, false, false); + } + + public void switchToConversation(Conversation conversation, String text, boolean newTask) { + switchToConversation(conversation, text, false, null, false, newTask); } public void highlightInMuc(Conversation conversation, String nick) { - switchToConversation(conversation, null, nick, false, false); + switchToConversation(conversation, null, false, nick, false, false); } public void privateMsgInMuc(Conversation conversation, String nick) { - switchToConversation(conversation, null, nick, true, false); + switchToConversation(conversation, null, false, nick, true, false); } - private void switchToConversation(Conversation conversation, String text, String nick, boolean pm, boolean newTask) { + private void switchToConversation(Conversation conversation, String text, boolean asQuote, String nick, boolean pm, boolean newTask) { Intent intent = new Intent(this, ConversationsActivity.class); intent.setAction(ConversationsActivity.ACTION_VIEW_CONVERSATION); intent.putExtra(ConversationsActivity.EXTRA_CONVERSATION, conversation.getUuid()); if (text != null) { intent.putExtra(ConversationsActivity.EXTRA_TEXT, text); + if (asQuote) { + intent.putExtra(ConversationsActivity.EXTRA_AS_QUOTE, asQuote); + } } if (nick != null) { intent.putExtra(ConversationsActivity.EXTRA_NICK, nick); diff --git a/src/main/java/de/pixart/messenger/ui/util/ChangeWatcher.java b/src/main/java/de/pixart/messenger/ui/util/ChangeWatcher.java new file mode 100644 index 000000000..c21c2fbb7 --- /dev/null +++ b/src/main/java/de/pixart/messenger/ui/util/ChangeWatcher.java @@ -0,0 +1,47 @@ +/* + * Copyright (c) 2018, Daniel Gultsch All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation and/or + * other materials provided with the distribution. + * + * 3. Neither the name of the copyright holder nor the names of its contributors + * may be used to endorse or promote products derived from this software without + * specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +package de.pixart.messenger.ui.util; + +public class ChangeWatcher<T> { + + private T object = null; + + public synchronized boolean watch(T object) { + if (this.object == null) { + this.object = object; + return object != null; + } else { + final boolean changed = !this.object.equals(object); + this.object = object; + return changed; + } + } + +}
\ No newline at end of file diff --git a/src/main/java/de/pixart/messenger/ui/util/DateSeparator.java b/src/main/java/de/pixart/messenger/ui/util/DateSeparator.java new file mode 100644 index 000000000..74633f62b --- /dev/null +++ b/src/main/java/de/pixart/messenger/ui/util/DateSeparator.java @@ -0,0 +1,48 @@ +/* + * Copyright (c) 2018, Daniel Gultsch All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation and/or + * other materials provided with the distribution. + * + * 3. Neither the name of the copyright holder nor the names of its contributors + * may be used to endorse or promote products derived from this software without + * specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +package de.pixart.messenger.ui.util; + +import java.util.List; + +import de.pixart.messenger.entities.IndividualMessage; +import de.pixart.messenger.entities.Message; +import de.pixart.messenger.utils.UIHelper; + +public class DateSeparator { + + public static void addAll(List<Message> messages) { + for (int i = 0; i < messages.size(); ++i) { + final Message current = messages.get(i); + if (i == 0 || !UIHelper.sameDay(messages.get(i - 1).getTimeSent(), current.getTimeSent())) { + messages.add(i, IndividualMessage.createDateSeparator(current)); + i++; + } + } + } +}
\ No newline at end of file diff --git a/src/main/java/de/pixart/messenger/ui/util/ShareUtil.java b/src/main/java/de/pixart/messenger/ui/util/ShareUtil.java new file mode 100644 index 000000000..63c505284 --- /dev/null +++ b/src/main/java/de/pixart/messenger/ui/util/ShareUtil.java @@ -0,0 +1,99 @@ +/* + * Copyright (c) 2018, Daniel Gultsch All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation and/or + * other materials provided with the distribution. + * + * 3. Neither the name of the copyright holder nor the names of its contributors + * may be used to endorse or promote products derived from this software without + * specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +package de.pixart.messenger.ui.util; + +import android.content.ActivityNotFoundException; +import android.content.Intent; +import android.widget.Toast; + +import de.pixart.messenger.R; +import de.pixart.messenger.entities.DownloadableFile; +import de.pixart.messenger.entities.Message; +import de.pixart.messenger.persistance.FileBackend; +import de.pixart.messenger.ui.XmppActivity; + +public class ShareUtil { + + public static void share(XmppActivity activity, Message message) { + Intent shareIntent = new Intent(); + shareIntent.setAction(Intent.ACTION_SEND); + if (message.isGeoUri()) { + shareIntent.putExtra(Intent.EXTRA_TEXT, message.getBody()); + shareIntent.setType("text/plain"); + } else if (!message.isFileOrImage()) { + shareIntent.putExtra(Intent.EXTRA_TEXT, message.getMergedBody().toString()); + shareIntent.setType("text/plain"); + } else { + final DownloadableFile file = activity.xmppConnectionService.getFileBackend().getFile(message); + try { + shareIntent.putExtra(Intent.EXTRA_STREAM, FileBackend.getUriForFile(activity, file)); + } catch (SecurityException e) { + Toast.makeText(activity, activity.getString(R.string.no_permission_to_access_x, file.getAbsolutePath()), Toast.LENGTH_SHORT).show(); + return; + } + shareIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); + String mime = message.getMimeType(); + if (mime == null) { + mime = "*/*"; + } + shareIntent.setType(mime); + } + try { + activity.startActivity(Intent.createChooser(shareIntent, activity.getText(R.string.share_with))); + } catch (ActivityNotFoundException e) { + //This should happen only on faulty androids because normally chooser is always available + Toast.makeText(activity, R.string.no_application_found_to_open_file, Toast.LENGTH_SHORT).show(); + } + } + + public static void copyToClipboard(XmppActivity activity, Message message) { + if (activity.copyTextToClipboard(message.getMergedBody().toString(), R.string.message)) { + Toast.makeText(activity, R.string.message_copied_to_clipboard, Toast.LENGTH_SHORT).show(); + } + } + + public static void copyUrlToClipboard(XmppActivity activity, Message message) { + final String url; + final int resId; + if (message.isGeoUri()) { + resId = R.string.location; + url = message.getBody(); + } else if (message.hasFileOnRemoteHost()) { + resId = R.string.file_url; + url = message.getFileParams().url.toString(); + } else { + url = message.getBody().trim(); + resId = R.string.file_url; + } + if (activity.copyTextToClipboard(url, resId)) { + Toast.makeText(activity, R.string.url_copied_to_clipboard, Toast.LENGTH_SHORT).show(); + } + } +}
\ No newline at end of file diff --git a/src/main/java/de/pixart/messenger/utils/ThemeHelper.java b/src/main/java/de/pixart/messenger/utils/ThemeHelper.java index 27a48f069..d12a5c1d3 100644 --- a/src/main/java/de/pixart/messenger/utils/ThemeHelper.java +++ b/src/main/java/de/pixart/messenger/utils/ThemeHelper.java @@ -36,6 +36,7 @@ import android.content.res.TypedArray; import android.preference.PreferenceManager; import android.support.annotation.StyleRes; import android.support.design.widget.Snackbar; +import android.support.v4.content.ContextCompat; import android.util.TypedValue; import android.widget.TextView; @@ -85,8 +86,9 @@ public class ThemeHelper { } } - public static void fixTextSize(Snackbar snackbar) { - TypedArray typedArray = snackbar.getContext().obtainStyledAttributes(new int[]{R.attr.TextSizeBody1}); + public static void fix(Snackbar snackbar) { + final Context context = snackbar.getContext(); + TypedArray typedArray = context.obtainStyledAttributes(new int[]{R.attr.TextSizeBody1}); final float size = typedArray.getDimension(0, 0f); typedArray.recycle(); if (size != 0f) { @@ -95,6 +97,7 @@ public class ThemeHelper { if (text != null && action != null) { text.setTextSize(TypedValue.COMPLEX_UNIT_PX, size); action.setTextSize(TypedValue.COMPLEX_UNIT_PX, size); + action.setTextColor(ContextCompat.getColor(context, R.color.deep_purple_a100)); } } } |