Skip to content

Commit

Permalink
Merge pull request #59 from briandr97/record
Browse files Browse the repository at this point in the history
시연 전 모든 남은 기능 구현
  • Loading branch information
briandr97 committed Jul 23, 2022
2 parents 8a4b31a + 60c95ef commit 215efa6
Show file tree
Hide file tree
Showing 13 changed files with 267 additions and 113 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -103,11 +103,11 @@ class HomeFragment : BaseFragment<FragmentHomeBinding>(R.layout.fragment_home) {

//데이터 랜덤을 위한 로직
val nobarList = listOf(
NobarRecipesResponse("1", R.string.homeAdapter1,R.drawable.ic_img_mojito),
NobarRecipesResponse("2", R.string.homeAdapter2, R.drawable.ic_img_bluehawaii),
NobarRecipesResponse("3", R.string.homeAdapter3, R.drawable.ic_img_sexonthebeach),
NobarRecipesResponse("4", R.string.homeAdapter4, R.drawable.ic_img_peachcrush),
NobarRecipesResponse("5", R.string.homeAdapter5, R.drawable.ic_img_cinderella)
NobarRecipesResponse("62dafdc9c146e2cc2d52f3e8", R.string.homeAdapter1,R.drawable.ic_img_mojito),
NobarRecipesResponse("62dafdc9c146e2cc2d52f3e2", R.string.homeAdapter2, R.drawable.ic_img_bluehawaii),
NobarRecipesResponse("62dafdc9c146e2cc2d52f3d8", R.string.homeAdapter3, R.drawable.ic_img_sexonthebeach),
NobarRecipesResponse("62dafdc9c146e2cc2d52f422", R.string.homeAdapter4, R.drawable.ic_img_peachcrush),
NobarRecipesResponse("62dafdc9c146e2cc2d52f417", R.string.homeAdapter5, R.drawable.ic_img_cinderella)
)

/* var randomRecipeList = mutableListOf<Int>()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,15 @@ import androidx.activity.result.ActivityResultLauncher
import androidx.activity.result.contract.ActivityResultContracts
import androidx.fragment.app.viewModels
import org.sopt.appzam.nobar_android.R
import org.sopt.appzam.nobar_android.data.remote.response.TastingNoteResponse
import org.sopt.appzam.nobar_android.databinding.FragmentMyPageTastingBinding
import org.sopt.appzam.nobar_android.presentation.base.BaseFragment
import org.sopt.appzam.nobar_android.presentation.main.mypage.adapter.MultiViewAdapter
import org.sopt.appzam.nobar_android.presentation.main.record.RecordActivity
import org.sopt.appzam.nobar_android.presentation.main.record.RecordActivity.Companion.MODE
import org.sopt.appzam.nobar_android.presentation.main.record.RecordActivity.Companion.NEW
import org.sopt.appzam.nobar_android.presentation.main.record.RecordActivity.Companion.NOTE_ID
import org.sopt.appzam.nobar_android.presentation.main.record.RecordActivity.Companion.READ

class MyPageTastingFragment :
BaseFragment<FragmentMyPageTastingBinding>(R.layout.fragment_my_page_tasting) {
Expand Down Expand Up @@ -54,17 +57,23 @@ class MyPageTastingFragment :
resultLauncher =
registerForActivityResult(ActivityResultContracts.StartActivityForResult()) { result ->
if (result.resultCode == RESULT_OK) {
initNetwork()
initObserver()
myPageViewModel.reMyPageNetwork()
}
}
}

private fun tastingNoteAdapter() {
multiViewAdapter = MultiViewAdapter()
multiViewAdapter = MultiViewAdapter { itemClick(it) }
binding.recyclerMyPageTasting.adapter = multiViewAdapter
}

private fun itemClick(tastingNoteResponse: TastingNoteResponse) {
val intent = Intent(requireContext(), RecordActivity::class.java)
intent.putExtra(MODE, READ)
intent.putExtra(NOTE_ID, tastingNoteResponse.id)
startActivity(intent)
}

private fun initNetwork() {
myPageViewModel.myPageNetwork()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ class MyPageViewModel : ViewModel() {
val state: LiveData<Boolean> get() = _state

private var _laterRecipes = MutableLiveData<List<RecipeResponse>>()
val laterRecipes : LiveData<List<RecipeResponse>> get() = _laterRecipes
val laterRecipes: LiveData<List<RecipeResponse>> get() = _laterRecipes

private var _tastingNotes = MutableLiveData<List<TastingNoteResponse>>()
val tastingNotes : LiveData<List<TastingNoteResponse>> get() = _tastingNotes
val tastingNotes: LiveData<List<TastingNoteResponse>> get() = _tastingNotes


fun myPageNetwork() {
Expand All @@ -34,4 +34,17 @@ class MyPageViewModel : ViewModel() {
}
)
}

fun reMyPageNetwork() {
call.clone().enqueueUtil(
onSuccess = {
_state.value = true
_laterRecipes.value = it.laterRecipes
_tastingNotes.value = it.tastingNotes
},
onError = {
Log.d("status", it.toString())
}
)
}
}
Original file line number Diff line number Diff line change
@@ -1,56 +1,63 @@
package org.sopt.appzam.nobar_android.presentation.main.mypage.adapter

import android.util.Log
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.recyclerview.widget.DiffUtil
import androidx.recyclerview.widget.ListAdapter
import androidx.recyclerview.widget.RecyclerView
import org.sopt.appzam.nobar_android.data.remote.response.MyPageTastingResponse
import org.sopt.appzam.nobar_android.data.remote.response.TagResponse
import org.sopt.appzam.nobar_android.data.remote.response.TastingNoteResponse
import org.sopt.appzam.nobar_android.databinding.ItemMyPageTastingNoteBinding
import org.sopt.appzam.nobar_android.databinding.ItemMyPageTastingNoteDateBinding
import java.lang.RuntimeException

class MultiViewAdapter :
class MultiViewAdapter(private val itemClick: (TastingNoteResponse) -> Unit) :
ListAdapter<TastingNoteResponse, RecyclerView.ViewHolder>(TastingNoteTagComparator()) {


inner class DateViewHolder(private val binding: ItemMyPageTastingNoteDateBinding) :
class DateViewHolder(private val binding: ItemMyPageTastingNoteDateBinding) :
RecyclerView.ViewHolder(binding.root) {
fun onBind(data: TastingNoteResponse) {
fun onBind(data: TastingNoteResponse, itemClick: (TastingNoteResponse) -> Unit) {
binding.tastingNoteDateItem = data

binding.ratingHeart.rating=data.rate.toFloat()
binding.ratingHeart.setOnTouchListener(View.OnTouchListener { v, event -> true })
val recipeTagAdapter = TastingNoteTagAdapter()
binding.recyclerTag.adapter = recipeTagAdapter

var tagList = mutableListOf<TagResponse>()
val tagList = mutableListOf<TagResponse>()

for(i in 0 until data.tag.count()){
if(data.tag[i].isSelected)
for (i in 0 until data.tag.count()) {
if (data.tag[i].isSelected)
tagList.add(data.tag[i])
}

recipeTagAdapter.submitList(tagList)

itemView.setOnClickListener {
itemClick(data)
}
}
}

inner class TastingViewHolder(private val binding: ItemMyPageTastingNoteBinding) :
RecyclerView.ViewHolder(binding.root) {
fun onBind(data: TastingNoteResponse) {
fun onBind(data: TastingNoteResponse, itemClick: (TastingNoteResponse) -> Unit) {
binding.myPageTastingNoteItem = data

val recipeTagAdapter = TastingNoteTagAdapter()

binding.recyclerTag.adapter = recipeTagAdapter
var tagList = mutableListOf<TagResponse>()
val tagList = mutableListOf<TagResponse>()

for(i in 0 until data.tag.count()){
if(data.tag[i].isSelected)
for (i in 0 until data.tag.count()) {
if (data.tag[i].isSelected)
tagList.add(data.tag[i])
}
recipeTagAdapter.submitList(tagList)

itemView.setOnClickListener {
itemClick(data)
}
}
}

Expand Down Expand Up @@ -79,9 +86,9 @@ class MultiViewAdapter :
}

override fun onBindViewHolder(holder: RecyclerView.ViewHolder, position: Int) {
when(holder){
is DateViewHolder -> holder.onBind(getItem(position))
is TastingViewHolder -> holder.onBind(getItem(position))
when (holder) {
is DateViewHolder -> holder.onBind(getItem(position), itemClick)
is TastingViewHolder -> holder.onBind(getItem(position), itemClick)
else -> throw IllegalArgumentException()
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,60 @@ package org.sopt.appzam.nobar_android.presentation.main.record

import android.os.Bundle
import android.view.View
import android.view.View.OnTouchListener
import androidx.fragment.app.activityViewModels
import org.sopt.appzam.nobar_android.R
import org.sopt.appzam.nobar_android.databinding.FragmentRecordReadBinding
import org.sopt.appzam.nobar_android.presentation.base.BaseFragment


class RecordReadFragment : BaseFragment<FragmentRecordReadBinding>(R.layout.fragment_record_read) {
private val recordViewModel: RecordViewModel by activityViewModels()
private lateinit var tagAdapter: RecordTagAdapter

override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
binding.viewmodel=recordViewModel
binding.viewmodel = recordViewModel
initAdapter()
putDate()
putRating()
initTagList()
clickX()
}

private fun initAdapter() {
tagAdapter = RecordTagAdapter{ }
tagAdapter = RecordTagAdapter { }
binding.recyclerView.adapter = tagAdapter
}

private fun initTagList() {
recordViewModel.tagList.observe(viewLifecycleOwner) {
tagAdapter.submitList(it)
}
}

private fun clickX(){
binding.imageX.setOnClickListener {
activity?.finish()
}
}

private fun putDate() {
recordViewModel.drinkingDate.observe(viewLifecycleOwner) {
val yearRange = IntRange(0, 3)
val monthRange = IntRange(5, 6)
val dayRange = IntRange(8, 9)
val year = it.slice(yearRange).toInt()
val month = it.slice(monthRange).toInt()
val day = it.slice(dayRange).toInt()
binding.textWhen.text = String.format("%d년 %2d월 %2d일", year, month, day)
}
}

private fun putRating() {
recordViewModel.rating.observe(viewLifecycleOwner) {
binding.rotationRatingBar.rating = it.toFloat()
}
binding.rotationRatingBar.setOnTouchListener(OnTouchListener { v, event -> true })
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ class RecordTagAdapter(private val itemClick: (TagResponse) -> Unit) :
RecyclerView.ViewHolder(binding.root) {
fun onBind(data: TagResponse) {
binding.model = data
Glide.with(binding.imageIcon).load(data.activeIcon).error(R.drawable.cocktail_sample)
val url = if(data.isSelected) data.activeIcon else data.inActiveIcon
Glide.with(binding.imageIcon).load(url).error(R.drawable.cocktail_sample)
.into(binding.imageIcon)

itemView.setOnClickListener {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ import org.sopt.appzam.nobar_android.data.remote.response.TastingNoteResponse
import org.sopt.appzam.nobar_android.presentation.base.NobarViewModel
import org.sopt.appzam.nobar_android.util.enqueueUtil
import retrofit2.Call
import java.text.SimpleDateFormat
import java.util.*

class RecordViewModel() : NobarViewModel() {
//서버에서 받아오는 태그 리스트
Expand All @@ -31,22 +29,25 @@ class RecordViewModel() : NobarViewModel() {
val cocktailTip = MutableLiveData<String>()
val TipCount = MutableLiveData(0)
val isTagCountMax = MutableLiveData(false)
val isTagClicked=MutableLiveData(false)
val isTagClicked = MutableLiveData(false)

// 쓰기 시 가져올 id
var cocktailId : String = ""
var cocktailId: String = ""

// 날짜 보내기 편하기 위해서
var tmpDate = ""

var tagCount = 0

// 쓰기 시 태그 선택하는 로직
fun setSelectedTag(tagResponse: TagResponse) {
val size = _tagList.value?.size ?: 0
tagCount = tagList.value.orEmpty().count { it.isSelected == true }
isTagCountMax.value = (tagCount >= 3)
isTagClicked.value=(tagCount>0)
isTagClicked.value = (tagCount > 0)

for (i in 0..size - 1) {
if (tagResponse.id == _tagList.value?.get(i)?.id ?: "") {
if (tagResponse.id == (_tagList.value?.get(i)?.id ?: "")) {
if (!(_tagList.value?.get(i)?.isSelected ?: false)) {
if (isTagCountMax.value ?: false)
return
Expand All @@ -57,7 +58,7 @@ class RecordViewModel() : NobarViewModel() {

tagCount = tagList.value.orEmpty().count { it.isSelected == true }
isTagCountMax.value = (tagCount >= 3)
isTagClicked.value=(tagCount>0)
isTagClicked.value = (tagCount > 0)
}

// 쓰기 글자 수
Expand All @@ -72,6 +73,12 @@ class RecordViewModel() : NobarViewModel() {
else TipCount.value = cocktailTip.value?.length ?: 0
}

// 등록 버튼 활성화
fun canRegister(): Boolean {
return !cocktailName.value.isNullOrEmpty() and !drinkingDate.value.isNullOrEmpty() and (isTagClicked.value
?: false)
}

//태그 목록 서버에서 가져오기
fun getTagListNetwork() {
val call: Call<List<TagResponse>> = ServiceCreator.mockupService.getTagList()
Expand Down Expand Up @@ -100,13 +107,21 @@ class RecordViewModel() : NobarViewModel() {
}

fun makeTastingNote(rating: Float): TastingNoteParams {
val yearRange = IntRange(0, 3)
val monthRange = IntRange(4, 5)
val dayRange = IntRange(6, 7)
val year = tmpDate.slice(yearRange)
val month = tmpDate.slice(monthRange)
val day = tmpDate.slice(dayRange)
val slash = "/"
val date = year + slash + month + slash + day
return TastingNoteParams(
recipeId = cocktailId,
rate = rating,
tagList = tagList.value ?: error("태그리스트 없음"),
tasteContent = cocktailEvaluation.value,
experienceContent = cocktailTip.value,
createdAt = SimpleDateFormat("yyyy-MM-dd").format(Date())
createdAt = date
)
}

Expand Down

0 comments on commit 215efa6

Please sign in to comment.