Fix MultiImageView not switching to thumbnail mode

Take special care when removing VideoViews to call stopPlayback
multisite
Floens 10 years ago
parent 262f34dfc1
commit 17cd26b6af
  1. 28
      Clover/app/src/main/java/org/floens/chan/ui/view/MultiImageView.java

@ -32,6 +32,7 @@ import android.widget.Toast;
import android.widget.VideoView; import android.widget.VideoView;
import com.android.volley.VolleyError; import com.android.volley.VolleyError;
import com.android.volley.toolbox.ImageLoader;
import com.android.volley.toolbox.ImageLoader.ImageContainer; import com.android.volley.toolbox.ImageLoader.ImageContainer;
import com.davemorrissey.labs.subscaleview.ImageSource; import com.davemorrissey.labs.subscaleview.ImageSource;
@ -109,8 +110,7 @@ public class MultiImageView extends FrameLayout implements View.OnClickListener
public void setMode(final Mode newMode) { public void setMode(final Mode newMode) {
if (this.mode != newMode) { if (this.mode != newMode) {
Logger.d(TAG, "Changing mode from " + this.mode + " to " + newMode + " for " + postImage.thumbnailUrl); // Logger.test("Changing mode from " + this.mode + " to " + newMode + " for " + postImage.thumbnailUrl);
Mode oldMode = this.mode;
this.mode = newMode; this.mode = newMode;
AndroidUtils.waitForMeasure(this, new AndroidUtils.OnMeasuredCallback() { AndroidUtils.waitForMeasure(this, new AndroidUtils.OnMeasuredCallback() {
@ -165,7 +165,7 @@ public class MultiImageView extends FrameLayout implements View.OnClickListener
} }
// Also use volley for the thumbnails // Also use volley for the thumbnails
thumbnailRequest = Chan.getVolleyImageLoader().get(thumbnailUrl, new com.android.volley.toolbox.ImageLoader.ImageListener() { thumbnailRequest = Chan.getVolleyImageLoader().get(thumbnailUrl, new ImageLoader.ImageListener() {
@Override @Override
public void onErrorResponse(VolleyError error) { public void onErrorResponse(VolleyError error) {
thumbnailRequest = null; thumbnailRequest = null;
@ -183,6 +183,13 @@ public class MultiImageView extends FrameLayout implements View.OnClickListener
} }
} }
}, getWidth(), getHeight()); }, getWidth(), getHeight());
if (thumbnailRequest.getBitmap() != null) {
// Request was immediate and thumbnailRequest was first set to null in onResponse, and then set to the container
// when the method returned
// Still set it to null here
thumbnailRequest = null;
}
} }
public void setBigImage(String imageUrl) { public void setBigImage(String imageUrl) {
@ -295,7 +302,7 @@ public class MultiImageView extends FrameLayout implements View.OnClickListener
onError(); onError();
return; return;
} catch (OutOfMemoryError e) { } catch (OutOfMemoryError e) {
System.gc(); Runtime.getRuntime().gc();
e.printStackTrace(); e.printStackTrace();
onOutOfMemoryError(); onOutOfMemoryError();
return; return;
@ -387,10 +394,6 @@ public class MultiImageView extends FrameLayout implements View.OnClickListener
} }
} }
public VideoView getVideoView() {
return videoView;
}
private void onVideoError() { private void onVideoError() {
if (!videoError) { if (!videoError) {
videoError = true; videoError = true;
@ -423,15 +426,19 @@ public class MultiImageView extends FrameLayout implements View.OnClickListener
public void cancelLoad() { public void cancelLoad() {
if (thumbnailRequest != null) { if (thumbnailRequest != null) {
thumbnailRequest.cancelRequest(); thumbnailRequest.cancelRequest();
thumbnailRequest = null;
} }
if (bigImageRequest != null) { if (bigImageRequest != null) {
bigImageRequest.cancel(); bigImageRequest.cancel();
bigImageRequest = null;
} }
if (gifRequest != null) { if (gifRequest != null) {
gifRequest.cancel(); gifRequest.cancel();
gifRequest = null;
} }
if (videoRequest != null) { if (videoRequest != null) {
videoRequest.cancel(); videoRequest.cancel();
videoRequest = null;
} }
} }
@ -454,6 +461,11 @@ public class MultiImageView extends FrameLayout implements View.OnClickListener
View child = getChildAt(i); View child = getChildAt(i);
if (child != playView) { if (child != playView) {
if (child != view) { if (child != view) {
if (child instanceof VideoView) {
VideoView item = (VideoView) child;
item.stopPlayback();
}
removeViewAt(i); removeViewAt(i);
} else { } else {
alreadyAttached = true; alreadyAttached = true;

Loading…
Cancel
Save