diff --git a/PennMobile/src/main/java/com/pennapps/labs/pennmobile/GsrFragment.kt b/PennMobile/src/main/java/com/pennapps/labs/pennmobile/GsrFragment.kt index e878c355..0c6c8fb5 100644 --- a/PennMobile/src/main/java/com/pennapps/labs/pennmobile/GsrFragment.kt +++ b/PennMobile/src/main/java/com/pennapps/labs/pennmobile/GsrFragment.kt @@ -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 @@ -66,6 +67,7 @@ class GsrFragment : Fragment() { private var bearerToken = "" private var isWharton = false + private var sortByTime = false private lateinit var mActivity: MainActivity @@ -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")) @@ -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 { @@ -270,6 +278,7 @@ class GsrFragment : Fragment() { selectTimeButton.isClickable = false gsrLocationDropDown.isEnabled = false durationDropDown.isEnabled = false + sortingSwitch.isClickable = false OAuth2NetworkManager(mActivity).getAccessToken { @@ -318,12 +327,8 @@ 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() @@ -331,17 +336,21 @@ class GsrFragment : Fragment() { 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 + } } } diff --git a/PennMobile/src/main/java/com/pennapps/labs/pennmobile/adapters/GsrBuildingAdapter.kt b/PennMobile/src/main/java/com/pennapps/labs/pennmobile/adapters/GsrBuildingAdapter.kt index 9eb052e2..c9899972 100644 --- a/PennMobile/src/main/java/com/pennapps/labs/pennmobile/adapters/GsrBuildingAdapter.kt +++ b/PennMobile/src/main/java/com/pennapps/labs/pennmobile/adapters/GsrBuildingAdapter.kt @@ -12,7 +12,7 @@ import org.joda.time.DateTime import java.util.* class GsrBuildingAdapter(internal var context: Context, internal var gsrs: ArrayList, - internal var gsrLocationCode: String, internal var duration: Int) : RecyclerView.Adapter() { + internal var gsrLocationCode: String, internal var duration: Int, internal var sortByTime : Boolean) : RecyclerView.Adapter() { override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): GsrBuildingHolder { val view = LayoutInflater.from(parent.context) @@ -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) { @@ -37,19 +39,36 @@ class GsrBuildingAdapter(internal var context: Context, internal var gsrs: Array val gids = ArrayList() val roomNames = ArrayList() - 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 + } } } diff --git a/PennMobile/src/main/java/com/pennapps/labs/pennmobile/classes/GSRContainer.kt b/PennMobile/src/main/java/com/pennapps/labs/pennmobile/classes/GSRContainer.kt index 4b365fc1..dd9e338f 100644 --- a/PennMobile/src/main/java/com/pennapps/labs/pennmobile/classes/GSRContainer.kt +++ b/PennMobile/src/main/java/com/pennapps/labs/pennmobile/classes/GSRContainer.kt @@ -30,5 +30,6 @@ class GSRContainer(val gsrName: String, constructorTimeRange: String, constructo availableGSRSlots.add(newGSRSlot) } + } diff --git a/PennMobile/src/main/res/layout/fragment_gsr.xml b/PennMobile/src/main/res/layout/fragment_gsr.xml index d63e96f0..5ededd06 100644 --- a/PennMobile/src/main/res/layout/fragment_gsr.xml +++ b/PennMobile/src/main/res/layout/fragment_gsr.xml @@ -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" /> @@ -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" /> @@ -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" /> @@ -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" /> @@ -126,6 +126,58 @@ android:text="@string/date" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toTopOf="parent" /> + + + + + + + + + + app:layout_constraintTop_toBottomOf="@id/gsr_selection" + app:layout_constraintVertical_bias="1.0"> Vote + Sort By: + Room Number Pottruck Sunday Mon - Fri Saturday Capacity + Room