From 20d9a3935bc26717cb3d7cabbcf9bec70621bab0 Mon Sep 17 00:00:00 2001 From: Austin Huang Date: Tue, 23 Feb 2021 22:02:13 -0500 Subject: [PATCH] close #717 and fix looper toast issue --- .../fragments/CommentsViewerFragment.java | 22 ++++++++-------- .../fragments/FollowViewerFragment.java | 5 ++-- .../fragments/HashTagFragment.java | 25 ++++++++++--------- 3 files changed, 28 insertions(+), 24 deletions(-) diff --git a/app/src/main/java/awais/instagrabber/fragments/CommentsViewerFragment.java b/app/src/main/java/awais/instagrabber/fragments/CommentsViewerFragment.java index d40f8608..af9af998 100644 --- a/app/src/main/java/awais/instagrabber/fragments/CommentsViewerFragment.java +++ b/app/src/main/java/awais/instagrabber/fragments/CommentsViewerFragment.java @@ -94,17 +94,12 @@ public final class CommentsViewerFragment extends BottomSheetDialogFragment impl commentsViewModel.getList().postValue(list); } binding.swipeRefreshLayout.setRefreshing(false); - stopCurrentExecutor(); + stopCurrentExecutor(false); } @Override public void onFailure(Throwable t) { - try { - Toast.makeText(getContext(), t.getMessage(), Toast.LENGTH_SHORT).show(); - binding.swipeRefreshLayout.setRefreshing(false); - stopCurrentExecutor(); - } - catch(Throwable e) {} + stopCurrentExecutor(true); } }; @@ -227,7 +222,7 @@ public final class CommentsViewerFragment extends BottomSheetDialogFragment impl endCursor = null; lazyLoader.resetState(); commentsViewModel.getList().postValue(Collections.emptyList()); - stopCurrentExecutor(); + stopCurrentExecutor(false); currentlyRunning = new CommentsFetcher(shortCode, "", fetchListener).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); } @@ -276,7 +271,7 @@ public final class CommentsViewerFragment extends BottomSheetDialogFragment impl endCursor = null; }); binding.rvComments.addOnScrollListener(lazyLoader); - stopCurrentExecutor(); + stopCurrentExecutor(false); onRefresh(); } @@ -462,7 +457,7 @@ public final class CommentsViewerFragment extends BottomSheetDialogFragment impl NavHostFragment.findNavController(this).navigate(action); } - private void stopCurrentExecutor() { + private void stopCurrentExecutor(@NonNull final boolean failed) { if (currentlyRunning != null) { try { currentlyRunning.cancel(true); @@ -470,6 +465,13 @@ public final class CommentsViewerFragment extends BottomSheetDialogFragment impl if (BuildConfig.DEBUG) Log.e(TAG, "", e); } } + if (failed) { + try { + Toast.makeText(getContext(), t.getMessage(), Toast.LENGTH_SHORT).show(); + binding.swipeRefreshLayout.setRefreshing(false); + } + catch(Throwable e) {} + } } @Nullable diff --git a/app/src/main/java/awais/instagrabber/fragments/FollowViewerFragment.java b/app/src/main/java/awais/instagrabber/fragments/FollowViewerFragment.java index 8112d497..42fcee57 100644 --- a/app/src/main/java/awais/instagrabber/fragments/FollowViewerFragment.java +++ b/app/src/main/java/awais/instagrabber/fragments/FollowViewerFragment.java @@ -348,16 +348,17 @@ public final class FollowViewerFragment extends Fragment implements SwipeRefresh loading = false; final ArrayList groups = new ArrayList<>(1); - if (isCompare) { + if (isCompare && followingModels != null && followersModels != null && allFollowing != null) { if (followingModels != null && followingModels.size() > 0) groups.add(new ExpandableGroup(resources.getString(R.string.followers_not_following, username), followingModels)); if (followersModels != null && followersModels.size() > 0) groups.add(new ExpandableGroup(resources.getString(R.string.followers_not_follower, namePost), followersModels)); if (allFollowing != null && allFollowing.size() > 0) groups.add(new ExpandableGroup(resources.getString(R.string.followers_both_following), allFollowing)); - } else { + } else if (followModels != null) { groups.add(new ExpandableGroup(type, followModels)); } + else return; adapter = new FollowAdapter(clickListener, groups); adapter.toggleGroup(0); binding.rvFollow.setAdapter(adapter); diff --git a/app/src/main/java/awais/instagrabber/fragments/HashTagFragment.java b/app/src/main/java/awais/instagrabber/fragments/HashTagFragment.java index 845da1c6..12b9b413 100644 --- a/app/src/main/java/awais/instagrabber/fragments/HashTagFragment.java +++ b/app/src/main/java/awais/instagrabber/fragments/HashTagFragment.java @@ -91,7 +91,7 @@ public class HashTagFragment extends Fragment implements SwipeRefreshLayout.OnRe private boolean hasStories = false; private boolean opening = false; private String hashtag; - private HashtagModel hashtagModel; + private HashtagModel hashtagModel = null; private ActionMode actionMode; private StoriesService storiesService; private AsyncTask currentlyExecuting; @@ -373,22 +373,12 @@ public class HashTagFragment extends Fragment implements SwipeRefreshLayout.OnRe public void onResult(final HashtagModel result) { hashtagModel = result; binding.swipeRefreshLayout.setRefreshing(false); - final Context context = getContext(); - if (context == null) return; - if (hashtagModel == null) { - Toast.makeText(context, R.string.error_loading_hashtag, Toast.LENGTH_SHORT).show(); - binding.swipeRefreshLayout.setEnabled(false); - return; - } - setTitle(); setHashtagDetails(); - setupPosts(); - fetchStories(); } @Override public void onFailure(Throwable t) { - Toast.makeText(getContext(), t.getMessage(), Toast.LENGTH_SHORT).show(); + setHashtagDetails(); } }).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); } @@ -406,6 +396,17 @@ public class HashTagFragment extends Fragment implements SwipeRefreshLayout.OnRe } private void setHashtagDetails() { + if (hashtagModel == null) { + try { + Toast.makeText(getContext(), R.string.error_loading_hashtag, Toast.LENGTH_SHORT).show(); + binding.swipeRefreshLayout.setEnabled(false); + } + catch (Exception ignored) {} + return; + } + setTitle(); + setupPosts(); + fetchStories(); if (isLoggedIn) { hashtagDetailsBinding.btnFollowTag.setVisibility(View.VISIBLE); hashtagDetailsBinding.btnFollowTag.setText(hashtagModel.getFollowing() ? R.string.unfollow : R.string.follow);