|
|
@@ -12,15 +12,18 @@ import androidx.lifecycle.Observer
|
|
|
import androidx.lifecycle.ViewModelProvider
|
|
|
import androidx.navigation.NavController
|
|
|
import androidx.navigation.findNavController
|
|
|
+import androidx.navigation.fragment.findNavController
|
|
|
import androidx.navigation.ui.AppBarConfiguration
|
|
|
import androidx.navigation.ui.navigateUp
|
|
|
import androidx.navigation.ui.setupActionBarWithNavController
|
|
|
import com.google.android.material.navigation.NavigationView
|
|
|
+import com.mrozon.core_api.entity.User
|
|
|
import com.mrozon.core_api.providers.AppWithFacade
|
|
|
import com.mrozon.healthdiary.R
|
|
|
import com.mrozon.healthdiary.databinding.ActivityMainBinding
|
|
|
import com.mrozon.healthdiary.di.main.MainActivityComponent
|
|
|
import com.mrozon.utils.base.BaseActivity
|
|
|
+import com.mrozon.utils.network.Result
|
|
|
import timber.log.Timber
|
|
|
import javax.inject.Inject
|
|
|
|
|
|
@@ -94,13 +97,19 @@ class MainActivity : BaseActivity<ActivityMainBinding>(){
|
|
|
}
|
|
|
})
|
|
|
|
|
|
+
|
|
|
viewModel.currentUser.observe(this, Observer { user ->
|
|
|
- val headerView = binding.navView.getHeaderView(0)
|
|
|
- val tvUserEmail = headerView.findViewById<TextView>(R.id.tvUserEmail)
|
|
|
- val tvUserName = headerView.findViewById<TextView>(R.id.tvUserName)
|
|
|
- val ivLogout = headerView.findViewById<ImageView>(R.id.ivLogout)
|
|
|
+ showUserProfile(user)
|
|
|
+ })
|
|
|
+ }
|
|
|
|
|
|
- if (user == null) {
|
|
|
+ private fun showUserProfile(user: User?) {
|
|
|
+ val headerView = binding.navView.getHeaderView(0)
|
|
|
+ val tvUserEmail = headerView.findViewById<TextView>(R.id.tvUserEmail)
|
|
|
+ val tvUserName = headerView.findViewById<TextView>(R.id.tvUserName)
|
|
|
+ val ivLogout = headerView.findViewById<ImageView>(R.id.ivLogout)
|
|
|
+
|
|
|
+ if (user == null) {
|
|
|
Timber.d("user is null")
|
|
|
supportActionBar?.hide()
|
|
|
drawerLayout.setDrawerLockMode(LOCK_MODE_LOCKED_CLOSED)
|
|
|
@@ -116,8 +125,8 @@ class MainActivity : BaseActivity<ActivityMainBinding>(){
|
|
|
drawerLayout.closeDrawer(GravityCompat.START)
|
|
|
}
|
|
|
viewModel.logoutUser(user)
|
|
|
+ showUserProfile(null)
|
|
|
}
|
|
|
}
|
|
|
- })
|
|
|
}
|
|
|
}
|