From ab37c2d72b68cd6cd7c2300613d13ae945aebc51 Mon Sep 17 00:00:00 2001 From: Austin Huang Date: Tue, 22 Sep 2020 23:15:57 -0400 Subject: [PATCH] dm button on profile?! (quick & dirty warning) --- .../CreateThreadAction.java} | 13 ++++---- .../fragments/StoryViewerFragment.java | 4 +-- .../fragments/main/ProfileFragment.java | 11 ++++++- app/src/main/res/layout/fragment_profile.xml | 19 +++++++++++ .../main/res/navigation/profile_nav_graph.xml | 32 ++++++++++++++++++- app/src/main/res/values/color.xml | 2 ++ app/src/main/res/values/strings.xml | 1 + 7 files changed, 71 insertions(+), 11 deletions(-) rename app/src/main/java/awais/instagrabber/asyncs/{CommentAction.java => direct_messages/CreateThreadAction.java} (85%) diff --git a/app/src/main/java/awais/instagrabber/asyncs/CommentAction.java b/app/src/main/java/awais/instagrabber/asyncs/direct_messages/CreateThreadAction.java similarity index 85% rename from app/src/main/java/awais/instagrabber/asyncs/CommentAction.java rename to app/src/main/java/awais/instagrabber/asyncs/direct_messages/CreateThreadAction.java index 9285bed7..cda2ef34 100644 --- a/app/src/main/java/awais/instagrabber/asyncs/CommentAction.java +++ b/app/src/main/java/awais/instagrabber/asyncs/direct_messages/CreateThreadAction.java @@ -1,4 +1,4 @@ -package awais.instagrabber.asyncs; +package awais.instagrabber.asyncs.direct_messages; import android.os.AsyncTask; import android.util.Log; @@ -9,7 +9,6 @@ import java.io.DataOutputStream; import java.net.HttpURLConnection; import java.net.URL; -import awais.instagrabber.models.StoryModel; import awais.instagrabber.utils.Constants; import awais.instagrabber.utils.CookieUtils; import awais.instagrabber.utils.NetworkUtils; @@ -17,16 +16,16 @@ import awais.instagrabber.utils.Utils; import static awais.instagrabber.utils.Utils.settingsHelper; -public class CommentAction extends AsyncTask { +public class CreateThreadAction extends AsyncTask { private static final String TAG = "CommentAction"; private final String cookie; - private final StoryModel storyModel; + private final String userId; private final OnTaskCompleteListener onTaskCompleteListener; - public CommentAction(final String cookie, final StoryModel storyModel, final OnTaskCompleteListener onTaskCompleteListener) { + public CreateThreadAction(final String cookie, final String userId, final OnTaskCompleteListener onTaskCompleteListener) { this.cookie = cookie; - this.storyModel = storyModel; + this.userId = userId; this.onTaskCompleteListener = onTaskCompleteListener; } @@ -41,7 +40,7 @@ public class CommentAction extends AsyncTask { final String urlParameters = Utils.sign("{\"_csrftoken\":\"" + cookie.split("csrftoken=")[1].split(";")[0] + "\",\"_uid\":\"" + CookieUtils.getUserIdFromCookie(cookie) + "\",\"__uuid\":\"" + settingsHelper.getString(Constants.DEVICE_UUID) - + "\",\"recipient_users\":\"[" + storyModel.getUserId() // <- string of array of number (not joking) + + "\",\"recipient_users\":\"[" + userId // <- string of array of number (not joking) + "]\"}"); urlConnection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded"); if (urlParameters != null) { diff --git a/app/src/main/java/awais/instagrabber/fragments/StoryViewerFragment.java b/app/src/main/java/awais/instagrabber/fragments/StoryViewerFragment.java index 57308082..29c50a80 100644 --- a/app/src/main/java/awais/instagrabber/fragments/StoryViewerFragment.java +++ b/app/src/main/java/awais/instagrabber/fragments/StoryViewerFragment.java @@ -62,12 +62,12 @@ import java.util.List; import awais.instagrabber.BuildConfig; import awais.instagrabber.R; import awais.instagrabber.adapters.StoriesAdapter; -import awais.instagrabber.asyncs.CommentAction; import awais.instagrabber.asyncs.DownloadAsync; import awais.instagrabber.asyncs.QuizAction; import awais.instagrabber.asyncs.RespondAction; import awais.instagrabber.asyncs.SeenAction; import awais.instagrabber.asyncs.VoteAction; +import awais.instagrabber.asyncs.direct_messages.CreateThreadAction; import awais.instagrabber.asyncs.direct_messages.DirectThreadBroadcaster; import awais.instagrabber.customviews.helpers.SwipeGestureListener; import awais.instagrabber.databinding.FragmentStoryViewerBinding; @@ -196,7 +196,7 @@ public class StoryViewerFragment extends Fragment { new AlertDialog.Builder(context) .setTitle(R.string.reply_story) .setView(input) - .setPositiveButton(R.string.ok, (d, w) -> new CommentAction(cookie, currentStory, threadId -> { + .setPositiveButton(R.string.ok, (d, w) -> new CreateThreadAction(cookie, currentStory.getUserId(), threadId -> { try { final DirectThreadBroadcaster.StoryReplyBroadcastOptions options = new DirectThreadBroadcaster.StoryReplyBroadcastOptions( input.getText().toString(), diff --git a/app/src/main/java/awais/instagrabber/fragments/main/ProfileFragment.java b/app/src/main/java/awais/instagrabber/fragments/main/ProfileFragment.java index 638f3749..62e09a53 100644 --- a/app/src/main/java/awais/instagrabber/fragments/main/ProfileFragment.java +++ b/app/src/main/java/awais/instagrabber/fragments/main/ProfileFragment.java @@ -56,6 +56,7 @@ import awais.instagrabber.asyncs.HighlightsFetcher; import awais.instagrabber.asyncs.PostsFetcher; import awais.instagrabber.asyncs.ProfileFetcher; import awais.instagrabber.asyncs.UsernameFetcher; +import awais.instagrabber.asyncs.direct_messages.CreateThreadAction; import awais.instagrabber.asyncs.i.iStoryStatusFetcher; import awais.instagrabber.customviews.PrimaryActionModeCallback; import awais.instagrabber.customviews.PrimaryActionModeCallback.CallbacksHelper; @@ -484,11 +485,13 @@ public class ProfileFragment extends Fragment implements SwipeRefreshLayout.OnRe binding.btnTagged.setVisibility(View.VISIBLE); binding.btnSaved.setVisibility(View.VISIBLE); binding.btnLiked.setVisibility(View.VISIBLE); + binding.btnDM.setVisibility(View.GONE); binding.btnSaved.setText(R.string.saved); } else { binding.btnTagged.setVisibility(View.GONE); binding.btnSaved.setVisibility(View.GONE); binding.btnLiked.setVisibility(View.GONE); + binding.btnDM.setVisibility(View.VISIBLE); // maybe there is a judgment mechanism? binding.btnFollow.setVisibility(View.VISIBLE); if (profileModel.getFollowing()) { binding.btnFollow.setText(R.string.unfollow); @@ -508,7 +511,7 @@ public class ProfileFragment extends Fragment implements SwipeRefreshLayout.OnRe restrictMenuItem.setTitle(R.string.restrict); } } - binding.btnTagged.setVisibility(View.VISIBLE); + binding.btnTagged.setVisibility(profileModel.isReallyPrivate() ? View.GONE : View.VISIBLE); if (blockMenuItem != null) { blockMenuItem.setVisible(true); if (profileModel.getBlocked()) { @@ -691,6 +694,12 @@ public class ProfileFragment extends Fragment implements SwipeRefreshLayout.OnRe PostItemType.TAGGED); NavHostFragment.findNavController(this).navigate(action); }); + binding.btnDM.setOnClickListener(v -> { + new CreateThreadAction(cookie, profileModel.getId(), threadId -> { + final NavDirections action = ProfileFragmentDirections.actionProfileFragmentToDMThreadFragment(threadId, profileModel.getUsername()); + NavHostFragment.findNavController(this).navigate(action); + }).execute(); + }); binding.mainProfileImage.setOnClickListener(v -> { if (storyModels == null || storyModels.length <= 0) { // show profile pic diff --git a/app/src/main/res/layout/fragment_profile.xml b/app/src/main/res/layout/fragment_profile.xml index 1528e9ac..aedcbaaa 100644 --- a/app/src/main/res/layout/fragment_profile.xml +++ b/app/src/main/res/layout/fragment_profile.xml @@ -221,11 +221,30 @@ app:iconTint="@color/red_600" app:layout_constraintBottom_toTopOf="@id/highlights_barrier" app:layout_constraintEnd_toEndOf="parent" + app:layout_constraintEnd_toStartOf="@id/btnDM" app:layout_constraintStart_toEndOf="@id/btnSaved" app:layout_constraintTop_toBottomOf="@id/mainUrl" app:rippleColor="@color/red_300" tools:visibility="visible" /> + + + app:destination="@id/profile_nav_graph"> + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/values/color.xml b/app/src/main/res/values/color.xml index ec9855a9..5d46cf57 100755 --- a/app/src/main/res/values/color.xml +++ b/app/src/main/res/values/color.xml @@ -141,6 +141,8 @@ #FFEA00 #FFD600 + #5CE362 + #a86735 #dd9561 diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index ceff402a..fe5c3d78 100755 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -112,6 +112,7 @@ Liked Saved Tagged + Message Like (%s) Unlike (%s) Bookmark