From 7af96bf591efad1a317366f3abf66d1aebae7770 Mon Sep 17 00:00:00 2001 From: Austin Huang Date: Sun, 26 Jul 2020 18:23:24 -0400 Subject: [PATCH] v16.9 part 1 --- app/build.gradle | 6 +- .../activities/CommentsViewer.java | 246 ++++++++++++++---- .../awais/instagrabber/activities/Main.java | 3 +- .../instagrabber/activities/PostViewer.java | 23 +- .../instagrabber/activities/StoryViewer.java | 7 +- .../adapters/CommentsAdapter.java | 1 + .../instagrabber/adapters/FeedAdapter.java | 6 +- .../viewholder/CommentViewHolder.java | 4 + .../instagrabber/asyncs/CommentsFetcher.java | 3 + .../instagrabber/asyncs/FeedFetcher.java | 3 +- .../instagrabber/asyncs/PostFetcher.java | 1 + .../instagrabber/asyncs/PostsFetcher.java | 2 +- .../helpers/VideoAwareRecyclerScroller.java | 6 +- .../dialogs/QuickAccessDialog.java | 14 +- .../directdownload/MultiDirectDialog.java | 2 +- .../instagrabber/models/BasePostModel.java | 12 + .../instagrabber/models/CommentModel.java | 10 +- .../awais/instagrabber/models/FeedModel.java | 4 +- .../awais/instagrabber/models/PostModel.java | 8 +- .../awais/instagrabber/utils/FlavorTown.java | 2 +- app/src/main/res/layout/activity_comments.xml | 68 ++++- app/src/main/res/layout/activity_viewer.xml | 4 +- .../main/res/layout/item_comment_small.xml | 47 ++-- .../res/layout/layout_include_simple_item.xml | 67 ++--- app/src/main/res/values-de/strings.xml | 2 +- app/src/main/res/values-es/strings.xml | 2 +- app/src/main/res/values-fr/strings.xml | 2 +- app/src/main/res/values-in/strings.xml | 2 +- app/src/main/res/values-it/strings.xml | 2 +- app/src/main/res/values-pl/strings.xml | 2 +- app/src/main/res/values-zh/strings.xml | 2 +- app/src/main/res/values/arrays.xml | 2 + app/src/main/res/values/strings.xml | 13 +- 33 files changed, 419 insertions(+), 159 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index 190d620f..2757b8d6 100755 --- a/app/build.gradle +++ b/app/build.gradle @@ -9,11 +9,11 @@ android { minSdkVersion 16 targetSdkVersion 29 - // REMEMBER TO CHANGE versionCode as well + // REMEMBER TO CHANGE versionCode AS WELL // 16.7 is 32 - versionCode 33 - versionName '16.8' + versionCode 34 + versionName '16.9' multiDexEnabled true diff --git a/app/src/main/java/awais/instagrabber/activities/CommentsViewer.java b/app/src/main/java/awais/instagrabber/activities/CommentsViewer.java index 1c2c4438..1aa14b09 100755 --- a/app/src/main/java/awais/instagrabber/activities/CommentsViewer.java +++ b/app/src/main/java/awais/instagrabber/activities/CommentsViewer.java @@ -8,15 +8,25 @@ import android.os.Bundle; 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.WindowManager; import android.widget.ArrayAdapter; +import android.widget.Toast; import androidx.annotation.Nullable; import androidx.appcompat.app.AlertDialog; import androidx.appcompat.app.AppCompatActivity; import androidx.appcompat.widget.SearchView; +import androidx.swiperefreshlayout.widget.SwipeRefreshLayout; + +import java.io.DataOutputStream; +import java.net.HttpURLConnection; +import java.net.URL; +import java.net.URLEncoder; import awais.instagrabber.R; import awais.instagrabber.adapters.CommentsAdapter; @@ -29,79 +39,71 @@ import awais.instagrabber.models.ProfileModel; import awais.instagrabber.utils.Constants; import awais.instagrabber.utils.Utils; -public final class CommentsViewer extends AppCompatActivity { +import static awais.instagrabber.utils.Utils.settingsHelper; + +public final class CommentsViewer extends BaseLanguageActivity implements SwipeRefreshLayout.OnRefreshListener { private CommentsAdapter commentsAdapter; private CommentModel commentModel; + private ActivityCommentsBinding commentsBinding; + private ArrayAdapter commmentDialogAdapter; + private String shortCode, postId, userId; + private final String cookie = Utils.settingsHelper.getString(Constants.COOKIE); + private Resources resources; @Override protected void onCreate(@Nullable final Bundle savedInstanceState) { super.onCreate(savedInstanceState); - final ActivityCommentsBinding commentsBinding = ActivityCommentsBinding.inflate(getLayoutInflater()); + commentsBinding = ActivityCommentsBinding.inflate(getLayoutInflater()); setContentView(commentsBinding.getRoot()); + commentsBinding.swipeRefreshLayout.setOnRefreshListener(this); - final String shortCode; final Intent intent = getIntent(); if (intent == null || !intent.hasExtra(Constants.EXTRAS_SHORTCODE) - || Utils.isEmpty((shortCode = intent.getStringExtra(Constants.EXTRAS_SHORTCODE)))) { + || Utils.isEmpty((shortCode = intent.getStringExtra(Constants.EXTRAS_SHORTCODE))) + || !intent.hasExtra(Constants.EXTRAS_POST) + || Utils.isEmpty((postId = intent.getStringExtra(Constants.EXTRAS_POST))) + || !intent.hasExtra(Constants.EXTRAS_USER) + || Utils.isEmpty((userId = intent.getStringExtra(Constants.EXTRAS_USER)))) { Utils.errorFinish(this); return; } + commentsBinding.swipeRefreshLayout.setRefreshing(true); setSupportActionBar(commentsBinding.toolbar.toolbar); commentsBinding.toolbar.toolbar.setTitle(R.string.title_comments); commentsBinding.toolbar.toolbar.setSubtitle(shortCode); - final Resources resources = getResources(); + resources = getResources(); - final ArrayAdapter commmentDialogAdapter = new ArrayAdapter<>(this, android.R.layout.simple_list_item_1, - new String[]{resources.getString(R.string.open_profile), - resources.getString(R.string.view_pfp), - resources.getString(R.string.comment_viewer_copy_user), - resources.getString(R.string.comment_viewer_copy_comment)}); - final DialogInterface.OnClickListener profileDialogListener = (dialog, which) -> { - final ProfileModel profileModel = commentModel.getProfileModel(); + if (!Utils.isEmpty(cookie)) { + commentsBinding.commentText.setVisibility(View.VISIBLE); + commentsBinding.commentSend.setVisibility(View.VISIBLE); - if (which == 0) { - searchUsername(profileModel.getUsername()); - } else if (which == 1) { - startActivity(new Intent(this, ProfileViewer.class).putExtra(Constants.EXTRAS_PROFILE, profileModel)); - } else if (which == 2) { - Utils.copyText(this, profileModel.getUsername()); - } else if (which == 3) { - Utils.copyText(this, commentModel.getText().toString()); - } - }; - - final View.OnClickListener clickListener = v -> { - final Object tag = v.getTag(); - if (tag instanceof CommentModel) { - commentModel = (CommentModel) tag; - - final String username = commentModel.getProfileModel().getUsername(); - final SpannableString title = new SpannableString(username + ":\n" + commentModel.getText()); - title.setSpan(new RelativeSizeSpan(1.23f), 0, username.length(), Spanned.SPAN_INCLUSIVE_INCLUSIVE); - - new AlertDialog.Builder(this).setTitle(title) - .setAdapter(commmentDialogAdapter, profileDialogListener) - .setNeutralButton(R.string.cancel, null) - .show(); - } - }; - - final MentionClickListener mentionClickListener = (view, text, isHashtag) -> - new AlertDialog.Builder(this).setTitle(text) - .setMessage(isHashtag ? R.string.comment_view_mention_hash_search : R.string.comment_view_mention_user_search) - .setNegativeButton(R.string.cancel, null).setPositiveButton(R.string.ok, - (dialog, which) -> searchUsername(text)).show(); + commentsBinding.commentSend.setOnClickListener(newCommentListener); + commentsBinding.commentCancelParent.setOnClickListener(newCommentListener); + } new CommentsFetcher(shortCode, new FetchListener() { @Override - public void doBefore() { - commentsBinding.toolbar.progressCircular.setVisibility(View.VISIBLE); - } + public void onResult(final CommentModel[] commentModels) { + commentsBinding.toolbar.progressCircular.setVisibility(View.GONE); + commentsAdapter = new CommentsAdapter(commentModels, true, clickListener, mentionClickListener); + + commentsBinding.rvComments.setAdapter(commentsAdapter); + commentsBinding.swipeRefreshLayout.setRefreshing(false); + } + }).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); + } + + @Override + public void onRefresh() { + commentsBinding.swipeRefreshLayout.setRefreshing(true); + new CommentsFetcher(shortCode, new FetchListener() { @Override public void onResult(final CommentModel[] commentModels) { + commentsBinding.swipeRefreshLayout.setRefreshing(false); + commentsBinding.toolbar.progressCircular.setVisibility(View.GONE); commentsAdapter = new CommentsAdapter(commentModels, true, clickListener, mentionClickListener); @@ -111,6 +113,103 @@ public final class CommentsViewer extends AppCompatActivity { }).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); } + final DialogInterface.OnClickListener profileDialogListener = (dialog, which) -> { + final ProfileModel profileModel = commentModel.getProfileModel(); + + if (which == 0) { + searchUsername(profileModel.getUsername()); + } else if (which == 1) { + startActivity(new Intent(this, ProfileViewer.class).putExtra(Constants.EXTRAS_PROFILE, profileModel)); + } else if (which == 2) { + Utils.copyText(this, profileModel.getUsername()); + } else if (which == 3) { + Utils.copyText(this, commentModel.getText().toString()); + } else if (which == 4) { + commentsBinding.rvComments.findViewWithTag(commentModel).setBackgroundColor(0x80888888); + commentsBinding.commentCancelParent.setVisibility(View.VISIBLE); + String mention = "@"+profileModel.getUsername()+" "; + commentsBinding.commentText.setText(mention); + commentsBinding.commentText.requestFocus(); + commentsBinding.commentText.setSelection(mention.length()); + commentsBinding.commentText.postDelayed(new Runnable(){ + @Override + public void run(){ + final InputMethodManager imm = (InputMethodManager) getSystemService(getApplicationContext().INPUT_METHOD_SERVICE); + imm.showSoftInput(commentsBinding.commentText, 0); + } + } + ,200); + } else if (which == 5) { + new CommentAction().execute((commentModel.getLiked() ? "unlike/" : "like/")+commentModel.getId()); + } else if (which == 6) { + new CommentAction().execute("delete/"+commentModel.getId()); + } + }; + + private final View.OnClickListener clickListener = v -> { + final Object tag = v.getTag(); + if (tag instanceof CommentModel) { + commentModel = (CommentModel) tag; + + final String username = commentModel.getProfileModel().getUsername(); + final SpannableString title = new SpannableString(username + ":\n" + commentModel.getText()); + title.setSpan(new RelativeSizeSpan(1.23f), 0, username.length(), Spanned.SPAN_INCLUSIVE_INCLUSIVE); + + String[] commentDialogList; + + if (!Utils.isEmpty(cookie) && + (Utils.getUserIdFromCookie(cookie).equals(commentModel.getProfileModel().getId()) || + Utils.getUserIdFromCookie(cookie).equals(userId))) commentDialogList = new String[]{ + resources.getString(R.string.open_profile), + resources.getString(R.string.view_pfp), + resources.getString(R.string.comment_viewer_copy_user), + resources.getString(R.string.comment_viewer_copy_comment), + resources.getString(R.string.comment_viewer_reply_comment), + commentModel.getLiked() ? resources.getString(R.string.comment_viewer_unlike_comment) : resources.getString(R.string.comment_viewer_like_comment), + resources.getString(R.string.comment_viewer_delete_comment) + }; + else if (!Utils.isEmpty(cookie)) commentDialogList = new String[]{ + resources.getString(R.string.open_profile), + resources.getString(R.string.view_pfp), + resources.getString(R.string.comment_viewer_copy_user), + resources.getString(R.string.comment_viewer_copy_comment), + resources.getString(R.string.comment_viewer_reply_comment), + commentModel.getLiked() ? resources.getString(R.string.comment_viewer_unlike_comment) : resources.getString(R.string.comment_viewer_like_comment), + }; + else commentDialogList = new String[]{ + resources.getString(R.string.open_profile), + resources.getString(R.string.view_pfp), + resources.getString(R.string.comment_viewer_copy_user), + resources.getString(R.string.comment_viewer_copy_comment) + }; + + commmentDialogAdapter = new ArrayAdapter<>(this, android.R.layout.simple_list_item_1, commentDialogList); + + new AlertDialog.Builder(this).setTitle(title) + .setAdapter(commmentDialogAdapter, profileDialogListener) + .setNeutralButton(R.string.cancel, null) + .show(); + } + }; + + private final MentionClickListener mentionClickListener = (view, text, isHashtag) -> + new AlertDialog.Builder(this).setTitle(text) + .setMessage(isHashtag ? R.string.comment_view_mention_hash_search : R.string.comment_view_mention_user_search) + .setNegativeButton(R.string.cancel, null).setPositiveButton(R.string.ok, + (dialog, which) -> searchUsername(text)).show(); + + private final View.OnClickListener newCommentListener = v -> { + if (Utils.isEmpty(commentsBinding.commentText.getText().toString()) && v == commentsBinding.commentSend) + Toast.makeText(getApplicationContext(), R.string.comment_send_empty_comment, Toast.LENGTH_SHORT).show(); + else if (v == commentsBinding.commentSend) new CommentAction().execute("add"); + else if (v == commentsBinding.commentCancelParent) { + commentsBinding.rvComments.findViewWithTag(commentModel).setBackgroundColor(commentModel.getLiked() ? 0x40FF69B4 : 0x00000000); + commentsBinding.commentCancelParent.setVisibility(View.GONE); + commentsBinding.commentText.setText(""); + commentModel = null; + } + }; + private void searchUsername(final String text) { if (Main.scanHack != null) { Main.scanHack.onResult(text); @@ -143,4 +242,57 @@ public final class CommentsViewer extends AppCompatActivity { return true; } + + class CommentAction extends AsyncTask { + boolean ok = false; + + protected Void doInBackground(String... rawAction) { + final String action = rawAction[0]; + final String url = "https://www.instagram.com/web/comments/"+postId+"/"+action+"/"; + try { + final HttpURLConnection urlConnection = (HttpURLConnection) new URL(url).openConnection(); + urlConnection.setRequestMethod("POST"); + urlConnection.setUseCaches(false); + urlConnection.setRequestProperty("User-Agent", Constants.USER_AGENT); + urlConnection.setRequestProperty("x-csrftoken", cookie.split("csrftoken=")[1].split(";")[0]); + if (action == "add") { + // https://stackoverflow.com/questions/14321873/java-url-encoding-urlencoder-vs-uri + final String commentText = URLEncoder.encode(commentsBinding.commentText.getText().toString(), "UTF-8") + .replaceAll("\\+", "%20").replaceAll("\\%21", "!").replaceAll("\\%27", "'") + .replaceAll("\\%28", "(").replaceAll("\\%29", ")").replaceAll("\\%7E", "~"); + final String urlParameters = "comment_text="+commentText+"&replied_to_comment_id="+ + (commentModel == null ? "" : commentModel.getId()); + 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; + if (action == "add") commentsBinding.commentText.setText(""); + } + else Toast.makeText(getApplicationContext(), R.string.downloader_unknown_error, Toast.LENGTH_SHORT).show(); + urlConnection.disconnect(); + } catch (Throwable ex) { + Log.e("austin_debug", action+": " + ex); + } + return null; + } + + @Override + protected void onPostExecute(Void result) { + if (ok == true) { + if (commentModel != null) { + commentsBinding.rvComments.findViewWithTag(commentModel).setBackgroundColor(commentModel.getLiked() ? 0x40FF69B4 : 0x00000000); + commentsBinding.commentCancelParent.setVisibility(View.GONE); + } + onRefresh(); + } + } + } } \ No newline at end of file diff --git a/app/src/main/java/awais/instagrabber/activities/Main.java b/app/src/main/java/awais/instagrabber/activities/Main.java index 0bd94955..9be7730b 100755 --- a/app/src/main/java/awais/instagrabber/activities/Main.java +++ b/app/src/main/java/awais/instagrabber/activities/Main.java @@ -316,7 +316,8 @@ public final class Main extends BaseLanguageActivity { searchView.setQueryHint(getResources().getString(R.string.action_search)); searchView.setSuggestionsAdapter(suggestionAdapter); searchView.setOnSearchClickListener(v -> { - searchView.setQuery(userQuery, false); + searchView.setQuery((profileModel != null && profileModel.getId().equals( + Utils.getUserIdFromCookie(Utils.settingsHelper.getString(Constants.COOKIE))) ? "" : userQuery), false); menu.findItem(R.id.action_about).setVisible(false); menu.findItem(R.id.action_settings).setVisible(false); menu.findItem(R.id.action_dms).setVisible(false); diff --git a/app/src/main/java/awais/instagrabber/activities/PostViewer.java b/app/src/main/java/awais/instagrabber/activities/PostViewer.java index 795d9cc3..c4da946a 100755 --- a/app/src/main/java/awais/instagrabber/activities/PostViewer.java +++ b/app/src/main/java/awais/instagrabber/activities/PostViewer.java @@ -81,7 +81,7 @@ public final class PostViewer extends BaseLanguageActivity { private View viewsContainer, viewerCaptionParent; private GestureDetectorCompat gestureDetector; private SwipeEvent swipeEvent; - private CharSequence postCaption = null, postShortCode; + private CharSequence postCaption = null, postShortCode, postUserId; private Resources resources; private boolean session = false, isFromShare; private int slidePos = 0, lastSlidePos = 0; @@ -153,7 +153,7 @@ public final class PostViewer extends BaseLanguageActivity { if (player != null) { final float intVol = player.getVolume() == 0f ? 1f : 0f; player.setVolume(intVol); - viewerBinding.bottomPanel.btnMute.setImageResource(intVol == 0f ? R.drawable.vol : R.drawable.mute); + viewerBinding.bottomPanel.btnMute.setImageResource(intVol == 0f ? R.drawable.mute : R.drawable.vol); Utils.sessionVolumeFull = intVol == 1f; } } else if (v == viewerBinding.btnLike) { @@ -359,7 +359,9 @@ public final class PostViewer extends BaseLanguageActivity { viewerBinding.bottomPanel.btnComments.setOnClickListener(v -> startActivityForResult(new Intent(this, CommentsViewer.class) .putExtra(Constants.EXTRAS_END_CURSOR, commentsEndCursor) - .putExtra(Constants.EXTRAS_SHORTCODE, postShortCode), 6969)); + .putExtra(Constants.EXTRAS_SHORTCODE, postShortCode) + .putExtra(Constants.EXTRAS_POST, viewerPostModel.getPostId()) + .putExtra(Constants.EXTRAS_USER, postUserId), 6969)); viewerBinding.bottomPanel.btnComments.setClickable(true); viewerBinding.bottomPanel.btnComments.setEnabled(true); } else { @@ -592,12 +594,12 @@ public final class PostViewer extends BaseLanguageActivity { postModel.setLike(viewerPostModel.getLike()); postModel.setBookmark(viewerPostModel.getBookmark()); if (viewerPostModel.getLike() == true) { - viewerBinding.btnLike.setText(R.string.unlike); + viewerBinding.btnLike.setText(resources.getString(R.string.unlike, postModel.getLikes())); viewerBinding.btnLike.setBackgroundTintList(ColorStateList.valueOf(resources.getColor( R.color.btn_pink_background, null))); } else { - viewerBinding.btnLike.setText(R.string.like); + viewerBinding.btnLike.setText(resources.getString(R.string.like, postModel.getLikes())); viewerBinding.btnLike.setBackgroundTintList(ColorStateList.valueOf(resources.getColor( R.color.btn_lightpink_background, null))); } @@ -620,7 +622,7 @@ public final class PostViewer extends BaseLanguageActivity { url = viewerPostModel.getDisplayUrl(); releasePlayer(); - viewerBinding.btnDownload.setVisibility(containerLayoutParams.weight == 3.3f ? View.GONE : View.VISIBLE); + viewerBinding.btnDownload.setVisibility(containerLayoutParams.weight == 3.3f ? View.VISIBLE : View.GONE); if (viewerPostModel.getItemType() == MediaItemType.MEDIA_TYPE_VIDEO) setupVideo(); else setupImage(); } @@ -645,6 +647,7 @@ public final class PostViewer extends BaseLanguageActivity { if (result != null) { final String hdProfilePic = result.getHdProfilePic(); final String sdProfilePic = result.getSdProfilePic(); + postUserId = result.getId(); final boolean hdPicEmpty = Utils.isEmpty(hdProfilePic); glideRequestManager.load(hdPicEmpty ? sdProfilePic : hdProfilePic).listener(new RequestListener() { @@ -732,13 +735,13 @@ public final class PostViewer extends BaseLanguageActivity { @Override protected void onPostExecute(Void result) { if (ok == true && action == "likes") { - viewerPostModel.setLike(postModel.getLike() == true ? false : true); - postModel.setLike(postModel.getLike() == true ? false : true); + viewerPostModel.setLike(!postModel.getLike()); + postModel.setManualLike(!postModel.getLike()); refreshPost(); } else if (ok == true && action == "save") { - viewerPostModel.setBookmark(postModel.getBookmark() == true ? false : true); - postModel.setBookmark(postModel.getBookmark() == true ? false : true); + viewerPostModel.setBookmark(!postModel.getBookmark()); + postModel.setBookmark(!postModel.getBookmark()); refreshPost(); } } diff --git a/app/src/main/java/awais/instagrabber/activities/StoryViewer.java b/app/src/main/java/awais/instagrabber/activities/StoryViewer.java index e4de59ff..c657f79c 100755 --- a/app/src/main/java/awais/instagrabber/activities/StoryViewer.java +++ b/app/src/main/java/awais/instagrabber/activities/StoryViewer.java @@ -121,8 +121,10 @@ public final class StoryViewer extends BaseLanguageActivity { @Override public void onSwipe(final boolean isRightSwipe) { + Log.d("austin_debug", "swipe: "+(isRightSwipe ? "backward " : "forward ") + slidePos + "/" + storiesLen + " " + + (slidePos == storiesLen - 1 && isRightSwipe == false) + " " + intent.hasExtra(Constants.FEED)); if (storyModels != null && storiesLen > 0) { - if (((slidePos == storiesLen - 1 && isRightSwipe == false) || (slidePos == 0 && isRightSwipe == true)) + if (((slidePos + 1 >= storiesLen && isRightSwipe == false) || (slidePos == 0 && isRightSwipe == true)) && intent.hasExtra(Constants.FEED)) { final FeedStoryModel[] storyFeed = (FeedStoryModel[]) intent.getSerializableExtra(Constants.FEED); final int index = intent.getIntExtra(Constants.FEED_ORDER, 1738); @@ -148,9 +150,8 @@ public final class StoryViewer extends BaseLanguageActivity { if (isRightSwipe) { if (--slidePos <= 0) slidePos = 0; } else if (++slidePos >= storiesLen) slidePos = storiesLen - 1; - currentStory = storyModels[slidePos]; - slidePos = currentStory.getPosition(); + //slidePos = currentStory.getPosition(); refreshStory(); } } diff --git a/app/src/main/java/awais/instagrabber/adapters/CommentsAdapter.java b/app/src/main/java/awais/instagrabber/adapters/CommentsAdapter.java index 69221bf0..3a456c21 100755 --- a/app/src/main/java/awais/instagrabber/adapters/CommentsAdapter.java +++ b/app/src/main/java/awais/instagrabber/adapters/CommentsAdapter.java @@ -107,6 +107,7 @@ public final class CommentsAdapter extends RecyclerView.Adapter switch (id) { case R.id.btnComments: activity.startActivityForResult(new Intent(activity, CommentsViewer.class) - .putExtra(Constants.EXTRAS_SHORTCODE, feedModel.getShortCode()), 6969); + .putExtra(Constants.EXTRAS_SHORTCODE, feedModel.getShortCode()) + .putExtra(Constants.EXTRAS_POST, feedModel.getPostId()) + .putExtra(Constants.EXTRAS_USER, feedModel.getProfileModel().getId()), 6969); break; case R.id.viewStoryPost: @@ -305,7 +307,7 @@ public final class FeedAdapter extends RecyclerView.Adapter final SimpleExoPlayer exoPlayer = (SimpleExoPlayer) player; final float intVol = exoPlayer.getVolume() == 0f ? 1f : 0f; exoPlayer.setVolume(intVol); - viewHolder.btnMute.setImageResource(intVol == 0f ? R.drawable.vol : R.drawable.mute); + viewHolder.btnMute.setImageResource(intVol == 0f ? R.drawable.mute : R.drawable.vol); Utils.sessionVolumeFull = intVol == 1f; } }; diff --git a/app/src/main/java/awais/instagrabber/adapters/viewholder/CommentViewHolder.java b/app/src/main/java/awais/instagrabber/adapters/viewholder/CommentViewHolder.java index 08476443..d34b0597 100755 --- a/app/src/main/java/awais/instagrabber/adapters/viewholder/CommentViewHolder.java +++ b/app/src/main/java/awais/instagrabber/adapters/viewholder/CommentViewHolder.java @@ -65,6 +65,10 @@ public final class CommentViewHolder extends RecyclerView.ViewHolder { if (tvLikes != null) tvLikes.setText(likes); } + public final void setLiked(final boolean liked) { + if (liked) container.setBackgroundColor(0x40FF69B4); + } + public final void setCommment(final CharSequence commment) { if (tvComment != null) { tvComment.setText(commment, commment instanceof Spannable ? TextView.BufferType.SPANNABLE : TextView.BufferType.NORMAL); diff --git a/app/src/main/java/awais/instagrabber/asyncs/CommentsFetcher.java b/app/src/main/java/awais/instagrabber/asyncs/CommentsFetcher.java index 02247264..400859a8 100755 --- a/app/src/main/java/awais/instagrabber/asyncs/CommentsFetcher.java +++ b/app/src/main/java/awais/instagrabber/asyncs/CommentsFetcher.java @@ -123,6 +123,7 @@ public final class CommentsFetcher extends AsyncTask childComment.getString("text"), childComment.getLong("created_at"), likedBy != null ? likedBy.optLong("count", 0) : 0, + childComment.getBoolean("viewer_has_liked"), profileModel)); } } @@ -201,6 +202,7 @@ public final class CommentsFetcher extends AsyncTask comment.getString("text"), comment.getLong("created_at"), likedBy != null ? likedBy.optLong("count", 0) : 0, + comment.getBoolean("viewer_has_liked"), profileModel); JSONObject tempJsonObject; @@ -238,6 +240,7 @@ public final class CommentsFetcher extends AsyncTask childComment.getString("text"), childComment.getLong("created_at"), tempJsonObject != null ? tempJsonObject.optLong("count", 0) : 0, + childComment.getBoolean("viewer_has_liked"), childProfileModel); } diff --git a/app/src/main/java/awais/instagrabber/asyncs/FeedFetcher.java b/app/src/main/java/awais/instagrabber/asyncs/FeedFetcher.java index 0c22564e..360e54d8 100755 --- a/app/src/main/java/awais/instagrabber/asyncs/FeedFetcher.java +++ b/app/src/main/java/awais/instagrabber/asyncs/FeedFetcher.java @@ -131,7 +131,8 @@ public final class FeedFetcher extends AsyncTask { commentsCount, feedItem.optLong("taken_at_timestamp", -1), feedItem.getBoolean("viewer_has_liked"), - feedItem.getBoolean("viewer_has_saved")); + feedItem.getBoolean("viewer_has_saved"), + feedItem.getJSONObject("edge_media_preview_like").getLong("count")); final boolean isSlider = "GraphSidecar".equals(mediaType) && feedItem.has("edge_sidecar_to_children"); diff --git a/app/src/main/java/awais/instagrabber/asyncs/PostFetcher.java b/app/src/main/java/awais/instagrabber/asyncs/PostFetcher.java index 2094233a..9ea1ecf0 100755 --- a/app/src/main/java/awais/instagrabber/asyncs/PostFetcher.java +++ b/app/src/main/java/awais/instagrabber/asyncs/PostFetcher.java @@ -81,6 +81,7 @@ public final class PostFetcher extends AsyncTask endCursor = commentObject.optString("end_cursor"); if (mediaItemType != MediaItemType.MEDIA_TYPE_SLIDER) { + Log.d("austin_debug", "m: "+media); final ViewerPostModel postModel = new ViewerPostModel(mediaItemType, media.getString(Constants.EXTRAS_ID), isVideo ? media.getString("video_url") : Utils.getHighQualityImage(media), diff --git a/app/src/main/java/awais/instagrabber/asyncs/PostsFetcher.java b/app/src/main/java/awais/instagrabber/asyncs/PostsFetcher.java index f5372b55..b23a7223 100755 --- a/app/src/main/java/awais/instagrabber/asyncs/PostsFetcher.java +++ b/app/src/main/java/awais/instagrabber/asyncs/PostsFetcher.java @@ -107,7 +107,7 @@ public final class PostsFetcher extends AsyncTask { mediaNode.getString(Constants.EXTRAS_SHORTCODE), captions.length() > 0 ? captions.getJSONObject(0).getJSONObject("node").getString("text") : null, mediaNode.getLong("taken_at_timestamp"), mediaNode.optBoolean("viewer_has_liked"), - mediaNode.optBoolean("viewer_has_saved")); + mediaNode.optBoolean("viewer_has_saved"), mediaNode.getJSONObject("edge_liked_by").getLong("count")); Utils.checkExistence(downloadDir, customDir, username, isSlider, -1, models[i]); } diff --git a/app/src/main/java/awais/instagrabber/customviews/helpers/VideoAwareRecyclerScroller.java b/app/src/main/java/awais/instagrabber/customviews/helpers/VideoAwareRecyclerScroller.java index 1deff1ad..0ee171f1 100755 --- a/app/src/main/java/awais/instagrabber/customviews/helpers/VideoAwareRecyclerScroller.java +++ b/app/src/main/java/awais/instagrabber/customviews/helpers/VideoAwareRecyclerScroller.java @@ -48,7 +48,9 @@ public class VideoAwareRecyclerScroller extends RecyclerView.OnScrollListener { if (tag instanceof FeedModel && context instanceof Activity) { if (player != null) player.setPlayWhenReady(false); ((Activity) context).startActivityForResult(new Intent(context, CommentsViewer.class) - .putExtra(Constants.EXTRAS_SHORTCODE, ((FeedModel) tag).getShortCode()), 6969); + .putExtra(Constants.EXTRAS_SHORTCODE, ((FeedModel) tag).getShortCode()) + .putExtra(Constants.EXTRAS_POST, ((FeedModel) tag).getPostId()) + .putExtra(Constants.EXTRAS_POST, ((FeedModel) tag).getProfileModel().getId()), 6969); } } }; @@ -56,7 +58,7 @@ public class VideoAwareRecyclerScroller extends RecyclerView.OnScrollListener { if (player == null) return; final float intVol = player.getVolume() == 0f ? 1f : 0f; player.setVolume(intVol); - if (btnMute != null) btnMute.setImageResource(intVol == 0f ? R.drawable.vol : R.drawable.mute); + if (btnMute != null) btnMute.setImageResource(intVol == 0f ? R.drawable.mute : R.drawable.vol); Utils.sessionVolumeFull = intVol == 1f; }; private final VideoChangeCallback videoChangeCallback; diff --git a/app/src/main/java/awais/instagrabber/dialogs/QuickAccessDialog.java b/app/src/main/java/awais/instagrabber/dialogs/QuickAccessDialog.java index ddae5a62..9349058f 100755 --- a/app/src/main/java/awais/instagrabber/dialogs/QuickAccessDialog.java +++ b/app/src/main/java/awais/instagrabber/dialogs/QuickAccessDialog.java @@ -36,6 +36,7 @@ public final class QuickAccessDialog extends BottomSheetDialogFragment implement private String userQuery; private View btnFavorite, btnImportExport; private SimpleAdapter favoritesAdapter; + private RecyclerView rvFavorites, rvQuickAccess; public QuickAccessDialog setQuery(final String userQuery) { this.userQuery = userQuery; @@ -66,8 +67,8 @@ public final class QuickAccessDialog extends BottomSheetDialogFragment implement btnFavorite.setOnClickListener(this); btnImportExport.setOnClickListener(this); - final RecyclerView rvFavorites = contentView.findViewById(R.id.rvFavorites); - final RecyclerView rvQuickAccess = contentView.findViewById(R.id.rvQuickAccess); + rvFavorites = contentView.findViewById(R.id.rvFavorites); + rvQuickAccess = contentView.findViewById(R.id.rvQuickAccess); final DividerItemDecoration itemDecoration = new DividerItemDecoration(activity, DividerItemDecoration.VERTICAL); rvFavorites.addItemDecoration(itemDecoration); @@ -133,9 +134,12 @@ public final class QuickAccessDialog extends BottomSheetDialogFragment implement if (tag instanceof DataBox.FavoriteModel) { final DataBox.FavoriteModel favoriteModel = (DataBox.FavoriteModel) tag; - new AlertDialog.Builder(activity).setPositiveButton(R.string.yes, (d, which) -> Utils.dataBox.delFavorite(favoriteModel)) - .setNegativeButton(R.string.no, null).setMessage(getString(R.string.quick_access_confirm_delete, - favoriteModel.getQuery())).show(); + new AlertDialog.Builder(activity).setPositiveButton(R.string.yes, (d, which) -> { + Utils.dataBox.delFavorite(favoriteModel); + rvFavorites.findViewWithTag(favoriteModel).setVisibility(View.GONE); + }) + .setNegativeButton(R.string.no, null).setMessage(getString(R.string.quick_access_confirm_delete, + favoriteModel.getQuery())).show(); } else if (tag instanceof DataBox.CookieModel) { final DataBox.CookieModel cookieModel = (DataBox.CookieModel) tag; diff --git a/app/src/main/java/awais/instagrabber/directdownload/MultiDirectDialog.java b/app/src/main/java/awais/instagrabber/directdownload/MultiDirectDialog.java index d0f0e379..1ae19957 100755 --- a/app/src/main/java/awais/instagrabber/directdownload/MultiDirectDialog.java +++ b/app/src/main/java/awais/instagrabber/directdownload/MultiDirectDialog.java @@ -60,7 +60,7 @@ public final class MultiDirectDialog extends BaseLanguageActivity { for (final ViewerPostModel postModel : postModels) models.add(new PostModel(postModel.getItemType(), postModel.getPostId(), postModel.getDisplayUrl(), postModel.getSliderDisplayUrl(), postModel.getShortCode(), postModel.getPostCaption(), postModel.getTimestamp(), - postModel.getLike(), postModel.getBookmark())); + postModel.getLike(), postModel.getBookmark(), postModel.getLikes())); postsAdapter = new PostsAdapter(models, v -> { final Object tag = v.getTag(); diff --git a/app/src/main/java/awais/instagrabber/models/BasePostModel.java b/app/src/main/java/awais/instagrabber/models/BasePostModel.java index e6d4ed10..a891fb75 100755 --- a/app/src/main/java/awais/instagrabber/models/BasePostModel.java +++ b/app/src/main/java/awais/instagrabber/models/BasePostModel.java @@ -19,10 +19,14 @@ public abstract class BasePostModel implements Serializable { protected long timestamp; protected int position; boolean liked, bookmarked; + long likes; public boolean getLike() { return liked; } + public long getLikes() { + return likes; + } public boolean getBookmark() { return bookmarked; } @@ -30,6 +34,14 @@ public abstract class BasePostModel implements Serializable { public boolean setLike(final boolean like) { liked = like; return liked; } + + // setManualLike means user liked from InstaGrabber + public boolean setManualLike(final boolean like) { + liked = like; + likes = (like) ? (likes + 1) : (likes - 1); + return liked; + } + public boolean setBookmark(final boolean bookmark) { bookmarked = bookmark; return bookmarked; } diff --git a/app/src/main/java/awais/instagrabber/models/CommentModel.java b/app/src/main/java/awais/instagrabber/models/CommentModel.java index 130139aa..88d93461 100755 --- a/app/src/main/java/awais/instagrabber/models/CommentModel.java +++ b/app/src/main/java/awais/instagrabber/models/CommentModel.java @@ -12,13 +12,15 @@ public final class CommentModel { private final CharSequence text; private final long likes, timestamp; private CommentModel[] childCommentModels; - private boolean hasNextPage; + private boolean hasNextPage, liked; private String endCursor; - public CommentModel(final String id, final String text, final long timestamp, final long likes, final ProfileModel profileModel) { + public CommentModel(final String id, final String text, final long timestamp, final long likes, final boolean liked, + final ProfileModel profileModel) { this.id = id; this.text = Utils.hasMentions(text) ? Utils.getMentionText(text) : text; this.likes = likes; + this.liked = liked; this.timestamp = timestamp; this.profileModel = profileModel; } @@ -40,6 +42,10 @@ public final class CommentModel { return likes; } + public boolean getLiked() { + return liked; + } + public ProfileModel getProfileModel() { return profileModel; } diff --git a/app/src/main/java/awais/instagrabber/models/FeedModel.java b/app/src/main/java/awais/instagrabber/models/FeedModel.java index 3a2442a7..99e22469 100755 --- a/app/src/main/java/awais/instagrabber/models/FeedModel.java +++ b/app/src/main/java/awais/instagrabber/models/FeedModel.java @@ -10,8 +10,8 @@ public final class FeedModel extends PostModel { public FeedModel(final ProfileModel profileModel, final MediaItemType itemType, final long viewCount, final String postId, final String displayUrl, final String thumbnailUrl, final String shortCode, final String postCaption, - final long commentsCount, final long timestamp, boolean liked, boolean bookmarked) { - super(itemType, postId, displayUrl, thumbnailUrl, shortCode, postCaption, timestamp, liked, bookmarked); + final long commentsCount, final long timestamp, boolean liked, boolean bookmarked, long likes) { + super(itemType, postId, displayUrl, thumbnailUrl, shortCode, postCaption, timestamp, liked, bookmarked, likes); this.profileModel = profileModel; this.commentsCount = commentsCount; this.viewCount = viewCount; diff --git a/app/src/main/java/awais/instagrabber/models/PostModel.java b/app/src/main/java/awais/instagrabber/models/PostModel.java index ac91f953..56ce63e7 100755 --- a/app/src/main/java/awais/instagrabber/models/PostModel.java +++ b/app/src/main/java/awais/instagrabber/models/PostModel.java @@ -13,7 +13,8 @@ public class PostModel extends BasePostModel { } public PostModel(final MediaItemType itemType, final String postId, final String displayUrl, final String thumbnailUrl, - final String shortCode, final CharSequence postCaption, long timestamp, boolean liked, boolean bookmarked) { + final String shortCode, final CharSequence postCaption, long timestamp, boolean liked, boolean bookmarked, + long likes) { this.itemType = itemType; this.postId = postId; this.displayUrl = displayUrl; @@ -22,6 +23,7 @@ public class PostModel extends BasePostModel { this.postCaption = postCaption; this.timestamp = timestamp; this.liked = liked; + this.likes = likes; this.bookmarked = bookmarked; } @@ -33,6 +35,10 @@ public class PostModel extends BasePostModel { return endCursor; } + public long getLikes() { + return likes; + } + public boolean hasNextPage() { return endCursor != null && hasNextPage; } diff --git a/app/src/main/java/awais/instagrabber/utils/FlavorTown.java b/app/src/main/java/awais/instagrabber/utils/FlavorTown.java index a37748e6..f5a61259 100755 --- a/app/src/main/java/awais/instagrabber/utils/FlavorTown.java +++ b/app/src/main/java/awais/instagrabber/utils/FlavorTown.java @@ -30,7 +30,7 @@ public final class FlavorTown { Resources res = context.getResources(); new UpdateChecker(version -> { new AlertDialog.Builder(context) - .setTitle(res.getString(R.string.update_available) + " (" + version + ")") + .setTitle(res.getString(R.string.update_available, version)) .setMessage(R.string.update_notice) .setNeutralButton(R.string.cancel, null) .setNegativeButton(R.string.action_github, (dialog, which) -> { diff --git a/app/src/main/res/layout/activity_comments.xml b/app/src/main/res/layout/activity_comments.xml index 7bad2d17..bca67c7b 100755 --- a/app/src/main/res/layout/activity_comments.xml +++ b/app/src/main/res/layout/activity_comments.xml @@ -5,21 +5,67 @@ android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" - tools:context=".activities.CommentsViewer"> + tools:context=".activities.CommentsViewer" + android:weightSum="8"> - + android:layout_height="match_parent"> + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/activity_viewer.xml b/app/src/main/res/layout/activity_viewer.xml index 982db62d..e280ef67 100755 --- a/app/src/main/res/layout/activity_viewer.xml +++ b/app/src/main/res/layout/activity_viewer.xml @@ -116,7 +116,7 @@ android:layout_weight="1" android:text="@string/like" android:textColor="@color/btn_lightpink_text_color" - android:textSize="20sp" + android:textSize="18sp" app:backgroundTint="@color/btn_lightpink_background" /> \ No newline at end of file diff --git a/app/src/main/res/layout/item_comment_small.xml b/app/src/main/res/layout/item_comment_small.xml index 997d39df..eff11707 100755 --- a/app/src/main/res/layout/item_comment_small.xml +++ b/app/src/main/res/layout/item_comment_small.xml @@ -35,13 +35,9 @@ android:layout_height="wrap_content" android:orientation="vertical"> - - - - - - + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/layout_include_simple_item.xml b/app/src/main/res/layout/layout_include_simple_item.xml index ae21c96f..27956961 100755 --- a/app/src/main/res/layout/layout_include_simple_item.xml +++ b/app/src/main/res/layout/layout_include_simple_item.xml @@ -51,13 +51,9 @@ android:layout_height="wrap_content" android:orientation="vertical"> - - - - - - - + android:weightSum="3"> + + + + \ No newline at end of file diff --git a/app/src/main/res/values-de/strings.xml b/app/src/main/res/values-de/strings.xml index a2751bf4..6e73c67a 100644 --- a/app/src/main/res/values-de/strings.xml +++ b/app/src/main/res/values-de/strings.xml @@ -157,7 +157,7 @@ %s not following Error loading cookies Successfully loaded cookies!\nIf you still can\'t open private pages/posts, re-login! - An update is available! + An update is available! (%s) Reminder: If you downloaded from F-Droid, you must update from it! Same applies for GitHub. Thank you for updating InstaGrabber! App crashed diff --git a/app/src/main/res/values-es/strings.xml b/app/src/main/res/values-es/strings.xml index 0f6153e5..2c6b2991 100755 --- a/app/src/main/res/values-es/strings.xml +++ b/app/src/main/res/values-es/strings.xml @@ -157,7 +157,7 @@ %s no está siguiendo Error al cargar cookies ¡Cookies cargadas con éxito!\nSi aún no puedes abrir páginas/publicaciones privadas, ¡vuelve a ingresar! - An update is available! + An update is available! (%s) Reminder: If you downloaded from F-Droid, you must update from it! Same applies for GitHub. Thank you for updating InstaGrabber! App atascada diff --git a/app/src/main/res/values-fr/strings.xml b/app/src/main/res/values-fr/strings.xml index 8f47e98e..aab437d2 100755 --- a/app/src/main/res/values-fr/strings.xml +++ b/app/src/main/res/values-fr/strings.xml @@ -157,7 +157,7 @@ Comptes non suivis par %s Erreur de chargement des cookies Cookies chargés avec succès!\nSi vous ne pouvez toujours pas ouvrir de pages/postes privés, reconnectez-vous ! - An update is available! + An update is available! (%s) Reminder: If you downloaded from F-Droid, you must update from it! Same applies for GitHub. Thank you for updating InstaGrabber! L\'application a planté diff --git a/app/src/main/res/values-in/strings.xml b/app/src/main/res/values-in/strings.xml index ae38f54a..74ea4686 100644 --- a/app/src/main/res/values-in/strings.xml +++ b/app/src/main/res/values-in/strings.xml @@ -157,7 +157,7 @@ %s tidak mengikuti Galat memuat cookies Berhasil memuat cookies!\nJika anda tetap tidak dapat membuka laman/kiriman pribadi, coba masuk lagi! - An update is available! + An update is available! (%s) Reminder: If you downloaded from F-Droid, you must update from it! Same applies for GitHub. Thank you for updating InstaGrabber! Aplikasi berhenti bekerja… diff --git a/app/src/main/res/values-it/strings.xml b/app/src/main/res/values-it/strings.xml index 3c1facb8..97d9c14d 100755 --- a/app/src/main/res/values-it/strings.xml +++ b/app/src/main/res/values-it/strings.xml @@ -157,7 +157,7 @@ %s non segue Errore durante il caricamento dei cookie Cookie caricati correttamente! \nSe non riesci ancora ad aprire pagine / post privati, accedi nuovamente! - Un aggiornamento è disponibile! + Un aggiornamento è disponibile! (%s) Reminder: If you downloaded from F-Droid, you must update from it! Same applies for GitHub. Grazie per aver aggiornato InstaGrabber! L\'app si è arrestata in modo anomalo diff --git a/app/src/main/res/values-pl/strings.xml b/app/src/main/res/values-pl/strings.xml index d4cf0c2a..bb35c024 100644 --- a/app/src/main/res/values-pl/strings.xml +++ b/app/src/main/res/values-pl/strings.xml @@ -157,7 +157,7 @@ %s not following Error loading cookies Successfully loaded cookies!\nIf you still can\'t open private pages/posts, re-login! - An update is available! + An update is available! (%s) Reminder: If you downloaded from F-Droid, you must update from it! Same applies for GitHub. Thank you for updating InstaGrabber! App crashed diff --git a/app/src/main/res/values-zh/strings.xml b/app/src/main/res/values-zh/strings.xml index 660f3300..74aec9a3 100755 --- a/app/src/main/res/values-zh/strings.xml +++ b/app/src/main/res/values-zh/strings.xml @@ -157,7 +157,7 @@ %s 未关注 载入 cookies 时出错 成功载入 cookies!\n若你仍不能查看私密页面/帖子,重新登录! - 检测到有新版本! + 检测到有新版本! (%s) Reminder: If you downloaded from F-Droid, you must update from it! Same applies for GitHub. 感谢阁下更新InstaGrabber! 应用崩溃了 diff --git a/app/src/main/res/values/arrays.xml b/app/src/main/res/values/arrays.xml index afee762f..65a09bb6 100755 --- a/app/src/main/res/values/arrays.xml +++ b/app/src/main/res/values/arrays.xml @@ -8,6 +8,8 @@ Chinese Simplified Indonesian [Thanks to @Galang23 (GitLab)] Italian [Thanks to @RAR_Ramar (Telegram)] + German [Thanks to @MoaufmKlo (GitHub)] + Polish [Thanks to @Lego8486 (GitHub)] diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 6df8e214..6220755c 100755 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -82,8 +82,8 @@ Join Telegram Group Join Matrix Room - Like - Unlike + Like (%s) + Unlike (%s) Bookmark Unbookmark @@ -173,6 +173,11 @@ Copy username Copy comment + Reply to comment + Like comment + Unlike comment + Delete comment + No empty comments, dawg! Do you want to search the username? Do you want to search the hashtag? @@ -186,7 +191,9 @@ Error loading cookies Successfully loaded cookies!\nIf you still can\'t open private pages/posts, re-login! - An update is available! + Write a new comment... + + An update is available! (%s) Reminder: If you downloaded from F-Droid, you must update from it! Same applies for GitHub. Thank you for updating InstaGrabber! App crashed