Advertisement
Guest User

Fragment

a guest
Jun 15th, 2021
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Kotlin 3.57 KB | None | 0 0
  1. @AndroidEntryPoint
  2. class ProfileFragment : Fragment() {
  3.  
  4.     @Inject
  5.     lateinit var repository: GirlsRepositoryImpl
  6.  
  7.     private var _binding: FragmentProfileBinding? = null
  8.     private val binding get() = _binding!!
  9.  
  10.  
  11.     private val viewModel by viewModels<ProfileViewModel>()
  12.  
  13.     private lateinit var name: String
  14.     private lateinit var birthday: String
  15.     private lateinit var info: String
  16.     private lateinit var busyness: String
  17.    
  18.  
  19.     override fun onCreateView(
  20.         inflater: LayoutInflater,
  21.         container: ViewGroup?,
  22.         savedInstanceState: Bundle?
  23.     ): View? {
  24.         _binding = FragmentProfileBinding.inflate(inflater, container, false)
  25.         return binding.root
  26.     }
  27.  
  28.  
  29.     @SuppressLint("TimberArgCount")
  30.     override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
  31.         super.onViewCreated(view, savedInstanceState)
  32.  
  33.         initView()
  34.         subscribeToObservables()
  35.  
  36.        /* var user: UserEntity = repository.getUserFromDb()
  37.         binding.apply {
  38.             currentNameUser.setText(user?.name)
  39.             currentBirthdayDate.text = user?.birthdayDate
  40.             currentUserInfo.setText(user?.info)
  41.             currentUserBusyness.setText(user?.busyness)
  42.         }*/
  43.        
  44.     }
  45.  
  46.     private fun subscribeToObservables() {
  47.         viewModel.user2.observe(viewLifecycleOwner, {
  48.             Timber.e("subscribeToObservables name = ${it?.name} info = ${it?.info} img = ${it.imageUrl}")
  49.             binding.apply {
  50.  
  51.                 name = checkNotNull(it.name)
  52.                 info = it.info
  53.                 birthday = it.birthdayDate
  54.                 busyness = it.busyness
  55.  
  56.                 currentNameUser.setText(it?.name)
  57.                 currentBirthdayDate.text = it?.birthdayDate
  58.                 currentUserInfo.setText(it?.info)
  59.                 currentUserBusyness.setText(it?.busyness)
  60.  
  61.              
  62.             }
  63.         })
  64.     }
  65.  
  66.     private fun initView() {
  67.  
  68.         binding.pickImage.setOnClickListener {
  69.             pickImage.launch(MIMETYPE_IMAGES)
  70.         }
  71.  
  72.         binding.apply {
  73.             currentNameUser.afterTextChanged { name ->
  74.                 Timber.e("currentNameUser.afterTextChanged ")
  75.                 viewModel.updateUser2(
  76.                     UserEntity(
  77.                         name = name,
  78.                         info = info,
  79.                         birthdayDate = birthday,
  80.                         busyness = busyness,
  81.                         imageUrl = imageUri
  82.                     )
  83.                 )
  84.             }
  85.             currentUserBusyness.afterTextChanged { busyness ->
  86.                 Timber.e("currentUserBusyness.afterTextChanged ")
  87.                 viewModel.updateUser2(
  88.                     UserEntity(
  89.                         name = name,
  90.                         info = info,
  91.                         birthdayDate = birthday,
  92.                         busyness = busyness,
  93.                         imageUrl = imageUri
  94.                     )
  95.                 )
  96.             }
  97.             currentUserInfo.afterTextChanged { info ->
  98.                 Timber.e("currentUserInfo.afterTextChanged ")
  99.                 viewModel.updateUser2(
  100.                     UserEntity(
  101.                         name = name,
  102.                         info = info,
  103.                         birthdayDate = birthday,
  104.                         busyness = busyness,
  105.                         imageUrl = imageUri
  106.                     )
  107.                 )
  108.             }
  109.         }
  110.     }
  111.  
  112.     override fun onDestroy() {
  113.         super.onDestroy()
  114.         _binding = null
  115.     }
  116. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement