Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: #26 #30

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import com.codingwithmitch.openapi.business.domain.models.BlogPost
import com.codingwithmitch.openapi.business.domain.util.*
import com.codingwithmitch.openapi.databinding.FragmentBlogBinding
import com.codingwithmitch.openapi.presentation.main.blog.BaseBlogFragment
import com.codingwithmitch.openapi.presentation.main.blog.detail.SHOULD_REFRESH
import com.codingwithmitch.openapi.presentation.util.TopSpacingItemDecoration
import com.codingwithmitch.openapi.presentation.util.processQueue
import kotlinx.coroutines.*
Expand Down Expand Up @@ -60,6 +61,16 @@ class BlogFragment : BaseBlogFragment(),
(activity as AppCompatActivity).supportActionBar?.setDisplayShowTitleEnabled(false)
setHasOptionsMenu(true)
binding.swipeRefresh.setOnRefreshListener(this)

// If an update occurred from UpdateBlogFragment, refresh the Blog
findNavController().currentBackStackEntry?.savedStateHandle?.getLiveData<Boolean>(SHOULD_REFRESH)
?.observe(viewLifecycleOwner) { shouldRefresh ->
shouldRefresh?.run {
viewModel.onTriggerEvent(BlogEvents.GetOrderAndFilter)
findNavController().currentBackStackEntry?.savedStateHandle?.set(SHOULD_REFRESH, null)
}
}

initRecyclerView()
subscribeObservers()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import com.canhub.cropper.CropImageView
import com.codingwithmitch.openapi.R
import com.codingwithmitch.openapi.business.domain.util.*
import com.codingwithmitch.openapi.databinding.FragmentCreateBlogBinding
import com.codingwithmitch.openapi.presentation.main.blog.detail.SHOULD_REFRESH
import com.codingwithmitch.openapi.presentation.util.processQueue

class CreateBlogFragment : BaseCreateBlogFragment() {
Expand Down Expand Up @@ -96,6 +97,7 @@ class CreateBlogFragment : BaseCreateBlogFragment() {
uri = state.uri,
)
if (state.onPublishSuccess) {
findNavController().previousBackStackEntry?.savedStateHandle?.set(SHOULD_REFRESH, true)
findNavController().popBackStack(R.id.blogFragment, false)
}
})
Expand Down