From a6c912c5d53c9c5eb7a92cee3c990c88c4cf38ea Mon Sep 17 00:00:00 2001 From: Austin Huang Date: Sun, 30 Aug 2020 10:06:15 -0400 Subject: [PATCH] post location optimizations --- .../awais/instagrabber/activities/PostViewer.java | 12 ++++++------ .../java/awais/instagrabber/asyncs/FeedFetcher.java | 5 ++++- .../java/awais/instagrabber/asyncs/PostFetcher.java | 10 ++++++++-- .../awais/instagrabber/asyncs/i/iPostFetcher.java | 10 ++++++++-- .../awais/instagrabber/models/ViewerPostModel.java | 12 ++++++++---- app/src/main/res/layout/item_feed_top.xml | 2 +- 6 files changed, 35 insertions(+), 16 deletions(-) diff --git a/app/src/main/java/awais/instagrabber/activities/PostViewer.java b/app/src/main/java/awais/instagrabber/activities/PostViewer.java index 0079c93a..b46c765b 100755 --- a/app/src/main/java/awais/instagrabber/activities/PostViewer.java +++ b/app/src/main/java/awais/instagrabber/activities/PostViewer.java @@ -242,7 +242,7 @@ public final class PostViewer extends BaseLanguageActivity { } setupPostInfoBar("@"+viewerPostModel.getUsername(), viewerPostModel.getItemType(), - viewerPostModel.getLocation()); + viewerPostModel.getLocationName(), viewerPostModel.getLocation()); postCaption = postModel.getPostCaption(); viewerCaptionParent.setVisibility(View.VISIBLE); @@ -302,7 +302,7 @@ public final class PostViewer extends BaseLanguageActivity { final boolean postIdNull = postModel.getPostId() == null; if (!postIdNull) - setupPostInfoBar(intent.getStringExtra(Constants.EXTRAS_USER), postModel.getItemType(), null); + setupPostInfoBar(intent.getStringExtra(Constants.EXTRAS_USER), postModel.getItemType(), null, null); isFromShare = postModel.getPosition() == -1 || postIdNull; @@ -586,7 +586,7 @@ public final class PostViewer extends BaseLanguageActivity { } setupPostInfoBar("@"+viewerPostModel.getUsername(), viewerPostModel.getItemType(), - viewerPostModel.getLocation()); + viewerPostModel.getLocationName(), viewerPostModel.getLocation()); if (postModel instanceof PostModel) { final PostModel postModel = (PostModel) this.postModel; @@ -636,7 +636,7 @@ public final class PostViewer extends BaseLanguageActivity { } } - private void setupPostInfoBar(final String from, final MediaItemType mediaItemType, final JSONObject location) { + private void setupPostInfoBar(final String from, final MediaItemType mediaItemType, final String locationName, final String location) { if (prevUsername == null || !prevUsername.equals(from)) { viewerBinding.topPanel.ivProfilePic.setImageBitmap(null); viewerBinding.topPanel.ivProfilePic.setImageDrawable(null); @@ -712,8 +712,8 @@ public final class PostViewer extends BaseLanguageActivity { } else { viewerBinding.topPanel.location.setVisibility(View.VISIBLE); - viewerBinding.topPanel.location.setText(location.optString("name")); - viewerBinding.topPanel.location.setOnClickListener(v -> searchUsername(location.optString("id")+"/"+location.optString("slug"))); + viewerBinding.topPanel.location.setText(locationName); + viewerBinding.topPanel.location.setOnClickListener(v -> searchUsername(location)); viewerBinding.topPanel.title.setLayoutParams(new RelativeLayout.LayoutParams( RelativeLayout.LayoutParams.MATCH_PARENT, RelativeLayout.LayoutParams.WRAP_CONTENT )); diff --git a/app/src/main/java/awais/instagrabber/asyncs/FeedFetcher.java b/app/src/main/java/awais/instagrabber/asyncs/FeedFetcher.java index 793d3574..b70fccea 100755 --- a/app/src/main/java/awais/instagrabber/asyncs/FeedFetcher.java +++ b/app/src/main/java/awais/instagrabber/asyncs/FeedFetcher.java @@ -158,7 +158,10 @@ public final class FeedFetcher extends AsyncTask { null, null, null, node.optLong("video_view_count", -1), -1, false, false, feedItem.getJSONObject("edge_media_preview_like").getLong("count"), - feedItem.optJSONObject("location")); + feedItem.isNull("location") ? null : feedItem.getJSONObject("location").optString("name"), + feedItem.isNull("location") ? null : + (feedItem.getJSONObject("location").optString("id") + "/" + + feedItem.getJSONObject("location").optString("slug"))); sliderItems[j].setSliderDisplayUrl(node.getString("display_url")); } diff --git a/app/src/main/java/awais/instagrabber/asyncs/PostFetcher.java b/app/src/main/java/awais/instagrabber/asyncs/PostFetcher.java index 528f2a76..38a6e0b0 100755 --- a/app/src/main/java/awais/instagrabber/asyncs/PostFetcher.java +++ b/app/src/main/java/awais/instagrabber/asyncs/PostFetcher.java @@ -95,7 +95,10 @@ public final class PostFetcher extends AsyncTask isVideo && media.has("video_view_count") ? media.getLong("video_view_count") : -1, timestamp, media.getBoolean("viewer_has_liked"), media.getBoolean("viewer_has_saved"), media.getJSONObject("edge_media_preview_like").getLong("count"), - media.optJSONObject("location")); + media.isNull("location") ? null : media.getJSONObject("location").optString("name"), + media.isNull("location") ? null : + (media.getJSONObject("location").optString("id") + "/" + + media.getJSONObject("location").optString("slug"))); postModel.setCommentsCount(commentsCount); @@ -120,7 +123,10 @@ public final class PostFetcher extends AsyncTask isChildVideo && node.has("video_view_count") ? node.getLong("video_view_count") : -1, timestamp, media.getBoolean("viewer_has_liked"), media.getBoolean("viewer_has_saved"), media.getJSONObject("edge_media_preview_like").getLong("count"), - media.optJSONObject("location")); + media.isNull("location") ? null : media.getJSONObject("location").optString("name"), + media.isNull("location") ? null : + (media.getJSONObject("location").optString("id") + "/" + + media.getJSONObject("location").optString("slug"))); postModels[i].setSliderDisplayUrl(node.getString("display_url")); Utils.checkExistence(downloadDir, customDir, true, postModels[i]); diff --git a/app/src/main/java/awais/instagrabber/asyncs/i/iPostFetcher.java b/app/src/main/java/awais/instagrabber/asyncs/i/iPostFetcher.java index 3e6330d7..a2d4c4a2 100755 --- a/app/src/main/java/awais/instagrabber/asyncs/i/iPostFetcher.java +++ b/app/src/main/java/awais/instagrabber/asyncs/i/iPostFetcher.java @@ -87,7 +87,10 @@ public final class iPostFetcher extends AsyncTask isVideo && media.has("view_count") ? media.getLong("view_count") : -1, timestamp, media.optBoolean("has_liked"), media.optBoolean("has_viewer_saved"), media.getLong("like_count"), - media.optJSONObject("location")); + media.isNull("location") ? null : media.getJSONObject("location").optString("name"), + media.isNull("location") ? null : + (media.getJSONObject("location").optString("id") + "/" + + media.getJSONObject("location").optString("slug"))); postModel.setCommentsCount(commentsCount); @@ -114,7 +117,10 @@ public final class iPostFetcher extends AsyncTask -1, timestamp, media.optBoolean("has_liked"), media.optBoolean("has_viewer_saved"), media.getLong("like_count"), - media.optJSONObject("location")); + media.isNull("location") ? null : media.getJSONObject("location").optString("name"), + media.isNull("location") ? null : + (media.getJSONObject("location").optString("id") + "/" + + media.getJSONObject("location").optString("slug"))); postModels[i].setSliderDisplayUrl(Utils.getHighQualityImage(node)); Utils.checkExistence(downloadDir, customDir, true, postModels[i]); diff --git a/app/src/main/java/awais/instagrabber/models/ViewerPostModel.java b/app/src/main/java/awais/instagrabber/models/ViewerPostModel.java index e4c1ec0d..fdc062e4 100755 --- a/app/src/main/java/awais/instagrabber/models/ViewerPostModel.java +++ b/app/src/main/java/awais/instagrabber/models/ViewerPostModel.java @@ -5,8 +5,7 @@ import org.json.JSONObject; import awais.instagrabber.models.enums.MediaItemType; public final class ViewerPostModel extends BasePostModel { - protected final String username; - protected final JSONObject location; + protected final String username, locationName, location; protected final long videoViews; protected String sliderDisplayUrl; protected long commentsCount, likes; @@ -14,7 +13,7 @@ public final class ViewerPostModel extends BasePostModel { public ViewerPostModel(final MediaItemType itemType, final String postId, final String displayUrl, final String shortCode, final String postCaption, final String username, final long videoViews, final long timestamp, - boolean liked, boolean bookmarked, long likes, final JSONObject location) { + boolean liked, boolean bookmarked, long likes, final String locationName, final String location) { this.itemType = itemType; this.postId = postId; this.displayUrl = displayUrl; @@ -26,6 +25,7 @@ public final class ViewerPostModel extends BasePostModel { this.liked = liked; this.likes = likes; this.bookmarked = bookmarked; + this.locationName = locationName; this.location = location; } @@ -41,7 +41,11 @@ public final class ViewerPostModel extends BasePostModel { return username; } - public JSONObject getLocation() { + public String getLocationName() { + return locationName; + } + + public String getLocation() { return location; } diff --git a/app/src/main/res/layout/item_feed_top.xml b/app/src/main/res/layout/item_feed_top.xml index 78dab810..31b688a5 100755 --- a/app/src/main/res/layout/item_feed_top.xml +++ b/app/src/main/res/layout/item_feed_top.xml @@ -44,7 +44,7 @@ android:layout_weight="1" android:gravity="center_vertical" android:textColor="@color/feed_text_primary_color" - android:textSize="18sp" /> + android:textSize="15sp" />