Browse Source

story list optimization

renovate/org.robolectric-robolectric-4.x
Austin Huang 4 years ago
parent
commit
f955a81599
No known key found for this signature in database GPG Key ID: 84C23AA04587A91F
  1. 8
      app/src/main/java/awais/instagrabber/adapters/viewholder/StoryListViewHolder.java
  2. 26
      app/src/main/java/awais/instagrabber/fragments/StoryListViewerFragment.java
  3. 31
      app/src/main/java/awais/instagrabber/fragments/StoryViewerFragment.java
  4. 5
      app/src/main/java/awais/instagrabber/fragments/main/FeedFragment.java

8
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);

26
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<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);

31
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<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);

5
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();
}

Loading…
Cancel
Save