diff --git a/app/src/main/java/live/shirabox/shirabox/ui/activity/player/PlayerActivity.kt b/app/src/main/java/live/shirabox/shirabox/ui/activity/player/PlayerActivity.kt index c5581ce..8088a1a 100644 --- a/app/src/main/java/live/shirabox/shirabox/ui/activity/player/PlayerActivity.kt +++ b/app/src/main/java/live/shirabox/shirabox/ui/activity/player/PlayerActivity.kt @@ -1,6 +1,8 @@ package live.shirabox.shirabox.ui.activity.player +import android.app.Activity import android.os.Bundle +import android.widget.Toast import androidx.activity.ComponentActivity import androidx.activity.compose.setContent import androidx.compose.foundation.layout.fillMaxSize @@ -31,6 +33,7 @@ class PlayerActivity : ComponentActivity() { ) { val arguments = intent.extras val context = LocalContext.current + val activity = context as? Activity rememberSystemUiController().apply { setStatusBarColor( @@ -40,21 +43,26 @@ class PlayerActivity : ComponentActivity() { Util.hideSystemUi(this) } + lateinit var model: PlayerViewModel - val model: PlayerViewModel = viewModel(factory = Util.viewModelFactory { - PlayerViewModel( + try { + model = PlayerViewModel( context = context, - contentUid = arguments?.getInt("content_uid") ?: -1, - contentName = arguments?.getString("name").toString(), - episode = arguments?.getInt("episode") ?: 0, - startIndex = arguments?.getInt("start_index") ?: 0, + contentUid = arguments!!.getLong("content_uid"), + contentName = arguments.getString("name").toString(), + episode = arguments.getInt("episode"), + startIndex = arguments.getInt("start_index"), playlist = Json.decodeFromString( - arguments?.getString("playlist") ?: "" + arguments.getString("playlist") ?: "" ) ) - }) + } catch (ex: Exception) { + ex.printStackTrace() + activity?.finish() + Toast.makeText(context, ex.localizedMessage, Toast.LENGTH_LONG).show() + } - ShiraPlayer(model = model) + ShiraPlayer(model = viewModel(factory = Util.viewModelFactory { model })) } } } diff --git a/app/src/main/java/live/shirabox/shirabox/ui/activity/resource/ResourceActivity.kt b/app/src/main/java/live/shirabox/shirabox/ui/activity/resource/ResourceActivity.kt index 1e49a87..8d64460 100644 --- a/app/src/main/java/live/shirabox/shirabox/ui/activity/resource/ResourceActivity.kt +++ b/app/src/main/java/live/shirabox/shirabox/ui/activity/resource/ResourceActivity.kt @@ -4,6 +4,7 @@ import android.app.Activity import android.content.Context import android.content.Intent import android.os.Bundle +import android.widget.Toast import androidx.activity.ComponentActivity import androidx.activity.compose.setContent import androidx.compose.animation.AnimatedVisibility @@ -99,21 +100,28 @@ class ResourceActivity : ComponentActivity() { ShiraBoxTheme( transparentStatusBar = true ) { - val activity = LocalContext.current as Activity? - - val arguments = intent.extras - if(arguments == null) { - activity?.finish() - return@ShiraBoxTheme - } - - val resourceId = arguments.getInt("id") - val type = arguments.getString("type")!!.let { ContentType.fromString(it) } - Surface( modifier = Modifier.fillMaxSize(), color = MaterialTheme.colorScheme.background ) { + val context = LocalContext.current + val activity = context as Activity? + + var resourceId: Int = -1 + lateinit var type: ContentType + + try { + val arguments = intent.extras!! + + resourceId = arguments.getInt("id") + type = arguments.getString("type").toString() + .let { ContentType.fromString(it) } + } catch (ex: Exception) { + ex.printStackTrace() + activity?.finish() + Toast.makeText(context, ex.localizedMessage, Toast.LENGTH_LONG).show() + } + Resource(resourceId, type, LocalContext.current) } }