From ecc1958a239bcb9cbff121b551003aa868b6d22f Mon Sep 17 00:00:00 2001 From: Austin Huang Date: Tue, 4 Aug 2020 22:18:38 -0400 Subject: [PATCH] liked viewer --- app/build.gradle | 7 +- .../java/awais/instagrabber/MainHelper.java | 19 ++- .../activities/NotificationsViewer.java | 52 ++++++-- .../instagrabber/activities/SavedViewer.java | 20 ++- .../instagrabber/activities/StoryViewer.java | 30 +++-- .../adapters/NotificationsAdapter.java | 9 +- .../asyncs/NotificationsFetcher.java | 36 +++-- .../instagrabber/asyncs/PostsFetcher.java | 2 +- .../instagrabber/asyncs/i/iLikedFetcher.java | 123 ++++++++++++++++++ .../instagrabber/asyncs/i/iPostFetcher.java | 4 +- .../asyncs/i/iStoryStatusFetcher.java | 8 +- .../models/enums/NotificationType.java | 3 +- .../java/awais/instagrabber/utils/Utils.java | 37 ++++-- app/src/main/res/layout/activity_main.xml | 23 +++- app/src/main/res/values/strings.xml | 4 + 15 files changed, 312 insertions(+), 65 deletions(-) create mode 100755 app/src/main/java/awais/instagrabber/asyncs/i/iLikedFetcher.java diff --git a/app/build.gradle b/app/build.gradle index 2e99b482..4dfdaeae 100755 --- a/app/build.gradle +++ b/app/build.gradle @@ -9,11 +9,8 @@ android { minSdkVersion 16 targetSdkVersion 29 - // REMEMBER TO CHANGE versionCode AS WELL - // 16.7 is 32, 16.9 is 35 (34 is public beta) - - versionCode 38 - versionName '17.2' + versionCode 39 + versionName '17.3' multiDexEnabled true diff --git a/app/src/main/java/awais/instagrabber/MainHelper.java b/app/src/main/java/awais/instagrabber/MainHelper.java index 776686d4..20de5793 100755 --- a/app/src/main/java/awais/instagrabber/MainHelper.java +++ b/app/src/main/java/awais/instagrabber/MainHelper.java @@ -142,9 +142,10 @@ public final class MainHelper implements SwipeRefreshLayout.OnRefreshListener { } hasNextPage = model.hasNextPage(); - if ((autoloadPosts && hasNextPage) && !isHashtag) + if (autoloadPosts && hasNextPage) currentlyExecuting = new PostsFetcher(main.profileModel.getId(), endCursor, this) - .setUsername(main.profileModel.getUsername()).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); + .setUsername((isLocation || isHashtag) ? null : main.profileModel.getUsername()) + .executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); else { main.mainBinding.swipeRefreshLayout.setRefreshing(false); } @@ -468,7 +469,7 @@ public final class MainHelper implements SwipeRefreshLayout.OnRefreshListener { main.mainBinding.swipeRefreshLayout.setRefreshing(true); stopCurrentExecutor(); currentlyExecuting = new PostsFetcher((isHashtag || isLocation) ? main.userQuery : main.profileModel.getId(), endCursor, postsFetchListener) - .setUsername(isHashtag ? null : main.profileModel.getUsername()) + .setUsername((isHashtag || isLocation) ? null : main.profileModel.getUsername()) .executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); endCursor = null; } @@ -658,6 +659,7 @@ public final class MainHelper implements SwipeRefreshLayout.OnRefreshListener { main.mainBinding.btnRestrict.setVisibility(View.GONE); main.mainBinding.btnBlock.setVisibility(View.GONE); main.mainBinding.btnSaved.setVisibility(View.GONE); + main.mainBinding.btnLiked.setVisibility(View.GONE); main.mainBinding.btnTagged.setVisibility(View.GONE); main.mainBinding.btnMap.setVisibility(View.GONE); @@ -665,6 +667,7 @@ public final class MainHelper implements SwipeRefreshLayout.OnRefreshListener { main.mainBinding.btnRestrict.setOnClickListener(profileActionListener); main.mainBinding.btnBlock.setOnClickListener(profileActionListener); main.mainBinding.btnSaved.setOnClickListener(profileActionListener); + main.mainBinding.btnLiked.setOnClickListener(profileActionListener); main.mainBinding.btnTagged.setOnClickListener(profileActionListener); main.mainBinding.btnFollowTag.setOnClickListener(profileActionListener); @@ -794,6 +797,7 @@ public final class MainHelper implements SwipeRefreshLayout.OnRefreshListener { if (!profileId.equals(myId)) { main.mainBinding.btnTagged.setVisibility(View.GONE); main.mainBinding.btnSaved.setVisibility(View.GONE); + main.mainBinding.btnLiked.setVisibility(View.GONE); main.mainBinding.btnFollow.setVisibility(View.VISIBLE); if (profileModel.getFollowing() == true) { main.mainBinding.btnFollow.setText(R.string.unfollow); @@ -823,7 +827,6 @@ public final class MainHelper implements SwipeRefreshLayout.OnRefreshListener { } if (profileModel.isReallyPrivate()) { main.mainBinding.btnBlock.setVisibility(View.VISIBLE); - main.mainBinding.btnSaved.setVisibility(View.GONE); main.mainBinding.btnTagged.setVisibility(View.GONE); if (profileModel.getBlocked() == true) { main.mainBinding.btnBlock.setText(R.string.unblock); @@ -852,6 +855,7 @@ public final class MainHelper implements SwipeRefreshLayout.OnRefreshListener { else { main.mainBinding.btnTagged.setVisibility(View.VISIBLE); main.mainBinding.btnSaved.setVisibility(View.VISIBLE); + main.mainBinding.btnLiked.setVisibility(View.VISIBLE); main.mainBinding.btnSaved.setText(R.string.saved); main.mainBinding.btnSaved.setBackgroundTintList(ColorStateList.valueOf(resources.getColor( R.color.btn_orange_background, null))); @@ -1063,7 +1067,7 @@ public final class MainHelper implements SwipeRefreshLayout.OnRefreshListener { else { main.mainBinding.swipeRefreshLayout.setRefreshing(true); main.mainBinding.mainPosts.setVisibility(View.VISIBLE); - currentlyExecuting = new PostsFetcher(profileId, postsFetchListener).setUsername(locationModel.getName()) + currentlyExecuting = new PostsFetcher(profileId, postsFetchListener) .executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); } } @@ -1231,6 +1235,11 @@ public final class MainHelper implements SwipeRefreshLayout.OnRefreshListener { .putExtra(Constants.EXTRAS_INDEX, "$"+main.profileModel.getId()) .putExtra(Constants.EXTRAS_USER, "@"+main.profileModel.getUsername()) ); + } else if (v == main.mainBinding.btnLiked) { + main.startActivity(new Intent(main, SavedViewer.class) + .putExtra(Constants.EXTRAS_INDEX, "^"+main.profileModel.getId()) + .putExtra(Constants.EXTRAS_USER, "@"+main.profileModel.getUsername()) + ); } } }; diff --git a/app/src/main/java/awais/instagrabber/activities/NotificationsViewer.java b/app/src/main/java/awais/instagrabber/activities/NotificationsViewer.java index 744dc8c2..b731f366 100755 --- a/app/src/main/java/awais/instagrabber/activities/NotificationsViewer.java +++ b/app/src/main/java/awais/instagrabber/activities/NotificationsViewer.java @@ -12,19 +12,15 @@ import android.util.Log; 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; import androidx.annotation.Nullable; import androidx.appcompat.app.AlertDialog; -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.NotificationsAdapter; @@ -32,6 +28,7 @@ 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; @@ -46,7 +43,7 @@ public final class NotificationsViewer extends BaseLanguageActivity implements S private String shortCode, postId, userId; private final String cookie = Utils.settingsHelper.getString(Constants.COOKIE); private Resources resources; - private InputMethodManager imm; + String[] commentDialogList; @Override protected void onCreate(@Nullable final Bundle savedInstanceState) { @@ -90,9 +87,11 @@ public final class NotificationsViewer extends BaseLanguageActivity implements S final DialogInterface.OnClickListener profileDialogListener = (dialog, which) -> { if (which == 0) searchUsername(notificationModel.getUsername()); - else if (which == 1) + else if (which == 1 && commentDialogList.length == 2) startActivity(new Intent(getApplicationContext(), PostViewer.class) .putExtra(Constants.EXTRAS_POST, new PostModel(notificationModel.getShortcode(), false))); + else if (which == 1) new ProfileAction().execute("/approve/"); + else if (which == 2) new ProfileAction().execute("/ignore/"); }; private final View.OnClickListener clickListener = v -> { @@ -104,12 +103,16 @@ public final class NotificationsViewer extends BaseLanguageActivity implements S final SpannableString title = new SpannableString(username + ":\n" + notificationModel.getText()); title.setSpan(new RelativeSizeSpan(1.23f), 0, username.length(), Spanned.SPAN_INCLUSIVE_INCLUSIVE); - String[] commentDialogList; - if (notificationModel.getShortcode() != null) commentDialogList = new String[]{ resources.getString(R.string.open_profile), resources.getString(R.string.view_post) }; + else if (notificationModel.getType() == NotificationType.REQUEST) + commentDialogList = new String[]{ + resources.getString(R.string.open_profile), + resources.getString(R.string.request_approve), + resources.getString(R.string.request_reject) + }; else commentDialogList = new String[]{ resources.getString(R.string.open_profile) }; @@ -137,4 +140,37 @@ public final class NotificationsViewer extends BaseLanguageActivity implements S finish(); } } + + class ProfileAction extends AsyncTask { + boolean ok = false; + String action; + + protected Void doInBackground(String... rawAction) { + action = rawAction[0]; + final String url = "https://www.instagram.com/web/friendships/"+notificationModel.getId()+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", + Utils.settingsHelper.getString(Constants.COOKIE).split("csrftoken=")[1].split(";")[0]);urlConnection.connect(); + if (urlConnection.getResponseCode() == HttpURLConnection.HTTP_OK) { + ok = true; + } + 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) { + onRefresh(); + } + } + } } \ No newline at end of file diff --git a/app/src/main/java/awais/instagrabber/activities/SavedViewer.java b/app/src/main/java/awais/instagrabber/activities/SavedViewer.java index 191d5f06..60edabbf 100755 --- a/app/src/main/java/awais/instagrabber/activities/SavedViewer.java +++ b/app/src/main/java/awais/instagrabber/activities/SavedViewer.java @@ -22,6 +22,7 @@ import awais.instagrabber.BuildConfig; import awais.instagrabber.R; import awais.instagrabber.adapters.PostsAdapter; import awais.instagrabber.asyncs.PostsFetcher; +import awais.instagrabber.asyncs.i.iLikedFetcher; import awais.instagrabber.customviews.helpers.GridAutofitLayoutManager; import awais.instagrabber.customviews.helpers.GridSpacingItemDecoration; import awais.instagrabber.customviews.helpers.RecyclerLazyLoader; @@ -73,9 +74,12 @@ public final class SavedViewer extends BaseLanguageActivity implements SwipeRefr endCursor = model.getEndCursor(); hasNextPage = model.hasNextPage(); - if (autoloadPosts && hasNextPage) + if (autoloadPosts && hasNextPage && action.charAt(0) == '^') + currentlyExecuting = new iLikedFetcher(endCursor, postsFetchListener) + .executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); + else if (autoloadPosts && hasNextPage) currentlyExecuting = new PostsFetcher(action, endCursor, this) - .setUsername(username).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); + .executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); else { savedBinding.swipeRefreshLayout.setRefreshing(false); } @@ -141,8 +145,10 @@ public final class SavedViewer extends BaseLanguageActivity implements SwipeRefr if (!autoloadPosts && hasNextPage) { savedBinding.swipeRefreshLayout.setRefreshing(true); stopCurrentExecutor(); - currentlyExecuting = new PostsFetcher(action, endCursor, postsFetchListener) - .executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); + + currentlyExecuting = action.charAt(0) == '^' + ? new iLikedFetcher(endCursor, postsFetchListener).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR) + : new PostsFetcher(action, endCursor, postsFetchListener).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); endCursor = null; } }); @@ -153,7 +159,8 @@ public final class SavedViewer extends BaseLanguageActivity implements SwipeRefr return null; }; - new PostsFetcher(action, postsFetchListener).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); + if (action.charAt(0) == '^') new iLikedFetcher(postsFetchListener).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); + else new PostsFetcher(action, postsFetchListener).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); } @Override @@ -191,7 +198,8 @@ public final class SavedViewer extends BaseLanguageActivity implements SwipeRefr postsAdapter.notifyDataSetChanged(); } savedBinding.swipeRefreshLayout.setRefreshing(true); - new PostsFetcher(action, postsFetchListener).setUsername(username).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); + if (action.charAt(0) == '^') new iLikedFetcher(postsFetchListener).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); + else new PostsFetcher(action, postsFetchListener).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); } @Override diff --git a/app/src/main/java/awais/instagrabber/activities/StoryViewer.java b/app/src/main/java/awais/instagrabber/activities/StoryViewer.java index f9304001..1c1b419e 100755 --- a/app/src/main/java/awais/instagrabber/activities/StoryViewer.java +++ b/app/src/main/java/awais/instagrabber/activities/StoryViewer.java @@ -153,18 +153,24 @@ public final class StoryViewer extends BaseLanguageActivity { (index == 0 ? null : storyFeed[index - 1]) : (storyFeed.length == index + 1 ? null : storyFeed[index + 1]); if (feedStoryModel != null) { - new iStoryStatusFetcher(feedStoryModel.getStoryMediaId(), null, false, false, result -> { - if (result != null && result.length > 0) { - final Intent newIntent = new Intent(getApplicationContext(), StoryViewer.class) - .putExtra(Constants.EXTRAS_STORIES, result) - .putExtra(Constants.EXTRAS_USERNAME, feedStoryModel.getProfileModel().getUsername()) - .putExtra(Constants.FEED, storyFeed) - .putExtra(Constants.FEED_ORDER, isRightSwipe ? (index - 1) : (index + 1)); - newIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); - startActivity(newIntent); - } - else Toast.makeText(getApplicationContext(), R.string.downloader_unknown_error, Toast.LENGTH_SHORT).show(); - }).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); + boolean fetching = false; + if (fetching) { + Toast.makeText(getApplicationContext(), R.string.be_patient, Toast.LENGTH_SHORT).show(); + } else { + fetching = true; + new iStoryStatusFetcher(feedStoryModel.getStoryMediaId(), null, false, false, result -> { + if (result != null && result.length > 0) { + final Intent newIntent = new Intent(getApplicationContext(), StoryViewer.class) + .putExtra(Constants.EXTRAS_STORIES, result) + .putExtra(Constants.EXTRAS_USERNAME, feedStoryModel.getProfileModel().getUsername()) + .putExtra(Constants.FEED, storyFeed) + .putExtra(Constants.FEED_ORDER, isRightSwipe ? (index - 1) : (index + 1)); + newIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); + startActivity(newIntent); + } else + Toast.makeText(getApplicationContext(), R.string.downloader_unknown_error, Toast.LENGTH_SHORT).show(); + }).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); + } } } } diff --git a/app/src/main/java/awais/instagrabber/adapters/NotificationsAdapter.java b/app/src/main/java/awais/instagrabber/adapters/NotificationsAdapter.java index 3afa2ad0..dc18c05d 100755 --- a/app/src/main/java/awais/instagrabber/adapters/NotificationsAdapter.java +++ b/app/src/main/java/awais/instagrabber/adapters/NotificationsAdapter.java @@ -1,6 +1,7 @@ package awais.instagrabber.adapters; import android.content.Context; +import android.util.Log; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; @@ -18,6 +19,7 @@ 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; @@ -67,11 +69,16 @@ public final class NotificationsAdapter extends RecyclerView.Adapter 0 && + int totalLength = 0, mediaLen = 0, reqLen = 0; + NotificationModel[] models = null, req = null; + + if ((media = ewaf.optJSONArray("edges")) != null && media.length() > 0 && (data = media.optJSONObject(0).optJSONObject("node")) != null) { - - final int mediaLen = media.length(); - - final NotificationModel[] models = new NotificationModel[mediaLen]; + mediaLen = media.length(); + models = new NotificationModel[mediaLen]; for (int i = 0; i < mediaLen; ++i) { data = media.optJSONObject(i).optJSONObject("node"); if (Utils.getNotifType(data.getString("__typename")) == null) continue; @@ -61,8 +64,23 @@ public final class NotificationsFetcher extends AsyncTask 0 && + (data = media.optJSONObject(0).optJSONObject("node")) != null) { + reqLen = media.length(); + req = new NotificationModel[reqLen]; + for (int i = 0; i < reqLen; ++i) { + data = media.optJSONObject(i).optJSONObject("node"); + req[i] = new NotificationModel(data.getString(Constants.EXTRAS_ID), + data.optString("full_name"), 0L, data.getString("username"), + data.getString("profile_pic_url"), null, null, NotificationType.REQUEST); + } + } + + result = new NotificationModel[mediaLen + reqLen]; + if (req != null) System.arraycopy(req, 0, result, 0, reqLen); + if (models != null) System.arraycopy(models, 0, result, reqLen, mediaLen); } conn.disconnect(); diff --git a/app/src/main/java/awais/instagrabber/asyncs/PostsFetcher.java b/app/src/main/java/awais/instagrabber/asyncs/PostsFetcher.java index 72f4d059..0add3388 100755 --- a/app/src/main/java/awais/instagrabber/asyncs/PostsFetcher.java +++ b/app/src/main/java/awais/instagrabber/asyncs/PostsFetcher.java @@ -28,7 +28,7 @@ public final class PostsFetcher extends AsyncTask { private final String endCursor; private final String id; private final FetchListener fetchListener; - private String username; + private String username = null; public PostsFetcher(final String id, final FetchListener fetchListener) { this.id = id; diff --git a/app/src/main/java/awais/instagrabber/asyncs/i/iLikedFetcher.java b/app/src/main/java/awais/instagrabber/asyncs/i/iLikedFetcher.java new file mode 100755 index 00000000..85a5247b --- /dev/null +++ b/app/src/main/java/awais/instagrabber/asyncs/i/iLikedFetcher.java @@ -0,0 +1,123 @@ +package awais.instagrabber.asyncs.i; + +import android.os.AsyncTask; +import android.os.Environment; +import android.util.Log; + +import org.json.JSONArray; +import org.json.JSONObject; + +import java.io.File; +import java.net.HttpURLConnection; +import java.net.URL; + +import awais.instagrabber.BuildConfig; +import awais.instagrabber.interfaces.FetchListener; +import awais.instagrabber.models.PostModel; +import awais.instagrabber.models.enums.MediaItemType; +import awais.instagrabber.utils.Constants; +import awais.instagrabber.utils.Utils; +import awaisomereport.LogCollector; + +import static awais.instagrabber.utils.Constants.DOWNLOAD_USER_FOLDER; +import static awais.instagrabber.utils.Constants.FOLDER_PATH; +import static awais.instagrabber.utils.Constants.FOLDER_SAVE_TO; +import static awais.instagrabber.utils.Utils.logCollector; + +public final class iLikedFetcher extends AsyncTask { + private final String endCursor; + private final FetchListener fetchListener; + + public iLikedFetcher(final FetchListener fetchListener) { + this.endCursor = ""; + this.fetchListener = fetchListener; + } + + public iLikedFetcher(final String endCursor, final FetchListener fetchListener) { + this.endCursor = endCursor == null ? "" : endCursor; + this.fetchListener = fetchListener; + } + + @Override + protected PostModel[] doInBackground(final Void... voids) { + final String url = "https://i.instagram.com/api/v1/feed/liked/?max_id="+endCursor; + + PostModel[] result = null; + try { + final HttpURLConnection conn = (HttpURLConnection) new URL(url).openConnection(); + conn.setUseCaches(false); + conn.setRequestProperty("User-Agent", Constants.I_USER_AGENT); + conn.connect(); + + if (conn.getResponseCode() == HttpURLConnection.HTTP_OK) { + final JSONObject body = new JSONObject(Utils.readFromConnection(conn)); + + final String endCursor; + final boolean hasNextPage; + + if (body.has("more_available")) { + hasNextPage = body.optBoolean("more_available"); + endCursor = hasNextPage ? body.optString("next_max_id") : null; + } else { + hasNextPage = false; + endCursor = null; + } + + final JSONArray edges = body.getJSONArray("items"); + final PostModel[] models = new PostModel[edges.length()]; + for (int i = 0; i < models.length; ++i) { + final JSONObject mediaNode = edges.getJSONObject(i); + + final boolean isSlider = mediaNode.has("carousel_media_count"); + final boolean isVideo = mediaNode.has("video_duration"); + + final MediaItemType itemType; + if (isSlider) itemType = MediaItemType.MEDIA_TYPE_SLIDER; + else if (isVideo) itemType = MediaItemType.MEDIA_TYPE_VIDEO; + else itemType = MediaItemType.MEDIA_TYPE_IMAGE; + + models[i] = new PostModel(itemType, mediaNode.getString(Constants.EXTRAS_ID), + isSlider + ? Utils.getHighQualityImage(mediaNode.getJSONArray("carousel_media").getJSONObject(0)) + : Utils.getHighQualityImage(mediaNode), + isSlider + ? Utils.getLowQualityImage(mediaNode.getJSONArray("carousel_media").getJSONObject(0)) + : Utils.getLowQualityImage(mediaNode), + mediaNode.getString("code"), + mediaNode.isNull("caption") ? null : mediaNode.getJSONObject("caption").optString("text"), + mediaNode.getLong("taken_at"), true, + mediaNode.optBoolean("has_viewer_saved"), mediaNode.getLong("like_count")); + + String username = mediaNode.getJSONObject("user").getString("username"); + final File downloadDir = new File(Environment.getExternalStorageDirectory(), "Download" + + (Utils.settingsHelper.getBoolean(DOWNLOAD_USER_FOLDER) ? ("/"+username) : "")); + File customDir = null; + if (Utils.settingsHelper.getBoolean(FOLDER_SAVE_TO)) { + final String customPath = Utils.settingsHelper.getString(FOLDER_PATH + + (Utils.settingsHelper.getBoolean(DOWNLOAD_USER_FOLDER) ? ("/"+username) : "")); + if (!Utils.isEmpty(customPath)) customDir = new File(customPath); + } + Utils.checkExistence(downloadDir, customDir, isSlider, models[i]); + } + + if (models[models.length - 1] != null) + models[models.length - 1].setPageCursor(hasNextPage, endCursor); + + result = models; + } + + conn.disconnect(); + } catch (Exception e) { + if (logCollector != null) + logCollector.appendException(e, LogCollector.LogFile.ASYNC_MAIN_POSTS_FETCHER, "doInBackground"); + if (BuildConfig.DEBUG) Log.e("AWAISKING_APP", "", e); + } + + return result; + } + + @Override + protected void onPostExecute(final PostModel[] postModels) { + if (fetchListener != null) fetchListener.onResult(postModels); + } +} diff --git a/app/src/main/java/awais/instagrabber/asyncs/i/iPostFetcher.java b/app/src/main/java/awais/instagrabber/asyncs/i/iPostFetcher.java index 45f59524..3e6330d7 100755 --- a/app/src/main/java/awais/instagrabber/asyncs/i/iPostFetcher.java +++ b/app/src/main/java/awais/instagrabber/asyncs/i/iPostFetcher.java @@ -79,7 +79,7 @@ public final class iPostFetcher extends AsyncTask final ViewerPostModel postModel = new ViewerPostModel(mediaItemType, media.getString(Constants.EXTRAS_ID), isVideo - ? Utils.getHighQualityPost(media.optJSONArray("video_versions"), true, true) + ? Utils.getHighQualityPost(media.optJSONArray("video_versions"), true, true, false) : Utils.getHighQualityImage(media), media.getString("code"), Utils.isEmpty(postCaption) ? null : postCaption, @@ -106,7 +106,7 @@ public final class iPostFetcher extends AsyncTask postModels[i] = new ViewerPostModel(isChildVideo ? MediaItemType.MEDIA_TYPE_VIDEO : MediaItemType.MEDIA_TYPE_IMAGE, media.getString(Constants.EXTRAS_ID), isChildVideo - ? Utils.getHighQualityPost(node.optJSONArray("video_versions"), true, true) + ? Utils.getHighQualityPost(node.optJSONArray("video_versions"), true, true, false) : Utils.getHighQualityImage(node), media.getString("code"), postCaption, 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 5b7c9ccf..61c872c5 100755 --- a/app/src/main/java/awais/instagrabber/asyncs/i/iStoryStatusFetcher.java +++ b/app/src/main/java/awais/instagrabber/asyncs/i/iStoryStatusFetcher.java @@ -50,9 +50,9 @@ public final class iStoryStatusFetcher extends AsyncTask 0 && @@ -73,7 +73,7 @@ public final class iStoryStatusFetcher extends AsyncTask lastResMain) { + if (currRes > lastResMain && !low) { + lastResMain = currRes; + lastIndexMain = i; + } + else if (currRes < lastResMain && low) { lastResMain = currRes; lastIndexMain = i; } } else { - if (currRes > lastResBase) { + if (currRes > lastResBase && !low) { + lastResBase = currRes; + lastIndexBase = i; + } + else if (currRes < lastResBase && low) { lastResBase = currRes; lastIndexBase = i; } @@ -306,9 +314,9 @@ public final class Utils { public static String getHighQualityImage(final JSONObject resources) { String src = null; try { - if (resources.has("display_resources")) src = getHighQualityPost(resources.getJSONArray("display_resources"), false, false); + if (resources.has("display_resources")) src = getHighQualityPost(resources.getJSONArray("display_resources"), false, false, false); else if (resources.has("image_versions2")) - src = getHighQualityPost(resources.getJSONObject("image_versions2").getJSONArray("candidates"), false, true); + src = getHighQualityPost(resources.getJSONObject("image_versions2").getJSONArray("candidates"), false, true, false); if (src == null) return resources.getString("display_url"); } catch (final Exception e) { if (logCollector != null) @@ -319,6 +327,19 @@ public final class Utils { return src; } + public static String getLowQualityImage(final JSONObject resources) { + String src = null; + try { + src = getHighQualityPost(resources.getJSONObject("image_versions2").getJSONArray("candidates"), false, true, true); + } catch (final Exception e) { + if (logCollector != null) + logCollector.appendException(e, LogCollector.LogFile.UTILS, "getLowQualityImage", + new Pair<>("resourcesNull", resources == null)); + if (BuildConfig.DEBUG) Log.e("AWAISKING_APP", "", e); + } + return src; + } + public static String getItemThumbnail(@NonNull final JSONArray jsonArray) { String thumbnail = null; final int imageResLen = jsonArray.length(); @@ -1195,7 +1216,7 @@ public final class Utils { data.getLong("taken_at_timestamp"), data.getJSONObject("owner").getString("username")); if (isVideo && data.has("video_resources")) - storyModels[j].setVideoUrl(Utils.getHighQualityPost(data.getJSONArray("video_resources"), true, false)); + storyModels[j].setVideoUrl(Utils.getHighQualityPost(data.getJSONArray("video_resources"), true, false, false)); if (!data.isNull("story_app_attribution")) storyModels[j].setSpotify(data.getJSONObject("story_app_attribution").optString("content_url").split("\\?")[0]); diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml index aeabab5b..a10b43c6 100755 --- a/app/src/main/res/layout/activity_main.xml +++ b/app/src/main/res/layout/activity_main.xml @@ -118,7 +118,8 @@ android:layout_width="match_parent" android:layout_height="match_parent" android:layout_marginLeft="8dp" - android:layout_marginStart="2dp" + android:layout_marginEnd="1dp" + android:layout_marginStart="1dp" android:layout_marginRight="8dp" android:layout_weight="1" android:text="@string/follow" @@ -148,7 +149,8 @@ android:layout_width="match_parent" android:layout_height="match_parent" android:layout_marginLeft="8dp" - android:layout_marginEnd="2dp" + android:layout_marginEnd="1dp" + android:layout_marginStart="1dp" android:layout_marginRight="8dp" android:layout_weight="1" android:text="@string/block" @@ -169,7 +171,8 @@ android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginLeft="8dp" - android:layout_marginStart="2dp" + android:layout_marginEnd="1dp" + android:layout_marginStart="1dp" android:layout_marginRight="8dp" android:layout_weight="1" android:text="@string/tagged" @@ -193,6 +196,20 @@ android:textSize="16sp" app:backgroundTint="@color/btn_orange_background" android:visibility="gone" /> + diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index f260760b..1ceaf822 100755 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -61,6 +61,7 @@ Whole Album Show stories No more stories! + Be patient! View Post View Post Spotify @@ -193,6 +194,9 @@ Commented on your post: Started following you Mentioned you: + Requested following you + Approve request + Reject request Share this public post to... This is a private post! Share to those who can view them!