Browse Source
Support opening media, hashtag, location, mentions in direct thread
renovate/org.robolectric-robolectric-4.x
Support opening media, hashtag, location, mentions in direct thread
renovate/org.robolectric-robolectric-4.x
Ammar Githam
4 years ago
29 changed files with 465 additions and 274 deletions
-
2app/src/main/java/awais/instagrabber/activities/MainActivity.java
-
50app/src/main/java/awais/instagrabber/adapters/DirectItemsAdapter.java
-
12app/src/main/java/awais/instagrabber/adapters/viewholder/directmessages/DirectItemActionLogViewHolder.java
-
7app/src/main/java/awais/instagrabber/adapters/viewholder/directmessages/DirectItemAnimatedMediaViewHolder.java
-
9app/src/main/java/awais/instagrabber/adapters/viewholder/directmessages/DirectItemDefaultViewHolder.java
-
7app/src/main/java/awais/instagrabber/adapters/viewholder/directmessages/DirectItemLikeViewHolder.java
-
21app/src/main/java/awais/instagrabber/adapters/viewholder/directmessages/DirectItemLinkViewHolder.java
-
105app/src/main/java/awais/instagrabber/adapters/viewholder/directmessages/DirectItemMediaShareViewHolder.java
-
9app/src/main/java/awais/instagrabber/adapters/viewholder/directmessages/DirectItemMediaViewHolder.java
-
9app/src/main/java/awais/instagrabber/adapters/viewholder/directmessages/DirectItemPlaceholderViewHolder.java
-
7app/src/main/java/awais/instagrabber/adapters/viewholder/directmessages/DirectItemProfileViewHolder.java
-
8app/src/main/java/awais/instagrabber/adapters/viewholder/directmessages/DirectItemRavenMediaViewHolder.java
-
8app/src/main/java/awais/instagrabber/adapters/viewholder/directmessages/DirectItemReelShareViewHolder.java
-
33app/src/main/java/awais/instagrabber/adapters/viewholder/directmessages/DirectItemStoryShareViewHolder.java
-
27app/src/main/java/awais/instagrabber/adapters/viewholder/directmessages/DirectItemTextViewHolder.java
-
7app/src/main/java/awais/instagrabber/adapters/viewholder/directmessages/DirectItemVideoCallEventViewHolder.java
-
49app/src/main/java/awais/instagrabber/adapters/viewholder/directmessages/DirectItemViewHolder.java
-
5app/src/main/java/awais/instagrabber/adapters/viewholder/directmessages/DirectItemVoiceMediaViewHolder.java
-
2app/src/main/java/awais/instagrabber/customviews/ChatMessageLayout.java
-
80app/src/main/java/awais/instagrabber/fragments/PostViewV2Fragment.java
-
120app/src/main/java/awais/instagrabber/fragments/directmessages/DirectMessageThreadFragment.java
-
3app/src/main/java/awais/instagrabber/fragments/main/FeedFragment.java
-
7app/src/main/java/awais/instagrabber/repositories/responses/Media.java
-
67app/src/main/java/awais/instagrabber/utils/DeepLinkParser.java
-
16app/src/main/java/awais/instagrabber/viewmodels/PostViewV2ViewModel.java
-
59app/src/main/res/layout/dialog_post_view.xml
-
2app/src/main/res/layout/fragment_direct_messages_thread.xml
-
3app/src/main/res/navigation/direct_messages_nav_graph.xml
-
5app/src/main/res/values/strings.xml
@ -0,0 +1,67 @@ |
|||
package awais.instagrabber.utils; |
|||
|
|||
import androidx.annotation.NonNull; |
|||
import androidx.annotation.Nullable; |
|||
|
|||
import com.google.common.collect.ImmutableMap; |
|||
|
|||
import java.util.Map; |
|||
import java.util.regex.Pattern; |
|||
|
|||
public final class DeepLinkParser { |
|||
private static final Map<DeepLink.Type, DeepLinkPattern> TYPE_PATTERN_MAP = ImmutableMap |
|||
.<DeepLink.Type, DeepLinkPattern>builder() |
|||
.put(DeepLink.Type.USER, new DeepLinkPattern("instagram://user?username=")) |
|||
.build(); |
|||
|
|||
@Nullable |
|||
public static DeepLink parse(@NonNull final String text) { |
|||
for (final Map.Entry<DeepLink.Type, DeepLinkPattern> entry : TYPE_PATTERN_MAP.entrySet()) { |
|||
if (text.startsWith(entry.getValue().getPatternText())) { |
|||
final String value = entry.getValue().getPattern().matcher(text).replaceAll(""); |
|||
return new DeepLink(entry.getKey(), value); |
|||
} |
|||
} |
|||
return null; |
|||
} |
|||
|
|||
public static class DeepLinkPattern { |
|||
private final String patternText; |
|||
private final Pattern pattern; |
|||
|
|||
public DeepLinkPattern(final String patternText) { |
|||
this.patternText = patternText; |
|||
pattern = Pattern.compile(patternText, Pattern.LITERAL); |
|||
} |
|||
|
|||
public String getPatternText() { |
|||
return patternText; |
|||
} |
|||
|
|||
public Pattern getPattern() { |
|||
return pattern; |
|||
} |
|||
} |
|||
|
|||
public static class DeepLink { |
|||
private final Type type; |
|||
private final String value; |
|||
|
|||
public DeepLink(final Type type, final String value) { |
|||
this.type = type; |
|||
this.value = value; |
|||
} |
|||
|
|||
public Type getType() { |
|||
return type; |
|||
} |
|||
|
|||
public String getValue() { |
|||
return value; |
|||
} |
|||
|
|||
public enum Type { |
|||
USER, |
|||
} |
|||
} |
|||
} |
Write
Preview
Loading…
Cancel
Save
Reference in new issue