1
0
mirror of https://github.com/KokaKiwi/BarInsta synced 2024-11-14 10:47:30 +00:00

remove TopicalExploreRequest

This commit is contained in:
Austin Huang 2021-07-25 16:34:05 -04:00
parent b8060d5bcf
commit 6e27427880
No known key found for this signature in database
GPG Key ID: 84C23AA04587A91F
3 changed files with 9 additions and 318 deletions

View File

@ -16,17 +16,16 @@ import awais.instagrabber.webservices.ServiceCallback;
public class DiscoverPostFetchService implements PostFetcher.PostFetchService {
private static final String TAG = "DiscoverPostFetchService";
private final DiscoverService discoverService;
private final DiscoverService.TopicalExploreRequest topicalExploreRequest;
private String maxId;
private boolean moreAvailable = false;
public DiscoverPostFetchService(final DiscoverService.TopicalExploreRequest topicalExploreRequest) {
this.topicalExploreRequest = topicalExploreRequest;
public DiscoverPostFetchService() {
discoverService = DiscoverService.getInstance();
}
@Override
public void fetch(final FetchListener<List<Media>> fetchListener) {
discoverService.topicalExplore(topicalExploreRequest, new ServiceCallback<TopicalExploreFeedResponse>() {
discoverService.topicalExplore(maxId, new ServiceCallback<TopicalExploreFeedResponse>() {
@Override
public void onSuccess(final TopicalExploreFeedResponse result) {
if (result == null) {
@ -34,7 +33,7 @@ public class DiscoverPostFetchService implements PostFetcher.PostFetchService {
return;
}
moreAvailable = result.getMoreAvailable();
topicalExploreRequest.setMaxId(result.getNextMaxId());
maxId = result.getNextMaxId();
final List<WrappedMedia> items = result.getItems();
final List<Media> posts;
if (items == null) {
@ -61,7 +60,7 @@ public class DiscoverPostFetchService implements PostFetcher.PostFetchService {
@Override
public void reset() {
topicalExploreRequest.setMaxId(null);
maxId = null;
}
@Override

View File

@ -272,7 +272,7 @@ public class DiscoverFragment extends Fragment implements SwipeRefreshLayout.OnR
private void setupPosts() {
binding.posts.setViewModelStoreOwner(this)
.setLifeCycleOwner(this)
.setPostFetchService(new DiscoverPostFetchService(new DiscoverService.TopicalExploreRequest()))
.setPostFetchService(new DiscoverPostFetchService())
.setLayoutPreferences(layoutPreferences)
.addFetchStatusChangeListener(fetching -> updateSwipeRefreshState())
.setFeedItemCallback(feedItemCallback)

View File

@ -34,18 +34,12 @@ public class DiscoverService {
return instance;
}
public void topicalExplore(@NonNull final TopicalExploreRequest request,
public void topicalExplore(final String maxId,
final ServiceCallback<TopicalExploreFeedResponse> callback) {
final ImmutableMap.Builder<String, String> builder = ImmutableMap.<String, String>builder()
.put("module", "explore_popular");
if (!TextUtils.isEmpty(request.getModule())) {
builder.put("module", request.getModule());
}
if (!TextUtils.isEmpty(request.getClusterId())) {
builder.put("cluster_id", request.getClusterId());
}
if (!TextUtils.isEmpty(request.getMaxId())) {
builder.put("max_id", request.getMaxId());
if (!TextUtils.isEmpty(maxId)) {
builder.put("max_id", maxId);
}
final Call<TopicalExploreFeedResponse> req = repository.topicalExplore(builder.build());
req.enqueue(new Callback<TopicalExploreFeedResponse>() {
@ -59,11 +53,6 @@ public class DiscoverService {
return;
}
callback.onSuccess(feedResponse);
// try {
// } catch (JSONException e) {
// callback.onFailure(e);
// // Log.e(TAG, "Error parsing topicalExplore response", e);
// }
}
@Override
@ -72,301 +61,4 @@ public class DiscoverService {
}
});
}
// private TopicalExploreResponse parseTopicalExploreResponse(@NonNull final String body) throws JSONException {
// final JSONObject root = new JSONObject(body);
// final boolean moreAvailable = root.optBoolean("more_available");
// final int nextMaxId = root.optInt("next_max_id", -1);
// final int numResults = root.optInt("num_results");
// final String status = root.optString("status");
// final JSONArray clustersJson = root.optJSONArray("clusters");
// final List<TopicCluster> clusters = parseClusters(clustersJson);
// final JSONArray itemsJson = root.optJSONArray("items");
// final List<FeedModel> items = parseItems(itemsJson);
// return new TopicalExploreResponse(
// moreAvailable,
// nextMaxId,
// numResults,
// status,
// clusters,
// items
// );
// }
// private List<TopicCluster> parseClusters(final JSONArray clustersJson) throws JSONException {
// if (clustersJson == null) {
// return Collections.emptyList();
// }
// final List<TopicCluster> clusters = new ArrayList<>();
// for (int i = 0; i < clustersJson.length(); i++) {
// final JSONObject clusterJson = clustersJson.getJSONObject(i);
// final String id = clusterJson.optString("id");
// final String title = clusterJson.optString("title");
// if (TextUtils.isEmpty(id) || TextUtils.isEmpty(title)) {
// continue;
// }
// final String type = clusterJson.optString("type");
// final boolean canMute = clusterJson.optBoolean("can_mute");
// final boolean getMuted = clusterJson.optBoolean("is_muted");
// final JSONObject coverMediaJson = clusterJson.optJSONObject("cover_media");
// final int rankedPosition = clusterJson.optInt("ranked_position");
// final FeedModel feedModel = parseClusterCover(coverMediaJson);
// final TopicCluster topicCluster = new TopicCluster(
// id,
// title,
// type,
// canMute,
// getMuted,
// rankedPosition,
// feedModel
// );
// clusters.add(topicCluster);
// }
// return clusters;
// }
// private FeedModel parseClusterCover(final JSONObject coverMediaJson) throws JSONException {
// if (coverMediaJson == null) {
// return null;
// }
// ProfileModel profileModel = null;
// if (coverMediaJson.has("user")) {
// final JSONObject user = coverMediaJson.getJSONObject("user");
// profileModel = new ProfileModel(
// user.optBoolean("is_private"),
// false,
// user.optBoolean("is_verified"),
// user.getString("pk"),
// user.getString(Constants.EXTRAS_USERNAME),
// user.optString("full_name"),
// null,
// null,
// user.getString("profile_pic_url"),
// null,
// 0,
// 0,
// 0,
// false,
// false,
// false,
// false,
// false);
// }
// final String resourceUrl = ResponseBodyUtils.getHighQualityImage(coverMediaJson);
// final String thumbnailUrl = ResponseBodyUtils.getLowQualityImage(coverMediaJson);
// final int width = coverMediaJson.optInt("original_width");
// final int height = coverMediaJson.optInt("original_height");
// return new FeedModel.Builder()
// .setProfileModel(profileModel)
// .setItemType(MediaItemType.MEDIA_TYPE_IMAGE)
// .setViewCount(0)
// .setPostId(coverMediaJson.getString(Constants.EXTRAS_ID))
// .setDisplayUrl(resourceUrl)
// .setThumbnailUrl(thumbnailUrl)
// .setShortCode(coverMediaJson.getString("code"))
// .setPostCaption(null)
// .setCommentsCount(0)
// .setTimestamp(coverMediaJson.optLong("taken_at", -1))
// .setLiked(false)
// .setBookmarked(false)
// .setLikesCount(0)
// .setLocationName(null)
// .setLocationId(null)
// .setImageHeight(height)
// .setImageWidth(width)
// .build();
// }
// private List<FeedModel> parseItems(final JSONArray items) throws JSONException {
// if (items == null) {
// return Collections.emptyList();
// }
// final List<FeedModel> feedModels = new ArrayList<>();
// for (int i = 0; i < items.length(); i++) {
// final JSONObject itemJson = items.optJSONObject(i);
// if (itemJson == null) {
// continue;
// }
// final JSONObject mediaJson = itemJson.optJSONObject("media");
// final FeedModel feedModel = ResponseBodyUtils.parseItem(mediaJson);
// if (feedModel != null) {
// feedModels.add(feedModel);
// }
// }
// return feedModels;
// }
public static class TopicalExploreRequest {
private String module;
private String clusterId;
private String maxId;
public TopicalExploreRequest() {}
public TopicalExploreRequest(final String module, final String clusterId, final String maxId) {
this.module = module;
this.clusterId = clusterId;
this.maxId = maxId;
}
public String getModule() {
return module;
}
public TopicalExploreRequest setModule(final String module) {
this.module = module;
return this;
}
public String getClusterId() {
return clusterId;
}
public void setClusterId(final String clusterId) {
this.clusterId = clusterId;
}
public String getMaxId() {
return maxId;
}
public void setMaxId(final String maxId) {
this.maxId = maxId;
}
@Override
public boolean equals(final Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
final TopicalExploreRequest that = (TopicalExploreRequest) o;
return maxId.equals(that.maxId) &&
Objects.equals(module, that.module) &&
Objects.equals(clusterId, that.clusterId);
}
@Override
public int hashCode() {
return Objects.hash(module, clusterId, maxId);
}
@NonNull
@Override
public String toString() {
return "TopicalExploreRequest{" +
"module='" + module + '\'' +
", clusterId='" + clusterId + '\'' +
", maxId=" + maxId +
'}';
}
}
// public static class TopicalExploreResponse {
//
// private boolean moreAvailable;
// private int nextMaxId;
// private int numResults;
// private String status;
// private List<TopicCluster> clusters;
// private List<FeedModel> items;
//
// public TopicalExploreResponse() {}
//
// public TopicalExploreResponse(final boolean moreAvailable,
// final int nextMaxId,
// final int numResults,
// final String status,
// final List<TopicCluster> clusters, final List<FeedModel> items) {
// this.moreAvailable = moreAvailable;
// this.nextMaxId = nextMaxId;
// this.numResults = numResults;
// this.status = status;
// this.clusters = clusters;
// this.items = items;
// }
//
// public boolean isMoreAvailable() {
// return moreAvailable;
// }
//
// public TopicalExploreResponse setMoreAvailable(final boolean moreAvailable) {
// this.moreAvailable = moreAvailable;
// return this;
// }
//
// public int getNextMaxId() {
// return nextMaxId;
// }
//
// public TopicalExploreResponse setNextMaxId(final int nextMaxId) {
// this.nextMaxId = nextMaxId;
// return this;
// }
//
// public int getNumResults() {
// return numResults;
// }
//
// public TopicalExploreResponse setNumResults(final int numResults) {
// this.numResults = numResults;
// return this;
// }
//
// public String getStatus() {
// return status;
// }
//
// public TopicalExploreResponse setStatus(final String status) {
// this.status = status;
// return this;
// }
//
// public List<TopicCluster> getClusters() {
// return clusters;
// }
//
// public TopicalExploreResponse setClusters(final List<TopicCluster> clusters) {
// this.clusters = clusters;
// return this;
// }
//
// public List<FeedModel> getItems() {
// return items;
// }
//
// public TopicalExploreResponse setItems(final List<FeedModel> items) {
// this.items = items;
// return this;
// }
//
// @Override
// public boolean equals(final Object o) {
// if (this == o) return true;
// if (o == null || getClass() != o.getClass()) return false;
// final TopicalExploreResponse that = (TopicalExploreResponse) o;
// return moreAvailable == that.moreAvailable &&
// nextMaxId == that.nextMaxId &&
// numResults == that.numResults &&
// Objects.equals(status, that.status) &&
// Objects.equals(clusters, that.clusters) &&
// Objects.equals(items, that.items);
// }
//
// @Override
// public int hashCode() {
// return Objects.hash(moreAvailable, nextMaxId, numResults, status, clusters, items);
// }
//
// @Override
// public String toString() {
// return "TopicalExploreResponse{" +
// "moreAvailable=" + moreAvailable +
// ", nextMaxId=" + nextMaxId +
// ", numResults=" + numResults +
// ", status='" + status + '\'' +
// ", clusters=" + clusters +
// ", items=" + items +
// '}';
// }
// }
}