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 home dining prefs #597

Merged
merged 16 commits into from
Jan 26, 2024
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Synchronous BlurView loading. Mildly scuffed sometimes?
meiron03 committed Jan 4, 2024
commit 9917e5788a42fe0b4704e7d516f83d318483be89
Original file line number Diff line number Diff line change
@@ -7,6 +7,7 @@ import android.content.Intent
import android.content.IntentFilter
import android.os.Bundle
import android.os.Handler
import android.util.Log
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
@@ -88,6 +89,12 @@ class HomeFragment : Fragment() {
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
getHomePage()
homepageViewModel.blurViewsLoaded.observe(viewLifecycleOwner) { loaded ->
if (loaded) {
binding.homeCellsRv.visibility = View.VISIBLE
loadingPanel?.visibility = View.GONE
}
}
}

private fun getOnline() : Boolean {
@@ -150,7 +157,7 @@ class HomeFragment : Fragment() {
homepageViewModel.populateHomePageCells(studentLife, bearerToken, deviceID) {
mActivity.runOnUiThread {
binding.homeCellsRv.adapter = HomeAdapter2(homepageViewModel)
loadingPanel?.visibility = View.GONE
binding.homeCellsRv.visibility = View.INVISIBLE
binding.internetConnectionHome.visibility = View.GONE
binding.homeRefreshLayout.isRefreshing = false
}
Original file line number Diff line number Diff line change
@@ -245,6 +245,7 @@ class HomeAdapter2(private val dataModel: HomepageDataModel) :
holder.itemView.blurView
.setOverlayColor(ColorUtils.setAlphaComponent(accentColor, 150))

dataModel.notifyNewsBlurLoaded()
}


@@ -368,7 +369,6 @@ class HomeAdapter2(private val dataModel: HomepageDataModel) :
holder.itemView.home_card_rv.adapter = HomeGsrBuildingAdapter(ArrayList(buildings))
}

@OptIn(DelicateCoroutinesApi::class)
private fun bindPostCell(holder: ViewHolder, cell: HomeCell) {
val info = cell.info
val post = cell.info?.post
@@ -407,6 +407,7 @@ class HomeAdapter2(private val dataModel: HomepageDataModel) :
holder.itemView.post_card_container.background = bitmapDrawable
holder.itemView.postBlurView
.setOverlayColor(ColorUtils.setAlphaComponent(accentColor, 150))
dataModel.notifyPostBlurLoaded()
}
}
/** Sets up blur view on post card */
Original file line number Diff line number Diff line change
@@ -3,4 +3,6 @@ package com.pennapps.labs.pennmobile.classes
interface HomepageDataModel {
fun getSize() : Int
fun getCell(position: Int) : HomeCell
fun notifyPostBlurLoaded()
fun notifyNewsBlurLoaded()
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package com.pennapps.labs.pennmobile.classes

import android.util.Log
import androidx.lifecycle.LiveData
import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.ViewModel
import com.pennapps.labs.pennmobile.api.StudentLife
import com.pennapps.labs.pennmobile.utils.Utils.getSha256Hash
@@ -23,13 +26,20 @@ class HomepageViewModel : HomepageDataModel, ViewModel() {

private val homepageCells = mutableListOf<HomeCell>()
private val cellMutex = Mutex()
private val _blurViewsLoaded = MutableLiveData<Boolean>(false)
val blurViewsLoaded: LiveData<Boolean>
get() = _blurViewsLoaded

private var postBlurViewLoaded = false
private var newsBlurViewLoaded = false
private val postBlurMutex = Mutex()
private val newsBlurMutex = Mutex()

init {
for (i in 1..NUM_CELLS) {
homepageCells.add(HomeCell())
}
}

@Synchronized
fun updateHomePageCells(studentLife: StudentLife, bearerToken: String, deviceID: String,
update: (Int) -> Unit, callback: () -> Unit) {
@@ -147,6 +157,8 @@ class HomepageViewModel : HomepageDataModel, ViewModel() {
postCell.info?.post = post[0]

addCell(postCell, POST_POS)
} else {
setPostBlurView(true)
}

latch.countDown()
@@ -185,6 +197,41 @@ class HomepageViewModel : HomepageDataModel, ViewModel() {
})
}

private fun setPostBlurView(status: Boolean) = runBlocking {
postBlurMutex.withLock {
postBlurViewLoaded = status
}
updateBlurViewStatus()
}
private fun setNewsBlurView(status: Boolean) = runBlocking {
newsBlurMutex.withLock {
newsBlurViewLoaded = status
}
updateBlurViewStatus()
}
private fun updateBlurViewStatus() = runBlocking {
postBlurMutex.lock()
newsBlurMutex.lock()
Log.i("HomeBlurViewLoadStatus", "Called updateBlurViewStatus")
Log.i("HomeBlurViewLoadStatus", "News: $newsBlurViewLoaded")
Log.i("HomeBlurViewLoadStatus", "Posts: $postBlurViewLoaded")
if (newsBlurViewLoaded && postBlurViewLoaded) {
_blurViewsLoaded.postValue(true)
} else {
_blurViewsLoaded.postValue(false)
}
postBlurMutex.unlock()
newsBlurMutex.unlock()
}

override fun notifyPostBlurLoaded() {
setPostBlurView(true)
}

override fun notifyNewsBlurLoaded() {
setNewsBlurView(true)
}

override fun getSize(): Int {
return homepageCells.size
}