Skip to content

Commit

Permalink
Feat : Add new function that opens skyscanner website when user click…
Browse files Browse the repository at this point in the history
…s likeItem tukcomCD2024#74
  • Loading branch information
ksh-g001 committed Aug 7, 2024
1 parent d6879c6 commit bea4bcd
Show file tree
Hide file tree
Showing 29 changed files with 591 additions and 126 deletions.
1 change: 1 addition & 0 deletions android/HowAboutTrip/app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ dependencies {

implementation("com.google.dagger:hilt-android:2.46")
implementation("androidx.activity:activity-ktx:1.9.1")
implementation("androidx.activity:activity:1.9.1")
kapt("com.google.dagger:hilt-android-compiler:2.46")

implementation("com.squareup.retrofit:retrofit:2.0.0-beta2")
Expand Down
3 changes: 3 additions & 0 deletions android/HowAboutTrip/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@
android:supportsRtl="true"
android:theme="@style/Base.Theme.HowAboutTrip"
tools:targetApi="31">
<activity
android:name=".view.activity.record.BillActivity"
android:exported="false" />
<activity
android:name=".view.activity.record.LocationMapActivity"
android:exported="false" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,20 @@ import android.view.ViewGroup
import androidx.recyclerview.widget.RecyclerView
import com.project.how.R
import com.project.how.data_class.dto.booking.airplane.GetOneWayFlightOffersResponseElement
import com.project.how.data_class.recyclerview.ticket.FlightMember
import com.project.how.databinding.OneWayAirplaneListItemBinding
import java.text.NumberFormat
import java.time.LocalDateTime
import java.time.format.DateTimeFormatter
import java.util.Locale

class OneWayAirplaneListAdapter(private val context: Context, private val data : ArrayList<GetOneWayFlightOffersResponseElement>, lid : MutableList<Long>, private val onItemClickListener : OnItemClickListener) : RecyclerView.Adapter<OneWayAirplaneListAdapter.ViewHolder>(){
class OneWayAirplaneListAdapter(
private val context: Context,
private val data: ArrayList<GetOneWayFlightOffersResponseElement>,
lid: MutableList<Long>,
private val onItemClickListener: OnItemClickListener,
private var flightMember: List<FlightMember>?
) : RecyclerView.Adapter<OneWayAirplaneListAdapter.ViewHolder>(){
private val hearts = lid.map { it > 0 }.toMutableList()
private var likeId = lid
private var heartClickable = false
Expand Down Expand Up @@ -91,7 +98,7 @@ class OneWayAirplaneListAdapter(private val context: Context, private val data :
val d = data[position]
holder.bind(d, position)
holder.itemView.setOnClickListener {
onItemClickListener.onItemClickerListener(d)
onItemClickListener.onItemClickerListener(d, if(flightMember.isNullOrEmpty()) null else flightMember!![position])
}
}

Expand Down Expand Up @@ -141,7 +148,10 @@ class OneWayAirplaneListAdapter(private val context: Context, private val data :
private fun getFormattedNumber(price : Long) : String = NumberFormat.getNumberInstance(Locale.US).format(price)

interface OnItemClickListener{
fun onItemClickerListener(data : GetOneWayFlightOffersResponseElement)
fun onItemClickerListener(
data: GetOneWayFlightOffersResponseElement,
flightMember: FlightMember?
)
fun onHeartClickerListener(
check: Boolean,
data: GetOneWayFlightOffersResponseElement,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,20 @@ import android.view.ViewGroup
import androidx.recyclerview.widget.RecyclerView
import com.project.how.R
import com.project.how.data_class.dto.booking.airplane.GetFlightOffersResponseElement
import com.project.how.data_class.recyclerview.ticket.FlightMember
import com.project.how.databinding.RoundTripAirplaneListItemBinding
import java.text.NumberFormat
import java.time.LocalDateTime
import java.time.format.DateTimeFormatter
import java.util.Locale

class RoundTripAirplaneListAdapter(private val context: Context, private val data : ArrayList<GetFlightOffersResponseElement>, lid : MutableList<Long>, private val onItemClickListener : OnItemClickListener) : RecyclerView.Adapter<RoundTripAirplaneListAdapter.ViewHolder>(){
class RoundTripAirplaneListAdapter(
private val context: Context,
private val data: ArrayList<GetFlightOffersResponseElement>,
lid: MutableList<Long>,
private val onItemClickListener: OnItemClickListener,
private val flightMember: List<FlightMember>?
) : RecyclerView.Adapter<RoundTripAirplaneListAdapter.ViewHolder>(){
private val hearts = lid.map { it > 0 }.toMutableList()
private var likeId = lid
private var heartClickable = false
Expand Down Expand Up @@ -108,7 +115,7 @@ class RoundTripAirplaneListAdapter(private val context: Context, private val dat
val d = data[position]
holder.bind(d, position)
holder.itemView.setOnClickListener {
onItemClickListener.onItemClickerListener(d)
onItemClickListener.onItemClickerListener(d, if (flightMember.isNullOrEmpty()) null else flightMember!![position])
}
}

Expand Down Expand Up @@ -158,7 +165,10 @@ class RoundTripAirplaneListAdapter(private val context: Context, private val dat
private fun getFormattedNumber(price : Long) : String = NumberFormat.getNumberInstance(Locale.US).format(price)

interface OnItemClickListener{
fun onItemClickerListener(data : GetFlightOffersResponseElement)
fun onItemClickerListener(
data: GetFlightOffersResponseElement,
flightMember: FlightMember?
)
fun onHeartClickerListener(
check: Boolean,
data: GetFlightOffersResponseElement,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import android.view.ViewGroup
import androidx.recyclerview.widget.RecyclerView
import com.bumptech.glide.Glide
import com.project.how.BuildConfig
import com.project.how.data_class.recyclerview.RecentHotel
import com.project.how.data_class.recyclerview.ticket.RecentHotel
import com.project.how.databinding.RecentHotelItemBinding

class RecentHotelAdapter(recentHotel : List<RecentHotel>, private val onItemClickListener: OnItemClickListener)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,27 +1,75 @@
package com.project.how.adapter.recyclerview.record

import android.content.Context
import android.view.LayoutInflater
import android.view.ViewGroup
import androidx.recyclerview.widget.RecyclerView
import com.bumptech.glide.Glide
import com.project.how.BuildConfig
import com.project.how.R
import com.project.how.data_class.recyclerview.record.Bill
import com.project.how.databinding.BillListItemBinding

class BillListAdapter (

data : List<Bill>,
private val context : Context,
private val onItemClickListener: OnItemClickListener
) : RecyclerView.Adapter<BillListAdapter.ViewHolder>(){
private var bills = data.toMutableList()
inner class ViewHolder(val binding: BillListItemBinding) : RecyclerView.ViewHolder(binding.root){
fun bind(){
fun bind(data: Bill, position: Int){
binding.title.text = data.title
binding.date.text = data.date
binding.cost.text = context.getString(R.string.cost, data.cost.toString())
binding.count.text = context.getString(R.string.bill_count, data.count.toString())
Glide.with(binding.root)
.load(data.image ?: BuildConfig.TEMPORARY_IMAGE_URL)
.error(BuildConfig.ERROR_IMAGE_URL)
.into(binding.image)

binding.delete.setOnClickListener {
onItemClickListener.onDeleteButtonClickListener(data.id, position)
}
itemView.setOnClickListener {
onItemClickListener.onItemClickListener(data.id)
}
}
}

override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
TODO("Not yet implemented")
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder = ViewHolder(
BillListItemBinding.inflate(
LayoutInflater.from(parent.context),
parent,
false
)
)

override fun getItemCount(): Int = bills.size

override fun getItemViewType(position: Int): Int = position

override fun onBindViewHolder(holder: ViewHolder, position: Int) {
val data = bills[position]
holder.bind(data, position)
}

fun update(newData : List<Bill>){
bills = newData.toMutableList()
notifyDataSetChanged()
}

override fun getItemCount(): Int {
TODO("Not yet implemented")
fun delete(position: Int){
bills.removeAt(position)
notifyItemRangeChanged(position, bills.lastIndex)
}

override fun onBindViewHolder(holder: ViewHolder, position: Int) {
TODO("Not yet implemented")
fun add(newData : Bill){
bills.add(newData)
notifyItemInserted(bills.lastIndex)
}

interface OnItemClickListener{
fun onItemClickListener(id: Long)
fun onDeleteButtonClickListener(id: Long, position: Int)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import android.view.ViewGroup
import androidx.recyclerview.widget.RecyclerView
import com.bumptech.glide.Glide
import com.project.how.BuildConfig
import com.project.how.data_class.recyclerview.RecentAddedRecord
import com.project.how.data_class.recyclerview.record.RecentAddedRecord
import com.project.how.databinding.ViewpagerRecentRecordItemBinding

class RecentAddedRecordsAdapter(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ data class GenerateSkyscannerUrlRequest(
val departureDate : String,
@SerializedName("returnDate")
val returnDate : String,
@SerializedName("adults")
val adults : Long,
@SerializedName("adult")
val adult : Long,
@SerializedName("children")
val children : Long,
@SerializedName("departureTime")
Expand All @@ -28,8 +28,8 @@ data class GenerateOneWaySkyscannerUrlRequest(
val arrivalIataCode : String,
@SerializedName("departureDate")
val departureDate : String,
@SerializedName("adults")
val adults : Long,
@SerializedName("adult")
val adult : Long,
@SerializedName("children")
val children : Long,
@SerializedName("departureTime")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,36 @@
package com.project.how.data_class.dto.booking.airplane

import com.google.gson.annotations.SerializedName

typealias GetLikeFlightResponse = List<GetLikeFlightResponseElement>

data class GetLikeFlightResponseElement(
@SerializedName("id")
val id: Long,
@SerializedName("carrierCode")
val carrierCode: String,
@SerializedName("totalPrice")
val totalPrice: Long,
@SerializedName("abroadDuration")
val abroadDuration: String,
@SerializedName("abroadDepartureTime")
val abroadDepartureTime: String,
@SerializedName("abroadArrivalTime")
val abroadArrivalTime: String,
@SerializedName("homeDuration")
val homeDuration: String? = null,
@SerializedName("homeDepartureTime")
val homeDepartureTime: String? = null,
@SerializedName("homeArrivalTime")
val homeArrivalTime: String? = null,
@SerializedName("departureIataCode")
val departureIataCode: String,
@SerializedName("arrivalIataCode")
val arrivalIataCode: String,
val transferCount: String
@SerializedName("transferCount")
val transferCount: String,
@SerializedName("adult")
val adult : Long,
@SerializedName("children")
val children : Long
)
Original file line number Diff line number Diff line change
@@ -1,18 +1,36 @@
package com.project.how.data_class.dto.booking.airplane

import com.google.gson.annotations.SerializedName

typealias LikeFlight = List<LikeFlightElement>

data class LikeFlightElement (
@SerializedName("carrierCode")
val carrierCode: String,
@SerializedName("totalPrice")
val totalPrice: Long,
@SerializedName("abroadDuration")
val abroadDuration: String,
@SerializedName("abroadDepartureTime")
val abroadDepartureTime: String,
@SerializedName("abroadArrivalTime")
val abroadArrivalTime: String,
@SerializedName("homeDuration")
val homeDuration: String,
@SerializedName("homeDepartureTime")
val homeDepartureTime: String,
@SerializedName("homeArrivalTime")
val homeArrivalTime: String,
@SerializedName("departureIataCode")
val departureIataCode: String,
@SerializedName("arrivalIataCode")
val arrivalIataCode: String,
@SerializedName("nonstop")
val nonstop: Boolean,
val transferCount: Long
@SerializedName("transferCount")
val transferCount: Long,
@SerializedName("adult")
val adult : Long,
@SerializedName("children")
val children : Long
)
Original file line number Diff line number Diff line change
@@ -1,15 +1,30 @@
package com.project.how.data_class.dto.booking.airplane

import com.google.gson.annotations.SerializedName

typealias LikeOneWayFlight = List<LikeOneWayFlightElement>

data class LikeOneWayFlightElement (
@SerializedName("carrierCode")
val carrierCode: String,
@SerializedName("totalPrice")
val totalPrice: Long,
@SerializedName("departureIataCode")
val departureIataCode: String,
@SerializedName("arrivalIataCode")
val arrivalIataCode: String,
@SerializedName("abroadDuration")
val abroadDuration: String,
@SerializedName("abroadDepartureTime")
val abroadDepartureTime: String,
@SerializedName("abroadArrivalTime")
val abroadArrivalTime: String,
@SerializedName("nonstop")
val nonstop: Boolean,
val transferCount: Long
@SerializedName("transferCount")
val transferCount: Long,
@SerializedName("adult")
val adult : Long,
@SerializedName("children")
val children : Long
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.project.how.data_class.recyclerview.record

data class Bill(
val id : Long,
val image : String?,
val title : String,
val date : String,
val cost : Long,
val count : Long
)
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.project.how.data_class.recyclerview
package com.project.how.data_class.recyclerview.record

data class RecentAddedRecord(
val id : Long,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package com.project.how.data_class.recyclerview.ticket

data class FlightMember(
val adult : Long,
val children : Long
)
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.project.how.data_class.recyclerview
package com.project.how.data_class.recyclerview.ticket

data class RecentAirplane(
val id : Long,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.project.how.data_class.recyclerview
package com.project.how.data_class.recyclerview.ticket

data class RecentHotel(
val id : Long,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package com.project.how.view.activity.record

import android.os.Bundle
import androidx.activity.enableEdgeToEdge
import androidx.appcompat.app.AppCompatActivity
import androidx.core.view.ViewCompat
import androidx.core.view.WindowInsetsCompat
import com.project.how.R

class BillActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
enableEdgeToEdge()
setContentView(R.layout.activity_bill)
ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.main)) { v, insets ->
val systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars())
v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom)
insets
}
}
}
Loading

0 comments on commit bea4bcd

Please sign in to comment.