Skip to content

Commit

Permalink
Merge pull request #489 from HackIllinois/leah/staff-attendance-new-b…
Browse files Browse the repository at this point in the history
…ackground

Staff meeting attendance w/ new background
  • Loading branch information
leahlud authored Oct 4, 2023
2 parents a873560 + bafaa9b commit 691b347
Show file tree
Hide file tree
Showing 12 changed files with 74 additions and 111 deletions.
7 changes: 4 additions & 3 deletions app/src/main/java/org/hackillinois/android/API.kt
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import org.hackillinois.android.model.profile.ProfileList
import org.hackillinois.android.model.projects.ProjectsList
import org.hackillinois.android.notifications.DeviceToken
import retrofit2.Call
import retrofit2.Response
import retrofit2.http.*

interface API {
Expand Down Expand Up @@ -51,8 +50,10 @@ interface API {
@POST("event/staff/checkin/")
suspend fun checkInUserAsStaff(@Body userTokenEventIdPair: UserTokenEventIdPair): EventCheckInAsStaffResponse

@POST("event/staff/attendance/")
suspend fun staffMeetingCheckIn(@Body eventId: MeetingEventId): Response<Void>
// STAFF

@POST("staff/attendance/")
suspend fun staffMeetingCheckIn(@Body eventId: MeetingEventId): MeetingCheckInResponse

// NOTIFICATIONS

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ data class EventCode(val code: String)
data class MeetingEventId(val eventId: String)

data class MeetingCheckInResponse(var status: String)

data class EventCheckInResponse(
val newPoints: Int,
val totalPoints: Int,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,9 @@ class EventRepository {
withContext(Dispatchers.IO) {
try {
val body = MeetingEventId(eventId)
App.getAPI().staffMeetingCheckIn(body)
apiResponse.status = "Success" // no response is sent from API, so just manually done
apiResponse = App.getAPI().staffMeetingCheckIn(body) // 200: status = "Success"
} catch (e: Exception) {
apiResponse.status = e.message.toString()
Log.d("STAFF MEETING API ERROR", "${e.message}")
}
}
Expand Down
14 changes: 14 additions & 0 deletions app/src/main/java/org/hackillinois/android/view/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import android.content.Intent
import android.os.Bundle
import android.util.Log
import android.view.View
import android.view.WindowManager
import android.widget.ImageButton
import android.widget.Toast
import androidx.appcompat.app.AppCompatActivity
Expand Down Expand Up @@ -80,6 +81,12 @@ class MainActivity : AppCompatActivity() {
if (newSelection != currentSelection) {
currentSelection = newSelection

val nightBlue = ContextCompat.getColor(this, R.color.nightBlue)
val window = window
window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS)
window.statusBarColor = nightBlue
bottomAppBar.setBackgroundColor(nightBlue)
bottomBarButtons.forEach { (it as ImageButton).setBackgroundColor(nightBlue) }
bottomBarButtons.forEach { (it as ImageButton).setColorFilter(unselectedIconColor) }
(view as ImageButton).setColorFilter(selectedIconColor)

Expand Down Expand Up @@ -122,6 +129,13 @@ class MainActivity : AppCompatActivity() {
if (isStaff()) {
// check if already on scanner attendance page for staff
if (!onScanner) {
val darkForest = ContextCompat.getColor(this, R.color.darkForest)
bottomAppBar.setBackgroundColor(darkForest)
bottomBarButtons.forEach { (it as ImageButton).setBackgroundColor(darkForest) }
val window = window
window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS)
window.statusBarColor = darkForest

switchFragment(staffScannerFragment, false)
}
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import android.os.Bundle
import android.os.Handler
import android.os.Looper
import android.transition.TransitionInflater
import android.util.Log
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
Expand Down Expand Up @@ -42,6 +41,7 @@ class ScannerFragment : Fragment() {
private var isMeetingAttendance: Boolean = false

private lateinit var codeScanner: CodeScanner
private var alertDialog: AlertDialog? = null

private lateinit var staffChipGroup: ChipGroup

Expand Down Expand Up @@ -70,6 +70,7 @@ class ScannerFragment : Fragment() {
} else {
displayScanResult(it)
}
codeScanner.startPreview()
},
)
roles.observe(
Expand All @@ -96,16 +97,17 @@ class ScannerFragment : Fragment() {

// Move the check-in to the first index
val index = listOfEvents!!.indexOfFirst { event -> event.name == "Check-in" }
val event = listOfEvents!![index]
listOfEvents!!.removeAt(index)
listOfEvents!!.add(0, event)
if (index >= 0) {
val event = listOfEvents!![index]
listOfEvents!!.removeAt(index)
listOfEvents!!.add(0, event)
}

var firstChipId = 0

// Go through all the events and add a chip for it
if (isStaff()) {
for ((index, event) in listOfEvents!!.withIndex()) {
Log.i("Events", "${event.name}: ${event.eventType}")
val chip =
inflater.inflate(R.layout.staff_scanner_chip, staffChipGroup, false) as Chip
chip.text = event.name
Expand All @@ -117,8 +119,6 @@ class ScannerFragment : Fragment() {
}
}

Log.i("Events", "Number of events: ${listOfEvents!!.size}")

// Select the first chipId
staffChipGroup.check(firstChipId)
}
Expand All @@ -144,9 +144,7 @@ class ScannerFragment : Fragment() {
if (userRoles != null && userRoles!!.isStaff()) {
// check if QR is for meeting attendance or staff attendee check-in
if (isMeetingAttendance) {
// do stuff
val eventId: String = getEventCodeFromQrString(it.text)
Log.d("QRCODE", "$eventId")
viewModel.scanQrToCheckInMeeting(eventId)
} else {
val userString = getUserIdFromQrString(it.text)
Expand Down Expand Up @@ -232,11 +230,15 @@ class ScannerFragment : Fragment() {
}
// make dialog from response
if (activity != null) {
AlertDialog.Builder(requireActivity())
.setMessage(responseString)
.setNegativeButton("OK") { dialog, id -> dialog.dismiss() }
.create()
.show()
if (alertDialog == null) {
val builder = AlertDialog.Builder(requireActivity())
.setMessage(responseString)
.setNegativeButton("OK") { dialog, id ->
dialog.dismiss()
}
alertDialog = builder.create()
}
alertDialog!!.show()
} else {
val toast = Toast.makeText(context, responseString, Toast.LENGTH_LONG)
toast.show()
Expand All @@ -252,7 +254,6 @@ class ScannerFragment : Fragment() {
else -> "Something isn't quite right."
}
// make toast from response
Log.d("SCAN STATUS RESULT", responseString)
val toast = Toast.makeText(context, responseString, Toast.LENGTH_LONG)
toast.show()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class ScheduleFragment : Fragment() {
this,
Observer {
favoriteButton.isSelected = it ?: false
}
},
)
}

Expand Down Expand Up @@ -76,7 +76,7 @@ class ScheduleFragment : Fragment() {
when (isSelected) {
true -> R.drawable.ic_star_filled
else -> R.drawable.ic_star_selectable
}
},
)
}
scheduleViewModel.showFavorites.postValue(favoriteButton.isSelected)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,6 @@ class ScannerViewModel : ViewModel() {
viewModelScope.launch {
try {
response = EventRepository.checkInEventAsStaff(userId, eventId)
Log.i("Check In", "Status: ${response.status}")
Log.i("Check In", "Response: $response")
lastScanStatus.postValue(
ScanStatus(
response.rsvpData != null,
Expand All @@ -121,65 +119,4 @@ class ScannerViewModel : ViewModel() {
}
return response
}

// fun checkInUser(checkIn: CheckIn) {
// viewModelScope.launch {
// try {
// val ci: CheckIn = App.getAPI().checkInUser(checkIn)
// // Check-in was a success
// val userId = ci.id
// // val scanStatus = ScanStatus(true, userId, "")
// // lastScanStatus.postValue(scanStatus)
// } catch (e: Exception) {
// when (e) {
// is HttpException -> {
// @Suppress("BlockingMethodInNonBlockingContext")
// val error = JSONObject(e.response()?.errorBody()?.string())
// val errorType = error.getString("type")
// val errorMessage = if (errorType == "ATTRIBUTE_MISMATCH_ERROR") {
// error.getString("message")
// } else {
// "Internal API error"
// }
// val scanStatus = ScanStatus(false, "", errorMessage)
// lastScanStatus.postValue(scanStatus)
// }
// else -> {
// val scanStatus = ScanStatus(false, "", "Request could not be made. Please try again.")
// lastScanStatus.postValue(scanStatus)
// }
// }
// }
// }
// }

// fun markUserAsAttendingEvent(userEventPair: UserEventPair) {
// viewModelScope.launch {
// try {
// val trackerContainer = App.getAPI().markUserAsAttendingEvent(userEventPair)
// val userId = trackerContainer.userTracker.userId
// val scanStatus = ScanStatus(true, userId, "")
// lastScanStatus.postValue(scanStatus)
// } catch (e: Exception) {
// when (e) {
// is HttpException -> {
// val error = JSONObject(e.response()?.errorBody()?.string())
// val errorType = error.getString("type")
// val errorMessage = if (errorType == "ATTRIBUTE_MISMATCH_ERROR") {
// error.getString("message")
// } else {
// "Internal API error"
// }
// val scanStatus = ScanStatus(false, "", errorMessage)
// lastScanStatus.postValue(scanStatus)
// }
// else -> {
// val scanStatus = ScanStatus(false, "",
// "Request could not be made. Please try again.")
// lastScanStatus.postValue(scanStatus)
// }
// }
// }
// }
// }
}
2 changes: 1 addition & 1 deletion app/src/main/res/color/chip_text_selector.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_checked="true"
android:color="@color/color_checked" />
android:color="@color/colorChecked" />
<item android:state_checked="false"
android:color="@color/white" />
</selector>
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions app/src/main/res/layout/fragment_scanner.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
app:frameAspectRatioHeight="1"
app:frameAspectRatioWidth="1"
app:frameColor="@color/scannerBorderColor"
app:frameCornersRadius="20dp"
app:frameCornersRadius="16dp"
app:frameCornersSize="50dp"
app:frameSize="0.75"
app:frameThickness="2dp"
Expand Down Expand Up @@ -59,7 +59,7 @@
app:checkedChip="@id/chip1"
android:layout_marginTop="10dp"
android:layout_marginHorizontal="50dp"
android:visibility="visible">
android:visibility="invisible">

</com.google.android.material.chip.ChipGroup>

Expand Down
46 changes: 24 additions & 22 deletions app/src/main/res/layout/fragment_staff_scanner.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,11 @@
android:layout_height="wrap_content"
android:adjustViewBounds="true"
android:scaleType="fitXY"
android:src="@drawable/welcome_bg"
android:src="@drawable/staff_attendance_bg"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintHorizontal_bias="1.0"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="1.0" />
app:layout_constraintTop_toTopOf="parent" />

<TextView
android:id="@+id/attendance_TextView"
Expand All @@ -30,51 +28,55 @@
android:fontFamily="@font/montserrat_bold"
android:gravity="start"
android:text="@string/attendance"
android:textColor="@color/white"
android:textColor="@color/darkForest"
android:textSize="24sp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />

<com.google.android.material.button.MaterialButton
android:id="@+id/staffMeetingBtn"
android:layout_width="wrap_content"
style="@style/Widget.MaterialComponents.Button.OutlinedButton"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginBottom="30dp"
android:backgroundTint="@color/cloudMist"
android:paddingHorizontal="22dp"
android:paddingVertical="16dp"
android:layout_marginBottom="20dp"
android:backgroundTint="@color/lightBlue"
android:paddingVertical="28dp"
android:text="@string/staff_meeting"
android:textAllCaps="false"
android:textColor="@color/midnight"
android:textColor="@color/darkForest"
android:textSize="18sp"
app:cornerRadius="28dp"
app:cornerRadius="12dp"
app:fontFamily="@font/montserrat_bold"
app:layout_constraintBottom_toTopOf="@+id/staffCheckInBtn"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.496"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintTop_toBottomOf="@+id/attendance_TextView"
app:layout_constraintVertical_bias="0.10"
app:layout_constraintVertical_chainStyle="packed"
app:layout_constraintWidth_percent=".6" />
app:layout_constraintWidth_percent=".8"
app:strokeColor="@color/mediumBlue"
app:strokeWidth="3dp" />

<com.google.android.material.button.MaterialButton
style="@style/Widget.MaterialComponents.Button.OutlinedButton"
android:id="@+id/staffCheckInBtn"
android:layout_width="wrap_content"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:backgroundTint="@color/cottonCandyPink"
android:paddingVertical="16dp"
android:paddingHorizontal="22dp"
app:cornerRadius="28dp"
app:strokeColor="@color/mediumYellow"
app:strokeWidth="3dp"
android:backgroundTint="@color/lightYellow"
android:paddingVertical="28dp"
app:cornerRadius="12dp"
android:textAllCaps="false"
android:textColor="@color/midnight"
android:textColor="@color/darkForest"
android:textSize="18sp"
android:text="@string/staff_checkin"
app:fontFamily="@font/montserrat_bold"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/staffMeetingBtn"
app:layout_constraintWidth_percent=".6" />
app:layout_constraintWidth_percent=".8" />

</androidx.constraintlayout.widget.ConstraintLayout>
9 changes: 8 additions & 1 deletion app/src/main/res/values/colors.xml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,13 @@
<color name="carnivalRed">#F11F20</color>
<color name="orangeSorbet">#F99557</color>
<color name="lemonade">#FCDC8F</color>
<color name="color_checked">#294C6C</color>
<color name="colorChecked">#294C6C</color>

<!-- 2024 color palette (tentative, no names yet) -->
<color name="darkForest">#0D3F41</color>
<color name="lightBlue">#F3FFFF</color>
<color name="mediumBlue">#D2F7FF</color>
<color name="lightYellow">#FFFACC</color>
<color name="mediumYellow">#FFF48D</color>

</resources>

0 comments on commit 691b347

Please sign in to comment.