mirror of
https://github.com/commons-app/apps-android-commons.git
synced 2025-11-03 08:13:55 +01:00
With lazy loading of contributions (#3566)
This commit is contained in:
parent
c216fdf0d4
commit
d863a404f1
34 changed files with 1397 additions and 928 deletions
|
|
@ -32,6 +32,7 @@ public class MediaClient {
|
|||
|
||||
//OkHttpJsonApiClient used JsonKvStore for this. I don't know why.
|
||||
private Map<String, Map<String, String>> continuationStore;
|
||||
private Map<String, Boolean> continuationExists;
|
||||
public static final String NO_CAPTION = "No caption";
|
||||
private static final String NO_DEPICTION = "No depiction";
|
||||
|
||||
|
|
@ -40,6 +41,7 @@ public class MediaClient {
|
|||
this.mediaInterface = mediaInterface;
|
||||
this.mediaDetailInterface = mediaDetailInterface;
|
||||
this.continuationStore = new HashMap<>();
|
||||
this.continuationExists = new HashMap<>();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -83,6 +85,36 @@ public class MediaClient {
|
|||
|
||||
}
|
||||
|
||||
/**
|
||||
* This method takes the userName as input and returns a list of Media objects filtered using
|
||||
* allimages query It uses the allimages query API to get the images contributed by the userName,
|
||||
* 10 at a time.
|
||||
*
|
||||
* @param userName the username
|
||||
* @return
|
||||
*/
|
||||
public Single<List<Media>> getMediaListForUser(String userName) {
|
||||
Map<String, String> continuation =
|
||||
continuationStore.containsKey("user_" + userName)
|
||||
? continuationStore.get("user_" + userName)
|
||||
: Collections.emptyMap();
|
||||
return responseToMediaList(mediaInterface
|
||||
.getMediaListForUser(userName, 10, continuation), "user_" + userName);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if media for user has reached the end of the list.
|
||||
* @param userName
|
||||
* @return
|
||||
*/
|
||||
public boolean doesMediaListForUserHaveMorePages(String userName) {
|
||||
final String key = "user_" + userName;
|
||||
if(continuationExists.containsKey(key)) {
|
||||
return continuationExists.get(key);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method takes a keyword as input and returns a list of Media objects filtered using image generator query
|
||||
* It uses the generator query API to get the images searched using a query, 10 at a time.
|
||||
|
|
@ -106,7 +138,12 @@ public class MediaClient {
|
|||
|| null == mwQueryResponse.query().pages()) {
|
||||
return Observable.empty();
|
||||
}
|
||||
continuationStore.put(key, mwQueryResponse.continuation());
|
||||
if(mwQueryResponse.continuation() != null) {
|
||||
continuationStore.put(key, mwQueryResponse.continuation());
|
||||
continuationExists.put(key, true);
|
||||
} else {
|
||||
continuationExists.put(key, false);
|
||||
}
|
||||
return Observable.fromIterable(mwQueryResponse.query().pages());
|
||||
})
|
||||
.map(Media::from)
|
||||
|
|
|
|||
|
|
@ -23,26 +23,21 @@ import butterknife.ButterKnife;
|
|||
import com.google.android.material.snackbar.Snackbar;
|
||||
import fr.free.nrw.commons.Media;
|
||||
import fr.free.nrw.commons.R;
|
||||
import fr.free.nrw.commons.auth.SessionManager;
|
||||
import fr.free.nrw.commons.bookmarks.Bookmark;
|
||||
import fr.free.nrw.commons.bookmarks.pictures.BookmarkPicturesContentProvider;
|
||||
import fr.free.nrw.commons.bookmarks.pictures.BookmarkPicturesDao;
|
||||
import fr.free.nrw.commons.category.CategoryImagesCallback;
|
||||
import fr.free.nrw.commons.contributions.Contribution;
|
||||
import fr.free.nrw.commons.di.CommonsDaggerSupportFragment;
|
||||
import fr.free.nrw.commons.kvstore.JsonKvStore;
|
||||
import fr.free.nrw.commons.utils.DownloadUtils;
|
||||
import fr.free.nrw.commons.utils.ImageUtils;
|
||||
import fr.free.nrw.commons.utils.NetworkUtils;
|
||||
import fr.free.nrw.commons.utils.ViewUtil;
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Named;
|
||||
import timber.log.Timber;
|
||||
|
||||
public class MediaDetailPagerFragment extends CommonsDaggerSupportFragment implements ViewPager.OnPageChangeListener {
|
||||
|
||||
@Inject SessionManager sessionManager;
|
||||
@Inject @Named("default_preferences") JsonKvStore store;
|
||||
@Inject BookmarkPicturesDao bookmarkDao;
|
||||
|
||||
@BindView(R.id.mediaDetailsPager) ViewPager pager;
|
||||
|
|
|
|||
|
|
@ -1,11 +1,9 @@
|
|||
package fr.free.nrw.commons.media;
|
||||
|
||||
import org.wikipedia.dataclient.mwapi.MwQueryResponse;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import fr.free.nrw.commons.depictions.models.DepictionResponse;
|
||||
import io.reactivex.Observable;
|
||||
import java.util.Map;
|
||||
import org.wikipedia.dataclient.mwapi.MwQueryResponse;
|
||||
import retrofit2.http.GET;
|
||||
import retrofit2.http.Query;
|
||||
import retrofit2.http.QueryMap;
|
||||
|
|
@ -17,6 +15,7 @@ public interface MediaInterface {
|
|||
String MEDIA_PARAMS="&prop=imageinfo&iiprop=url|extmetadata&iiurlwidth=640" +
|
||||
"&iiextmetadatafilter=DateTime|Categories|GPSLatitude|GPSLongitude|ImageDescription|DateTimeOriginal" +
|
||||
"|Artist|LicenseShortName|LicenseUrl";
|
||||
|
||||
/**
|
||||
* Checks if a page exists or not.
|
||||
*
|
||||
|
|
@ -48,6 +47,19 @@ public interface MediaInterface {
|
|||
MEDIA_PARAMS)
|
||||
Observable<MwQueryResponse> getMediaListFromCategory(@Query("gcmtitle") String category, @Query("gcmlimit") int itemLimit, @QueryMap Map<String, String> continuation);
|
||||
|
||||
/**
|
||||
* This method retrieves a list of Media objects for a given user name
|
||||
*
|
||||
* @param username user's Wikimedia Commons username.
|
||||
* @param itemLimit how many images are returned
|
||||
* @param continuation the continuation string from the previous query or empty map
|
||||
* @return
|
||||
*/
|
||||
@GET("w/api.php?action=query&format=json&formatversion=2" + //Basic parameters
|
||||
"&generator=allimages&gaisort=timestamp&gaidir=older" + MEDIA_PARAMS)
|
||||
Observable<MwQueryResponse> getMediaListForUser(@Query("gaiuser") String username,
|
||||
@Query("gailimit") int itemLimit, @QueryMap(encoded = true) Map<String, String> continuation);
|
||||
|
||||
/**
|
||||
* This method retrieves a list of Media objects filtered using image generator query
|
||||
*
|
||||
|
|
@ -86,21 +98,15 @@ public interface MediaInterface {
|
|||
Observable<MwParseResponse> getPageHtml(@Query("page") String title);
|
||||
|
||||
/**
|
||||
* Fetches caption using file name
|
||||
*
|
||||
* @param filename name of the file to be used for fetching captions
|
||||
* */
|
||||
@GET("w/api.php?action=wbgetentities&props=labels&format=json&languagefallback=1")
|
||||
Observable<MwQueryResponse> fetchCaptionByFilename(@Query("language") String language, @Query("titles") String filename);
|
||||
* Fetches list of images from a depiction entity
|
||||
*
|
||||
* @param query depictionEntityId
|
||||
* @param sroffset number od depictions already fetched, this is useful in implementing
|
||||
* pagination
|
||||
*/
|
||||
|
||||
/**
|
||||
* Fetches list of images from a depiction entity
|
||||
*
|
||||
* @param query depictionEntityId
|
||||
* @param sroffset number od depictions already fetched, this is useful in implementing pagination
|
||||
*/
|
||||
|
||||
@GET("w/api.php?action=query&list=search&format=json&srnamespace=6")
|
||||
Observable<DepictionResponse> fetchImagesForDepictedItem(@Query("srsearch") String query, @Query("sroffset") String sroffset);
|
||||
@GET("w/api.php?action=query&list=search&format=json&srnamespace=6")
|
||||
Observable<DepictionResponse> fetchImagesForDepictedItem(@Query("srsearch") String query,
|
||||
@Query("sroffset") String sroffset);
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue