Skip to content

Instantly share code, notes, and snippets.

View SomeView.kt
if (isCurrentLanguageRTL) {
etEmail.doOnTextChanged { text, start, before, count ->
etEmail.setSelection(0)
}
}
View SomeView.kt
if(isCurrentLanguageRTL) {
textView.gravity = Gravity.END
}
View MyCustomView.kt
override fun onRtlPropertiesChanged(layoutDirection: kotlin.Int) {
super.onRtlPropertiesChanged(layoutDirection)
//do magic
}
View View.kt
val layoutDirection = context.resources.configuration.layoutDirection
val viewLayoutDirection = view.layoutDirection
if (layoutDirection == View.LAYOUT_DIRECTION_RTL){
//do stuff
}
View WebViewFragment.kt
willLoadHtmlData = if(isCurrentLanguageRTL) <html dir=\"rtl\"><body> $mainHtmlData </body></html> else $mainHtmlData
@cengiztoru
cengiztoru / ExampleFragment.kt
Created Jul 8, 2021
TabLayout with ViewPager2
View ExampleFragment.kt
TabLayoutMediator(mTabLayout, mViewPager) { tab, position ->
tab.text = it[position].title
}.attach()
@cengiztoru
cengiztoru / HomeFragment.kt
Created Jul 1, 2020
Navigation Architectural Components - Getting Passed Data
View HomeFragment.kt
lateinit var user: User
val args: HomeFragmentArgs by navArgs()
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
user = args.user
}
override fun onCreateView(
inflater: LayoutInflater, container: ViewGroup?,
@cengiztoru
cengiztoru / LoginFragment.kt
Last active Jul 2, 2020
Navigation Architectural Component Pass Data With SafeArgs
View LoginFragment.kt
val user = getUserData()
val action = LoginFragmentDirections.actionLoginFragmentToHomeFragment(user)
navController.navigate(action)
// ************************************************************************************
//TODO YOU CAN CUSTOMIZE HERE FOR YOU
private fun getUserData() = User(etMail.text.toString(), "Cengiz", "TORU")
@cengiztoru
cengiztoru / HomeFragment.kt
Last active Jul 1, 2020
Navigation Architectural Component - Getting Passed Object
View HomeFragment.kt
lateinit var user: User
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
user = arguments!!.getParcelable<User>("user")!!
}
@cengiztoru
cengiztoru / LoginFragment.kt
Last active Jul 2, 2020
Navigation Architecture Components - Pass Object without SafeArgs
View LoginFragment.kt
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")