mirror of
https://github.com/element-hq/element-android
synced 2024-11-27 20:06:51 +03:00
Always start MainActivity to ensure that current session is set.
This commit is contained in:
parent
0dd9e943c7
commit
c8a2bfc738
7 changed files with 51 additions and 22 deletions
|
@ -17,6 +17,7 @@
|
|||
package im.vector.app.features
|
||||
|
||||
import android.app.Activity
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.os.Bundle
|
||||
import android.os.Parcelable
|
||||
|
@ -76,6 +77,7 @@ class MainActivity : VectorBaseActivity<ActivityMainBinding>(), UnlockedActivity
|
|||
|
||||
companion object {
|
||||
private const val EXTRA_ARGS = "EXTRA_ARGS"
|
||||
private const val EXTRA_NEXT_INTENT = "EXTRA_NEXT_INTENT"
|
||||
|
||||
// Special action to clear cache and/or clear credentials
|
||||
fun restartApp(activity: Activity, args: MainActivityArgs) {
|
||||
|
@ -85,6 +87,12 @@ class MainActivity : VectorBaseActivity<ActivityMainBinding>(), UnlockedActivity
|
|||
intent.putExtra(EXTRA_ARGS, args)
|
||||
activity.startActivity(intent)
|
||||
}
|
||||
|
||||
fun getIntentWithNextIntent(context: Context, nextIntent: Intent): Intent {
|
||||
val intent = Intent(context, MainActivity::class.java)
|
||||
intent.putExtra(EXTRA_NEXT_INTENT, nextIntent)
|
||||
return intent
|
||||
}
|
||||
}
|
||||
|
||||
private val mainViewModel: MainViewModel by viewModel()
|
||||
|
@ -123,15 +131,21 @@ class MainActivity : VectorBaseActivity<ActivityMainBinding>(), UnlockedActivity
|
|||
}
|
||||
|
||||
private fun handleAppStarted() {
|
||||
args = parseArgs()
|
||||
if (args.clearCredentials || args.isUserLoggedOut || args.clearCache) {
|
||||
clearNotifications()
|
||||
}
|
||||
// Handle some wanted cleanup
|
||||
if (args.clearCache || args.clearCredentials) {
|
||||
doCleanUp()
|
||||
if (intent.hasExtra(EXTRA_NEXT_INTENT)) {
|
||||
// Start the next Activity
|
||||
val nextIntent = intent.getParcelableExtra<Intent>(EXTRA_NEXT_INTENT)
|
||||
startIntentAndFinish(nextIntent)
|
||||
} else {
|
||||
startNextActivityAndFinish()
|
||||
args = parseArgs()
|
||||
if (args.clearCredentials || args.isUserLoggedOut || args.clearCache) {
|
||||
clearNotifications()
|
||||
}
|
||||
// Handle some wanted cleanup
|
||||
if (args.clearCache || args.clearCredentials) {
|
||||
doCleanUp()
|
||||
} else {
|
||||
startNextActivityAndFinish()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -273,6 +287,10 @@ class MainActivity : VectorBaseActivity<ActivityMainBinding>(), UnlockedActivity
|
|||
null
|
||||
}
|
||||
}
|
||||
startIntentAndFinish(intent)
|
||||
}
|
||||
|
||||
private fun startIntentAndFinish(intent: Intent?) {
|
||||
intent?.let { startActivity(it) }
|
||||
finish()
|
||||
}
|
||||
|
|
|
@ -604,7 +604,7 @@ class VectorCallActivity :
|
|||
private fun returnToChat() {
|
||||
val roomId = withState(callViewModel) { it.roomId }
|
||||
val args = TimelineArgs(roomId)
|
||||
val intent = RoomDetailActivity.newIntent(this, args).apply {
|
||||
val intent = RoomDetailActivity.newIntent(this, args, false).apply {
|
||||
flags = FLAG_ACTIVITY_CLEAR_TOP
|
||||
}
|
||||
startActivity(intent)
|
||||
|
|
|
@ -623,10 +623,12 @@ class HomeActivity :
|
|||
inviteNotificationRoomId = inviteNotificationRoomId
|
||||
)
|
||||
|
||||
return Intent(context, HomeActivity::class.java)
|
||||
val intent = Intent(context, HomeActivity::class.java)
|
||||
.apply {
|
||||
putExtra(Mavericks.KEY_ARG, args)
|
||||
}
|
||||
|
||||
return MainActivity.getIntentWithNextIntent(context, intent)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -35,6 +35,7 @@ import im.vector.app.core.extensions.keepScreenOn
|
|||
import im.vector.app.core.extensions.replaceFragment
|
||||
import im.vector.app.core.platform.VectorBaseActivity
|
||||
import im.vector.app.databinding.ActivityRoomDetailBinding
|
||||
import im.vector.app.features.MainActivity
|
||||
import im.vector.app.features.analytics.plan.MobileScreen
|
||||
import im.vector.app.features.analytics.plan.ViewRoom
|
||||
import im.vector.app.features.home.room.breadcrumbs.BreadcrumbsFragment
|
||||
|
@ -191,10 +192,15 @@ class RoomDetailActivity :
|
|||
const val EXTRA_ROOM_ID = "EXTRA_ROOM_ID"
|
||||
const val ACTION_ROOM_DETAILS_FROM_SHORTCUT = "ROOM_DETAILS_FROM_SHORTCUT"
|
||||
|
||||
fun newIntent(context: Context, timelineArgs: TimelineArgs): Intent {
|
||||
return Intent(context, RoomDetailActivity::class.java).apply {
|
||||
fun newIntent(context: Context, timelineArgs: TimelineArgs, firstStartMainActivity: Boolean): Intent {
|
||||
val intent = Intent(context, RoomDetailActivity::class.java).apply {
|
||||
putExtra(EXTRA_ROOM_DETAIL_ARGS, timelineArgs)
|
||||
}
|
||||
return if (firstStartMainActivity) {
|
||||
MainActivity.getIntentWithNextIntent(context, intent)
|
||||
} else {
|
||||
intent
|
||||
}
|
||||
}
|
||||
|
||||
// Shortcuts can't have intents with parcelables
|
||||
|
|
|
@ -1206,9 +1206,9 @@ class TimelineFragment @Inject constructor(
|
|||
getRootThreadEventId()?.let {
|
||||
val newRoom = timelineArgs.copy(threadTimelineArgs = null, eventId = it)
|
||||
context?.let { con ->
|
||||
val int = RoomDetailActivity.newIntent(con, newRoom)
|
||||
int.flags = Intent.FLAG_ACTIVITY_CLEAR_TOP or Intent.FLAG_ACTIVITY_NEW_TASK
|
||||
con.startActivity(int)
|
||||
val intent = RoomDetailActivity.newIntent(con, newRoom, false)
|
||||
intent.flags = Intent.FLAG_ACTIVITY_CLEAR_TOP or Intent.FLAG_ACTIVITY_NEW_TASK
|
||||
con.startActivity(intent)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -173,7 +173,7 @@ class DefaultNavigator @Inject constructor(
|
|||
}
|
||||
|
||||
val args = TimelineArgs(roomId = roomId, eventId = eventId, isInviteAlreadyAccepted = isInviteAlreadyAccepted)
|
||||
val intent = RoomDetailActivity.newIntent(context, args)
|
||||
val intent = RoomDetailActivity.newIntent(context, args, false)
|
||||
startActivity(context, intent, buildTask)
|
||||
}
|
||||
|
||||
|
@ -203,7 +203,7 @@ class DefaultNavigator @Inject constructor(
|
|||
eventId = null,
|
||||
openShareSpaceForId = spaceId.takeIf { postSwitchSpaceAction.showShareSheet }
|
||||
)
|
||||
val intent = RoomDetailActivity.newIntent(context, args)
|
||||
val intent = RoomDetailActivity.newIntent(context, args, false)
|
||||
startActivity(context, intent, false)
|
||||
}
|
||||
}
|
||||
|
@ -290,7 +290,7 @@ class DefaultNavigator @Inject constructor(
|
|||
|
||||
override fun openRoomForSharingAndFinish(activity: Activity, roomId: String, sharedData: SharedData) {
|
||||
val args = TimelineArgs(roomId, null, sharedData)
|
||||
val intent = RoomDetailActivity.newIntent(activity, args)
|
||||
val intent = RoomDetailActivity.newIntent(activity, args, false)
|
||||
activity.startActivity(intent)
|
||||
activity.finish()
|
||||
}
|
||||
|
|
|
@ -53,6 +53,7 @@ import im.vector.app.core.resources.StringProvider
|
|||
import im.vector.app.core.services.CallAndroidService
|
||||
import im.vector.app.core.time.Clock
|
||||
import im.vector.app.core.utils.startNotificationChannelSettingsIntent
|
||||
import im.vector.app.features.MainActivity
|
||||
import im.vector.app.features.call.VectorCallActivity
|
||||
import im.vector.app.features.call.service.CallHeadsUpActionReceiver
|
||||
import im.vector.app.features.call.webrtc.WebRtcCall
|
||||
|
@ -241,7 +242,8 @@ class NotificationUtils @Inject constructor(
|
|||
// build the pending intent go to the home screen if this is clicked.
|
||||
val i = HomeActivity.newIntent(context)
|
||||
i.flags = Intent.FLAG_ACTIVITY_CLEAR_TOP or Intent.FLAG_ACTIVITY_SINGLE_TOP
|
||||
val pi = PendingIntent.getActivity(context, 0, i, PendingIntentCompat.FLAG_IMMUTABLE)
|
||||
val mainIntent = MainActivity.getIntentWithNextIntent(context, i)
|
||||
val pi = PendingIntent.getActivity(context, 0, mainIntent, PendingIntentCompat.FLAG_IMMUTABLE)
|
||||
|
||||
val accentColor = ContextCompat.getColor(context, R.color.notification_accent_color)
|
||||
|
||||
|
@ -531,7 +533,7 @@ class NotificationUtils @Inject constructor(
|
|||
|
||||
val contentPendingIntent = TaskStackBuilder.create(context)
|
||||
.addNextIntentWithParentStack(HomeActivity.newIntent(context))
|
||||
.addNextIntent(RoomDetailActivity.newIntent(context, TimelineArgs(callInformation.nativeRoomId)))
|
||||
.addNextIntent(RoomDetailActivity.newIntent(context, TimelineArgs(callInformation.nativeRoomId), true))
|
||||
.getPendingIntent(clock.epochMillis().toInt(), PendingIntent.FLAG_UPDATE_CURRENT or PendingIntentCompat.FLAG_IMMUTABLE)
|
||||
|
||||
builder.setContentIntent(contentPendingIntent)
|
||||
|
@ -828,7 +830,7 @@ class NotificationUtils @Inject constructor(
|
|||
}
|
||||
|
||||
private fun buildOpenRoomIntent(roomId: String): PendingIntent? {
|
||||
val roomIntentTap = RoomDetailActivity.newIntent(context, TimelineArgs(roomId = roomId, switchToParentSpace = true))
|
||||
val roomIntentTap = RoomDetailActivity.newIntent(context, TimelineArgs(roomId = roomId, switchToParentSpace = true), true)
|
||||
roomIntentTap.action = TAP_TO_VIEW_ACTION
|
||||
// pending intent get reused by system, this will mess up the extra params, so put unique info to avoid that
|
||||
roomIntentTap.data = createIgnoredUri("openRoom?$roomId")
|
||||
|
@ -847,10 +849,11 @@ class NotificationUtils @Inject constructor(
|
|||
val intent = HomeActivity.newIntent(context, clearNotification = true)
|
||||
intent.flags = Intent.FLAG_ACTIVITY_CLEAR_TOP or Intent.FLAG_ACTIVITY_SINGLE_TOP
|
||||
intent.data = createIgnoredUri("tapSummary")
|
||||
val mainIntent = MainActivity.getIntentWithNextIntent(context, intent)
|
||||
return PendingIntent.getActivity(
|
||||
context,
|
||||
Random.nextInt(1000),
|
||||
intent,
|
||||
mainIntent,
|
||||
PendingIntent.FLAG_UPDATE_CURRENT or PendingIntentCompat.FLAG_IMMUTABLE
|
||||
)
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue