Skip to content

Commit

Permalink
Added null checks for setting bottom app bar's visibility
Browse files Browse the repository at this point in the history
  • Loading branch information
leahlud committed Feb 19, 2024
1 parent f2d7379 commit f52abe7
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,32 +16,38 @@ class AttendeeScannerFragment : Fragment() {
val view = inflater.inflate(R.layout.fragment_attendee_scanner, container, false)

// get bottom app bar and scanner button views from the MainActivity
val appBar = activity!!.findViewById<BottomAppBar>(R.id.bottomAppBar)
val scannerBtn = activity!!.findViewById<FloatingActionButton>(R.id.code_entry_fab)
val appBar = activity?.findViewById<BottomAppBar>(R.id.bottomAppBar)
val scannerBtn = activity?.findViewById<FloatingActionButton>(R.id.code_entry_fab)

// when event check in button is clicked
val eventCheckInButton = view.findViewById<Button>(R.id.eventCheckInBtn)
eventCheckInButton.setOnClickListener {
appBar.visibility = View.INVISIBLE
scannerBtn.visibility = View.INVISIBLE
if (appBar != null && scannerBtn != null) {
appBar.visibility = View.INVISIBLE
scannerBtn.visibility = View.INVISIBLE
}
val scannerFragment = ScannerFragment.newInstance("event-check-in")
(context as MainActivity).switchFragment(scannerFragment, true)
}

// when mentor check in button is clicked
val mentorCheckInButton = view.findViewById<Button>(R.id.mentorCheckInBtn)
mentorCheckInButton.setOnClickListener {
appBar.visibility = View.INVISIBLE
scannerBtn.visibility = View.INVISIBLE
if (appBar != null && scannerBtn != null) {
appBar.visibility = View.INVISIBLE
scannerBtn.visibility = View.INVISIBLE
}
val scannerFragment = ScannerFragment.newInstance("mentor-check-in")
(context as MainActivity).switchFragment(scannerFragment, true)
}

// when point shop button is clicked
val pointShopButton = view.findViewById<Button>(R.id.pointShopBtn)
pointShopButton.setOnClickListener {
appBar.visibility = View.INVISIBLE
scannerBtn.visibility = View.INVISIBLE
if (appBar != null && scannerBtn != null) {
appBar.visibility = View.INVISIBLE
scannerBtn.visibility = View.INVISIBLE
}
val scannerFragment = ScannerFragment.newInstance("point-shop")
(context as MainActivity).switchFragment(scannerFragment, true)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -337,10 +337,12 @@ class ScannerFragment : Fragment(), SimpleScanDialogFragment.OnSimpleOKButtonSel

private fun closeScannerPage() {
// set bottom app bar visible again and pop scanner fragment from the backstack
val appBar = activity!!.findViewById<BottomAppBar>(R.id.bottomAppBar)
val scannerBtn = activity!!.findViewById<FloatingActionButton>(R.id.code_entry_fab)
appBar.visibility = View.VISIBLE
scannerBtn.visibility = View.VISIBLE
val appBar = activity?.findViewById<BottomAppBar>(R.id.bottomAppBar)
val scannerBtn = activity?.findViewById<FloatingActionButton>(R.id.code_entry_fab)
if (appBar != null && scannerBtn != null) {
appBar.visibility = View.VISIBLE
scannerBtn.visibility = View.VISIBLE
}
activity?.supportFragmentManager?.popBackStackImmediate()
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,23 +16,27 @@ class StaffScannerFragment : Fragment() {
val view = inflater.inflate(R.layout.fragment_staff_scanner, container, false)

// get bottom app bar and scanner button views from the MainActivity
val appBar = activity!!.findViewById<BottomAppBar>(R.id.bottomAppBar)
val scannerBtn = activity!!.findViewById<FloatingActionButton>(R.id.code_entry_fab)
val appBar = activity?.findViewById<BottomAppBar>(R.id.bottomAppBar)
val scannerBtn = activity?.findViewById<FloatingActionButton>(R.id.code_entry_fab)

// when meeting attendance button is clicked
val meetingAttendanceButton = view.findViewById<Button>(R.id.staffMeetingBtn)
meetingAttendanceButton.setOnClickListener {
appBar.visibility = View.INVISIBLE
scannerBtn.visibility = View.INVISIBLE
if (appBar != null && scannerBtn != null) {
appBar.visibility = View.INVISIBLE
scannerBtn.visibility = View.INVISIBLE
}
val scannerFragment = ScannerFragment.newInstance("meeting-attendance")
(context as MainActivity).switchFragment(scannerFragment, true)
}

// when attendee check in button is clicked
val attendeeCheckInButton = view.findViewById<Button>(R.id.attendeeCheckInBtn)
attendeeCheckInButton.setOnClickListener {
appBar.visibility = View.INVISIBLE
scannerBtn.visibility = View.INVISIBLE
if (appBar != null && scannerBtn != null) {
appBar.visibility = View.INVISIBLE
scannerBtn.visibility = View.INVISIBLE
}
val scannerFragment = ScannerFragment.newInstance("attendee-check-in")
(context as MainActivity).switchFragment(scannerFragment, true)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,12 @@ class EventInfoFragment : Fragment() {
)

// set bottom app bar invisible
val appBar = activity!!.findViewById<BottomAppBar>(R.id.bottomAppBar)
val scannerBtn = activity!!.findViewById<FloatingActionButton>(R.id.code_entry_fab)
appBar.visibility = View.INVISIBLE
scannerBtn.visibility = View.INVISIBLE

val appBar = activity?.findViewById<BottomAppBar>(R.id.bottomAppBar)
val scannerBtn = activity?.findViewById<FloatingActionButton>(R.id.code_entry_fab)
if (appBar != null && scannerBtn != null) {
appBar.visibility = View.INVISIBLE
scannerBtn.visibility = View.INVISIBLE
}
// get bundle arguments and set up viewModel
eventId = arguments?.getString(EVENT_ID_KEY) ?: ""
isAttendeeViewing = arguments?.getBoolean(IS_ATTENDEE_VIEWING) ?: false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,12 @@ class ScheduleFragment : Fragment() {
scheduleBackground.setImageResource(R.drawable.dark_fantasy_bg_2024)

// set bottom app bar visible again and pop scanner fragment from the backstack
val appBar = activity!!.findViewById<BottomAppBar>(R.id.bottomAppBar)
val scannerBtn = activity!!.findViewById<FloatingActionButton>(R.id.code_entry_fab)
appBar.visibility = View.VISIBLE
scannerBtn.visibility = View.VISIBLE
val appBar = activity?.findViewById<BottomAppBar>(R.id.bottomAppBar)
val scannerBtn = activity?.findViewById<FloatingActionButton>(R.id.code_entry_fab)
if (appBar != null && scannerBtn != null) {
appBar.visibility = View.VISIBLE
scannerBtn.visibility = View.VISIBLE
}

scheduleViewModel = ViewModelProviders.of(this).get(ScheduleViewModel::class.java)
scheduleViewModel.initEvents()
Expand Down

0 comments on commit f52abe7

Please sign in to comment.