layout fix, image preview improvement, added mediacontroller theme

This commit is contained in:
nuclearfog 2021-02-15 17:08:15 +01:00
parent 17c5d2c8a4
commit 6104c730bd
No known key found for this signature in database
GPG Key ID: D5490E4A81F97B14
6 changed files with 95 additions and 84 deletions

View File

@ -8,7 +8,6 @@ import android.media.MediaPlayer.OnInfoListener;
import android.media.MediaPlayer.OnPreparedListener; import android.media.MediaPlayer.OnPreparedListener;
import android.net.Uri; import android.net.Uri;
import android.os.Bundle; import android.os.Bundle;
import android.view.View;
import android.widget.MediaController; import android.widget.MediaController;
import android.widget.ProgressBar; import android.widget.ProgressBar;
import android.widget.Toast; import android.widget.Toast;
@ -79,9 +78,10 @@ public class MediaViewer extends MediaActivity implements OnImageClickListener,
public static final int MEDIAVIEWER_ANGIF = 4; public static final int MEDIAVIEWER_ANGIF = 4;
private ImageLoader imageAsync; private ImageLoader imageAsync;
private GlobalSettings settings;
private ProgressBar media_progress; private ProgressBar media_progress;
private MediaController videoController; private MediaController controlPanel;
private ImageAdapter adapter; private ImageAdapter adapter;
private VideoView videoView; private VideoView videoView;
private ZoomView zoomImage; private ZoomView zoomImage;
@ -99,12 +99,12 @@ public class MediaViewer extends MediaActivity implements OnImageClickListener,
media_progress = findViewById(R.id.media_progress); media_progress = findViewById(R.id.media_progress);
zoomImage = findViewById(R.id.image_full); zoomImage = findViewById(R.id.image_full);
videoView = findViewById(R.id.video_view); videoView = findViewById(R.id.video_view);
videoController = new MediaController(this); controlPanel = new MediaController(this);
videoView.setZOrderOnTop(true); videoView.setZOrderOnTop(true);
videoView.setOnPreparedListener(this); videoView.setOnPreparedListener(this);
videoView.setOnErrorListener(this); videoView.setOnErrorListener(this);
GlobalSettings settings = GlobalSettings.getInstance(this); settings = GlobalSettings.getInstance(this);
adapter = new ImageAdapter(settings, this); adapter = new ImageAdapter(settings, this);
AppStyles.setProgressColor(media_progress, settings.getHighlightColor()); AppStyles.setProgressColor(media_progress, settings.getHighlightColor());
@ -115,7 +115,8 @@ public class MediaViewer extends MediaActivity implements OnImageClickListener,
case MEDIAVIEWER_IMG_S: case MEDIAVIEWER_IMG_S:
adapter.disableSaveButton(); adapter.disableSaveButton();
case MEDIAVIEWER_IMAGE: case MEDIAVIEWER_IMAGE:
videoView.setVisibility(GONE); zoomImage.setVisibility(VISIBLE);
imageList.setVisibility(VISIBLE);
imageList.setLayoutManager(new LinearLayoutManager(this, HORIZONTAL, false)); imageList.setLayoutManager(new LinearLayoutManager(this, HORIZONTAL, false));
imageList.setAdapter(adapter); imageList.setAdapter(adapter);
if (imageAsync == null) { if (imageAsync == null) {
@ -125,9 +126,8 @@ public class MediaViewer extends MediaActivity implements OnImageClickListener,
break; break;
case MEDIAVIEWER_VIDEO: case MEDIAVIEWER_VIDEO:
zoomImage.setVisibility(GONE); videoView.setVisibility(VISIBLE);
imageList.setVisibility(GONE); videoView.setMediaController(controlPanel);
videoView.setMediaController(videoController);
case MEDIAVIEWER_ANGIF: case MEDIAVIEWER_ANGIF:
zoomImage.setVisibility(GONE); zoomImage.setVisibility(GONE);
Uri video = Uri.parse(mediaLinks[0]); Uri video = Uri.parse(mediaLinks[0]);
@ -185,7 +185,8 @@ public class MediaViewer extends MediaActivity implements OnImageClickListener,
if (type == MEDIAVIEWER_ANGIF) { if (type == MEDIAVIEWER_ANGIF) {
mp.setLooping(true); mp.setLooping(true);
} else { } else {
videoController.show(0); controlPanel.show(Integer.MAX_VALUE);
AppStyles.setTheme(settings, controlPanel);
if (videoPos > 0) { if (videoPos > 0) {
mp.seekTo(videoPos); mp.seekTo(videoPos);
} }
@ -246,8 +247,8 @@ public class MediaViewer extends MediaActivity implements OnImageClickListener,
public void setImage(ImageHolder image) { public void setImage(ImageHolder image) {
if (adapter.isEmpty()) { if (adapter.isEmpty()) {
zoomImage.reset(); zoomImage.reset();
zoomImage.setImageBitmap(image.getMiddleSize()); zoomImage.setImageBitmap(image.reducedImage);
media_progress.setVisibility(View.INVISIBLE); media_progress.setVisibility(INVISIBLE);
} }
adapter.addLast(image); adapter.addLast(image);
} }

View File

@ -125,7 +125,7 @@ public class ImageAdapter extends Adapter<ViewHolder> {
public void onClick(View v) { public void onClick(View v) {
int pos = item.getAdapterPosition(); int pos = item.getAdapterPosition();
if (pos != NO_POSITION) { if (pos != NO_POSITION) {
Bitmap img = images.get(pos).getMiddleSize(); Bitmap img = images.get(pos).reducedImage;
itemClickListener.onImageClick(img); itemClickListener.onImageClick(img);
} }
} }
@ -137,7 +137,7 @@ public class ImageAdapter extends Adapter<ViewHolder> {
public void onClick(View v) { public void onClick(View v) {
int pos = item.getAdapterPosition(); int pos = item.getAdapterPosition();
if (pos != NO_POSITION) { if (pos != NO_POSITION) {
Bitmap img = images.get(pos).getOriginalImage(); Bitmap img = images.get(pos).fullImage;
itemClickListener.onImageSave(img, pos); itemClickListener.onImageSave(img, pos);
} }
} }
@ -155,7 +155,7 @@ public class ImageAdapter extends Adapter<ViewHolder> {
public void onBindViewHolder(@NonNull ViewHolder vh, int index) { public void onBindViewHolder(@NonNull ViewHolder vh, int index) {
if (vh instanceof ImageItem) { if (vh instanceof ImageItem) {
ImageItem item = (ImageItem) vh; ImageItem item = (ImageItem) vh;
Bitmap image = images.get(index).getSmallSize(); Bitmap image = images.get(index).preview;
item.preview.setImageBitmap(image); item.preview.setImageBitmap(image);
} }
} }

View File

@ -2,7 +2,6 @@ package org.nuclearfog.twidda.backend;
import android.graphics.Bitmap; import android.graphics.Bitmap;
import android.graphics.BitmapFactory; import android.graphics.BitmapFactory;
import android.graphics.Point;
import android.os.AsyncTask; import android.os.AsyncTask;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
@ -23,13 +22,10 @@ import java.lang.ref.WeakReference;
*/ */
public class ImageLoader extends AsyncTask<String, ImageHolder, Boolean> { public class ImageLoader extends AsyncTask<String, ImageHolder, Boolean> {
private static final float PREV_HEIGHT_RATIO = 5.0f;
@Nullable @Nullable
private EngineException err; private EngineException err;
private TwitterEngine mTwitter; private TwitterEngine mTwitter;
private WeakReference<MediaViewer> callback; private WeakReference<MediaViewer> callback;
private float previewHeight, zoomPreview;
/** /**
@ -41,10 +37,6 @@ public class ImageLoader extends AsyncTask<String, ImageHolder, Boolean> {
super(); super();
this.callback = new WeakReference<>(callback); this.callback = new WeakReference<>(callback);
mTwitter = TwitterEngine.getInstance(callback); mTwitter = TwitterEngine.getInstance(callback);
Point displaySize = new Point();
callback.getWindowManager().getDefaultDisplay().getSize(displaySize);
zoomPreview = displaySize.x;
previewHeight = displaySize.y / PREV_HEIGHT_RATIO;
} }
@ -59,7 +51,7 @@ public class ImageLoader extends AsyncTask<String, ImageHolder, Boolean> {
image = BitmapFactory.decodeFile(link); image = BitmapFactory.decodeFile(link);
} }
if (image != null) { if (image != null) {
ImageHolder images = new ImageHolder(image, previewHeight, zoomPreview); ImageHolder images = new ImageHolder(image);
publishProgress(images); publishProgress(images);
} }
} }

View File

@ -11,53 +11,53 @@ import androidx.annotation.NonNull;
*/ */
public class ImageHolder { public class ImageHolder {
private Bitmap smallImage, middleImage, fullImage; /**
* maximum height of the smallest preview in pixels
*/
private static final float previewHeight = 320.0f;
/**
* maximum height of the image preview in pixels
*/
private static final float reducedHeight = 1200.0f;
/**
* preview image bitmap
*/
public final Bitmap preview;
/**
* downscaled image bitmap
*/
public final Bitmap reducedImage;
/**
* full image bitmap
*/
public final Bitmap fullImage;
/** /**
* @param fullImage Full size image * @param fullImage Full size image
* @param smallImageHeight height of the smallest image preview
* @param middleImageWidth width of the image preview
*/ */
public ImageHolder(@NonNull Bitmap fullImage, float smallImageHeight, float middleImageWidth) { public ImageHolder(@NonNull Bitmap fullImage) {
this.fullImage = fullImage; this.fullImage = fullImage;
float ratio = fullImage.getHeight() / smallImageHeight; float reducedRatio = fullImage.getHeight() / reducedHeight;
int destWidth = (int) (fullImage.getWidth() / ratio); float previewRatio = fullImage.getHeight() / previewHeight;
smallImage = Bitmap.createScaledBitmap(fullImage, destWidth, (int) smallImageHeight, false);
if (middleImageWidth > 0 && fullImage.getWidth() > middleImageWidth) { if (reducedRatio > 1.0f) {
ratio = fullImage.getWidth() / middleImageWidth; int height = (int) reducedHeight;
int destHeight = (int) (fullImage.getHeight() / ratio); int width = (int) (fullImage.getWidth() / reducedRatio);
middleImage = Bitmap.createScaledBitmap(fullImage, (int) middleImageWidth, destHeight, false); reducedImage = Bitmap.createScaledBitmap(fullImage, width, height, false);
} else { } else {
middleImage = fullImage; reducedImage = fullImage;
} }
if (previewRatio > 1.0f) {
int height = (int) previewHeight;
int width = (int) (fullImage.getWidth() / previewRatio);
preview = Bitmap.createScaledBitmap(fullImage, width, height, false);
} else {
preview = fullImage;
} }
/**
* get small sized image
*
* @return Image Bitmap
*/
public Bitmap getSmallSize() {
return smallImage;
}
/**
* get Middle sized image
*
* @return Image Bitmap
*/
public Bitmap getMiddleSize() {
return middleImage;
}
/**
* get Original Image
*
* @return Image Bitmap
*/
public Bitmap getOriginalImage() {
return fullImage;
} }
} }

View File

@ -1,35 +1,53 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" <androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent"> android:layout_height="match_parent">
<VideoView
android:id="@+id/video_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center" />
<org.nuclearfog.zoomview.ZoomView <org.nuclearfog.zoomview.ZoomView
android:id="@+id/image_full" android:id="@+id/image_full"
android:layout_width="match_parent" android:layout_width="0dp"
android:layout_height="match_parent" android:layout_height="0dp"
android:visibility="invisible"
app:enable_move="true" app:enable_move="true"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:max_zoom_in="10.0" app:max_zoom_in="10.0"
app:max_zoom_out="0.8" /> app:max_zoom_out="0.7" />
<ProgressBar
android:id="@+id/media_progress"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center" />
<androidx.recyclerview.widget.RecyclerView <androidx.recyclerview.widget.RecyclerView
android:id="@+id/image_list" android:id="@+id/image_list"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="0dp"
android:layout_gravity="bottom" android:layout_marginStart="@dimen/mediapage_preview_margin"
android:layout_marginLeft="@dimen/mediapage_preview_margin"
android:layout_marginBottom="@dimen/mediapage_preview_margin"
android:scrollbars="horizontal" android:scrollbars="horizontal"
android:layout_margin="@dimen/mediapage_preview_margin" /> android:visibility="invisible"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintHeight_percent="0.2"
app:layout_constraintStart_toStartOf="parent" />
</FrameLayout> <VideoView
android:id="@+id/video_view"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:visibility="invisible"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<ProgressBar
android:id="@+id/media_progress"
android:layout_width="@dimen/mediapage_circle_size"
android:layout_height="@dimen/mediapage_circle_size"
android:layout_marginTop="@dimen/mediapage_preview_margin"
app:layout_constraintBottom_toTopOf="@+id/image_list"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>

View File

@ -57,7 +57,6 @@
<dimen name="editprofile_layout_padding">20dp</dimen> <dimen name="editprofile_layout_padding">20dp</dimen>
<dimen name="editprofile_button_padding">5dp</dimen> <dimen name="editprofile_button_padding">5dp</dimen>
<dimen name="editprofile_button_height">20sp</dimen> <dimen name="editprofile_button_height">20sp</dimen>
<dimen name="editprofile_button_width">120sp</dimen>
<dimen name="editprofile_edittext_padding">5dp</dimen> <dimen name="editprofile_edittext_padding">5dp</dimen>
<dimen name="editprofile_bio_min_height">150dp</dimen> <dimen name="editprofile_bio_min_height">150dp</dimen>
<dimen name="editprofile_image">@dimen/profile_image_size</dimen> <dimen name="editprofile_image">@dimen/profile_image_size</dimen>
@ -148,6 +147,7 @@
<!--dimens of page_media.xml--> <!--dimens of page_media.xml-->
<dimen name="mediapage_preview_margin">10dp</dimen> <dimen name="mediapage_preview_margin">10dp</dimen>
<dimen name="mediapage_circle_size">64dp</dimen>
<!--dimens of item_placeholder.xml--> <!--dimens of item_placeholder.xml-->
<dimen name="placeholderitem_margin">8dp</dimen> <dimen name="placeholderitem_margin">8dp</dimen>