Skip to content

Commit

Permalink
[feat/api_friend] : #16 마이탭 마시멜로우 분기처리
Browse files Browse the repository at this point in the history
  • Loading branch information
SsongSik committed May 14, 2023
1 parent 27c2b53 commit 9c4a0a8
Show file tree
Hide file tree
Showing 13 changed files with 32 additions and 142 deletions.
109 changes: 0 additions & 109 deletions app/build.gradle

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ package com.teampome.pome.model.mytab

// Marshmello Response
data class MyTabMarshmello(
val recordMarshmelloLv: Int,
val growthMarshmelloLv: Int,
val emotionMarshmelloLv: Int,
val honestMarshmelloLv: Int,
val marshmelloName : String,
val marshmelloLv : Int
)
Original file line number Diff line number Diff line change
@@ -1,22 +1,16 @@
package com.teampome.pome.presentation.friend

import android.icu.lang.UCharacter.VerticalOrientation
import android.nfc.Tag
import android.util.Log
import android.widget.Toast
import androidx.fragment.app.viewModels
import androidx.navigation.fragment.findNavController
import androidx.recyclerview.widget.DividerItemDecoration
import androidx.recyclerview.widget.LinearLayoutManager
import com.google.android.material.snackbar.Snackbar
import com.teampome.pome.R
import com.teampome.pome.util.base.BaseFragment
import com.teampome.pome.databinding.FragmentFriendBinding
import com.teampome.pome.presentation.record.RecordCategoryAdapter
import com.teampome.pome.util.base.ApiResponse
import com.teampome.pome.util.base.BaseFragment
import com.teampome.pome.util.base.CoroutineErrorHandler
import com.teampome.pome.viewmodel.AddFriendsViewModel
import com.teampome.pome.viewmodel.record.RecordViewModel
import dagger.hilt.android.AndroidEntryPoint

@AndroidEntryPoint
Expand Down Expand Up @@ -63,6 +57,7 @@ class FriendFragment : BaseFragment<FragmentFriendBinding>(R.layout.fragment_fri
viewModel.getFriendRecordResponse.observe(viewLifecycleOwner){
when(it) {
is ApiResponse.Success -> {
hideLoading()
it.data.data?.content?.let { list ->
(binding.friendDetailRv.adapter as FriendRecordGetAdapter).submitList(
list
Expand All @@ -72,7 +67,9 @@ class FriendFragment : BaseFragment<FragmentFriendBinding>(R.layout.fragment_fri
is ApiResponse.Failure -> {

}
is ApiResponse.Loading -> {}
is ApiResponse.Loading -> {
showLoading()
}
}
}
}
Expand All @@ -90,7 +87,6 @@ class FriendFragment : BaseFragment<FragmentFriendBinding>(R.layout.fragment_fri
friendGetAdapter.setOnItemClickListener {
viewModel.getRecordFriend(it.friendUserId, object : CoroutineErrorHandler{
override fun onError(message: String) {
Log.e("friendGetRecordError", "friendGetRecordError $message")
Toast.makeText(requireContext(), message, Toast.LENGTH_SHORT).show()
hideLoading()
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,20 @@
package com.teampome.pome.presentation.mypage

import android.content.Context
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.bumptech.glide.Glide
import com.teampome.pome.R
import com.teampome.pome.databinding.ItemMypageCardBinding
import com.teampome.pome.model.mytab.MyTabMarshmello

/// 마이탭 마시멜로우 어댑터
class MarshmelloAdapter : ListAdapter<MyTabMarshmello, MarshmelloAdapter.MyTabMarshmelloViewHolder>(BookDiffCallback) {
class MarshmelloAdapter(
private val context : Context?
): ListAdapter<MyTabMarshmello, MarshmelloAdapter.MyTabMarshmelloViewHolder>(BookDiffCallback) {

override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): MyTabMarshmelloViewHolder {
return MyTabMarshmelloViewHolder(
Expand All @@ -29,14 +34,22 @@ class MarshmelloAdapter : ListAdapter<MyTabMarshmello, MarshmelloAdapter.MyTabMa

fun bind(myTabMarshmello: MyTabMarshmello){
binding.myTabMarshmello = myTabMarshmello
context?.let{
when(myTabMarshmello.marshmelloName) {
"record" -> Glide.with(context).load(R.drawable.marshmallow_level_4_pink).into(binding.ivArticleImage)
"emotion" -> Glide.with(context).load(R.drawable.marshmallow_level_2_yellow).into(binding.ivArticleImage)
"growth" -> Glide.with(context).load(R.drawable.marshmallow_level_4_mint).into(binding.ivArticleImage)
"honest" -> Glide.with(context).load(R.drawable.ic_mashmellow).into(binding.ivArticleImage)
else -> Glide.with(context).load(R.drawable.ic_mashmellow).into(binding.ivArticleImage)
}
}
}

}

companion object{
private val BookDiffCallback = object : DiffUtil.ItemCallback<MyTabMarshmello>(){
override fun areItemsTheSame(oldItem: MyTabMarshmello, newItem: MyTabMarshmello): Boolean {
return oldItem.recordMarshmelloLv == newItem.recordMarshmelloLv
return oldItem.marshmelloName == newItem.marshmelloName
}

override fun areContentsTheSame(oldItem: MyTabMarshmello, newItem: MyTabMarshmello): Boolean {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ class MyPageFragment : BaseFragment<FragmentMypageBinding>(R.layout.fragment_myp

viewModel.getMarshmello(object : CoroutineErrorHandler{
override fun onError(message: String) {
Log.e("marshmelloError", "marshmelloError $message")
Toast.makeText(requireContext(), message, Toast.LENGTH_SHORT).show()
hideLoading()
}
Expand Down Expand Up @@ -64,21 +63,17 @@ class MyPageFragment : BaseFragment<FragmentMypageBinding>(R.layout.fragment_myp
}

private fun setUpRecyclerView(){
marshmelloAdapter = MarshmelloAdapter()
marshmelloAdapter = MarshmelloAdapter(requireContext())
val manager = GridLayoutManager(requireContext(), 2, LinearLayoutManager.VERTICAL, false)

//첫 번째 나오는 Header size 를 꽉 차게 함
manager.spanSizeLookup = object : GridLayoutManager.SpanSizeLookup() {
override fun getSpanSize(position: Int): Int = when(position){
0 -> 2
else -> 1
}
override fun getSpanSize(position: Int): Int = 1
}
binding.recordEmotionRv.apply {
// setHasFixedSize(true)
layoutManager = manager
adapter = marshmelloAdapter
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,10 @@ import androidx.navigation.fragment.findNavController
import androidx.recyclerview.widget.LinearLayoutManager
import com.teampome.pome.R
import com.teampome.pome.databinding.FragmentFriendDeleteDialogBinding
import com.teampome.pome.databinding.FragmentMypageAlarmBinding
import com.teampome.pome.util.base.BaseFragment
import com.teampome.pome.databinding.FragmentMypageBinding
import com.teampome.pome.databinding.FragmentMypageFriendBinding
import com.teampome.pome.databinding.FragmentMypageGoalBinding
import com.teampome.pome.presentation.friend.FriendGetAdapter
import com.teampome.pome.util.CommonUtil
import com.teampome.pome.util.common.CommonUtil
import com.teampome.pome.util.base.ApiResponse
import com.teampome.pome.util.base.BaseFragment
import com.teampome.pome.util.base.CoroutineErrorHandler
import com.teampome.pome.viewmodel.AddFriendsViewModel
import dagger.hilt.android.AndroidEntryPoint
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import com.teampome.pome.util.base.ApiResponse
import com.teampome.pome.util.base.BaseViewModel
import com.teampome.pome.util.base.CoroutineErrorHandler
import dagger.hilt.android.lifecycle.HiltViewModel
import kotlinx.coroutines.launch
import javax.inject.Inject

@HiltViewModel
Expand Down
Binary file added app/src/main/res/drawable/ic_mashmellow.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions app/src/main/res/layout/fragment_mypage.xml
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@
android:layout_height="wrap_content"
app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager"
tools:listitem="@layout/item_mypage_card"
android:layout_marginHorizontal="16dp"
app:layout_constraintTop_toBottomOf="@id/mypage_marshmallow_tv"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent" />
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/layout/item_friend_detail_card.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
name="getFriendRecord"
type="com.teampome.pome.model.response.GetFriendRecord" />

<import type="com.teampome.pome.util.CommonUtil" />
<import type="com.teampome.pome.util.common.CommonUtil" />
<import type="android.view.View" />
</data>

Expand Down
5 changes: 2 additions & 3 deletions app/src/main/res/layout/item_mypage_card.xml
Original file line number Diff line number Diff line change
Expand Up @@ -88,10 +88,9 @@

<ImageView
android:id="@+id/iv_article_image"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_width="120dp"
android:layout_height="120dp"
android:scaleType="fitXY"
android:background="@drawable/marshmallow_level_4_pink"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/mypage_card_record_cl"
app:layout_constraintEnd_toEndOf="parent"
Expand Down

0 comments on commit 9c4a0a8

Please sign in to comment.