diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/main/java/de/pixart/messenger/ui/MediaViewerActivity.java | 2 | ||||
-rw-r--r-- | src/main/java/de/pixart/messenger/ui/SettingsActivity.java | 1 | ||||
-rw-r--r-- | src/main/java/de/pixart/messenger/ui/ShowLocationActivity.java | 2 | ||||
-rw-r--r-- | src/main/java/de/pixart/messenger/ui/XmppActivity.java | 14 | ||||
-rw-r--r-- | src/main/java/de/pixart/messenger/ui/adapter/MessageAdapter.java | 95 | ||||
-rw-r--r-- | src/main/res/layout/message_content.xml | 13 | ||||
-rw-r--r-- | src/main/res/values/defaults.xml | 1 | ||||
-rw-r--r-- | src/main/res/values/strings.xml | 2 | ||||
-rw-r--r-- | src/main/res/xml/preferences.xml | 5 |
9 files changed, 111 insertions, 24 deletions
diff --git a/src/main/java/de/pixart/messenger/ui/MediaViewerActivity.java b/src/main/java/de/pixart/messenger/ui/MediaViewerActivity.java index d8659709b..2f2dcdf97 100644 --- a/src/main/java/de/pixart/messenger/ui/MediaViewerActivity.java +++ b/src/main/java/de/pixart/messenger/ui/MediaViewerActivity.java @@ -391,7 +391,7 @@ public class MediaViewerActivity extends XmppActivity { return getPreferences().getBoolean("use_auto_rotate", getResources().getBoolean(R.bool.auto_rotate)); } - protected SharedPreferences getPreferences() { + public SharedPreferences getPreferences() { return PreferenceManager.getDefaultSharedPreferences(getApplicationContext()); } }
\ No newline at end of file diff --git a/src/main/java/de/pixart/messenger/ui/SettingsActivity.java b/src/main/java/de/pixart/messenger/ui/SettingsActivity.java index 6f5cd2f0d..dc41011fb 100644 --- a/src/main/java/de/pixart/messenger/ui/SettingsActivity.java +++ b/src/main/java/de/pixart/messenger/ui/SettingsActivity.java @@ -62,6 +62,7 @@ public class SettingsActivity extends XmppActivity implements public static final String USE_MULTI_ACCOUNTS = "use_multi_accounts"; public static final String QUICK_SHARE_ATTACHMENT_CHOICE = "quick_share_attachment_choice"; public static final String NUMBER_OF_ACCOUNTS = "number_of_accounts"; + public static final String PLAY_GIF_INSIDE = "play_gif_inside"; public static final int REQUEST_WRITE_LOGS = 0xbf8701; Preference multiAccountPreference; diff --git a/src/main/java/de/pixart/messenger/ui/ShowLocationActivity.java b/src/main/java/de/pixart/messenger/ui/ShowLocationActivity.java index a12d398f2..d8c565345 100644 --- a/src/main/java/de/pixart/messenger/ui/ShowLocationActivity.java +++ b/src/main/java/de/pixart/messenger/ui/ShowLocationActivity.java @@ -103,7 +103,7 @@ public class ShowLocationActivity extends XmppActivity { } } - protected SharedPreferences getPreferences() { + public SharedPreferences getPreferences() { return PreferenceManager.getDefaultSharedPreferences(getApplicationContext()); } diff --git a/src/main/java/de/pixart/messenger/ui/XmppActivity.java b/src/main/java/de/pixart/messenger/ui/XmppActivity.java index 19319df18..65383c2aa 100644 --- a/src/main/java/de/pixart/messenger/ui/XmppActivity.java +++ b/src/main/java/de/pixart/messenger/ui/XmppActivity.java @@ -55,6 +55,7 @@ import android.widget.Toast; import net.java.otr4j.session.SessionID; +import java.io.File; import java.io.IOException; import java.lang.ref.WeakReference; import java.util.ArrayList; @@ -87,6 +88,7 @@ import de.pixart.messenger.utils.MenuDoubleTabUtil; import de.pixart.messenger.utils.ThemeHelper; import de.pixart.messenger.xmpp.OnKeyStatusUpdated; import de.pixart.messenger.xmpp.OnUpdateBlocklist; +import pl.droidsonroids.gif.GifDrawable; import rocks.xmpp.addr.Jid; public abstract class XmppActivity extends ActionBarActivity { @@ -441,7 +443,7 @@ public abstract class XmppActivity extends ActionBarActivity { return getBooleanPreference("display_enter_key", R.bool.display_enter_key); } - protected SharedPreferences getPreferences() { + public SharedPreferences getPreferences() { return PreferenceManager.getDefaultSharedPreferences(getApplicationContext()); } @@ -1083,6 +1085,16 @@ public abstract class XmppActivity extends ActionBarActivity { return xmppConnectionService.getAvatarService(); } + public void loadGif(File file, ImageView imageView) { + GifDrawable gifDrawable = null; + try { + gifDrawable = new GifDrawable(file); + } catch (IOException e) { + e.printStackTrace(); + } + imageView.setImageDrawable(gifDrawable); + } + public void loadBitmap(Message message, ImageView imageView) { Bitmap bm; try { diff --git a/src/main/java/de/pixart/messenger/ui/adapter/MessageAdapter.java b/src/main/java/de/pixart/messenger/ui/adapter/MessageAdapter.java index fd9074771..1c53f1b5d 100644 --- a/src/main/java/de/pixart/messenger/ui/adapter/MessageAdapter.java +++ b/src/main/java/de/pixart/messenger/ui/adapter/MessageAdapter.java @@ -27,6 +27,7 @@ import android.text.style.RelativeSizeSpan; import android.text.style.StyleSpan; import android.util.Base64; import android.util.DisplayMetrics; +import android.util.Log; import android.view.ActionMode; import android.view.Menu; import android.view.MenuItem; @@ -44,6 +45,7 @@ import android.widget.Toast; import com.bumptech.glide.Glide; import com.bumptech.glide.load.engine.DiskCacheStrategy; +import java.io.IOException; import java.io.UnsupportedEncodingException; import java.lang.ref.WeakReference; import java.net.URL; @@ -84,6 +86,10 @@ import de.pixart.messenger.utils.GeoHelper; import de.pixart.messenger.utils.StylingHelper; import de.pixart.messenger.utils.UIHelper; import de.pixart.messenger.xmpp.mam.MamReference; +import pl.droidsonroids.gif.GifDrawable; +import pl.droidsonroids.gif.GifImageView; + +import static de.pixart.messenger.ui.SettingsActivity.PLAY_GIF_INSIDE; public class MessageAdapter extends ArrayAdapter<Message> implements CopyTextView.CopyHandler { @@ -384,6 +390,7 @@ public class MessageAdapter extends ArrayAdapter<Message> implements CopyTextVie viewHolder.download_button.setVisibility(View.GONE); viewHolder.audioPlayer.setVisibility(View.GONE); viewHolder.image.setVisibility(View.GONE); + viewHolder.gifImage.setVisibility(View.GONE); viewHolder.messageBody.setVisibility(View.VISIBLE); viewHolder.messageBody.setText(text); if (darkBackground) { @@ -398,6 +405,7 @@ public class MessageAdapter extends ArrayAdapter<Message> implements CopyTextVie viewHolder.download_button.setVisibility(View.GONE); viewHolder.audioPlayer.setVisibility(View.GONE); viewHolder.image.setVisibility(View.GONE); + viewHolder.gifImage.setVisibility(View.GONE); viewHolder.messageBody.setVisibility(View.VISIBLE); if (darkBackground) { viewHolder.messageBody.setTextAppearance(getContext(), R.style.TextAppearance_Conversations_Body1_Emoji_OnDark); @@ -441,6 +449,7 @@ public class MessageAdapter extends ArrayAdapter<Message> implements CopyTextVie }); viewHolder.image.setVisibility(View.GONE); + viewHolder.gifImage.setVisibility(View.GONE); viewHolder.messageBody.setVisibility(View.GONE); } @@ -515,6 +524,7 @@ public class MessageAdapter extends ArrayAdapter<Message> implements CopyTextVie private void displayTextMessage(final ViewHolder viewHolder, final Message message, boolean darkBackground, int type) { viewHolder.download_button.setVisibility(View.GONE); viewHolder.image.setVisibility(View.GONE); + viewHolder.gifImage.setVisibility(View.GONE); viewHolder.audioPlayer.setVisibility(View.GONE); viewHolder.messageBody.setVisibility(View.VISIBLE); if (darkBackground) { @@ -611,6 +621,7 @@ public class MessageAdapter extends ArrayAdapter<Message> implements CopyTextVie private void displayDownloadableMessage(ViewHolder viewHolder, final Message message, String text) { viewHolder.audioPlayer.setVisibility(View.GONE); viewHolder.image.setVisibility(View.GONE); + viewHolder.gifImage.setVisibility(View.GONE); viewHolder.messageBody.setVisibility(View.GONE); viewHolder.download_button.setVisibility(View.VISIBLE); viewHolder.download_button.setText(text); @@ -621,6 +632,7 @@ public class MessageAdapter extends ArrayAdapter<Message> implements CopyTextVie private void displayOpenableMessage(ViewHolder viewHolder, final Message message) { viewHolder.audioPlayer.setVisibility(View.GONE); viewHolder.image.setVisibility(View.GONE); + viewHolder.gifImage.setVisibility(View.GONE); viewHolder.messageBody.setVisibility(View.GONE); viewHolder.download_button.setVisibility(View.VISIBLE); final String mimeType = message.getMimeType(); @@ -686,6 +698,7 @@ public class MessageAdapter extends ArrayAdapter<Message> implements CopyTextVie viewHolder.messageBody.setVisibility(View.GONE); String url = GeoHelper.MapPreviewUri(message); viewHolder.image.setVisibility(View.VISIBLE); + viewHolder.gifImage.setVisibility(View.GONE); double target = metrics.density * 200; int scaledW; int scaledH; @@ -723,6 +736,7 @@ public class MessageAdapter extends ArrayAdapter<Message> implements CopyTextVie private void displayAudioMessage(ViewHolder viewHolder, Message message, boolean darkBackground) { viewHolder.image.setVisibility(View.GONE); + viewHolder.gifImage.setVisibility(View.GONE); viewHolder.messageBody.setVisibility(View.GONE); viewHolder.download_button.setVisibility(View.GONE); final RelativeLayout audioPlayer = viewHolder.audioPlayer; @@ -735,29 +749,65 @@ public class MessageAdapter extends ArrayAdapter<Message> implements CopyTextVie viewHolder.download_button.setVisibility(View.GONE); viewHolder.messageBody.setVisibility(View.GONE); viewHolder.audioPlayer.setVisibility(View.GONE); - viewHolder.image.setVisibility(View.VISIBLE); - FileParams params = message.getFileParams(); - double target = metrics.density * 200; - int scaledW; - int scaledH; - if (Math.max(params.height, params.width) * metrics.density <= target) { - scaledW = (int) (params.width * metrics.density); - scaledH = (int) (params.height * metrics.density); - } else if (Math.max(params.height, params.width) <= target) { - scaledW = params.width; - scaledH = params.height; - } else if (params.width <= params.height) { - scaledW = (int) (params.width / ((double) params.height / target)); - scaledH = (int) target; + DownloadableFile file = activity.xmppConnectionService.getFileBackend().getFile(message); + if (!file.exists()) { + Toast.makeText(activity, R.string.file_deleted, Toast.LENGTH_SHORT).show(); + return; + } + String mime = file.getMimeType(); + boolean playGifInside = activity.getPreferences().getBoolean(PLAY_GIF_INSIDE, activity.getResources().getBoolean(R.bool.play_gif_inside)); + if (mime != null && mime.equals("image/gif") && playGifInside) { + Log.d(Config.LOGTAG, "Gif Image file"); + viewHolder.image.setVisibility(View.GONE); + viewHolder.gifImage.setVisibility(View.VISIBLE); + FileParams params = message.getFileParams(); + double target = metrics.density * 200; + int scaledW; + int scaledH; + if (Math.max(params.height, params.width) * metrics.density <= target) { + scaledW = (int) (params.width * metrics.density); + scaledH = (int) (params.height * metrics.density); + } else if (Math.max(params.height, params.width) <= target) { + scaledW = params.width; + scaledH = params.height; + } else if (params.width <= params.height) { + scaledW = (int) (params.width / ((double) params.height / target)); + scaledH = (int) target; + } else { + scaledW = (int) target; + scaledH = (int) (params.height / ((double) params.width / target)); + } + LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(scaledW, scaledH); + layoutParams.setMargins(0, (int) (metrics.density * 4), 0, (int) (metrics.density * 4)); + viewHolder.gifImage.setLayoutParams(layoutParams); + activity.loadGif(file, viewHolder.gifImage); + viewHolder.gifImage.setOnClickListener(v -> openDownloadable(message)); } else { - scaledW = (int) target; - scaledH = (int) (params.height / ((double) params.width / target)); + viewHolder.image.setVisibility(View.VISIBLE); + viewHolder.gifImage.setVisibility(View.GONE); + FileParams params = message.getFileParams(); + double target = metrics.density * 200; + int scaledW; + int scaledH; + if (Math.max(params.height, params.width) * metrics.density <= target) { + scaledW = (int) (params.width * metrics.density); + scaledH = (int) (params.height * metrics.density); + } else if (Math.max(params.height, params.width) <= target) { + scaledW = params.width; + scaledH = params.height; + } else if (params.width <= params.height) { + scaledW = (int) (params.width / ((double) params.height / target)); + scaledH = (int) target; + } else { + scaledW = (int) target; + scaledH = (int) (params.height / ((double) params.width / target)); + } + LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(scaledW, scaledH); + layoutParams.setMargins(0, (int) (metrics.density * 4), 0, (int) (metrics.density * 4)); + viewHolder.image.setLayoutParams(layoutParams); + activity.loadBitmap(message, viewHolder.image); + viewHolder.image.setOnClickListener(v -> openDownloadable(message)); } - LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(scaledW, scaledH); - layoutParams.setMargins(0, (int) (metrics.density * 4), 0, (int) (metrics.density * 4)); - viewHolder.image.setLayoutParams(layoutParams); - activity.loadBitmap(message, viewHolder.image); - viewHolder.image.setOnClickListener(v -> openDownloadable(message)); } private void loadMoreMessages(Conversation conversation) { @@ -805,6 +855,7 @@ public class MessageAdapter extends ArrayAdapter<Message> implements CopyTextVie viewHolder.indicator = view.findViewById(R.id.security_indicator); viewHolder.edit_indicator = view.findViewById(R.id.edit_indicator); viewHolder.image = view.findViewById(R.id.message_image); + viewHolder.gifImage = view.findViewById(R.id.message_image_gif); viewHolder.messageBody = view.findViewById(R.id.message_body); viewHolder.time = view.findViewById(R.id.message_time); viewHolder.indicatorReceived = view.findViewById(R.id.indicator_received); @@ -819,6 +870,7 @@ public class MessageAdapter extends ArrayAdapter<Message> implements CopyTextVie viewHolder.indicator = view.findViewById(R.id.security_indicator); viewHolder.edit_indicator = view.findViewById(R.id.edit_indicator); viewHolder.image = view.findViewById(R.id.message_image); + viewHolder.gifImage = view.findViewById(R.id.message_image_gif); viewHolder.messageBody = view.findViewById(R.id.message_body); viewHolder.time = view.findViewById(R.id.message_time); viewHolder.indicatorReceived = view.findViewById(R.id.indicator_received); @@ -1147,6 +1199,7 @@ public class MessageAdapter extends ArrayAdapter<Message> implements CopyTextVie protected Button download_button; protected Button resend_button; protected ImageView image; + protected GifImageView gifImage; protected ImageView indicator; protected ImageView indicatorReceived; protected ImageView indicatorRead; diff --git a/src/main/res/layout/message_content.xml b/src/main/res/layout/message_content.xml index 67c993cac..f14f310c3 100644 --- a/src/main/res/layout/message_content.xml +++ b/src/main/res/layout/message_content.xml @@ -15,6 +15,19 @@ android:scaleType="centerCrop" app:riv_corner_radius="@dimen/rounded_image_border" /> + <pl.droidsonroids.gif.GifImageView + android:id="@+id/message_image_gif" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:layout_marginTop="2dp" + android:layout_marginBottom="4dp" + android:adjustViewBounds="true" + android:longClickable="true" + android:maxWidth="500dp" + android:maxHeight="500dp" + android:scaleType="centerCrop" + app:riv_corner_radius="@dimen/rounded_image_border" /> + <de.pixart.messenger.ui.widget.CopyTextView android:id="@+id/message_body" android:layout_width="wrap_content" diff --git a/src/main/res/values/defaults.xml b/src/main/res/values/defaults.xml index a9edc5a92..116081eb0 100644 --- a/src/main/res/values/defaults.xml +++ b/src/main/res/values/defaults.xml @@ -110,6 +110,7 @@ <bool name="show_record_voice_btn">true</bool> <bool name="quick_share_attachment_choice">true</bool> <bool name="screen_security">false</bool> + <bool name="play_gif_inside">false</bool> <string-array name="domains"> <item>pix-art.de</item> diff --git a/src/main/res/values/strings.xml b/src/main/res/values/strings.xml index 5d0160b7a..e80438379 100644 --- a/src/main/res/values/strings.xml +++ b/src/main/res/values/strings.xml @@ -857,4 +857,6 @@ <string name="enter_your_name_instructions">Please enter your nickname which will be visible to your contacts.</string> <string name="no_name_set_instructions">No nickname set.</string> <string name="autojoin_groupchat">Automatically join this group chat</string> + <string name="pref_play_gif_inside">Play GIF files in chat</string> + <string name="pref_play_gif_inside_summary">Setting this to true plays GIF files directly inside the chat view.</string> </resources> diff --git a/src/main/res/xml/preferences.xml b/src/main/res/xml/preferences.xml index e5ccfa8e4..747338435 100644 --- a/src/main/res/xml/preferences.xml +++ b/src/main/res/xml/preferences.xml @@ -71,6 +71,11 @@ android:key="scroll_to_bottom" android:summary="@string/pref_scroll_to_bottom_summary" android:title="@string/pref_scroll_to_bottom" /> + <CheckBoxPreference + android:defaultValue="@bool/play_gif_inside" + android:key="play_gif_inside" + android:summary="@string/pref_play_gif_inside_summary" + android:title="@string/pref_play_gif_inside" /> </PreferenceScreen> <!--Notifications--> <PreferenceScreen |