Advertisement
Guest User

Untitled

a guest
Feb 21st, 2019
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.47 KB | None | 0 0
  1. class MainFragment : android.app.Fragment() {
  2. // TODO: Rename and change types of parameters
  3. private var param1: String? = null
  4. private var param2: String? = null
  5.  
  6. lateinit var navigationView: BottomNavigationView
  7.  
  8. override fun onCreate(savedInstanceState: Bundle?) {
  9. super.onCreate(savedInstanceState)
  10. arguments?.let {
  11. // param1 = it.getString(ARG_PARAM1)
  12. // param2 = it.getString(ARG_PARAM2)
  13. }
  14. }
  15.  
  16. override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?,
  17. savedInstanceState: Bundle?): View? {
  18. // Inflate the layout for this fragment
  19. var view : View = inflater.inflate(R.layout.fragment_main, container, false)
  20. navigationView = view.findViewById(R.id.navigation)
  21. navigationView.setOnNavigationItemReselectedListener{mOnNavigationItemSelectedListener}
  22.  
  23.  
  24.  
  25. return view
  26. }
  27.  
  28. private val mOnNavigationItemSelectedListener = BottomNavigationView.OnNavigationItemSelectedListener { item ->
  29. when (item.itemId) {
  30. R.id.navigation_daylifeed -> {
  31. //message.setText(R.string.title_home)
  32. openFragment("DailyFeedFragment")
  33. return@OnNavigationItemSelectedListener true
  34. }
  35. R.id.navigation_notices -> {
  36. //message.setText(R.string.title_dashboard)
  37. openFragment("NoticesFragment")
  38. return@OnNavigationItemSelectedListener true
  39. }
  40. R.id.navigation_attendence -> {
  41. //message.setText(R.string.title_notifications)
  42. openFragment("AttendenceFragment")
  43. return@OnNavigationItemSelectedListener true
  44. }
  45. }
  46. false
  47. }
  48.  
  49.  
  50.  
  51. fun openFragment(fragment: String) {
  52. val manager = fragmentManager
  53.  
  54. val transaction = manager.beginTransaction()
  55. // animation
  56. // transaction.setCustomAnimations(android.R.animator.fade_in, android.R.animator.fade_out)
  57. if(fragment.equals("DailyFeedFragment")) {
  58. transaction.replace(R.id.frame_container, DailyFeedFragment.newInstance("", "")) // newInstance() is a static factory method.
  59. transaction.addToBackStack(null)
  60. transaction.commit()
  61. }
  62. else if(fragment.equals("NoticesFragment")){
  63. transaction.replace(R.id.frame_container, NoticesFragment.newInstance("", "")) // newInstance() is a static factory method.
  64. transaction.addToBackStack(null)
  65. transaction.commit()
  66. }
  67. else{
  68. transaction.replace(R.id.frame_container, AttendenceFragment.newInstance("", "")) // newInstance() is a static factory method.
  69. transaction.addToBackStack(null)
  70. transaction.commit()
  71. }
  72. }
  73.  
  74.  
  75. companion object {
  76. /**
  77. * Use this factory method to create a new instance of
  78. * this fragment using the provided parameters.
  79. *
  80. * @param param1 Parameter 1.
  81. * @param param2 Parameter 2.
  82. * @return A new instance of fragment MainFragment.
  83. */
  84. // TODO: Rename and change types and number of parameters
  85. @JvmStatic
  86. fun newInstance(param1: String, param2: String) =
  87. MainFragment().apply {
  88. arguments = Bundle().apply {
  89. // putString(ARG_PARAM1, param1)
  90. // putString(ARG_PARAM2, param2)
  91. }
  92. }
  93. }
  94. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement