From 3fb404fa206120ebb9c4547188774f7f2ce91757 Mon Sep 17 00:00:00 2001 From: Austin Huang Date: Tue, 4 Aug 2020 12:51:30 -0400 Subject: [PATCH] v17.2 --- .../instagrabber/activities/StoryViewer.java | 72 ++++++++++++++++++- .../asyncs/i/iStoryStatusFetcher.java | 21 ++++++ .../awais/instagrabber/models/StoryModel.java | 10 +++ .../models/stickers/QuizModel.java | 37 ++++++++++ .../main/res/layout/activity_story_viewer.xml | 11 ++- app/src/main/res/values-zh/strings.xml | 4 +- app/src/main/res/values/strings.xml | 4 +- fastlane/metadata/android/changelogs/38.txt | 2 + 8 files changed, 157 insertions(+), 4 deletions(-) create mode 100755 app/src/main/java/awais/instagrabber/models/stickers/QuizModel.java create mode 100644 fastlane/metadata/android/changelogs/38.txt diff --git a/app/src/main/java/awais/instagrabber/activities/StoryViewer.java b/app/src/main/java/awais/instagrabber/activities/StoryViewer.java index af41abf0..e735199a 100755 --- a/app/src/main/java/awais/instagrabber/activities/StoryViewer.java +++ b/app/src/main/java/awais/instagrabber/activities/StoryViewer.java @@ -62,6 +62,7 @@ import awais.instagrabber.interfaces.SwipeEvent; import awais.instagrabber.models.FeedStoryModel; import awais.instagrabber.models.stickers.PollModel; import awais.instagrabber.models.stickers.QuestionModel; +import awais.instagrabber.models.stickers.QuizModel; import awais.instagrabber.models.PostModel; import awais.instagrabber.models.StoryModel; import awais.instagrabber.models.enums.MediaItemType; @@ -97,6 +98,7 @@ public final class StoryViewer extends BaseLanguageActivity { private PollModel poll; private QuestionModel question; private String[] mentions; + private QuizModel quiz; private StoryModel currentStory; private String url, username; private int slidePos = 0, lastSlidePos = 0; @@ -267,11 +269,25 @@ public final class StoryViewer extends BaseLanguageActivity { .setPositiveButton(R.string.cancel, null) .show(); } + else if (tag instanceof QuizModel) { + quiz = (QuizModel) quiz; + String[] choices = new String[quiz.getChoices().length]; + for (int q = 0; q < choices.length; ++q) { + choices[q] = (quiz.getMyChoice() == q ? "√ " :"") + quiz.getChoices()[q]+ " (" + String.valueOf(quiz.getCounts()[q]) + ")"; + } + new AlertDialog.Builder(this).setTitle(quiz.getMyChoice() > -1 ? getString(R.string.story_quizzed) : quiz.getQuestion()) + .setAdapter(new ArrayAdapter<>(this, android.R.layout.simple_list_item_1, choices), (d,w) -> { + if (quiz.getMyChoice() == -1) new QuizAction().execute(w); + }) + .setPositiveButton(R.string.cancel, null) + .show(); + } }; storyViewerBinding.poll.setOnClickListener(storyActionListener); storyViewerBinding.answer.setOnClickListener(storyActionListener); storyViewerBinding.mention.setOnClickListener(storyActionListener); + storyViewerBinding.quiz.setOnClickListener(storyActionListener); storiesAdapter.setData(storyModels); if (storyModels.length > 1) storyViewerBinding.storiesList.setVisibility(View.VISIBLE); @@ -462,6 +478,10 @@ public final class StoryViewer extends BaseLanguageActivity { storyViewerBinding.mention.setVisibility((mentions != null && mentions.length > 0) ? View.VISIBLE : View.GONE); storyViewerBinding.mention.setTag(mentions); + quiz = currentStory.getQuiz(); + storyViewerBinding.quiz.setVisibility((quiz != null && mentions.length > 0) ? View.VISIBLE : View.GONE); + storyViewerBinding.quiz.setTag(quiz); + releasePlayer(); final Intent intent = getIntent(); if (intent.getBooleanExtra(Constants.EXTRAS_HASHTAG, false)) { @@ -545,6 +565,56 @@ public final class StoryViewer extends BaseLanguageActivity { } } + class QuizAction extends AsyncTask { + int ok = -1; + String action; + + protected Void doInBackground(Integer... rawchoice) { + int choice = rawchoice[0]; + final String cookie = settingsHelper.getString(Constants.COOKIE); + final String url = "https://i.instagram.com/api/v1/media/"+currentStory.getStoryMediaId()+"/"+quiz.getId()+"/story_quiz_answer/"; + try { + JSONObject ogbody = new JSONObject("{\"client_context\":\"" + UUID.randomUUID().toString() + +"\",\"mutation_token\":\"" + UUID.randomUUID().toString() + +"\",\"_csrftoken\":\"" + cookie.split("csrftoken=")[1].split(";")[0] + +"\",\"_uid\":\"" + Utils.getUserIdFromCookie(cookie) + +"\",\"__uuid\":\"" + settingsHelper.getString(Constants.DEVICE_UUID) + +"\"}"); + ogbody.put("answer", String.valueOf(choice)); + String urlParameters = Utils.sign(ogbody.toString()); + final HttpURLConnection urlConnection = (HttpURLConnection) new URL(url).openConnection(); + urlConnection.setRequestMethod("POST"); + urlConnection.setUseCaches(false); + urlConnection.setRequestProperty("User-Agent", Constants.I_USER_AGENT); + urlConnection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded"); + urlConnection.setRequestProperty("Content-Length", Integer.toString(urlParameters.getBytes().length)); + urlConnection.setDoOutput(true); + DataOutputStream wr = new DataOutputStream(urlConnection.getOutputStream()); + wr.writeBytes(urlParameters); + wr.flush(); + wr.close(); + Log.d("austin_debug", "quiz: "+url+" "+cookie+" "+urlParameters); + urlConnection.connect(); + if (urlConnection.getResponseCode() == HttpURLConnection.HTTP_OK) { + ok = choice; + } + else Toast.makeText(getApplicationContext(), R.string.downloader_unknown_error, Toast.LENGTH_SHORT).show(); + urlConnection.disconnect(); + } catch (Throwable ex) { + Log.e("austin_debug", "quiz: " + ex); + } + return null; + } + + @Override + protected void onPostExecute(Void result) { + if (ok > -1) { + quiz.setMyChoice(ok); + Toast.makeText(getApplicationContext(), R.string.answered_story, Toast.LENGTH_SHORT).show(); + } + } + } + class RespondAction extends AsyncTask { boolean ok = false; String action; @@ -581,7 +651,7 @@ public final class StoryViewer extends BaseLanguageActivity { else Toast.makeText(getApplicationContext(), R.string.downloader_unknown_error, Toast.LENGTH_SHORT).show(); urlConnection.disconnect(); } catch (Throwable ex) { - Log.e("austin_debug", "vote: " + ex); + Log.e("austin_debug", "respond: " + ex); } return null; } diff --git a/app/src/main/java/awais/instagrabber/asyncs/i/iStoryStatusFetcher.java b/app/src/main/java/awais/instagrabber/asyncs/i/iStoryStatusFetcher.java index 9c728c24..5b7c9ccf 100755 --- a/app/src/main/java/awais/instagrabber/asyncs/i/iStoryStatusFetcher.java +++ b/app/src/main/java/awais/instagrabber/asyncs/i/iStoryStatusFetcher.java @@ -13,6 +13,7 @@ import awais.instagrabber.BuildConfig; import awais.instagrabber.interfaces.FetchListener; import awais.instagrabber.models.stickers.PollModel; import awais.instagrabber.models.stickers.QuestionModel; +import awais.instagrabber.models.stickers.QuizModel; import awais.instagrabber.models.StoryModel; import awais.instagrabber.models.enums.MediaItemType; import awais.instagrabber.utils.Constants; @@ -100,6 +101,26 @@ public final class iStoryStatusFetcher extends AsyncTask + diff --git a/app/src/main/res/values-zh/strings.xml b/app/src/main/res/values-zh/strings.xml index 26190480..650abf06 100755 --- a/app/src/main/res/values-zh/strings.xml +++ b/app/src/main/res/values-zh/strings.xml @@ -185,8 +185,10 @@ 感谢阁下更新InstaGrabber! 应用崩溃了 糟糕.. 应用崩溃了,不过别担心,你可以向开发者发送错误报告来帮助他修复问题。(: - 回答 + 回答 在此回答... 回答完成! 提及 + 测验 + 您已回答! diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 5031003d..f260760b 100755 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -67,9 +67,11 @@ Vote Vote successful! You have already voted! - Answer + Respond Answer... Answer successful! + Quiz + You have already answered! Mentions This Account is Private You can log in via Settings on the bottom-right corner. Or, you can view public accounts without login! diff --git a/fastlane/metadata/android/changelogs/38.txt b/fastlane/metadata/android/changelogs/38.txt new file mode 100644 index 00000000..1ac1f9c7 --- /dev/null +++ b/fastlane/metadata/android/changelogs/38.txt @@ -0,0 +1,2 @@ +* You can now respond to quizzes, plus you get to see correct answer beforehand (FYI: I will not support music questions) +* Fixed feed story fetch approach \ No newline at end of file