still can't fix the sync issue
This commit is contained in:
parent
81ac6ee2bd
commit
22d327e166
@ -52,43 +52,6 @@ public final class FeedStoriesAdapter extends ListAdapter<FeedStoryModel, FeedSt
|
||||
holder.bind(model, position, listener);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void submitList(@Nullable final List<FeedStoryModel> list, @Nullable final Runnable commitCallback) {
|
||||
if (list == null) {
|
||||
super.submitList(null, commitCallback);
|
||||
return;
|
||||
}
|
||||
super.submitList(sort(list), commitCallback);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void submitList(@Nullable final List<FeedStoryModel> list) {
|
||||
if (list == null) {
|
||||
super.submitList(null);
|
||||
return;
|
||||
}
|
||||
super.submitList(sort(list));
|
||||
}
|
||||
|
||||
private List<FeedStoryModel> sort(final List<FeedStoryModel> list) {
|
||||
final List<FeedStoryModel> listCopy = new ArrayList<>(list);
|
||||
Collections.sort(listCopy, (o1, o2) -> {
|
||||
int result;
|
||||
switch (Utils.settingsHelper.getString(Constants.STORY_SORT)) {
|
||||
case "1":
|
||||
result = o1.getTimestamp() > o2.getTimestamp() ? -1 : (o1.getTimestamp() == o2.getTimestamp() ? 0 : 1);
|
||||
break;
|
||||
case "2":
|
||||
result = o1.getTimestamp() > o2.getTimestamp() ? 1 : (o1.getTimestamp() == o2.getTimestamp() ? 0 : -1);
|
||||
break;
|
||||
default:
|
||||
result = 0;
|
||||
}
|
||||
return result;
|
||||
});
|
||||
return listCopy;
|
||||
}
|
||||
|
||||
public interface OnFeedStoryClickListener {
|
||||
void onFeedStoryClick(FeedStoryModel model, int position);
|
||||
|
||||
|
@ -57,6 +57,7 @@ public final class StoryListViewerFragment extends Fragment implements SwipeRefr
|
||||
private Context context;
|
||||
private String type, endCursor = null;
|
||||
private RecyclerLazyLoader lazyLoader;
|
||||
private FeedStoriesListAdapter adapter;
|
||||
|
||||
private final OnFeedStoryClickListener clickListener = new OnFeedStoryClickListener() {
|
||||
@Override
|
||||
@ -153,8 +154,8 @@ public final class StoryListViewerFragment extends Fragment implements SwipeRefr
|
||||
final ActionBar actionBar = fragmentActivity.getSupportActionBar();
|
||||
if (type == "feed") {
|
||||
if (actionBar != null) actionBar.setTitle(R.string.feed_stories);
|
||||
feedStoriesViewModel = new ViewModelProvider(this).get(FeedStoriesViewModel.class);
|
||||
final FeedStoriesListAdapter adapter = new FeedStoriesListAdapter(clickListener);
|
||||
feedStoriesViewModel = new ViewModelProvider(fragmentActivity).get(FeedStoriesViewModel.class);
|
||||
adapter = new FeedStoriesListAdapter(clickListener);
|
||||
binding.rvStories.setLayoutManager(layoutManager);
|
||||
binding.rvStories.setAdapter(adapter);
|
||||
feedStoriesViewModel.getList().observe(getViewLifecycleOwner(), adapter::submitList);
|
||||
@ -180,7 +181,7 @@ public final class StoryListViewerFragment extends Fragment implements SwipeRefr
|
||||
binding.swipeRefreshLayout.setRefreshing(true);
|
||||
if (type == "feed" && firstRefresh) {
|
||||
binding.swipeRefreshLayout.setRefreshing(false);
|
||||
feedStoriesViewModel.getList().postValue(FeedFragment.feedStories);
|
||||
adapter.submitList(feedStoriesViewModel.getList().getValue());
|
||||
firstRefresh = false;
|
||||
}
|
||||
else if (type == "feed") {
|
||||
@ -189,7 +190,6 @@ public final class StoryListViewerFragment extends Fragment implements SwipeRefr
|
||||
@Override
|
||||
public void onSuccess(final List<FeedStoryModel> result) {
|
||||
feedStoriesViewModel.getList().postValue(result);
|
||||
FeedFragment.feedStories = result;
|
||||
binding.swipeRefreshLayout.setRefreshing(false);
|
||||
}
|
||||
|
||||
|
@ -978,10 +978,8 @@ public class StoryViewerFragment extends Fragment {
|
||||
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);
|
||||
feedStoriesViewModel.getList().postValue(models);
|
||||
}
|
||||
}
|
||||
fetching = true;
|
||||
|
@ -79,8 +79,6 @@ public class FeedFragment extends Fragment implements SwipeRefreshLayout.OnRefre
|
||||
private RecyclerView storiesRecyclerView;
|
||||
private MenuItem storyListMenu;
|
||||
|
||||
public static List<FeedStoryModel> feedStories;
|
||||
|
||||
private final FeedAdapterV2.FeedItemCallback feedItemCallback = new FeedAdapterV2.FeedItemCallback() {
|
||||
@Override
|
||||
public void onPostClick(final FeedModel feedModel, final View profilePicView, final View mainPostImage) {
|
||||
@ -295,15 +293,6 @@ public class FeedFragment extends Fragment implements SwipeRefreshLayout.OnRefre
|
||||
return super.onOptionsItemSelected(item);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResume() {
|
||||
super.onResume();
|
||||
updateSwipeRefreshState();
|
||||
// if (videoAwareRecyclerScroller != null && shouldAutoPlay) {
|
||||
// videoAwareRecyclerScroller.startPlaying();
|
||||
// }
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRefresh() {
|
||||
binding.feedRecyclerView.refresh();
|
||||
@ -401,7 +390,6 @@ public class FeedFragment extends Fragment implements SwipeRefreshLayout.OnRefre
|
||||
@Override
|
||||
public void onSuccess(final List<FeedStoryModel> result) {
|
||||
feedStoriesViewModel.getList().postValue(result);
|
||||
feedStories = result;
|
||||
storiesFetching = false;
|
||||
if (storyListMenu != null) storyListMenu.setVisible(true);
|
||||
updateSwipeRefreshState();
|
||||
|
@ -126,7 +126,6 @@ public class StoriesService extends BaseService {
|
||||
if (itemJson != null) {
|
||||
firstStoryModel = ResponseBodyUtils.parseStoryItem(itemJson, false, false, null);
|
||||
}
|
||||
else Log.d("austin_debug", "node: "+node);
|
||||
feedStoryModels.add(new FeedStoryModel(id, profileModel, fullyRead, timestamp, firstStoryModel, mediaCount));
|
||||
}
|
||||
callback.onSuccess(sort(feedStoryModels));
|
||||
|
Loading…
Reference in New Issue
Block a user