Skip to content

Commit

Permalink
Merge pull request UMC-5th-Coumo#76 from UMC-5th-Coumo/feat_#65-api
Browse files Browse the repository at this point in the history
  • Loading branch information
NaZe0320 authored Feb 17, 2024
2 parents 30a80af + b5581f9 commit 7c94021
Show file tree
Hide file tree
Showing 10 changed files with 79 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,29 +44,29 @@ class CoumoRepositoryImpl @Inject constructor(
page: Int?
): List<StoreCouponCountModel>? {
val data = coumoApi.getNearStoreList(
App.prefs.getInt(CUSTOMER_ID, 1),
App.prefs.getInt(CUSTOMER_ID, 0),
category?.api, longitude, latitude, page)
return mapToStoreCouponCountModelList(data.body()?.result)
}

override suspend fun getStoreData(storeId: Int): StoreInfoModel? {
val data = coumoApi.getStoreData(App.prefs.getInt(CUSTOMER_ID,1),storeId)
val data = coumoApi.getStoreData(App.prefs.getInt(CUSTOMER_ID,0),storeId)
return mapToStoreInfoModel(data.body()?.result)
}

override suspend fun getMyPage(): MyPageModel? {
val data = coumoApi.getMyPageData(App.prefs.getInt(CUSTOMER_ID,1))
val data = coumoApi.getMyPageData(App.prefs.getInt(CUSTOMER_ID,0))
return mapToMyPageModel(data.body()?.result)
}

override suspend fun getCouponList(filter: CouponAlignType): List<CouponModel> {
val data = coumoApi.getCouponList(App.prefs.getInt(CUSTOMER_ID,1),filter.api)
val data = coumoApi.getCouponList(App.prefs.getInt(CUSTOMER_ID,0),filter.api)
Log.d("TEST http list", "${data.body()}")
return emptyList()
}

override suspend fun getCouponStore(storeId: Int): CouponModel? {
val data = coumoApi.getCouponStore(App.prefs.getInt(CUSTOMER_ID,1),storeId)
val data = coumoApi.getCouponStore(App.prefs.getInt(CUSTOMER_ID,0),storeId)
Log.d("TEST http store", "${data.body()}")
return CouponModel("",0, stampImage = null)
}
Expand All @@ -79,7 +79,7 @@ class CoumoRepositoryImpl @Inject constructor(
val data = coumoApi.postOwnerStamp(RequestOwnerQRModel(
storeId = storeId,
customerId = customerId,
ownerId = App.prefs.getInt(OWNER_ID,1),
ownerId = App.prefs.getInt(OWNER_ID,35),
stampCnt = stampCnt
))
return data.isSuccessful
Expand All @@ -93,7 +93,7 @@ class CoumoRepositoryImpl @Inject constructor(
val data = coumoApi.postOwnerPayment(RequestOwnerQRModel(
storeId = storeId,
customerId = customerId,
ownerId = App.prefs.getInt(OWNER_ID,1),
ownerId = App.prefs.getInt(OWNER_ID,35),
stampCnt = stampCnt
))
return data.isSuccessful
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import com.umc.coumo.data.remote.model.response.ResponseJoinModel
import com.umc.coumo.data.remote.model.response.ResponseLoginAsOwnerModel
import com.umc.coumo.data.remote.model.response.ResponseLoginModel
import com.umc.coumo.domain.repository.LoginRepository
import retrofit2.Response
import javax.inject.Inject

class LoginRepositoryImpl @Inject constructor(
Expand Down Expand Up @@ -81,6 +80,8 @@ class LoginRepositoryImpl @Inject constructor(

override suspend fun postLoginAsOwner(loginId: String, password: String): ResponseLoginAsOwnerModel? {
val data = loginApi.postLoginAsOwner(RequestLoginModel(loginId, password))
val token = data.body()?.result?.token
App.prefs.setString("accessToken", token ?: "")
App.prefs.setInt("ownerId", data.body()?.result?.ownerId ?: 0)
return mapToResponseLoginAsOwner(data.body()?.result)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@ class HomeViewModel @Inject constructor(
private val _timeDropDown = MutableLiveData<Boolean>(false)
val timeDropDown: LiveData<Boolean> get() = _timeDropDown

private val _currentPage = MutableLiveData<Int>(0)
val currentPage: LiveData<Int> get() = _currentPage

fun setCurrentLocation(longitude: Double, latitude: Double ) {
_currentLocation.value = LocationLatLng(longitude, latitude)
}
Expand Down Expand Up @@ -101,10 +104,19 @@ class HomeViewModel @Inject constructor(
getCouponStore(storeId)
_timeDropDown.value = false
} else {
listOf<StoreInfoModel>() //값을 못 받아 왔을 때, 빈 값 처리
_storeData.value = it //값을 못 받아 왔을 때, 빈 값 처리
}
}
}
}

fun resetPage() {
_currentPage.value = 0
Log.d("HTTP 페이지", "페이지 초기화")
}

fun addPage() {
_currentPage.value = _currentPage.value?.plus(1)
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ import com.umc.coumo.App
import com.umc.coumo.R
import com.umc.coumo.databinding.ActivityLoginBinding
import com.umc.coumo.domain.viewmodel.LoginViewModel
import com.umc.coumo.utils.Constants.ACCESS_TOKEN
import com.umc.coumo.utils.Constants.CUSTOMER_ID
import com.umc.coumo.utils.Constants.OWNER_ID
import com.umc.coumo.utils.binding.BindingActivity
import dagger.hilt.android.AndroidEntryPoint

Expand All @@ -22,8 +25,12 @@ class LoginActivity : BindingActivity<ActivityLoginBinding>(R.layout.activity_lo

//TODO(테스트 코드: 임시로 토큰이 10자 이하면 토큰이 없다고 판단)
private fun autoLogin() {
if (App.prefs.getString("accessToken","").length > 10 ) {
moveToMain()
if (App.prefs.getString(ACCESS_TOKEN,"").length > 10 ) {
if (App.prefs.getInt(CUSTOMER_ID, 0) != 0 ) {
moveToMain()
} else if (App.prefs.getInt(OWNER_ID, 0) != 0) {
moveToMainOwner()
}
}
}

Expand All @@ -32,4 +39,10 @@ class LoginActivity : BindingActivity<ActivityLoginBinding>(R.layout.activity_lo
startActivity(intent)
finish()
}

private fun moveToMainOwner() {
val intent = Intent(this, MainOwnerActivity::class.java)
startActivity(intent)
finish()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import androidx.activity.viewModels
import com.umc.coumo.R
import com.umc.coumo.databinding.ActivityMainBinding
import com.umc.coumo.domain.type.TabType
import com.umc.coumo.domain.viewmodel.AccountViewModel
import com.umc.coumo.domain.viewmodel.HomeViewModel
import com.umc.coumo.domain.viewmodel.MainViewModel
import com.umc.coumo.presentation.adapter.MainFragmentAdapter
Expand All @@ -22,6 +23,7 @@ class MainActivity : BindingActivity<ActivityMainBinding>(R.layout.activity_main

private val viewModel: MainViewModel by viewModels()
private val homeViewModel: HomeViewModel by viewModels()
private val profile : AccountViewModel by viewModels()

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
Expand All @@ -36,6 +38,8 @@ class MainActivity : BindingActivity<ActivityMainBinding>(R.layout.activity_main
setNaviButton()
setObserver()
setLocationPermission()

profile.getMyPage()
}

fun setLocationPermission() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import com.umc.coumo.databinding.FragmentAccountBinding
import com.umc.coumo.domain.type.AccountAction
import com.umc.coumo.domain.viewmodel.AccountViewModel
import com.umc.coumo.presentation.dialog.AccountBottomSheetDialog
import com.umc.coumo.utils.Constants.CUSTOMER_ID
import com.umc.coumo.utils.binding.BindingFragment

class AccountFragment: BindingFragment<FragmentAccountBinding>(R.layout.fragment_account) {
Expand All @@ -35,6 +36,7 @@ class AccountFragment: BindingFragment<FragmentAccountBinding>(R.layout.fragment
binding.btnLogout.setOnClickListener {
val dialog = AccountBottomSheetDialog(AccountAction.LOGOUT) {
App.prefs.setString("accessToken","") //Token 없애기
App.prefs.setString(CUSTOMER_ID,"") //Token 없애기
requireActivity().finish()
}
dialog.show(parentFragmentManager, null)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,28 +1,36 @@
package com.umc.coumo.presentation.fragment.home

import android.content.Context
import android.os.Bundle
import android.view.View
import androidx.fragment.app.activityViewModels
import androidx.navigation.fragment.findNavController
import androidx.recyclerview.widget.LinearLayoutManager
import com.umc.coumo.R
import com.umc.coumo.databinding.FragmentHomeListBinding
import com.umc.coumo.domain.viewmodel.AccountViewModel
import com.umc.coumo.domain.viewmodel.HomeViewModel
import com.umc.coumo.presentation.adapter.StoreCouponCountAdapter
import com.umc.coumo.utils.binding.BindingFragment

class HomeListFragment: BindingFragment<FragmentHomeListBinding>(R.layout.fragment_home_list) {

private val viewModel : HomeViewModel by activityViewModels ()
private val profile : AccountViewModel by activityViewModels()

override fun onAttach(context: Context) {
super.onAttach(context)
viewModel.resetPage()
}
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
binding.viewModel = viewModel
binding.lifecycleOwner = viewLifecycleOwner

setButton()

val storeCouponAdapter = StoreCouponCountAdapter()
binding.tvListTitle.text = profile.accountData.value?.name + "님 근처 "+viewModel.category.value?.title + " 매장"


binding.btnRefresh.setOnClickListener {
viewModel.loadStoreData(1)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import com.umc.coumo.databinding.FragmentOwnerAccountBinding
import com.umc.coumo.domain.type.AccountAction
import com.umc.coumo.presentation.dialog.AccountBottomSheetDialog
import com.umc.coumo.utils.Constants.ACCESS_TOKEN
import com.umc.coumo.utils.Constants.OWNER_ID
import com.umc.coumo.utils.binding.BindingFragment

class OwnerAccountFragment: BindingFragment<FragmentOwnerAccountBinding>(R.layout.fragment_owner_account) {
Expand All @@ -29,7 +30,8 @@ class OwnerAccountFragment: BindingFragment<FragmentOwnerAccountBinding>(R.layou

binding.btnLogout.setOnClickListener {
val dialog = AccountBottomSheetDialog(AccountAction.LOGOUT) {
App.prefs.setString(ACCESS_TOKEN,"") //Token 없애기
App.prefs.setString(ACCESS_TOKEN,"")
App.prefs.setString(OWNER_ID,"")//Token 없애기
requireActivity().finish()
}
dialog.show(parentFragmentManager, null)
Expand Down
16 changes: 9 additions & 7 deletions app/src/main/java/com/umc/coumo/utils/BindingAdapter.kt
Original file line number Diff line number Diff line change
Expand Up @@ -151,12 +151,14 @@ fun TextView.setTimeTableText(time: RunTimeModel?) {

@SuppressLint("SetTextI18n")
@BindingAdapter("currentTimeTableText")
fun TextView.setTimeTableText(runTimes: List<RunTimeModel>) {
val today = LocalDate.now().dayOfWeek.toString()
val time = runTimes.filter { it.day == today }
text = if (time.first().startTime != "none" && time.first().endTime != "none") {
"${time.first().day} : ${time.first().startTime} ~ ${time.first().endTime}"
} else {
"${time.first().day} : 휴무일"
fun TextView.setTimeTableText(runTimes: List<RunTimeModel>?) {
if (runTimes != null) {
val today = LocalDate.now().dayOfWeek.toString()
val time = runTimes.filter { it.day == today }
text = if (time.first().startTime != "none" && time.first().endTime != "none") {
"${time.first().day} : ${time.first().startTime} ~ ${time.first().endTime}"
} else {
"${time.first().day} : 휴무일"
}
}
}
30 changes: 15 additions & 15 deletions app/src/main/res/layout/fragment_home_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@
android:layout_height="wrap_content"
android:adjustViewBounds="true"
android:src="@drawable/image_cafe"
app:layout_constraintEnd_toStartOf="@id/iv_entertainment"
app:layout_constraintEnd_toStartOf="@id/iv_retail"
app:layout_constraintHorizontal_chainStyle="spread_inside"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
Expand All @@ -149,7 +149,7 @@


<androidx.constraintlayout.utils.widget.ImageFilterView
android:id="@+id/iv_entertainment"
android:id="@+id/iv_retail"
android:layout_width="68dp"
android:layout_height="wrap_content"
android:adjustViewBounds="true"
Expand All @@ -159,15 +159,15 @@
app:layout_constraintTop_toTopOf="parent" />

<TextView
android:id="@+id/tv_entertainment"
android:id="@+id/tv_retail"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="리테일"
android:textSize="12sp"
android:layout_marginTop="3dp"
app:layout_constraintStart_toStartOf="@id/iv_entertainment"
app:layout_constraintEnd_toEndOf="@id/iv_entertainment"
app:layout_constraintTop_toBottomOf="@id/iv_entertainment"/>
app:layout_constraintStart_toStartOf="@id/iv_retail"
app:layout_constraintEnd_toEndOf="@id/iv_retail"
app:layout_constraintTop_toBottomOf="@id/iv_retail"/>

<androidx.constraintlayout.utils.widget.ImageFilterView
android:id="@+id/iv_food"
Expand All @@ -176,7 +176,7 @@
android:adjustViewBounds="true"
android:src="@drawable/image_food"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@id/iv_entertainment"
app:layout_constraintStart_toEndOf="@id/iv_retail"
app:layout_constraintTop_toTopOf="parent" />

<TextView
Expand All @@ -191,7 +191,7 @@
app:layout_constraintTop_toBottomOf="@id/iv_food"/>

<androidx.constraintlayout.utils.widget.ImageFilterView
android:id="@+id/iv_retail"
android:id="@+id/iv_entertainment"
android:layout_width="68dp"
android:layout_height="wrap_content"
android:adjustViewBounds="true"
Expand All @@ -203,15 +203,15 @@
app:layout_constraintTop_toBottomOf="@id/tv_cafe" />

<TextView
android:id="@+id/tv_retail"
android:id="@+id/tv_entertainment"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="리테일"
android:text="오락/스포츠"
android:textSize="12sp"
android:layout_marginTop="3dp"
app:layout_constraintStart_toStartOf="@id/iv_retail"
app:layout_constraintEnd_toEndOf="@id/iv_retail"
app:layout_constraintTop_toBottomOf="@id/iv_retail"/>
app:layout_constraintStart_toStartOf="@id/iv_entertainment"
app:layout_constraintEnd_toEndOf="@id/iv_entertainment"
app:layout_constraintTop_toBottomOf="@id/iv_entertainment"/>

<androidx.constraintlayout.utils.widget.ImageFilterView
android:id="@+id/iv_beauty"
Expand All @@ -221,8 +221,8 @@
android:src="@drawable/image_beauty"
android:layout_marginTop="10dp"
app:layout_constraintEnd_toStartOf="@id/iv_class"
app:layout_constraintStart_toEndOf="@id/iv_retail"
app:layout_constraintTop_toBottomOf="@id/tv_entertainment" />
app:layout_constraintStart_toEndOf="@id/iv_entertainment"
app:layout_constraintTop_toBottomOf="@id/tv_retail" />

<TextView
android:id="@+id/tv_beauty"
Expand Down

0 comments on commit 7c94021

Please sign in to comment.