diff --git a/app/src/main/java/awais/instagrabber/adapters/viewholder/StoryListViewHolder.java b/app/src/main/java/awais/instagrabber/adapters/viewholder/StoryListViewHolder.java index 3433889d..b2bb5d17 100644 --- a/app/src/main/java/awais/instagrabber/adapters/viewholder/StoryListViewHolder.java +++ b/app/src/main/java/awais/instagrabber/adapters/viewholder/StoryListViewHolder.java @@ -40,13 +40,19 @@ public final class StoryListViewHolder extends RecyclerView.ViewHolder { notificationClickListener.onProfileClick(model.getProfileModel().getUsername()); }); - binding.ivPreviewPic.setVisibility(View.VISIBLE); if (model.getFirstStoryModel() != null) { binding.ivPreviewPic.setVisibility(View.VISIBLE); binding.ivPreviewPic.setImageURI(model.getFirstStoryModel().getThumbnail()); } else binding.ivPreviewPic.setVisibility(View.INVISIBLE); + float alpha = model.isFullyRead() ? 0.5F : 1.0F; + binding.ivProfilePic.setAlpha(alpha); + binding.ivPreviewPic.setAlpha(alpha); + binding.tvUsername.setAlpha(alpha); + binding.tvComment.setAlpha(alpha); + binding.tvDate.setAlpha(alpha); + itemView.setOnClickListener(v -> { if (notificationClickListener == null) return; notificationClickListener.onFeedStoryClick(model, position); diff --git a/app/src/main/java/awais/instagrabber/fragments/StoryListViewerFragment.java b/app/src/main/java/awais/instagrabber/fragments/StoryListViewerFragment.java index d35d62e0..b8303db4 100644 --- a/app/src/main/java/awais/instagrabber/fragments/StoryListViewerFragment.java +++ b/app/src/main/java/awais/instagrabber/fragments/StoryListViewerFragment.java @@ -33,6 +33,8 @@ import awais.instagrabber.fragments.main.FeedFragment; import awais.instagrabber.fragments.settings.MorePreferencesFragmentDirections; import awais.instagrabber.models.FeedStoryModel; import awais.instagrabber.models.HighlightModel; +import awais.instagrabber.utils.Constants; +import awais.instagrabber.utils.CookieUtils; import awais.instagrabber.utils.TextUtils; import awais.instagrabber.viewmodels.FeedStoriesViewModel; import awais.instagrabber.viewmodels.ArchivesViewModel; @@ -40,13 +42,15 @@ import awais.instagrabber.webservices.ServiceCallback; import awais.instagrabber.webservices.StoriesService; import awais.instagrabber.webservices.StoriesService.ArchiveFetchResponse; +import static awais.instagrabber.utils.Utils.settingsHelper; + public final class StoryListViewerFragment extends Fragment implements SwipeRefreshLayout.OnRefreshListener { private static final String TAG = "StoryListViewerFragment"; private AppCompatActivity fragmentActivity; private FragmentStoryListViewerBinding binding; private SwipeRefreshLayout root; - private boolean shouldRefresh = true; + private boolean shouldRefresh = true, firstRefresh = true; private FeedStoriesViewModel feedStoriesViewModel; private ArchivesViewModel archivesViewModel; private StoriesService storiesService; @@ -174,9 +178,27 @@ public final class StoryListViewerFragment extends Fragment implements SwipeRefr @Override public void onRefresh() { binding.swipeRefreshLayout.setRefreshing(true); - if (type == "feed") { + if (type == "feed" && firstRefresh) { binding.swipeRefreshLayout.setRefreshing(false); feedStoriesViewModel.getList().postValue(FeedFragment.feedStories); + firstRefresh = false; + } + else if (type == "feed") { + final String cookie = settingsHelper.getString(Constants.COOKIE); + storiesService.getFeedStories(CookieUtils.getCsrfTokenFromCookie(cookie), new ServiceCallback>() { + @Override + public void onSuccess(final List result) { + feedStoriesViewModel.getList().postValue(result); + FeedFragment.feedStories = result; + binding.swipeRefreshLayout.setRefreshing(false); + } + + @Override + public void onFailure(final Throwable t) { + Log.e(TAG, "failed", t); + Toast.makeText(context, t.getMessage(), Toast.LENGTH_SHORT).show(); + } + }); } else if (type == "archive") { storiesService.fetchArchive(endCursor, cb); diff --git a/app/src/main/java/awais/instagrabber/fragments/StoryViewerFragment.java b/app/src/main/java/awais/instagrabber/fragments/StoryViewerFragment.java index 6c8f39f9..41f37e2f 100644 --- a/app/src/main/java/awais/instagrabber/fragments/StoryViewerFragment.java +++ b/app/src/main/java/awais/instagrabber/fragments/StoryViewerFragment.java @@ -968,21 +968,22 @@ public class StoryViewerFragment extends Fragment { Toast.makeText(context, R.string.be_patient, Toast.LENGTH_SHORT).show(); return; } -// if (settingsHelper.getBoolean(MARK_AS_SEEN) -// && oldFeedStory != null -// && oldFeedStory instanceof FeedStoryModel -// && viewModel instanceof FeedStoriesViewModel) { -// final FeedStoriesViewModel feedStoriesViewModel = (FeedStoriesViewModel) viewModel; -// final FeedStoryModel oldFeedStoryModel = (FeedStoryModel) oldFeedStory; -// if (oldFeedStoryModel.isFullyRead()) { -// oldFeedStoryModel.setFullyRead(false); -// final List models = feedStoriesViewModel.getList().getValue(); -// final List modelsCopy = models == null ? new ArrayList<>() : new ArrayList<>(models); -// Log.d("austin_debug", oldFeedStoryModel.getProfileModel().getUsername() + ", v " + models.get(currentFeedStoryIndex).isFullyRead() + " l " + oldFeedStoryModel.isFullyRead()); -// modelsCopy.set(currentFeedStoryIndex, oldFeedStoryModel); -// feedStoriesViewModel.getList().setValue(models); -// } -// } + if (settingsHelper.getBoolean(MARK_AS_SEEN) + && oldFeedStory != null + && oldFeedStory instanceof FeedStoryModel + && viewModel instanceof FeedStoriesViewModel) { + final FeedStoriesViewModel feedStoriesViewModel = (FeedStoriesViewModel) viewModel; + final FeedStoryModel oldFeedStoryModel = (FeedStoryModel) oldFeedStory; + if (!oldFeedStoryModel.isFullyRead()) { + oldFeedStoryModel.setFullyRead(true); + final List models = feedStoriesViewModel.getList().getValue(); + final List modelsCopy = models == null ? new ArrayList<>() : new ArrayList<>(models); + Log.d("austin_debug", oldFeedStoryModel.getProfileModel().getUsername() + ", v " + models.get(currentFeedStoryIndex).isFullyRead() + " l " + oldFeedStoryModel.isFullyRead()); + modelsCopy.set(currentFeedStoryIndex, oldFeedStoryModel); + FeedFragment.feedStories = modelsCopy; + feedStoriesViewModel.getList().setValue(models); + } + } fetching = true; binding.btnBackward.setVisibility(currentFeedStoryIndex == 1 && backward ? View.INVISIBLE : View.VISIBLE); binding.btnForward.setVisibility(last ? View.INVISIBLE : View.VISIBLE); diff --git a/app/src/main/java/awais/instagrabber/fragments/main/FeedFragment.java b/app/src/main/java/awais/instagrabber/fragments/main/FeedFragment.java index f627435e..096cf206 100644 --- a/app/src/main/java/awais/instagrabber/fragments/main/FeedFragment.java +++ b/app/src/main/java/awais/instagrabber/fragments/main/FeedFragment.java @@ -389,10 +389,7 @@ public class FeedFragment extends Fragment implements SwipeRefreshLayout.OnRefre storiesRecyclerView.setLayoutManager(new LinearLayoutManager(context, RecyclerView.HORIZONTAL, false)); storiesRecyclerView.setAdapter(feedStoriesAdapter); fragmentActivity.setCollapsingView(storiesRecyclerView); - feedStoriesViewModel.getList().observe(fragmentActivity, list -> { - Log.d("austin_debug", "observed"); - feedStoriesAdapter.submitList(list); - }); + feedStoriesViewModel.getList().observe(getViewLifecycleOwner(), feedStoriesAdapter::submitList); fetchStories(); }