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

implement profile context (backend)

This commit is contained in:
Austin Huang 2021-03-05 10:50:10 -05:00
parent b992456a2c
commit a37bb2d185
No known key found for this signature in database
GPG Key ID: 84C23AA04587A91F
7 changed files with 74 additions and 46 deletions

View File

@ -115,7 +115,7 @@ public final class CommentsFetcher extends AsyncTask<Void, Void, List<CommentMod
owner.getString("profile_pic_url"), owner.getString("profile_pic_url"),
null, null,
new FriendshipStatus(false, false, false, false, false, false, false, false, false, false), new FriendshipStatus(false, false, false, false, false, false, false, false, false, false),
false, false, false, false, false, null, null, 0, 0, 0, 0, null, null, 0, null, null); false, false, false, false, false, null, null, 0, 0, 0, 0, null, null, 0, null, null, null, null);
final JSONObject likedBy = childComment.optJSONObject("edge_liked_by"); final JSONObject likedBy = childComment.optJSONObject("edge_liked_by");
commentModels.add(new CommentModel(childComment.getString(Constants.EXTRAS_ID), commentModels.add(new CommentModel(childComment.getString(Constants.EXTRAS_ID),
childComment.getString("text"), childComment.getString("text"),
@ -193,7 +193,7 @@ public final class CommentsFetcher extends AsyncTask<Void, Void, List<CommentMod
null, null,
new FriendshipStatus(false, false, false, false, false, false, false, false, false, false), new FriendshipStatus(false, false, false, false, false, false, false, false, false, false),
owner.optBoolean("is_verified"), 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 JSONObject likedBy = comment.optJSONObject("edge_liked_by"); final JSONObject likedBy = comment.optJSONObject("edge_liked_by");
final String commentId = comment.getString(Constants.EXTRAS_ID); final String commentId = comment.getString(Constants.EXTRAS_ID);
final CommentModel commentModel = new CommentModel(commentId, final CommentModel commentModel = new CommentModel(commentId,
@ -235,7 +235,7 @@ public final class CommentsFetcher extends AsyncTask<Void, Void, List<CommentMod
null, null,
new FriendshipStatus(false, false, false, false, false, false, false, false, false, false), new FriendshipStatus(false, false, false, false, false, false, false, false, false, false),
tempJsonObject.optBoolean("is_verified"), false, false, false, false, null, null, 0, 0, 0, 0, null, null, 0, tempJsonObject.optBoolean("is_verified"), false, false, false, false, null, null, 0, 0, 0, 0, null, null, 0,
null, null); null, null, null, null);
tempJsonObject = childComment.optJSONObject("edge_liked_by"); tempJsonObject = childComment.optJSONObject("edge_liked_by");
childCommentModels.add(new CommentModel(childComment.getString(Constants.EXTRAS_ID), childCommentModels.add(new CommentModel(childComment.getString(Constants.EXTRAS_ID),

View File

@ -86,6 +86,7 @@ import awais.instagrabber.repositories.responses.FriendshipRestrictResponse;
import awais.instagrabber.repositories.responses.FriendshipStatus; import awais.instagrabber.repositories.responses.FriendshipStatus;
import awais.instagrabber.repositories.responses.Media; import awais.instagrabber.repositories.responses.Media;
import awais.instagrabber.repositories.responses.User; import awais.instagrabber.repositories.responses.User;
import awais.instagrabber.repositories.responses.UserProfileContextLink;
import awais.instagrabber.utils.Constants; import awais.instagrabber.utils.Constants;
import awais.instagrabber.utils.CookieUtils; import awais.instagrabber.utils.CookieUtils;
import awais.instagrabber.utils.DownloadUtils; import awais.instagrabber.utils.DownloadUtils;
@ -692,7 +693,11 @@ public class ProfileFragment extends Fragment implements SwipeRefreshLayout.OnRe
: profileModel.getFullName()); : profileModel.getFullName());
final String biography = profileModel.getBiography(); final String biography = profileModel.getBiography();
if (!TextUtils.isEmpty(biography)) { if (TextUtils.isEmpty(biography)) {
profileDetailsBinding.mainBiography.setVisibility(View.GONE);
}
else {
profileDetailsBinding.mainBiography.setVisibility(View.VISIBLE);
profileDetailsBinding.mainBiography.setText(biography); profileDetailsBinding.mainBiography.setText(biography);
profileDetailsBinding.mainBiography.addOnHashtagListener(autoLinkItem -> { profileDetailsBinding.mainBiography.addOnHashtagListener(autoLinkItem -> {
final NavController navController = NavHostFragment.findNavController(this); final NavController navController = NavHostFragment.findNavController(this);
@ -757,6 +762,27 @@ public class ProfileFragment extends Fragment implements SwipeRefreshLayout.OnRe
return true; return true;
}); });
} }
String profileContext = profileModel.getProfileContext();
if (TextUtils.isEmpty(profileContext)) {
profileDetailsBinding.profileContext.setVisibility(View.GONE);
}
else {
profileDetailsBinding.profileContext.setVisibility(View.VISIBLE);
final List<UserProfileContextLink> 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(); final String url = profileModel.getExternalUrl();
if (TextUtils.isEmpty(url)) { if (TextUtils.isEmpty(url)) {
profileDetailsBinding.mainUrl.setVisibility(View.GONE); profileDetailsBinding.mainUrl.setVisibility(View.GONE);

View File

@ -1,6 +1,7 @@
package awais.instagrabber.repositories.responses; package awais.instagrabber.repositories.responses;
import java.io.Serializable; import java.io.Serializable;
import java.util.List;
import java.util.Objects; import java.util.Objects;
public class User implements Serializable { public class User implements Serializable {
@ -27,7 +28,8 @@ public class User implements Serializable {
private final long usertagsCount; private final long usertagsCount;
private final String publicEmail; private final String publicEmail;
private final HdProfilePicUrlInfo hdProfilePicUrlInfo; private final HdProfilePicUrlInfo hdProfilePicUrlInfo;
private final String profileContext;
private final List<UserProfileContextLink> profileContextLinksWithUserIds;
public User(final long pk, public User(final long pk,
final String username, final String username,
@ -51,7 +53,9 @@ public class User implements Serializable {
final String externalUrl, final String externalUrl,
final long usertagsCount, final long usertagsCount,
final String publicEmail, final String publicEmail,
final HdProfilePicUrlInfo hdProfilePicUrlInfo) { final HdProfilePicUrlInfo hdProfilePicUrlInfo,
final String profileContext,
final List<UserProfileContextLink> profileContextLinksWithUserIds) {
this.pk = pk; this.pk = pk;
this.username = username; this.username = username;
this.fullName = fullName; this.fullName = fullName;
@ -75,6 +79,8 @@ public class User implements Serializable {
this.usertagsCount = usertagsCount; this.usertagsCount = usertagsCount;
this.publicEmail = publicEmail; this.publicEmail = publicEmail;
this.hdProfilePicUrlInfo = hdProfilePicUrlInfo; this.hdProfilePicUrlInfo = hdProfilePicUrlInfo;
this.profileContext = profileContext;
this.profileContextLinksWithUserIds = profileContextLinksWithUserIds;
} }
public long getPk() { public long getPk() {
@ -173,46 +179,13 @@ public class User implements Serializable {
return publicEmail; return publicEmail;
} }
// public boolean isReallyPrivate() { public String getProfileContext() {
// final FriendshipStatus friendshipStatus = getFriendshipStatus(); return profileContext;
// !user.optBoolean("followed_by_viewer") && (id != uid && isPrivate) }
// }
// public static User fromProfileModel(final ProfileModel profileModel) { public List<UserProfileContextLink> getProfileContextLinks() {
// return new User( return profileContextLinksWithUserIds;
// 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);
// }
@Override @Override
public boolean equals(final Object o) { public boolean equals(final Object o) {

View File

@ -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;
}
}

View File

@ -782,7 +782,7 @@ public final class ResponseBodyUtils {
null, null,
friendshipStatus, friendshipStatus,
owner.optBoolean("is_verified"), 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 String id = feedItem.getString(Constants.EXTRAS_ID);
final ImageVersions2 imageVersions2 = new ImageVersions2( final ImageVersions2 imageVersions2 = new ImageVersions2(

View File

@ -243,6 +243,8 @@ public class GraphQLService extends BaseService {
null, null,
0, 0,
null, null,
null,
null,
null null
)); ));
// userModels.add(new ProfileModel(userObject.optBoolean("is_private"), // userModels.add(new ProfileModel(userObject.optBoolean("is_private"),
@ -334,6 +336,8 @@ public class GraphQLService extends BaseService {
url, url,
0, 0,
null, null,
null,
null,
null)); null));
} catch (JSONException e) { } catch (JSONException e) {
Log.e(TAG, "onResponse", e); Log.e(TAG, "onResponse", e);

View File

@ -172,6 +172,8 @@ public class StoriesService extends BaseService {
null, null,
0, 0,
null, null,
null,
null,
null null
); );
final String id = node.getString("id"); final String id = node.getString("id");
@ -231,6 +233,8 @@ public class StoriesService extends BaseService {
null, null,
0, 0,
null, null,
null,
null,
null null
); );
final String id = node.getString("id"); final String id = node.getString("id");