Skip to content
Open
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 @@ -50,13 +50,17 @@ import org.ole.planet.myplanet.ui.team.TeamDetailFragment
import org.ole.planet.myplanet.ui.userprofile.BecomeMemberActivity
import org.ole.planet.myplanet.ui.userprofile.UserProfileFragment
import org.ole.planet.myplanet.utilities.Constants
import androidx.fragment.app.viewModels
import dagger.hilt.android.AndroidEntryPoint
import org.ole.planet.myplanet.utilities.DialogUtils
import org.ole.planet.myplanet.utilities.DownloadUtils
import org.ole.planet.myplanet.utilities.FileUtils
import org.ole.planet.myplanet.utilities.Utilities

@AndroidEntryPoint
open class BaseDashboardFragment : BaseDashboardFragmentPlugin(), NotificationCallback,
SyncListener {
private val dashboardViewModel: DashboardViewModel by viewModels()
private var fullName: String? = null
private var params = LinearLayout.LayoutParams(250, 100)
private var di: DialogUtils.CustomProgressDialog? = null
Expand Down Expand Up @@ -139,14 +143,7 @@ open class BaseDashboardFragment : BaseDashboardFragmentPlugin(), NotificationCa
}
}

private suspend fun myLibraryDiv(view: View) {
val dbMylibrary = withContext(Dispatchers.IO) {
Realm.getDefaultInstance().use { realm ->
val results = RealmMyLibrary.getMyLibraryByUserId(realm, settings)
realm.copyFromRealm(results)
}
}

private fun myLibraryDiv(view: View, dbMylibrary: List<RealmMyLibrary>) {
view.findViewById<FlexboxLayout>(R.id.flexboxLayout).flexDirection = FlexDirection.ROW
if (dbMylibrary.isEmpty()) {
view.findViewById<TextView>(R.id.count_library).visibility = View.GONE
Expand Down Expand Up @@ -336,7 +333,8 @@ open class BaseDashboardFragment : BaseDashboardFragmentPlugin(), NotificationCa
homeItemClickListener?.openCallFragment(UserProfileFragment())
}
viewLifecycleOwner.lifecycleScope.launch {
myLibraryDiv(view)
val dbMylibrary = dashboardViewModel.getMyLibraryItems(settings.getString("userId", "--"))
myLibraryDiv(view, dbMylibrary)
}
initializeFlexBoxView(view, R.id.flexboxLayoutCourse, RealmMyCourse::class.java)
initializeFlexBoxView(view, R.id.flexboxLayoutTeams, RealmMyTeam::class.java)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.flow.asStateFlow
import org.ole.planet.myplanet.model.RealmSubmission
import org.ole.planet.myplanet.model.RealmMyLibrary
import org.ole.planet.myplanet.repository.CourseRepository
import org.ole.planet.myplanet.repository.LibraryRepository
import org.ole.planet.myplanet.repository.NotificationRepository
Expand Down Expand Up @@ -65,4 +66,8 @@ class DashboardViewModel @Inject constructor(
suspend fun getUnreadNotificationsSize(userId: String?): Int {
return notificationRepository.getUnreadCount(userId)
}

suspend fun getMyLibraryItems(userId: String?): List<RealmMyLibrary> {
return libraryRepository.getLibraryListForUser(userId)
Comment on lines 66 to +71

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Avoid narrowing "My Library" query

The new getMyLibraryItems delegates to LibraryRepository.getLibraryListForUser, which filters results to non‑private items that needToUpdate() and does not merge team resources. The previous fragment code called RealmMyLibrary.getMyLibraryByUserId, which returned all items the user owns or receives through team membership regardless of update status. As a result, the dashboard’s “My Library” section will now omit any up‑to‑date or team‑shared resources and show only those needing updates, changing the visible data set rather than just moving the query off the main thread.

Useful? React with 👍 / 👎.

}
}