From a37bb2d1852d4cc968fd27c772b9e693962cb5bd Mon Sep 17 00:00:00 2001 From: Austin Huang Date: Fri, 5 Mar 2021 10:50:10 -0500 Subject: [PATCH] implement profile context (backend) --- .../instagrabber/asyncs/CommentsFetcher.java | 6 +- .../fragments/main/ProfileFragment.java | 28 ++++++++- .../repositories/responses/User.java | 57 +++++-------------- .../responses/UserProfileContextLink.java | 21 +++++++ .../instagrabber/utils/ResponseBodyUtils.java | 2 +- .../webservices/GraphQLService.java | 4 ++ .../webservices/StoriesService.java | 4 ++ 7 files changed, 75 insertions(+), 47 deletions(-) create mode 100644 app/src/main/java/awais/instagrabber/repositories/responses/UserProfileContextLink.java diff --git a/app/src/main/java/awais/instagrabber/asyncs/CommentsFetcher.java b/app/src/main/java/awais/instagrabber/asyncs/CommentsFetcher.java index 6b9929c5..b5ba3d27 100755 --- a/app/src/main/java/awais/instagrabber/asyncs/CommentsFetcher.java +++ b/app/src/main/java/awais/instagrabber/asyncs/CommentsFetcher.java @@ -115,7 +115,7 @@ public final class CommentsFetcher extends AsyncTask { final NavController navController = NavHostFragment.findNavController(this); @@ -757,6 +762,27 @@ public class ProfileFragment extends Fragment implements SwipeRefreshLayout.OnRe return true; }); } + + String profileContext = profileModel.getProfileContext(); + if (TextUtils.isEmpty(profileContext)) { + profileDetailsBinding.profileContext.setVisibility(View.GONE); + } + else { + profileDetailsBinding.profileContext.setVisibility(View.VISIBLE); + final List userProfileContextLinks = profileModel.getProfileContextLinks(); + for (int i = 0; i < userProfileContextLinks.size(); i++) { + final UserProfileContextLink link = userProfileContextLinks.get(i); + if (link.getUsername() != null) + profileContext = profileContext.substring(0, link.getStart() + i) + + "@" + profileContext.substring(link.getStart() + i); + } + profileDetailsBinding.profileContext.setText(profileContext); + profileDetailsBinding.profileContext.addOnMentionClickListener(autoLinkItem -> { + final String originalText = autoLinkItem.getOriginalText().trim(); + navigateToProfile(originalText); + }); + } + final String url = profileModel.getExternalUrl(); if (TextUtils.isEmpty(url)) { profileDetailsBinding.mainUrl.setVisibility(View.GONE); diff --git a/app/src/main/java/awais/instagrabber/repositories/responses/User.java b/app/src/main/java/awais/instagrabber/repositories/responses/User.java index efae4dbf..12f23fdd 100644 --- a/app/src/main/java/awais/instagrabber/repositories/responses/User.java +++ b/app/src/main/java/awais/instagrabber/repositories/responses/User.java @@ -1,6 +1,7 @@ package awais.instagrabber.repositories.responses; import java.io.Serializable; +import java.util.List; import java.util.Objects; public class User implements Serializable { @@ -27,7 +28,8 @@ public class User implements Serializable { private final long usertagsCount; private final String publicEmail; private final HdProfilePicUrlInfo hdProfilePicUrlInfo; - + private final String profileContext; + private final List profileContextLinksWithUserIds; public User(final long pk, final String username, @@ -51,7 +53,9 @@ public class User implements Serializable { final String externalUrl, final long usertagsCount, final String publicEmail, - final HdProfilePicUrlInfo hdProfilePicUrlInfo) { + final HdProfilePicUrlInfo hdProfilePicUrlInfo, + final String profileContext, + final List profileContextLinksWithUserIds) { this.pk = pk; this.username = username; this.fullName = fullName; @@ -75,6 +79,8 @@ public class User implements Serializable { this.usertagsCount = usertagsCount; this.publicEmail = publicEmail; this.hdProfilePicUrlInfo = hdProfilePicUrlInfo; + this.profileContext = profileContext; + this.profileContextLinksWithUserIds = profileContextLinksWithUserIds; } public long getPk() { @@ -173,46 +179,13 @@ public class User implements Serializable { return publicEmail; } - // public boolean isReallyPrivate() { - // final FriendshipStatus friendshipStatus = getFriendshipStatus(); - // !user.optBoolean("followed_by_viewer") && (id != uid && isPrivate) - // } - - // public static User fromProfileModel(final ProfileModel profileModel) { - // return new User( - // Long.parseLong(profileModel.getId()), - // profileModel.getUsername(), - // profileModel.getName(), - // profileModel.isPrivate(), - // profileModel.getSdProfilePic(), - // null, - // new FriendshipStatus( - // profileModel.isFollowing(), - // false, - // profileModel.isBlocked(), - // false, - // profileModel.isPrivate(), - // false, - // profileModel.isRequested(), - // false, - // profileModel.isRestricted(), - // false), - // profileModel.isVerified(), - // false, - // false, - // false, - // false, - // null, - // null, - // profileModel.getPostCount(), - // profileModel.getFollowersCount(), - // profileModel.getFollowingCount(), - // 0, - // profileModel.getBiography(), - // profileModel.getUrl(), - // 0, - // null); - // } + public String getProfileContext() { + return profileContext; + } + + public List getProfileContextLinks() { + return profileContextLinksWithUserIds; + } @Override public boolean equals(final Object o) { diff --git a/app/src/main/java/awais/instagrabber/repositories/responses/UserProfileContextLink.java b/app/src/main/java/awais/instagrabber/repositories/responses/UserProfileContextLink.java new file mode 100644 index 00000000..7beb954d --- /dev/null +++ b/app/src/main/java/awais/instagrabber/repositories/responses/UserProfileContextLink.java @@ -0,0 +1,21 @@ +package awais.instagrabber.repositories.responses; + +public class UserProfileContextLink { + private final String username; + private final int start; + private final int end; + + public UserProfileContextLink(final String username, final int start, final int end) { + this.username = username; + this.start = start; + this.end = end; + } + + public String getUsername() { + return username; + } + + public int getStart() { + return start; + } +} diff --git a/app/src/main/java/awais/instagrabber/utils/ResponseBodyUtils.java b/app/src/main/java/awais/instagrabber/utils/ResponseBodyUtils.java index 43b24637..30d5ed21 100644 --- a/app/src/main/java/awais/instagrabber/utils/ResponseBodyUtils.java +++ b/app/src/main/java/awais/instagrabber/utils/ResponseBodyUtils.java @@ -782,7 +782,7 @@ public final class ResponseBodyUtils { null, friendshipStatus, owner.optBoolean("is_verified"), - false, false, false, false, null, null, 0, 0, 0, 0, null, null, 0, null, null); + false, false, false, false, null, null, 0, 0, 0, 0, null, null, 0, null, null, null, null); } final String id = feedItem.getString(Constants.EXTRAS_ID); final ImageVersions2 imageVersions2 = new ImageVersions2( diff --git a/app/src/main/java/awais/instagrabber/webservices/GraphQLService.java b/app/src/main/java/awais/instagrabber/webservices/GraphQLService.java index 74044d29..aa6a29bd 100644 --- a/app/src/main/java/awais/instagrabber/webservices/GraphQLService.java +++ b/app/src/main/java/awais/instagrabber/webservices/GraphQLService.java @@ -243,6 +243,8 @@ public class GraphQLService extends BaseService { null, 0, null, + null, + null, null )); // userModels.add(new ProfileModel(userObject.optBoolean("is_private"), @@ -334,6 +336,8 @@ public class GraphQLService extends BaseService { url, 0, null, + null, + null, null)); } catch (JSONException e) { Log.e(TAG, "onResponse", e); diff --git a/app/src/main/java/awais/instagrabber/webservices/StoriesService.java b/app/src/main/java/awais/instagrabber/webservices/StoriesService.java index 3f84226c..faf00f6c 100644 --- a/app/src/main/java/awais/instagrabber/webservices/StoriesService.java +++ b/app/src/main/java/awais/instagrabber/webservices/StoriesService.java @@ -172,6 +172,8 @@ public class StoriesService extends BaseService { null, 0, null, + null, + null, null ); final String id = node.getString("id"); @@ -231,6 +233,8 @@ public class StoriesService extends BaseService { null, 0, null, + null, + null, null ); final String id = node.getString("id");