1
0
mirror of https://github.com/KokaKiwi/BarInsta synced 2024-11-26 00:27:30 +00:00

dm button on profile?! (quick & dirty warning)

This commit is contained in:
Austin Huang 2020-09-22 23:15:57 -04:00
parent 3e3c39ae4b
commit ab37c2d72b
No known key found for this signature in database
GPG Key ID: 84C23AA04587A91F
7 changed files with 71 additions and 11 deletions

View File

@ -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<Void, Void, String> {
public class CreateThreadAction extends AsyncTask<Void, Void, String> {
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<Void, Void, String> {
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) {

View File

@ -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(),

View File

@ -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

View File

@ -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" />
<com.google.android.material.button.MaterialButton
android:id="@+id/btnDM"
style="@style/Widget.MaterialComponents.Button.TextButton"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="@string/dm_person"
android:textColor="@color/green"
android:visibility="gone"
app:icon="@drawable/ic_send_24"
app:iconGravity="top"
app:iconTint="@color/green"
app:layout_constraintBottom_toTopOf="@id/highlights_barrier"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@id/btnLiked"
app:layout_constraintTop_toBottomOf="@id/mainUrl"
app:rippleColor="@color/green"
tools:visibility="visible" />
<androidx.constraintlayout.widget.Barrier
android:id="@+id/highlights_barrier"
android:layout_width="wrap_content"

View File

@ -36,7 +36,7 @@
<action
android:id="@+id/action_global_profileFragment"
app:destination="@id/profileFragment">
app:destination="@id/profile_nav_graph">
<argument
android:name="username"
android:defaultValue=""
@ -74,6 +74,9 @@
<action
android:id="@+id/action_profileFragment_to_storyViewerFragment"
app:destination="@id/storyViewerFragment" />
<action
android:id="@+id/action_profileFragment_to_dMThreadFragment"
app:destination="@id/directMessagesThreadFragment" />
</fragment>
<fragment
android:id="@+id/savedViewerFragment"
@ -145,4 +148,31 @@
app:argType="string"
app:nullable="true" />
</fragment>
<fragment
android:id="@+id/directMessagesThreadFragment"
android:name="awais.instagrabber.fragments.directmessages.DirectMessageThreadFragment"
android:label="DirectMessagesThreadFragment"
tools:layout="@layout/fragment_direct_messages_thread">
<argument
android:name="threadId"
app:argType="string" />
<argument
android:name="title"
app:argType="string" />
<action
android:id="@+id/action_dMThreadFragment_to_dMSettingsFragment"
app:destination="@id/directMessagesSettingsFragment" />
</fragment>
<fragment
android:id="@+id/directMessagesSettingsFragment"
android:name="awais.instagrabber.fragments.directmessages.DirectMessageSettingsFragment"
android:label="DirectMessagesSettingsFragment"
tools:layout="@layout/fragment_direct_messages_settings">
<argument
android:name="threadId"
app:argType="string" />
<argument
android:name="title"
app:argType="string" />
</fragment>
</navigation>

View File

@ -141,6 +141,8 @@
<color name="yellow_A400">#FFEA00</color>
<color name="yellow_A700">#FFD600</color>
<color name="green">#5CE362</color>
<!-- Barinsta Theme colors -->
<color name="barinstaColorPrimary">#a86735</color>
<color name="barinstaColorPrimaryLight">#dd9561</color>

View File

@ -112,6 +112,7 @@
<string name="liked">Liked</string>
<string name="saved">Saved</string>
<string name="tagged">Tagged</string>
<string name="dm_person">Message</string>
<string name="like">Like (%s)</string>
<string name="unlike">Unlike (%s)</string>
<string name="bookmark">Bookmark</string>