-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[feature/myPage] myPage 진행상황 공유 (#57)
* [feat/store]: del legacy code * [feat/store]: feat MyFage * [feat/store]: add fake Repository * [feat/store]: refactor approve code review * [feat/store]: add background store text * [feat/store]: UI albumPhotoCount * [feat/mypage]: UI photoCount * [feat/mypage]: add getMyPageEmtpyInfo * [feat/mypage]: UI EmtpyImage * [feat/mypage]: move GridSpacingItemDecoration to core/common * [feat/mypage]: approve code review * [feat/mypage]: add DiffUtil at MyPageAdapter super * [feat/mypage]: add listener at iv_setting * [feat/mypage]: refactor to MultiViewType Rv * [feat/mypage]: refactor Any Class * [feat/store]: UI title logo margin edit * [feat/mypage]: chore black del * [feat/mypage]: fix responsenamig * [feat/mypage]: fix bug
- Loading branch information
1 parent
6df9e25
commit 8d3f365
Showing
22 changed files
with
692 additions
and
29 deletions.
There are no files selected for viewing
7 changes: 7 additions & 0 deletions
7
app/src/main/java/com/teampophory/pophory/data/repository/MyPageInfoRepository.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package com.teampophory.pophory.data.repository | ||
|
||
import com.teampophory.pophory.network.model.MyPageResponse | ||
|
||
interface MyPageInfoRepository { | ||
suspend fun getMyPageInfo(): Result<MyPageResponse> | ||
} |
25 changes: 25 additions & 0 deletions
25
app/src/main/java/com/teampophory/pophory/data/repository/fake/FakeMyPageInfoRepository.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package com.teampophory.pophory.data.repository.fake | ||
|
||
import com.teampophory.pophory.data.repository.MyPageInfoRepository | ||
import com.teampophory.pophory.network.model.MyPageResponse | ||
import kotlinx.coroutines.delay | ||
|
||
class FakeMyPageInfoRepository : MyPageInfoRepository { | ||
private val fakeImageUrl = | ||
"https://images.unsplash.com/photo-1687023956422-117d5c47029d?ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8fA%3D%3D&auto=format&fit=crop&w=3432&q=80" | ||
|
||
override suspend fun getMyPageInfo(): Result<MyPageResponse> { | ||
delay(300) | ||
return runCatching { | ||
MyPageResponse( | ||
"한수아", | ||
"HANSUAH", | ||
"", | ||
5, | ||
listOf( | ||
|
||
) | ||
) | ||
} | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
app/src/main/java/com/teampophory/pophory/feature/home/mypage/MyPageDisplayItem.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package com.teampophory.pophory.feature.home.mypage | ||
|
||
sealed class MyPageDisplayItem { | ||
data class Profile( | ||
val realName: String, | ||
val nickname: String, | ||
val photoCount: Int | ||
) : MyPageDisplayItem() | ||
|
||
data class Photo(val photo: MyPageInfo.Photo) : MyPageDisplayItem() | ||
} | ||
|
||
data class MyPageInfo( | ||
val realName: String, | ||
val nickname: String, | ||
val photoCount: Int, | ||
val photos: List<Photo> | ||
) { | ||
data class Photo( | ||
val photoId: Long, | ||
val photoUrl: String | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 8 additions & 0 deletions
8
app/src/main/java/com/teampophory/pophory/feature/home/mypage/MyPageInfoState.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package com.teampophory.pophory.feature.home.mypage | ||
|
||
sealed class MyPageInfoState { | ||
object Uninitialized : MyPageInfoState() | ||
object Loading : MyPageInfoState() | ||
data class SuccessMyPageInfo(val data: List<MyPageDisplayItem>) : MyPageInfoState() | ||
data class Error(val error: Throwable) : MyPageInfoState() | ||
} |
32 changes: 32 additions & 0 deletions
32
app/src/main/java/com/teampophory/pophory/feature/home/mypage/MyPageViewModel.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package com.teampophory.pophory.feature.home.mypage | ||
|
||
import androidx.lifecycle.LiveData | ||
import androidx.lifecycle.MutableLiveData | ||
import androidx.lifecycle.ViewModel | ||
import androidx.lifecycle.viewModelScope | ||
import com.teampophory.pophory.data.repository.MyPageInfoRepository | ||
import com.teampophory.pophory.data.repository.fake.FakeMyPageInfoRepository | ||
import kotlinx.coroutines.launch | ||
|
||
|
||
class MyPageViewModel : ViewModel() { | ||
|
||
private val myPageInfoRepository: MyPageInfoRepository = FakeMyPageInfoRepository() | ||
|
||
private val _myPageUserInfo = MutableLiveData<MyPageInfoState>(MyPageInfoState.Uninitialized) | ||
val myPageInfo: LiveData<MyPageInfoState> get() = _myPageUserInfo | ||
|
||
fun getMyPageInfo() { | ||
viewModelScope.launch { | ||
_myPageUserInfo.value = MyPageInfoState.Loading | ||
|
||
myPageInfoRepository.getMyPageInfo() | ||
.onSuccess { | ||
_myPageUserInfo.value = | ||
MyPageInfoState.SuccessMyPageInfo(it.toItems()) | ||
}.onFailure { | ||
_myPageUserInfo.value = MyPageInfoState.Error(it) | ||
} | ||
} | ||
} | ||
} |
119 changes: 119 additions & 0 deletions
119
app/src/main/java/com/teampophory/pophory/feature/home/mypage/adapter/MyPageAdapter.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,119 @@ | ||
package com.teampophory.pophory.feature.home.mypage.adapter | ||
|
||
import android.content.Context | ||
import android.text.Spannable | ||
import android.text.SpannableStringBuilder | ||
import android.text.style.ForegroundColorSpan | ||
import android.view.LayoutInflater | ||
import android.view.ViewGroup | ||
import androidx.core.content.ContextCompat | ||
import androidx.recyclerview.widget.ListAdapter | ||
import androidx.recyclerview.widget.RecyclerView | ||
import coil.load | ||
import com.teampophory.pophory.R | ||
import com.teampophory.pophory.common.view.ItemDiffCallback | ||
import com.teampophory.pophory.databinding.ItemMypageFeedBinding | ||
import com.teampophory.pophory.databinding.ItemMypageProfileBinding | ||
import com.teampophory.pophory.feature.home.mypage.MyPageDisplayItem | ||
|
||
class MyPageAdapter( | ||
private val onItemClicked: (MyPageDisplayItem.Photo) -> Unit | ||
) : ListAdapter<MyPageDisplayItem, RecyclerView.ViewHolder>( | ||
ItemDiffCallback<MyPageDisplayItem>( | ||
onItemsTheSame = { old, new -> old == new }, | ||
onContentsTheSame = { old, new -> old == new } | ||
) | ||
) { | ||
companion object { | ||
const val VIEW_TYPE_PROFILE = 0 | ||
const val VIEW_TYPE_PHOTO = 1 | ||
} | ||
|
||
override fun getItemViewType(position: Int): Int { | ||
return when (getItem(position)) { | ||
is MyPageDisplayItem.Profile -> VIEW_TYPE_PROFILE | ||
is MyPageDisplayItem.Photo -> VIEW_TYPE_PHOTO | ||
} | ||
} | ||
|
||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): RecyclerView.ViewHolder { | ||
val context = parent.context | ||
return when (viewType) { | ||
VIEW_TYPE_PROFILE -> { | ||
val binding = | ||
ItemMypageProfileBinding.inflate(LayoutInflater.from(context), parent, false) | ||
ProfileViewHolder(binding, context) | ||
} | ||
|
||
VIEW_TYPE_PHOTO -> { | ||
val binding = | ||
ItemMypageFeedBinding.inflate(LayoutInflater.from(context), parent, false) | ||
PhotoViewHolder(binding, onItemClicked) | ||
} | ||
|
||
else -> throw IllegalArgumentException("Invalid view type") | ||
} | ||
} | ||
|
||
override fun onBindViewHolder(holder: RecyclerView.ViewHolder, position: Int) { | ||
when (val item = getItem(position)) { | ||
is MyPageDisplayItem.Profile -> { | ||
(holder as ProfileViewHolder).bind(item) | ||
} | ||
|
||
is MyPageDisplayItem.Photo -> { | ||
(holder as PhotoViewHolder).bind(item) | ||
} | ||
} | ||
} | ||
|
||
class PhotoViewHolder( | ||
private val binding: ItemMypageFeedBinding, | ||
private val onItemClicked: (MyPageDisplayItem.Photo) -> Unit | ||
) : RecyclerView.ViewHolder(binding.root) { | ||
fun bind(photo: MyPageDisplayItem.Photo) { | ||
binding.ivMypageFeedItem.load(photo.photo.photoUrl) | ||
itemView.setOnClickListener { | ||
onItemClicked(photo) | ||
} | ||
} | ||
} | ||
|
||
class ProfileViewHolder( | ||
private val binding: ItemMypageProfileBinding, | ||
private val context: Context | ||
) : RecyclerView.ViewHolder(binding.root) { | ||
fun bind(profileInfo: MyPageDisplayItem.Profile) { | ||
with(binding) { | ||
tvMypageName.text = profileInfo.realName | ||
tvMypagePictureCount.text = setSpannableString(profileInfo.photoCount) | ||
} | ||
} | ||
|
||
private fun setSpannableString(myPageInfoDataPhotoCount: Int): SpannableStringBuilder { | ||
val fullText = | ||
context.getString(R.string.mypage_picture_count, myPageInfoDataPhotoCount) | ||
val coloredText = myPageInfoDataPhotoCount.toString() | ||
|
||
val spannableStringBuilder = SpannableStringBuilder(fullText) | ||
val start = fullText.indexOf(coloredText) | ||
val end = start + coloredText.length | ||
|
||
if (start != -1) { | ||
spannableStringBuilder.setSpan( | ||
ForegroundColorSpan( | ||
ContextCompat.getColor( | ||
context, | ||
R.color.pophory_purple | ||
) | ||
), | ||
start, | ||
end, | ||
Spannable.SPAN_EXCLUSIVE_EXCLUSIVE | ||
) | ||
} | ||
return spannableStringBuilder | ||
} | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 7 additions & 0 deletions
7
app/src/main/java/com/teampophory/pophory/network/MyPageInfoNetworkDataSource.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package com.teampophory.pophory.network | ||
|
||
import com.teampophory.pophory.network.model.MyPageResponse | ||
|
||
interface MyPageInfoNetworkDataSource { | ||
suspend fun getMyPageInfo(): MyPageResponse | ||
} |
Oops, something went wrong.