1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
|
package org.fox.ttrss;
import android.os.Bundle;
import android.support.v4.app.ActivityCompat;
import android.support.v4.view.ViewCompat;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.ProgressBar;
import com.bogdwellers.pinchtozoom.ImageMatrixTouchHandler;
import com.bumptech.glide.Glide;
import com.bumptech.glide.load.engine.DiskCacheStrategy;
import com.bumptech.glide.load.resource.drawable.GlideDrawable;
import com.bumptech.glide.request.RequestListener;
import com.bumptech.glide.request.target.GlideDrawableImageViewTarget;
import com.bumptech.glide.request.target.Target;
import icepick.State;
public class GalleryImageFragment extends GalleryBaseFragment {
private final String TAG = this.getClass().getSimpleName();
@State String m_url;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_gallery_entry, container, false);
Log.d(TAG, "called for URL: " + m_url);
ImageView imgView = view.findViewById(R.id.flavor_image);
// TODO: ImageMatrixTouchHandler doesn't like context menus
ImageMatrixTouchHandler touchHandler = new ImageMatrixTouchHandler(view.getContext());
imgView.setOnTouchListener(touchHandler);
// shared element transitions stop GIFs from playing
if (m_url.toLowerCase().indexOf(".gif") == -1) {
ViewCompat.setTransitionName(imgView, "gallery:" + m_url);
}
registerForContextMenu(imgView);
final ProgressBar progressBar = view.findViewById(R.id.flavor_image_progress);
final View errorMessage = view.findViewById(R.id.flavor_image_error);
final GlideDrawableImageViewTarget glideImage = new GlideDrawableImageViewTarget(imgView);
Glide.with(this)
.load(m_url)
//.dontAnimate()
.diskCacheStrategy(DiskCacheStrategy.ALL)
.skipMemoryCache(false)
.listener(new RequestListener<String, GlideDrawable>() {
@Override
public boolean onException(Exception e, String model, Target<GlideDrawable> target, boolean isFirstResource) {
progressBar.setVisibility(View.GONE);
errorMessage.setVisibility(View.VISIBLE);
ActivityCompat.startPostponedEnterTransition(m_activity);
return false;
}
@Override
public boolean onResourceReady(GlideDrawable resource, String model, Target<GlideDrawable> target, boolean isFromMemoryCache, boolean isFirstResource) {
progressBar.setVisibility(View.GONE);
errorMessage.setVisibility(View.GONE);
ActivityCompat.startPostponedEnterTransition(m_activity);
return false;
}
})
.into(glideImage);
return view;
}
public void initialize(String url) {
m_url = url;
}
/*@Override
public boolean onContextItemSelected(MenuItem item) {
int position = m_pager.getCurrentItem();
String url = m_checkedUrls.get(position);
if (!onImageMenuItemSelected(item, url))
return super.onContextItemSelected(item);
else
return true;
}*/
}
|