Skip to content

Commit

Permalink
dashboard: smoother visits sync (fixes #3511) (#3515)
Browse files Browse the repository at this point in the history
Co-authored-by: dogi <[email protected]>
  • Loading branch information
Okuro3499 and dogi authored May 28, 2024
1 parent fe1e36e commit 91f40ea
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ android {
applicationId "org.ole.planet.myplanet"
minSdkVersion 21
targetSdkVersion 34
versionCode 1545
versionName "0.15.45"
versionCode 1546
versionName "0.15.46"
ndkVersion '21.3.6528147'
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
vectorDrawables.useSupportLibrary = true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,13 @@ import org.ole.planet.myplanet.model.RealmMyLibrary
import org.ole.planet.myplanet.model.RealmMyLife
import org.ole.planet.myplanet.model.RealmMyTeam
import org.ole.planet.myplanet.model.RealmNews
import org.ole.planet.myplanet.model.RealmOfflineActivity
import org.ole.planet.myplanet.model.RealmTeamNotification
import org.ole.planet.myplanet.model.RealmTeamTask
import org.ole.planet.myplanet.model.RealmUserModel
import org.ole.planet.myplanet.service.TransactionSyncManager
import org.ole.planet.myplanet.service.UserProfileDbHandler
import org.ole.planet.myplanet.service.UserProfileDbHandler.Companion.KEY_LOGIN
import org.ole.planet.myplanet.ui.dashboard.notification.NotificationFragment
import org.ole.planet.myplanet.ui.exam.UserInformationFragment
import org.ole.planet.myplanet.ui.myhealth.UserListArrayAdapter
Expand Down Expand Up @@ -62,6 +64,11 @@ open class BaseDashboardFragment : BaseDashboardFragmentPlugin(), NotificationCa
private val myTeamsChangeListener = RealmChangeListener<RealmResults<RealmMyTeam>> { results ->
updateMyTeamsUI()
}
private lateinit var offlineActivitiesResults: RealmResults<RealmOfflineActivity>
private val offlineActivitiesChangeListener = RealmChangeListener<RealmResults<RealmOfflineActivity>> { results ->
updateOfflineVisitsUI()
}


fun onLoaded(v: View) {
profileDbHandler = UserProfileDbHandler(requireContext())
Expand Down Expand Up @@ -90,11 +97,21 @@ open class BaseDashboardFragment : BaseDashboardFragmentPlugin(), NotificationCa
imageView.setImageResource(R.drawable.profile)
}

v.findViewById<TextView>(R.id.txtVisits).text = "${profileDbHandler.offlineVisits} ${getString(R.string.visits)}"
offlineActivitiesResults = mRealm.where(RealmOfflineActivity::class.java)
.equalTo("userName", profileDbHandler.userModel?.name)
.equalTo("type", KEY_LOGIN)
.findAllAsync()
offlineActivitiesResults.addChangeListener(offlineActivitiesChangeListener)
updateOfflineVisitsUI()
v.findViewById<TextView>(R.id.txtRole).text = "- ${model.getRoleAsString()}"
v.findViewById<TextView>(R.id.txtFullName).text = fullName
}

private fun updateOfflineVisitsUI() {
val offlineVisits = profileDbHandler.offlineVisits
view?.findViewById<TextView>(R.id.txtVisits)?.text = "$offlineVisits ${getString(R.string.visits)}"
}

override fun forceDownloadNewsImages() {
mRealm = DatabaseService(requireContext()).realmInstance
Utilities.toast(activity, getString(R.string.please_select_starting_date))
Expand Down Expand Up @@ -274,6 +291,7 @@ open class BaseDashboardFragment : BaseDashboardFragmentPlugin(), NotificationCa
profileDbHandler.onDestory()
myCoursesResults.removeChangeListener(myCoursesChangeListener)
myTeamsResults.removeChangeListener(myTeamsChangeListener)
offlineActivitiesResults.removeChangeListener(offlineActivitiesChangeListener)
mRealm.close()
}

Expand Down

0 comments on commit 91f40ea

Please sign in to comment.