Skip to content

Commit

Permalink
Buf fixes for corner cases (e.g., no internet, request fails)
Browse files Browse the repository at this point in the history
  • Loading branch information
meiron03 committed Jan 5, 2024
1 parent 9f4f485 commit 516ba2f
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ class HomeFragment : Fragment() {
private fun refreshHomePage() {
mActivity.showBottomBar()


if (!getOnline()) {
return
}
Expand All @@ -128,18 +129,30 @@ class HomeFragment : Fragment() {
val bearerToken = "Bearer " + sp.getString(getString(R.string.access_token), "").toString()

lifecycleScope.launch(Dispatchers.Default) {
homepageViewModel.updateHomePageCells(studentLife, bearerToken, deviceID, { pos ->
mActivity.runOnUiThread {
binding.homeCellsRv.adapter!!.notifyItemChanged(pos)
}
}, {
mActivity.runOnUiThread {
binding.homeRefreshLayout.isRefreshing = false
}
})
if (binding.homeCellsRv.adapter == null) {
homepageViewModel.populateHomePageCells(studentLife, bearerToken, deviceID) {
mActivity.runOnUiThread {
binding.homeCellsRv.adapter = HomeAdapter2(homepageViewModel)
binding.homeCellsRv.visibility = View.INVISIBLE
binding.internetConnectionHome.visibility = View.GONE
binding.homeRefreshLayout.isRefreshing = false
}
}
} else {
homepageViewModel.updateHomePageCells(studentLife, bearerToken, deviceID, { pos ->
mActivity.runOnUiThread {
binding.homeCellsRv.adapter!!.notifyItemChanged(pos)
}
}, {
mActivity.runOnUiThread {
binding.homeRefreshLayout.isRefreshing = false
}
})
}
}
}
}

private fun getHomePage() {
mActivity.showBottomBar()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ class HomepageViewModel : HomepageDataModel, ViewModel() {
fun resetBlurViews() {
setPostBlurView(false)
setNewsBlurView(false)
updateBlurViewStatus()
}

@Synchronized
Expand Down Expand Up @@ -119,6 +120,7 @@ class HomepageViewModel : HomepageDataModel, ViewModel() {
addCell(newsCell2, NEWS_POS)
latch.countDown()
}, { throwable ->

throwable.printStackTrace()
latch.countDown()
})
Expand Down Expand Up @@ -158,6 +160,7 @@ class HomepageViewModel : HomepageDataModel, ViewModel() {
addCell(laundryCell2, LAUNDRY_POS)
latch.countDown()
}, { throwable ->
setNewsBlurView(true)
throwable.printStackTrace()
latch.countDown()
})
Expand All @@ -182,6 +185,7 @@ class HomepageViewModel : HomepageDataModel, ViewModel() {
latch.countDown()

}, { throwable ->
setPostBlurView(true)
throwable.printStackTrace()
latch.countDown()
})
Expand Down

0 comments on commit 516ba2f

Please sign in to comment.