mirror of
https://github.com/KokaKiwi/BarInsta
synced 2024-11-22 14:47:29 +00:00
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());
|
notificationClickListener.onProfileClick(model.getProfileModel().getUsername());
|
||||||
});
|
});
|
||||||
|
|
||||||
binding.ivPreviewPic.setVisibility(View.VISIBLE);
|
|
||||||
if (model.getFirstStoryModel() != null) {
|
if (model.getFirstStoryModel() != null) {
|
||||||
binding.ivPreviewPic.setVisibility(View.VISIBLE);
|
binding.ivPreviewPic.setVisibility(View.VISIBLE);
|
||||||
binding.ivPreviewPic.setImageURI(model.getFirstStoryModel().getThumbnail());
|
binding.ivPreviewPic.setImageURI(model.getFirstStoryModel().getThumbnail());
|
||||||
}
|
}
|
||||||
else binding.ivPreviewPic.setVisibility(View.INVISIBLE);
|
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 -> {
|
itemView.setOnClickListener(v -> {
|
||||||
if (notificationClickListener == null) return;
|
if (notificationClickListener == null) return;
|
||||||
notificationClickListener.onFeedStoryClick(model, position);
|
notificationClickListener.onFeedStoryClick(model, position);
|
||||||
|
@ -33,6 +33,8 @@ import awais.instagrabber.fragments.main.FeedFragment;
|
|||||||
import awais.instagrabber.fragments.settings.MorePreferencesFragmentDirections;
|
import awais.instagrabber.fragments.settings.MorePreferencesFragmentDirections;
|
||||||
import awais.instagrabber.models.FeedStoryModel;
|
import awais.instagrabber.models.FeedStoryModel;
|
||||||
import awais.instagrabber.models.HighlightModel;
|
import awais.instagrabber.models.HighlightModel;
|
||||||
|
import awais.instagrabber.utils.Constants;
|
||||||
|
import awais.instagrabber.utils.CookieUtils;
|
||||||
import awais.instagrabber.utils.TextUtils;
|
import awais.instagrabber.utils.TextUtils;
|
||||||
import awais.instagrabber.viewmodels.FeedStoriesViewModel;
|
import awais.instagrabber.viewmodels.FeedStoriesViewModel;
|
||||||
import awais.instagrabber.viewmodels.ArchivesViewModel;
|
import awais.instagrabber.viewmodels.ArchivesViewModel;
|
||||||
@ -40,13 +42,15 @@ import awais.instagrabber.webservices.ServiceCallback;
|
|||||||
import awais.instagrabber.webservices.StoriesService;
|
import awais.instagrabber.webservices.StoriesService;
|
||||||
import awais.instagrabber.webservices.StoriesService.ArchiveFetchResponse;
|
import awais.instagrabber.webservices.StoriesService.ArchiveFetchResponse;
|
||||||
|
|
||||||
|
import static awais.instagrabber.utils.Utils.settingsHelper;
|
||||||
|
|
||||||
public final class StoryListViewerFragment extends Fragment implements SwipeRefreshLayout.OnRefreshListener {
|
public final class StoryListViewerFragment extends Fragment implements SwipeRefreshLayout.OnRefreshListener {
|
||||||
private static final String TAG = "StoryListViewerFragment";
|
private static final String TAG = "StoryListViewerFragment";
|
||||||
|
|
||||||
private AppCompatActivity fragmentActivity;
|
private AppCompatActivity fragmentActivity;
|
||||||
private FragmentStoryListViewerBinding binding;
|
private FragmentStoryListViewerBinding binding;
|
||||||
private SwipeRefreshLayout root;
|
private SwipeRefreshLayout root;
|
||||||
private boolean shouldRefresh = true;
|
private boolean shouldRefresh = true, firstRefresh = true;
|
||||||
private FeedStoriesViewModel feedStoriesViewModel;
|
private FeedStoriesViewModel feedStoriesViewModel;
|
||||||
private ArchivesViewModel archivesViewModel;
|
private ArchivesViewModel archivesViewModel;
|
||||||
private StoriesService storiesService;
|
private StoriesService storiesService;
|
||||||
@ -174,9 +178,27 @@ public final class StoryListViewerFragment extends Fragment implements SwipeRefr
|
|||||||
@Override
|
@Override
|
||||||
public void onRefresh() {
|
public void onRefresh() {
|
||||||
binding.swipeRefreshLayout.setRefreshing(true);
|
binding.swipeRefreshLayout.setRefreshing(true);
|
||||||
if (type == "feed") {
|
if (type == "feed" && firstRefresh) {
|
||||||
binding.swipeRefreshLayout.setRefreshing(false);
|
binding.swipeRefreshLayout.setRefreshing(false);
|
||||||
feedStoriesViewModel.getList().postValue(FeedFragment.feedStories);
|
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") {
|
else if (type == "archive") {
|
||||||
storiesService.fetchArchive(endCursor, cb);
|
storiesService.fetchArchive(endCursor, cb);
|
||||||
|
@ -968,21 +968,22 @@ public class StoryViewerFragment extends Fragment {
|
|||||||
Toast.makeText(context, R.string.be_patient, Toast.LENGTH_SHORT).show();
|
Toast.makeText(context, R.string.be_patient, Toast.LENGTH_SHORT).show();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// if (settingsHelper.getBoolean(MARK_AS_SEEN)
|
if (settingsHelper.getBoolean(MARK_AS_SEEN)
|
||||||
// && oldFeedStory != null
|
&& oldFeedStory != null
|
||||||
// && oldFeedStory instanceof FeedStoryModel
|
&& oldFeedStory instanceof FeedStoryModel
|
||||||
// && viewModel instanceof FeedStoriesViewModel) {
|
&& viewModel instanceof FeedStoriesViewModel) {
|
||||||
// final FeedStoriesViewModel feedStoriesViewModel = (FeedStoriesViewModel) viewModel;
|
final FeedStoriesViewModel feedStoriesViewModel = (FeedStoriesViewModel) viewModel;
|
||||||
// final FeedStoryModel oldFeedStoryModel = (FeedStoryModel) oldFeedStory;
|
final FeedStoryModel oldFeedStoryModel = (FeedStoryModel) oldFeedStory;
|
||||||
// if (oldFeedStoryModel.isFullyRead()) {
|
if (!oldFeedStoryModel.isFullyRead()) {
|
||||||
// oldFeedStoryModel.setFullyRead(false);
|
oldFeedStoryModel.setFullyRead(true);
|
||||||
// final List<FeedStoryModel> models = feedStoriesViewModel.getList().getValue();
|
final List<FeedStoryModel> models = feedStoriesViewModel.getList().getValue();
|
||||||
// final List<FeedStoryModel> modelsCopy = models == null ? new ArrayList<>() : new ArrayList<>(models);
|
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());
|
Log.d("austin_debug", oldFeedStoryModel.getProfileModel().getUsername() + ", v " + models.get(currentFeedStoryIndex).isFullyRead() + " l " + oldFeedStoryModel.isFullyRead());
|
||||||
// modelsCopy.set(currentFeedStoryIndex, oldFeedStoryModel);
|
modelsCopy.set(currentFeedStoryIndex, oldFeedStoryModel);
|
||||||
// feedStoriesViewModel.getList().setValue(models);
|
FeedFragment.feedStories = modelsCopy;
|
||||||
// }
|
feedStoriesViewModel.getList().setValue(models);
|
||||||
// }
|
}
|
||||||
|
}
|
||||||
fetching = true;
|
fetching = true;
|
||||||
binding.btnBackward.setVisibility(currentFeedStoryIndex == 1 && backward ? View.INVISIBLE : View.VISIBLE);
|
binding.btnBackward.setVisibility(currentFeedStoryIndex == 1 && backward ? View.INVISIBLE : View.VISIBLE);
|
||||||
binding.btnForward.setVisibility(last ? 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.setLayoutManager(new LinearLayoutManager(context, RecyclerView.HORIZONTAL, false));
|
||||||
storiesRecyclerView.setAdapter(feedStoriesAdapter);
|
storiesRecyclerView.setAdapter(feedStoriesAdapter);
|
||||||
fragmentActivity.setCollapsingView(storiesRecyclerView);
|
fragmentActivity.setCollapsingView(storiesRecyclerView);
|
||||||
feedStoriesViewModel.getList().observe(fragmentActivity, list -> {
|
feedStoriesViewModel.getList().observe(getViewLifecycleOwner(), feedStoriesAdapter::submitList);
|
||||||
Log.d("austin_debug", "observed");
|
|
||||||
feedStoriesAdapter.submitList(list);
|
|
||||||
});
|
|
||||||
fetchStories();
|
fetchStories();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user