Skip to content

Commit

Permalink
Merge pull request #586 from pennlabs/gsr-time-sorting
Browse files Browse the repository at this point in the history
Add time based sorting to GSR booking
  • Loading branch information
vavali08 authored Oct 24, 2023
2 parents 8f933db + 2fdee43 commit 40f7d3b
Show file tree
Hide file tree
Showing 5 changed files with 111 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ class GsrFragment : Fragment() {
lateinit var durationDropDown: Spinner
lateinit var loadingPanel: LinearLayout
lateinit var noResultsPanel: LinearLayout
lateinit var sortingSwitch: Switch

// api manager
private lateinit var mStudentLife: StudentLife
Expand Down Expand Up @@ -66,6 +67,7 @@ class GsrFragment : Fragment() {

private var bearerToken = ""
private var isWharton = false
private var sortByTime = false

private lateinit var mActivity: MainActivity

Expand Down Expand Up @@ -97,6 +99,8 @@ class GsrFragment : Fragment() {
durationDropDown = view.gsr_duration
loadingPanel = view.gsr_loading
noResultsPanel = view.gsr_no_results
sortingSwitch = view.sorting_switch
sortByTime = sortingSwitch.isChecked

durationAdapter = ArrayAdapter(mActivity, R.layout.gsr_spinner_item, arrayOf("30m", "60m", "90m", "120m"))
whartonDurationAdapter = ArrayAdapter(mActivity, R.layout.gsr_spinner_item, arrayOf("30m", "60m", "90m"))
Expand Down Expand Up @@ -179,6 +183,10 @@ class GsrFragment : Fragment() {
datePickerDialog.show()
}

sortingSwitch.setOnClickListener{
sortByTime = sortingSwitch.isChecked
searchForGSR(false)
}
// handle swipe to refresh
view.gsr_refresh_layout?.setColorSchemeResources(R.color.color_accent, R.color.color_primary)
view.gsr_refresh_layout?.setOnRefreshListener {
Expand Down Expand Up @@ -270,6 +278,7 @@ class GsrFragment : Fragment() {
selectTimeButton.isClickable = false
gsrLocationDropDown.isEnabled = false
durationDropDown.isEnabled = false
sortingSwitch.isClickable = false


OAuth2NetworkManager(mActivity).getAccessToken {
Expand Down Expand Up @@ -318,30 +327,30 @@ class GsrFragment : Fragment() {
}

gsr_rooms_list?.adapter = (context?.let {
GsrBuildingAdapter(
it,
mGSRS,
location.toString(),
(durationDropDown.selectedItemPosition + 1) * 30
)
GsrBuildingAdapter(it, mGSRS, location.toString(), (durationDropDown.selectedItemPosition + 1) * 30, sortByTime)

})

mGSRS = ArrayList()
selectDateButton.isClickable = true
selectTimeButton.isClickable = true
gsrLocationDropDown.isEnabled = true
durationDropDown.isEnabled = true
sortingSwitch.isClickable = true

}
}
}, {
Log.e("GsrFragment", "Error getting gsr times", it)
activity?.let { activity ->
activity?.let { activity ->
activity.runOnUiThread {
showNoResults()
selectDateButton.isClickable = true
selectTimeButton.isClickable = true
gsrLocationDropDown.isEnabled = true
durationDropDown.isEnabled = true
sortingSwitch.isClickable = true

}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import org.joda.time.DateTime
import java.util.*

class GsrBuildingAdapter(internal var context: Context, internal var gsrs: ArrayList<GSRContainer>,
internal var gsrLocationCode: String, internal var duration: Int) : RecyclerView.Adapter<GsrBuildingHolder>() {
internal var gsrLocationCode: String, internal var duration: Int, internal var sortByTime : Boolean) : RecyclerView.Adapter<GsrBuildingHolder>() {

override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): GsrBuildingHolder {
val view = LayoutInflater.from(parent.context)
Expand All @@ -21,6 +21,8 @@ class GsrBuildingAdapter(internal var context: Context, internal var gsrs: Array
}

override fun onBindViewHolder(holder: GsrBuildingHolder, position: Int) {
var timeGsrs = gsrs.sortedWith(compareBy { it.start })

if (position < itemCount) {
val gsrRoomsRecyclerView = holder.recyclerView
if (gsrRoomsRecyclerView != null) {
Expand All @@ -37,19 +39,36 @@ class GsrBuildingAdapter(internal var context: Context, internal var gsrs: Array
val gids = ArrayList<Int>()
val roomNames = ArrayList<String>()

for (j in 0 until gsrs[position].availableGSRSlots.size) {
val gsrslot = gsrs[position].availableGSRSlots[j]
timeRanges.add(gsrslot.timeRange)
startTimes.add(gsrslot.startTime)
starts.add(gsrslot.start)
ends.add(gsrslot.end)
ids.add(gsrslot.elementId)
gids.add(gsrslot.gid)
roomNames.add(gsrslot.roomName)
if(sortByTime) {
for (j in 0 until timeGsrs[position].availableGSRSlots.size) {
val gsrslot = timeGsrs[position].availableGSRSlots[j]
timeRanges.add(gsrslot.timeRange)
startTimes.add(gsrslot.startTime)
starts.add(gsrslot.start)
ends.add(gsrslot.end)
ids.add(gsrslot.elementId)
gids.add(gsrslot.gid)
roomNames.add(gsrslot.roomName)
}
// Add GSR as parameter
gsrRoomsRecyclerView.adapter = GsrRoomAdapter(timeRanges, ids, gsrLocationCode, context, startTimes, duration, gids, roomNames, starts, ends)
holder.gsrBuildingName?.text = timeGsrs[position].gsrName
} else {
for (j in 0 until gsrs[position].availableGSRSlots.size) {
val gsrslot = gsrs[position].availableGSRSlots[j]
timeRanges.add(gsrslot.timeRange)
startTimes.add(gsrslot.startTime)
starts.add(gsrslot.start)
ends.add(gsrslot.end)
ids.add(gsrslot.elementId)
gids.add(gsrslot.gid)
roomNames.add(gsrslot.roomName)
}
// Add GSR as parameter
gsrRoomsRecyclerView.adapter = GsrRoomAdapter(timeRanges, ids, gsrLocationCode, context, startTimes, duration, gids, roomNames, starts, ends)
holder.gsrBuildingName?.text = gsrs[position].gsrName
}
// Add GSR as parameter
gsrRoomsRecyclerView.adapter = GsrRoomAdapter(timeRanges, ids, gsrLocationCode, context, startTimes, duration, gids, roomNames, starts, ends)
holder.gsrBuildingName?.text = gsrs[position].gsrName

}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,6 @@ class GSRContainer(val gsrName: String, constructorTimeRange: String, constructo

availableGSRSlots.add(newGSRSlot)
}

}

64 changes: 59 additions & 5 deletions PennMobile/src/main/res/layout/fragment_gsr.xml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
android:minWidth="0dp"
android:textColor="@color/color_primary"
android:textStyle="bold"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintBottom_toTopOf="@id/sort_by_text"
app:layout_constraintEnd_toEndOf="@+id/gsr_date_text"
app:layout_constraintStart_toStartOf="@+id/gsr_date_text"
app:layout_constraintTop_toBottomOf="@id/gsr_date_text" />
Expand All @@ -52,7 +52,7 @@
android:minWidth="0dp"
android:textColor="@color/color_primary"
android:textStyle="bold"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintBottom_toTopOf="@id/sort_by_text"
app:layout_constraintEnd_toEndOf="@+id/gsr_time_text"
app:layout_constraintStart_toStartOf="@+id/gsr_time_text"
app:layout_constraintTop_toBottomOf="@id/gsr_time_text" />
Expand All @@ -67,7 +67,7 @@
android:gravity="center"
android:textAlignment="center"
android:spinnerMode="dropdown"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintBottom_toTopOf="@id/sort_by_text"
app:layout_constraintEnd_toEndOf="@+id/gsr_building_text"
app:layout_constraintStart_toStartOf="@+id/gsr_building_text"
app:layout_constraintTop_toBottomOf="@id/gsr_building_text" />
Expand All @@ -79,7 +79,7 @@
android:layout_marginTop="4dp"
android:layout_marginBottom="16dp"
android:background="@null"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintBottom_toTopOf="@id/sort_by_text"
app:layout_constraintEnd_toEndOf="@+id/gsr_duration_text"
app:layout_constraintStart_toStartOf="@+id/gsr_duration_text"
app:layout_constraintTop_toBottomOf="@id/gsr_duration_text" />
Expand Down Expand Up @@ -126,6 +126,58 @@
android:text="@string/date"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />

<TextView
android:id = "@+id/sort_by_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:layout_marginBottom="16dp"
android:layout_marginRight="5dp"
android:paddingBottom="10dp"
android:textStyle="bold"
android:textColor="@color/color_primary"
android:text = "@string/sort_by"
app:layout_constraintTop_toBottomOf="@id/gsr_select_date"
app:layout_constraintEnd_toStartOf="@id/sort_by_room_number_text"/>

<TextView
android:id = "@+id/sort_by_room_number_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:layout_marginLeft="10dp"
android:layout_marginBottom="16dp"
android:paddingBottom="10dp"
android:textColor="@color/color_primary"
android:text = "@string/room"
app:layout_constraintTop_toBottomOf="@id/gsr_select_date"
app:layout_constraintEnd_toStartOf="@id/sorting_switch"/>

<Switch
android:id="@+id/sorting_switch"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:paddingTop="2dp"
android:paddingBottom="10dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="@+id/sort_by_time_text"
app:layout_constraintTop_toTopOf="@id/sort_by_room_number_text"
app:layout_constraintVertical_bias="1.0"
/>

<TextView
android:id="@+id/sort_by_time_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:layout_marginRight="10dp"
android:paddingBottom="10dp"
android:text="@string/time"
android:textColor="@color/color_primary"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="@id/gsr_select_date" />

</androidx.constraintlayout.widget.ConstraintLayout>

<TextView
Expand Down Expand Up @@ -165,8 +217,10 @@
android:layout_height="0dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="1.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/gsr_selection">
app:layout_constraintTop_toBottomOf="@id/gsr_selection"
app:layout_constraintVertical_bias="1.0">

<androidx.recyclerview.widget.RecyclerView
android:id="@+id/gsr_rooms_list"
Expand Down
3 changes: 3 additions & 0 deletions PennMobile/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -228,9 +228,12 @@

<!-- Poll -->
<string name="vote">Vote</string>
<string name="sort_by">Sort By:</string>
<string name="room_number">Room Number</string>
<string name="pottruck">Pottruck</string>
<string name="fitness_sunday">Sunday</string>
<string name="fitness_mf">Mon - Fri</string>
<string name="fitness_sat">Saturday</string>
<string name="fitness_capacity">Capacity</string>
<string name="room">Room</string>
</resources>

0 comments on commit 40f7d3b

Please sign in to comment.