Skip to content

Commit

Permalink
fix to handleActionFromContact
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
mahibi committed Jul 6, 2023
1 parent 8eee8df commit 3099cbf
Showing 1 changed file with 53 additions and 53 deletions.
106 changes: 53 additions & 53 deletions app/src/main/java/com/nextcloud/talk/activities/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
}
Expand Down Expand Up @@ -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)
Expand All @@ -301,35 +269,67 @@ class MainActivity : BaseActivity(), ActionBarProvider {
override fun onNewIntent(intent: Intent) {
super.onNewIntent(intent)
Log.d(TAG, "onNewIntent Activity: " + System.identityHashCode(this).toString())
handleIntent(intent)
}

private fun handleIntent(intent: Intent) {
handleActionFromContact(intent)

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)
var user: User? = null
if (internalUserId != null) {
user = userManager.getUserWithId(internalUserId).blockingGet()
}
}

private fun handleIntent(intent: Intent) {
handleActionFromContact(intent)
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()) {
openConversationList()
}
val callNotificationIntent = Intent(this, CallNotificationActivity::class.java)
intent.extras?.let { callNotificationIntent.putExtras(it) }
startActivity(callNotificationIntent)
} else {
logRouterBackStack(router!!)

if (intent.hasExtra(BundleKeys.KEY_FROM_NOTIFICATION_START_CALL)) {
if (intent.getBooleanExtra(BundleKeys.KEY_FROM_NOTIFICATION_START_CALL, false)) {
if (!router!!.hasRootController()) {
openConversationList()
val chatIntent = Intent(context, ChatActivity::class.java)
chatIntent.putExtras(intent.extras!!)
startActivity(chatIntent)

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
}
val callNotificationIntent = Intent(this, CallNotificationActivity::class.java)
intent.extras?.let { callNotificationIntent.putExtras(it) }
startActivity(callNotificationIntent)
} else {
logRouterBackStack(router!!)

val chatIntent = Intent(context, ChatActivity::class.java)
chatIntent.putExtras(intent.extras!!)
startActivity(chatIntent)
override fun onSuccess(users: List<User>) {
if (users.isNotEmpty()) {
runOnUiThread {
openConversationList()
}
} else {
runOnUiThread {
launchLoginScreen()
}
}
}

logRouterBackStack(router!!)
}
override fun onError(e: Throwable) {
Log.e(TAG, "Error loading existing users", e)
}
})
}
}

Expand Down

0 comments on commit 3099cbf

Please sign in to comment.