Skip to content

Commit

Permalink
Merge pull request #524 from HackIllinois/leah/home-2024
Browse files Browse the repository at this point in the history
Home Page 2024
  • Loading branch information
leahlud authored Jan 7, 2024
2 parents 5c65fa1 + fe5b114 commit 6f9d6ab
Show file tree
Hide file tree
Showing 20 changed files with 289 additions and 155 deletions.
6 changes: 0 additions & 6 deletions app/src/main/java/org/hackillinois/android/API.kt
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package org.hackillinois.android

import org.hackillinois.android.database.entity.*
import org.hackillinois.android.model.TimesWrapper
import org.hackillinois.android.model.checkin.CheckIn
import org.hackillinois.android.model.event.EventsList
import org.hackillinois.android.model.leaderboard.LeaderboardList
Expand Down Expand Up @@ -62,11 +61,6 @@ interface API {
@POST("staff/attendance/")
suspend fun staffMeetingCheckIn(@Body eventId: MeetingEventId): MeetingCheckInResponse

// UPLOAD

@GET("upload/blobstore/times/")
suspend fun times(): TimesWrapper

// USER

@GET("user/")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,32 +3,29 @@ package org.hackillinois.android.view.home
import android.os.CountDownTimer
import org.hackillinois.android.common.isBeforeNow
import org.hackillinois.android.common.timeUntilMs
import org.hackillinois.android.model.TimesWrapper
import java.util.*

class CountdownManager(val listener: CountDownListener) {

// 2023-02-24 15:00:00
// 02-23-2024 15:30:00
private val eventStartTime: Calendar = Calendar.getInstance().apply {
timeZone = TimeZone.getTimeZone("America/Chicago")
timeInMillis = 1677272400000
timeInMillis = 1708723800000
}

// 2023-02-24 19:00:00
// 02-23-2024 19:00:00
private val hackingStartTime: Calendar = Calendar.getInstance().apply {
timeZone = TimeZone.getTimeZone("America/Chicago")
timeInMillis = 1677286800000
timeInMillis = 1708736400000
}

// 2023-02-26 9:00:00
// 02-25-2024 9:00:00
private val hackingEndTime: Calendar = Calendar.getInstance().apply {
timeZone = TimeZone.getTimeZone("America/Chicago")
timeInMillis = 1677423600000
timeInMillis = 1708873200000
}

private var times = listOf(eventStartTime, hackingStartTime, hackingEndTime)

// placeholders in case design team decides to change this
private val titles = listOf("HACKILLINOIS BEGINS IN", "HACKING BEGINS IN", "HACKING ENDS IN", "MEMORIES MADE")

private var timer: CountDownTimer? = null
Expand All @@ -37,28 +34,32 @@ class CountdownManager(val listener: CountDownListener) {
private val refreshRateMs = 500L

fun start() {
// find current state of the countdown in terms of timestamps
while (state < times.size && times[state].isBeforeNow()) {
state++
}
startTimer()
}

private fun startTimer() {
// if past the last timestamp, don't start another timer
if (state >= times.size) {
listener.updateTitle(titles[state])

listener.updateTitle(titles[titles.size - 1]) // set to be last title
return
}
listener.updateTitle(titles[state])

// else set the current title and start timer until next timestamp
listener.updateTitle(titles[state])
val millisTillTimerFinishes = times[state].timeUntilMs()

timer = object : CountDownTimer(millisTillTimerFinishes, refreshRateMs) {
// update the time on each tick
override fun onTick(millisUntilFinished: Long) {
val timeUntil = times[state].timeUntilMs()
listener.updateTime(timeUntil)
}

// increment the state when timer is finished
override fun onFinish() {
state++
startTimer()
Expand All @@ -77,28 +78,6 @@ class CountdownManager(val listener: CountDownListener) {
}
}

fun setAPITimes(timesWrapper: TimesWrapper) {
onPause()
val apiEventStartTime = Calendar.getInstance().apply {
timeZone = TimeZone.getTimeZone("America/Chicago")
timeInMillis = timesWrapper.data.eventStart * 1000L
}

val apiHackingStartTime = Calendar.getInstance().apply {
timeZone = TimeZone.getTimeZone("America/Chicago")
timeInMillis = timesWrapper.data.hackStart * 1000L
}

val apiHackingEndTime = Calendar.getInstance().apply {
timeZone = TimeZone.getTimeZone("America/Chicago")
timeInMillis = timesWrapper.data.hackEnd * 1000L
}

times = listOf(apiEventStartTime, apiHackingStartTime, apiHackingEndTime)
state = 0
startTimer()
}

interface CountDownListener {
fun updateTime(timeUntil: Long)
fun updateTitle(newTitle: String)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
package org.hackillinois.android.view.home

import android.os.CountDownTimer
import org.hackillinois.android.R
import org.hackillinois.android.common.isBeforeNow
import org.hackillinois.android.common.timeUntilMs
import java.util.*

class EventProgressManager(val listener: CountDownListener) {

// CORRECT TIMES ARE NOT SET YET
// 02-23-2024 15:30:00
private val checkInTime: Calendar = Calendar.getInstance().apply {
timeZone = TimeZone.getTimeZone("America/Chicago")
timeInMillis = 1708723800000
}

// 02-23-2024 16:00:00
private val scavengerHuntTime: Calendar = Calendar.getInstance().apply {
timeZone = TimeZone.getTimeZone("America/Chicago")
timeInMillis = 1708725600000
}

// 02-23-2024 18:00:00
private val openingCeremonyTime: Calendar = Calendar.getInstance().apply {
timeZone = TimeZone.getTimeZone("America/Chicago")
timeInMillis = 1708732800000
}

// 02-23-2024 19:00:00
private val hackingTime: Calendar = Calendar.getInstance().apply {
timeZone = TimeZone.getTimeZone("America/Chicago")
timeInMillis = 1708736400000
}

// 02-25-2024 11:00:00
private val projectShowcaseTime: Calendar = Calendar.getInstance().apply {
timeZone = TimeZone.getTimeZone("America/Chicago")
timeInMillis = 1708880400000
}

// 02-25-2024 15:00:00
private val closingCeremonyTime: Calendar = Calendar.getInstance().apply {
timeZone = TimeZone.getTimeZone("America/Chicago")
timeInMillis = 1708894800000
}

// 02-25-2024 16:00:00
private val afterHackathonTime: Calendar = Calendar.getInstance().apply {
timeZone = TimeZone.getTimeZone("America/Chicago")
timeInMillis = 1708898400000
}

private var times = listOf(checkInTime, scavengerHuntTime, openingCeremonyTime, hackingTime, projectShowcaseTime, closingCeremonyTime, afterHackathonTime)
private var backgrounds = listOf(R.drawable.home_bg_start, R.drawable.home_check_in_bg, R.drawable.home_scavenger_hunt_bg, R.drawable.home_opening_bg, R.drawable.home_hacking_bg, R.drawable.home_project_showcase_bg, R.drawable.home_closing_bg, R.drawable.home_final_bg)
private var timer: CountDownTimer? = null
private var state = 0

private val refreshRateMs = 500L

fun start() {
// find current state of the event progress
while (state < times.size && times[state].isBeforeNow()) {
state++
}
startTimer()
}

private fun startTimer() {
// if past the last event, don't start another timer
if (state >= times.size) {
listener.updateBackground(backgrounds[backgrounds.size - 1])
return
}

// else set the current title and start timer until next timestamp
listener.updateBackground(backgrounds[state])
val millisTillTimerFinishes = times[state].timeUntilMs()

timer = object : CountDownTimer(millisTillTimerFinishes, refreshRateMs) {
override fun onTick(millisUntilFinished: Long) {
// do nothing
}

override fun onFinish() {
state++
startTimer()
}
}.start()
}

fun onPause() {
timer?.cancel()
timer = null
}

fun onResume() {
if (timer == null) {
start()
}
}

interface CountDownListener {
fun updateBackground(newBackgroundResource: Int)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,27 +4,27 @@ import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.ImageView
import android.widget.TextView
import androidx.fragment.app.Fragment
import androidx.lifecycle.ViewModelProvider
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.launch
import org.hackillinois.android.App
import org.hackillinois.android.R
import org.hackillinois.android.common.TimeInfo
import org.hackillinois.android.viewmodel.HomeViewModel
import java.lang.Exception

class HomeFragment : Fragment(), CountdownManager.CountDownListener {
class HomeFragment : Fragment(), CountdownManager.CountDownListener, EventProgressManager.CountDownListener {

private lateinit var daysValue: TextView
private lateinit var hoursValue: TextView
private lateinit var minutesValue: TextView
private lateinit var countdownTextView: TextView
private lateinit var homeBackgroundImageView: ImageView
private lateinit var homeBackgroundTagsImageView: ImageView
private lateinit var infoButton: ImageView

private lateinit var viewModel: HomeViewModel
private val countDownManager = CountdownManager(this)
private val countDownManager = CountdownManager(this) // for timer countdown
private val eventProgressManager = EventProgressManager(this) // for updating background of home page

private var isActive = false

Expand All @@ -41,6 +41,20 @@ class HomeFragment : Fragment(), CountdownManager.CountDownListener {
hoursValue = view.findViewById(R.id.hoursValue)
minutesValue = view.findViewById(R.id.minutesValue)
countdownTextView = view.findViewById(R.id.countdownTextView)
homeBackgroundImageView = view.findViewById(R.id.homeBackgroundImageView)
homeBackgroundTagsImageView = view.findViewById(R.id.homeBackgroundTagsImageView)
infoButton = view.findViewById(R.id.homeInfoImageView)

// set info button's functionality to toggle tag descriptions on home page when pressed on/off
infoButton.setOnClickListener {
if (homeBackgroundTagsImageView.visibility == View.INVISIBLE) {
homeBackgroundTagsImageView.visibility = View.VISIBLE
infoButton.setImageResource(R.drawable.question_mark_toggled)
} else {
homeBackgroundTagsImageView.visibility = View.INVISIBLE
infoButton.setImageResource(R.drawable.question_mark)
}
}

return view
}
Expand All @@ -49,25 +63,21 @@ class HomeFragment : Fragment(), CountdownManager.CountDownListener {
super.onStart()
isActive = true
countDownManager.start()
eventProgressManager.start()
}

override fun onPause() {
super.onPause()
isActive = false
countDownManager.onPause()
eventProgressManager.onPause()
}

override fun onResume() {
super.onResume()
isActive = true
countDownManager.onResume()
GlobalScope.launch(Dispatchers.Main) {
try {
val time = App.getAPI().times()
countDownManager.setAPITimes(time)
} catch (e: Exception) {
}
}
eventProgressManager.onResume()
}

override fun onStop() {
Expand All @@ -91,5 +101,11 @@ class HomeFragment : Fragment(), CountdownManager.CountDownListener {
}
}

override fun updateBackground(newBackgroundResource: Int) {
if (isActive) {
homeBackgroundImageView.setImageResource(newBackgroundResource)
}
}

private fun padNumber(number: Long) = String.format("%02d", number)
}
Binary file added app/src/main/res/drawable/home_bg_scenery.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/src/main/res/drawable/home_bg_start.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/src/main/res/drawable/home_bg_tags.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/src/main/res/drawable/home_check_in_bg.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/src/main/res/drawable/home_closing_bg.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/src/main/res/drawable/home_final_bg.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/src/main/res/drawable/home_hacking_bg.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/src/main/res/drawable/home_opening_bg.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/src/main/res/drawable/question_mark.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 6 additions & 0 deletions app/src/main/res/drawable/rounded_countdown_time_bg.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<shape android:shape="rectangle"
xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="@color/tangerine" />
<corners android:radius="8dp"/>
</shape>
6 changes: 6 additions & 0 deletions app/src/main/res/drawable/rounded_countdown_title_bg.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<shape android:shape="rectangle"
xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="@color/sweetCitrus" />
<corners android:topLeftRadius="8dp" android:topRightRadius="8dp"/>
</shape>
Loading

0 comments on commit 6f9d6ab

Please sign in to comment.