-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' of https://github.com/pennlabs/penn-mobile-android
- Loading branch information
Showing
10 changed files
with
379 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
102 changes: 102 additions & 0 deletions
102
PennMobile/src/main/java/com/pennapps/labs/pennmobile/adapters/HomeGsrReservationAdapter.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
package com.pennapps.labs.pennmobile.adapters | ||
|
||
import android.content.Context | ||
import android.os.Bundle | ||
import android.util.Log | ||
import androidx.fragment.app.FragmentTransaction | ||
import androidx.core.content.ContextCompat | ||
import androidx.recyclerview.widget.RecyclerView | ||
import android.view.LayoutInflater | ||
import android.view.View | ||
import android.view.View.GONE | ||
import android.view.ViewGroup | ||
import android.widget.Button | ||
import android.widget.ImageView | ||
import android.widget.TextView | ||
import android.widget.Toast | ||
import androidx.fragment.app.Fragment | ||
import com.bumptech.glide.Glide | ||
import com.pennapps.labs.pennmobile.GsrReservationsFragment | ||
import com.pennapps.labs.pennmobile.GsrTabbedFragment | ||
import com.pennapps.labs.pennmobile.MainActivity | ||
import com.pennapps.labs.pennmobile.MenuFragment | ||
import com.pennapps.labs.pennmobile.R | ||
import com.pennapps.labs.pennmobile.api.StudentLife | ||
import com.pennapps.labs.pennmobile.classes.GSRReservation | ||
import com.squareup.picasso.Picasso | ||
import kotlinx.android.synthetic.main.dining_list_item.view.* | ||
import kotlinx.android.synthetic.main.gsr_list_item.view.item_gsr_date | ||
import kotlinx.android.synthetic.main.gsr_list_item.view.item_gsr_image | ||
import kotlinx.android.synthetic.main.gsr_list_item.view.item_gsr_location | ||
import kotlinx.android.synthetic.main.gsr_reservation.view.gsr_reservation_cancel_btn | ||
import kotlinx.android.synthetic.main.gsr_reservation.view.gsr_reservation_date_tv | ||
import kotlinx.android.synthetic.main.gsr_reservation.view.gsr_reservation_iv | ||
import kotlinx.android.synthetic.main.gsr_reservation.view.gsr_reservation_location_tv | ||
import org.joda.time.format.DateTimeFormat | ||
import org.joda.time.format.DateTimeFormatter | ||
import rx.android.schedulers.AndroidSchedulers | ||
|
||
class HomeGsrReservationAdapter (reservations: List<GSRReservation>) : RecyclerView.Adapter<HomeGsrReservationAdapter.ViewHolder>() { | ||
private var activeReservations: List<GSRReservation> = reservations | ||
|
||
private lateinit var itemImage: ImageView | ||
private lateinit var itemLocation: TextView | ||
private lateinit var itemDate: TextView | ||
|
||
|
||
private lateinit var mContext: Context | ||
private lateinit var mActivity: MainActivity | ||
private lateinit var mStudentLife: StudentLife | ||
override fun onBindViewHolder(holder: HomeGsrReservationAdapter.ViewHolder, position: Int) { | ||
val currentReservation = activeReservations[position] | ||
val location = currentReservation.name | ||
val formatter: DateTimeFormatter = DateTimeFormat.forPattern("yyyy-MM-dd'T'HH:mm:ssZ") | ||
val from = formatter.parseDateTime(currentReservation.fromDate) | ||
val to = formatter.parseDateTime(currentReservation.toDate) | ||
val day = from.toString("EEEE, MMMM d") | ||
val fromHour = from.toString("h:mm a") | ||
val toHour = to.toString("h:mm a") | ||
|
||
val imageUrl = currentReservation.info?.get("thumbnail") ?: "https://s3.us-east-2.amazonaws.com/labs.api/dining/MBA+Cafe.jpg" | ||
Picasso.get().load(imageUrl).fit().centerCrop().into(holder.itemView.item_gsr_image) | ||
|
||
holder.itemView.item_gsr_location.text = location | ||
holder.itemView.item_gsr_date.text = day + "\n" + fromHour + "-" + toHour | ||
|
||
holder.itemView.setOnClickListener { | ||
// Moves to GSR Booking Tab | ||
mActivity.setTab(MainActivity.GSR_ID) | ||
|
||
// Changes tab to "My Reservations" tab (from "Book a Room" tab) | ||
for (fragment in mActivity.supportFragmentManager.fragments) { | ||
if(fragment is GsrTabbedFragment) { | ||
fragment.viewPager.currentItem = 1 | ||
} | ||
} | ||
} | ||
|
||
} | ||
|
||
override fun getItemCount(): Int { | ||
return activeReservations.size | ||
} | ||
|
||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): HomeGsrReservationAdapter.ViewHolder { | ||
mContext = parent.context | ||
mActivity = mContext as MainActivity | ||
mStudentLife = MainActivity.studentLifeInstance | ||
|
||
val view = LayoutInflater.from(parent.context).inflate(R.layout.gsr_list_item, parent, false) | ||
return ViewHolder(view) | ||
} | ||
inner class ViewHolder (itemView: View) : RecyclerView.ViewHolder(itemView) { | ||
|
||
init { | ||
itemImage = itemView.item_gsr_image | ||
itemLocation = itemView.item_gsr_location | ||
itemDate = itemView.item_gsr_date | ||
|
||
} | ||
|
||
} | ||
} |
7 changes: 7 additions & 0 deletions
7
PennMobile/src/main/java/com/pennapps/labs/pennmobile/classes/GSRCell.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package com.pennapps.labs.pennmobile.classes | ||
|
||
data class GSRCell(val reservations: List<GSRReservation>) : HomeCell() { | ||
init { | ||
type = "gsr_booking" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Oops, something went wrong.