Skip to content

Commit f2f26e2

Browse files
feat(dashboard): Optimize DashboardActivity startup
- Moved non-critical initializations from onCreate to onStart. - Introduced postponeEnterTransition() and reportFullyDrawn() for faster UI rendering. - Batched heavy tasks into a background coroutine to prevent blocking the main thread.
1 parent 83a17ba commit f2f26e2

File tree

1 file changed

+24
-3
lines changed

1 file changed

+24
-3
lines changed

app/src/main/java/org/ole/planet/myplanet/ui/dashboard/DashboardActivity.kt

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import android.view.LayoutInflater
1515
import android.view.Menu
1616
import android.view.MenuItem
1717
import android.view.View
18+
import android.view.ViewTreeObserver
1819
import android.widget.TextView
1920
import androidx.activity.OnBackPressedCallback
2021
import androidx.activity.viewModels
@@ -126,22 +127,33 @@ class DashboardActivity : DashboardElementActivity(), OnHomeItemClickListener, N
126127

127128
override fun onCreate(savedInstanceState: Bundle?) {
128129
super.onCreate(savedInstanceState)
130+
postponeEnterTransition()
129131
checkUser()
130132
initViews()
131133
updateAppTitle()
132134
notificationManager = NotificationUtils.getInstance(this)
133135
if (handleGuestAccess()) return
134-
setupNavigation()
135136
handleInitialFragment()
136137
setupToolbarActions()
137138
hideWifi()
138-
setupRealmListeners()
139139
setupSystemNotificationReceiver()
140140
checkIfShouldShowNotifications()
141141
addBackPressCallback()
142+
handleNotificationIntent(intent)
143+
}
144+
145+
override fun onStart() {
146+
super.onStart()
147+
lifecycleScope.launch(Dispatchers.IO) {
148+
setupHeavyTasks()
149+
}
150+
}
151+
152+
private fun setupHeavyTasks() {
153+
setupNavigation()
154+
setupRealmListeners()
142155
challengeHelper = ChallengeHelper(this, mRealm, user, settings, editor, dashboardViewModel)
143156
challengeHelper.evaluateChallengeDialog()
144-
handleNotificationIntent(intent)
145157
}
146158

147159
private fun initViews() {
@@ -160,6 +172,15 @@ class DashboardActivity : DashboardElementActivity(), OnHomeItemClickListener, N
160172
service = Service(this)
161173
tl = findViewById(R.id.tab_layout)
162174
binding.root.viewTreeObserver.addOnGlobalLayoutListener { topBarVisible() }
175+
binding.root.viewTreeObserver.addOnPreDrawListener(
176+
object : ViewTreeObserver.OnPreDrawListener {
177+
override fun onPreDraw(): Boolean {
178+
binding.root.viewTreeObserver.removeOnPreDrawListener(this)
179+
startPostponedEnterTransition()
180+
reportFullyDrawn()
181+
return true
182+
}
183+
})
163184
binding.appBarBell.ivSetting.setOnClickListener {
164185
startActivity(Intent(this, SettingActivity::class.java))
165186
}

0 commit comments

Comments
 (0)