I haven't touched this source code for half a year. Recently, before I touched anything, I decided to update the following: AGP, Gradle, dependencies and Kotlin Migration.
Code:
Placeholder Fragment
class myPlaceholderFragment : Fragment() {
private lateinit var myPageViewModel: MyPageViewModel
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
myPageViewModel = ViewModelProvider(this).get(MyPageViewModel::class.java).apply {
setIndex(arguments?.getInt(ARG_SECTION_NUMBER) ?: 1)
}
}
override fun onCreateView(
inflater: LayoutInflater, container: ViewGroup?,
savedInstanceState: Bundle?
): View? {
val root = inflater.inflate(R.layout.fragment_my_main, container, false)
val textView: TextView = root.findViewById(R.id.my_main_section_label)
myPageViewModel.text.observe(viewLifecycleOwner, {
textView.text = it
})
return root
}
}
PageViewModel
class myPageViewModel : ViewModel() {
private val _index = MutableLiveData<Int>()
val text: LiveData<String> = Transformations.map(_index) {
"Hello world from section: $it"
}
fun setIndex(index: Int) {
_index.value = index
}
}
Error:
Unresolved reference: Transformations