Commit ae739488 authored by Thomas's avatar Thomas
Browse files

Improve media activity

parent 27423a6a
Loading
Loading
Loading
Loading
+33 −61
Original line number Diff line number Diff line
@@ -30,7 +30,6 @@ import android.os.Handler;
import android.view.Display;
import android.view.Menu;
import android.view.MenuItem;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
@@ -222,6 +221,11 @@ public class MediaActivity extends BaseTransparentActivity implements OnDownload
    }


    public void toogleFullScreen() {
        fullscreen = !fullscreen;
        setFullscreen(fullscreen);
    }

    @Override
    public boolean onCreateOptionsMenu(@NonNull Menu menu) {
        getMenuInflater().inflate(R.menu.menu_media, menu);
@@ -310,25 +314,9 @@ public class MediaActivity extends BaseTransparentActivity implements OnDownload
        }
    }

    @Override
    public boolean dispatchTouchEvent(MotionEvent event) {

        switch (event.getAction()) {
            case MotionEvent.ACTION_DOWN:
                startX = event.getX();
                startY = event.getY();
                break;
            case MotionEvent.ACTION_UP:
                float endX = event.getX();
                float endY = event.getY();
                if (endY > minTouch && endY < maxTouch && isAClick(startX, endX, startY, endY)) {
                    setFullscreen(!fullscreen);
    private void toggleScreenContain(boolean fullscreen) {
        if (!fullscreen) {
            String description = attachments.get(binding.mediaViewpager.getCurrentItem()).description;
                        if (handler != null) {
                            handler.removeCallbacksAndMessages(null);
                        }
                        handler = new Handler();
            if (description != null && description.trim().length() > 0 && description.trim().compareTo("null") != 0) {
                binding.mediaDescription.setText(description);
                if (attachments.get(binding.mediaViewpager.getCurrentItem()).translation != null) {
@@ -356,24 +344,7 @@ public class MediaActivity extends BaseTransparentActivity implements OnDownload
            binding.mediaDescription.setVisibility(View.GONE);
        }
    }
                break;
        }
        try {
            return super.dispatchTouchEvent(event);
        } catch (IllegalArgumentException ex) {
            ex.printStackTrace();
        }
        return false;

    }


    private boolean isAClick(float startX, float endX, float startY, float endY) {
        float differenceX = Math.abs(startX - endX);
        float differenceY = Math.abs(startY - endY);
        int CLICK_ACTION_THRESHOLD = 200;
        return !(differenceX > CLICK_ACTION_THRESHOLD/* =5 */ || differenceY > CLICK_ACTION_THRESHOLD);
    }

    @Override
    public void onDestroy() {
@@ -425,6 +396,7 @@ public class MediaActivity extends BaseTransparentActivity implements OnDownload
            binding.translate.setVisibility(View.GONE);
            binding.originalMessage.setVisibility(View.INVISIBLE);
        }
        toggleScreenContain(fullscreen);
    }

    private void hideSystemUI() {
+11 −0
Original line number Diff line number Diff line
@@ -14,6 +14,7 @@ package app.fedilab.android.ui.fragment.media;
 * You should have received a copy of the GNU General Public License along with Fedilab; if not,
 * see <http://www.gnu.org/licenses>. */


import android.content.SharedPreferences;
import android.graphics.Bitmap;
import android.graphics.Color;
@@ -104,6 +105,14 @@ public class FragmentMedia extends Fragment {
                enableSliding(true);
            }
        });
        binding.mediaPicture.setOnClickListener(v -> {
            ((MediaActivity) requireActivity()).toogleFullScreen();
        });

        binding.mediaVideo.setOnClickListener(v -> {
            ((MediaActivity) requireActivity()).toogleFullScreen();
        });

        String type = attachment.type;
        String preview_url = attachment.preview_url;
        if (type.equalsIgnoreCase("unknown")) {
@@ -119,6 +128,7 @@ public class FragmentMedia extends Fragment {
        binding.mediaPicture.setZoomable(false);
        binding.mediaPicture.setTransitionName(attachment.url);
        binding.mediaPicture.setVisibility(View.VISIBLE);

        binding.pbarInf.setScaleY(1f);
        binding.pbarInf.setIndeterminate(true);
        binding.loader.setVisibility(View.VISIBLE);
@@ -322,6 +332,7 @@ public class FragmentMedia extends Fragment {
        });
    }


    private void enableSliding(boolean enable) {
        if (enable && !swipeEnabled) {
            swipeEnabled = true;