mirror of
https://github.com/KokaKiwi/BarInsta
synced 2024-11-22 14:47:29 +00:00
implement swipe-up sticker + refresh inbox list after sending message
This commit is contained in:
parent
7b4c005513
commit
c3d92b8fc0
@ -65,6 +65,7 @@ import awais.instagrabber.models.enums.MediaItemType;
|
||||
import awais.instagrabber.models.stickers.PollModel;
|
||||
import awais.instagrabber.models.stickers.QuestionModel;
|
||||
import awais.instagrabber.models.stickers.QuizModel;
|
||||
import awais.instagrabber.models.stickers.SwipeUpModel;
|
||||
import awais.instagrabber.utils.Constants;
|
||||
import awais.instagrabber.utils.Utils;
|
||||
import awaisomereport.LogCollector;
|
||||
@ -99,6 +100,7 @@ public final class StoryViewer extends BaseLanguageActivity {
|
||||
private QuestionModel question;
|
||||
private String[] mentions;
|
||||
private QuizModel quiz;
|
||||
private SwipeUpModel swipeUp;
|
||||
private StoryModel currentStory;
|
||||
private String url, username;
|
||||
private int slidePos = 0, lastSlidePos = 0;
|
||||
@ -220,14 +222,17 @@ public final class StoryViewer extends BaseLanguageActivity {
|
||||
return false;
|
||||
});
|
||||
|
||||
storyViewerBinding.spotify.setOnClickListener(v -> {
|
||||
final View.OnClickListener linkActionListener = v -> {
|
||||
final Object tag = v.getTag();
|
||||
if (tag instanceof CharSequence) {
|
||||
final Intent intent = new Intent(Intent.ACTION_VIEW);
|
||||
intent.setData(Uri.parse(tag.toString()));
|
||||
startActivity(intent);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
storyViewerBinding.spotify.setOnClickListener(linkActionListener);
|
||||
storyViewerBinding.swipeUp.setOnClickListener(linkActionListener);
|
||||
|
||||
storyViewerBinding.viewStoryPost.setOnClickListener(v -> {
|
||||
final Object tag = v.getTag();
|
||||
@ -279,7 +284,7 @@ public final class StoryViewer extends BaseLanguageActivity {
|
||||
.show();
|
||||
}
|
||||
else if (tag instanceof QuizModel) {
|
||||
quiz = (QuizModel) quiz;
|
||||
quiz = quiz;
|
||||
String[] choices = new String[quiz.getChoices().length];
|
||||
for (int q = 0; q < choices.length; ++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.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();
|
||||
final Intent intent = getIntent();
|
||||
if (intent.getBooleanExtra(Constants.EXTRAS_HASHTAG, false)) {
|
||||
|
@ -16,7 +16,9 @@ import awais.instagrabber.models.enums.MediaItemType;
|
||||
import awais.instagrabber.models.stickers.PollModel;
|
||||
import awais.instagrabber.models.stickers.QuestionModel;
|
||||
import awais.instagrabber.models.stickers.QuizModel;
|
||||
import awais.instagrabber.models.stickers.SwipeUpModel;
|
||||
import awais.instagrabber.utils.Constants;
|
||||
import awais.instagrabber.utils.LocaleUtils;
|
||||
import awais.instagrabber.utils.Utils;
|
||||
import awaisomereport.LogCollector;
|
||||
|
||||
@ -51,6 +53,7 @@ public final class iStoryStatusFetcher extends AsyncTask<Void, Void, StoryModel[
|
||||
conn.setInstanceFollowRedirects(true);
|
||||
conn.setUseCaches(false);
|
||||
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();
|
||||
|
||||
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"));
|
||||
}
|
||||
|
||||
// assuming everything is spotify
|
||||
if (!data.isNull("story_app_attribution"))
|
||||
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)
|
||||
));
|
||||
}
|
||||
|
||||
if (data.has("story_questions")) {
|
||||
JSONObject tappableObject = data.getJSONArray("story_questions").getJSONObject(0).optJSONObject("question_sticker");
|
||||
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")
|
||||
));
|
||||
}
|
||||
|
||||
if (data.has("story_quizs")) {
|
||||
JSONObject tappableObject = data.getJSONArray("story_quizs").getJSONObject(0).optJSONObject("quiz_sticker");
|
||||
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 locations = data.optJSONArray("story_locations");
|
||||
JSONArray atmarks = data.optJSONArray("reel_mentions");
|
||||
|
@ -46,7 +46,7 @@ public class DirectMessageInboxFragment extends Fragment implements SwipeRefresh
|
||||
private String endCursor;
|
||||
private AsyncTask<Void, Void, InboxModel> currentlyRunning;
|
||||
private InboxThreadModelListViewModel listViewModel;
|
||||
public static boolean afterLeave = false;
|
||||
public static boolean refreshPlease = false;
|
||||
|
||||
private final FetchListener<InboxModel> fetchListener = new FetchListener<InboxModel>() {
|
||||
@Override
|
||||
@ -119,9 +119,9 @@ public class DirectMessageInboxFragment extends Fragment implements SwipeRefresh
|
||||
@Override
|
||||
public void onResume() {
|
||||
super.onResume();
|
||||
if (afterLeave) {
|
||||
if (refreshPlease) {
|
||||
onRefresh();
|
||||
afterLeave = false;
|
||||
refreshPlease = false;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -199,7 +199,7 @@ public class DirectMessageSettingsFragment extends Fragment implements SwipeRefr
|
||||
titleText.clearFocus();
|
||||
}
|
||||
else if (action.equals("leave")) {
|
||||
DirectMessageInboxFragment.afterLeave = true;
|
||||
DirectMessageInboxFragment.refreshPlease = true;
|
||||
NavHostFragment.findNavController(DirectMessageSettingsFragment.this).popBackStack(R.id.directMessagesInboxFragment, false);
|
||||
}
|
||||
}
|
||||
|
@ -221,12 +221,16 @@ public class DirectMessageThreadFragment extends Fragment {
|
||||
case RAVEN_MEDIA:
|
||||
case MEDIA:
|
||||
final ProfileModel user = getUser(directItemModel.getUserId());
|
||||
String url = selectedItem.getMediaType() == MediaItemType.MEDIA_TYPE_VIDEO ? selectedItem.getVideoUrl() : selectedItem.getThumbUrl();
|
||||
if (url != null) {
|
||||
Utils.dmDownload(requireContext(), user.getUsername(), DownloadMethod.DOWNLOAD_DIRECT, Collections.singletonList(itemType == DirectItemType.MEDIA ? directItemModel.getMediaModel() : directItemModel.getRavenMediaModel().getMedia()));
|
||||
final DirectItemModel.DirectItemMediaModel selectedItem =
|
||||
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();
|
||||
}
|
||||
else Toast.makeText(requireContext(), R.string.downloader_unknown_error, Toast.LENGTH_SHORT).show();
|
||||
break;
|
||||
case STORY_SHARE:
|
||||
if (directItemModel.getReelShare() != null) {
|
||||
@ -372,6 +376,7 @@ public class DirectMessageThreadFragment extends Fragment {
|
||||
}
|
||||
directItemModel.setLiked();
|
||||
}
|
||||
DirectMessageInboxFragment.refreshPlease = true;
|
||||
hasSentSomething = true;
|
||||
new DirectMessageInboxThreadFetcher(threadId, UserInboxDirection.OLDER, null, fetchListener).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
||||
});
|
||||
|
@ -6,6 +6,7 @@ import awais.instagrabber.models.enums.MediaItemType;
|
||||
import awais.instagrabber.models.stickers.PollModel;
|
||||
import awais.instagrabber.models.stickers.QuestionModel;
|
||||
import awais.instagrabber.models.stickers.QuizModel;
|
||||
import awais.instagrabber.models.stickers.SwipeUpModel;
|
||||
|
||||
public final class StoryModel implements Serializable {
|
||||
private final String storyMediaId, storyUrl, username, userId;
|
||||
@ -15,6 +16,7 @@ public final class StoryModel implements Serializable {
|
||||
private PollModel poll;
|
||||
private QuestionModel question;
|
||||
private QuizModel quiz;
|
||||
private SwipeUpModel swipeUp;
|
||||
private String[] mentions;
|
||||
private int position;
|
||||
private boolean isCurrentSlide = false, canReply = false;
|
||||
@ -66,6 +68,8 @@ public final class StoryModel implements Serializable {
|
||||
return quiz;
|
||||
}
|
||||
|
||||
public SwipeUpModel getSwipeUp() { return swipeUp;}
|
||||
|
||||
public String[] getMentions() {
|
||||
return mentions;
|
||||
}
|
||||
@ -106,6 +110,10 @@ public final class StoryModel implements Serializable {
|
||||
this.mentions = mentions;
|
||||
}
|
||||
|
||||
public void setSwipeUp(final SwipeUpModel swipeUp) {
|
||||
this.swipeUp = swipeUp;
|
||||
}
|
||||
|
||||
public void setPosition(final int position) {
|
||||
this.position = position;
|
||||
}
|
||||
|
20
app/src/main/java/awais/instagrabber/models/stickers/SwipeUpModel.java
Executable file
20
app/src/main/java/awais/instagrabber/models/stickers/SwipeUpModel.java
Executable 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;
|
||||
}
|
||||
}
|
@ -990,10 +990,10 @@ public final class Utils {
|
||||
}
|
||||
|
||||
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 (itemsToDownload == null || itemsToDownload.size() < 1) return;
|
||||
if (itemsToDownload == null) return;
|
||||
|
||||
if (ContextCompat.checkSelfPermission(context, Utils.PERMS[0]) == PackageManager.PERMISSION_GRANTED)
|
||||
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,
|
||||
final DownloadMethod method, final List<? extends DirectItemMediaModel> itemsToDownload) {
|
||||
final DownloadMethod method, final DirectItemMediaModel selectedItem) {
|
||||
File dir = new File(Environment.getExternalStorageDirectory(), "Download");
|
||||
|
||||
if (settingsHelper.getBoolean(FOLDER_SAVE_TO)) {
|
||||
@ -1014,22 +1014,11 @@ public final class Utils {
|
||||
dir = new File(dir, username);
|
||||
|
||||
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;
|
||||
for (int i = itemsToDownloadSize - 1; i >= 0; i--) {
|
||||
final DirectItemMediaModel selectedItem = itemsToDownload.get(i);
|
||||
|
||||
if (main == null) {
|
||||
new DownloadAsync(context,
|
||||
selectedItem.getMediaType() == MediaItemType.MEDIA_TYPE_VIDEO ? selectedItem.getVideoUrl() : selectedItem.getThumbUrl(),
|
||||
getDownloadSaveFileDm(finalDir, selectedItem, ""),
|
||||
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
|
||||
Toast.makeText(context, R.string.error_creating_folders, Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
|
@ -81,6 +81,15 @@
|
||||
android:textColor="@color/btn_blue_text_color"
|
||||
android:visibility="gone"
|
||||
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
|
||||
android:id="@+id/mention"
|
||||
android:layout_width="match_parent"
|
||||
|
Loading…
Reference in New Issue
Block a user