Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added serialization / deserialization ability for AppScreen #144

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -6,10 +6,11 @@ import android.os.Bundle
import androidx.fragment.app.Fragment
import androidx.fragment.app.FragmentFactory
import com.github.terrakok.cicerone.Screen
import java.io.Serializable

sealed class AppScreen : Screen
sealed class AppScreen : Screen, Serializable

fun interface Creator<A, R> {
fun interface Creator<A, R>: Serializable {
fun create(argument: A): R
}

Expand All @@ -28,4 +29,4 @@ open class ActivityScreen @JvmOverloads constructor(
override val screenKey: String get() = key ?: super.screenKey
open val startActivityOptions: Bundle? = null
fun createIntent(context: Context) = intentCreator.create(context)
}
}
Expand Up @@ -28,8 +28,11 @@ object Screens {
Intent(it, StartActivity::class.java)
}

fun Main() = ActivityScreen {
Intent(it, MainActivity::class.java)
// Consider to use val and upper-case naming
val MAIN = ActivityScreen {
Intent(it, MainActivity::class.java).apply {
putExtra("sampleScreen", Sample(1))
}
}

fun BottomNavigation() = ActivityScreen {
Expand Down Expand Up @@ -59,4 +62,4 @@ object Screens {
fun SelectPhoto(resultKey: String) = FragmentScreen {
SelectPhotoFragment.getNewInstance(resultKey)
}
}
}
@@ -1,8 +1,8 @@
package com.github.terrakok.cicerone.sample.mvp.start

import com.github.terrakok.cicerone.Router
import com.github.terrakok.cicerone.sample.Screens
import com.github.terrakok.cicerone.sample.Screens.BottomNavigation
import com.github.terrakok.cicerone.sample.Screens.Main
import com.github.terrakok.cicerone.sample.Screens.Profile
import moxy.MvpPresenter

Expand All @@ -12,7 +12,7 @@ import moxy.MvpPresenter
class StartActivityPresenter(private val router: Router) : MvpPresenter<StartActivityView>() {

fun onOrdinaryPressed() {
router.navigateTo(Main())
router.navigateTo(Screens.MAIN)
}

fun onMultiPressed() {
Expand All @@ -27,4 +27,4 @@ class StartActivityPresenter(private val router: Router) : MvpPresenter<StartAct
router.exit()
}

}
}
Expand Up @@ -8,7 +8,9 @@ import com.github.terrakok.cicerone.Command
import com.github.terrakok.cicerone.Navigator
import com.github.terrakok.cicerone.NavigatorHolder
import com.github.terrakok.cicerone.Replace
import com.github.terrakok.cicerone.Router
import com.github.terrakok.cicerone.androidx.AppNavigator
import com.github.terrakok.cicerone.androidx.FragmentScreen
import com.github.terrakok.cicerone.sample.R
import com.github.terrakok.cicerone.sample.SampleApplication
import com.github.terrakok.cicerone.sample.Screens.Sample
Expand All @@ -31,6 +33,9 @@ class MainActivity : MvpAppCompatActivity(), ChainHolder {
@Inject
lateinit var navigatorHolder: NavigatorHolder

@Inject
lateinit var router: Router

private val navigator: Navigator = object : AppNavigator(this, R.id.main_container) {

override fun applyCommands(commands: Array<out Command>) {
Expand All @@ -48,7 +53,9 @@ class MainActivity : MvpAppCompatActivity(), ChainHolder {
screensSchemeTV = findViewById<View>(R.id.screens_scheme) as TextView

if (savedInstanceState == null) {
navigator.applyCommands(arrayOf<Command>(Replace(Sample(1))))
// Just for sample of deserialization
val sampleScreen = intent.getSerializableExtra("sampleScreen") as FragmentScreen
router.replaceScreen(sampleScreen)
} else {
printScreensScheme()
}
Expand Down Expand Up @@ -92,4 +99,4 @@ class MainActivity : MvpAppCompatActivity(), ChainHolder {
}
screensSchemeTV.text = "Chain: $keys"
}
}
}