Skip to content

Commit

Permalink
Merge pull request #139 from juyoung0520/feature/#127
Browse files Browse the repository at this point in the history
Feature:#127 거래 내역 화면 구현
  • Loading branch information
juyoung0520 authored Dec 6, 2022
2 parents cbb66a6 + 7eed155 commit 52b8f09
Show file tree
Hide file tree
Showing 30 changed files with 611 additions and 20 deletions.
8 changes: 5 additions & 3 deletions buildSrc/src/main/java/com/gta/buildsrc/Dependencies.kt
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ object Dependencies {
const val STARTUP = "1.2.0-alpha01"
const val SPLASH = "1.0.0"
const val DATASTORE = "1.0.0"
const val SWIPE_REFRESH_LAYOUT = "1.1.0"

// KTX
const val KOTLIN = "1.7.10"
Expand Down Expand Up @@ -72,6 +73,8 @@ object Dependencies {
const val CORE = "androidx.core:core-ktx:${Versions.CORE}"
const val STARTUP = "androidx.startup:startup-runtime:${Versions.STARTUP}"
const val SPLASH = "androidx.core:core-splashscreen:${Versions.SPLASH}"
const val DATASTORE = "androidx.datastore:datastore-preferences:${Versions.DATASTORE}"
const val SWIPE_REFRESH_LAYOUT = "androidx.swiperefreshlayout:swiperefreshlayout:${Versions.SWIPE_REFRESH_LAYOUT}"

fun getAll(): ArrayList<String> {
return arrayListOf(APP_COMPAT, CORE)
Expand Down Expand Up @@ -209,8 +212,6 @@ object Dependencies {

const val INJECT = "javax.inject:javax.inject:${Versions.INJECT}"

const val DATASTORE = "androidx.datastore:datastore-preferences:${Versions.DATASTORE}"

object Test {
const val EXT = "androidx.test.ext:junit:${Versions.JUNIT_EXT}"
const val JUNIT = "junit:junit:${Versions.JUNIT}"
Expand Down Expand Up @@ -240,7 +241,7 @@ object Dependencies {
addAll(Room.getAll())
add(TIMBER)
addAll(Retrofit.getAll())
add(DATASTORE)
add(AndroidX.DATASTORE)
add(LOGGING_INTERCEPTER)
add(Paging.PAGING)
}
Expand Down Expand Up @@ -275,6 +276,7 @@ object Dependencies {
add(INDICATOR)
add(LOTTIE)
add(Paging.PAGING)
add(AndroidX.SWIPE_REFRESH_LAYOUT)
}

val presentationKaptLibraries = arrayListOf<String>().apply {
Expand Down
10 changes: 10 additions & 0 deletions data/src/main/java/com/gta/data/di/RepositoryModule.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,18 @@ package com.gta.data.di
import com.gta.data.repository.CarRepositoryImpl
import com.gta.data.repository.MapRepositoryImpl
import com.gta.data.repository.ReportRepositoryImpl
import com.gta.data.repository.TransactionRepositoryImpl
import com.gta.data.repository.UserRepositoryImpl
import com.gta.data.source.CarDataSource
import com.gta.data.source.MapDataSource
import com.gta.data.source.ReservationDataSource
import com.gta.data.source.StorageDataSource
import com.gta.data.source.TransactionDataSource
import com.gta.data.source.UserDataSource
import com.gta.domain.repository.CarRepository
import com.gta.domain.repository.MapRepository
import com.gta.domain.repository.ReportRepository
import com.gta.domain.repository.TransactionRepository
import com.gta.domain.repository.UserRepository
import dagger.Module
import dagger.Provides
Expand Down Expand Up @@ -58,4 +61,11 @@ class RepositoryModule {
@Singleton
fun provideReportRepository(userDataSource: UserDataSource): ReportRepository =
ReportRepositoryImpl(userDataSource)

@Provides
@Singleton
fun provideTransactionRepository(
transactionDataSource: TransactionDataSource
): TransactionRepository =
TransactionRepositoryImpl(transactionDataSource)
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import com.gta.domain.model.LocationInfo
import com.gta.domain.model.UCMCResult
import com.gta.domain.repository.MapRepository
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.catch
import kotlinx.coroutines.flow.flow
import timber.log.Timber
import javax.inject.Inject
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.gta.data.repository

import com.gta.data.source.TransactionDataSource
import com.gta.domain.model.SimpleReservation
import com.gta.domain.repository.TransactionRepository
import kotlinx.coroutines.flow.first
import javax.inject.Inject

class TransactionRepositoryImpl @Inject constructor(private val transactionDataSource: TransactionDataSource) : TransactionRepository {
override suspend fun getYourCarTransactions(uid: String): List<SimpleReservation> {
return transactionDataSource.getYourCarTransactions(uid).first()
}

override suspend fun getMyCarTransactions(uid: String): List<SimpleReservation> {
return transactionDataSource.getMyCarTransactions(uid).first()
}
}
43 changes: 43 additions & 0 deletions data/src/main/java/com/gta/data/source/TransactionDataSource.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package com.gta.data.source

import com.google.firebase.firestore.FirebaseFirestore
import com.gta.domain.model.Reservation
import com.gta.domain.model.SimpleReservation
import com.gta.domain.model.toSimpleReservation
import kotlinx.coroutines.channels.awaitClose
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.callbackFlow
import javax.inject.Inject

class TransactionDataSource @Inject constructor(private val fireStore: FirebaseFirestore) {

fun getYourCarTransactions(uid: String): Flow<List<SimpleReservation>> = callbackFlow {
fireStore.collection("reservations").whereEqualTo("lenderId", uid).get().addOnCompleteListener {
if (it.isSuccessful) {
it.result.map { snapshot ->
snapshot.toObject(Reservation::class.java).toSimpleReservation(snapshot.id)
}.also { result ->
trySend(result)
}
} else {
trySend(emptyList())
}
}
awaitClose()
}

fun getMyCarTransactions(uid: String): Flow<List<SimpleReservation>> = callbackFlow {
fireStore.collection("reservations").whereEqualTo("ownerId", uid).get().addOnCompleteListener {
if (it.isSuccessful) {
it.result.map { snapshot ->
snapshot.toObject(Reservation::class.java).toSimpleReservation(snapshot.id)
}.also { result ->
trySend(result)
}
} else {
trySend(emptyList())
}
}
awaitClose()
}
}
2 changes: 1 addition & 1 deletion domain/src/main/java/com/gta/domain/model/CarDetail.kt
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,5 @@ data class CarDetail(
val availableDate: AvailableDate = AvailableDate(),
val images: List<String> = emptyList(),
val owner: UserProfile = UserProfile(),
val coordinate: Coordinate = Coordinate(),
val coordinate: Coordinate = Coordinate()
)
1 change: 1 addition & 0 deletions domain/src/main/java/com/gta/domain/model/Reservation.kt
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,6 @@ data class Reservation(
fun Reservation.toSimpleReservation(reservationId: String): SimpleReservation = SimpleReservation(
reservationId = reservationId,
carId = carId,
reservationState = state,
reservationDate = reservationDate
)
11 changes: 11 additions & 0 deletions domain/src/main/java/com/gta/domain/model/SimpleReservation.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,16 @@ package com.gta.domain.model
data class SimpleReservation(
val reservationId: String = "",
val carId: String = "",
val reservationState: Int = ReservationState.PENDING.state,
val reservationDate: AvailableDate = AvailableDate()
)

fun SimpleReservation.toTransaction(simpleCar: SimpleCar): Transaction {
return Transaction(
reservationId = reservationId,
reservationState = ReservationState.values().find { it.state == reservationState } ?: ReservationState.RENTING,
reservationDate = reservationDate,
carModel = simpleCar.model,
thumbnailImg = simpleCar.image
)
}
9 changes: 9 additions & 0 deletions domain/src/main/java/com/gta/domain/model/Transaction.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.gta.domain.model

data class Transaction(
val reservationId: String = "",
val reservationState: ReservationState = ReservationState.PENDING,
val reservationDate: AvailableDate = AvailableDate(),
val carModel: String = "",
val thumbnailImg: String = ""
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.gta.domain.repository

import com.gta.domain.model.SimpleReservation

interface TransactionRepository {
suspend fun getYourCarTransactions(uid: String): List<SimpleReservation>
suspend fun getMyCarTransactions(uid: String): List<SimpleReservation>
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package com.gta.domain.usecase.transaction

import com.gta.domain.model.Transaction
import com.gta.domain.model.toTransaction
import com.gta.domain.repository.CarRepository
import com.gta.domain.repository.TransactionRepository
import kotlinx.coroutines.flow.first
import javax.inject.Inject

class GetTransactionsUseCase @Inject constructor(
private val carRepository: CarRepository,
private val transactionRepository: TransactionRepository
) {
private val tradingCondition =
{ transaction: Transaction -> transaction.reservationState.state >= 0 }
private val completedCondition =
{ transaction: Transaction -> transaction.reservationState.state < 0 }

suspend operator fun invoke(
uid: String,
isLender: Boolean,
isTrading: Boolean
): List<Transaction> {
val transactions = if (isLender) {
transactionRepository.getYourCarTransactions(uid)
} else {
transactionRepository.getMyCarTransactions(uid)
}

val filterCondition = if (isTrading) tradingCondition else completedCondition

return transactions.map { reservation ->
val simpleCar = carRepository.getSimpleCar(reservation.carId).first()
reservation.toTransaction(simpleCar)
}.filter(filterCondition)
}
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.gta.presentation.model

import android.os.Parcelable
import kotlinx.parcelize.Parcelize

@Parcelize
enum class TransactionState : Parcelable {
TRADING, COMPLETED
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.gta.presentation.model

import android.os.Parcelable
import kotlinx.parcelize.Parcelize

@Parcelize
enum class TransactionUserState : Parcelable {
LENDER, OWNER
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,11 @@ import android.widget.Button
import android.widget.ImageView
import android.widget.TextView
import androidx.databinding.BindingAdapter
import androidx.recyclerview.widget.ListAdapter
import androidx.recyclerview.widget.RecyclerView
import com.gta.domain.model.AvailableDate
import com.gta.domain.model.NotificationType
import com.gta.domain.model.ReservationState
import com.gta.domain.usecase.cardetail.UseState
import com.gta.presentation.R
import com.gta.presentation.model.DateType
Expand Down Expand Up @@ -51,11 +54,7 @@ fun setReservationTime(textView: TextView, selection: AvailableDate?, dateType:
when (dateType) {
DateType.RANGE -> {
textView.text = selection?.let {
"${DateUtil.dateFormat.format(selection.start)} ~ ${
DateUtil.dateFormat.format(
selection.end
)
}"
"${DateUtil.dateFormat.format(selection.start)} ~ ${DateUtil.dateFormat.format(selection.end)}"
} ?: textView.resources.getString(R.string.placeholder_date_range)
}
DateType.DAY_COUNT -> {
Expand Down Expand Up @@ -128,3 +127,32 @@ fun setNotificationListItemBody(
}
}
}

@BindingAdapter("reservation_state")
fun setReservationState(textView: TextView, reservationState: ReservationState) {
textView.text =
when (reservationState) {
ReservationState.CANCEL -> {
textView.resources.getString(R.string.cancel)
}
ReservationState.PENDING -> {
textView.resources.getString(R.string.pending)
}
ReservationState.ACCEPT -> {
textView.resources.getString(R.string.accept)
}
ReservationState.RENTING -> {
textView.resources.getString(R.string.renting)
}
ReservationState.DONE -> {
textView.resources.getString(R.string.return_completed)
}
}
}

@BindingAdapter("submitList")
fun bindSubmitList(view: RecyclerView, itemList: List<Any>?) {
view.adapter?.let {
(view.adapter as ListAdapter<Any, *>).submitList(itemList)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -122,12 +122,11 @@ class CarDetailFragment : BaseFragment<FragmentCarDetailBinding>(
}
}


override fun onStop() {
viewModel.stopCollect()
super.onStop()
}

private fun handleErrorMessage(e: Exception) {
when (e) {
is FirestoreException -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import com.google.android.material.datepicker.CalendarConstraints
import com.google.android.material.datepicker.DateValidatorPointForward
import com.google.android.material.datepicker.MaterialDatePicker
import com.google.android.material.snackbar.Snackbar
import com.gta.domain.model.Coordinate
import com.gta.presentation.R
import com.gta.presentation.databinding.FragmentCarEditBinding
import com.gta.presentation.ui.base.BaseFragment
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ class CarEditViewModel @Inject constructor(
val availableDate: StateFlow<AvailableDate>
get() = _availableDate


private val _location = MutableStateFlow<String>("정보 없음")
val location: StateFlow<String>
get() = _location
Expand Down Expand Up @@ -77,7 +76,6 @@ class CarEditViewModel @Inject constructor(
_location.value = carInfo.data.location
coordinate = carInfo.data.coordinate
}

}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import androidx.lifecycle.viewModelScope
import com.gta.domain.model.Coordinate
import com.gta.domain.model.LocationInfo
import com.gta.domain.model.SimpleCar
import com.gta.domain.usecase.cardetail.edit.GetCoordinateLocationUseCase
import com.gta.domain.model.UCMCResult
import com.gta.domain.usecase.cardetail.edit.GetCoordinateLocationUseCase
import com.gta.domain.usecase.map.GetNearCarsUseCase
import com.gta.domain.usecase.map.GetSearchAddressUseCase
import com.gta.presentation.util.EventFlow
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,12 @@ class MyPageFragment : BaseFragment<FragmentMypageBinding>(
binding.btnMypageLicense.setOnClickListener {
findNavController().navigate(R.id.action_myPageFragment_to_myPageLicenseFragment)
}
binding.btnMypageBuyHistory.setOnClickListener {
findNavController().navigate(MyPageFragmentDirections.actionMyPageFragmentToTransactionListFragment(getString(R.string.mypage_btn_transaction_buy)))
}
binding.btnMypageSellHistory.setOnClickListener {
findNavController().navigate(MyPageFragmentDirections.actionMyPageFragmentToTransactionListFragment(getString(R.string.mypage_btn_transaction_sell)))
}
}

private fun initCollector() {
Expand Down
Loading

0 comments on commit 52b8f09

Please sign in to comment.