GSA - Generator Safe Arguments
A lightweight library that automates the creation of screens for Cicerone library usage
repositories {
mavenCentral()
}
dependencies {
implementation(" me.adkhambek.gsa:gsa-core:${ latest_version} " )
}
dependencies {
ksp(" me.adkhambek.gsa:ciceron-compiler:${ latest_version} " )
}
There are 2 ways we can access the safe arguments (args)
1st option is by using "by navArgs()"
2nd option is by calling requireArguments() inside .fromBundle method
abstract class Home private constructor()
@Screen(
installIn = Home ::class ,
)
class MainFragment : Fragment ()
@Screen(
installIn = Home ::class ,
args = [
Arg (
name = " user_name" ,
type = String ::class ,
),
Arg (
name = " user_id" ,
type = Long ::class ,
)
]
)
class ProfileFragment : Fragment () {
// 1 option
private val arg: ProfileScreenArgs by navArgs()
override fun onViewCreated (view : View , savedInstanceState : Bundle ? ) {
super .onViewCreated(view, savedInstanceState)
// 2 option
val args = ProfileScreenArgs .fromBundle(requireArguments())
}
}
This is an example class generated by GSA, which includes auto-generated factories and screens
// Arg holders
data class ProfileScreenArgs (
val userName : String ,
val userId : Long
) {
fun toBundle (): Bundle = TODO ()
companion object {
fun fromBundle (bundle : Bundle ): ProfileScreenArgs = TODO ()
}
}
// Cicerone Screen factories
@Suppress(" FunctionName" )
object HomeScreens {
@JvmStatic
fun MainScreen (): FragmentScreen {
return FragmentScreen {
MainFragment ()
}
}
@JvmStatic
fun ProfileScreen (userName : String ,userId : Long ): FragmentScreen {
val bundle : Bundle = TODO ()
return FragmentScreen {
MainFragment ().apply { arguments = bundle}
}
}
}