Browse Source

fix observer delegations

renovate/androidx.fragment-fragment-ktx-1.x
Austin Huang 4 years ago
parent
commit
d106ac5c0a
No known key found for this signature in database GPG Key ID: 84C23AA04587A91F
  1. 16
      app/src/main/java/awais/instagrabber/fragments/StoryViewerFragment.kt
  2. 10
      app/src/main/java/awais/instagrabber/fragments/main/FeedFragment.java

16
app/src/main/java/awais/instagrabber/fragments/StoryViewerFragment.kt

@ -213,7 +213,7 @@ class StoryViewerFragment : Fragment() {
storiesViewModel.setMedia(position)
}
binding.storiesList.adapter = storiesAdapter
storiesViewModel.getCurrentStory().observe(viewLifecycleOwner, {
storiesViewModel.getCurrentStory().observe(fragmentActivity, {
if (it?.items != null && it.items.size > 1) {
val storyMedias = it.items.toMutableList()
val newItem = storyMedias.get(0)
@ -231,19 +231,19 @@ class StoryViewerFragment : Fragment() {
binding.storiesList.visibility = View.GONE
}
})
storiesViewModel.getDate().observe(viewLifecycleOwner, {
storiesViewModel.getDate().observe(fragmentActivity, {
val actionBar = fragmentActivity.supportActionBar
if (actionBar != null && it != null) actionBar.subtitle = it
})
storiesViewModel.getTitle().observe(viewLifecycleOwner, {
storiesViewModel.getTitle().observe(fragmentActivity, {
val actionBar = fragmentActivity.supportActionBar
if (actionBar != null && it != null) actionBar.title = it
})
storiesViewModel.getCurrentMedia().observe(viewLifecycleOwner, { refreshStory(it) })
storiesViewModel.getCurrentIndex().observe(viewLifecycleOwner, {
storiesViewModel.getCurrentMedia().observe(fragmentActivity, { refreshStory(it) })
storiesViewModel.getCurrentIndex().observe(fragmentActivity, {
storiesAdapter!!.paginate(it)
})
storiesViewModel.getOptions().observe(viewLifecycleOwner, {
storiesViewModel.getOptions().observe(fragmentActivity, {
binding.stickers.isEnabled = it.first.size > 0
})
}
@ -268,7 +268,7 @@ class StoryViewerFragment : Fragment() {
when (type) {
StoryViewerOptions.Type.HIGHLIGHT -> {
storiesViewModel.fetchHighlights(options!!.id)
storiesViewModel.highlights.observe(viewLifecycleOwner) {
storiesViewModel.highlights.observe(fragmentActivity) {
setupMultipage(it)
}
}
@ -319,7 +319,7 @@ class StoryViewerFragment : Fragment() {
private fun setupMultipage(models: List<Story>?) {
if (models == null) return
storiesViewModel.getPagination().observe(viewLifecycleOwner, {
storiesViewModel.getPagination().observe(fragmentActivity, {
when (it) {
StoryPaginationType.FORWARD -> {
if (currentFeedStoryIndex == models.size - 1)

10
app/src/main/java/awais/instagrabber/fragments/main/FeedFragment.java

@ -319,14 +319,6 @@ public class FeedFragment extends Fragment implements SwipeRefreshLayout.OnRefre
return super.onOptionsItemSelected(item);
}
@Override
public void onResume() {
super.onResume();
// temporary fix
feedStoriesViewModel.getList().removeObservers(getViewLifecycleOwner());
feedStoriesViewModel.getList().observe(getViewLifecycleOwner(), feedStoriesAdapter::submitList);
}
@Override
public void onRefresh() {
binding.feedRecyclerView.refresh();
@ -382,7 +374,7 @@ public class FeedFragment extends Fragment implements SwipeRefreshLayout.OnRefre
storiesRecyclerView = binding.header;
storiesRecyclerView.setLayoutManager(new LinearLayoutManager(context, RecyclerView.HORIZONTAL, false));
storiesRecyclerView.setAdapter(feedStoriesAdapter);
feedStoriesViewModel.getList().observe(getViewLifecycleOwner(), feedStoriesAdapter::submitList);
feedStoriesViewModel.getList().observe(fragmentActivity, feedStoriesAdapter::submitList);
fetchStories();
}

Loading…
Cancel
Save