mirror of
https://github.com/SchildiChat/SchildiChat-android.git
synced 2024-11-22 01:15:54 +03:00
Shortcuts must first start MainActivity to ensure the session is restored.
This commit is contained in:
parent
5daf82a32a
commit
6e0ca3958b
3 changed files with 20 additions and 19 deletions
|
@ -86,6 +86,8 @@ class MainActivity : VectorBaseActivity<ActivityMainBinding>(), UnlockedActivity
|
|||
private const val EXTRA_ARGS = "EXTRA_ARGS"
|
||||
private const val EXTRA_NEXT_INTENT = "EXTRA_NEXT_INTENT"
|
||||
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
|
||||
fun restartApp(activity: Activity, args: MainActivityArgs) {
|
||||
|
@ -107,6 +109,14 @@ class MainActivity : VectorBaseActivity<ActivityMainBinding>(), UnlockedActivity
|
|||
intent.putExtra(EXTRA_NEXT_INTENT, nextIntent)
|
||||
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()
|
||||
|
@ -171,6 +181,13 @@ class MainActivity : VectorBaseActivity<ActivityMainBinding>(), UnlockedActivity
|
|||
} else if (intent.hasExtra(EXTRA_INIT_SESSION)) {
|
||||
setResult(RESULT_OK)
|
||||
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 {
|
||||
args = parseArgs()
|
||||
if (args.clearCredentials || args.isUserLoggedOut || args.clearCache) {
|
||||
|
|
|
@ -27,7 +27,7 @@ import androidx.core.graphics.drawable.IconCompat
|
|||
import im.vector.app.BuildConfig
|
||||
import im.vector.app.core.glide.GlideApp
|
||||
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.util.toMatrixItem
|
||||
import javax.inject.Inject
|
||||
|
@ -58,7 +58,7 @@ class ShortcutCreator @Inject constructor(
|
|||
|
||||
@WorkerThread
|
||||
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 glideRequests = GlideApp.with(context)
|
||||
val matrixItem = roomSummary.toMatrixItem()
|
||||
|
|
|
@ -99,12 +99,7 @@ class RoomDetailActivity :
|
|||
super.onCreate(savedInstanceState)
|
||||
supportFragmentManager.registerFragmentLifecycleCallbacks(fragmentLifecycleCallbacks, false)
|
||||
waitingView = views.waitingView.waitingView
|
||||
val timelineArgs: TimelineArgs? = if (intent?.action == ACTION_ROOM_DETAILS_FROM_SHORTCUT) {
|
||||
TimelineArgs(roomId = intent?.extras?.getString(EXTRA_ROOM_ID)!!)
|
||||
} else {
|
||||
intent?.extras?.getParcelable(EXTRA_ROOM_DETAIL_ARGS)
|
||||
}
|
||||
if (timelineArgs == null) return
|
||||
val timelineArgs: TimelineArgs = intent?.extras?.getParcelable(EXTRA_ROOM_DETAIL_ARGS) ?: return
|
||||
intent.putExtra(Mavericks.KEY_ARG, timelineArgs)
|
||||
currentRoomId = timelineArgs.roomId
|
||||
|
||||
|
@ -187,10 +182,7 @@ class RoomDetailActivity :
|
|||
}
|
||||
|
||||
companion object {
|
||||
|
||||
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 {
|
||||
val intent = Intent(context, RoomDetailActivity::class.java).apply {
|
||||
|
@ -202,14 +194,6 @@ class RoomDetailActivity :
|
|||
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?) {
|
||||
|
|
Loading…
Reference in a new issue