From 548582a6d2780a1918a603cb22e8d729d4caca14 Mon Sep 17 00:00:00 2001 From: Ammar Githam Date: Wed, 14 Apr 2021 01:02:42 +0900 Subject: [PATCH 1/9] Fix options menu item background in dark black theme. Fixes https://github.com/austinhuang0131/barinsta/issues/1076 --- app/src/main/res/values/themes.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/main/res/values/themes.xml b/app/src/main/res/values/themes.xml index a0e7a3b8..28de10d8 100644 --- a/app/src/main/res/values/themes.xml +++ b/app/src/main/res/values/themes.xml @@ -126,7 +126,7 @@ @style/Widget.Dialog.Dark.Black @style/Widget.AlertDialog.Dark.Black @style/Widget.AppCompat.CompoundButton.Switch.Dark.Black - @style/Widget.AppCompat.ListView.DropDown.Dark.Black + @style/PreferenceFragmentCompatStyle.Dark.Black @style/Widget.MaterialComponents.AppBarLayout.Primary @color/grey_600 From ea2956f3caa3080a3c3cc8385dea775bd8165627 Mon Sep 17 00:00:00 2001 From: Ammar Githam Date: Wed, 14 Apr 2021 01:08:08 +0900 Subject: [PATCH 2/9] Add state saved check before show. Fixes https://github.com/austinhuang0131/barinsta/issues/1071. --- .../webservices/interceptors/IgErrorsInterceptor.java | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/awais/instagrabber/webservices/interceptors/IgErrorsInterceptor.java b/app/src/main/java/awais/instagrabber/webservices/interceptors/IgErrorsInterceptor.java index e27eeae2..01cec822 100644 --- a/app/src/main/java/awais/instagrabber/webservices/interceptors/IgErrorsInterceptor.java +++ b/app/src/main/java/awais/instagrabber/webservices/interceptors/IgErrorsInterceptor.java @@ -5,6 +5,7 @@ import android.view.View; import androidx.annotation.NonNull; import androidx.annotation.StringRes; +import androidx.fragment.app.FragmentManager; import com.google.android.material.snackbar.Snackbar; @@ -59,7 +60,7 @@ public class IgErrorsInterceptor implements Interceptor { return; case 302: // redirect final String location = response.header("location"); - if (location.equals("https://www.instagram.com/accounts/login/")) { + if (location != null && location.equals("https://www.instagram.com/accounts/login/")) { // rate limited showErrorDialog(R.string.rate_limit); } @@ -70,7 +71,7 @@ public class IgErrorsInterceptor implements Interceptor { try { final String bodyString = body.string(); final JSONObject jsonObject = new JSONObject(bodyString); - String message = jsonObject.optString("message", null); + String message = jsonObject.optString("message"); if (!TextUtils.isEmpty(message)) { message = message.toLowerCase(); switch (message) { @@ -91,7 +92,7 @@ public class IgErrorsInterceptor implements Interceptor { return; } } - final String errorType = jsonObject.optString("error_type", null); + final String errorType = jsonObject.optString("error_type"); if (TextUtils.isEmpty(errorType)) return; if (errorType.equals("sentry_block")) { showErrorDialog(R.string.sentry_block); @@ -127,7 +128,9 @@ public class IgErrorsInterceptor implements Interceptor { 0, 0 ); - dialogFragment.show(mainActivity.getSupportFragmentManager(), "network_error_dialog"); + final FragmentManager fragmentManager = mainActivity.getSupportFragmentManager(); + if (fragmentManager.isStateSaved()) return; + dialogFragment.show(fragmentManager, "network_error_dialog"); } public void destroy() { From af3670e3ece32aa1af2848534a1bc5c01dd2a835 Mon Sep 17 00:00:00 2001 From: Ammar Githam Date: Wed, 14 Apr 2021 01:16:32 +0900 Subject: [PATCH 3/9] Add fragment manager destroyed checks. Fixes https://github.com/austinhuang0131/barinsta/issues/1068 --- .../instagrabber/asyncs/PostFetcher.java | 9 +-- .../fragments/HashTagFragment.java | 13 ++-- .../fragments/LocationFragment.java | 65 ++++++++++--------- 3 files changed, 47 insertions(+), 40 deletions(-) diff --git a/app/src/main/java/awais/instagrabber/asyncs/PostFetcher.java b/app/src/main/java/awais/instagrabber/asyncs/PostFetcher.java index ddd670f1..c0e63ea6 100755 --- a/app/src/main/java/awais/instagrabber/asyncs/PostFetcher.java +++ b/app/src/main/java/awais/instagrabber/asyncs/PostFetcher.java @@ -12,9 +12,6 @@ import awais.instagrabber.interfaces.FetchListener; import awais.instagrabber.repositories.responses.Media; import awais.instagrabber.utils.NetworkUtils; import awais.instagrabber.utils.ResponseBodyUtils; -//import awaisomereport.LogCollector; - -//import static awais.instagrabber.utils.Utils.logCollector; public final class PostFetcher extends AsyncTask { private static final String TAG = "PostFetcher"; @@ -136,9 +133,9 @@ public final class PostFetcher extends AsyncTask { return ResponseBodyUtils.parseGraphQLItem(media, null); } } catch (Exception e) { -// if (logCollector != null) { -// logCollector.appendException(e, LogCollector.LogFile.ASYNC_POST_FETCHER, "doInBackground"); -// } + // if (logCollector != null) { + // logCollector.appendException(e, LogCollector.LogFile.ASYNC_POST_FETCHER, "doInBackground"); + // } Log.e(TAG, "Error fetching post", e); } finally { if (conn != null) { diff --git a/app/src/main/java/awais/instagrabber/fragments/HashTagFragment.java b/app/src/main/java/awais/instagrabber/fragments/HashTagFragment.java index 81530dc5..c620f4f2 100644 --- a/app/src/main/java/awais/instagrabber/fragments/HashTagFragment.java +++ b/app/src/main/java/awais/instagrabber/fragments/HashTagFragment.java @@ -26,6 +26,7 @@ import androidx.appcompat.app.ActionBar; import androidx.coordinatorlayout.widget.CoordinatorLayout; import androidx.core.content.PermissionChecker; import androidx.fragment.app.Fragment; +import androidx.fragment.app.FragmentManager; import androidx.navigation.NavController; import androidx.navigation.NavDirections; import androidx.navigation.fragment.NavHostFragment; @@ -60,6 +61,7 @@ import awais.instagrabber.repositories.requests.StoryViewerOptions; import awais.instagrabber.repositories.responses.Hashtag; import awais.instagrabber.repositories.responses.Location; import awais.instagrabber.repositories.responses.Media; +import awais.instagrabber.repositories.responses.User; import awais.instagrabber.utils.Constants; import awais.instagrabber.utils.CookieUtils; import awais.instagrabber.utils.DownloadUtils; @@ -213,7 +215,9 @@ public class HashTagFragment extends Fragment implements SwipeRefreshLayout.OnRe final View mainPostImage, final int position) { if (opening) return; - if (TextUtils.isEmpty(feedModel.getUser().getUsername())) { + final User user = feedModel.getUser(); + if (user == null) return; + if (TextUtils.isEmpty(user.getUsername())) { opening = true; new PostFetcher(feedModel.getCode(), newFeedModel -> { opening = false; @@ -231,7 +235,9 @@ public class HashTagFragment extends Fragment implements SwipeRefreshLayout.OnRe builder.setSharedProfilePicElement(profilePicView) .setSharedMainPostElement(mainPostImage); } - builder.build().show(getChildFragmentManager(), "post_view"); + final FragmentManager fragmentManager = getChildFragmentManager(); + if (fragmentManager.isDestroyed()) return; + builder.build().show(fragmentManager, "post_view"); opening = false; } }; @@ -403,8 +409,7 @@ public class HashTagFragment extends Fragment implements SwipeRefreshLayout.OnRe try { Toast.makeText(getContext(), R.string.error_loading_hashtag, Toast.LENGTH_SHORT).show(); binding.swipeRefreshLayout.setEnabled(false); - } - catch (Exception ignored) {} + } catch (Exception ignored) {} return; } setTitle(); diff --git a/app/src/main/java/awais/instagrabber/fragments/LocationFragment.java b/app/src/main/java/awais/instagrabber/fragments/LocationFragment.java index c42809c5..75690dd0 100644 --- a/app/src/main/java/awais/instagrabber/fragments/LocationFragment.java +++ b/app/src/main/java/awais/instagrabber/fragments/LocationFragment.java @@ -24,6 +24,7 @@ import androidx.appcompat.app.ActionBar; import androidx.coordinatorlayout.widget.CoordinatorLayout; import androidx.core.content.PermissionChecker; import androidx.fragment.app.Fragment; +import androidx.fragment.app.FragmentManager; import androidx.navigation.NavController; import androidx.navigation.NavDirections; import androidx.navigation.fragment.NavHostFragment; @@ -56,6 +57,7 @@ import awais.instagrabber.models.enums.FavoriteType; import awais.instagrabber.repositories.requests.StoryViewerOptions; import awais.instagrabber.repositories.responses.Location; import awais.instagrabber.repositories.responses.Media; +import awais.instagrabber.repositories.responses.User; import awais.instagrabber.utils.Constants; import awais.instagrabber.utils.CookieUtils; import awais.instagrabber.utils.DownloadUtils; @@ -204,7 +206,9 @@ public class LocationFragment extends Fragment implements SwipeRefreshLayout.OnR final View mainPostImage, final int position) { if (opening) return; - if (TextUtils.isEmpty(feedModel.getUser().getUsername())) { + final User user = feedModel.getUser(); + if (user == null) return; + if (TextUtils.isEmpty(user.getUsername())) { opening = true; new PostFetcher(feedModel.getCode(), newFeedModel -> { opening = false; @@ -223,7 +227,9 @@ public class LocationFragment extends Fragment implements SwipeRefreshLayout.OnR builder.setSharedProfilePicElement(profilePicView) .setSharedMainPostElement(mainPostImage); } - builder.build().show(getChildFragmentManager(), "post_view"); + final FragmentManager fragmentManager = getChildFragmentManager(); + if (fragmentManager.isDestroyed()) return; + builder.build().show(fragmentManager, "post_view"); opening = false; } }; @@ -399,8 +405,7 @@ public class LocationFragment extends Fragment implements SwipeRefreshLayout.OnR try { Toast.makeText(getContext(), R.string.error_loading_location, Toast.LENGTH_SHORT).show(); binding.swipeRefreshLayout.setEnabled(false); - } - catch (Exception ignored) {} + } catch (Exception ignored) {} return; } setTitle(); @@ -409,16 +414,16 @@ public class LocationFragment extends Fragment implements SwipeRefreshLayout.OnR final long locationId = locationModel.getPk(); // binding.swipeRefreshLayout.setRefreshing(true); locationDetailsBinding.mainLocationImage.setImageURI("res:/" + R.drawable.ic_location); -// final String postCount = String.valueOf(locationModel.getCount()); -// final SpannableStringBuilder span = new SpannableStringBuilder(getResources().getQuantityString(R.plurals.main_posts_count_inline, -// locationModel.getPostCount() > 2000000000L -// ? 2000000000 -// : locationModel.getPostCount().intValue(), -// postCount)); -// span.setSpan(new RelativeSizeSpan(1.2f), 0, postCount.length(), 0); -// span.setSpan(new StyleSpan(Typeface.BOLD), 0, postCount.length(), 0); -// locationDetailsBinding.mainLocPostCount.setText(span); -// locationDetailsBinding.mainLocPostCount.setVisibility(View.VISIBLE); + // final String postCount = String.valueOf(locationModel.getCount()); + // final SpannableStringBuilder span = new SpannableStringBuilder(getResources().getQuantityString(R.plurals.main_posts_count_inline, + // locationModel.getPostCount() > 2000000000L + // ? 2000000000 + // : locationModel.getPostCount().intValue(), + // postCount)); + // span.setSpan(new RelativeSizeSpan(1.2f), 0, postCount.length(), 0); + // span.setSpan(new StyleSpan(Typeface.BOLD), 0, postCount.length(), 0); + // locationDetailsBinding.mainLocPostCount.setText(span); + // locationDetailsBinding.mainLocPostCount.setVisibility(View.VISIBLE); locationDetailsBinding.locationFullName.setText(locationModel.getName()); CharSequence biography = locationModel.getAddress() + "\n" + locationModel.getCity(); // binding.locationBiography.setCaptionIsExpandable(true); @@ -431,22 +436,22 @@ public class LocationFragment extends Fragment implements SwipeRefreshLayout.OnR } else { locationDetailsBinding.locationBiography.setVisibility(View.VISIBLE); locationDetailsBinding.locationBiography.setText(biography); -// locationDetailsBinding.locationBiography.addOnHashtagListener(autoLinkItem -> { -// final NavController navController = NavHostFragment.findNavController(this); -// final Bundle bundle = new Bundle(); -// final String originalText = autoLinkItem.getOriginalText().trim(); -// bundle.putString(ARG_HASHTAG, originalText); -// navController.navigate(R.id.action_global_hashTagFragment, bundle); -// }); -// locationDetailsBinding.locationBiography.addOnMentionClickListener(autoLinkItem -> { -// final String originalText = autoLinkItem.getOriginalText().trim(); -// navigateToProfile(originalText); -// }); -// locationDetailsBinding.locationBiography.addOnEmailClickListener(autoLinkItem -> Utils.openEmailAddress(context, -// autoLinkItem.getOriginalText() -// .trim())); -// locationDetailsBinding.locationBiography -// .addOnURLClickListener(autoLinkItem -> Utils.openURL(context, autoLinkItem.getOriginalText().trim())); + // locationDetailsBinding.locationBiography.addOnHashtagListener(autoLinkItem -> { + // final NavController navController = NavHostFragment.findNavController(this); + // final Bundle bundle = new Bundle(); + // final String originalText = autoLinkItem.getOriginalText().trim(); + // bundle.putString(ARG_HASHTAG, originalText); + // navController.navigate(R.id.action_global_hashTagFragment, bundle); + // }); + // locationDetailsBinding.locationBiography.addOnMentionClickListener(autoLinkItem -> { + // final String originalText = autoLinkItem.getOriginalText().trim(); + // navigateToProfile(originalText); + // }); + // locationDetailsBinding.locationBiography.addOnEmailClickListener(autoLinkItem -> Utils.openEmailAddress(context, + // autoLinkItem.getOriginalText() + // .trim())); + // locationDetailsBinding.locationBiography + // .addOnURLClickListener(autoLinkItem -> Utils.openURL(context, autoLinkItem.getOriginalText().trim())); locationDetailsBinding.locationBiography.setOnLongClickListener(v -> { Utils.copyText(context, biography); return true; From de9891f368dfecf98122b6de55ed0430ee97fede Mon Sep 17 00:00:00 2001 From: Ammar Githam Date: Wed, 14 Apr 2021 01:27:31 +0900 Subject: [PATCH 4/9] Add null check. Fixes https://github.com/austinhuang0131/barinsta/issues/1078 --- .../customviews/VideoPlayerViewHelper.java | 50 ++++++++++--------- 1 file changed, 27 insertions(+), 23 deletions(-) diff --git a/app/src/main/java/awais/instagrabber/customviews/VideoPlayerViewHelper.java b/app/src/main/java/awais/instagrabber/customviews/VideoPlayerViewHelper.java index b2cfc2f1..b8776bfd 100644 --- a/app/src/main/java/awais/instagrabber/customviews/VideoPlayerViewHelper.java +++ b/app/src/main/java/awais/instagrabber/customviews/VideoPlayerViewHelper.java @@ -14,8 +14,8 @@ import androidx.appcompat.widget.AppCompatTextView; import androidx.appcompat.widget.PopupMenu; import com.facebook.drawee.backends.pipeline.Fresco; +import com.facebook.drawee.backends.pipeline.PipelineDraweeControllerBuilder; import com.facebook.drawee.controller.BaseControllerListener; -import com.facebook.drawee.interfaces.DraweeController; import com.facebook.imagepipeline.image.ImageInfo; import com.facebook.imagepipeline.request.ImageRequest; import com.facebook.imagepipeline.request.ImageRequestBuilder; @@ -156,29 +156,33 @@ public class VideoPlayerViewHelper implements Player.EventListener { private void setThumbnail() { binding.thumbnail.setAspectRatio(thumbnailAspectRatio); - final ImageRequest thumbnailRequest = ImageRequestBuilder.newBuilderWithSource(Uri.parse(thumbnailUrl)) - .build(); - final DraweeController controller = Fresco.newDraweeControllerBuilder() - .setControllerListener(new BaseControllerListener() { - @Override - public void onFailure(final String id, final Throwable throwable) { - if (videoPlayerCallback != null) { - videoPlayerCallback.onThumbnailLoaded(); - } - } + ImageRequest thumbnailRequest = null; + if (thumbnailUrl != null) { + thumbnailRequest = ImageRequestBuilder.newBuilderWithSource(Uri.parse(thumbnailUrl)).build(); + } + final PipelineDraweeControllerBuilder builder = Fresco.newDraweeControllerBuilder() + .setControllerListener(new BaseControllerListener() { + @Override + public void onFailure(final String id, + final Throwable throwable) { + if (videoPlayerCallback != null) { + videoPlayerCallback.onThumbnailLoaded(); + } + } - @Override - public void onFinalImageSet(final String id, - final ImageInfo imageInfo, - final Animatable animatable) { - if (videoPlayerCallback != null) { - videoPlayerCallback.onThumbnailLoaded(); - } - } - }) - .setImageRequest(thumbnailRequest) - .build(); - binding.thumbnail.setController(controller); + @Override + public void onFinalImageSet(final String id, + final ImageInfo imageInfo, + final Animatable animatable) { + if (videoPlayerCallback != null) { + videoPlayerCallback.onThumbnailLoaded(); + } + } + }); + if (thumbnailRequest != null) { + builder.setImageRequest(thumbnailRequest); + } + binding.thumbnail.setController(builder.build()); } private void loadPlayer() { From 34e54837d5eccce0f961c2e7818ced7aaf87ec43 Mon Sep 17 00:00:00 2001 From: Ammar Githam Date: Wed, 14 Apr 2021 20:17:00 +0900 Subject: [PATCH 5/9] Create new caption object if null. Fixes https://github.com/austinhuang0131/barinsta/issues/1030 --- .../instagrabber/repositories/responses/Media.java | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/awais/instagrabber/repositories/responses/Media.java b/app/src/main/java/awais/instagrabber/repositories/responses/Media.java index c11669a8..135eee89 100644 --- a/app/src/main/java/awais/instagrabber/repositories/responses/Media.java +++ b/app/src/main/java/awais/instagrabber/repositories/responses/Media.java @@ -34,7 +34,7 @@ public class Media implements Serializable { private final boolean hasAudio; private final double videoDuration; private final long viewCount; - private final Caption caption; + private Caption caption; private final boolean canViewerSave; private final Audio audio; private final String title; @@ -271,7 +271,14 @@ public class Media implements Serializable { } public void setPostCaption(final String caption) { - final Caption caption1 = getCaption(); + Caption caption1 = getCaption(); + if (caption1 == null) { + final User user = getUser(); + if (user == null) return; + caption1 = new Caption(user.getPk(), caption); + this.caption = caption1; + return; + } caption1.setText(caption); } From d4ee1b9f4217d33cc787697fc5c3435f6ac7946f Mon Sep 17 00:00:00 2001 From: Ammar Githam Date: Wed, 14 Apr 2021 20:23:42 +0900 Subject: [PATCH 6/9] Set click listener on parent view. Fixes https://github.com/austinhuang0131/barinsta/issues/1055 --- .../adapters/viewholder/feed/FeedItemViewHolder.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/awais/instagrabber/adapters/viewholder/feed/FeedItemViewHolder.java b/app/src/main/java/awais/instagrabber/adapters/viewholder/feed/FeedItemViewHolder.java index 860bd027..042264c9 100644 --- a/app/src/main/java/awais/instagrabber/adapters/viewholder/feed/FeedItemViewHolder.java +++ b/app/src/main/java/awais/instagrabber/adapters/viewholder/feed/FeedItemViewHolder.java @@ -55,7 +55,7 @@ public abstract class FeedItemViewHolder extends RecyclerView.ViewHolder { private void setupComments(@NonNull final Media feedModel) { final long commentsCount = feedModel.getCommentCount(); bottomBinding.commentsCount.setText(String.valueOf(commentsCount)); - bottomBinding.commentsCount.setOnClickListener(v -> feedItemCallback.onCommentsClick(feedModel)); + bottomBinding.btnComments.setOnClickListener(v -> feedItemCallback.onCommentsClick(feedModel)); } private void setupProfilePic(@NonNull final Media media) { @@ -75,6 +75,7 @@ public abstract class FeedItemViewHolder extends RecyclerView.ViewHolder { // final SpannableString spannableString = new SpannableString(); // spannableString.setSpan(new CommentMentionClickSpan(), 0, titleLen, 0); final User user = media.getUser(); + if (user == null) return; final String title = "@" + user.getUsername(); topBinding.title.setText(title); topBinding.title.setOnClickListener(v -> feedItemCallback.onNameClick(media, topBinding.ivProfilePic)); @@ -120,8 +121,7 @@ public abstract class FeedItemViewHolder extends RecyclerView.ViewHolder { topBinding.title.setLayoutParams(new RelativeLayout.LayoutParams( RelativeLayout.LayoutParams.MATCH_PARENT, RelativeLayout.LayoutParams.MATCH_PARENT )); - } - else { + } else { final String locationName = location.getName(); if (TextUtils.isEmpty(locationName)) { topBinding.location.setVisibility(View.GONE); From f2a3506b19a0f05277ea5dc41d78767fcc74168a Mon Sep 17 00:00:00 2001 From: Ammar Githam Date: Wed, 14 Apr 2021 20:48:42 +0900 Subject: [PATCH 7/9] Make refreshStory synchronised? May fix https://github.com/austinhuang0131/barinsta/issues/945 --- .../fragments/StoryViewerFragment.java | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/app/src/main/java/awais/instagrabber/fragments/StoryViewerFragment.java b/app/src/main/java/awais/instagrabber/fragments/StoryViewerFragment.java index ddd84ce3..c13efdc1 100644 --- a/app/src/main/java/awais/instagrabber/fragments/StoryViewerFragment.java +++ b/app/src/main/java/awais/instagrabber/fragments/StoryViewerFragment.java @@ -2,14 +2,12 @@ package awais.instagrabber.fragments; import android.annotation.SuppressLint; import android.content.Context; -import android.content.Intent; import android.content.pm.PackageManager; import android.graphics.drawable.Animatable; import android.net.Uri; import android.os.Bundle; import android.os.Handler; import android.util.Log; -import android.util.Pair; import android.view.GestureDetector; import android.view.Gravity; import android.view.LayoutInflater; @@ -72,7 +70,6 @@ import awais.instagrabber.BuildConfig; import awais.instagrabber.R; import awais.instagrabber.adapters.StoriesAdapter; import awais.instagrabber.asyncs.CreateThreadAction; -import awais.instagrabber.asyncs.PostFetcher; import awais.instagrabber.customviews.helpers.SwipeGestureListener; import awais.instagrabber.databinding.FragmentStoryViewerBinding; import awais.instagrabber.fragments.main.ProfileFragmentDirections; @@ -105,7 +102,6 @@ import awais.instagrabber.webservices.DirectMessagesService; import awais.instagrabber.webservices.MediaService; import awais.instagrabber.webservices.ServiceCallback; import awais.instagrabber.webservices.StoriesService; -//import awaisomereport.LogCollector; import retrofit2.Call; import retrofit2.Callback; import retrofit2.Response; @@ -113,7 +109,6 @@ import retrofit2.Response; import static awais.instagrabber.customviews.helpers.SwipeGestureListener.SWIPE_THRESHOLD; import static awais.instagrabber.customviews.helpers.SwipeGestureListener.SWIPE_VELOCITY_THRESHOLD; import static awais.instagrabber.utils.Constants.MARK_AS_SEEN; -//import static awais.instagrabber.utils.Utils.logCollector; import static awais.instagrabber.utils.Utils.settingsHelper; public class StoryViewerFragment extends Fragment { @@ -417,10 +412,10 @@ public class StoryViewerFragment extends Fragment { return true; } } catch (final Exception e) { -// if (logCollector != null) -// logCollector.appendException(e, LogCollector.LogFile.ACTIVITY_STORY_VIEWER, "setupListeners", -// new Pair<>("swipeEvent", swipeEvent), -// new Pair<>("diffX", diffX)); + // if (logCollector != null) + // logCollector.appendException(e, LogCollector.LogFile.ACTIVITY_STORY_VIEWER, "setupListeners", + // new Pair<>("swipeEvent", swipeEvent), + // new Pair<>("diffX", diffX)); if (BuildConfig.DEBUG) Log.e(TAG, "Error", e); } return false; @@ -838,7 +833,7 @@ public class StoryViewerFragment extends Fragment { } } - private void refreshStory() { + private synchronized void refreshStory() { if (binding.storiesList.getVisibility() == View.VISIBLE) { final List storyModels = storiesViewModel.getList().getValue(); if (storyModels != null && storyModels.size() > 0) { From eed4036ad94ff29636cabd39fc888e8618a60d9c Mon Sep 17 00:00:00 2001 From: Ammar Githam Date: Wed, 14 Apr 2021 21:17:07 +0900 Subject: [PATCH 8/9] Fix setItemsToThread. Fixes https://github.com/austinhuang0131/barinsta/issues/967 --- .../java/awais/instagrabber/managers/InboxManager.java | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/awais/instagrabber/managers/InboxManager.java b/app/src/main/java/awais/instagrabber/managers/InboxManager.java index efca55f5..eb54b8e2 100644 --- a/app/src/main/java/awais/instagrabber/managers/InboxManager.java +++ b/app/src/main/java/awais/instagrabber/managers/InboxManager.java @@ -285,8 +285,13 @@ public final class InboxManager { if (index < 0) return; final List threads = inbox.getThreads(); final DirectThread thread = threads.get(index); - thread.setItems(updatedItems); - setThread(inbox, index, thread); + try { + final DirectThread threadClone = (DirectThread) thread.clone(); + threadClone.setItems(updatedItems); + setThread(inbox, index, threadClone); + } catch (Exception e) { + Log.e(TAG, "setItemsToThread: ", e); + } } } From cfd1d4a421685791ff8597343b5e33c7f279d9a2 Mon Sep 17 00:00:00 2001 From: Ammar Githam Date: Wed, 14 Apr 2021 21:17:24 +0900 Subject: [PATCH 9/9] Null check csrf token --- .../java/awais/instagrabber/managers/ThreadManager.java | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/awais/instagrabber/managers/ThreadManager.java b/app/src/main/java/awais/instagrabber/managers/ThreadManager.java index 5b84c97c..6074363e 100644 --- a/app/src/main/java/awais/instagrabber/managers/ThreadManager.java +++ b/app/src/main/java/awais/instagrabber/managers/ThreadManager.java @@ -92,14 +92,14 @@ public final class ThreadManager { private final MutableLiveData pendingRequests = new MutableLiveData<>(null); private final String threadId; - private final DirectMessagesService service; private final long viewerId; private final ThreadIdOrUserIds threadIdOrUserIds; private final User currentUser; private final ContentResolver contentResolver; - private final MediaService mediaService; - private final FriendshipService friendshipService; + private DirectMessagesService service; + private MediaService mediaService; + private FriendshipService friendshipService; private InboxManager inboxManager; private LiveData thread; private LiveData inputMode; @@ -157,6 +157,7 @@ public final class ThreadManager { viewerId = CookieUtils.getUserIdFromCookie(cookie); final String deviceUuid = settingsHelper.getString(Constants.DEVICE_UUID); final String csrfToken = CookieUtils.getCsrfTokenFromCookie(cookie); + if (csrfToken == null) return; // if (TextUtils.isEmpty(csrfToken) || viewerId <= 0 || TextUtils.isEmpty(deviceUuid)) { // throw new IllegalArgumentException("User is not logged in!"); // }