1
0
mirror of https://github.com/KokaKiwi/BarInsta synced 2024-11-22 22:57:29 +00:00

add many fetch failure checks, close #486

This commit is contained in:
Austin Huang 2020-12-31 19:35:33 -05:00
parent b790f85d6e
commit 251228dcc4
No known key found for this signature in database
GPG Key ID: 84C23AA04587A91F
7 changed files with 51 additions and 19 deletions

View File

@ -145,6 +145,7 @@ public final class CommentsFetcher extends AsyncTask<Void, Void, List<CommentMod
"getChildComments", "getChildComments",
new Pair<>("commentModels.size", commentModels.size())); new Pair<>("commentModels.size", commentModels.size()));
if (BuildConfig.DEBUG) Log.e(TAG, "", e); if (BuildConfig.DEBUG) Log.e(TAG, "", e);
if (fetchListener != null) fetchListener.onFailure(e);
break; break;
} }
} }
@ -284,6 +285,7 @@ public final class CommentsFetcher extends AsyncTask<Void, Void, List<CommentMod
logCollector.appendException(e, LogCollector.LogFile.ASYNC_COMMENTS_FETCHER, "getParentComments", logCollector.appendException(e, LogCollector.LogFile.ASYNC_COMMENTS_FETCHER, "getParentComments",
new Pair<>("commentModelsList.size", commentModels.size())); new Pair<>("commentModelsList.size", commentModels.size()));
if (BuildConfig.DEBUG) Log.e("AWAISKING_APP", "", e); if (BuildConfig.DEBUG) Log.e("AWAISKING_APP", "", e);
if (fetchListener != null) fetchListener.onFailure(e);
return null; return null;
} }
return commentModels; return commentModels;

View File

@ -89,6 +89,7 @@ public final class HashtagFetcher extends AsyncTask<Void, Void, HashtagModel> {
if (logCollector != null) if (logCollector != null)
logCollector.appendException(e, LogCollector.LogFile.ASYNC_HASHTAG_FETCHER, "doInBackground"); logCollector.appendException(e, LogCollector.LogFile.ASYNC_HASHTAG_FETCHER, "doInBackground");
if (BuildConfig.DEBUG) Log.e(TAG, "", e); if (BuildConfig.DEBUG) Log.e(TAG, "", e);
if (fetchListener != null) fetchListener.onFailure(e);
} }
return result; return result;

View File

@ -97,6 +97,13 @@ public final class CommentsViewerFragment extends BottomSheetDialogFragment impl
binding.swipeRefreshLayout.setRefreshing(false); binding.swipeRefreshLayout.setRefreshing(false);
stopCurrentExecutor(); stopCurrentExecutor();
} }
@Override
public void onFailure(Throwable t) {
Toast.makeText(getContext(), t.getMessage(), Toast.LENGTH_SHORT).show();
binding.swipeRefreshLayout.setRefreshing(false);
stopCurrentExecutor();
}
}; };
private final CommentsAdapter.CommentCallback commentCallback = new CommentsAdapter.CommentCallback() { private final CommentsAdapter.CommentCallback commentCallback = new CommentsAdapter.CommentCallback() {

View File

@ -80,6 +80,7 @@ public final class FollowViewerFragment extends Fragment implements SwipeRefresh
@Override @Override
public void onFailure(final Throwable t) { public void onFailure(final Throwable t) {
binding.swipeRefreshLayout.setRefreshing(false); binding.swipeRefreshLayout.setRefreshing(false);
Toast.makeText(getContext(), t.getMessage(), Toast.LENGTH_SHORT).show();
Log.e(TAG, "Error fetching list (double, following)", t); Log.e(TAG, "Error fetching list (double, following)", t);
} }
}; };
@ -105,6 +106,7 @@ public final class FollowViewerFragment extends Fragment implements SwipeRefresh
@Override @Override
public void onFailure(final Throwable t) { public void onFailure(final Throwable t) {
binding.swipeRefreshLayout.setRefreshing(false); binding.swipeRefreshLayout.setRefreshing(false);
Toast.makeText(getContext(), t.getMessage(), Toast.LENGTH_SHORT).show();
Log.e(TAG, "Error fetching list (double, follower)", t); Log.e(TAG, "Error fetching list (double, follower)", t);
} }
}; };
@ -219,6 +221,7 @@ public final class FollowViewerFragment extends Fragment implements SwipeRefresh
@Override @Override
public void onFailure(final Throwable t) { public void onFailure(final Throwable t) {
binding.swipeRefreshLayout.setRefreshing(false); binding.swipeRefreshLayout.setRefreshing(false);
Toast.makeText(getContext(), t.getMessage(), Toast.LENGTH_SHORT).show();
Log.e(TAG, "Error fetching list (single)", t); Log.e(TAG, "Error fetching list (single)", t);
} }
}; };

View File

@ -54,6 +54,7 @@ import awais.instagrabber.db.entities.Favorite;
import awais.instagrabber.db.repositories.FavoriteRepository; import awais.instagrabber.db.repositories.FavoriteRepository;
import awais.instagrabber.db.repositories.RepositoryCallback; import awais.instagrabber.db.repositories.RepositoryCallback;
import awais.instagrabber.dialogs.PostsLayoutPreferencesDialogFragment; import awais.instagrabber.dialogs.PostsLayoutPreferencesDialogFragment;
import awais.instagrabber.interfaces.FetchListener;
import awais.instagrabber.models.FeedModel; import awais.instagrabber.models.FeedModel;
import awais.instagrabber.models.HashtagModel; import awais.instagrabber.models.HashtagModel;
import awais.instagrabber.models.PostsLayoutPreferences; import awais.instagrabber.models.PostsLayoutPreferences;
@ -363,19 +364,27 @@ public class HashTagFragment extends Fragment implements SwipeRefreshLayout.OnRe
private void fetchHashtagModel() { private void fetchHashtagModel() {
stopCurrentExecutor(); stopCurrentExecutor();
binding.swipeRefreshLayout.setRefreshing(true); binding.swipeRefreshLayout.setRefreshing(true);
currentlyExecuting = new HashtagFetcher(hashtag.substring(1), result -> { currentlyExecuting = new HashtagFetcher(hashtag.substring(1), new FetchListener<HashtagModel>() {
hashtagModel = result; @Override
binding.swipeRefreshLayout.setRefreshing(false); public void onResult(final HashtagModel result) {
final Context context = getContext(); hashtagModel = result;
if (context == null) return; binding.swipeRefreshLayout.setRefreshing(false);
if (hashtagModel == null) { final Context context = getContext();
Toast.makeText(context, R.string.error_loading_profile, Toast.LENGTH_SHORT).show(); if (context == null) return;
return; if (hashtagModel == null) {
Toast.makeText(context, R.string.error_loading_profile, Toast.LENGTH_SHORT).show();
return;
}
setTitle();
setHashtagDetails();
setupPosts();
fetchStories();
}
@Override
public void onFailure(Throwable t) {
Toast.makeText(getContext(), t.getMessage(), Toast.LENGTH_SHORT).show();
} }
setTitle();
setHashtagDetails();
setupPosts();
fetchStories();
}).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); }).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
} }
@ -524,7 +533,7 @@ public class HashTagFragment extends Fragment implements SwipeRefreshLayout.OnRe
public void onSuccess(final Void result) { public void onSuccess(final Void result) {
hashtagDetailsBinding.favChip.setText(R.string.favorite_short); hashtagDetailsBinding.favChip.setText(R.string.favorite_short);
hashtagDetailsBinding.favChip.setChipIconResource(R.drawable.ic_star_check_24); hashtagDetailsBinding.favChip.setChipIconResource(R.drawable.ic_star_check_24);
showSnackbar(getString(R.string.added_to_favs)); showSnackbar(getString(R.string.added_to_favs_short));
} }
@Override @Override

View File

@ -97,9 +97,7 @@ public final class LikesViewerFragment extends BottomSheetDialogFragment impleme
NavHostFragment.findNavController(LikesViewerFragment.this).navigate(R.id.action_global_profileFragment, bundle); NavHostFragment.findNavController(LikesViewerFragment.this).navigate(R.id.action_global_profileFragment, bundle);
} }
}); });
layoutManager = new LinearLayoutManager(getContext());
binding.rvLikes.setAdapter(likesAdapter); binding.rvLikes.setAdapter(likesAdapter);
binding.rvLikes.setLayoutManager(layoutManager);
binding.swipeRefreshLayout.setRefreshing(false); binding.swipeRefreshLayout.setRefreshing(false);
} }
@ -158,6 +156,8 @@ public final class LikesViewerFragment extends BottomSheetDialogFragment impleme
binding.swipeRefreshLayout.setRefreshing(true); binding.swipeRefreshLayout.setRefreshing(true);
resources = getResources(); resources = getResources();
if (isComment && !isLoggedIn) { if (isComment && !isLoggedIn) {
layoutManager = new LinearLayoutManager(getContext());
binding.rvLikes.setLayoutManager(layoutManager);
lazyLoader = new RecyclerLazyLoader(layoutManager, (page, totalItemsCount) -> { lazyLoader = new RecyclerLazyLoader(layoutManager, (page, totalItemsCount) -> {
if (!TextUtils.isEmpty(endCursor)) if (!TextUtils.isEmpty(endCursor))
graphQLService.fetchCommentLikers(postId, endCursor, acb); graphQLService.fetchCommentLikers(postId, endCursor, acb);

View File

@ -36,6 +36,7 @@ import awais.instagrabber.asyncs.PostFetcher;
import awais.instagrabber.databinding.FragmentNotificationsViewerBinding; import awais.instagrabber.databinding.FragmentNotificationsViewerBinding;
import awais.instagrabber.dialogs.ProfilePicDialogFragment; import awais.instagrabber.dialogs.ProfilePicDialogFragment;
import awais.instagrabber.fragments.settings.MorePreferencesFragmentDirections; import awais.instagrabber.fragments.settings.MorePreferencesFragmentDirections;
import awais.instagrabber.interfaces.FetchListener;
import awais.instagrabber.interfaces.MentionClickListener; import awais.instagrabber.interfaces.MentionClickListener;
import awais.instagrabber.models.FeedModel; import awais.instagrabber.models.FeedModel;
import awais.instagrabber.models.NotificationModel; import awais.instagrabber.models.NotificationModel;
@ -267,9 +268,18 @@ public final class NotificationsViewerFragment extends Fragment implements Swipe
binding.swipeRefreshLayout.setRefreshing(true); binding.swipeRefreshLayout.setRefreshing(true);
switch (type) { switch (type) {
case "notif": case "notif":
new NotificationsFetcher(true, notificationModels -> { new NotificationsFetcher(true, new FetchListener<List<NotificationModel>>() {
binding.swipeRefreshLayout.setRefreshing(false); @Override
notificationViewModel.getList().postValue(notificationModels); public void onResult(final List<NotificationModel> notificationModels) {
binding.swipeRefreshLayout.setRefreshing(false);
notificationViewModel.getList().postValue(notificationModels);
}
@Override
public void onFailure(Throwable t) {
binding.swipeRefreshLayout.setRefreshing(false);
Toast.makeText(getContext(), t.getMessage(), Toast.LENGTH_SHORT).show();
}
}).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); }).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
break; break;
case "ayml": case "ayml":
@ -284,7 +294,7 @@ public final class NotificationsViewerFragment extends Fragment implements Swipe
@Override @Override
public void onFailure(final Throwable t) { public void onFailure(final Throwable t) {
binding.swipeRefreshLayout.setRefreshing(false); binding.swipeRefreshLayout.setRefreshing(false);
Toast.makeText(context, R.string.downloader_unknown_error, Toast.LENGTH_SHORT).show(); Toast.makeText(getContext(), t.getMessage(), Toast.LENGTH_SHORT).show();
} }
}); });
break; break;