Use lifecycleScope rather than an Empty ViewModel
This commit is contained in:
parent
f2f4d325eb
commit
afa3149504
@ -1,23 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (c) 2021 New Vector Ltd
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package im.vector.app.core.platform
|
|
||||||
|
|
||||||
import com.airbnb.mvrx.MvRxState
|
|
||||||
|
|
||||||
data class EmptyState(
|
|
||||||
val dummy: Int = 0
|
|
||||||
) : MvRxState
|
|
@ -1,26 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (c) 2021 New Vector Ltd
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package im.vector.app.core.platform
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Mainly used to get a viewModelScope
|
|
||||||
*/
|
|
||||||
class EmptyViewModel(initialState: EmptyState) : VectorViewModel<EmptyState, EmptyAction, EmptyViewEvents>(initialState) {
|
|
||||||
override fun handle(action: EmptyAction) {
|
|
||||||
// N/A
|
|
||||||
}
|
|
||||||
}
|
|
@ -22,15 +22,13 @@ import android.os.Bundle
|
|||||||
import android.os.Parcelable
|
import android.os.Parcelable
|
||||||
import androidx.appcompat.app.AlertDialog
|
import androidx.appcompat.app.AlertDialog
|
||||||
import androidx.lifecycle.Lifecycle
|
import androidx.lifecycle.Lifecycle
|
||||||
import androidx.lifecycle.viewModelScope
|
import androidx.lifecycle.lifecycleScope
|
||||||
import com.airbnb.mvrx.viewModel
|
|
||||||
import com.bumptech.glide.Glide
|
import com.bumptech.glide.Glide
|
||||||
import im.vector.app.R
|
import im.vector.app.R
|
||||||
import im.vector.app.core.di.ActiveSessionHolder
|
import im.vector.app.core.di.ActiveSessionHolder
|
||||||
import im.vector.app.core.di.ScreenComponent
|
import im.vector.app.core.di.ScreenComponent
|
||||||
import im.vector.app.core.error.ErrorFormatter
|
import im.vector.app.core.error.ErrorFormatter
|
||||||
import im.vector.app.core.extensions.startSyncing
|
import im.vector.app.core.extensions.startSyncing
|
||||||
import im.vector.app.core.platform.EmptyViewModel
|
|
||||||
import im.vector.app.core.platform.VectorBaseActivity
|
import im.vector.app.core.platform.VectorBaseActivity
|
||||||
import im.vector.app.core.utils.deleteAllFiles
|
import im.vector.app.core.utils.deleteAllFiles
|
||||||
import im.vector.app.databinding.FragmentLoadingBinding
|
import im.vector.app.databinding.FragmentLoadingBinding
|
||||||
@ -83,8 +81,6 @@ class MainActivity : VectorBaseActivity<FragmentLoadingBinding>(), UnlockedActiv
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private val emptyViewModel: EmptyViewModel by viewModel()
|
|
||||||
|
|
||||||
override fun getBinding() = FragmentLoadingBinding.inflate(layoutInflater)
|
override fun getBinding() = FragmentLoadingBinding.inflate(layoutInflater)
|
||||||
|
|
||||||
private lateinit var args: MainActivityArgs
|
private lateinit var args: MainActivityArgs
|
||||||
@ -150,7 +146,7 @@ class MainActivity : VectorBaseActivity<FragmentLoadingBinding>(), UnlockedActiv
|
|||||||
}
|
}
|
||||||
when {
|
when {
|
||||||
args.isAccountDeactivated -> {
|
args.isAccountDeactivated -> {
|
||||||
emptyViewModel.viewModelScope.launch {
|
lifecycleScope.launch {
|
||||||
// Just do the local cleanup
|
// Just do the local cleanup
|
||||||
Timber.w("Account deactivated, start app")
|
Timber.w("Account deactivated, start app")
|
||||||
sessionHolder.clearActiveSession()
|
sessionHolder.clearActiveSession()
|
||||||
@ -159,7 +155,7 @@ class MainActivity : VectorBaseActivity<FragmentLoadingBinding>(), UnlockedActiv
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
args.clearCredentials -> {
|
args.clearCredentials -> {
|
||||||
emptyViewModel.viewModelScope.launch {
|
lifecycleScope.launch {
|
||||||
try {
|
try {
|
||||||
session.signOut(!args.isUserLoggedOut)
|
session.signOut(!args.isUserLoggedOut)
|
||||||
Timber.w("SIGN_OUT: success, start app")
|
Timber.w("SIGN_OUT: success, start app")
|
||||||
@ -172,7 +168,7 @@ class MainActivity : VectorBaseActivity<FragmentLoadingBinding>(), UnlockedActiv
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
args.clearCache -> {
|
args.clearCache -> {
|
||||||
emptyViewModel.viewModelScope.launch {
|
lifecycleScope.launch {
|
||||||
try {
|
try {
|
||||||
session.clearCache()
|
session.clearCache()
|
||||||
doLocalCleanup(clearPreferences = false)
|
doLocalCleanup(clearPreferences = false)
|
||||||
|
@ -19,13 +19,11 @@ package im.vector.app.features.link
|
|||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
import android.net.Uri
|
import android.net.Uri
|
||||||
import androidx.appcompat.app.AlertDialog
|
import androidx.appcompat.app.AlertDialog
|
||||||
import androidx.lifecycle.viewModelScope
|
import androidx.lifecycle.lifecycleScope
|
||||||
import com.airbnb.mvrx.viewModel
|
|
||||||
import im.vector.app.R
|
import im.vector.app.R
|
||||||
import im.vector.app.core.di.ActiveSessionHolder
|
import im.vector.app.core.di.ActiveSessionHolder
|
||||||
import im.vector.app.core.di.ScreenComponent
|
import im.vector.app.core.di.ScreenComponent
|
||||||
import im.vector.app.core.error.ErrorFormatter
|
import im.vector.app.core.error.ErrorFormatter
|
||||||
import im.vector.app.core.platform.EmptyViewModel
|
|
||||||
import im.vector.app.core.platform.VectorBaseActivity
|
import im.vector.app.core.platform.VectorBaseActivity
|
||||||
import im.vector.app.core.utils.toast
|
import im.vector.app.core.utils.toast
|
||||||
import im.vector.app.databinding.ActivityProgressBinding
|
import im.vector.app.databinding.ActivityProgressBinding
|
||||||
@ -48,8 +46,6 @@ class LinkHandlerActivity : VectorBaseActivity<ActivityProgressBinding>() {
|
|||||||
@Inject lateinit var errorFormatter: ErrorFormatter
|
@Inject lateinit var errorFormatter: ErrorFormatter
|
||||||
@Inject lateinit var permalinkHandler: PermalinkHandler
|
@Inject lateinit var permalinkHandler: PermalinkHandler
|
||||||
|
|
||||||
private val emptyViewModel: EmptyViewModel by viewModel()
|
|
||||||
|
|
||||||
override fun injectWith(injector: ScreenComponent) {
|
override fun injectWith(injector: ScreenComponent) {
|
||||||
injector.inject(this)
|
injector.inject(this)
|
||||||
}
|
}
|
||||||
@ -155,7 +151,7 @@ class LinkHandlerActivity : VectorBaseActivity<ActivityProgressBinding>() {
|
|||||||
// Should not happen
|
// Should not happen
|
||||||
startLoginActivity(uri)
|
startLoginActivity(uri)
|
||||||
} else {
|
} else {
|
||||||
emptyViewModel.viewModelScope.launch {
|
lifecycleScope.launch {
|
||||||
try {
|
try {
|
||||||
session.signOut(true)
|
session.signOut(true)
|
||||||
Timber.d("## displayAlreadyLoginPopup(): logout succeeded")
|
Timber.d("## displayAlreadyLoginPopup(): logout succeeded")
|
||||||
|
Loading…
Reference in New Issue
Block a user