Skip to content
This repository has been archived by the owner on Jun 9, 2023. It is now read-only.

Commit

Permalink
MediaViewer: Always limit video height to vertical space
Browse files Browse the repository at this point in the history
  • Loading branch information
Tunous committed Dec 28, 2018
1 parent 9778054 commit 4186b3e
Showing 1 changed file with 6 additions and 11 deletions.
17 changes: 6 additions & 11 deletions app/src/main/java/me/saket/dank/ui/media/MediaVideoFragment.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,18 @@
import android.view.ViewGroup;
import android.widget.ViewFlipper;

import butterknife.BindView;
import butterknife.ButterKnife;
import com.danikula.videocache.HttpProxyCacheServer;
import com.devbrackets.android.exomedia.ui.widget.VideoView;
import com.google.android.exoplayer2.ExoPlaybackException;
import com.google.android.exoplayer2.upstream.HttpDataSource;
import com.jakewharton.rxrelay2.BehaviorRelay;
import dagger.Lazy;
import timber.log.Timber;

import javax.inject.Inject;

import butterknife.BindView;
import butterknife.ButterKnife;
import dagger.Lazy;
import me.saket.dank.R;
import me.saket.dank.data.ErrorResolver;
import me.saket.dank.data.ResolvedError;
Expand All @@ -32,7 +33,6 @@
import me.saket.dank.widgets.MediaAlbumViewerTitleDescriptionView;
import me.saket.dank.widgets.binoculars.FlickDismissLayout;
import me.saket.dank.widgets.binoculars.FlickGestureListener;
import timber.log.Timber;

public class MediaVideoFragment extends BaseMediaViewerFragment {

Expand Down Expand Up @@ -171,17 +171,12 @@ public void onViewCreated(View fragmentLayout, @Nullable Bundle savedInstanceSta
int parentHeight = parent.getHeight();

int videoControlsHeight = videoControlsView.heightOfControlButtons();
boolean isPortraitVideo = (videoHeight + videoControlsHeight) > videoWidth;

float resizeFactorToFillHorizontalSpace = (float) parentWidth / videoWidth;
int resizedHeight = (int) (videoHeight * resizeFactorToFillHorizontalSpace) + videoControlsHeight;

if (isPortraitVideo) {
int verticalSpaceAvailable = parentHeight - Views.getPaddingVertical(parent);
Views.setDimensions(videoView, parentWidth, Math.min(resizedHeight, verticalSpaceAvailable));
} else {
Views.setDimensions(videoView, parentWidth, resizedHeight);
}
int verticalSpaceAvailable = parentHeight - Views.getPaddingVertical(parent);
Views.setDimensions(videoView, parentWidth, Math.min(resizedHeight, verticalSpaceAvailable));
}, error -> {
ResolvedError resolvedError = errorResolver.get().resolve(error);
resolvedError.ifUnknown(() -> Timber.e(error, "Error while trying to get option buttons' height"));
Expand Down

0 comments on commit 4186b3e

Please sign in to comment.