From 4a439f74eb11cfaf94a1287f8d5c8547ee34703c Mon Sep 17 00:00:00 2001 From: Austin Huang Date: Sat, 22 Aug 2020 17:03:55 -0400 Subject: [PATCH 1/3] optimize imports, add DM settings (init), add notification setting --- .../java/awais/instagrabber/MainHelper.java | 1 - .../activities/CommentsViewer.java | 4 +- .../activities/DirectMessagesActivity.java | 14 ++ .../instagrabber/activities/FollowViewer.java | 3 - .../awais/instagrabber/activities/Login.java | 1 - .../awais/instagrabber/activities/Main.java | 9 +- .../activities/NotificationsViewer.java | 5 +- .../instagrabber/activities/PostViewer.java | 6 +- .../activities/ProfileViewer.java | 10 - .../instagrabber/activities/StoryViewer.java | 21 +- .../adapters/DirectMessageMembersAdapter.java | 55 +++++ .../instagrabber/adapters/FeedAdapter.java | 7 +- .../adapters/NotificationsAdapter.java | 8 +- .../instagrabber/adapters/PostsAdapter.java | 7 - .../adapters/SuggestionsAdapter.java | 1 - .../viewholder/NotificationViewHolder.java | 1 - .../DirectMessageActionLogViewHolder.java | 1 - .../DirectMessagePlaceholderViewHolder.java | 1 - .../instagrabber/asyncs/FeedFetcher.java | 2 +- .../instagrabber/asyncs/PostFetcher.java | 2 +- .../instagrabber/asyncs/PostsFetcher.java | 2 +- .../asyncs/ProfilePictureFetcher.java | 1 - .../DirectMessageInboxThreadFetcher.java | 2 +- .../asyncs/i/iStoryStatusFetcher.java | 6 +- .../instagrabber/asyncs/i/iTopicFetcher.java | 2 - .../dialogs/QuickAccessDialog.java | 1 - .../instagrabber/dialogs/SettingsDialog.java | 5 + .../directdownload/MultiDirectDialog.java | 2 +- .../DirectMessageInboxFragment.java | 10 + .../DirectMessageSettingsFragment.java | 209 ++++++++++++++++++ .../DirectMessageThreadFragment.java | 47 ++-- .../awais/instagrabber/models/FeedModel.java | 4 +- .../models/NotificationModel.java | 2 +- .../instagrabber/models/ViewerPostModel.java | 1 + .../awais/instagrabber/utils/Constants.java | 1 + .../awais/instagrabber/utils/FlavorTown.java | 9 - .../instagrabber/utils/SettingsHelper.java | 3 +- .../main/res/drawable-anydpi/ic_submit.xml | 10 + app/src/main/res/drawable-hdpi/ic_submit.png | Bin 0 -> 186 bytes app/src/main/res/drawable-mdpi/ic_submit.png | Bin 0 -> 139 bytes app/src/main/res/drawable-xhdpi/ic_submit.png | Bin 0 -> 323 bytes .../main/res/drawable-xxhdpi/ic_submit.png | Bin 0 -> 337 bytes .../res/layout/activity_direct_messages.xml | 18 +- app/src/main/res/layout/activity_saved.xml | 1 - .../main/res/layout/dialog_main_settings.xml | 25 +++ .../fragment_direct_messages_settings.xml | 68 ++++++ app/src/main/res/layout/item_feed_top.xml | 1 - app/src/main/res/layout/item_follow.xml | 10 +- app/src/main/res/layout/item_notification.xml | 1 - .../res/layout/layout_include_notif_item.xml | 2 - .../navigation/direct_messages_nav_graph.xml | 14 ++ app/src/main/res/values/strings.xml | 4 + 52 files changed, 507 insertions(+), 113 deletions(-) create mode 100755 app/src/main/java/awais/instagrabber/adapters/DirectMessageMembersAdapter.java create mode 100644 app/src/main/java/awais/instagrabber/fragments/directmessages/DirectMessageSettingsFragment.java create mode 100644 app/src/main/res/drawable-anydpi/ic_submit.xml create mode 100644 app/src/main/res/drawable-hdpi/ic_submit.png create mode 100644 app/src/main/res/drawable-mdpi/ic_submit.png create mode 100644 app/src/main/res/drawable-xhdpi/ic_submit.png create mode 100644 app/src/main/res/drawable-xxhdpi/ic_submit.png create mode 100644 app/src/main/res/layout/fragment_direct_messages_settings.xml diff --git a/app/src/main/java/awais/instagrabber/MainHelper.java b/app/src/main/java/awais/instagrabber/MainHelper.java index deae13d8..088b3350 100755 --- a/app/src/main/java/awais/instagrabber/MainHelper.java +++ b/app/src/main/java/awais/instagrabber/MainHelper.java @@ -33,7 +33,6 @@ import androidx.recyclerview.widget.LinearLayoutManager; import androidx.swiperefreshlayout.widget.SwipeRefreshLayout; import com.google.android.exoplayer2.SimpleExoPlayer; -import com.google.android.material.appbar.AppBarLayout; import java.io.DataOutputStream; import java.io.InputStream; diff --git a/app/src/main/java/awais/instagrabber/activities/CommentsViewer.java b/app/src/main/java/awais/instagrabber/activities/CommentsViewer.java index 62f497bc..0a98cc01 100755 --- a/app/src/main/java/awais/instagrabber/activities/CommentsViewer.java +++ b/app/src/main/java/awais/instagrabber/activities/CommentsViewer.java @@ -9,10 +9,10 @@ import android.text.SpannableString; import android.text.Spanned; import android.text.style.RelativeSizeSpan; import android.util.Log; -import android.view.inputmethod.InputMethodManager; import android.view.Menu; import android.view.MenuItem; import android.view.View; +import android.view.inputmethod.InputMethodManager; import android.widget.ArrayAdapter; import android.widget.Toast; @@ -259,7 +259,7 @@ public final class CommentsViewer extends BaseLanguageActivity implements SwipeR (commentModel == null ? "" : commentModel.getId()); urlConnection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded"); urlConnection.setRequestProperty("Content-Length", "" + - Integer.toString(urlParameters.getBytes().length)); + urlParameters.getBytes().length); urlConnection.setDoOutput(true); DataOutputStream wr = new DataOutputStream(urlConnection.getOutputStream()); wr.writeBytes(urlParameters); diff --git a/app/src/main/java/awais/instagrabber/activities/DirectMessagesActivity.java b/app/src/main/java/awais/instagrabber/activities/DirectMessagesActivity.java index a3435d07..80483316 100644 --- a/app/src/main/java/awais/instagrabber/activities/DirectMessagesActivity.java +++ b/app/src/main/java/awais/instagrabber/activities/DirectMessagesActivity.java @@ -1,10 +1,12 @@ package awais.instagrabber.activities; import android.os.Bundle; +import android.view.View; import android.widget.TextView; import androidx.annotation.NonNull; import androidx.annotation.Nullable; +import androidx.appcompat.widget.AppCompatImageView; import androidx.appcompat.widget.Toolbar; import androidx.coordinatorlayout.widget.CoordinatorLayout; import androidx.navigation.NavController; @@ -20,6 +22,7 @@ import awais.instagrabber.fragments.directmessages.DirectMessageThreadFragmentAr public class DirectMessagesActivity extends BaseLanguageActivity implements NavController.OnDestinationChangedListener { private TextView toolbarTitle; + private AppCompatImageView infoButton; @Override protected void onCreate(Bundle savedInstanceState) { @@ -33,6 +36,8 @@ public class DirectMessagesActivity extends BaseLanguageActivity implements NavC final Toolbar toolbar = binding.toolbar; setSupportActionBar(toolbar); + infoButton = binding.dmInfo; + final NavController navController = Navigation.findNavController(this, R.id.direct_messages_nav_host_fragment); navController.addOnDestinationChangedListener(this); final AppBarConfiguration appBarConfiguration = new AppBarConfiguration.Builder(navController.getGraph()).build(); @@ -46,6 +51,7 @@ public class DirectMessagesActivity extends BaseLanguageActivity implements NavC switch (destination.getId()) { case R.id.directMessagesInboxFragment: setToolbarTitle(R.string.action_dms); + infoButton.setVisibility(View.GONE); return; case R.id.directMessagesThreadFragment: if (arguments == null) { @@ -53,6 +59,14 @@ public class DirectMessagesActivity extends BaseLanguageActivity implements NavC } final String title = DirectMessageThreadFragmentArgs.fromBundle(arguments).getTitle(); setToolbarTitle(title); + infoButton.setVisibility(View.VISIBLE); + return; + case R.id.directMessagesSettingsFragment: + if (arguments == null) { + return; + } + setToolbarTitle(R.string.action_settings); + infoButton.setVisibility(View.GONE); return; } } diff --git a/app/src/main/java/awais/instagrabber/activities/FollowViewer.java b/app/src/main/java/awais/instagrabber/activities/FollowViewer.java index e64e841a..95491188 100755 --- a/app/src/main/java/awais/instagrabber/activities/FollowViewer.java +++ b/app/src/main/java/awais/instagrabber/activities/FollowViewer.java @@ -2,17 +2,14 @@ package awais.instagrabber.activities; import android.content.Intent; import android.content.res.Resources; -import android.net.Uri; import android.os.AsyncTask; import android.os.Bundle; import android.util.Log; import android.view.Menu; import android.view.MenuItem; import android.view.View; -import android.widget.ArrayAdapter; import androidx.annotation.Nullable; -import androidx.appcompat.app.AlertDialog; import androidx.appcompat.widget.SearchView; import androidx.swiperefreshlayout.widget.SwipeRefreshLayout; diff --git a/app/src/main/java/awais/instagrabber/activities/Login.java b/app/src/main/java/awais/instagrabber/activities/Login.java index ed5b7b4d..55c30ca6 100755 --- a/app/src/main/java/awais/instagrabber/activities/Login.java +++ b/app/src/main/java/awais/instagrabber/activities/Login.java @@ -1,7 +1,6 @@ package awais.instagrabber.activities; import android.annotation.SuppressLint; -import android.content.Intent; import android.graphics.Bitmap; import android.os.Build; import android.os.Bundle; diff --git a/app/src/main/java/awais/instagrabber/activities/Main.java b/app/src/main/java/awais/instagrabber/activities/Main.java index 21d5a5bb..ab7c9b2a 100755 --- a/app/src/main/java/awais/instagrabber/activities/Main.java +++ b/app/src/main/java/awais/instagrabber/activities/Main.java @@ -71,6 +71,7 @@ import static awais.instagrabber.utils.Utils.settingsHelper; public final class Main extends BaseLanguageActivity { private static final int INITIAL_DELAY_MILLIS = 200; + private static final int DELAY_MILLIS = 60000; public static FetchListener scanHack; public static ItemGetter itemGetter; // -------- items -------- @@ -263,9 +264,7 @@ public final class Main extends BaseLanguageActivity { runnable = () -> { final GetActivityAsyncTask activityAsyncTask = new GetActivityAsyncTask(uid, cookie, result -> { if (result == null) { - if (!Utils.isEmpty(cookie)) { - Toast.makeText(Main.this, R.string.downloader_unknown_error, Toast.LENGTH_SHORT).show(); - } + Toast.makeText(Main.this, R.string.downloader_unknown_error, Toast.LENGTH_SHORT).show(); return; } if (notificationManager == null) { @@ -304,8 +303,8 @@ public final class Main extends BaseLanguageActivity { notificationManager.cancel(1800000000); notificationManager.notify(1800000000, notification); }); - activityAsyncTask.execute(); - handler.postDelayed(runnable, 60000); + if (!Utils.isEmpty(cookie) && Utils.settingsHelper.getBoolean(Constants.CHECK_ACTIVITY)) activityAsyncTask.execute(); + handler.postDelayed(runnable, DELAY_MILLIS); }; handler.postDelayed(runnable, INITIAL_DELAY_MILLIS); } diff --git a/app/src/main/java/awais/instagrabber/activities/NotificationsViewer.java b/app/src/main/java/awais/instagrabber/activities/NotificationsViewer.java index 799d2a8a..4bb0cb2a 100755 --- a/app/src/main/java/awais/instagrabber/activities/NotificationsViewer.java +++ b/app/src/main/java/awais/instagrabber/activities/NotificationsViewer.java @@ -9,8 +9,6 @@ import android.text.SpannableString; import android.text.Spanned; import android.text.style.RelativeSizeSpan; import android.util.Log; -import android.view.Menu; -import android.view.MenuItem; import android.view.View; import android.widget.ArrayAdapter; import android.widget.Toast; @@ -28,10 +26,9 @@ import awais.instagrabber.asyncs.NotificationsFetcher; import awais.instagrabber.databinding.ActivityNotificationBinding; import awais.instagrabber.interfaces.FetchListener; import awais.instagrabber.interfaces.MentionClickListener; -import awais.instagrabber.models.enums.NotificationType; import awais.instagrabber.models.NotificationModel; import awais.instagrabber.models.PostModel; -import awais.instagrabber.models.ProfileModel; +import awais.instagrabber.models.enums.NotificationType; import awais.instagrabber.utils.Constants; import awais.instagrabber.utils.Utils; diff --git a/app/src/main/java/awais/instagrabber/activities/PostViewer.java b/app/src/main/java/awais/instagrabber/activities/PostViewer.java index 0241419a..e7de230d 100755 --- a/app/src/main/java/awais/instagrabber/activities/PostViewer.java +++ b/app/src/main/java/awais/instagrabber/activities/PostViewer.java @@ -44,6 +44,8 @@ import com.google.android.exoplayer2.source.MediaSourceEventListener; import com.google.android.exoplayer2.source.ProgressiveMediaSource; import com.google.android.exoplayer2.upstream.DefaultDataSourceFactory; +import org.json.JSONObject; + import java.io.IOException; import java.net.HttpURLConnection; import java.net.URL; @@ -51,8 +53,6 @@ import java.util.ArrayList; import java.util.Collections; import java.util.List; -import org.json.JSONObject; - import awais.instagrabber.R; import awais.instagrabber.adapters.PostsMediaAdapter; import awais.instagrabber.asyncs.PostFetcher; @@ -244,7 +244,7 @@ public final class PostViewer extends BaseLanguageActivity { } setupPostInfoBar("@"+viewerPostModel.getUsername(), viewerPostModel.getItemType(), - viewerPostModel.getLocation() == null ? null : viewerPostModel.getLocation()); + viewerPostModel.getLocation()); postCaption = postModel.getPostCaption(); viewerCaptionParent.setVisibility(View.VISIBLE); diff --git a/app/src/main/java/awais/instagrabber/activities/ProfileViewer.java b/app/src/main/java/awais/instagrabber/activities/ProfileViewer.java index 587f6427..54379a7f 100755 --- a/app/src/main/java/awais/instagrabber/activities/ProfileViewer.java +++ b/app/src/main/java/awais/instagrabber/activities/ProfileViewer.java @@ -16,15 +16,10 @@ import android.text.method.LinkMovementMethod; import android.text.style.RelativeSizeSpan; import android.text.style.StyleSpan; import android.util.Log; -import android.util.TypedValue; import android.view.Menu; import android.view.MenuItem; import android.view.View; -import android.view.ViewGroup; -import android.widget.AdapterView; import android.widget.ArrayAdapter; -import android.widget.ImageView; -import android.widget.LinearLayout; import android.widget.TextView; import android.widget.Toast; @@ -32,8 +27,6 @@ import androidx.annotation.NonNull; import androidx.annotation.Nullable; import androidx.appcompat.app.AlertDialog; import androidx.core.content.ContextCompat; -import androidx.core.view.GravityCompat; -import androidx.core.widget.ImageViewCompat; import androidx.recyclerview.widget.LinearLayoutManager; import androidx.swiperefreshlayout.widget.SwipeRefreshLayout; @@ -54,12 +47,10 @@ import awais.instagrabber.asyncs.LocationFetcher; import awais.instagrabber.asyncs.PostsFetcher; import awais.instagrabber.asyncs.ProfileFetcher; import awais.instagrabber.asyncs.i.iStoryStatusFetcher; -import awais.instagrabber.customviews.MouseDrawer; import awais.instagrabber.customviews.RamboTextView; import awais.instagrabber.customviews.helpers.GridAutofitLayoutManager; import awais.instagrabber.customviews.helpers.GridSpacingItemDecoration; import awais.instagrabber.customviews.helpers.RecyclerLazyLoader; -import awais.instagrabber.customviews.helpers.VideoAwareRecyclerScroller; import awais.instagrabber.databinding.ActivityProfileBinding; import awais.instagrabber.interfaces.FetchListener; import awais.instagrabber.interfaces.MentionClickListener; @@ -78,7 +69,6 @@ import awais.instagrabber.utils.Utils; import awaisomereport.LogCollector; import static awais.instagrabber.utils.Constants.AUTOLOAD_POSTS; -import static awais.instagrabber.utils.Constants.BOTTOM_TOOLBAR; import static awais.instagrabber.utils.Utils.logCollector; public final class ProfileViewer extends BaseLanguageActivity implements SwipeRefreshLayout.OnRefreshListener { diff --git a/app/src/main/java/awais/instagrabber/activities/StoryViewer.java b/app/src/main/java/awais/instagrabber/activities/StoryViewer.java index 22a1dc13..2385b557 100755 --- a/app/src/main/java/awais/instagrabber/activities/StoryViewer.java +++ b/app/src/main/java/awais/instagrabber/activities/StoryViewer.java @@ -10,7 +10,6 @@ import android.os.Build; import android.os.Bundle; import android.os.Environment; import android.os.Handler; -import android.text.InputType; import android.util.Log; import android.util.Pair; import android.view.Menu; @@ -18,7 +17,6 @@ import android.view.MenuItem; import android.view.View; import android.widget.ArrayAdapter; import android.widget.EditText; -import android.widget.LinearLayout; import android.widget.Toast; import androidx.annotation.NonNull; @@ -41,17 +39,16 @@ import com.google.android.exoplayer2.source.MediaSourceEventListener; import com.google.android.exoplayer2.source.ProgressiveMediaSource; import com.google.android.exoplayer2.upstream.DefaultDataSourceFactory; +import org.json.JSONObject; + import java.io.DataOutputStream; import java.io.File; import java.io.IOException; import java.net.HttpURLConnection; import java.net.URL; -import java.net.URLEncoder; import java.util.Date; import java.util.UUID; -import org.json.JSONObject; - import awais.instagrabber.BuildConfig; import awais.instagrabber.R; import awais.instagrabber.adapters.StoriesAdapter; @@ -62,12 +59,12 @@ import awais.instagrabber.customviews.helpers.SwipeGestureListener; import awais.instagrabber.databinding.ActivityStoryViewerBinding; 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; +import awais.instagrabber.models.stickers.PollModel; +import awais.instagrabber.models.stickers.QuestionModel; +import awais.instagrabber.models.stickers.QuizModel; import awais.instagrabber.utils.Constants; import awais.instagrabber.utils.Utils; import awaisomereport.LogCollector; @@ -285,7 +282,7 @@ public final class StoryViewer extends BaseLanguageActivity { 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]) + ")"; + choices[q] = (quiz.getMyChoice() == q ? "√ " :"") + quiz.getChoices()[q]+ " (" + 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) -> { @@ -700,8 +697,8 @@ final String url = "https://i.instagram.com/api/v1/media/"+currentStory.getStory String urlParameters = "reelMediaId="+currentStory.getStoryMediaId().split("_")[0] +"&reelMediaOwnerId="+currentStory.getUserId() +"&reelId="+currentStory.getUserId() - +"&reelMediaTakenAt="+String.valueOf(currentStory.getTimestamp()) - +"&viewSeenAt="+String.valueOf(currentStory.getTimestamp()); + +"&reelMediaTakenAt="+ currentStory.getTimestamp() + +"&viewSeenAt="+ currentStory.getTimestamp(); final HttpURLConnection urlConnection = (HttpURLConnection) new URL(url).openConnection(); urlConnection.setRequestMethod("POST"); urlConnection.setUseCaches(false); @@ -738,7 +735,7 @@ final String url = "https://i.instagram.com/api/v1/media/"+currentStory.getStory +"\",\"recipient_users\":\"["+currentStory.getUserId() // <- string of array of number (not joking) +"]\"}"); urlConnection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded"); - urlConnection.setRequestProperty("Content-Length", "" + Integer.toString(urlParameters.getBytes().length)); + urlConnection.setRequestProperty("Content-Length", "" + urlParameters.getBytes().length); urlConnection.setDoOutput(true); DataOutputStream wr = new DataOutputStream(urlConnection.getOutputStream()); wr.writeBytes(urlParameters); diff --git a/app/src/main/java/awais/instagrabber/adapters/DirectMessageMembersAdapter.java b/app/src/main/java/awais/instagrabber/adapters/DirectMessageMembersAdapter.java new file mode 100755 index 00000000..971275f1 --- /dev/null +++ b/app/src/main/java/awais/instagrabber/adapters/DirectMessageMembersAdapter.java @@ -0,0 +1,55 @@ +package awais.instagrabber.adapters; + +import android.content.Context; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; + +import androidx.annotation.NonNull; +import androidx.recyclerview.widget.RecyclerView; + +import com.bumptech.glide.Glide; + +import awais.instagrabber.R; +import awais.instagrabber.adapters.viewholder.FollowsViewHolder; +import awais.instagrabber.models.ProfileModel; + +public final class DirectMessageMembersAdapter extends RecyclerView.Adapter { + private final ProfileModel[] profileModels; + private final View.OnClickListener onClickListener; + private final LayoutInflater layoutInflater; + + public DirectMessageMembersAdapter(final ProfileModel[] profileModels, final Context context, final View.OnClickListener onClickListener) { + this.profileModels = profileModels; + this.layoutInflater = LayoutInflater.from(context); + this.onClickListener = onClickListener; + } + + @NonNull + @Override + public RecyclerView.ViewHolder onCreateViewHolder(@NonNull final ViewGroup parent, final int viewType) { + final View view = layoutInflater.inflate(R.layout.item_follow, parent, false); + return new FollowsViewHolder(view); + } + + @Override + public void onBindViewHolder(@NonNull final RecyclerView.ViewHolder holder, final int position) { + final ProfileModel model = profileModels[position]; + + final FollowsViewHolder followHolder = (FollowsViewHolder) holder; + if (model != null) { + followHolder.itemView.setTag(model); + followHolder.itemView.setOnClickListener(onClickListener); + + followHolder.tvUsername.setText(model.getUsername()); + followHolder.tvFullName.setText(model.getName()); + + Glide.with(layoutInflater.getContext()).load(model.getSdProfilePic()).into(followHolder.profileImage); + } + } + + @Override + public int getItemCount() { + return profileModels.length; + } +} \ No newline at end of file diff --git a/app/src/main/java/awais/instagrabber/adapters/FeedAdapter.java b/app/src/main/java/awais/instagrabber/adapters/FeedAdapter.java index c9dd3810..acf8834a 100755 --- a/app/src/main/java/awais/instagrabber/adapters/FeedAdapter.java +++ b/app/src/main/java/awais/instagrabber/adapters/FeedAdapter.java @@ -5,13 +5,10 @@ import android.app.Activity; import android.content.Context; import android.content.DialogInterface; import android.content.Intent; -import android.graphics.Typeface; import android.net.Uri; import android.text.SpannableString; -import android.text.SpannableStringBuilder; import android.text.Spanned; import android.text.method.LinkMovementMethod; -import android.text.style.StyleSpan; import android.util.Log; import android.view.LayoutInflater; import android.view.View; @@ -35,11 +32,11 @@ import com.google.android.exoplayer2.source.ProgressiveMediaSource; import com.google.android.exoplayer2.ui.PlayerView; import com.google.android.exoplayer2.upstream.DefaultDataSourceFactory; +import org.json.JSONObject; + import java.util.ArrayList; import java.util.Collections; -import org.json.JSONObject; - import awais.instagrabber.BuildConfig; import awais.instagrabber.R; import awais.instagrabber.activities.CommentsViewer; diff --git a/app/src/main/java/awais/instagrabber/adapters/NotificationsAdapter.java b/app/src/main/java/awais/instagrabber/adapters/NotificationsAdapter.java index dc18c05d..b5d9606b 100755 --- a/app/src/main/java/awais/instagrabber/adapters/NotificationsAdapter.java +++ b/app/src/main/java/awais/instagrabber/adapters/NotificationsAdapter.java @@ -1,28 +1,22 @@ package awais.instagrabber.adapters; import android.content.Context; -import android.util.Log; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import androidx.annotation.NonNull; -import androidx.core.text.HtmlCompat; import androidx.recyclerview.widget.RecyclerView; import com.bumptech.glide.Glide; import com.bumptech.glide.RequestManager; import com.bumptech.glide.request.RequestOptions; -import java.util.ArrayList; - import awais.instagrabber.R; import awais.instagrabber.adapters.viewholder.NotificationViewHolder; import awais.instagrabber.interfaces.MentionClickListener; -import awais.instagrabber.models.enums.NotificationType; import awais.instagrabber.models.NotificationModel; -import awais.instagrabber.utils.LocaleUtils; -import awais.instagrabber.utils.Utils; +import awais.instagrabber.models.enums.NotificationType; public final class NotificationsAdapter extends RecyclerView.Adapter { private final View.OnClickListener onClickListener; diff --git a/app/src/main/java/awais/instagrabber/adapters/PostsAdapter.java b/app/src/main/java/awais/instagrabber/adapters/PostsAdapter.java index 3750cc64..7a528f65 100755 --- a/app/src/main/java/awais/instagrabber/adapters/PostsAdapter.java +++ b/app/src/main/java/awais/instagrabber/adapters/PostsAdapter.java @@ -1,7 +1,6 @@ package awais.instagrabber.adapters; import android.graphics.drawable.Drawable; -import android.util.Log; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; @@ -17,18 +16,12 @@ import com.bumptech.glide.load.engine.GlideException; import com.bumptech.glide.request.RequestListener; import com.bumptech.glide.request.target.Target; -import java.net.HttpURLConnection; -import java.net.URL; import java.util.ArrayList; -import awais.instagrabber.BuildConfig; import awais.instagrabber.R; import awais.instagrabber.adapters.viewholder.PostViewHolder; import awais.instagrabber.models.PostModel; import awais.instagrabber.models.enums.MediaItemType; -import awaisomereport.LogCollector; - -import static awais.instagrabber.utils.Utils.logCollector; public final class PostsAdapter extends RecyclerView.Adapter { private final ArrayList postModels; diff --git a/app/src/main/java/awais/instagrabber/adapters/SuggestionsAdapter.java b/app/src/main/java/awais/instagrabber/adapters/SuggestionsAdapter.java index a772e6a2..826b8767 100755 --- a/app/src/main/java/awais/instagrabber/adapters/SuggestionsAdapter.java +++ b/app/src/main/java/awais/instagrabber/adapters/SuggestionsAdapter.java @@ -2,7 +2,6 @@ package awais.instagrabber.adapters; import android.content.Context; import android.database.Cursor; -import android.util.Log; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; diff --git a/app/src/main/java/awais/instagrabber/adapters/viewholder/NotificationViewHolder.java b/app/src/main/java/awais/instagrabber/adapters/viewholder/NotificationViewHolder.java index 261a4aff..e660c5e2 100755 --- a/app/src/main/java/awais/instagrabber/adapters/viewholder/NotificationViewHolder.java +++ b/app/src/main/java/awais/instagrabber/adapters/viewholder/NotificationViewHolder.java @@ -9,7 +9,6 @@ import androidx.annotation.NonNull; import androidx.recyclerview.widget.RecyclerView; import awais.instagrabber.R; -import awais.instagrabber.adapters.CommentsAdapter; import awais.instagrabber.customviews.RamboTextView; import awais.instagrabber.interfaces.MentionClickListener; import awais.instagrabber.models.NotificationModel; diff --git a/app/src/main/java/awais/instagrabber/adapters/viewholder/directmessages/DirectMessageActionLogViewHolder.java b/app/src/main/java/awais/instagrabber/adapters/viewholder/directmessages/DirectMessageActionLogViewHolder.java index 4c5bfc85..72cb31d4 100644 --- a/app/src/main/java/awais/instagrabber/adapters/viewholder/directmessages/DirectMessageActionLogViewHolder.java +++ b/app/src/main/java/awais/instagrabber/adapters/viewholder/directmessages/DirectMessageActionLogViewHolder.java @@ -7,7 +7,6 @@ import androidx.core.text.HtmlCompat; import awais.instagrabber.databinding.LayoutDmBaseBinding; import awais.instagrabber.databinding.LayoutDmTextBinding; -import awais.instagrabber.models.ProfileModel; import awais.instagrabber.models.direct_messages.DirectItemModel; import static androidx.core.text.HtmlCompat.FROM_HTML_MODE_COMPACT; diff --git a/app/src/main/java/awais/instagrabber/adapters/viewholder/directmessages/DirectMessagePlaceholderViewHolder.java b/app/src/main/java/awais/instagrabber/adapters/viewholder/directmessages/DirectMessagePlaceholderViewHolder.java index 00691588..78eec36b 100644 --- a/app/src/main/java/awais/instagrabber/adapters/viewholder/directmessages/DirectMessagePlaceholderViewHolder.java +++ b/app/src/main/java/awais/instagrabber/adapters/viewholder/directmessages/DirectMessagePlaceholderViewHolder.java @@ -7,7 +7,6 @@ import androidx.core.text.HtmlCompat; import awais.instagrabber.databinding.LayoutDmBaseBinding; import awais.instagrabber.databinding.LayoutDmTextBinding; -import awais.instagrabber.models.ProfileModel; import awais.instagrabber.models.direct_messages.DirectItemModel; import static androidx.core.text.HtmlCompat.FROM_HTML_MODE_COMPACT; diff --git a/app/src/main/java/awais/instagrabber/asyncs/FeedFetcher.java b/app/src/main/java/awais/instagrabber/asyncs/FeedFetcher.java index 36bc384e..793d3574 100755 --- a/app/src/main/java/awais/instagrabber/asyncs/FeedFetcher.java +++ b/app/src/main/java/awais/instagrabber/asyncs/FeedFetcher.java @@ -14,10 +14,10 @@ import java.util.ArrayList; import awais.instagrabber.BuildConfig; import awais.instagrabber.interfaces.FetchListener; -import awais.instagrabber.models.enums.MediaItemType; import awais.instagrabber.models.FeedModel; import awais.instagrabber.models.ProfileModel; import awais.instagrabber.models.ViewerPostModel; +import awais.instagrabber.models.enums.MediaItemType; import awais.instagrabber.utils.Constants; import awais.instagrabber.utils.Utils; import awaisomereport.LogCollector; diff --git a/app/src/main/java/awais/instagrabber/asyncs/PostFetcher.java b/app/src/main/java/awais/instagrabber/asyncs/PostFetcher.java index 91179049..528f2a76 100755 --- a/app/src/main/java/awais/instagrabber/asyncs/PostFetcher.java +++ b/app/src/main/java/awais/instagrabber/asyncs/PostFetcher.java @@ -13,8 +13,8 @@ import java.net.URL; import awais.instagrabber.BuildConfig; import awais.instagrabber.interfaces.FetchListener; -import awais.instagrabber.models.enums.MediaItemType; import awais.instagrabber.models.ViewerPostModel; +import awais.instagrabber.models.enums.MediaItemType; import awais.instagrabber.utils.Constants; import awais.instagrabber.utils.Utils; import awaisomereport.LogCollector; diff --git a/app/src/main/java/awais/instagrabber/asyncs/PostsFetcher.java b/app/src/main/java/awais/instagrabber/asyncs/PostsFetcher.java index 0add3388..3e972871 100755 --- a/app/src/main/java/awais/instagrabber/asyncs/PostsFetcher.java +++ b/app/src/main/java/awais/instagrabber/asyncs/PostsFetcher.java @@ -13,8 +13,8 @@ import java.net.URL; import awais.instagrabber.BuildConfig; import awais.instagrabber.interfaces.FetchListener; -import awais.instagrabber.models.enums.MediaItemType; import awais.instagrabber.models.PostModel; +import awais.instagrabber.models.enums.MediaItemType; import awais.instagrabber.utils.Constants; import awais.instagrabber.utils.Utils; import awaisomereport.LogCollector; diff --git a/app/src/main/java/awais/instagrabber/asyncs/ProfilePictureFetcher.java b/app/src/main/java/awais/instagrabber/asyncs/ProfilePictureFetcher.java index 1e7ad664..39cb4cfa 100755 --- a/app/src/main/java/awais/instagrabber/asyncs/ProfilePictureFetcher.java +++ b/app/src/main/java/awais/instagrabber/asyncs/ProfilePictureFetcher.java @@ -2,7 +2,6 @@ package awais.instagrabber.asyncs; import android.os.AsyncTask; import android.util.Log; -import android.util.Pair; import org.json.JSONObject; import org.jsoup.Jsoup; diff --git a/app/src/main/java/awais/instagrabber/asyncs/direct_messages/DirectMessageInboxThreadFetcher.java b/app/src/main/java/awais/instagrabber/asyncs/direct_messages/DirectMessageInboxThreadFetcher.java index b45d44bd..36ed285e 100644 --- a/app/src/main/java/awais/instagrabber/asyncs/direct_messages/DirectMessageInboxThreadFetcher.java +++ b/app/src/main/java/awais/instagrabber/asyncs/direct_messages/DirectMessageInboxThreadFetcher.java @@ -47,7 +47,7 @@ public final class DirectMessageInboxThreadFetcher extends AsyncTask queryParamsMap = new HashMap<>(); queryParamsMap.put("visual_message_return_type", "unseen"); - queryParamsMap.put("direction", direction.getValue()); + if (direction != null) queryParamsMap.put("direction", direction.getValue()); if (!Utils.isEmpty(endCursor)) { queryParamsMap.put("cursor", endCursor); } 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 919f761e..d85f3d47 100755 --- a/app/src/main/java/awais/instagrabber/asyncs/i/iStoryStatusFetcher.java +++ b/app/src/main/java/awais/instagrabber/asyncs/i/iStoryStatusFetcher.java @@ -11,11 +11,11 @@ import java.net.URL; import awais.instagrabber.BuildConfig; import awais.instagrabber.interfaces.FetchListener; +import awais.instagrabber.models.StoryModel; +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.StoryModel; -import awais.instagrabber.models.enums.MediaItemType; import awais.instagrabber.utils.Constants; import awais.instagrabber.utils.Utils; import awaisomereport.LogCollector; @@ -149,7 +149,7 @@ public final class iStoryStatusFetcher extends AsyncTask selectedItems = new ArrayList<>(); diff --git a/app/src/main/java/awais/instagrabber/fragments/directmessages/DirectMessageInboxFragment.java b/app/src/main/java/awais/instagrabber/fragments/directmessages/DirectMessageInboxFragment.java index 9dfbf68a..3827e390 100644 --- a/app/src/main/java/awais/instagrabber/fragments/directmessages/DirectMessageInboxFragment.java +++ b/app/src/main/java/awais/instagrabber/fragments/directmessages/DirectMessageInboxFragment.java @@ -46,6 +46,7 @@ public class DirectMessageInboxFragment extends Fragment implements SwipeRefresh private String endCursor; private AsyncTask currentlyRunning; private InboxThreadModelListViewModel listViewModel; + public static boolean afterLeave = false; private final FetchListener fetchListener = new FetchListener() { @Override @@ -115,6 +116,15 @@ public class DirectMessageInboxFragment extends Fragment implements SwipeRefresh currentlyRunning = new InboxFetcher(null, fetchListener).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); } + @Override + public void onResume() { + super.onResume(); + if (afterLeave) { + onRefresh(); + afterLeave = false; + } + } + private void initData() { lazyLoader = new RecyclerLazyLoader(layoutManager, (page, totalItemsCount) -> { if (!Utils.isEmpty(endCursor)) diff --git a/app/src/main/java/awais/instagrabber/fragments/directmessages/DirectMessageSettingsFragment.java b/app/src/main/java/awais/instagrabber/fragments/directmessages/DirectMessageSettingsFragment.java new file mode 100644 index 00000000..9b2c642d --- /dev/null +++ b/app/src/main/java/awais/instagrabber/fragments/directmessages/DirectMessageSettingsFragment.java @@ -0,0 +1,209 @@ +package awais.instagrabber.fragments.directmessages; + +import android.content.Intent; +import android.os.AsyncTask; +import android.os.Bundle; +import android.text.Editable; +import android.text.TextWatcher; +import android.util.Log; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.EditText; +import android.widget.LinearLayout; +import android.widget.Toast; + +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; +import androidx.appcompat.app.AlertDialog; +import androidx.appcompat.widget.AppCompatButton; +import androidx.appcompat.widget.AppCompatImageView; +import androidx.fragment.app.Fragment; +import androidx.fragment.app.FragmentActivity; +import androidx.navigation.fragment.NavHostFragment; +import androidx.recyclerview.widget.LinearLayoutManager; +import androidx.recyclerview.widget.RecyclerView; +import androidx.swiperefreshlayout.widget.SwipeRefreshLayout; + +import java.io.DataOutputStream; +import java.net.HttpURLConnection; +import java.net.URL; +import java.net.URLEncoder; + +import awais.instagrabber.BuildConfig; +import awais.instagrabber.R; +import awais.instagrabber.activities.ProfileViewer; +import awais.instagrabber.adapters.DirectMessageMembersAdapter; +import awais.instagrabber.asyncs.direct_messages.DirectMessageInboxThreadFetcher; +import awais.instagrabber.databinding.FragmentDirectMessagesSettingsBinding; +import awais.instagrabber.interfaces.FetchListener; +import awais.instagrabber.models.ProfileModel; +import awais.instagrabber.models.direct_messages.InboxThreadModel; +import awais.instagrabber.utils.Constants; +import awais.instagrabber.utils.Utils; + +public class DirectMessageSettingsFragment extends Fragment implements SwipeRefreshLayout.OnRefreshListener { + private static final String TAG = "DirectMessagesSettingsFrag"; + + private FragmentActivity fragmentActivity; + private RecyclerView userList; + private EditText titleText; + private AppCompatImageView titleSend; + private AppCompatButton btnLeave; + private LinearLayoutManager layoutManager; + private String threadId, threadTitle; + private final String cookie = Utils.settingsHelper.getString(Constants.COOKIE); + private AsyncTask currentlyRunning; + private DirectMessageMembersAdapter memberAdapter; + private View.OnClickListener clickListener; + + private final FetchListener fetchListener = new FetchListener() { + @Override + public void doBefore() {} + + @Override + public void onResult(final InboxThreadModel threadModel) { + memberAdapter = new DirectMessageMembersAdapter(threadModel.getUsers(), requireContext(), clickListener); + userList.setAdapter(memberAdapter); + } + }; + + @Override + public void onCreate(@Nullable final Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + fragmentActivity = requireActivity(); + + clickListener = v -> { + final Object tag = v.getTag(); + if (tag instanceof ProfileModel) { + // TODO: kick dialog + ProfileModel model = (ProfileModel) tag; + startActivity( + new Intent(requireContext(), ProfileViewer.class) + .putExtra(Constants.EXTRAS_USERNAME, model.getUsername()) + ); + } + }; + } + + @Override + public View onCreateView(@NonNull final LayoutInflater inflater, + final ViewGroup container, + final Bundle savedInstanceState) { + final FragmentDirectMessagesSettingsBinding binding = FragmentDirectMessagesSettingsBinding.inflate(inflater, container, false); + final LinearLayout root = binding.getRoot(); + layoutManager = new LinearLayoutManager(requireContext()); + + threadId = DirectMessageSettingsFragmentArgs.fromBundle(getArguments()).getThreadId(); + threadTitle = DirectMessageSettingsFragmentArgs.fromBundle(getArguments()).getTitle(); + binding.swipeRefreshLayout.setEnabled(false); + + userList = binding.userList; + userList.setHasFixedSize(true); + userList.setLayoutManager(layoutManager); + + titleText = binding.titleText; + titleText.setText(threadTitle); + + titleSend = binding.titleSend; + titleSend.setOnClickListener(v -> { + new ChangeSettings().execute("update_title"); + }); + + titleText.addTextChangedListener(new TextWatcher() { + @Override + public void afterTextChanged(Editable s) {} + + @Override + public void beforeTextChanged(CharSequence s, int start, int count, int after) {} + + @Override + public void onTextChanged(CharSequence s, int start, int before, int count) { + titleSend.setVisibility(s.toString().equals(threadTitle) ? View.GONE : View.VISIBLE); + } + }); + + btnLeave = binding.btnLeave; + btnLeave.setOnClickListener(v -> { + new AlertDialog.Builder(requireContext()).setTitle(R.string.dms_action_leave_question) + .setPositiveButton(R.string.yes, (x,y) -> { + new ChangeSettings().execute("leave"); + }) + .setNegativeButton(R.string.no, null) + .show(); + }); + + currentlyRunning = new DirectMessageInboxThreadFetcher(threadId, null, null, fetchListener).execute(); + return root; + } + + @Override + public void onRefresh() { + stopCurrentExecutor(); + currentlyRunning = new DirectMessageInboxThreadFetcher(threadId, null, null, fetchListener).execute(); + } + + private void stopCurrentExecutor() { + if (currentlyRunning != null) { + try { + currentlyRunning.cancel(true); + } catch (final Exception e) { + if (BuildConfig.DEBUG) Log.e(TAG, "", e); + } + } + } + + class ChangeSettings extends AsyncTask { + String action; + boolean ok = false; + + protected Void doInBackground(String... rawAction) { + action = rawAction[0]; + final String url = "https://i.instagram.com/api/v1/direct_v2/threads/"+threadId+"/"+action+"/"; + try { + String urlParameters = "_csrftoken=" + cookie.split("csrftoken=")[1].split(";")[0] + +"&_uuid=" + Utils.settingsHelper.getString(Constants.DEVICE_UUID); + if (action.equals("update_title")) + urlParameters += "&title=" + URLEncoder.encode(titleText.getText().toString(), "UTF-8") + .replaceAll("\\+", "%20").replaceAll("%21", "!").replaceAll("%27", "'") + .replaceAll("%28", "(").replaceAll("%29", ")").replaceAll("%7E", "~"); + 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(); + urlConnection.connect(); + if (urlConnection.getResponseCode() == HttpURLConnection.HTTP_OK) { + ok = true; + } + urlConnection.disconnect(); + } catch (Throwable ex) { + Log.e("austin_debug", "unsend: " + ex); + } + return null; + } + + @Override + protected void onPostExecute(Void result) { + if (ok) { + Toast.makeText(requireContext(), R.string.dms_action_success, Toast.LENGTH_SHORT).show(); + if (action.equals("update_title")) { + threadTitle = titleText.getText().toString(); + titleSend.setVisibility(View.GONE); + titleText.clearFocus(); + } + else if (action.equals("leave")) { + DirectMessageInboxFragment.afterLeave = true; + NavHostFragment.findNavController(DirectMessageSettingsFragment.this).popBackStack(R.id.directMessagesInboxFragment, false); + } + } + else Toast.makeText(requireContext(), R.string.downloader_unknown_error, Toast.LENGTH_SHORT).show(); + } + } +} diff --git a/app/src/main/java/awais/instagrabber/fragments/directmessages/DirectMessageThreadFragment.java b/app/src/main/java/awais/instagrabber/fragments/directmessages/DirectMessageThreadFragment.java index fe53e374..a077b082 100644 --- a/app/src/main/java/awais/instagrabber/fragments/directmessages/DirectMessageThreadFragment.java +++ b/app/src/main/java/awais/instagrabber/fragments/directmessages/DirectMessageThreadFragment.java @@ -20,11 +20,15 @@ import android.widget.Toast; import androidx.annotation.NonNull; import androidx.annotation.Nullable; import androidx.appcompat.app.AlertDialog; +import androidx.appcompat.widget.AppCompatImageView; +import androidx.coordinatorlayout.widget.CoordinatorLayout; import androidx.fragment.app.Fragment; import androidx.fragment.app.FragmentActivity; import androidx.lifecycle.MutableLiveData; import androidx.lifecycle.ViewModel; import androidx.lifecycle.ViewModelProvider; +import androidx.navigation.NavDirections; +import androidx.navigation.fragment.NavHostFragment; import androidx.recyclerview.widget.LinearLayoutManager; import androidx.recyclerview.widget.RecyclerView; @@ -32,8 +36,6 @@ import org.json.JSONException; import org.json.JSONObject; import java.io.DataOutputStream; -import java.io.File; -import java.io.FileNotFoundException; import java.io.IOException; import java.io.InputStream; import java.io.UnsupportedEncodingException; @@ -44,7 +46,6 @@ import java.util.Arrays; import java.util.Collections; import java.util.LinkedList; import java.util.List; -import java.util.UUID; import awais.instagrabber.R; import awais.instagrabber.activities.PostViewer; @@ -75,7 +76,7 @@ public class DirectMessageThreadFragment extends Fragment { private static final int PICK_IMAGE = 100; private FragmentActivity fragmentActivity; - private String threadId; + private String threadId, threadTitle; private String cursor; private final String cookie = Utils.settingsHelper.getString(Constants.COOKIE); private final String myId = Utils.getUserIdFromCookie(cookie); @@ -83,6 +84,7 @@ public class DirectMessageThreadFragment extends Fragment { private DirectItemModelListViewModel listViewModel; private DirectItemModel directItemModel; private RecyclerView messageList; + private AppCompatImageView dmInfo; private boolean hasSentSomething, hasDeletedSomething; private boolean hasOlder = true; @@ -131,12 +133,6 @@ public class DirectMessageThreadFragment extends Fragment { leftUsers.clear(); leftUsers.addAll(Arrays.asList(result.getLeftUsers())); - // thread title is already comma separated username, so no need to set by ourselves - // String[] users = new String[result.getUsers().length]; - // for (int i = 0; i < users.length; ++i) { - // users[i] = result.getUsers()[i].getUsername(); - // } - List list = listViewModel.getList().getValue(); final List newList = Arrays.asList(result.getItems()); list = list != null ? new LinkedList<>(list) : new LinkedList<>(); @@ -170,11 +166,18 @@ public class DirectMessageThreadFragment extends Fragment { final ViewGroup container, final Bundle savedInstanceState) { binding = FragmentDirectMessagesThreadBinding.inflate(inflater, container, false); + CoordinatorLayout containerTwo = (CoordinatorLayout) container.getParent(); + dmInfo = containerTwo.findViewById(R.id.dmInfo); final LinearLayout root = binding.getRoot(); + listViewModel = new ViewModelProvider(fragmentActivity).get(DirectItemModelListViewModel.class); if (getArguments() == null) { return root; } - threadId = DirectMessageThreadFragmentArgs.fromBundle(getArguments()).getThreadId(); + if (!DirectMessageThreadFragmentArgs.fromBundle(getArguments()).getThreadId().equals(threadId)) { + listViewModel.empty(); + threadId = DirectMessageThreadFragmentArgs.fromBundle(getArguments()).getThreadId(); + } + threadTitle = DirectMessageThreadFragmentArgs.fromBundle(getArguments()).getTitle(); binding.swipeRefreshLayout.setEnabled(false); messageList = binding.messageList; messageList.setHasFixedSize(true); @@ -190,6 +193,11 @@ public class DirectMessageThreadFragment extends Fragment { } new DirectMessageInboxThreadFetcher(threadId, UserInboxDirection.OLDER, cursor, fetchListener).execute(); // serial because we don't want messages to be randomly ordered })); + dmInfo.setOnClickListener(v -> { + final NavDirections action = + DirectMessageThreadFragmentDirections.actionDMThreadFragmentToDMSettingsFragment(threadId, threadTitle); + NavHostFragment.findNavController(DirectMessageThreadFragment.this).navigate(action); + }); final DialogInterface.OnClickListener onDialogListener = (dialogInterface, which) -> { if (which == 0) { @@ -306,9 +314,10 @@ public class DirectMessageThreadFragment extends Fragment { final MentionClickListener mentionClickListener = (view, text, isHashtag) -> searchUsername(text); final DirectMessageItemsAdapter adapter = new DirectMessageItemsAdapter(users, leftUsers, onClickListener, mentionClickListener); messageList.setAdapter(adapter); - listViewModel = new ViewModelProvider(fragmentActivity).get(DirectItemModelListViewModel.class); listViewModel.getList().observe(fragmentActivity, adapter::submitList); - new DirectMessageInboxThreadFetcher(threadId, UserInboxDirection.OLDER, null, fetchListener).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); + if (listViewModel.isEmpty()) { + new DirectMessageInboxThreadFetcher(threadId, UserInboxDirection.OLDER, null, fetchListener).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); + } return root; } @@ -420,13 +429,25 @@ public class DirectMessageThreadFragment extends Fragment { public static class DirectItemModelListViewModel extends ViewModel { private MutableLiveData> list; + private boolean isEmpty; public MutableLiveData> getList() { if (list == null) { list = new MutableLiveData<>(); + isEmpty = true; } + else isEmpty = false; return list; } + + public boolean isEmpty() { + return isEmpty; + } + + public void empty() { + list = null; + isEmpty = true; + } } class Unsend extends AsyncTask { diff --git a/app/src/main/java/awais/instagrabber/models/FeedModel.java b/app/src/main/java/awais/instagrabber/models/FeedModel.java index 9eeeda1a..e848b5ae 100755 --- a/app/src/main/java/awais/instagrabber/models/FeedModel.java +++ b/app/src/main/java/awais/instagrabber/models/FeedModel.java @@ -1,9 +1,9 @@ package awais.instagrabber.models; -import awais.instagrabber.models.enums.MediaItemType; - import org.json.JSONObject; +import awais.instagrabber.models.enums.MediaItemType; + public final class FeedModel extends PostModel { private final ProfileModel profileModel; private final long commentsCount, viewCount; diff --git a/app/src/main/java/awais/instagrabber/models/NotificationModel.java b/app/src/main/java/awais/instagrabber/models/NotificationModel.java index f50c1331..41686576 100755 --- a/app/src/main/java/awais/instagrabber/models/NotificationModel.java +++ b/app/src/main/java/awais/instagrabber/models/NotificationModel.java @@ -4,8 +4,8 @@ import androidx.annotation.NonNull; import java.util.Date; -import awais.instagrabber.utils.Utils; import awais.instagrabber.models.enums.NotificationType; +import awais.instagrabber.utils.Utils; public final class NotificationModel { private final String id, username, profilePicUrl, shortcode, previewUrl; diff --git a/app/src/main/java/awais/instagrabber/models/ViewerPostModel.java b/app/src/main/java/awais/instagrabber/models/ViewerPostModel.java index 3ced283e..e4c1ec0d 100755 --- a/app/src/main/java/awais/instagrabber/models/ViewerPostModel.java +++ b/app/src/main/java/awais/instagrabber/models/ViewerPostModel.java @@ -1,6 +1,7 @@ package awais.instagrabber.models; import org.json.JSONObject; + import awais.instagrabber.models.enums.MediaItemType; public final class ViewerPostModel extends BasePostModel { diff --git a/app/src/main/java/awais/instagrabber/utils/Constants.java b/app/src/main/java/awais/instagrabber/utils/Constants.java index 8697a478..692342d9 100755 --- a/app/src/main/java/awais/instagrabber/utils/Constants.java +++ b/app/src/main/java/awais/instagrabber/utils/Constants.java @@ -23,6 +23,7 @@ public final class Constants { public static final String INSTADP = "instadp"; public static final String STORIESIG = "storiesig"; public static final String AMOLED_THEME = "amoled_theme"; + public static final String CHECK_ACTIVITY = "check_activity"; // never Export public static final String COOKIE = "cookie"; public static final String SHOW_QUICK_ACCESS_DIALOG = "show_quick_dlg"; diff --git a/app/src/main/java/awais/instagrabber/utils/FlavorTown.java b/app/src/main/java/awais/instagrabber/utils/FlavorTown.java index 64ba36e0..bd641684 100755 --- a/app/src/main/java/awais/instagrabber/utils/FlavorTown.java +++ b/app/src/main/java/awais/instagrabber/utils/FlavorTown.java @@ -6,22 +6,13 @@ import android.content.Intent; import android.content.res.Resources; import android.net.Uri; import android.os.AsyncTask; -import android.text.SpannableStringBuilder; -import android.text.method.LinkMovementMethod; -import android.text.style.RelativeSizeSpan; -import android.text.style.URLSpan; -import android.view.View; -import android.view.ViewGroup; -import android.widget.TextView; import android.widget.Toast; import androidx.annotation.NonNull; import androidx.appcompat.app.AlertDialog; -import androidx.fragment.app.FragmentManager; import awais.instagrabber.BuildConfig; import awais.instagrabber.R; -import awais.instagrabber.interfaces.FetchListener; import static awais.instagrabber.utils.Utils.settingsHelper; diff --git a/app/src/main/java/awais/instagrabber/utils/SettingsHelper.java b/app/src/main/java/awais/instagrabber/utils/SettingsHelper.java index 53d07f47..d6b22b5b 100755 --- a/app/src/main/java/awais/instagrabber/utils/SettingsHelper.java +++ b/app/src/main/java/awais/instagrabber/utils/SettingsHelper.java @@ -14,6 +14,7 @@ import static awais.instagrabber.utils.Constants.APP_THEME; import static awais.instagrabber.utils.Constants.AUTOLOAD_POSTS; import static awais.instagrabber.utils.Constants.AUTOPLAY_VIDEOS; import static awais.instagrabber.utils.Constants.BOTTOM_TOOLBAR; +import static awais.instagrabber.utils.Constants.CHECK_ACTIVITY; import static awais.instagrabber.utils.Constants.COOKIE; import static awais.instagrabber.utils.Constants.CUSTOM_DATE_TIME_FORMAT; import static awais.instagrabber.utils.Constants.CUSTOM_DATE_TIME_FORMAT_ENABLED; @@ -110,7 +111,7 @@ public final class SettingsHelper { public @interface StringSettings {} @StringDef({DOWNLOAD_USER_FOLDER, BOTTOM_TOOLBAR, FOLDER_SAVE_TO, AUTOPLAY_VIDEOS, SHOW_QUICK_ACCESS_DIALOG, MUTED_VIDEOS, - AUTOLOAD_POSTS, CUSTOM_DATE_TIME_FORMAT_ENABLED, MARK_AS_SEEN, INSTADP, STORIESIG, AMOLED_THEME}) + AUTOLOAD_POSTS, CUSTOM_DATE_TIME_FORMAT_ENABLED, MARK_AS_SEEN, INSTADP, STORIESIG, AMOLED_THEME, CHECK_ACTIVITY}) public @interface BooleanSettings {} @StringDef({APP_THEME, APP_LANGUAGE, PREV_INSTALL_VERSION}) diff --git a/app/src/main/res/drawable-anydpi/ic_submit.xml b/app/src/main/res/drawable-anydpi/ic_submit.xml new file mode 100644 index 00000000..0432fa69 --- /dev/null +++ b/app/src/main/res/drawable-anydpi/ic_submit.xml @@ -0,0 +1,10 @@ + + + diff --git a/app/src/main/res/drawable-hdpi/ic_submit.png b/app/src/main/res/drawable-hdpi/ic_submit.png new file mode 100644 index 0000000000000000000000000000000000000000..54775ebdd04314c1211a36e34785cc749612ae91 GIT binary patch literal 186 zcmeAS@N?(olHy`uVBq!ia0vp^Dj>|k1|%Oc%$NbB8a-VcLn>~)z3#}>pdiqin17iu zE$wlpjc@sjZBLyz41+wLJHBtvFt3@y)pkH4+5XHKB_XwyuO{9%nDJ>x-AXn!L1!Mr zfEhJzJ$$pfBxS9>n%{M_Jv@EQ%(yF;SpT#Y-SqX>xV|=au}ez1eR`J2sfFT+2But0 j!Mhx!^Vxbf_FFNUp6I-A|5Sb%&@l|2u6{1-oD!M<=XgZo literal 0 HcmV?d00001 diff --git a/app/src/main/res/drawable-mdpi/ic_submit.png b/app/src/main/res/drawable-mdpi/ic_submit.png new file mode 100644 index 0000000000000000000000000000000000000000..9dee29dd376f6b7aceba9b8a705c216f092392e2 GIT binary patch literal 139 zcmeAS@N?(olHy`uVBq!ia0vp^5+KaM1|%Pp+x`GjL7py-Ar-fh6C_v{H;5!8B`xwZ zKJ4r3yS72>49g`>6XQ8*Vm(rRwTB(09M~=#DG0D~yOiTPIlq m3ulT<)Ll69;o^h}1_nuSm;XBt3(W(X&fw|l=d#Wzp$Pz#&@68N literal 0 HcmV?d00001 diff --git a/app/src/main/res/drawable-xhdpi/ic_submit.png b/app/src/main/res/drawable-xhdpi/ic_submit.png new file mode 100644 index 0000000000000000000000000000000000000000..6dc1a3f02fbe843181ddceb8c49b4e9b6f53e52f GIT binary patch literal 323 zcmV-J0lfZ+P)iejCAQdo$=CWTk=1bP4wgBH21Gmv6gvWXgScl3L(RoKk?Cc|cX zJpcdz0D#}a^Sn_I1RIg^Q4|e*-@ni*Y3)SGr)fG?U(zV$kcYehlAMT^ zr{nSl`EL`)@l>=t$rh0R8+n@5KCL4Qba=mH60001>15as{ V`cQY_8gT#s002ovPDHLkV1k4>ij@EW literal 0 HcmV?d00001 diff --git a/app/src/main/res/drawable-xxhdpi/ic_submit.png b/app/src/main/res/drawable-xxhdpi/ic_submit.png new file mode 100644 index 0000000000000000000000000000000000000000..a017055bbbca85813350c3a92c0d0b69d6e0a1bd GIT binary patch literal 337 zcmeAS@N?(olHy`uVBq!ia0vp^9w5xY1|&n@Zgyv2V3hE5aSW-r_4bB0*C7KDhl}Ut z{-9%`BC$=ozq0C-OuFIUq_R`oC^z1}d722TAQS{PWv&g^hOvV6V3+JECuI zn;q~yV^*59YM*3GTlGxFv&=KL%Y2f%_~^@N^PnJ$eG?ZQHRNn6f8?$Lv%ZLkE@TnBYcsvk*`s(jq{u6)H9Gt(| RJOTz4gQu&X%Q~loCIFy(hOz(v literal 0 HcmV?d00001 diff --git a/app/src/main/res/layout/activity_direct_messages.xml b/app/src/main/res/layout/activity_direct_messages.xml index cda5e611..459fadaa 100644 --- a/app/src/main/res/layout/activity_direct_messages.xml +++ b/app/src/main/res/layout/activity_direct_messages.xml @@ -44,10 +44,26 @@ + + diff --git a/app/src/main/res/layout/activity_saved.xml b/app/src/main/res/layout/activity_saved.xml index c5b0d296..7dbd46a1 100644 --- a/app/src/main/res/layout/activity_saved.xml +++ b/app/src/main/res/layout/activity_saved.xml @@ -1,6 +1,5 @@ + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/item_feed_top.xml b/app/src/main/res/layout/item_feed_top.xml index 0e0991d1..78dab810 100755 --- a/app/src/main/res/layout/item_feed_top.xml +++ b/app/src/main/res/layout/item_feed_top.xml @@ -1,7 +1,6 @@ + + + + + \ No newline at end of file diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index df5ceba0..05fbc373 100755 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -37,6 +37,7 @@ Download posts to username folder in Downloads Auto-load all posts from user Mark stories as seen after viewing\n(Story author will know you viewed it) + Enable activity notifications Error loading profile!\nTry logging in and search again. Error creating Download folder(s). Show user feed (Works only when user is logged in) @@ -169,6 +170,9 @@ Suggested Screenshotted Cannot delivered + Great success! + Leave + Leave this chat? Download directly Downloads posts directly to the phone! Fetching post(s) From ae058813e04815464d64733a4f2c97a242848b44 Mon Sep 17 00:00:00 2001 From: Austin Huang Date: Sat, 22 Aug 2020 17:09:36 -0400 Subject: [PATCH 2/3] stop notification toast --- app/src/main/java/awais/instagrabber/activities/Main.java | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/app/src/main/java/awais/instagrabber/activities/Main.java b/app/src/main/java/awais/instagrabber/activities/Main.java index ab7c9b2a..57c24244 100755 --- a/app/src/main/java/awais/instagrabber/activities/Main.java +++ b/app/src/main/java/awais/instagrabber/activities/Main.java @@ -263,11 +263,7 @@ public final class Main extends BaseLanguageActivity { handler = new Handler(); runnable = () -> { final GetActivityAsyncTask activityAsyncTask = new GetActivityAsyncTask(uid, cookie, result -> { - if (result == null) { - Toast.makeText(Main.this, R.string.downloader_unknown_error, Toast.LENGTH_SHORT).show(); - return; - } - if (notificationManager == null) { + if (result == null || notificationManager == null) { return; } final List list = new ArrayList<>(); From 23269528fe320c177dc81f2a2707b0cfd285bdf3 Mon Sep 17 00:00:00 2001 From: Austin Huang Date: Sat, 22 Aug 2020 17:29:58 -0400 Subject: [PATCH 3/3] version up --- app/build.gradle | 4 ++-- fastlane/metadata/android/en-US/changelogs/47.txt | 3 +++ 2 files changed, 5 insertions(+), 2 deletions(-) create mode 100644 fastlane/metadata/android/en-US/changelogs/47.txt diff --git a/app/build.gradle b/app/build.gradle index e5b0c4fa..c30ea6bf 100755 --- a/app/build.gradle +++ b/app/build.gradle @@ -10,8 +10,8 @@ android { minSdkVersion 16 targetSdkVersion 29 - versionCode 46 - versionName '18.0' + versionCode 47 + versionName '18.1' multiDexEnabled true diff --git a/fastlane/metadata/android/en-US/changelogs/47.txt b/fastlane/metadata/android/en-US/changelogs/47.txt new file mode 100644 index 00000000..c6b2a0fe --- /dev/null +++ b/fastlane/metadata/android/en-US/changelogs/47.txt @@ -0,0 +1,3 @@ +* You can now change the topic or leave a room, as well as see members +* More optimizations on activity check (You can now disable it) and DM +* Fix the inconsistent autoplay setting bug \ No newline at end of file