Last active
June 3, 2019 13:32
-
-
Save angusholder/12a8c5974b2cba0f96cf0ca5a5f12754 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@file:SuppressLint("ValidController") | |
package co.mopo.android.ui | |
import android.annotation.SuppressLint | |
import android.os.Bundle | |
import android.view.LayoutInflater | |
import android.view.View | |
import android.view.ViewGroup | |
import co.mopo.android.data.disk.AppDatabase | |
import com.bluelinelabs.conductor.Controller | |
import com.bluelinelabs.conductor.RouterTransaction | |
import org.threeten.bp.Clock | |
class ControllerRestorer2(private val map: Map<Class<out Controller>, ControllerFactoryAssisted<Controller>>) : ControllerRestorer { | |
override fun restoreController(clazz: Class<out Controller>, bundle: Bundle): Controller { | |
val factory = map[clazz] | |
?: throw IllegalArgumentException("There is no registered Controller ${clazz.name}") | |
return factory.create(bundle) | |
} | |
} | |
interface ControllerFactoryAssisted <T : Controller> { | |
fun create(@Assisted bundle: Bundle): T | |
} | |
class ChildController @AssistedInject constructor( | |
bundle: Bundle, | |
private val database: AppDatabase, | |
private val clock: Clock | |
) : Controller(bundle) { | |
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup): View { | |
TODO("not implemented") | |
} | |
@AssistedInject.Factory | |
interface Factory : ControllerFactoryAssisted<ChildController> { | |
fun create(userId: String): ChildController = create(Bundle().apply { | |
putString("userId", userId) | |
}) | |
} | |
} | |
class ParentController @AssistedInject constructor( | |
bundle: Bundle, | |
private val database: AppDatabase, | |
private val clock: Clock, | |
private val childFactory: ChildController.Factory | |
) : Controller(bundle) { | |
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup): View { | |
router.pushController(RouterTransaction.with(childFactory.create("0123abcd"))) | |
TODO("not implemented") | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment