# android

Adam Kirk

04/03/2019, 12:50 AM
Does this make sense? The assetRepoImpl checks the database first and assigns the currentUser then checks the server (When appropriate) and updates the currentUser on the observer. I need access to the currentUser inside the AssetRepo to get the Assets. So I am looking to see if this is the best way / right way?
Copy code
class AssetRepositoryImpl(private val assetDao: AssetDao,
                          private val assetAPIDataSource: AssetAPIDataSource,
                          userAPIDataSource: UserAPIDataSource,
                          userDao: UserDao
) : AssetRepository {

    private lateinit var currentUser: User

    init {
        //Check the database first
        userDao.getCurrentUserLiveData().observeOnce {
            println("ObserverOnce In AssetRepo Impl ${it.token}")
            currentUser = it

        //When there is an update then update here
        userAPIDataSource.downloadedCurrentUser.observeForever {
            currentUser = createUser(it)

        assetAPIDataSource.downloadedCurrentAssets.observeForever { newCurrentAssets ->
I should note that it works. 🙂 but just because something works doesn’t mean its right and yes I am aware that there is lots missing for proper understanding. hopefully most will be able to understand what I am trying to do. In essence I need a way to access the user inside the asset repo.
stackoverflow 4


04/03/2019, 1:40 AM
No need to post it here. This channel is for kotlin related android questions

Adam Kirk

04/03/2019, 1:49 AM
Fair enough, this is android and kotlin (thus why i thought it would be ok). Still fairly new to all of this.