mirror of
https://github.com/commons-app/apps-android-commons.git
synced 2025-10-27 04:43:54 +01:00
parent
707e3145c2
commit
82bf2d757f
2 changed files with 77 additions and 15 deletions
|
|
@ -7,6 +7,7 @@ import android.annotation.SuppressLint;
|
||||||
import android.app.AlertDialog;
|
import android.app.AlertDialog;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
|
import android.content.res.Configuration;
|
||||||
import android.graphics.drawable.Animatable;
|
import android.graphics.drawable.Animatable;
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
|
|
@ -101,6 +102,8 @@ public class MediaDetailFragment extends CommonsDaggerSupportFragment {
|
||||||
|
|
||||||
@BindView(R.id.mediaDetailImageView)
|
@BindView(R.id.mediaDetailImageView)
|
||||||
SimpleDraweeView image;
|
SimpleDraweeView image;
|
||||||
|
@BindView(R.id.mediaDetailImageViewLandscape)
|
||||||
|
SimpleDraweeView imageLandscape;
|
||||||
@BindView(R.id.mediaDetailImageViewSpacer)
|
@BindView(R.id.mediaDetailImageViewSpacer)
|
||||||
LinearLayout imageSpacer;
|
LinearLayout imageSpacer;
|
||||||
@BindView(R.id.mediaDetailTitle)
|
@BindView(R.id.mediaDetailTitle)
|
||||||
|
|
@ -144,10 +147,14 @@ public class MediaDetailFragment extends CommonsDaggerSupportFragment {
|
||||||
* However unlike categories depictions is multi-lingual
|
* However unlike categories depictions is multi-lingual
|
||||||
* Ex: key: en value: monument
|
* Ex: key: en value: monument
|
||||||
*/
|
*/
|
||||||
|
private ImageInfo imageInfoCache;
|
||||||
|
private int oldWidthOfImageView;
|
||||||
|
private int newWidthOfImageView;
|
||||||
private Depictions depictions;
|
private Depictions depictions;
|
||||||
private boolean categoriesLoaded = false;
|
private boolean categoriesLoaded = false;
|
||||||
private boolean categoriesPresent = false;
|
private boolean categoriesPresent = false;
|
||||||
private boolean depictionLoaded = false;
|
private boolean depictionLoaded = false;
|
||||||
|
private boolean heightVerifyingBoolean = true; // helps in maintaining aspect ratio
|
||||||
private ViewTreeObserver.OnGlobalLayoutListener layoutListener; // for layout stuff, only used once!
|
private ViewTreeObserver.OnGlobalLayoutListener layoutListener; // for layout stuff, only used once!
|
||||||
|
|
||||||
//Had to make this class variable, to implement various onClicks, which access the media, also I fell why make separate variables when one can serve the purpose
|
//Had to make this class variable, to implement various onClicks, which access the media, also I fell why make separate variables when one can serve the purpose
|
||||||
|
|
@ -238,12 +245,49 @@ public class MediaDetailFragment extends CommonsDaggerSupportFragment {
|
||||||
@Override
|
@Override
|
||||||
public void onGlobalLayout() {
|
public void onGlobalLayout() {
|
||||||
scrollView.getViewTreeObserver().removeOnGlobalLayoutListener(this);
|
scrollView.getViewTreeObserver().removeOnGlobalLayoutListener(this);
|
||||||
|
if (getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE) {
|
||||||
|
imageLandscape.setVisibility(VISIBLE);
|
||||||
|
}
|
||||||
|
oldWidthOfImageView = scrollView.getWidth();
|
||||||
displayMediaDetails();
|
displayMediaDetails();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onConfigurationChanged(Configuration newConfig) {
|
||||||
|
super.onConfigurationChanged(newConfig);
|
||||||
|
scrollView.getViewTreeObserver().addOnGlobalLayoutListener(
|
||||||
|
new OnGlobalLayoutListener() {
|
||||||
|
@Override
|
||||||
|
public void onGlobalLayout() {
|
||||||
|
if (scrollView.getWidth() != oldWidthOfImageView) {
|
||||||
|
if (newWidthOfImageView == 0) {
|
||||||
|
newWidthOfImageView = scrollView.getWidth();
|
||||||
|
updateAspectRatio(newWidthOfImageView);
|
||||||
|
}
|
||||||
|
scrollView.getViewTreeObserver().removeOnGlobalLayoutListener(this);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
);
|
||||||
|
// check orientation
|
||||||
|
if (getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE) {
|
||||||
|
imageLandscape.setVisibility(VISIBLE);
|
||||||
|
} else if (newConfig.orientation == Configuration.ORIENTATION_PORTRAIT) {
|
||||||
|
imageLandscape.setVisibility(GONE);
|
||||||
|
}
|
||||||
|
// ensuring correct aspect ratio for landscape mode
|
||||||
|
if (heightVerifyingBoolean) {
|
||||||
|
updateAspectRatio(newWidthOfImageView);
|
||||||
|
heightVerifyingBoolean = false;
|
||||||
|
} else {
|
||||||
|
updateAspectRatio(oldWidthOfImageView);
|
||||||
|
heightVerifyingBoolean = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void displayMediaDetails() {
|
private void displayMediaDetails() {
|
||||||
//Always load image from Internet to allow viewing the desc, license, and cats
|
//Always load image from Internet to allow viewing the desc, license, and cats
|
||||||
setupImageView();
|
setupImageView();
|
||||||
|
|
@ -262,29 +306,31 @@ public class MediaDetailFragment extends CommonsDaggerSupportFragment {
|
||||||
* The imageSpacer is Basically a transparent overlay for the SimpleDraweeView
|
* The imageSpacer is Basically a transparent overlay for the SimpleDraweeView
|
||||||
* which holds the image to be displayed( moreover this image is out of
|
* which holds the image to be displayed( moreover this image is out of
|
||||||
* the scroll view )
|
* the scroll view )
|
||||||
* @param imageInfo used to calculate height of the ImageSpacer
|
* @param scrollWidth the current width of the scrollView
|
||||||
*/
|
*/
|
||||||
private void updateAspectRatio(ImageInfo imageInfo) {
|
private void updateAspectRatio(int scrollWidth) {
|
||||||
if (imageInfo != null) {
|
if (imageInfoCache != null) {
|
||||||
int screenWidth = scrollView.getWidth();
|
int finalHeight = (scrollWidth*imageInfoCache.getHeight()) / imageInfoCache.getWidth();
|
||||||
int finalHeight = (screenWidth*imageInfo.getHeight()) / imageInfo.getWidth();
|
|
||||||
ViewGroup.LayoutParams params = image.getLayoutParams();
|
ViewGroup.LayoutParams params = image.getLayoutParams();
|
||||||
ViewGroup.LayoutParams spacerParams = imageSpacer.getLayoutParams();
|
ViewGroup.LayoutParams spacerParams = imageSpacer.getLayoutParams();
|
||||||
params.height = finalHeight;
|
params.height = finalHeight;
|
||||||
spacerParams.height = finalHeight;
|
spacerParams.height = finalHeight;
|
||||||
image.setLayoutParams(params);
|
image.setLayoutParams(params);
|
||||||
imageSpacer.setLayoutParams(spacerParams);
|
imageSpacer.setLayoutParams(spacerParams);
|
||||||
|
imageLandscape.setLayoutParams(params);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private final ControllerListener aspectRatioListener = new BaseControllerListener<ImageInfo>() {
|
private final ControllerListener aspectRatioListener = new BaseControllerListener<ImageInfo>() {
|
||||||
@Override
|
@Override
|
||||||
public void onIntermediateImageSet(String id, @Nullable ImageInfo imageInfo) {
|
public void onIntermediateImageSet(String id, @Nullable ImageInfo imageInfo) {
|
||||||
updateAspectRatio(imageInfo);
|
imageInfoCache = imageInfo;
|
||||||
|
updateAspectRatio(scrollView.getWidth());
|
||||||
}
|
}
|
||||||
@Override
|
@Override
|
||||||
public void onFinalImageSet(String id, @Nullable ImageInfo imageInfo, @Nullable Animatable animatable) {
|
public void onFinalImageSet(String id, @Nullable ImageInfo imageInfo, @Nullable Animatable animatable) {
|
||||||
updateAspectRatio(imageInfo);
|
imageInfoCache = imageInfo;
|
||||||
|
updateAspectRatio(scrollView.getWidth());
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -300,7 +346,14 @@ public class MediaDetailFragment extends CommonsDaggerSupportFragment {
|
||||||
.setControllerListener(aspectRatioListener)
|
.setControllerListener(aspectRatioListener)
|
||||||
.setOldController(image.getController())
|
.setOldController(image.getController())
|
||||||
.build();
|
.build();
|
||||||
|
DraweeController controllerLandscape = Fresco.newDraweeControllerBuilder()
|
||||||
|
.setLowResImageRequest(ImageRequest.fromUri(media.getThumbUrl()))
|
||||||
|
.setImageRequest(ImageRequest.fromUri(media.getImageUrl()))
|
||||||
|
.setControllerListener(aspectRatioListener)
|
||||||
|
.setOldController(imageLandscape.getController())
|
||||||
|
.build();
|
||||||
image.setController(controller);
|
image.setController(controller);
|
||||||
|
imageLandscape.setController(controllerLandscape);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
||||||
|
|
@ -40,13 +40,24 @@
|
||||||
<!-- Placeholder. Height gets set at runtime based on container size; the initial value is a hack to keep
|
<!-- Placeholder. Height gets set at runtime based on container size; the initial value is a hack to keep
|
||||||
the detail info offscreen until it's placed properly. May be a better way to do this. -->
|
the detail info offscreen until it's placed properly. May be a better way to do this. -->
|
||||||
|
|
||||||
<LinearLayout
|
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="@dimen/dimen_250"
|
android:layout_height="wrap_content" >
|
||||||
android:orientation="vertical"
|
|
||||||
android:background="@android:color/transparent"
|
<com.facebook.drawee.view.SimpleDraweeView
|
||||||
android:id="@+id/mediaDetailImageViewSpacer"
|
android:id="@+id/mediaDetailImageViewLandscape"
|
||||||
/>
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="@dimen/dimen_250"
|
||||||
|
app:actualImageScaleType="none"
|
||||||
|
android:visibility="gone" />
|
||||||
|
|
||||||
|
<LinearLayout
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="@dimen/dimen_250"
|
||||||
|
android:orientation="vertical"
|
||||||
|
android:id="@+id/mediaDetailImageViewSpacer" />
|
||||||
|
|
||||||
|
</FrameLayout>
|
||||||
|
|
||||||
<LinearLayout
|
<LinearLayout
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
|
|
@ -54,8 +65,6 @@
|
||||||
android:background="?attr/mainBackground"
|
android:background="?attr/mainBackground"
|
||||||
android:orientation="vertical">
|
android:orientation="vertical">
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
<LinearLayout
|
<LinearLayout
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue