mirror of
https://github.com/commons-app/apps-android-commons.git
synced 2025-10-26 20:33:53 +01:00
Final touch-ups to improved image loading.
This commit is contained in:
parent
7a4062a377
commit
38e7cad345
9 changed files with 44 additions and 33 deletions
|
|
@ -11,6 +11,7 @@ import android.content.pm.PackageManager;
|
|||
import android.os.Build;
|
||||
import android.database.sqlite.SQLiteDatabase;
|
||||
import android.preference.PreferenceManager;
|
||||
import android.support.v4.util.LruCache;
|
||||
|
||||
import com.facebook.drawee.backends.pipeline.Fresco;
|
||||
import com.facebook.stetho.Stetho;
|
||||
|
|
@ -84,6 +85,7 @@ public class CommonsApplication extends Application {
|
|||
private static CommonsApplication instance = null;
|
||||
private AbstractHttpClient httpClient = null;
|
||||
private MWApi api = null;
|
||||
LruCache<String, String> thumbnailUrlCache = new LruCache<>(1024);
|
||||
private CacheController cacheData = null;
|
||||
private DBOpenHelper dbOpenHelper = null;
|
||||
private NearbyPlaces nearbyPlaces = null;
|
||||
|
|
@ -139,6 +141,10 @@ public class CommonsApplication extends Application {
|
|||
return cacheData;
|
||||
}
|
||||
|
||||
public LruCache<String, String> getThumbnailUrlCache() {
|
||||
return thumbnailUrlCache;
|
||||
}
|
||||
|
||||
public synchronized DBOpenHelper getDBOpenHelper() {
|
||||
if (dbOpenHelper == null) {
|
||||
dbOpenHelper = new DBOpenHelper(this);
|
||||
|
|
|
|||
|
|
@ -3,14 +3,12 @@ package fr.free.nrw.commons;
|
|||
import android.content.Context;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.v4.util.LruCache;
|
||||
import android.util.AttributeSet;
|
||||
|
||||
import com.facebook.drawee.view.SimpleDraweeView;
|
||||
|
||||
public class MediaWikiImageView extends SimpleDraweeView {
|
||||
private ThumbnailFetchTask currentThumbnailTask;
|
||||
LruCache<String, String> thumbnailUrlCache = new LruCache<>(1024);
|
||||
|
||||
public MediaWikiImageView(Context context) {
|
||||
this(context, null);
|
||||
|
|
@ -29,14 +27,13 @@ public class MediaWikiImageView extends SimpleDraweeView {
|
|||
currentThumbnailTask.cancel(true);
|
||||
}
|
||||
if(media == null) {
|
||||
setImageURI((String) null);
|
||||
return;
|
||||
}
|
||||
|
||||
if (thumbnailUrlCache.get(media.getFilename()) != null) {
|
||||
setImageUrl(thumbnailUrlCache.get(media.getFilename()));
|
||||
if (CommonsApplication.getInstance().getThumbnailUrlCache().get(media.getFilename()) != null) {
|
||||
setImageUrl(CommonsApplication.getInstance().getThumbnailUrlCache().get(media.getFilename()));
|
||||
} else {
|
||||
setImageURI((String) null);
|
||||
setImageUrl(null);
|
||||
currentThumbnailTask = new ThumbnailFetchTask(media);
|
||||
currentThumbnailTask.execute(media.getFilename());
|
||||
}
|
||||
|
|
@ -64,7 +61,7 @@ public class MediaWikiImageView extends SimpleDraweeView {
|
|||
if (isCancelled()) {
|
||||
return;
|
||||
}
|
||||
thumbnailUrlCache.put(media.getFilename(), result);
|
||||
CommonsApplication.getInstance().getThumbnailUrlCache().put(media.getFilename(), result);
|
||||
setImageUrl(result);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -10,9 +10,7 @@ import android.view.LayoutInflater;
|
|||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.view.ViewTreeObserver;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.ProgressBar;
|
||||
import android.widget.ScrollView;
|
||||
import android.widget.TextView;
|
||||
|
||||
|
|
@ -50,10 +48,7 @@ public class MediaDetailFragment extends Fragment {
|
|||
return mf;
|
||||
}
|
||||
|
||||
private ImageView image;
|
||||
//private EditText title;
|
||||
private ProgressBar loadingProgress;
|
||||
private ImageView loadingFailed;
|
||||
private MediaWikiImageView image;
|
||||
private MediaDetailSpacer spacer;
|
||||
private int initialListTop = 0;
|
||||
|
||||
|
|
@ -105,9 +100,7 @@ public class MediaDetailFragment extends Fragment {
|
|||
|
||||
final View view = inflater.inflate(R.layout.fragment_media_detail, container, false);
|
||||
|
||||
image = (ImageView) view.findViewById(R.id.mediaDetailImage);
|
||||
loadingProgress = (ProgressBar) view.findViewById(R.id.mediaDetailImageLoading);
|
||||
loadingFailed = (ImageView) view.findViewById(R.id.mediaDetailImageFailed);
|
||||
image = (MediaWikiImageView) view.findViewById(R.id.mediaDetailImage);
|
||||
scrollView = (ScrollView) view.findViewById(R.id.mediaDetailScrollView);
|
||||
|
||||
// Detail consists of a list view with main pane in header view, plus category list.
|
||||
|
|
@ -178,8 +171,7 @@ public class MediaDetailFragment extends Fragment {
|
|||
|
||||
private void displayMediaDetails(final Media media) {
|
||||
//Always load image from Internet to allow viewing the desc, license, and cats
|
||||
MediaWikiImageView mwImage = (MediaWikiImageView) image;
|
||||
mwImage.setMedia(media);
|
||||
image.setMedia(media);
|
||||
|
||||
// FIXME: For transparent images
|
||||
// FIXME: keep the spinner going while we load data
|
||||
|
|
|
|||
|
|
@ -0,0 +1,9 @@
|
|||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="48dp"
|
||||
android:height="48dp"
|
||||
android:viewportWidth="24.0"
|
||||
android:viewportHeight="24.0">
|
||||
<path
|
||||
android:fillColor="#FF808080"
|
||||
android:pathData="M11,15h2v2h-2zM11,7h2v6h-2zM11.99,2C6.47,2 2,6.48 2,12s4.47,10 9.99,10C17.52,22 22,17.52 22,12S17.52,2 11.99,2zM12,20c-4.42,0 -8,-3.58 -8,-8s3.58,-8 8,-8 8,3.58 8,8 -3.58,8 -8,8z"/>
|
||||
</vector>
|
||||
9
app/src/main/res/drawable/ic_image_black_24dp.xml
Normal file
9
app/src/main/res/drawable/ic_image_black_24dp.xml
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="48dp"
|
||||
android:height="48dp"
|
||||
android:viewportWidth="24.0"
|
||||
android:viewportHeight="24.0">
|
||||
<path
|
||||
android:fillColor="#FF808080"
|
||||
android:pathData="M21,19V5c0,-1.1 -0.9,-2 -2,-2H5c-1.1,0 -2,0.9 -2,2v14c0,1.1 0.9,2 2,2h14c1.1,0 2,-0.9 2,-2zM8.5,13.5l2.5,3.01L14.5,12l4.5,6H5l3.5,-4.5z"/>
|
||||
</vector>
|
||||
|
|
@ -25,7 +25,9 @@
|
|||
android:id="@+id/backgroundImage"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
app:actualImageScaleType="centerCrop" />
|
||||
app:actualImageScaleType="centerCrop"
|
||||
app:placeholderImage="@drawable/ic_image_black_24dp"
|
||||
app:failureImage="@drawable/ic_error_outline_black_24dp" />
|
||||
|
||||
<FrameLayout
|
||||
android:id="@+id/single_upload_fragment_container"
|
||||
|
|
|
|||
|
|
@ -1,20 +1,12 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
android:orientation="vertical"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:background="?attr/mainBackground"
|
||||
>
|
||||
|
||||
<ProgressBar
|
||||
android:id="@+id/mediaDetailImageLoading"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center"
|
||||
android:indeterminate="true"
|
||||
android:visibility="visible"
|
||||
/>
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/mediaDetailImageFailed"
|
||||
android:layout_height="wrap_content"
|
||||
|
|
@ -28,7 +20,9 @@
|
|||
android:id="@+id/mediaDetailImage"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:scaleType="fitCenter"
|
||||
app:actualImageScaleType="fitCenter"
|
||||
app:placeholderImage="@drawable/ic_image_black_24dp"
|
||||
app:failureImage="@drawable/ic_image_black_24dp"
|
||||
/>
|
||||
|
||||
<ScrollView
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:custom="http://schemas.android.com/apk/res-auto"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
android:orientation="vertical"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
|
|
@ -22,8 +22,9 @@
|
|||
android:id="@+id/contributionImage"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="240dp"
|
||||
android:scaleType="centerCrop"
|
||||
custom:isThumbnail="true"
|
||||
app:actualImageScaleType="centerCrop"
|
||||
app:placeholderImage="@drawable/ic_image_black_24dp"
|
||||
app:failureImage="@drawable/ic_image_black_24dp"
|
||||
/>
|
||||
|
||||
<LinearLayout
|
||||
|
|
|
|||
|
|
@ -14,7 +14,8 @@
|
|||
android:layout_width="match_parent"
|
||||
android:layout_height="192dp"
|
||||
app:actualImageScaleType="centerCrop"
|
||||
/>
|
||||
app:placeholderImage="@drawable/ic_image_black_24dp"
|
||||
app:failureImage="@drawable/ic_error_outline_black_24dp" />
|
||||
|
||||
<RelativeLayout
|
||||
android:id="@+id/uploadOverlay"
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue