1
0
mirror of https://github.com/KokaKiwi/BarInsta synced 2024-11-22 22:57:29 +00:00

still can't fix the sync issue

This commit is contained in:
Austin Huang 2020-12-31 14:07:32 -05:00
parent 81ac6ee2bd
commit 22d327e166
No known key found for this signature in database
GPG Key ID: 84C23AA04587A91F
5 changed files with 5 additions and 57 deletions

View File

@ -52,43 +52,6 @@ public final class FeedStoriesAdapter extends ListAdapter<FeedStoryModel, FeedSt
holder.bind(model, position, listener); 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 { public interface OnFeedStoryClickListener {
void onFeedStoryClick(FeedStoryModel model, int position); void onFeedStoryClick(FeedStoryModel model, int position);

View File

@ -57,6 +57,7 @@ public final class StoryListViewerFragment extends Fragment implements SwipeRefr
private Context context; private Context context;
private String type, endCursor = null; private String type, endCursor = null;
private RecyclerLazyLoader lazyLoader; private RecyclerLazyLoader lazyLoader;
private FeedStoriesListAdapter adapter;
private final OnFeedStoryClickListener clickListener = new OnFeedStoryClickListener() { private final OnFeedStoryClickListener clickListener = new OnFeedStoryClickListener() {
@Override @Override
@ -153,8 +154,8 @@ public final class StoryListViewerFragment extends Fragment implements SwipeRefr
final ActionBar actionBar = fragmentActivity.getSupportActionBar(); final ActionBar actionBar = fragmentActivity.getSupportActionBar();
if (type == "feed") { if (type == "feed") {
if (actionBar != null) actionBar.setTitle(R.string.feed_stories); if (actionBar != null) actionBar.setTitle(R.string.feed_stories);
feedStoriesViewModel = new ViewModelProvider(this).get(FeedStoriesViewModel.class); feedStoriesViewModel = new ViewModelProvider(fragmentActivity).get(FeedStoriesViewModel.class);
final FeedStoriesListAdapter adapter = new FeedStoriesListAdapter(clickListener); adapter = new FeedStoriesListAdapter(clickListener);
binding.rvStories.setLayoutManager(layoutManager); binding.rvStories.setLayoutManager(layoutManager);
binding.rvStories.setAdapter(adapter); binding.rvStories.setAdapter(adapter);
feedStoriesViewModel.getList().observe(getViewLifecycleOwner(), adapter::submitList); feedStoriesViewModel.getList().observe(getViewLifecycleOwner(), adapter::submitList);
@ -180,7 +181,7 @@ public final class StoryListViewerFragment extends Fragment implements SwipeRefr
binding.swipeRefreshLayout.setRefreshing(true); binding.swipeRefreshLayout.setRefreshing(true);
if (type == "feed" && firstRefresh) { if (type == "feed" && firstRefresh) {
binding.swipeRefreshLayout.setRefreshing(false); binding.swipeRefreshLayout.setRefreshing(false);
feedStoriesViewModel.getList().postValue(FeedFragment.feedStories); adapter.submitList(feedStoriesViewModel.getList().getValue());
firstRefresh = false; firstRefresh = false;
} }
else if (type == "feed") { else if (type == "feed") {
@ -189,7 +190,6 @@ public final class StoryListViewerFragment extends Fragment implements SwipeRefr
@Override @Override
public void onSuccess(final List<FeedStoryModel> result) { public void onSuccess(final List<FeedStoryModel> result) {
feedStoriesViewModel.getList().postValue(result); feedStoriesViewModel.getList().postValue(result);
FeedFragment.feedStories = result;
binding.swipeRefreshLayout.setRefreshing(false); binding.swipeRefreshLayout.setRefreshing(false);
} }

View File

@ -978,10 +978,8 @@ public class StoryViewerFragment extends Fragment {
oldFeedStoryModel.setFullyRead(true); 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());
modelsCopy.set(currentFeedStoryIndex, oldFeedStoryModel); modelsCopy.set(currentFeedStoryIndex, oldFeedStoryModel);
FeedFragment.feedStories = modelsCopy; feedStoriesViewModel.getList().postValue(models);
feedStoriesViewModel.getList().setValue(models);
} }
} }
fetching = true; fetching = true;

View File

@ -79,8 +79,6 @@ public class FeedFragment extends Fragment implements SwipeRefreshLayout.OnRefre
private RecyclerView storiesRecyclerView; private RecyclerView storiesRecyclerView;
private MenuItem storyListMenu; private MenuItem storyListMenu;
public static List<FeedStoryModel> feedStories;
private final FeedAdapterV2.FeedItemCallback feedItemCallback = new FeedAdapterV2.FeedItemCallback() { private final FeedAdapterV2.FeedItemCallback feedItemCallback = new FeedAdapterV2.FeedItemCallback() {
@Override @Override
public void onPostClick(final FeedModel feedModel, final View profilePicView, final View mainPostImage) { 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); return super.onOptionsItemSelected(item);
} }
@Override
public void onResume() {
super.onResume();
updateSwipeRefreshState();
// if (videoAwareRecyclerScroller != null && shouldAutoPlay) {
// videoAwareRecyclerScroller.startPlaying();
// }
}
@Override @Override
public void onRefresh() { public void onRefresh() {
binding.feedRecyclerView.refresh(); binding.feedRecyclerView.refresh();
@ -401,7 +390,6 @@ public class FeedFragment extends Fragment implements SwipeRefreshLayout.OnRefre
@Override @Override
public void onSuccess(final List<FeedStoryModel> result) { public void onSuccess(final List<FeedStoryModel> result) {
feedStoriesViewModel.getList().postValue(result); feedStoriesViewModel.getList().postValue(result);
feedStories = result;
storiesFetching = false; storiesFetching = false;
if (storyListMenu != null) storyListMenu.setVisible(true); if (storyListMenu != null) storyListMenu.setVisible(true);
updateSwipeRefreshState(); updateSwipeRefreshState();

View File

@ -126,7 +126,6 @@ public class StoriesService extends BaseService {
if (itemJson != null) { if (itemJson != null) {
firstStoryModel = ResponseBodyUtils.parseStoryItem(itemJson, false, false, 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)); feedStoryModels.add(new FeedStoryModel(id, profileModel, fullyRead, timestamp, firstStoryModel, mediaCount));
} }
callback.onSuccess(sort(feedStoryModels)); callback.onSuccess(sort(feedStoryModels));