Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Team-16] [Android] [PR-5] 구글맵 연동, 숙소 상세 및 예약 화면, 위시리스트 화면, 예약 내역 화면 구현 #275

Open
wants to merge 19 commits into
base: team-16
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion Android/app/build.gradle
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
plugins {
id 'com.android.application'
id 'org.jetbrains.kotlin.android'

id 'kotlin-kapt'
id 'dagger.hilt.android.plugin'
id 'kotlinx-serialization'
}

android {
Expand Down Expand Up @@ -79,6 +79,7 @@ dependencies {

//serialization
implementation 'org.jetbrains.kotlinx:kotlinx-serialization-json:1.3.3'
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"

//Hilt
implementation "com.google.dagger:hilt-android:$hilt_version"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import androidx.core.content.ContextCompat
import androidx.databinding.BindingAdapter
import com.team16.airbnb.R
import com.team16.airbnb.data.model.DayInfo
import java.text.DecimalFormat

@SuppressLint("UseCompatLoadingForDrawables")
@BindingAdapter("dayCheck")
Expand Down Expand Up @@ -70,4 +71,11 @@ fun setReviewCount(textView: TextView, count: Int) {
"(후기 ${count}개)".also { textView.text = it }
}

@BindingAdapter("moneyFormat")
fun setMoneyFormat(textView: TextView, money: Int) {
val format = DecimalFormat("₩#,###")
val money = format.format(money.toLong())
textView.text = money
}


56 changes: 56 additions & 0 deletions Android/app/src/main/java/com/team16/airbnb/data/dto/MyBookDTO.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
package com.team16.airbnb.data.dto


import com.team16.airbnb.data.model.MyBookData
import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable

@Serializable
data class MyBookDTO(
@SerialName("result")
val result: List<Result>?
) {

@Serializable
data class Result(
@SerialName("address")
val address: List<Address>?,
@SerialName("checkIn")
val checkIn: String?,
@SerialName("checkOut")
val checkOut: String?,
@SerialName("imageThumnail")
val imageThumnail: String?,
@SerialName("roomId")
val roomId: Int?,
@SerialName("roomName")
val roomName: String?
) {

@Serializable
data class Address(
@SerialName("city")
val city: String?,
@SerialName("detail")
val detail: String?,
@SerialName("district")
val district: String?,
@SerialName("region")
val region: String?
)

}
}

fun MyBookDTO.toMyBookData(): MyBookData {
val list = mutableListOf<MyBookData.Result>()
this.result?.forEach {
val address: List<Address>?,
val checkIn: String?,
val checkOut: String?,
val imageThumnail: String?,
val roomId: Int?,
val roomName: String?
}
return MyBookData(list)
}
43 changes: 43 additions & 0 deletions Android/app/src/main/java/com/team16/airbnb/data/dto/WishDTO.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package com.team16.airbnb.data.dto


import com.team16.airbnb.data.model.WishData
import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable

@Serializable
data class WishDTO(
@SerialName("result")
val result: List<Result>?
) {
@Serializable
data class Result(
@SerialName("imageThumnail")
val imageThumnail: String?,
@SerialName("price")
val price: Int?,
@SerialName("review")
val review: Int?,
@SerialName("roomId")
val roomId: Int?,
@SerialName("roomName")
val roomName: String?,
@SerialName("star")
val star: Double?
)
}

fun WishDTO.toWishData(): WishData {
val list = mutableListOf<WishData.ResultData>()
this.result?.forEach {
val imageThumnail = it.imageThumnail.orEmpty()
val price = requireNotNull(it.price)
val review = it.review ?: 0
val roomId = requireNotNull(it.roomId)
val roomName = requireNotNull(it.roomName)
val star = it.star ?: 0.0

list.add(WishData.ResultData(imageThumnail, price, review, roomId, roomName, star))
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

map, toList() 오퍼레이터를 잘 이용하면 list.add(WishData.ResultData(imageThumnail, price, review, roomId, roomName, star) 하지 않아도 됩니다 ㅎㅎ

return WishData(list)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package com.team16.airbnb.data.model

data class MyBookData(
val result: List<Result>
) {

data class Result(
val address: List<Address>,
val checkIn: String,
val checkOut: String,
val imageThumnail: String,
val roomId: Int,
val roomName: String
) {

data class Address(
val city: String,
val detail: String,
val district: String,
val region: String
)

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
package com.team16.airbnb.data.model


data class WishData(
val result: List<WishData.ResultData>
) {

data class ResultData(
val imageThumnail: String,
val price: Int,
val review: Int,
val roomId: Int,
val roomName: String,
val star: Double
)
}

val wishList = listOf(
WishData.ResultData(
"https://cloudfront-ap-northeast-1.images.arcpublishing.com/chosun/T7Y4P736SLLCA6FU2HAHOQIISA.jpg",
3000,
100,
1,
"스터디룸",
400.0
),
WishData.ResultData(
"https://cloudfront-ap-northeast-1.images.arcpublishing.com/chosun/T7Y4P736SLLCA6FU2HAHOQIISA.jpg",
3000,
200,
2,
"스터디룸",
400.0
),
WishData.ResultData(
"https://cloudfront-ap-northeast-1.images.arcpublishing.com/chosun/T7Y4P736SLLCA6FU2HAHOQIISA.jpg",
3000,
300,
3,
"스터디룸",
400.0
),
WishData.ResultData(
"https://cloudfront-ap-northeast-1.images.arcpublishing.com/chosun/T7Y4P736SLLCA6FU2HAHOQIISA.jpg",
3000,
400,
4,
"스터디룸",
400.0
),
WishData.ResultData(
"https://cloudfront-ap-northeast-1.images.arcpublishing.com/chosun/T7Y4P736SLLCA6FU2HAHOQIISA.jpg",
3000,
500,
5,
"스터디룸",
400.0
),
)
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.team16.airbnb.ui
package com.team16.airbnb.ui.home

import android.os.Bundle
import android.util.Log
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.team16.airbnb.ui
package com.team16.airbnb.ui.mybook

import android.os.Bundle
import androidx.fragment.app.Fragment
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,6 @@ class DetailSearchActivity : AppCompatActivity() {

private val calendarViewModel: CalendarViewModel by viewModels()

// private lateinit var navController: NavController

private val fragmentList = listOf(CalendarFragment(), MoneyRangeFragment(), PersonFragment())

private var currentView = 0
Expand All @@ -45,11 +43,7 @@ class DetailSearchActivity : AppCompatActivity() {
supportActionBar?.setDisplayHomeAsUpEnabled(true)
supportActionBar?.title = ""

// val navHostFragment = supportFragmentManager.findFragmentById(R.id.detail_nav_host) as NavHostFragment
// navController = navHostFragment.navController

setFragment()

setCalendarPickDateState()
setSkip()
setRemove()
Expand Down
36 changes: 36 additions & 0 deletions Android/app/src/main/java/com/team16/airbnb/ui/wish/WishAdapter.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package com.team16.airbnb.ui.wish

import android.view.LayoutInflater
import android.view.ViewGroup
import androidx.recyclerview.widget.DiffUtil
import androidx.recyclerview.widget.ListAdapter
import androidx.recyclerview.widget.RecyclerView
import com.team16.airbnb.data.model.SearchResult
import com.team16.airbnb.data.model.WishData
import com.team16.airbnb.databinding.ItemWishBinding

class WishAdapter: ListAdapter<WishData.ResultData, WishAdapter.WishViewHolder>(WishDiffUtil) {

override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): WishViewHolder {
return WishViewHolder(ItemWishBinding.inflate(LayoutInflater.from(parent.context), parent, false))
}

override fun onBindViewHolder(holder: WishViewHolder, position: Int) {
holder.bind(getItem(position))
}

class WishViewHolder(private val binding: ItemWishBinding): RecyclerView.ViewHolder(binding.root) {
fun bind(item: WishData.ResultData) {
binding.item = item
}
}

private object WishDiffUtil: DiffUtil.ItemCallback<WishData.ResultData>() {
override fun areItemsTheSame(oldItem: WishData.ResultData, newItem: WishData.ResultData) =
oldItem.roomId == newItem.roomId

override fun areContentsTheSame(oldItem: WishData.ResultData, newItem: WishData.ResultData) =
oldItem == newItem

}
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
package com.team16.airbnb.ui
package com.team16.airbnb.ui.wish

import android.os.Bundle
import androidx.fragment.app.Fragment
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.navigation.fragment.findNavController
import com.team16.airbnb.R
import com.team16.airbnb.data.model.wishList
import com.team16.airbnb.databinding.FragmentWishBinding


Expand All @@ -23,5 +26,16 @@ class WishFragment : Fragment() {

override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)

val adapter = WishAdapter()
binding.rvWishList.adapter = adapter
setBackButton()
adapter.submitList(wishList)
}

private fun setBackButton() {
binding.topAppBar.setNavigationOnClickListener {
findNavController().navigate(R.id.homeFragment)
}
}
}
3 changes: 2 additions & 1 deletion Android/app/src/main/res/drawable/ic_favorite_outline.xml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<vector android:height="24dp" android:tint="#000000"
<vector android:height="24dp" android:tint="@color/airbnb_Primary"
android:strokeColor="@color/airbnb_offWhite" android:strokeWidth="4"
android:viewportHeight="24" android:viewportWidth="24"
android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
<path android:fillColor="@color/airbnb_offWhite" android:pathData="M12,21.35l-1.45,-1.32C5.4,15.36 2,12.28 2,8.5 2,5.42 4.42,3 7.5,3c1.74,0 3.41,0.81 4.5,2.09C13.09,3.81 14.76,3 16.5,3 19.58,3 22,5.42 22,8.5c0,3.78 -3.4,6.86 -8.55,11.54L12,21.35z"/>
Expand Down
2 changes: 1 addition & 1 deletion Android/app/src/main/res/layout/fragment_home.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".ui.HomeFragment">
tools:context=".ui.home.HomeFragment">

<androidx.compose.ui.platform.ComposeView
android:id="@+id/composeView_in_home"
Expand Down
29 changes: 24 additions & 5 deletions Android/app/src/main/res/layout/fragment_my_book.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto">

<data>

Expand All @@ -9,12 +10,30 @@
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".ui.MyBookFragment">
tools:context=".ui.mybook.MyBookFragment">

<TextView
<com.google.android.material.appbar.AppBarLayout
android:id="@+id/lo_appbar"
app:layout_constraintTop_toTopOf="parent"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="@string/label_my" />
android:layout_height="wrap_content">

<com.google.android.material.appbar.MaterialToolbar
android:id="@+id/topAppBar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="@color/airbnb_offWhite"
app:title="예약"
app:navigationIcon="@drawable/ic_back" />

</com.google.android.material.appbar.AppBarLayout>

<androidx.recyclerview.widget.RecyclerView
android:id="@+id/rv_book_list"
android:layout_width="match_parent"
android:layout_height="0dp"
app:layout_constraintTop_toBottomOf="@id/lo_appbar"
app:layout_constraintBottom_toBottomOf="parent"/>

</androidx.constraintlayout.widget.ConstraintLayout>
</layout>
Loading