-
Notifications
You must be signed in to change notification settings - Fork 0
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
Feature/my shiny feature n 7 #8
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,6 +16,7 @@ | |
|
||
package com.google.samples.apps.nowinandroid | ||
|
||
import android.content.Context | ||
import androidx.lifecycle.ViewModel | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Adding logging is a good practice, but it would be beneficial to have more context about the logs, such as timestamps and log levels (INFO, DEBUG, ERROR). Additionally, consider using a logging library that provides more flexibility. |
||
import androidx.lifecycle.viewModelScope | ||
import com.google.samples.apps.nowinandroid.MainActivityUiState.Loading | ||
|
@@ -33,13 +34,20 @@ import javax.inject.Inject | |
class MainActivityViewModel @Inject constructor( | ||
userDataRepository: UserDataRepository, | ||
) : ViewModel() { | ||
|
||
private lateinit var _context: Context | ||
|
||
val uiState: StateFlow<MainActivityUiState> = userDataRepository.userData.map { | ||
Success(it) | ||
}.stateIn( | ||
scope = viewModelScope, | ||
OussamaHaff marked this conversation as resolved.
Show resolved
Hide resolved
|
||
initialValue = Loading, | ||
started = SharingStarted.WhileSubscribed(5_000), | ||
) | ||
|
||
fun saveActivity(context: Context) { | ||
_context = context | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The usage of lateinit for _context can lead to potential null pointer exceptions if the context is not set before use. It's safer to either pass the context through constructor injection or handle it in a more controlled manner. |
||
} | ||
} | ||
|
||
sealed interface MainActivityUiState { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,6 +16,7 @@ | |
|
||
package com.google.samples.apps.nowinandroid.ui | ||
|
||
import android.util.Log | ||
import androidx.compose.foundation.layout.Box | ||
import androidx.compose.foundation.layout.Column | ||
import androidx.compose.foundation.layout.WindowInsets | ||
|
@@ -147,6 +148,10 @@ internal fun NiaApp( | |
) | ||
} | ||
|
||
LaunchedEffect(Unit) { | ||
OussamaHaff marked this conversation as resolved.
Show resolved
Hide resolved
|
||
Log.e("#####","info message - App UI") | ||
} | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The saveActivity method simply assigns the context to a private variable without performing any action. It's unclear what the intended functionality is. Consider adding comments or documentation explaining why this method exists and how it should be used. |
||
NiaNavigationSuiteScaffold( | ||
navigationSuiteItems = { | ||
appState.topLevelDestinations.forEach { destination -> | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changing the dispatcher from IO to Default might not be ideal for UI-related work. It's generally recommended to use IO for background tasks that involve disk or network operations.