Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Staff attendance scanner #486

Closed
wants to merge 27 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
7c0a299
fixed file formatting
leahlud Aug 12, 2023
4632848
fixed ktlint issue
leahlud Aug 12, 2023
416ca71
Added new fragment for staff scanner
leahlud Aug 14, 2023
1984bdb
updated xml to use defined color
leahlud Aug 14, 2023
91c6798
fixed formatting
leahlud Aug 14, 2023
473f503
Added code for switching fragments in MainActivity
leahlud Aug 14, 2023
bf3e33a
Removed old view models for Project
leahlud Aug 14, 2023
62c69d9
Delete GroupmatchingViewModel.kt
leahlud Aug 14, 2023
e09d22f
Update strings.xml
leahlud Aug 14, 2023
802673f
Update fragment_staff_scanner.xml
leahlud Aug 14, 2023
b99244c
fix formatting
leahlud Aug 14, 2023
9aedaa5
setup staff scanner fragment
leahlud Aug 14, 2023
cfe780a
created staff scanner viewModel
leahlud Aug 14, 2023
f319b0e
added code for switching to scanner fragment from staff fragment
leahlud Aug 14, 2023
e1c1ef9
Update StaffScannerFragment.kt
leahlud Aug 14, 2023
055d7a3
Removed StaffScannerViewModel and fixed formatting
leahlud Aug 14, 2023
fed21c2
fixed import formatting
leahlud Aug 14, 2023
c6654d3
Update StaffScannerFragment.kt
leahlud Aug 14, 2023
b3bc7be
Updated comments in StaffScannerFragment
leahlud Aug 14, 2023
b2eff1e
Added logic for meeting attendance
leahlud Aug 14, 2023
d23295e
Merge remote-tracking branch 'origin/development' into staff-attendan…
leahlud Sep 9, 2023
bd144f4
Fixed top margin on Profile page
leahlud Sep 10, 2023
fda3e4b
Added attendance title to scanner page
leahlud Sep 10, 2023
54651f3
Updated formatting of attendance buttons
leahlud Sep 10, 2023
843a339
Fixed code formatting in scanner layout file
leahlud Sep 10, 2023
66ccedc
Changed constraints on scanner chip group
leahlud Sep 10, 2023
e95d9ec
Updated comment in API.kt
leahlud Sep 11, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/src/main/java/org/hackillinois/android/API.kt
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import retrofit2.http.*
interface API {

// AUTH
// note: @GET("auth/login/{provider}/") is not part of this file because the URL
// note: @GET("auth/login/{provider}/") is not called in this file because the URL
// is directly accessed in the LoginActivity.kt file to get to the OAuth page

@GET("auth/roles/")
Expand Down
21 changes: 14 additions & 7 deletions app/src/main/java/org/hackillinois/android/view/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import androidx.appcompat.app.AppCompatActivity
import androidx.core.content.ContextCompat
import androidx.fragment.app.Fragment
import androidx.fragment.app.FragmentTransaction
import androidx.lifecycle.ViewModelProviders
import androidx.lifecycle.ViewModelProvider
import com.google.firebase.FirebaseApp
import com.google.firebase.messaging.FirebaseMessaging
import kotlinx.android.synthetic.main.activity_main.*
Expand All @@ -26,6 +26,7 @@ import org.hackillinois.android.view.leaderboard.LeaderboardFragment
import org.hackillinois.android.view.onboarding.OnboardingActivity
import org.hackillinois.android.view.profile.ProfileFragment
import org.hackillinois.android.view.scanner.ScannerFragment
import org.hackillinois.android.view.scanner.StaffScannerFragment
import org.hackillinois.android.view.schedule.ScheduleFragment
import org.hackillinois.android.viewmodel.MainViewModel
import kotlin.concurrent.thread
Expand All @@ -48,7 +49,8 @@ class MainActivity : AppCompatActivity() {
val startFragment = HomeFragment()
supportFragmentManager.beginTransaction().replace(R.id.contentFrame, startFragment).commit()

viewModel = ViewModelProviders.of(this).get(MainViewModel::class.java).apply {
// ViewModelProvider(this).get(ProfileViewModel::class.java)
viewModel = ViewModelProvider(this).get(MainViewModel::class.java).apply {
init()
val owner = this@MainActivity
}
Expand All @@ -63,7 +65,7 @@ class MainActivity : AppCompatActivity() {
bottomAppBar.homeButton,
bottomAppBar.scheduleButton,
bottomAppBar.leaderboard,
bottomAppBar.profile
bottomAppBar.profile,
)

// by default, home button is selected
Expand Down Expand Up @@ -94,16 +96,21 @@ class MainActivity : AppCompatActivity() {
private fun setupCodeEntrySheet() {
val inflater: LayoutInflater = layoutInflater

val scannerFragment = ScannerFragment()

code_entry_fab.setOnClickListener {
if (!hasLoggedIn()) {
val toast = Toast.makeText(applicationContext, getString(R.string.login_error_msg), Toast.LENGTH_LONG)
// ((toast.view as LinearLayout).getChildAt(0) as TextView).gravity = Gravity.CENTER_HORIZONTAL
toast.show()
// Snackbar.make(findViewById(android.R.id.content), getString(R.string.login_error_msg), Snackbar.LENGTH_SHORT).show()
} else {
switchFragment(scannerFragment, true)
val scannerFragment = ScannerFragment()
val staffScannerFragment = StaffScannerFragment()
// if staff, send them to fragment to select meeting attendance or attendee check-in
// if attendee, send them right to the scanner fragment
if (isStaff()) {
switchFragment(staffScannerFragment, true)
} else {
switchFragment(scannerFragment, true)
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ class EventInfoFragment : Fragment(), OnMapReadyCallback {
if (mapIsReady && !mapUpdated) {
setupMap()
}
}
},
)
viewModel.isFavorited.observe(this, Observer { updateFavoritedUI(it) })
}
Expand Down Expand Up @@ -84,7 +84,7 @@ class EventInfoFragment : Fragment(), OnMapReadyCallback {
override fun onCreateView(
inflater: LayoutInflater,
container: ViewGroup?,
savedInstanceState: Bundle?
savedInstanceState: Bundle?,
): View? {
val view = inflater.inflate(R.layout.fragment_event_info, container, false)
view.exit_button.setOnClickListener { activity?.onBackPressed() }
Expand Down Expand Up @@ -136,7 +136,7 @@ class EventInfoFragment : Fragment(), OnMapReadyCallback {
var marker = googleMap.addMarker(
MarkerOptions()
.position(latLng)
.title(eventLocation.description)
.title(eventLocation.description),
)
Log.i("Map", marker.toString())
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ class ProfileFragment : Fragment() {
override fun onCreateView(
inflater: LayoutInflater,
container: ViewGroup?,
savedInstanceState: Bundle?
savedInstanceState: Bundle?,
): View? {
if (!hasLoggedIn() or (hasLoggedIn() and isStaff())) {
val view = inflater.inflate(R.layout.fragment_profile_not_logged_in, container, false)
Expand Down Expand Up @@ -244,7 +244,7 @@ class ProfileFragment : Fragment() {
val context = requireActivity().applicationContext
return context.getSharedPreferences(
context.getString(R.string.authorization_pref_file_key),
Context.MODE_PRIVATE
Context.MODE_PRIVATE,
).getString("provider", "") ?: "" == "google"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ class ScannerFragment : Fragment() {

private lateinit var eventId: String
private lateinit var eventName: String
private var isMeetingAttendance: Boolean = false

private lateinit var codeScanner: CodeScanner

Expand All @@ -55,6 +56,7 @@ class ScannerFragment : Fragment() {

eventId = arguments?.getString(EVENT_ID_KEY) ?: ""
eventName = arguments?.getString(EVENT_NAME_KEY) ?: ""
isMeetingAttendance = arguments?.getBoolean(IS_MEETING_ATTENDANCE_KEY) ?: false

viewModel = ViewModelProviders.of(this).get(ScannerViewModel::class.java).apply {
init(eventName)
Expand All @@ -66,14 +68,14 @@ class ScannerFragment : Fragment() {
} else {
displayScanResult(it)
}
}
},
)
roles.observe(
this@ScannerFragment,
Observer {
userRoles = it
showStaffChipGroup(it)
}
},
)
}
}
Expand Down Expand Up @@ -120,6 +122,11 @@ class ScannerFragment : Fragment() {
}

closeButton.setOnClickListener {
// need to add logic for popping this fragment and StaffScannerFragment?
// if (isStaff()) {
// activity?.supportFragmentManager?.popBackStack()
// activity?.supportFragmentManager?.popBackStack()
// }
activity?.supportFragmentManager?.popBackStackImmediate()
}

Expand All @@ -137,9 +144,14 @@ class ScannerFragment : Fragment() {
Log.d("USER QR CODE", userString)
viewModel.checkUserIntoEventAsStaff(userString, getStaffCheckInEventId())
} else {
val eventId: String = getEventCodeFromQrString(it.text)
Log.d("EVENT CODE STRING", it.toString())
viewModel.scanQrToCheckIn(eventId)
// add code for meeting attendance
if (isMeetingAttendance) {
// TODO
} else {
val eventId: String = getEventCodeFromQrString(it.text)
Log.d("EVENT CODE STRING", it.toString())
viewModel.scanQrToCheckIn(eventId)
}
}
}
errorCallback = ErrorCallback {
Expand Down Expand Up @@ -196,6 +208,7 @@ class ScannerFragment : Fragment() {

private fun displayStaffScanResult(lastScanStatus: ScanStatus?) = lastScanStatus?.let {
val responseString = when (it.userMessage) {
// TODO update to add meeting attendance error?
"Success" -> "Success! The attendant has the following dietary restrictions: ${it.dietary}"
"InvalidEventId" -> "The event code doesn't seem to be correct. Try selecting the event again or select another event"
"BadUserToken" -> "The QR code may have expired or might be invalid. Please refresh the QR code and try again"
Expand Down Expand Up @@ -231,7 +244,7 @@ class ScannerFragment : Fragment() {
}

private fun showStaffChipGroup(it: Roles?) = it?.let {
staffChipGroup.visibility = if (it.isStaff()) View.VISIBLE else View.INVISIBLE
staffChipGroup.visibility = if (it.isStaff() && !isMeetingAttendance) View.VISIBLE else View.INVISIBLE
}

private fun getStaffCheckInEventId(): String {
Expand All @@ -251,12 +264,14 @@ class ScannerFragment : Fragment() {
companion object {
val EVENT_ID_KEY = "event_id"
val EVENT_NAME_KEY = "event_name"
val IS_MEETING_ATTENDANCE_KEY = "is_meeting_attendance_key"

fun newInstance(eventId: String, eventName: String): ScannerFragment {
fun newInstance(eventId: String, eventName: String, isMeetingAttendance: Boolean): ScannerFragment {
val fragment = ScannerFragment()
val args = Bundle().apply {
putString(EVENT_ID_KEY, eventId)
putString(EVENT_NAME_KEY, eventName)
putBoolean(IS_MEETING_ATTENDANCE_KEY, isMeetingAttendance)
}
fragment.arguments = args
return fragment
Expand All @@ -267,7 +282,7 @@ class ScannerFragment : Fragment() {
val context = requireActivity().applicationContext
return context.getSharedPreferences(
context.getString(R.string.authorization_pref_file_key),
Context.MODE_PRIVATE
Context.MODE_PRIVATE,
).getString("provider", "") ?: "" == "google"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package org.hackillinois.android.view.scanner

import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.Button
import androidx.fragment.app.Fragment
import org.hackillinois.android.R
import org.hackillinois.android.view.MainActivity

class StaffScannerFragment : Fragment() {
override fun onCreateView(
inflater: LayoutInflater,
container: ViewGroup?,
savedInstanceState: Bundle?,
): View? {
val view = inflater.inflate(R.layout.fragment_staff_scanner, container, false)

// when meeting attendance button is clicked
val meetingAttendanceButton = view.findViewById<Button>(R.id.staffMeetingBtn)
meetingAttendanceButton.setOnClickListener {
val scannerFragment = ScannerFragment.newInstance("", "", true)
(context as MainActivity).switchFragment(scannerFragment, true)
}

// when attendee check-in button is clicked
val staffCheckInButton = view.findViewById<Button>(R.id.staffCheckInBtn)
staffCheckInButton.setOnClickListener {
val scannerFragment = ScannerFragment.newInstance("", "", false)
(context as MainActivity).switchFragment(scannerFragment, true)
}

return view
}
}

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,9 @@ class ScannerViewModel : ViewModel() {
"",
false,
RegistrationData(
AttendeeData(listOf())
)
)
AttendeeData(listOf()),
),
),
)
viewModelScope.launch {
try {
Expand All @@ -97,8 +97,10 @@ class ScannerViewModel : ViewModel() {
.attendee
.dietary
.joinToString()
} else "Bad User Token"
)
} else {
"Bad User Token"
},
),
)
} catch (e: Exception) {
Log.e("Staff Check In", e.toString())
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:width="30dp"
android:height="30dp"
android:viewportWidth="24.0"
android:viewportHeight="24.0">
<path
android:fillColor="@color/primaryGrayColor"
android:fillColor="@color/white"
android:pathData="M19,6.41L17.59,5 12,10.59 6.41,5 5,6.41 10.59,12 5,17.59 6.41,19 12,13.41 17.59,19 19,17.59 13.41,12z"/>
</vector>
2 changes: 1 addition & 1 deletion app/src/main/res/layout/activity_login.xml
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginBottom="16dp"
android:backgroundTint="#1D2644"
android:backgroundTint="@color/midnight"
android:text="@string/attendee_login"
android:textColor="@android:color/white"
android:textSize="16sp"
Expand Down
Loading
Loading