Last active
November 6, 2020 11:18
-
-
Save mattiaferigutti/4612d283f0b04a55a4b9c45b74037d48 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| package com.mattiaferigutti.backdrop | |
| import android.os.Bundle | |
| import android.view.LayoutInflater | |
| import android.view.View | |
| import android.view.ViewGroup | |
| import com.google.android.material.bottomsheet.BottomSheetBehavior | |
| import com.google.android.material.bottomsheet.BottomSheetDialogFragment | |
| import kotlinx.android.synthetic.main.fragment_window.* | |
| class WindowFragment : BottomSheetDialogFragment(), OnBottomSheetCallbacks { | |
| private var currentState: Int = BottomSheetBehavior.STATE_EXPANDED | |
| override fun onCreateView( | |
| inflater: LayoutInflater, container: ViewGroup?, | |
| savedInstanceState: Bundle? | |
| ): View? { | |
| // Inflate the layout for this fragment | |
| (activity as MainActivity).setOnBottomSheetCallbacks(this) | |
| return inflater.inflate(R.layout.fragment_window, container, false) | |
| } | |
| override fun onViewCreated(view: View, savedInstanceState: Bundle?) { | |
| super.onViewCreated(view, savedInstanceState) | |
| textResult.setOnClickListener { | |
| (activity as MainActivity).openBottomSheet() | |
| } | |
| filterImage.setOnClickListener { | |
| if (currentState == BottomSheetBehavior.STATE_EXPANDED) { | |
| (activity as MainActivity).closeBottomSheet() | |
| } else { | |
| (activity as MainActivity).openBottomSheet() | |
| } | |
| } | |
| } | |
| override fun onStateChanged(bottomSheet: View, newState: Int) { | |
| currentState = newState | |
| when (newState) { | |
| BottomSheetBehavior.STATE_EXPANDED -> { | |
| textResult.text = "0 results" | |
| filterImage.setImageResource(R.drawable.ic_baseline_filter_list_24) | |
| } | |
| BottomSheetBehavior.STATE_COLLAPSED -> { | |
| textResult.text = "See the results" | |
| filterImage.setImageResource(R.drawable.ic_baseline_keyboard_arrow_up_24) | |
| } | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment