Commit edbe7689 authored by Thomas's avatar Thomas
Browse files

- Fix layout issues with media descriptions

- Fix a crash when taping the media to open original message
parent 45f573bc
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -230,7 +230,7 @@
            android:configChanges="keyboardHidden|orientation|screenSize" />
        <activity
            android:name=".mastodon.activities.MediaActivity"
            android:hardwareAccelerated="false"
            android:hardwareAccelerated="true"
            android:configChanges="keyboardHidden|orientation|screenSize"
            android:theme="@style/Transparent" />

+6 −0
Original line number Diff line number Diff line
@@ -141,6 +141,9 @@ public class MediaActivity extends BaseBarActivity implements OnDownloadInterfac

        if (bundle != null) {
            mediaPosition = bundle.getInt(Helper.ARG_MEDIA_POSITION, 1);
            if(mediaPosition < 1 ) {
                mediaPosition = 1;
            }
            attachments = (ArrayList<Attachment>) bundle.getSerializable(Helper.ARG_MEDIA_ARRAY);
            mediaFromProfile = bundle.getBoolean(Helper.ARG_MEDIA_ARRAY_PROFILE, false);
            status = (Status) bundle.getSerializable(Helper.ARG_STATUS);
@@ -230,6 +233,9 @@ public class MediaActivity extends BaseBarActivity implements OnDownloadInterfac

            public void onPageSelected(int position) {
                mediaPosition = position;
                if(mediaPosition < 1 ) {
                    mediaPosition = 1;
                }
                String description = attachments.get(position).description;
                if (handler != null) {
                    handler.removeCallbacksAndMessages(null);
+27 −0
Original line number Diff line number Diff line
@@ -25,6 +25,7 @@ import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Matrix;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.media.MediaRecorder;
import android.media.MediaScannerConnection;
@@ -266,6 +267,32 @@ public class MediaHelper {
        );
    }


    public static Drawable rescaleImageIfNeeded(Activity activity, Drawable image) {
        if (!(image instanceof BitmapDrawable)) {
            return image;
        }
        int maxSize = 2000;
        int width = image.getIntrinsicWidth();
        int height = image.getIntrinsicHeight();
        float scaleFactor;
        if(width > maxSize || height > maxSize) {
            if(width >= height) {
                scaleFactor = (float) maxSize / width;
            } else {
                scaleFactor = (float) maxSize / height;
            }
        } else {
            return image;
        }
        Bitmap b = ((BitmapDrawable)image).getBitmap();
        int sizeX = Math.round(image.getIntrinsicWidth() * scaleFactor);
        int sizeY = Math.round(image.getIntrinsicHeight() * scaleFactor);
        Bitmap bitmapResized = Bitmap.createScaledBitmap(b, sizeX, sizeY, false);
        image = new BitmapDrawable(activity.getResources(), bitmapResized);
        return image;
    }

    /**
     * Record media
     *
+7 −2
Original line number Diff line number Diff line
@@ -15,6 +15,7 @@ package app.fedilab.android.mastodon.ui.fragment.media;
 * see <http://www.gnu.org/licenses>. */



import android.content.SharedPreferences;
import android.graphics.Color;
import android.graphics.drawable.Drawable;
@@ -58,6 +59,7 @@ import app.fedilab.android.mastodon.activities.MediaActivity;
import app.fedilab.android.mastodon.client.entities.api.Attachment;
import app.fedilab.android.mastodon.helper.CacheDataSourceFactory;
import app.fedilab.android.mastodon.helper.Helper;
import app.fedilab.android.mastodon.helper.MediaHelper;
import app.fedilab.android.mastodon.viewmodel.mastodon.TimelinesVM;
import es.dmoral.toasty.Toasty;

@@ -167,7 +169,9 @@ public class FragmentMedia extends Fragment {
                                        return;
                                    }
                                    binding.mediaPicture.setZoomable(true);
                                    binding.mediaPicture.setImageDrawable(resource);

                                    Drawable scaledRessource = MediaHelper.rescaleImageIfNeeded(requireActivity(), resource);
                                    binding.mediaPicture.setImageDrawable(scaledRessource);

                                    if (attachment.type.equalsIgnoreCase("image") && !attachment.url.toLowerCase().endsWith(".gif")) {
                                        binding.mediaPicture.setVisibility(View.VISIBLE);
@@ -185,7 +189,8 @@ public class FragmentMedia extends Fragment {
                                                                            return;
                                                                        }
                                                                        binding.loader.setVisibility(View.GONE);
                                                                        binding.mediaPicture.setImageDrawable(resource);
                                                                        Drawable scaledRessource = MediaHelper.rescaleImageIfNeeded(requireActivity(), resource);
                                                                        binding.mediaPicture.setImageDrawable(scaledRessource);
                                                                        binding.mediaPicture.setZoomable(true);
                                                                    }

+2 −1
Original line number Diff line number Diff line
@@ -20,7 +20,7 @@
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:animateLayoutChanges="true"
    android:fitsSystemWindows="true"
    android:fitsSystemWindows="false"
    android:background="@android:color/transparent">


@@ -35,6 +35,7 @@

    <androidx.constraintlayout.widget.ConstraintLayout
        android:id="@+id/description_container"
        android:fitsSystemWindows="true"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        android:background="#AA000000"