Skip to content

Instantly share code, notes, and snippets.

View cengiztoru's full-sized avatar
💻

Cengiz TORU cengiztoru

💻
View GitHub Profile
@cengiztoru
cengiztoru / LoginFragment.kt
Last active July 2, 2020 22:27
Navigation Architecture Components - Pass Object without SafeArgs
val bundle = Bundle()
bundle.putParcelable("user", getUserData())
navController.navigate(R.id.action_loginFragment_to_homeFragment, bundle)
// ************************************************************************************
//TODO YOU CAN CUSTOMIZE HERE FOR YOU
private fun getUserData() = User(etMail.text.toString(), "Cengiz", "TORU")
@cengiztoru
cengiztoru / navigation_graph.xml
Created July 1, 2020 21:06
Navigation Architecture Components Pass Object - Define Argument
<fragment
android:id="@+id/homeFragment"
android:name="com.cengiztoru.samplenavigationexample.ui.fragments.HomeFragment"
android:label="fragment_home"
tools:layout="@layout/fragment_home">
<argument
android:name="user"
app:argType="com.cengiztoru.samplenavigationexample.data.User"
app:nullable="false" />
@cengiztoru
cengiztoru / User.kt
Created July 1, 2020 21:02
Navigation Architecture Components Pass Object Model
@Parcelize
data class User(val email: String, val name: String, val surname: String) : Parcelable
@cengiztoru
cengiztoru / HomeFragment.kt
Last active July 1, 2020 20:59
Navigatiıon Architectural Components - Getting Passed Data
lateinit var email: String
lateinit var userID: Int
lateinit var isActive: Boolean
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
email = arguments!!.getString("email")!!
userID = arguments!!.getInt("userId")!!
isActive = arguments!!.getBoolean("isActive")!!
@cengiztoru
cengiztoru / navigation_graph.xml
Created July 1, 2020 20:46
Navigation Architectural Components Define Arguments
<fragment
android:id="@+id/homeFragment"
android:name="com.cengiztoru.samplenavigationexample.ui.fragments.HomeFragment"
android:label="fragment_home"
tools:layout="@layout/fragment_home">
<argument
android:name="email"
app:argType="string"
android:defaultValue="none" />
@cengiztoru
cengiztoru / LoginFragment.kt
Last active July 1, 2020 20:51
Navigation Architectural Component - Pass Primitive Data Without SafeArgs
//PASS DATA WITHOUT SAFE ARGS, PASS DATA BY SIMPLE BUNDLE
val bundle = Bundle()
bundle.putString("email", etMail.text.toString())
bundle.putInt("userID", 123)
bundle.putBoolean("isActive",false)
// ...
navController.navigate(R.id.action_loginFragment_to_homeFragment, bundle)
@cengiztoru
cengiztoru / navigation_graph.xml
Created July 1, 2020 16:57
Animation With Action
<fragment
android:id="@+id/loginFragment"
android:name="com.cengiztoru.samplenavigationexample.ui.fragments.LoginFragment"
android:label="fragment_login"
tools:layout="@layout/fragment_login">
<action
app:enterAnim="@anim/slide_in_right"
app:exitAnim="@anim/slide_out_left"
app:popEnterAnim="@anim/slide_in_left"
@cengiztoru
cengiztoru / navigation_graph.xml
Last active July 1, 2020 16:51
Prevent Bactracking
<fragment
android:id="@+id/loginFragment"
android:name="com.cengiztoru.samplenavigationexample.ui.fragments.LoginFragment"
android:label="fragment_login"
tools:layout="@layout/fragment_login">
<action
app:popUpTo="@id/loginFragment"
app:popUpToInclusive="true"
@cengiztoru
cengiztoru / navigation_graph.xml
Created July 1, 2020 16:38
Navigation Architectural Component
<fragment
android:id="@+id/loginFragment"
android:name="com.cengiztoru.samplenavigationexample.ui.fragments.LoginFragment"
android:label="fragment_login"
tools:layout="@layout/fragment_login">
<action
android:id="@+id/action_loginFragment_to_signupFragment"
app:destination="@id/signupFragment"/>
@cengiztoru
cengiztoru / LoginFragment.kt
Created July 1, 2020 16:31
Navigation Architectural Component
lateinit var navController: NavController
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
navController = Navigation.findNavController(view)
btnSignup.setOnClickListener {
navController.navigate(R.id.action_loginFragment_to_signupFragment)
}