Skip to content

Commit

Permalink
[Refactor] 파일 명 변경, 줄 바꿈 삭제, 생명주기에 따른 binding 객체 null 값 처리 (#5)
Browse files Browse the repository at this point in the history
  • Loading branch information
arinming committed May 2, 2024
1 parent 6e1a9e2 commit 98b6573
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 70 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,20 @@ package com.sopt.now.data

import androidx.annotation.DrawableRes

sealed class MultiData {
sealed class ItemData {

data class MyProfile(
@DrawableRes val profileImage: Int?,
val name: String,
val description: String?,
) : MultiData()
) : ItemData()


data class Friend(
@DrawableRes val profileImage: Int?,
val name: String,
val description: String?,
) : MultiData()
) : ItemData()


}
12 changes: 6 additions & 6 deletions app/src/main/java/com/sopt/now/ui/adapter/ItemAdapter.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ import android.view.View
import android.view.ViewGroup
import androidx.recyclerview.widget.RecyclerView
import androidx.recyclerview.widget.RecyclerView.ViewHolder
import com.sopt.now.data.MultiData
import com.sopt.now.data.ItemData
import com.sopt.now.databinding.ItemFriendBinding
import com.sopt.now.databinding.ItemMyProfileBinding

class ItemAdapter(private val items: MutableList<MultiData>) : RecyclerView.Adapter<ViewHolder>() {
class ItemAdapter(private val items: MutableList<ItemData>) : RecyclerView.Adapter<ViewHolder>() {

companion object {
private const val VIEW_TYPE_MY_PROFILE = 0
Expand Down Expand Up @@ -40,13 +40,13 @@ class ItemAdapter(private val items: MutableList<MultiData>) : RecyclerView.Adap

override fun onBindViewHolder(holder: ViewHolder, position: Int) {
when (val item = items[position]) {
is MultiData.MyProfile -> {
is ItemData.MyProfile -> {
(holder as MyProfileViewHolder).profileImage.setImageResource(item.profileImage!!)
holder.name.text = item.name
holder.description.text = item.description
}

is MultiData.Friend -> {
is ItemData.Friend -> {
(holder as FriendViewHolder).profileImage.setImageResource(item.profileImage!!)
holder.name.text = item.name
holder.description.text = item.description
Expand All @@ -64,8 +64,8 @@ class ItemAdapter(private val items: MutableList<MultiData>) : RecyclerView.Adap

override fun getItemViewType(position: Int): Int {
return when (items[position]) {
is MultiData.MyProfile -> VIEW_TYPE_MY_PROFILE
is MultiData.Friend -> VIEW_TYPE_FRIEND
is ItemData.MyProfile -> VIEW_TYPE_MY_PROFILE
is ItemData.Friend -> VIEW_TYPE_FRIEND
}
}

Expand Down
6 changes: 3 additions & 3 deletions app/src/main/java/com/sopt/now/ui/home/HomFragment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import android.view.View
import android.view.ViewGroup
import androidx.fragment.app.Fragment
import androidx.fragment.app.viewModels
import com.sopt.now.data.MultiData
import com.sopt.now.data.ItemData
import com.sopt.now.databinding.FragmentHomeBinding
import com.sopt.now.ui.adapter.ItemAdapter
import com.sopt.now.ui.home.viewModel.HomeViewModel
Expand Down Expand Up @@ -38,11 +38,11 @@ class HomeFragment : Fragment() {
}

override fun onDestroy() {
super.onDestroy()
_binding = null
super.onDestroy()
}

private fun setFriendList(friendList: List<MultiData>) {
private fun setFriendList(friendList: List<ItemData>) {
friendList.toList()
}

Expand Down
28 changes: 14 additions & 14 deletions app/src/main/java/com/sopt/now/ui/home/viewModel/HomeViewModel.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,72 +2,72 @@ package com.sopt.now.ui.home.viewModel

import androidx.lifecycle.ViewModel
import com.sopt.now.R
import com.sopt.now.data.MultiData
import com.sopt.now.data.ItemData

class HomeViewModel : ViewModel() {
val friendList = mutableListOf(

MultiData.MyProfile(
ItemData.MyProfile(
profileImage = R.drawable.img_arin,
name = "김아린",
description = "업보 청산 중..",
),
MultiData.Friend(
ItemData.Friend(
profileImage = R.drawable.img_profile0,
name = "이의경",
description = "김아린 과제 벼락치기 하지 마라",
),
MultiData.Friend(
ItemData.Friend(
profileImage = R.drawable.img_profile1,
name = "최준서",
description = "오운완 ㅋㅋ",
),
MultiData.Friend(
ItemData.Friend(
profileImage = R.drawable.img_profile2,
name = "이연진",
description = "아리니 넘 기엽당..",
),
MultiData.Friend(
ItemData.Friend(
profileImage = R.drawable.img_profile3,
name = "손민재",
description = "점심 뭐 먹지?",
),
MultiData.Friend(
ItemData.Friend(
profileImage = R.drawable.img_profile4,
name = "홍해인",
description = "난 눈물의 여왕이야",
),
MultiData.Friend(
ItemData.Friend(
profileImage = R.drawable.img_profile5,
name = "백현우",
description = "눈물의여왕시작하지말걸공부가안된다",
),
MultiData.Friend(
ItemData.Friend(
profileImage = R.drawable.img_profile6,
name = "이서경",
description = "저는 환연 과몰입러예요",
),
MultiData.Friend(
ItemData.Friend(
profileImage = R.drawable.img_profile7,
name = "이주원",
description = "너가 자기야 미안해 했잖아?",
),
MultiData.Friend(
ItemData.Friend(
profileImage = R.drawable.img_profile8,
name = "김광태",
description = "내일 뭐 해?",
),
MultiData.Friend(
ItemData.Friend(
profileImage = R.drawable.img_profile9,
name = "정현규",
description = "내봬누",
),
MultiData.Friend(
ItemData.Friend(
profileImage = R.drawable.img_profile10,
name = "성해은",
description = "벌써 스물 아홉이야",
),
MultiData.Friend(
ItemData.Friend(
profileImage = R.drawable.img_profile11,
name = "정규민",
description = "오마카세 사줄게",
Expand Down
44 changes: 0 additions & 44 deletions app/src/main/res/layout/fragment_my_page.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,99 +24,55 @@
android:layout_marginBottom="16dp"
android:importantForAccessibility="no"
android:src="@drawable/ic_launcher_background"

app:layout_constraintStart_toStartOf="parent"

app:layout_constraintTop_toTopOf="parent" />


<TextView

android:id="@+id/tv_my_nickname"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:text="@string/nickname_label" />


</LinearLayout>


<LinearLayout

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:orientation="vertical"

app:layout_constraintEnd_toEndOf="parent"

app:layout_constraintStart_toStartOf="parent"

app:layout_constraintTop_toBottomOf="@+id/ll_top">


<TextView

android:id="@+id/tv_my_id"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_marginStart="16dp"

android:layout_marginTop="16dp"

android:layout_marginEnd="16dp"

android:layout_marginBottom="16dp"

android:text="@string/id_label" />


<TextView

android:id="@+id/tv_my_pw"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_marginStart="16dp"

android:layout_marginTop="16dp"

android:layout_marginEnd="16dp"

android:layout_marginBottom="16dp"

android:text="@string/pw_label" />


<TextView

android:id="@+id/tv_my_mbti"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_marginStart="16dp"

android:layout_marginTop="16dp"

android:layout_marginEnd="16dp"

android:layout_marginBottom="16dp"

android:text="@string/mbti_label" />


</LinearLayout>


</androidx.constraintlayout.widget.ConstraintLayout>

0 comments on commit 98b6573

Please sign in to comment.