story list optimization
This commit is contained in:
parent
d2e3f6c4df
commit
f955a81599
@ -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);
|
||||
|
@ -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<List<FeedStoryModel>>() {
|
||||
@Override
|
||||
public void onSuccess(final List<FeedStoryModel> 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);
|
||||
|
@ -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<FeedStoryModel> models = feedStoriesViewModel.getList().getValue();
|
||||
// final List<FeedStoryModel> 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<FeedStoryModel> models = feedStoriesViewModel.getList().getValue();
|
||||
final List<FeedStoryModel> 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);
|
||||
|
@ -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();
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user