1
0
mirror of https://github.com/KokaKiwi/BarInsta synced 2024-11-22 22:57:29 +00:00

implement swipe-up sticker + refresh inbox list after sending message

This commit is contained in:
Austin Huang 2020-08-29 16:42:08 -04:00
parent 7b4c005513
commit c3d92b8fc0
No known key found for this signature in database
GPG Key ID: 84C23AA04587A91F
9 changed files with 90 additions and 29 deletions

View File

@ -65,6 +65,7 @@ import awais.instagrabber.models.enums.MediaItemType;
import awais.instagrabber.models.stickers.PollModel; import awais.instagrabber.models.stickers.PollModel;
import awais.instagrabber.models.stickers.QuestionModel; import awais.instagrabber.models.stickers.QuestionModel;
import awais.instagrabber.models.stickers.QuizModel; import awais.instagrabber.models.stickers.QuizModel;
import awais.instagrabber.models.stickers.SwipeUpModel;
import awais.instagrabber.utils.Constants; import awais.instagrabber.utils.Constants;
import awais.instagrabber.utils.Utils; import awais.instagrabber.utils.Utils;
import awaisomereport.LogCollector; import awaisomereport.LogCollector;
@ -99,6 +100,7 @@ public final class StoryViewer extends BaseLanguageActivity {
private QuestionModel question; private QuestionModel question;
private String[] mentions; private String[] mentions;
private QuizModel quiz; private QuizModel quiz;
private SwipeUpModel swipeUp;
private StoryModel currentStory; private StoryModel currentStory;
private String url, username; private String url, username;
private int slidePos = 0, lastSlidePos = 0; private int slidePos = 0, lastSlidePos = 0;
@ -220,14 +222,17 @@ public final class StoryViewer extends BaseLanguageActivity {
return false; return false;
}); });
storyViewerBinding.spotify.setOnClickListener(v -> { final View.OnClickListener linkActionListener = v -> {
final Object tag = v.getTag(); final Object tag = v.getTag();
if (tag instanceof CharSequence) { if (tag instanceof CharSequence) {
final Intent intent = new Intent(Intent.ACTION_VIEW); final Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setData(Uri.parse(tag.toString())); intent.setData(Uri.parse(tag.toString()));
startActivity(intent); startActivity(intent);
} }
}); };
storyViewerBinding.spotify.setOnClickListener(linkActionListener);
storyViewerBinding.swipeUp.setOnClickListener(linkActionListener);
storyViewerBinding.viewStoryPost.setOnClickListener(v -> { storyViewerBinding.viewStoryPost.setOnClickListener(v -> {
final Object tag = v.getTag(); final Object tag = v.getTag();
@ -279,7 +284,7 @@ public final class StoryViewer extends BaseLanguageActivity {
.show(); .show();
} }
else if (tag instanceof QuizModel) { else if (tag instanceof QuizModel) {
quiz = (QuizModel) quiz; quiz = quiz;
String[] choices = new String[quiz.getChoices().length]; String[] choices = new String[quiz.getChoices().length];
for (int q = 0; q < choices.length; ++q) { for (int q = 0; q < choices.length; ++q) {
choices[q] = (quiz.getMyChoice() == q ? "" :"") + quiz.getChoices()[q]+ " (" + quiz.getCounts()[q] + ")"; choices[q] = (quiz.getMyChoice() == q ? "" :"") + quiz.getChoices()[q]+ " (" + quiz.getCounts()[q] + ")";
@ -509,6 +514,13 @@ public final class StoryViewer extends BaseLanguageActivity {
storyViewerBinding.quiz.setVisibility(quiz != null ? View.VISIBLE : View.GONE); storyViewerBinding.quiz.setVisibility(quiz != null ? View.VISIBLE : View.GONE);
storyViewerBinding.quiz.setTag(quiz); storyViewerBinding.quiz.setTag(quiz);
swipeUp = currentStory.getSwipeUp();
storyViewerBinding.swipeUp.setVisibility(swipeUp != null ? View.VISIBLE : View.GONE);
if (swipeUp != null) {
storyViewerBinding.swipeUp.setText(swipeUp.getText());
storyViewerBinding.swipeUp.setTag(swipeUp.getUrl());
}
releasePlayer(); releasePlayer();
final Intent intent = getIntent(); final Intent intent = getIntent();
if (intent.getBooleanExtra(Constants.EXTRAS_HASHTAG, false)) { if (intent.getBooleanExtra(Constants.EXTRAS_HASHTAG, false)) {

View File

@ -16,7 +16,9 @@ import awais.instagrabber.models.enums.MediaItemType;
import awais.instagrabber.models.stickers.PollModel; import awais.instagrabber.models.stickers.PollModel;
import awais.instagrabber.models.stickers.QuestionModel; import awais.instagrabber.models.stickers.QuestionModel;
import awais.instagrabber.models.stickers.QuizModel; import awais.instagrabber.models.stickers.QuizModel;
import awais.instagrabber.models.stickers.SwipeUpModel;
import awais.instagrabber.utils.Constants; import awais.instagrabber.utils.Constants;
import awais.instagrabber.utils.LocaleUtils;
import awais.instagrabber.utils.Utils; import awais.instagrabber.utils.Utils;
import awaisomereport.LogCollector; import awaisomereport.LogCollector;
@ -51,6 +53,7 @@ public final class iStoryStatusFetcher extends AsyncTask<Void, Void, StoryModel[
conn.setInstanceFollowRedirects(true); conn.setInstanceFollowRedirects(true);
conn.setUseCaches(false); conn.setUseCaches(false);
conn.setRequestProperty("User-Agent", storiesig ? Constants.A_USER_AGENT : Constants.I_USER_AGENT); conn.setRequestProperty("User-Agent", storiesig ? Constants.A_USER_AGENT : Constants.I_USER_AGENT);
conn.setRequestProperty("Accept-Language", LocaleUtils.getCurrentLocale().getLanguage() + ",en-US;q=0.8");
conn.connect(); conn.connect();
if (conn.getResponseCode() == HttpURLConnection.HTTP_OK) { if (conn.getResponseCode() == HttpURLConnection.HTTP_OK) {
@ -86,6 +89,7 @@ public final class iStoryStatusFetcher extends AsyncTask<Void, Void, StoryModel[
models[i].setTappableShortCode(data.getJSONArray("story_feed_media").getJSONObject(0).optString("media_id")); models[i].setTappableShortCode(data.getJSONArray("story_feed_media").getJSONObject(0).optString("media_id"));
} }
// assuming everything is spotify
if (!data.isNull("story_app_attribution")) if (!data.isNull("story_app_attribution"))
models[i].setSpotify(data.getJSONObject("story_app_attribution").optString("content_url").split("\\?")[0]); models[i].setSpotify(data.getJSONObject("story_app_attribution").optString("content_url").split("\\?")[0]);
@ -101,6 +105,7 @@ public final class iStoryStatusFetcher extends AsyncTask<Void, Void, StoryModel[
tappableObject.optInt("viewer_vote", -1) tappableObject.optInt("viewer_vote", -1)
)); ));
} }
if (data.has("story_questions")) { if (data.has("story_questions")) {
JSONObject tappableObject = data.getJSONArray("story_questions").getJSONObject(0).optJSONObject("question_sticker"); JSONObject tappableObject = data.getJSONArray("story_questions").getJSONObject(0).optJSONObject("question_sticker");
if (tappableObject != null && !tappableObject.getString("question_type").equals("music")) if (tappableObject != null && !tappableObject.getString("question_type").equals("music"))
@ -109,6 +114,7 @@ public final class iStoryStatusFetcher extends AsyncTask<Void, Void, StoryModel[
tappableObject.getString("question") tappableObject.getString("question")
)); ));
} }
if (data.has("story_quizs")) { if (data.has("story_quizs")) {
JSONObject tappableObject = data.getJSONArray("story_quizs").getJSONObject(0).optJSONObject("quiz_sticker"); JSONObject tappableObject = data.getJSONArray("story_quizs").getJSONObject(0).optJSONObject("quiz_sticker");
if (tappableObject != null) { if (tappableObject != null) {
@ -129,6 +135,18 @@ public final class iStoryStatusFetcher extends AsyncTask<Void, Void, StoryModel[
)); ));
} }
} }
if (data.has("story_cta") && data.has("link_text")) {
JSONObject tappableObject = data.getJSONArray("story_cta").getJSONObject(0).getJSONArray("links").getJSONObject(0);
String swipeUpUrl = tappableObject.getString("webUri");
if (swipeUpUrl.startsWith("http")) {
models[i].setSwipeUp(new SwipeUpModel(
swipeUpUrl,
data.getString("link_text")
));
}
}
JSONArray hashtags = data.optJSONArray("story_hashtags"); JSONArray hashtags = data.optJSONArray("story_hashtags");
JSONArray locations = data.optJSONArray("story_locations"); JSONArray locations = data.optJSONArray("story_locations");
JSONArray atmarks = data.optJSONArray("reel_mentions"); JSONArray atmarks = data.optJSONArray("reel_mentions");

View File

@ -46,7 +46,7 @@ public class DirectMessageInboxFragment extends Fragment implements SwipeRefresh
private String endCursor; private String endCursor;
private AsyncTask<Void, Void, InboxModel> currentlyRunning; private AsyncTask<Void, Void, InboxModel> currentlyRunning;
private InboxThreadModelListViewModel listViewModel; private InboxThreadModelListViewModel listViewModel;
public static boolean afterLeave = false; public static boolean refreshPlease = false;
private final FetchListener<InboxModel> fetchListener = new FetchListener<InboxModel>() { private final FetchListener<InboxModel> fetchListener = new FetchListener<InboxModel>() {
@Override @Override
@ -119,9 +119,9 @@ public class DirectMessageInboxFragment extends Fragment implements SwipeRefresh
@Override @Override
public void onResume() { public void onResume() {
super.onResume(); super.onResume();
if (afterLeave) { if (refreshPlease) {
onRefresh(); onRefresh();
afterLeave = false; refreshPlease = false;
} }
} }

View File

@ -199,7 +199,7 @@ public class DirectMessageSettingsFragment extends Fragment implements SwipeRefr
titleText.clearFocus(); titleText.clearFocus();
} }
else if (action.equals("leave")) { else if (action.equals("leave")) {
DirectMessageInboxFragment.afterLeave = true; DirectMessageInboxFragment.refreshPlease = true;
NavHostFragment.findNavController(DirectMessageSettingsFragment.this).popBackStack(R.id.directMessagesInboxFragment, false); NavHostFragment.findNavController(DirectMessageSettingsFragment.this).popBackStack(R.id.directMessagesInboxFragment, false);
} }
} }

View File

@ -221,12 +221,16 @@ public class DirectMessageThreadFragment extends Fragment {
case RAVEN_MEDIA: case RAVEN_MEDIA:
case MEDIA: case MEDIA:
final ProfileModel user = getUser(directItemModel.getUserId()); final ProfileModel user = getUser(directItemModel.getUserId());
String url = selectedItem.getMediaType() == MediaItemType.MEDIA_TYPE_VIDEO ? selectedItem.getVideoUrl() : selectedItem.getThumbUrl(); final DirectItemModel.DirectItemMediaModel selectedItem =
if (url != null) { itemType == DirectItemType.MEDIA ? directItemModel.getMediaModel() : directItemModel.getRavenMediaModel().getMedia();
Utils.dmDownload(requireContext(), user.getUsername(), DownloadMethod.DOWNLOAD_DIRECT, Collections.singletonList(itemType == DirectItemType.MEDIA ? directItemModel.getMediaModel() : directItemModel.getRavenMediaModel().getMedia())); final String url = selectedItem.getMediaType() == MediaItemType.MEDIA_TYPE_VIDEO ? selectedItem.getVideoUrl() : selectedItem.getThumbUrl();
if (url == null) {
Toast.makeText(requireContext(), R.string.downloader_unknown_error, Toast.LENGTH_SHORT).show();
}
else {
Utils.dmDownload(requireContext(), user.getUsername(), DownloadMethod.DOWNLOAD_DIRECT, selectedItem);
Toast.makeText(requireContext(), R.string.downloader_downloading_media, Toast.LENGTH_SHORT).show(); Toast.makeText(requireContext(), R.string.downloader_downloading_media, Toast.LENGTH_SHORT).show();
} }
else Toast.makeText(requireContext(), R.string.downloader_unknown_error, Toast.LENGTH_SHORT).show();
break; break;
case STORY_SHARE: case STORY_SHARE:
if (directItemModel.getReelShare() != null) { if (directItemModel.getReelShare() != null) {
@ -372,6 +376,7 @@ public class DirectMessageThreadFragment extends Fragment {
} }
directItemModel.setLiked(); directItemModel.setLiked();
} }
DirectMessageInboxFragment.refreshPlease = true;
hasSentSomething = true; hasSentSomething = true;
new DirectMessageInboxThreadFetcher(threadId, UserInboxDirection.OLDER, null, fetchListener).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); new DirectMessageInboxThreadFetcher(threadId, UserInboxDirection.OLDER, null, fetchListener).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}); });

View File

@ -6,6 +6,7 @@ import awais.instagrabber.models.enums.MediaItemType;
import awais.instagrabber.models.stickers.PollModel; import awais.instagrabber.models.stickers.PollModel;
import awais.instagrabber.models.stickers.QuestionModel; import awais.instagrabber.models.stickers.QuestionModel;
import awais.instagrabber.models.stickers.QuizModel; import awais.instagrabber.models.stickers.QuizModel;
import awais.instagrabber.models.stickers.SwipeUpModel;
public final class StoryModel implements Serializable { public final class StoryModel implements Serializable {
private final String storyMediaId, storyUrl, username, userId; private final String storyMediaId, storyUrl, username, userId;
@ -15,6 +16,7 @@ public final class StoryModel implements Serializable {
private PollModel poll; private PollModel poll;
private QuestionModel question; private QuestionModel question;
private QuizModel quiz; private QuizModel quiz;
private SwipeUpModel swipeUp;
private String[] mentions; private String[] mentions;
private int position; private int position;
private boolean isCurrentSlide = false, canReply = false; private boolean isCurrentSlide = false, canReply = false;
@ -66,6 +68,8 @@ public final class StoryModel implements Serializable {
return quiz; return quiz;
} }
public SwipeUpModel getSwipeUp() { return swipeUp;}
public String[] getMentions() { public String[] getMentions() {
return mentions; return mentions;
} }
@ -106,6 +110,10 @@ public final class StoryModel implements Serializable {
this.mentions = mentions; this.mentions = mentions;
} }
public void setSwipeUp(final SwipeUpModel swipeUp) {
this.swipeUp = swipeUp;
}
public void setPosition(final int position) { public void setPosition(final int position) {
this.position = position; this.position = position;
} }

View File

@ -0,0 +1,20 @@
package awais.instagrabber.models.stickers;
import java.io.Serializable;
public final class SwipeUpModel implements Serializable {
private final String url, text;
public SwipeUpModel(final String url, final String text) {
this.url = url;
this.text = text;
}
public String getUrl() {
return url;
}
public String getText() {
return text;
}
}

View File

@ -990,10 +990,10 @@ public final class Utils {
} }
public static void dmDownload(@NonNull final Context context, @Nullable final String username, final DownloadMethod method, public static void dmDownload(@NonNull final Context context, @Nullable final String username, final DownloadMethod method,
final List<? extends DirectItemMediaModel> itemsToDownload) { final DirectItemMediaModel itemsToDownload) {
if (settingsHelper == null) settingsHelper = new SettingsHelper(context); if (settingsHelper == null) settingsHelper = new SettingsHelper(context);
if (itemsToDownload == null || itemsToDownload.size() < 1) return; if (itemsToDownload == null) return;
if (ContextCompat.checkSelfPermission(context, Utils.PERMS[0]) == PackageManager.PERMISSION_GRANTED) if (ContextCompat.checkSelfPermission(context, Utils.PERMS[0]) == PackageManager.PERMISSION_GRANTED)
dmDownloadImpl(context, username, method, itemsToDownload); dmDownloadImpl(context, username, method, itemsToDownload);
@ -1002,7 +1002,7 @@ public final class Utils {
} }
private static void dmDownloadImpl(@NonNull final Context context, @Nullable final String username, private static void dmDownloadImpl(@NonNull final Context context, @Nullable final String username,
final DownloadMethod method, final List<? extends DirectItemMediaModel> itemsToDownload) { final DownloadMethod method, final DirectItemMediaModel selectedItem) {
File dir = new File(Environment.getExternalStorageDirectory(), "Download"); File dir = new File(Environment.getExternalStorageDirectory(), "Download");
if (settingsHelper.getBoolean(FOLDER_SAVE_TO)) { if (settingsHelper.getBoolean(FOLDER_SAVE_TO)) {
@ -1014,22 +1014,11 @@ public final class Utils {
dir = new File(dir, username); dir = new File(dir, username);
if (dir.exists() || dir.mkdirs()) { if (dir.exists() || dir.mkdirs()) {
final Main main = method != DownloadMethod.DOWNLOAD_FEED && context instanceof Main ? (Main) context : null;
final int itemsToDownloadSize = itemsToDownload.size();
final File finalDir = dir; final File finalDir = dir;
for (int i = itemsToDownloadSize - 1; i >= 0; i--) { new DownloadAsync(context,
final DirectItemMediaModel selectedItem = itemsToDownload.get(i); selectedItem.getMediaType() == MediaItemType.MEDIA_TYPE_VIDEO ? selectedItem.getVideoUrl() : selectedItem.getThumbUrl(),
getDownloadSaveFileDm(finalDir, selectedItem, ""),
if (main == null) { null).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
new DownloadAsync(context,
selectedItem.getMediaType() == MediaItemType.MEDIA_TYPE_VIDEO ? selectedItem.getVideoUrl() : selectedItem.getThumbUrl(),
getDownloadSaveFileDm(finalDir, selectedItem, ""),
null).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}
}
} else } else
Toast.makeText(context, R.string.error_creating_folders, Toast.LENGTH_SHORT).show(); Toast.makeText(context, R.string.error_creating_folders, Toast.LENGTH_SHORT).show();
} }

View File

@ -81,6 +81,15 @@
android:textColor="@color/btn_blue_text_color" android:textColor="@color/btn_blue_text_color"
android:visibility="gone" android:visibility="gone"
app:backgroundTint="@color/btn_blue_background" /> app:backgroundTint="@color/btn_blue_background" />
<androidx.appcompat.widget.AppCompatButton
android:id="@+id/swipeUp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="SAMPLE TEXT"
android:textColor="@color/btn_blue_text_color"
android:visibility="gone"
app:backgroundTint="@color/btn_blue_background" />
<androidx.appcompat.widget.AppCompatButton <androidx.appcompat.widget.AppCompatButton
android:id="@+id/mention" android:id="@+id/mention"
android:layout_width="match_parent" android:layout_width="match_parent"