Skip to content

Instantly share code, notes, and snippets.

Avatar
🚀

faskN furkanaskin

🚀
View GitHub Profile
View Recent Activity
🎉 Merged PR #5 in furkanaskin/ClickablePieChart
🗣 Commented on #5 in furkanaskin/ClickablePieChart
🗣 Commented on #639 in PierfrancescoSoffritti/android-youtu...
🗣 Commented on #543 in PierfrancescoSoffritti/android-youtu...
🗣 Commented on #639 in PierfrancescoSoffritti/android-youtu...
View DataSenderFragment.kt
class DataSenderFragment : Fragment() {
// some stuff..
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
// Set data
findNavController().getBackStackEntry(R.id.gamesFragment).savedStateHandle.set("myData", "Test")
}
}
@furkanaskin
furkanaskin / BottomSheetSampleFragment.kt
Created May 13, 2020
findNavController().getBackStackEntry(R.id.gamesFragment).savedStateHandle.set("myData", "Test")
View BottomSheetSampleFragment.kt
class BottomSheetSampleFragment : BaseBottomSheetFragment() {
private var _binding: FragmentBottomSheetSampleBinding? = null
private val binding get() = _binding!!
val timerTotal = 600000L // 10 Min
lateinit var timer: CountDownTimer
override fun onCreateDialog(savedInstanceState: Bundle?): Dialog {
val dialog = super.onCreateDialog(savedInstanceState) as BottomSheetDialog
@furkanaskin
furkanaskin / BottomSheetSampleFragment.kt
Created May 13, 2020
findNavController().getBackStackEntry(R.id.gamesFragment).savedStateHandle.set("myData", "Test")
View BottomSheetSampleFragment.kt
class BottomSheetSampleFragment : BaseBottomSheetFragment() {
private var _binding: FragmentBottomSheetSampleBinding? = null
private val binding get() = _binding!!
val timerTotal = 600000L // 10 Min
lateinit var timer: CountDownTimer
override fun onCreateDialog(savedInstanceState: Bundle?): Dialog {
val dialog = super.onCreateDialog(savedInstanceState) as BottomSheetDialog
View build.gradle(app)
//navigation
implementation 'androidx.navigation:navigation-fragment-ktx:2.3.0-alpha05'
implementation 'androidx.navigation:navigation-ui-ktx:2.3.0-alpha05'
View BottomSheetSampleFragment.kt
class BottomSheetSampleFragment : BaseBottomSheetFragment() {
override fun onCreateDialog(savedInstanceState: Bundle?): Dialog {
val dialog = super.onCreateDialog(savedInstanceState) as BottomSheetDialog
dialog.setOnShowListener {
val bottomSheet =
(it as BottomSheetDialog).findViewById<View>(com.google.android.material.R.id.design_bottom_sheet) as FrameLayout?
val behavior = BottomSheetBehavior.from(bottomSheet!!)
behavior.state = BottomSheetBehavior.STATE_EXPANDED
behavior.isDraggable = false
View BaseBottomSheetFragment.kt
open class BaseBottomSheetFragment : BottomSheetDialogFragment() {
override fun onCreateDialog(savedInstanceState: Bundle?): Dialog {
val dialog = super.onCreateDialog(savedInstanceState)
if (dialog.window != null) {
dialog.window!!.setGravity(Gravity.BOTTOM)
dialog.window!!.setBackgroundDrawableResource(android.R.color.transparent)
dialog.window!!.clearFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND)
dialog.setCancelable(false)
}
return dialog
View SearchFragment.kt
binding.buttonDynamicTitleNavigate.setOnClickListener {
navigateWithAction(
SearchFragmentDirections.actionSearchFragmentToDynamicTitleFragment(
binding.editTextTitle.text.toString()
)
)
}
View nav_graph.xml
<fragment
android:id="@+id/dynamicTitleFragment"
android:name="com.faskn.trickynavigationsample.fragments.DynamicTitleFragment"
android:label="{title}"
tools:layout="@layout/fragment_dynamic_title" >
<argument
android:name="title"
app:argType="string"
android:defaultValue="Title" />
</fragment>
View MainActivity.kt
binding.toolbar.setNavigationOnClickListener {
when (navController.currentDestination?.id) {
R.id.searchFragment, R.id.gamesFragment, R.id.notificationsFragment -> {
if (onBackPressedDispatcher.hasEnabledCallbacks())
onBackPressedDispatcher.onBackPressed()
else
navController.navigateUp()
}
else -> navController.navigateUp()
}