Shortcuts must first start MainActivity to ensure the session is restored.

This commit is contained in:
Benoit Marty 2022-07-28 16:03:13 +02:00
parent 5daf82a32a
commit 6e0ca3958b
3 changed files with 20 additions and 19 deletions

View File

@ -86,6 +86,8 @@ class MainActivity : VectorBaseActivity<ActivityMainBinding>(), UnlockedActivity
private const val EXTRA_ARGS = "EXTRA_ARGS" private const val EXTRA_ARGS = "EXTRA_ARGS"
private const val EXTRA_NEXT_INTENT = "EXTRA_NEXT_INTENT" private const val EXTRA_NEXT_INTENT = "EXTRA_NEXT_INTENT"
private const val EXTRA_INIT_SESSION = "EXTRA_INIT_SESSION" private const val EXTRA_INIT_SESSION = "EXTRA_INIT_SESSION"
private const val EXTRA_ROOM_ID = "EXTRA_ROOM_ID"
private const val ACTION_ROOM_DETAILS_FROM_SHORTCUT = "ROOM_DETAILS_FROM_SHORTCUT"
// Special action to clear cache and/or clear credentials // Special action to clear cache and/or clear credentials
fun restartApp(activity: Activity, args: MainActivityArgs) { fun restartApp(activity: Activity, args: MainActivityArgs) {
@ -107,6 +109,14 @@ class MainActivity : VectorBaseActivity<ActivityMainBinding>(), UnlockedActivity
intent.putExtra(EXTRA_NEXT_INTENT, nextIntent) intent.putExtra(EXTRA_NEXT_INTENT, nextIntent)
return intent return intent
} }
// Shortcuts can't have intents with parcelables
fun shortcutIntent(context: Context, roomId: String): Intent {
return Intent(context, MainActivity::class.java).apply {
action = ACTION_ROOM_DETAILS_FROM_SHORTCUT
putExtra(EXTRA_ROOM_ID, roomId)
}
}
} }
private val startAppViewModel: StartAppViewModel by viewModel() private val startAppViewModel: StartAppViewModel by viewModel()
@ -171,6 +181,13 @@ class MainActivity : VectorBaseActivity<ActivityMainBinding>(), UnlockedActivity
} else if (intent.hasExtra(EXTRA_INIT_SESSION)) { } else if (intent.hasExtra(EXTRA_INIT_SESSION)) {
setResult(RESULT_OK) setResult(RESULT_OK)
finish() finish()
} else if (intent.action == ACTION_ROOM_DETAILS_FROM_SHORTCUT) {
val roomId = intent.getStringExtra(EXTRA_ROOM_ID)
if (roomId?.isNotEmpty() == true) {
// TODO Add a trigger Shortcut to the analytics.
navigator.openRoom(this, roomId)
}
finish()
} else { } else {
args = parseArgs() args = parseArgs()
if (args.clearCredentials || args.isUserLoggedOut || args.clearCache) { if (args.clearCredentials || args.isUserLoggedOut || args.clearCache) {

View File

@ -27,7 +27,7 @@ import androidx.core.graphics.drawable.IconCompat
import im.vector.app.BuildConfig import im.vector.app.BuildConfig
import im.vector.app.core.glide.GlideApp import im.vector.app.core.glide.GlideApp
import im.vector.app.core.utils.DimensionConverter import im.vector.app.core.utils.DimensionConverter
import im.vector.app.features.home.room.detail.RoomDetailActivity import im.vector.app.features.MainActivity
import org.matrix.android.sdk.api.session.room.model.RoomSummary import org.matrix.android.sdk.api.session.room.model.RoomSummary
import org.matrix.android.sdk.api.util.toMatrixItem import org.matrix.android.sdk.api.util.toMatrixItem
import javax.inject.Inject import javax.inject.Inject
@ -58,7 +58,7 @@ class ShortcutCreator @Inject constructor(
@WorkerThread @WorkerThread
fun create(roomSummary: RoomSummary, rank: Int = 1): ShortcutInfoCompat { fun create(roomSummary: RoomSummary, rank: Int = 1): ShortcutInfoCompat {
val intent = RoomDetailActivity.shortcutIntent(context, roomSummary.roomId) val intent = MainActivity.shortcutIntent(context, roomSummary.roomId)
val bitmap = try { val bitmap = try {
val glideRequests = GlideApp.with(context) val glideRequests = GlideApp.with(context)
val matrixItem = roomSummary.toMatrixItem() val matrixItem = roomSummary.toMatrixItem()

View File

@ -99,12 +99,7 @@ class RoomDetailActivity :
super.onCreate(savedInstanceState) super.onCreate(savedInstanceState)
supportFragmentManager.registerFragmentLifecycleCallbacks(fragmentLifecycleCallbacks, false) supportFragmentManager.registerFragmentLifecycleCallbacks(fragmentLifecycleCallbacks, false)
waitingView = views.waitingView.waitingView waitingView = views.waitingView.waitingView
val timelineArgs: TimelineArgs? = if (intent?.action == ACTION_ROOM_DETAILS_FROM_SHORTCUT) { val timelineArgs: TimelineArgs = intent?.extras?.getParcelable(EXTRA_ROOM_DETAIL_ARGS) ?: return
TimelineArgs(roomId = intent?.extras?.getString(EXTRA_ROOM_ID)!!)
} else {
intent?.extras?.getParcelable(EXTRA_ROOM_DETAIL_ARGS)
}
if (timelineArgs == null) return
intent.putExtra(Mavericks.KEY_ARG, timelineArgs) intent.putExtra(Mavericks.KEY_ARG, timelineArgs)
currentRoomId = timelineArgs.roomId currentRoomId = timelineArgs.roomId
@ -187,10 +182,7 @@ class RoomDetailActivity :
} }
companion object { companion object {
const val EXTRA_ROOM_DETAIL_ARGS = "EXTRA_ROOM_DETAIL_ARGS" const val EXTRA_ROOM_DETAIL_ARGS = "EXTRA_ROOM_DETAIL_ARGS"
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, firstStartMainActivity: Boolean): Intent { fun newIntent(context: Context, timelineArgs: TimelineArgs, firstStartMainActivity: Boolean): Intent {
val intent = Intent(context, RoomDetailActivity::class.java).apply { val intent = Intent(context, RoomDetailActivity::class.java).apply {
@ -202,14 +194,6 @@ class RoomDetailActivity :
intent intent
} }
} }
// Shortcuts can't have intents with parcelables
fun shortcutIntent(context: Context, roomId: String): Intent {
return Intent(context, RoomDetailActivity::class.java).apply {
action = ACTION_ROOM_DETAILS_FROM_SHORTCUT
putExtra(EXTRA_ROOM_ID, roomId)
}
}
} }
override fun mxToBottomSheetNavigateToRoom(roomId: String, trigger: ViewRoom.Trigger?) { override fun mxToBottomSheetNavigateToRoom(roomId: String, trigger: ViewRoom.Trigger?) {