Skip to content

Commit

Permalink
[feat/#51] coupon item test
Browse files Browse the repository at this point in the history
  • Loading branch information
NaZe0320 committed Feb 13, 2024
1 parent 2e65c4d commit eb6dedd
Show file tree
Hide file tree
Showing 9 changed files with 133 additions and 51 deletions.
15 changes: 15 additions & 0 deletions app/src/main/java/com/umc/coumo/data/remote/api/CoumoApi.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import com.umc.coumo.data.remote.model.response.ResponseStoreDataModel
import com.umc.coumo.domain.type.CategoryType
import retrofit2.Response
import retrofit2.http.GET
import retrofit2.http.Headers
import retrofit2.http.POST
import retrofit2.http.Path
import retrofit2.http.Query

Expand All @@ -32,4 +34,17 @@ interface CoumoApi {
@Path("customerId") customerId: Int,
@Path("storeId") storeId: Int
): Response<ResponseModel<ResponseStoreDataModel>>

@Headers("Content-Type: image/png")
@POST("/api/qr/customer/stamp/{customerId}/{storeId}")
suspend fun postCustomerStamp(
@Path("customerId") customerId: Int,
@Path("storeId") storeId: Int,
): String

@POST("/api/qr/customer/payment/{customerId}/{storeId}")
suspend fun postCustomerPayment(
@Path("customerId") customerId: Int,
@Path("storeId") storeId: Int
): Response<Any>
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ class CoumoRepositoryImpl @Inject constructor(
//API Injection
private val coumoApi: CoumoApi
): CoumoRepository {

override suspend fun getPopularStoreList(
longitude: Double,
latitude: Double
Expand All @@ -44,6 +45,14 @@ class CoumoRepositoryImpl @Inject constructor(
return mapToStoreInfoModel(data.body()?.result)
}

override suspend fun postStampCustomer(storeId: Int): String? {
return coumoApi.postCustomerStamp(1, storeId)
}

override suspend fun postPaymentCustomer(storeId: Int): Uri? {
TODO("Not yet implemented")
}

private fun mapToStoreInfoModel(response: ResponseStoreDataModel?): StoreInfoModel? {
return if (response != null) {
StoreInfoModel(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package com.umc.coumo.data.remote.model.response

data class ResponseQR(
val qr: String?
)
4 changes: 3 additions & 1 deletion app/src/main/java/com/umc/coumo/di/RetrofitModule.kt
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import okhttp3.Response
import okhttp3.logging.HttpLoggingInterceptor
import retrofit2.Retrofit
import retrofit2.converter.gson.GsonConverterFactory
import retrofit2.converter.scalars.ScalarsConverterFactory
import java.io.IOException
import javax.inject.Singleton

Expand All @@ -31,7 +32,8 @@ object RetrofitModule {
fun provideApiService(): CoumoApi {
return Retrofit.Builder()
.baseUrl(BASE_URL)
.addConverterFactory(GsonConverterFactory.create())
.addConverterFactory(ScalarsConverterFactory.create())
.addConverterFactory(GsonConverterFactory.create(gson))
.client(okHttpClient(AppInterceptor())) //Interceptor 필요할 때
.build()
.create(CoumoApi::class.java)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.umc.coumo.domain.repository

import android.net.Uri
import com.umc.coumo.domain.model.StoreCouponCountModel
import com.umc.coumo.domain.model.StoreInfoItemModel
import com.umc.coumo.domain.model.StoreInfoModel
Expand All @@ -18,4 +19,12 @@ interface CoumoRepository {
suspend fun getStoreData(
storeId: Int
): StoreInfoModel?

suspend fun postStampCustomer(
storeId: Int
): String?

suspend fun postPaymentCustomer(
storeId: Int
): Uri?
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,18 @@ package com.umc.coumo.domain.viewmodel
import androidx.lifecycle.LiveData
import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import com.umc.coumo.domain.model.CouponModel
import com.umc.coumo.domain.repository.CoumoRepository
import com.umc.coumo.domain.type.CouponAlignType
import dagger.hilt.android.lifecycle.HiltViewModel
import kotlinx.coroutines.launch
import javax.inject.Inject

@HiltViewModel
class CouponViewModel @Inject constructor(): ViewModel() {
class CouponViewModel @Inject constructor(
private val repository: CoumoRepository
): ViewModel() {
private val _align = MutableLiveData(CouponAlignType.MOST)
val align: LiveData<CouponAlignType> get() = _align

Expand All @@ -19,6 +24,9 @@ class CouponViewModel @Inject constructor(): ViewModel() {
private val _currentCoupon = MutableLiveData<CouponModel>()
val currentCoupon: LiveData<CouponModel> get() = _currentCoupon

private val _currentQR = MutableLiveData<String?>()
val currentQR: LiveData<String?> get() = _currentQR

fun changeAlign(align: CouponAlignType) {
_align.value = align
}
Expand All @@ -32,4 +40,17 @@ class CouponViewModel @Inject constructor(): ViewModel() {
)
_couponList.value = list
}

fun postCustomerStamp(storeId: Int) {
viewModelScope.launch {
_currentQR.value = repository.postStampCustomer(storeId)
}
}

fun postCustomerPayment(storeId: Int) {
viewModelScope.launch {
//_currentQR.value = repository.postPaymentCustomer(storeId)
}
}

}
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
package com.umc.coumo.presentation.dialog

import android.app.Dialog
import android.os.Bundle
import android.view.View
import android.view.WindowManager
import androidx.recyclerview.widget.GridLayoutManager
import com.umc.coumo.R
import com.umc.coumo.databinding.DialogConfirmBinding
import com.umc.coumo.databinding.DialogCouponBinding
import com.umc.coumo.domain.model.CouponModel
import com.umc.coumo.domain.viewmodel.CouponViewModel
Expand All @@ -17,6 +14,10 @@ class CouponDialog(val viewModel: CouponViewModel) : BindingDialogFragment<Dialo

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

binding.coupon = viewModel
binding.lifecycleOwner = viewLifecycleOwner

val coupon = viewModel.currentCoupon.value?:
CouponModel(name = "가게 이름", stampCount = 0, stampMax = 10, stampImage = null)
val stampAdapter = StampAdapter()
Expand All @@ -27,6 +28,14 @@ class CouponDialog(val viewModel: CouponViewModel) : BindingDialogFragment<Dialo
)
}

binding.btnAdd.setOnClickListener {
viewModel.postCustomerStamp(1)
}

binding.btnUse.setOnClickListener {
viewModel.postCustomerPayment(1)
}

val result = MutableList(coupon.stampMax) { i -> i < coupon.stampCount }
stampAdapter.submitList(result)

Expand Down
13 changes: 13 additions & 0 deletions app/src/main/java/com/umc/coumo/utils/BindingAdapter.kt
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
package com.umc.coumo.utils

import android.content.res.ColorStateList
import android.graphics.BitmapFactory
import android.graphics.Color
import android.net.Uri
import android.text.Spannable
import android.text.SpannableString
import android.text.style.ForegroundColorSpan
import android.util.Log
import android.view.View
import android.view.ViewGroup
import android.widget.ImageView
Expand Down Expand Up @@ -74,6 +76,17 @@ fun setImageUri(imageView: ImageView, imageUri: Uri?) {
}
}

@BindingAdapter("imageQR")
fun setImageQR(imageView: ImageView, imageUri: String?) {
Log.d("TEST HTTP","$imageUri")
if (imageUri != null) {
imageView.setImageBitmap(BitmapFactory.decodeStream(imageUri.byteInputStream()))
} else {
imageView.setImageResource(R.drawable.default_image)
imageView.scaleType = ImageView.ScaleType.CENTER_CROP
}
}

@BindingAdapter("highlightText")
fun TextView.setHighlightedText(fullText: String?) {
fullText?.let {
Expand Down
91 changes: 45 additions & 46 deletions app/src/main/res/layout/dialog_coupon.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<data>
<variable
name="coupon"
type="com.umc.coumo.domain.model.CouponModel" />
type="com.umc.coumo.domain.viewmodel.CouponViewModel" />
</data>

<androidx.constraintlayout.widget.ConstraintLayout
Expand Down Expand Up @@ -34,61 +34,24 @@
android:layout_height="180dp"
android:background="@drawable/shape_rect_round_6"
android:paddingTop="28dp"
app:dynamicBackgroundColor="@{coupon.color}"
app:dynamicBackgroundColor="@{coupon.currentCoupon.color}"
app:layout_constraintDimensionRatio="308:180"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
tools:backgroundTint="#FFDA26">

<TextView
<androidx.constraintlayout.utils.widget.ImageFilterView
android:id="@+id/tv_qr"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_width="200dp"
android:layout_height="200dp"
android:fontFamily="@font/modak_400"
android:text="QR uri"
imageQR="@{coupon.currentQR}"
android:textSize="22sp"
app:dynamicTextColor="@{coupon.fontColor}"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
tools:text="COFFEE SHOP" />

<TextView
android:id="@+id/btn_add"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:background="@drawable/shape_rect_side_round"
android:backgroundTint="@color/sub"
android:paddingHorizontal="28dp"
android:paddingVertical="8dp"
android:text="적립하기"
android:textColor="@color/main"
android:textSize="16sp"
app:layout_constraintEnd_toStartOf="@+id/btn_use"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent"/>

<TextView
android:id="@+id/btn_use"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:background="@drawable/shape_rect_side_round"
android:backgroundTint="@color/sub"
android:paddingHorizontal="28dp"
android:paddingVertical="8dp"
android:text="사용하기"
android:textColor="@color/main"
android:textSize="16sp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toEndOf="@+id/btn_add"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent" />
app:layout_constraintTop_toTopOf="parent"/>

</androidx.constraintlayout.widget.ConstraintLayout>

Expand All @@ -98,7 +61,7 @@
android:layout_height="match_parent"
android:background="@drawable/shape_rect_round_6"
android:paddingTop="28dp"
app:dynamicBackgroundColor="@{coupon.color}"
app:dynamicBackgroundColor="@{coupon.currentCoupon.color}"
tools:backgroundTint="#FFDA26">

<TextView
Expand All @@ -108,7 +71,7 @@
android:fontFamily="@font/modak_400"
android:text="COFFEE SHOP"
android:textSize="22sp"
app:dynamicTextColor="@{coupon.fontColor}"
app:dynamicTextColor="@{coupon.currentCoupon.fontColor}}"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
Expand All @@ -125,5 +88,41 @@
</androidx.constraintlayout.widget.ConstraintLayout>

</com.wajahatkarim3.easyflipview.EasyFlipView>

<TextView
android:id="@+id/btn_add"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:background="@drawable/shape_rect_side_round"
android:backgroundTint="@color/sub"
android:paddingHorizontal="28dp"
android:paddingVertical="8dp"
android:text="적립하기"
android:textColor="@color/main"
android:textSize="16sp"
app:layout_constraintEnd_toStartOf="@+id/btn_use"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent"/>

<TextView
android:id="@+id/btn_use"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:background="@drawable/shape_rect_side_round"
android:backgroundTint="@color/sub"
android:paddingHorizontal="28dp"
android:paddingVertical="8dp"
android:text="사용하기"
android:textColor="@color/main"
android:textSize="16sp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toEndOf="@+id/btn_add"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
</layout>

0 comments on commit eb6dedd

Please sign in to comment.