Austin Huang
4 years ago
No known key found for this signature in database
GPG Key ID: 84C23AA04587A91F
19 changed files with 453 additions and 462 deletions
-
35app/src/main/java/awais/instagrabber/adapters/NotificationsAdapter.java
-
31app/src/main/java/awais/instagrabber/adapters/viewholder/NotificationViewHolder.java
-
139app/src/main/java/awais/instagrabber/asyncs/GetActivityAsyncTask.java
-
18app/src/main/java/awais/instagrabber/asyncs/NotificationsFetcher.java
-
37app/src/main/java/awais/instagrabber/fragments/NotificationsViewerFragment.java
-
79app/src/main/java/awais/instagrabber/models/NotificationModel.java
-
6app/src/main/java/awais/instagrabber/repositories/NewsRepository.java
-
22app/src/main/java/awais/instagrabber/repositories/responses/AymlResponse.java
-
34app/src/main/java/awais/instagrabber/repositories/responses/AymlUser.java
-
15app/src/main/java/awais/instagrabber/repositories/responses/AymlUserList.java
-
29app/src/main/java/awais/instagrabber/repositories/responses/NewsInboxResponse.java
-
29app/src/main/java/awais/instagrabber/repositories/responses/Notification.java
-
86app/src/main/java/awais/instagrabber/repositories/responses/NotificationArgs.java
-
57app/src/main/java/awais/instagrabber/repositories/responses/NotificationCounts.java
-
19app/src/main/java/awais/instagrabber/repositories/responses/NotificationImage.java
-
49app/src/main/java/awais/instagrabber/repositories/responses/UserInfo.java
-
17app/src/main/java/awais/instagrabber/services/ActivityCheckerService.java
-
6app/src/main/java/awais/instagrabber/viewmodels/NotificationViewModel.java
-
207app/src/main/java/awais/instagrabber/webservices/NewsService.java
@ -1,139 +0,0 @@ |
|||
package awais.instagrabber.asyncs; |
|||
|
|||
import android.os.AsyncTask; |
|||
import android.util.Log; |
|||
|
|||
import androidx.annotation.NonNull; |
|||
|
|||
import org.json.JSONObject; |
|||
|
|||
import java.net.HttpURLConnection; |
|||
import java.net.URL; |
|||
|
|||
import awais.instagrabber.utils.Constants; |
|||
import awais.instagrabber.utils.CookieUtils; |
|||
import awais.instagrabber.utils.NetworkUtils; |
|||
import awais.instagrabber.utils.TextUtils; |
|||
import awais.instagrabber.utils.Utils; |
|||
|
|||
public class GetActivityAsyncTask extends AsyncTask<String, Void, GetActivityAsyncTask.NotificationCounts> { |
|||
private static final String TAG = "GetActivityAsyncTask"; |
|||
|
|||
private final OnTaskCompleteListener onTaskCompleteListener; |
|||
|
|||
public GetActivityAsyncTask(final OnTaskCompleteListener onTaskCompleteListener) { |
|||
this.onTaskCompleteListener = onTaskCompleteListener; |
|||
} |
|||
|
|||
/* |
|||
This needs to be redone to fetch i inbox instead |
|||
Within inbox, data is (body JSON => counts) |
|||
Then we have these counts: |
|||
new_posts, activity_feed_dot_badge, relationships, campaign_notification |
|||
usertags, likes, comment_likes, shopping_notification, comments |
|||
photos_of_you (not sure about difference to usertags), requests |
|||
*/ |
|||
|
|||
protected NotificationCounts doInBackground(final String... cookiesArray) { |
|||
if (cookiesArray == null) return null; |
|||
final String cookie = cookiesArray[0]; |
|||
if (TextUtils.isEmpty(cookie)) return null; |
|||
final long uid = CookieUtils.getUserIdFromCookie(cookie); |
|||
final String url = "https://www.instagram.com/graphql/query/?query_hash=0f318e8cfff9cc9ef09f88479ff571fb" |
|||
+ "&variables={\"id\":\"" + uid + "\"}"; |
|||
HttpURLConnection urlConnection = null; |
|||
try { |
|||
urlConnection = (HttpURLConnection) new URL(url).openConnection(); |
|||
urlConnection.setUseCaches(false); |
|||
urlConnection.setRequestProperty("User-Agent", Utils.settingsHelper.getString(Constants.BROWSER_UA)); |
|||
urlConnection.setRequestProperty("x-csrftoken", cookie.split("csrftoken=")[1].split(";")[0]); |
|||
urlConnection.connect(); |
|||
if (urlConnection.getResponseCode() != HttpURLConnection.HTTP_OK) { |
|||
return null; |
|||
} |
|||
final JSONObject data = new JSONObject(NetworkUtils.readFromConnection(urlConnection)) |
|||
.getJSONObject("data") |
|||
.getJSONObject("user") |
|||
.getJSONObject("edge_activity_count") |
|||
.getJSONArray("edges") |
|||
.getJSONObject(0) |
|||
.getJSONObject("node"); |
|||
return new NotificationCounts( |
|||
data.getInt("relationships"), |
|||
data.getInt("usertags"), |
|||
data.getInt("comments"), |
|||
data.getInt("comment_likes"), |
|||
data.getInt("likes") |
|||
); |
|||
} catch (Throwable ex) { |
|||
Log.e(TAG, "Error", ex); |
|||
} finally { |
|||
if (urlConnection != null) { |
|||
urlConnection.disconnect(); |
|||
} |
|||
} |
|||
return null; |
|||
} |
|||
|
|||
@Override |
|||
protected void onPostExecute(final NotificationCounts result) { |
|||
if (onTaskCompleteListener == null) return; |
|||
onTaskCompleteListener.onTaskComplete(result); |
|||
} |
|||
|
|||
public static class NotificationCounts { |
|||
private final int relationshipsCount; |
|||
private final int userTagsCount; |
|||
private final int commentsCount; |
|||
private final int commentLikesCount; |
|||
private final int likesCount; |
|||
|
|||
public NotificationCounts(final int relationshipsCount, |
|||
final int userTagsCount, |
|||
final int commentsCount, |
|||
final int commentLikesCount, |
|||
final int likesCount) { |
|||
this.relationshipsCount = relationshipsCount; |
|||
this.userTagsCount = userTagsCount; |
|||
this.commentsCount = commentsCount; |
|||
this.commentLikesCount = commentLikesCount; |
|||
this.likesCount = likesCount; |
|||
} |
|||
|
|||
public int getRelationshipsCount() { |
|||
return relationshipsCount; |
|||
} |
|||
|
|||
public int getUserTagsCount() { |
|||
return userTagsCount; |
|||
} |
|||
|
|||
public int getCommentsCount() { |
|||
return commentsCount; |
|||
} |
|||
|
|||
public int getCommentLikesCount() { |
|||
return commentLikesCount; |
|||
} |
|||
|
|||
public int getLikesCount() { |
|||
return likesCount; |
|||
} |
|||
|
|||
@NonNull |
|||
@Override |
|||
public String toString() { |
|||
return "NotificationCounts{" + |
|||
"relationshipsCount=" + relationshipsCount + |
|||
", userTagsCount=" + userTagsCount + |
|||
", commentsCount=" + commentsCount + |
|||
", commentLikesCount=" + commentLikesCount + |
|||
", likesCount=" + likesCount + |
|||
'}'; |
|||
} |
|||
} |
|||
|
|||
public interface OnTaskCompleteListener { |
|||
void onTaskComplete(final NotificationCounts result); |
|||
} |
|||
} |
@ -1,79 +0,0 @@ |
|||
package awais.instagrabber.models; |
|||
|
|||
import androidx.annotation.NonNull; |
|||
|
|||
import java.util.Date; |
|||
|
|||
import awais.instagrabber.models.enums.NotificationType; |
|||
import awais.instagrabber.utils.Utils; |
|||
|
|||
public final class NotificationModel { |
|||
private final String id; |
|||
private final long userId; |
|||
private final String username; |
|||
private final String profilePicUrl; |
|||
private final long postId; |
|||
private final String previewUrl; |
|||
private final NotificationType type; |
|||
private final CharSequence text; |
|||
private final long timestamp; |
|||
|
|||
public NotificationModel(final String id, |
|||
final String text, |
|||
final long timestamp, |
|||
final long userId, |
|||
final String username, |
|||
final String profilePicUrl, |
|||
final long postId, |
|||
final String previewUrl, |
|||
final NotificationType type) { |
|||
this.id = id; |
|||
this.text = text; |
|||
this.timestamp = timestamp; |
|||
this.userId = userId; |
|||
this.username = username; |
|||
this.profilePicUrl = profilePicUrl; |
|||
this.postId = postId; |
|||
this.previewUrl = previewUrl; |
|||
this.type = type; |
|||
} |
|||
|
|||
public String getId() { |
|||
return id; |
|||
} |
|||
|
|||
public CharSequence getText() { |
|||
return text; |
|||
} |
|||
|
|||
public long getTimestamp() { |
|||
return timestamp; |
|||
} |
|||
|
|||
@NonNull |
|||
public String getDateTime() { |
|||
return Utils.datetimeParser.format(new Date(timestamp * 1000L)); |
|||
} |
|||
|
|||
public long getUserId() { |
|||
return userId; |
|||
} |
|||
|
|||
public String getUsername() { |
|||
return username; |
|||
} |
|||
|
|||
public String getProfilePic() { |
|||
return profilePicUrl; |
|||
} |
|||
|
|||
public long getPostId() { |
|||
return postId; |
|||
} |
|||
|
|||
public String getPreviewPic() { |
|||
return previewUrl; |
|||
} |
|||
|
|||
public NotificationType getType() { return type; } |
|||
} |
@ -0,0 +1,22 @@ |
|||
package awais.instagrabber.repositories.responses; |
|||
|
|||
import java.util.List; |
|||
|
|||
public class AymlResponse { |
|||
private final AymlUserList newSuggestedUsers; |
|||
private final AymlUserList suggestedUsers; |
|||
|
|||
public AymlResponse(final AymlUserList newSuggestedUsers, |
|||
final AymlUserList suggestedUsers) { |
|||
this.newSuggestedUsers = newSuggestedUsers; |
|||
this.suggestedUsers = suggestedUsers; |
|||
} |
|||
|
|||
public AymlUserList getNewSuggestedUsers() { |
|||
return newSuggestedUsers; |
|||
} |
|||
|
|||
public AymlUserList getSuggestedUsers() { |
|||
return suggestedUsers; |
|||
} |
|||
} |
@ -0,0 +1,34 @@ |
|||
package awais.instagrabber.repositories.responses; |
|||
|
|||
public class AymlUser { |
|||
private final User user; |
|||
private final String algorithm; |
|||
private final String socialContext; |
|||
private final String uuid; |
|||
|
|||
public AymlUser(final User user, |
|||
final String algorithm, |
|||
final String socialContext, |
|||
final String uuid) { |
|||
this.user = user; |
|||
this.algorithm = algorithm; |
|||
this.socialContext = socialContext; |
|||
this.uuid = uuid; |
|||
} |
|||
|
|||
public User getUser() { |
|||
return user; |
|||
} |
|||
|
|||
public String getAlgorithm() { |
|||
return algorithm; |
|||
} |
|||
|
|||
public String getSocialContext() { |
|||
return socialContext; |
|||
} |
|||
|
|||
public String getUuid() { |
|||
return uuid; |
|||
} |
|||
} |
@ -0,0 +1,15 @@ |
|||
package awais.instagrabber.repositories.responses; |
|||
|
|||
import java.util.List; |
|||
|
|||
public class AymlUserList { |
|||
private final List<AymlUser> suggestions; |
|||
|
|||
public AymlUserList(final List<AymlUser> suggestions) { |
|||
this.suggestions = suggestions; |
|||
} |
|||
|
|||
public List<AymlUser> getSuggestions() { |
|||
return suggestions; |
|||
} |
|||
} |
@ -0,0 +1,29 @@ |
|||
package awais.instagrabber.repositories.responses; |
|||
|
|||
import java.util.List; |
|||
|
|||
public class NewsInboxResponse { |
|||
private final NotificationCounts counts; |
|||
private final List<Notification> newStories; |
|||
private final List<Notification> oldStories; |
|||
|
|||
public NewsInboxResponse(final NotificationCounts counts, |
|||
final List<Notification> newStories, |
|||
final List<Notification> oldStories) { |
|||
this.counts = counts; |
|||
this.newStories = newStories; |
|||
this.oldStories = oldStories; |
|||
} |
|||
|
|||
public NotificationCounts getCounts() { |
|||
return counts; |
|||
} |
|||
|
|||
public List<Notification> getNewStories() { |
|||
return newStories; |
|||
} |
|||
|
|||
public List<Notification> getOldStories() { |
|||
return oldStories; |
|||
} |
|||
} |
@ -0,0 +1,29 @@ |
|||
package awais.instagrabber.repositories.responses; |
|||
|
|||
import awais.instagrabber.models.enums.NotificationType; |
|||
|
|||
public class Notification { |
|||
private final NotificationArgs args; |
|||
private final String storyType; |
|||
private final String pk; |
|||
|
|||
public Notification(final NotificationArgs args, |
|||
final String storyType, |
|||
final String pk) { |
|||
this.args = args; |
|||
this.storyType = storyType; |
|||
this.pk = pk; |
|||
} |
|||
|
|||
public NotificationArgs getArgs() { |
|||
return args; |
|||
} |
|||
|
|||
public NotificationType getType() { |
|||
return NotificationType.valueOfType(storyType); |
|||
} |
|||
|
|||
public String getPk() { |
|||
return pk; |
|||
} |
|||
} |
@ -0,0 +1,86 @@ |
|||
package awais.instagrabber.repositories.responses; |
|||
|
|||
import androidx.annotation.NonNull; |
|||
|
|||
import java.util.Date; |
|||
import java.util.List; |
|||
import java.util.regex.Matcher; |
|||
import java.util.regex.Pattern; |
|||
|
|||
import android.util.Log; |
|||
|
|||
import awais.instagrabber.utils.Utils; |
|||
|
|||
public class NotificationArgs { |
|||
private final String text; |
|||
private final String richText; |
|||
private final long profileId; |
|||
private final String profileImage; |
|||
private final List<NotificationImage> media; |
|||
private final double timestamp; |
|||
private final String profileName; |
|||
private final String fullName; // for AYML, not naturally generated |
|||
|
|||
public NotificationArgs(final String text, |
|||
final String richText, // for AYML, this is the algorithm |
|||
final long profileId, |
|||
final String profileImage, |
|||
final List<NotificationImage> media, |
|||
final double timestamp, |
|||
final String profileName, |
|||
final String fullName) { |
|||
this.text = text; |
|||
this.richText = richText; |
|||
this.profileId = profileId; |
|||
this.profileImage = profileImage; |
|||
this.media = media; |
|||
this.timestamp = timestamp; |
|||
this.profileName = profileName; |
|||
this.fullName = fullName; |
|||
} |
|||
|
|||
public String getText() { |
|||
return text == null ? cleanRichText(richText) : text; |
|||
} |
|||
|
|||
public long getUserId() { |
|||
return profileId; |
|||
} |
|||
|
|||
public String getProfilePic() { |
|||
return profileImage; |
|||
} |
|||
|
|||
public String getUsername() { |
|||
return profileName; |
|||
} |
|||
|
|||
public String getFullName() { |
|||
return fullName; |
|||
} |
|||
|
|||
public List<NotificationImage> getMedia() { |
|||
return media; |
|||
} |
|||
|
|||
public double getTimestamp() { |
|||
return timestamp; |
|||
} |
|||
|
|||
@NonNull |
|||
public String getDateTime() { |
|||
return Utils.datetimeParser.format(new Date(Math.round(timestamp * 1000))); |
|||
} |
|||
|
|||
private String cleanRichText(final String raw) { |
|||
if (raw == null) return null; |
|||
final Matcher matcher = Pattern.compile("\\{[\\p{L}\\d._]+\\|000000\\|1\\|user\\?id=\\d+\\}").matcher(raw); |
|||
String result = raw; |
|||
while (matcher.find()) { |
|||
final String richObject = raw.substring(matcher.start(), matcher.end()); |
|||
final String username = richObject.split("\\|")[0].substring(1); |
|||
result = result.replace(richObject, username); |
|||
} |
|||
return result; |
|||
} |
|||
} |
@ -0,0 +1,57 @@ |
|||
package awais.instagrabber.repositories.responses; |
|||
|
|||
import androidx.annotation.NonNull; |
|||
|
|||
public class NotificationCounts { |
|||
private final int commentLikes; |
|||
private final int usertags; |
|||
private final int likes; |
|||
private final int comments; |
|||
private final int relationships; |
|||
private final int photosOfYou; |
|||
private final int requests; |
|||
|
|||
public NotificationCounts(final int commentLikes, |
|||
final int usertags, |
|||
final int likes, |
|||
final int comments, |
|||
final int relationships, |
|||
final int photosOfYou, |
|||
final int requests) { |
|||
this.commentLikes = commentLikes; |
|||
this.usertags = usertags; |
|||
this.likes = likes; |
|||
this.comments = comments; |
|||
this.relationships = relationships; |
|||
this.photosOfYou = photosOfYou; |
|||
this.requests = requests; |
|||
} |
|||
|
|||
public int getRelationshipsCount() { |
|||
return relationships; |
|||
} |
|||
|
|||
public int getUserTagsCount() { |
|||
return usertags; |
|||
} |
|||
|
|||
public int getCommentsCount() { |
|||
return comments; |
|||
} |
|||
|
|||
public int getCommentLikesCount() { |
|||
return commentLikes; |
|||
} |
|||
|
|||
public int getLikesCount() { |
|||
return likes; |
|||
} |
|||
|
|||
public int getPOYCount() { |
|||
return photosOfYou; |
|||
} |
|||
|
|||
public int getRequestsCount() { |
|||
return requests; |
|||
} |
|||
} |
@ -0,0 +1,19 @@ |
|||
package awais.instagrabber.repositories.responses; |
|||
|
|||
public class NotificationImage { |
|||
private final String id; |
|||
private final String image; |
|||
|
|||
public NotificationImage(final String id, final String image) { |
|||
this.id = id; |
|||
this.image = image; |
|||
} |
|||
|
|||
public String getId() { |
|||
return id; |
|||
} |
|||
|
|||
public String getImage() { |
|||
return image; |
|||
} |
|||
} |
@ -1,49 +0,0 @@ |
|||
package awais.instagrabber.repositories.responses; |
|||
|
|||
public class UserInfo { |
|||
private final long pk; |
|||
private final String username, fullName, profilePicUrl, hdProfilePicUrl; |
|||
|
|||
public UserInfo(final long pk, |
|||
final String username, |
|||
final String fullName, |
|||
final String profilePicUrl, |
|||
final String hdProfilePicUrl) { |
|||
this.pk = pk; |
|||
this.username = username; |
|||
this.fullName = fullName; |
|||
this.profilePicUrl = profilePicUrl; |
|||
this.hdProfilePicUrl = hdProfilePicUrl; |
|||
} |
|||
|
|||
public long getPk() { |
|||
return pk; |
|||
} |
|||
|
|||
public String getUsername() { |
|||
return username; |
|||
} |
|||
|
|||
public String getFullName() { |
|||
return fullName; |
|||
} |
|||
|
|||
public String getProfilePicUrl() { |
|||
return profilePicUrl; |
|||
} |
|||
|
|||
public String getHDProfilePicUrl() { |
|||
return hdProfilePicUrl; |
|||
} |
|||
|
|||
@Override |
|||
public String toString() { |
|||
return "UserInfo{" + |
|||
"uid='" + pk + '\'' + |
|||
", username='" + username + '\'' + |
|||
", fullName='" + fullName + '\'' + |
|||
", profilePicUrl='" + profilePicUrl + '\'' + |
|||
", hdProfilePicUrl='" + hdProfilePicUrl + '\'' + |
|||
'}'; |
|||
} |
|||
} |
Write
Preview
Loading…
Cancel
Save
Reference in new issue