mirror of
https://github.com/commons-app/apps-android-commons.git
synced 2025-10-26 12:23:58 +01:00
Fix loading of images in contributions list (#2932)
This commit is contained in:
parent
ee3f4d4d30
commit
c004e47c0b
2 changed files with 18 additions and 1 deletions
|
|
@ -6,9 +6,14 @@ import android.widget.LinearLayout;
|
|||
import android.widget.ProgressBar;
|
||||
import android.widget.TextView;
|
||||
|
||||
import androidx.collection.LruCache;
|
||||
|
||||
import com.facebook.drawee.view.SimpleDraweeView;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Named;
|
||||
|
||||
import butterknife.BindView;
|
||||
import butterknife.ButterKnife;
|
||||
|
|
@ -18,6 +23,7 @@ import fr.free.nrw.commons.R;
|
|||
import fr.free.nrw.commons.ViewHolder;
|
||||
import fr.free.nrw.commons.contributions.model.DisplayableContribution;
|
||||
import fr.free.nrw.commons.di.ApplicationlessInjection;
|
||||
import io.reactivex.android.schedulers.AndroidSchedulers;
|
||||
import io.reactivex.disposables.CompositeDisposable;
|
||||
import io.reactivex.disposables.Disposable;
|
||||
import io.reactivex.schedulers.Schedulers;
|
||||
|
|
@ -35,6 +41,10 @@ public class ContributionViewHolder implements ViewHolder<DisplayableContributio
|
|||
@Inject
|
||||
MediaDataExtractor mediaDataExtractor;
|
||||
|
||||
@Inject
|
||||
@Named("thumbnail-cache")
|
||||
LruCache<String, String> thumbnailCache;
|
||||
|
||||
private DisplayableContribution contribution;
|
||||
private CompositeDisposable compositeDisposable = new CompositeDisposable();
|
||||
|
||||
|
|
@ -89,15 +99,21 @@ public class ContributionViewHolder implements ViewHolder<DisplayableContributio
|
|||
|
||||
/**
|
||||
* This method fetches the thumbnail url from file name
|
||||
* If the thumbnail url is present in cache, then it is used otherwise API call is made to fetch the thumbnail
|
||||
* This can be removed once #2904 is in place and contribution contains all metadata beforehand
|
||||
* @param contribution
|
||||
*/
|
||||
private void fetchAndDisplayThumbnail(DisplayableContribution contribution) {
|
||||
if (!StringUtils.isBlank(thumbnailCache.get(contribution.getFilename()))) {
|
||||
imageView.setImageURI(thumbnailCache.get(contribution.getFilename()));
|
||||
return;
|
||||
}
|
||||
Timber.d("Fetching thumbnail for %s", contribution.getFilename());
|
||||
Disposable disposable = mediaDataExtractor.getMediaFromFileName(contribution.getFilename())
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe(media -> {
|
||||
thumbnailCache.put(contribution.getFilename(), media.getThumbUrl());
|
||||
imageView.setImageURI(media.getThumbUrl());
|
||||
});
|
||||
compositeDisposable.add(disposable);
|
||||
|
|
|
|||
|
|
@ -150,6 +150,7 @@ public class CommonsApplicationModule {
|
|||
|
||||
@Provides
|
||||
@Singleton
|
||||
@Named("thumbnail-cache")
|
||||
public LruCache<String, String> provideLruCache() {
|
||||
return new LruCache<>(1024);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue