Created
February 22, 2020 20:08
-
-
Save AliAzaz/329c75874285ee6ff7de5336c41feaf8 to your computer and use it in GitHub Desktop.
Defines both the navigation and receiving arguments
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
class RegistrationFragment : Fragment() { | |
private lateinit var bi: FragmentRegistrationBinding | |
lateinit var vModel: MainViewModel | |
private val flag: RegistrationFragmentArgs by navArgs() | |
override fun onCreate(savedInstanceState: Bundle?) { | |
super.onCreate(savedInstanceState) | |
vModel = activity?.run { | |
ViewModelProviders.of(this)[MainViewModel::class.java] | |
} ?: throw Exception("Invalid Activity") | |
} | |
override fun onCreateView( | |
inflater: LayoutInflater, container: ViewGroup?, | |
savedInstanceState: Bundle? | |
): View? { | |
bi = FragmentRegistrationBinding.inflate(inflater, container, false) | |
bi.callback = this | |
return bi.root | |
} | |
fun BtnStart() { | |
if (!Validator.emptyCheckingContainer(layoutInflater.context, bi.fldGrpA)) | |
return | |
// Set Users | |
vModel.setUsers(listOf(bi.fName.text.toString(), bi.sName.text.toString())) | |
// Navigation | |
findNavController().navigate(RegistrationFragmentDirections.actionRegistrationFragmentToFirstFragment()) | |
} | |
override fun onActivityCreated(savedInstanceState: Bundle?) { | |
super.onActivityCreated(savedInstanceState) | |
(activity as AppCompatActivity?)!!.supportActionBar!!.hide() | |
} | |
override fun onViewCreated(view: View, savedInstanceState: Bundle?) { | |
super.onViewCreated(view, savedInstanceState) | |
// Get NavArguments | |
bi.txtHead.visibility = | |
if (flag.welcomeFlag) View.VISIBLE else View.GONE // getting argument data | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment