fix to handleActionFromContact

handleActionFromContact was not executed in onCreate of the MainActivity which is now fixed by this commit.

+ refactoring some intent handling

Signed-off-by: Marcel Hibbe <dev@mhibbe.de>
This commit is contained in:
Marcel Hibbe 2023-07-06 14:58:44 +02:00
parent 007c4a97dc
commit 4c9913a760

View File

@ -62,7 +62,6 @@ import com.nextcloud.talk.utils.ApiUtils
import com.nextcloud.talk.utils.SecurityUtils
import com.nextcloud.talk.utils.bundle.BundleKeys
import com.nextcloud.talk.utils.bundle.BundleKeys.ADD_ACCOUNT
import com.nextcloud.talk.utils.bundle.BundleKeys.KEY_ROOM_ID
import com.nextcloud.talk.utils.bundle.BundleKeys.KEY_ROOM_TOKEN
import io.reactivex.Observer
import io.reactivex.SingleObserver
@ -114,37 +113,7 @@ class MainActivity : BaseActivity(), ActionBarProvider {
router = Conductor.attachRouter(this, binding.controllerContainer, savedInstanceState)
if (intent.hasExtra(ADD_ACCOUNT) && intent.getBooleanExtra(ADD_ACCOUNT, false)) {
addAccount()
} else if (intent.hasExtra(BundleKeys.KEY_FROM_NOTIFICATION_START_CALL)) {
onNewIntent(intent)
} else if (!router!!.hasRootController()) {
if (!appPreferences.isDbRoomMigrated) {
appPreferences.isDbRoomMigrated = true
}
userManager.users.subscribe(object : SingleObserver<List<User>> {
override fun onSubscribe(d: Disposable) {
// unused atm
}
override fun onSuccess(users: List<User>) {
if (users.isNotEmpty()) {
runOnUiThread {
openConversationList()
}
} else {
runOnUiThread {
launchLoginScreen()
}
}
}
override fun onError(e: Throwable) {
Log.e(TAG, "Error loading existing users", e)
}
})
}
handleIntent(intent)
onBackPressedDispatcher.addCallback(this, onBackPressedCallback)
}
@ -281,7 +250,6 @@ class MainActivity : BaseActivity(), ActionBarProvider {
override fun onNext(roomOverall: RoomOverall) {
val bundle = Bundle()
bundle.putString(KEY_ROOM_TOKEN, roomOverall.ocs!!.data!!.token)
bundle.putString(KEY_ROOM_ID, roomOverall.ocs!!.data!!.roomId)
val chatIntent = Intent(context, ChatActivity::class.java)
chatIntent.putExtras(bundle)
@ -301,18 +269,21 @@ class MainActivity : BaseActivity(), ActionBarProvider {
override fun onNewIntent(intent: Intent) {
super.onNewIntent(intent)
Log.d(TAG, "onNewIntent Activity: " + System.identityHashCode(this).toString())
val internalUserId = intent.extras?.getLong(BundleKeys.KEY_INTERNAL_USER_ID)
val user = userManager.getUserWithId(internalUserId!!).blockingGet()
if (user != null && userManager.setUserAsActive(user).blockingGet()) {
handleIntent(intent)
}
}
private fun handleIntent(intent: Intent) {
handleActionFromContact(intent)
val internalUserId = intent.extras?.getLong(BundleKeys.KEY_INTERNAL_USER_ID)
var user: User? = null
if (internalUserId != null) {
user = userManager.getUserWithId(internalUserId).blockingGet()
}
if (user != null && userManager.setUserAsActive(user).blockingGet()) {
// this should be avoided (it's still from conductor architecture). activities should be opened directly.
if (intent.hasExtra(BundleKeys.KEY_FROM_NOTIFICATION_START_CALL)) {
if (intent.getBooleanExtra(BundleKeys.KEY_FROM_NOTIFICATION_START_CALL, false)) {
if (!router!!.hasRootController()) {
@ -331,6 +302,35 @@ class MainActivity : BaseActivity(), ActionBarProvider {
logRouterBackStack(router!!)
}
}
} else if (intent.hasExtra(ADD_ACCOUNT) && intent.getBooleanExtra(ADD_ACCOUNT, false)) {
addAccount()
} else if (!router!!.hasRootController()) {
if (!appPreferences.isDbRoomMigrated) {
appPreferences.isDbRoomMigrated = true
}
userManager.users.subscribe(object : SingleObserver<List<User>> {
override fun onSubscribe(d: Disposable) {
// unused atm
}
override fun onSuccess(users: List<User>) {
if (users.isNotEmpty()) {
runOnUiThread {
openConversationList()
}
} else {
runOnUiThread {
launchLoginScreen()
}
}
}
override fun onError(e: Throwable) {
Log.e(TAG, "Error loading existing users", e)
}
})
}
}
private fun logRouterBackStack(router: Router) {