diff --git a/app/src/main/java/awais/instagrabber/asyncs/ProfilePictureFetcher.java b/app/src/main/java/awais/instagrabber/asyncs/ProfilePictureFetcher.java index 6fe750a1..433697de 100755 --- a/app/src/main/java/awais/instagrabber/asyncs/ProfilePictureFetcher.java +++ b/app/src/main/java/awais/instagrabber/asyncs/ProfilePictureFetcher.java @@ -40,51 +40,34 @@ public final class ProfilePictureFetcher extends AsyncTask { protected String doInBackground(final Void... voids) { String out = null; if (isHashtag) out = picUrl; - else try { - final HttpURLConnection conn = - (HttpURLConnection) new URL("https://i.instagram.com/api/v1/users/"+userId+"/info/").openConnection(); - conn.setUseCaches(false); - conn.setRequestMethod("GET"); - conn.setRequestProperty("User-Agent", Constants.USER_AGENT); + else if (Utils.settingsHelper.getBoolean(Constants.INSTADP)) try { + final HttpURLConnection backup = + (HttpURLConnection) new URL("https://instadp.com/fullsize/" + userName).openConnection(); + backup.setUseCaches(false); + backup.setRequestMethod("GET"); + backup.setRequestProperty("User-Agent", Constants.A_USER_AGENT); - final String result = conn.getResponseCode() == HttpURLConnection.HTTP_OK ? NetworkUtils.readFromConnection(conn) : null; - conn.disconnect(); + final String instadp = backup.getResponseCode() == HttpURLConnection.HTTP_OK ? NetworkUtils.readFromConnection(backup) : null; + backup.disconnect(); - if (!TextUtils.isEmpty(result)) { - JSONObject data = new JSONObject(result).getJSONObject("user"); - if (data.has("hd_profile_pic_url_info")) - out = data.getJSONObject("hd_profile_pic_url_info").optString("url"); - } + if (!TextUtils.isEmpty(instadp)) { + final Document doc = Jsoup.parse(instadp); + boolean fallback = false; - if (TextUtils.isEmpty(out) && Utils.settingsHelper.getBoolean(Constants.INSTADP)) { - final HttpURLConnection backup = - (HttpURLConnection) new URL("https://instadp.com/fullsize/" + userName).openConnection(); - backup.setUseCaches(false); - backup.setRequestMethod("GET"); - backup.setRequestProperty("User-Agent", Constants.A_USER_AGENT); + final int imgIndex = instadp.indexOf("preloadImg('"), lastIndex; - final String instadp = backup.getResponseCode() == HttpURLConnection.HTTP_OK ? NetworkUtils.readFromConnection(backup) : null; - backup.disconnect(); - - if (!TextUtils.isEmpty(instadp)) { - final Document doc = Jsoup.parse(instadp); - boolean fallback = false; - - final int imgIndex = instadp.indexOf("preloadImg('"), lastIndex; - - Element element = doc.selectFirst(".instadp"); - if (element != null && (element = element.selectFirst(".picture")) != null) - out = element.attr("src"); - else if ((element = doc.selectFirst(".download-btn")) != null) - out = element.attr("href"); - else if (imgIndex != -1 && (lastIndex = instadp.indexOf("')", imgIndex)) != -1) - out = instadp.substring(imgIndex + 12, lastIndex); - else { - final Elements imgs = doc.getElementsByTag("img"); - for (final Element img : imgs) { - final String imgStr = img.toString(); - if (imgStr.contains("cdninstagram.com")) out = img.attr("src"); - } + Element element = doc.selectFirst(".instadp"); + if (element != null && (element = element.selectFirst(".picture")) != null) + out = element.attr("src"); + else if ((element = doc.selectFirst(".download-btn")) != null) + out = element.attr("href"); + else if (imgIndex != -1 && (lastIndex = instadp.indexOf("')", imgIndex)) != -1) + out = instadp.substring(imgIndex + 12, lastIndex); + else { + final Elements imgs = doc.getElementsByTag("img"); + for (final Element img : imgs) { + final String imgStr = img.toString(); + if (imgStr.contains("cdninstagram.com")) out = img.attr("src"); } } } diff --git a/app/src/main/java/awais/instagrabber/dialogs/ProfilePicDialogFragment.java b/app/src/main/java/awais/instagrabber/dialogs/ProfilePicDialogFragment.java index 6a468cf3..1e75eba4 100644 --- a/app/src/main/java/awais/instagrabber/dialogs/ProfilePicDialogFragment.java +++ b/app/src/main/java/awais/instagrabber/dialogs/ProfilePicDialogFragment.java @@ -9,6 +9,7 @@ import android.graphics.drawable.ColorDrawable; import android.os.AsyncTask; import android.os.Bundle; import android.os.Environment; +import android.util.Log; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; @@ -19,6 +20,7 @@ import androidx.annotation.NonNull; import androidx.annotation.Nullable; import androidx.core.content.ContextCompat; import androidx.fragment.app.DialogFragment; +import androidx.fragment.app.FragmentActivity; import com.facebook.drawee.backends.pipeline.Fresco; import com.facebook.drawee.controller.BaseControllerListener; @@ -30,9 +32,20 @@ import java.io.File; import awais.instagrabber.R; import awais.instagrabber.asyncs.ProfilePictureFetcher; import awais.instagrabber.databinding.DialogProfilepicBinding; +import awais.instagrabber.db.entities.Account; +import awais.instagrabber.db.repositories.RepositoryCallback; import awais.instagrabber.interfaces.FetchListener; +import awais.instagrabber.models.StoryModel; +import awais.instagrabber.repositories.responses.UserInfo; +import awais.instagrabber.utils.Constants; +import awais.instagrabber.utils.CookieUtils; import awais.instagrabber.utils.DownloadUtils; import awais.instagrabber.utils.TextUtils; +import awais.instagrabber.webservices.ProfileService; +import awais.instagrabber.webservices.ServiceCallback; +import awais.instagrabber.webservices.StoriesService; + +import static awais.instagrabber.utils.Utils.settingsHelper; public class ProfilePicDialogFragment extends DialogFragment { private static final String TAG = "ProfilePicDlgFragment"; @@ -41,9 +54,15 @@ public class ProfilePicDialogFragment extends DialogFragment { private final String name; private final String fallbackUrl; + private boolean isLoggedIn; private DialogProfilepicBinding binding; private String url; + private final FetchListener fetchListener = profileUrl -> { + url = profileUrl; + setupPhoto(); + }; + public ProfilePicDialogFragment(final String id, final String name, final String fallbackUrl) { this.id = id; this.name = name; @@ -55,6 +74,8 @@ public class ProfilePicDialogFragment extends DialogFragment { final ViewGroup container, final Bundle savedInstanceState) { binding = DialogProfilepicBinding.inflate(inflater, container, false); + final String cookie = settingsHelper.getString(Constants.COOKIE); + isLoggedIn = !TextUtils.isEmpty(cookie) && CookieUtils.getUserIdFromCookie(cookie) != null; return binding.getRoot(); } @@ -83,7 +104,8 @@ public class ProfilePicDialogFragment extends DialogFragment { public void onViewCreated(@NonNull final View view, @Nullable final Bundle savedInstanceState) { super.onViewCreated(view, savedInstanceState); init(); - fetchPhoto(); + if (id.contains("_")) fetchStory(); + else fetchAvatar(); } private void init() { @@ -106,37 +128,75 @@ public class ProfilePicDialogFragment extends DialogFragment { } } - private void fetchPhoto() { - final FetchListener fetchListener = profileUrl -> { - url = profileUrl; - if (TextUtils.isEmpty(url)) { - url = fallbackUrl; - } - final DraweeController controller = Fresco - .newDraweeControllerBuilder() - .setUri(url) - .setOldController(binding.imageViewer.getController()) - .setControllerListener(new BaseControllerListener() { - @Override - public void onFailure(final String id, final Throwable throwable) { - super.onFailure(id, throwable); - binding.download.setVisibility(View.GONE); - binding.progressView.setVisibility(View.GONE); - } + private void fetchAvatar() { + if (isLoggedIn) { + final ProfileService profileService = ProfileService.getInstance(); + profileService.getUserInfo(id, new ServiceCallback() { + @Override + public void onSuccess(final UserInfo result) { + if (result != null) { + fetchListener.onResult(result.getHDProfilePicUrl()); + } + } - @Override - public void onFinalImageSet(final String id, - final ImageInfo imageInfo, - final Animatable animatable) { - super.onFinalImageSet(id, imageInfo, animatable); - binding.download.setVisibility(View.VISIBLE); - binding.progressView.setVisibility(View.GONE); - } - }) - .build(); - binding.imageViewer.setController(controller); - }; - new ProfilePictureFetcher(name, id, fetchListener, url, false).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); + @Override + public void onFailure(final Throwable t) { + final Context context = getContext(); + Toast.makeText(context, R.string.downloader_unknown_error, Toast.LENGTH_SHORT).show(); + getDialog().dismiss(); + } + }); + } + else new ProfilePictureFetcher(name, id, fetchListener, fallbackUrl, false).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); + } + + private void fetchStory() { + final StoriesService storiesService = StoriesService.getInstance(); + storiesService.fetch(id, new ServiceCallback() { + @Override + public void onSuccess(final StoryModel result) { + if (result != null) { + fetchListener.onResult(result.getStoryUrl()); + } + } + + @Override + public void onFailure(final Throwable t) { + final Context context = getContext(); + Log.d("austin_debug", "error", t); + Toast.makeText(context, R.string.downloader_unknown_error, Toast.LENGTH_SHORT).show(); + getDialog().dismiss(); + } + }); + } + + private void setupPhoto() { + if (TextUtils.isEmpty(url)) { + url = fallbackUrl; + } + final DraweeController controller = Fresco + .newDraweeControllerBuilder() + .setUri(url) + .setOldController(binding.imageViewer.getController()) + .setControllerListener(new BaseControllerListener() { + @Override + public void onFailure(final String id, final Throwable throwable) { + super.onFailure(id, throwable); + binding.download.setVisibility(View.GONE); + binding.progressView.setVisibility(View.GONE); + } + + @Override + public void onFinalImageSet(final String id, + final ImageInfo imageInfo, + final Animatable animatable) { + super.onFinalImageSet(id, imageInfo, animatable); + binding.download.setVisibility(View.VISIBLE); + binding.progressView.setVisibility(View.GONE); + } + }) + .build(); + binding.imageViewer.setController(controller); } private void downloadProfilePicture() { diff --git a/app/src/main/java/awais/instagrabber/repositories/StoriesRepository.java b/app/src/main/java/awais/instagrabber/repositories/StoriesRepository.java index c66368de..4f61964c 100644 --- a/app/src/main/java/awais/instagrabber/repositories/StoriesRepository.java +++ b/app/src/main/java/awais/instagrabber/repositories/StoriesRepository.java @@ -14,6 +14,9 @@ import retrofit2.http.QueryMap; import retrofit2.http.Url; public interface StoriesRepository { + @GET("/api/v1/media/{mediaId}/info/") + Call fetch(@Path("mediaId") final String mediaId); + // this one is the same as MediaRepository.fetch BUT you need to make sure it's a story @FormUrlEncoded @POST("/api/v1/feed/reels_tray/") diff --git a/app/src/main/java/awais/instagrabber/repositories/responses/UserInfo.java b/app/src/main/java/awais/instagrabber/repositories/responses/UserInfo.java index 4cca9b69..995beab9 100644 --- a/app/src/main/java/awais/instagrabber/repositories/responses/UserInfo.java +++ b/app/src/main/java/awais/instagrabber/repositories/responses/UserInfo.java @@ -2,15 +2,18 @@ package awais.instagrabber.repositories.responses; public class UserInfo { private final String pk; - private final String username; - private final String fullName; - private final String profilePicUrl; + private final String username, fullName, profilePicUrl, hdProfilePicUrl; - public UserInfo(final String pk, final String username, final String fullName, final String profilePicUrl) { + public UserInfo(final String 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 String getPk() { @@ -29,6 +32,10 @@ public class UserInfo { return profilePicUrl; } + public String getHDProfilePicUrl() { + return hdProfilePicUrl; + } + @Override public String toString() { return "UserInfo{" + @@ -36,6 +43,7 @@ public class UserInfo { ", username='" + username + '\'' + ", fullName='" + fullName + '\'' + ", profilePicUrl='" + profilePicUrl + '\'' + + ", hdProfilePicUrl='" + hdProfilePicUrl + '\'' + '}'; } } diff --git a/app/src/main/java/awais/instagrabber/utils/ResponseBodyUtils.java b/app/src/main/java/awais/instagrabber/utils/ResponseBodyUtils.java index 97248ba1..c4633f04 100644 --- a/app/src/main/java/awais/instagrabber/utils/ResponseBodyUtils.java +++ b/app/src/main/java/awais/instagrabber/utils/ResponseBodyUtils.java @@ -18,6 +18,7 @@ import awais.instagrabber.BuildConfig; import awais.instagrabber.models.FeedModel; import awais.instagrabber.models.PostChild; import awais.instagrabber.models.ProfileModel; +import awais.instagrabber.models.StoryModel; import awais.instagrabber.models.direct_messages.DirectItemModel; import awais.instagrabber.models.direct_messages.InboxThreadModel; import awais.instagrabber.models.enums.DirectItemType; @@ -25,6 +26,11 @@ import awais.instagrabber.models.enums.InboxReadState; import awais.instagrabber.models.enums.MediaItemType; import awais.instagrabber.models.enums.RavenExpiringMediaType; import awais.instagrabber.models.enums.RavenMediaViewType; +import awais.instagrabber.models.stickers.PollModel; +import awais.instagrabber.models.stickers.QuestionModel; +import awais.instagrabber.models.stickers.QuizModel; +import awais.instagrabber.models.stickers.SliderModel; +import awais.instagrabber.models.stickers.SwipeUpModel; import awaisomereport.LogCollector; import static awais.instagrabber.utils.Utils.settingsHelper; @@ -875,4 +881,127 @@ public final class ResponseBodyUtils { } return sliderItems; } + + public static StoryModel parseStoryItem(final JSONObject data, + final boolean isLoc, + final boolean isHashtag, + final String localUsername) throws JSONException { + final boolean isVideo = data.has("video_duration"); + final StoryModel model = new StoryModel(data.getString("id"), + data.getJSONObject("image_versions2").getJSONArray("candidates").getJSONObject(0) + .getString("url"), + isVideo ? MediaItemType.MEDIA_TYPE_VIDEO : MediaItemType.MEDIA_TYPE_IMAGE, + data.optLong("taken_at", 0), + (isLoc || isHashtag) + ? data.getJSONObject("user").getString("username") + : localUsername, + data.getJSONObject("user").getString("pk"), + data.optBoolean("can_reply")); + + final JSONArray videoResources = data.optJSONArray("video_versions"); + if (isVideo && videoResources != null) + model.setVideoUrl(ResponseBodyUtils.getHighQualityPost(videoResources, true, true, false)); + + if (data.has("story_feed_media")) { + model.setTappableShortCode(data.getJSONArray("story_feed_media").getJSONObject(0).optString("media_code")); + } + + // TODO: this may not be limited to spotify + if (!data.isNull("story_app_attribution")) + model.setSpotify(data.getJSONObject("story_app_attribution").optString("content_url").split("\\?")[0]); + + if (data.has("story_polls")) { + final JSONArray storyPolls = data.optJSONArray("story_polls"); + JSONObject tappableObject = null; + if (storyPolls != null) { + tappableObject = storyPolls.getJSONObject(0).optJSONObject("poll_sticker"); + } + if (tappableObject != null) model.setPoll(new PollModel( + String.valueOf(tappableObject.getLong("poll_id")), + tappableObject.getString("question"), + tappableObject.getJSONArray("tallies").getJSONObject(0).getString("text"), + tappableObject.getJSONArray("tallies").getJSONObject(0).getInt("count"), + tappableObject.getJSONArray("tallies").getJSONObject(1).getString("text"), + tappableObject.getJSONArray("tallies").getJSONObject(1).getInt("count"), + tappableObject.optInt("viewer_vote", -1) + )); + } + if (data.has("story_questions")) { + final JSONObject tappableObject = data.getJSONArray("story_questions").getJSONObject(0) + .optJSONObject("question_sticker"); + if (tappableObject != null && !tappableObject.getString("question_type").equals("music")) + model.setQuestion(new QuestionModel( + String.valueOf(tappableObject.getLong("question_id")), + tappableObject.getString("question") + )); + } + if (data.has("story_quizs")) { + JSONObject tappableObject = data.getJSONArray("story_quizs").getJSONObject(0).optJSONObject("quiz_sticker"); + if (tappableObject != null) { + String[] choices = new String[tappableObject.getJSONArray("tallies").length()]; + Long[] counts = new Long[choices.length]; + for (int q = 0; q < choices.length; ++q) { + JSONObject tempchoice = tappableObject.getJSONArray("tallies").getJSONObject(q); + choices[q] = (q == tappableObject.getInt("correct_answer") ? "*** " : "") + + tempchoice.getString("text"); + counts[q] = tempchoice.getLong("count"); + } + model.setQuiz(new QuizModel( + String.valueOf(tappableObject.getLong("quiz_id")), + tappableObject.getString("question"), + choices, + counts, + tappableObject.optInt("viewer_answer", -1) + )); + } + } + 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")) { + model.setSwipeUp(new SwipeUpModel(swipeUpUrl, data.getString("link_text"))); + } + } + if (data.has("story_sliders")) { + final JSONObject tappableObject = data.getJSONArray("story_sliders").getJSONObject(0) + .optJSONObject("slider_sticker"); + if (tappableObject != null) + model.setSlider(new SliderModel( + String.valueOf(tappableObject.getLong("slider_id")), + tappableObject.getString("question"), + tappableObject.getString("emoji"), + tappableObject.getBoolean("viewer_can_vote"), + tappableObject.getDouble("slider_vote_average"), + tappableObject.getInt("slider_vote_count"), + tappableObject.optDouble("viewer_vote") + )); + } + JSONArray hashtags = data.optJSONArray("story_hashtags"); + JSONArray locations = data.optJSONArray("story_locations"); + JSONArray atmarks = data.optJSONArray("reel_mentions"); + String[] mentions = new String[(hashtags == null ? 0 : hashtags.length()) + + (atmarks == null ? 0 : atmarks.length()) + + (locations == null ? 0 : locations.length())]; + if (hashtags != null) { + for (int h = 0; h < hashtags.length(); ++h) { + mentions[h] = "#" + hashtags.getJSONObject(h).getJSONObject("hashtag").getString("name"); + } + } + if (atmarks != null) { + for (int h = 0; h < atmarks.length(); ++h) { + mentions[h + (hashtags == null ? 0 : hashtags.length())] = + "@" + atmarks.getJSONObject(h).getJSONObject("user").getString("username"); + } + } + if (locations != null) { + for (int h = 0; h < locations.length(); ++h) { + mentions[h + (hashtags == null ? 0 : hashtags.length()) + (atmarks == null ? 0 : atmarks.length())] = + locations.getJSONObject(h).getJSONObject("location").getString("short_name") + + " (" + locations.getJSONObject(h).getJSONObject("location").getLong("pk") + ")"; + } + } + if (mentions.length != 0) model.setMentions(mentions); + + return model; + } } diff --git a/app/src/main/java/awais/instagrabber/webservices/ProfileService.java b/app/src/main/java/awais/instagrabber/webservices/ProfileService.java index 056463d9..495cd06c 100644 --- a/app/src/main/java/awais/instagrabber/webservices/ProfileService.java +++ b/app/src/main/java/awais/instagrabber/webservices/ProfileService.java @@ -63,7 +63,9 @@ public class ProfileService extends BaseService { uid, user.getString(Constants.EXTRAS_USERNAME), user.optString("full_name"), - user.optString("profile_pic_url") + user.optString("profile_pic_url"), + user.has("hd_profile_pic_url_info") + ? user.getJSONObject("hd_profile_pic_url_info").optString("url") : null ); callback.onSuccess(userInfo); } catch (JSONException e) { diff --git a/app/src/main/java/awais/instagrabber/webservices/StoriesService.java b/app/src/main/java/awais/instagrabber/webservices/StoriesService.java index 50cc9fef..8d2bf5d3 100644 --- a/app/src/main/java/awais/instagrabber/webservices/StoriesService.java +++ b/app/src/main/java/awais/instagrabber/webservices/StoriesService.java @@ -1,6 +1,5 @@ package awais.instagrabber.webservices; -import android.os.Handler; import android.util.Log; import androidx.annotation.NonNull; @@ -9,11 +8,6 @@ import org.json.JSONArray; import org.json.JSONException; import org.json.JSONObject; -import java.io.IOException; -import java.io.InputStream; -import java.io.InputStreamReader; -import java.io.Reader; -import java.nio.charset.StandardCharsets; import java.util.ArrayList; import java.util.HashMap; import java.util.List; @@ -63,6 +57,37 @@ public class StoriesService extends BaseService { return instance; } + public void fetch(final String mediaId, + final ServiceCallback callback) { + final Call request = repository.fetch(mediaId); + request.enqueue(new Callback() { + @Override + public void onResponse(@NonNull final Call call, + @NonNull final Response response) { + if (callback == null) return; + final String body = response.body(); + if (body == null) { + callback.onSuccess(null); + return; + } + try { + final JSONObject itemJson = new JSONObject(body).getJSONArray("items").getJSONObject(0); + callback.onSuccess(ResponseBodyUtils.parseStoryItem(itemJson, false, false, null)); + } catch (JSONException e) { + callback.onFailure(e); + } + } + + @Override + public void onFailure(@NonNull final Call call, + @NonNull final Throwable t) { + if (callback != null) { + callback.onFailure(t); + } + } + }); + } + public void getFeedStories(final String csrfToken, final ServiceCallback> callback) { final Map form = new HashMap<>(4); form.put("reason", "cold_start"); @@ -198,122 +223,7 @@ public class StoriesService extends BaseService { final List models = new ArrayList<>(); for (int i = 0; i < mediaLen; ++i) { data = media.getJSONObject(i); - final boolean isVideo = data.has("video_duration"); - final StoryModel model = new StoryModel(data.getString("id"), - data.getJSONObject("image_versions2").getJSONArray("candidates").getJSONObject(0) - .getString("url"), - isVideo ? MediaItemType.MEDIA_TYPE_VIDEO : MediaItemType.MEDIA_TYPE_IMAGE, - data.optLong("taken_at", 0), - (isLoc || isHashtag) - ? data.getJSONObject("user").getString("username") - : localUsername, - data.getJSONObject("user").getString("pk"), - data.getBoolean("can_reply")); - - final JSONArray videoResources = data.optJSONArray("video_versions"); - if (isVideo && videoResources != null) - model.setVideoUrl(ResponseBodyUtils.getHighQualityPost(videoResources, true, true, false)); - - if (data.has("story_feed_media")) { - model.setTappableShortCode(data.getJSONArray("story_feed_media").getJSONObject(0).optString("media_code")); - } - - // TODO: this may not be limited to spotify - if (!data.isNull("story_app_attribution")) - model.setSpotify(data.getJSONObject("story_app_attribution").optString("content_url").split("\\?")[0]); - - if (data.has("story_polls")) { - final JSONArray storyPolls = data.optJSONArray("story_polls"); - JSONObject tappableObject = null; - if (storyPolls != null) { - tappableObject = storyPolls.getJSONObject(0).optJSONObject("poll_sticker"); - } - if (tappableObject != null) model.setPoll(new PollModel( - String.valueOf(tappableObject.getLong("poll_id")), - tappableObject.getString("question"), - tappableObject.getJSONArray("tallies").getJSONObject(0).getString("text"), - tappableObject.getJSONArray("tallies").getJSONObject(0).getInt("count"), - tappableObject.getJSONArray("tallies").getJSONObject(1).getString("text"), - tappableObject.getJSONArray("tallies").getJSONObject(1).getInt("count"), - tappableObject.optInt("viewer_vote", -1) - )); - } - if (data.has("story_questions")) { - final JSONObject tappableObject = data.getJSONArray("story_questions").getJSONObject(0) - .optJSONObject("question_sticker"); - if (tappableObject != null && !tappableObject.getString("question_type").equals("music")) - model.setQuestion(new QuestionModel( - String.valueOf(tappableObject.getLong("question_id")), - tappableObject.getString("question") - )); - } - if (data.has("story_quizs")) { - JSONObject tappableObject = data.getJSONArray("story_quizs").getJSONObject(0).optJSONObject("quiz_sticker"); - if (tappableObject != null) { - String[] choices = new String[tappableObject.getJSONArray("tallies").length()]; - Long[] counts = new Long[choices.length]; - for (int q = 0; q < choices.length; ++q) { - JSONObject tempchoice = tappableObject.getJSONArray("tallies").getJSONObject(q); - choices[q] = (q == tappableObject.getInt("correct_answer") ? "*** " : "") - + tempchoice.getString("text"); - counts[q] = tempchoice.getLong("count"); - } - model.setQuiz(new QuizModel( - String.valueOf(tappableObject.getLong("quiz_id")), - tappableObject.getString("question"), - choices, - counts, - tappableObject.optInt("viewer_answer", -1) - )); - } - } - 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")) { - model.setSwipeUp(new SwipeUpModel(swipeUpUrl, data.getString("link_text"))); - } - } - if (data.has("story_sliders")) { - final JSONObject tappableObject = data.getJSONArray("story_sliders").getJSONObject(0) - .optJSONObject("slider_sticker"); - if (tappableObject != null) - model.setSlider(new SliderModel( - String.valueOf(tappableObject.getLong("slider_id")), - tappableObject.getString("question"), - tappableObject.getString("emoji"), - tappableObject.getBoolean("viewer_can_vote"), - tappableObject.getDouble("slider_vote_average"), - tappableObject.getInt("slider_vote_count"), - tappableObject.optDouble("viewer_vote") - )); - } - JSONArray hashtags = data.optJSONArray("story_hashtags"); - JSONArray locations = data.optJSONArray("story_locations"); - JSONArray atmarks = data.optJSONArray("reel_mentions"); - String[] mentions = new String[(hashtags == null ? 0 : hashtags.length()) - + (atmarks == null ? 0 : atmarks.length()) - + (locations == null ? 0 : locations.length())]; - if (hashtags != null) { - for (int h = 0; h < hashtags.length(); ++h) { - mentions[h] = "#" + hashtags.getJSONObject(h).getJSONObject("hashtag").getString("name"); - } - } - if (atmarks != null) { - for (int h = 0; h < atmarks.length(); ++h) { - mentions[h + (hashtags == null ? 0 : hashtags.length())] = - "@" + atmarks.getJSONObject(h).getJSONObject("user").getString("username"); - } - } - if (locations != null) { - for (int h = 0; h < locations.length(); ++h) { - mentions[h + (hashtags == null ? 0 : hashtags.length()) + (atmarks == null ? 0 : atmarks.length())] = - locations.getJSONObject(h).getJSONObject("location").getString("short_name") - + " (" + locations.getJSONObject(h).getJSONObject("location").getLong("pk") + ")"; - } - } - if (mentions.length != 0) model.setMentions(mentions); - models.add(model); + models.add(ResponseBodyUtils.parseStoryItem(data, isLoc, isHashtag, localUsername)); } callback.onSuccess(models); } else { diff --git a/app/src/main/res/layout/dialog_profilepic.xml b/app/src/main/res/layout/dialog_profilepic.xml index 38db7201..c589cad3 100644 --- a/app/src/main/res/layout/dialog_profilepic.xml +++ b/app/src/main/res/layout/dialog_profilepic.xml @@ -36,6 +36,7 @@ android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="bottom|end" + android:backgroundTint="@color/black_a50" android:text="@string/action_download" android:visibility="gone" app:icon="@drawable/ic_download"