Как вызвать функцию baseactivity из viewmodel в android

Привет У меня есть LoginActivity и LoginViewModel и еще несколько классов. У меня есть showLoading и hideLoading в BaseActivity поэтому он может быть доступен из каждого действия.

Я могу вызвать метод LoginActivity из LoginViewModel например mNavigator?.startForgotPasswordActivity()

Я хочу назвать это из LoginViewModel затем, как это сделать, используя MVVM? или я иду с неправильным подходом. Пожалуйста, предложите, как правильно это сделать?

BaseActivity.kt

 abstract class BaseActivity : AppCompatActivity(), AnkoLogger { private val progressBar: ProgressBar? = null override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) } protected fun getToolbar(): Toolbar { val toolbar: Toolbar = findViewById(R.id.toolbar) setSupportActionBar(toolbar) return toolbar } protected fun performDependencyInjection() { AndroidInjection.inject(this); } @TargetApi(Build.VERSION_CODES.M) fun requestPermissionsSafely(permissions: Array<String>, requestCode: Int) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { requestPermissions(permissions, requestCode) } } @TargetApi(Build.VERSION_CODES.M) fun hasPermission(permission: String): Boolean { return Build.VERSION.SDK_INT < Build.VERSION_CODES.M || checkSelfPermission(permission) == PackageManager.PERMISSION_GRANTED } fun isNetworkConnected(): Boolean { return NetworkUtils.isNetworkConnected(applicationContext) } fun showLoading() { hideLoading() // show progress bar } fun hideLoading() { // hide progress bar } } 

LoginActivity.kt

 class LoginActivity : BaseActivity(), LoginNavigator { @Inject lateinit var loginViewModel: LoginViewModel override fun onCreate(savedInstanceState: Bundle?) { performDependencyInjection() super.onCreate(savedInstanceState) val activityLoginBinding: ActivityLoginBinding = DataBindingUtil.setContentView<ActivityLoginBinding>(this, R.layout.activity_login) activityLoginBinding.loginViewModel = loginViewModel loginViewModel.mNavigator = this } override fun startHomeActivity() { TODO("not implemented") //To change body of created functions use File | Settings | File Templates. } override fun startRegistrationActivity() { startActivity(Intent(this, RegistrationActivity::class.java)) } override fun startForgotPasswordActivity() { startActivity(Intent(this, ForgotPasswordActivity::class.java)) } override fun handleError(throwable: Throwable) { TODO("not implemented") //To change body of created functions use File | Settings | File Templates. } } 

LoginViewModel.kt

 class LoginViewModel : BaseViewModel<LoginNavigator>(), AnkoLogger { val emailField = ObservableField<String>() private val email: String get() = emailField.get() val passwordField = ObservableField<String>() private val password: String get() = passwordField.get() @Suppress("PARAMETER_NAME_CHANGED_ON_OVERRIDE") fun login(view: View) { if (isEmailAndPasswordValid(email, password)) { ApiHelperImpl().doServerLoginApiCall(email, password) .subscribeOn(Schedulers.io()) .observeOn(AndroidSchedulers.mainThread()) .subscribeWith(object : CallbackWrapper<LoginResponse>() { override fun onSuccess(loginResponse: LoginResponse) { info { loginResponse } } }) } } /** * Validate email and password. It checks email and password is empty or not * and validate email address is correct or not * @param email email address for login * @param password password for login * @return true if email and password pass all conditions else false */ private fun isEmailAndPasswordValid(email: String, password: String): Boolean { if (email.isEmpty()) return false if (!Patterns.EMAIL_ADDRESS.matcher(email).matches()) return false if (password.isEmpty()) return false return true } } 

BaseViewModel.kt

 abstract class BaseViewModel<N> { var mNavigator: N? = null }