Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
…into feat/#54-onboarding-friend-add
  • Loading branch information
Marchbreeze committed Jul 19, 2023
2 parents 103d482 + df5bc15 commit 644b45e
Show file tree
Hide file tree
Showing 52 changed files with 2,347 additions and 306 deletions.
1 change: 1 addition & 0 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -133,5 +133,6 @@ dependencies {
debugImplementation(flipperLeakCanary)
debugImplementation(leakCanary)
debugImplementation(soloader)
debugImplementation(circleIndicator)
}
}
14 changes: 14 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@
xmlns:tools="http://schemas.android.com/tools">

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />

<queries>
<package android:name="com.instagram.android" />
</queries>

<application
android:name=".MyApp"
Expand Down Expand Up @@ -88,6 +93,15 @@
<activity
android:name=".presentation.main.myyello.read.MyYelloReadActivity"
android:exported="false"
android:screenOrientation="portrait" >
</activity>
<activity
android:name=".presentation.pay.PayActivity"
android:exported="false"
android:screenOrientation="portrait" />
<activity
android:name=".presentation.pay.PayEndActivity"
android:exported="false"
android:screenOrientation="portrait" />
</application>
</manifest>
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import com.yello.R
import com.yello.databinding.ItemMyYelloBinding
import com.yello.util.Utils

class MyYelloAdapter(private val itemClick: (Yello) -> (Unit)) :
class MyYelloAdapter(private val itemClick: (Yello, Int) -> (Unit)) :
RecyclerView.Adapter<MyYelloAdapter.MyYelloViewHolder>() {
private val yelloList = mutableListOf<Yello>()
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): MyYelloViewHolder {
Expand All @@ -25,25 +25,45 @@ class MyYelloAdapter(private val itemClick: (Yello) -> (Unit)) :
}

override fun onBindViewHolder(holder: MyYelloViewHolder, position: Int) {
holder.onBind(yelloList[position])
holder.onBind(yelloList[position], position)
}

override fun getItemCount(): Int = yelloList.size

override fun getItemId(position: Int): Long {
return position.toLong()
}

fun addItem(newItems: List<Yello>) {
yelloList.addAll(newItems)
notifyDataSetChanged()
}

fun currentList(): List<Yello> {
return yelloList
}

fun changeItem(position: Int, newItem: Yello) {
yelloList[position] = newItem
notifyItemChanged(position)
}

class MyYelloViewHolder(
private val binding: ItemMyYelloBinding,
private val itemClick: (Yello) -> Unit
private val itemClick: (Yello, Int) -> Unit
) : RecyclerView.ViewHolder(binding.root) {
fun onBind(item: Yello) {
fun onBind(item: Yello, position: Int) {
binding.data = item
binding.ivReadYelloPoint.isVisible = !item.isRead && !item.isHintUsed
binding.tvTime.text = item.createdAt
binding.clSendCheck.isVisible = item.isHintUsed
binding.tvGender.isVisible = !item.isHintUsed
binding.cardMyYello.setCardBackgroundColor(
ContextCompat.getColor(
itemView.context,
R.color.grayscales_900
)
)
if (item.gender == GenderEnum.M) {
if (item.isHintUsed) {
binding.cardMyYello.setCardBackgroundColor(
Expand Down Expand Up @@ -91,7 +111,7 @@ class MyYelloAdapter(private val itemClick: (Yello) -> (Unit)) :
}

binding.root.setOnSingleClickListener {
itemClick(item)
itemClick(item, position)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
package com.yello.presentation.main.myyello

import android.app.Activity
import android.content.Intent
import android.os.Bundle
import android.view.View
import androidx.activity.result.contract.ActivityResultContracts
import androidx.fragment.app.viewModels
import androidx.lifecycle.flowWithLifecycle
import androidx.lifecycle.lifecycleScope
Expand All @@ -10,9 +13,11 @@ import androidx.recyclerview.widget.RecyclerView
import com.example.ui.base.BindingFragment
import com.example.ui.fragment.toast
import com.example.ui.view.UiState
import com.example.ui.view.setOnSingleClickListener
import com.yello.R
import com.yello.databinding.FragmentMyYelloBinding
import com.yello.presentation.main.myyello.read.MyYelloReadActivity
import com.yello.presentation.pay.PayActivity
import com.yello.presentation.util.BaseLinearRcvItemDeco
import dagger.hilt.android.AndroidEntryPoint
import kotlinx.coroutines.flow.launchIn
Expand All @@ -28,13 +33,22 @@ class MyYelloFragment : BindingFragment<FragmentMyYelloBinding>(R.layout.fragmen
super.onViewCreated(view, savedInstanceState)

initView()
initEvent()
observe()
}

private fun initView() {
viewModel.getMyYelloList()
adapter = MyYelloAdapter {
startActivity(MyYelloReadActivity.getIntent(requireContext(), it.id))
adapter = MyYelloAdapter { it, pos ->
viewModel.setPosition(pos)
myYelloReadActivityLauncher.launch(
MyYelloReadActivity.getIntent(
requireContext(),
it.id,
it.nameHint,
it.isHintUsed
)
)
}
binding.rvMyYelloReceive.addItemDecoration(
BaseLinearRcvItemDeco(
Expand All @@ -47,11 +61,20 @@ class MyYelloFragment : BindingFragment<FragmentMyYelloBinding>(R.layout.fragmen
94
)
)
adapter?.setHasStableIds(true)
binding.rvMyYelloReceive.adapter = adapter

infinityScroll()
}

private fun initEvent() {
binding.clSendCheck.setOnSingleClickListener {
Intent(requireContext(), PayActivity::class.java).apply {
startActivity(this)
}
}
}

private fun observe() {
viewModel.myYelloData.flowWithLifecycle(viewLifecycleOwner.lifecycle)
.onEach {
Expand Down Expand Up @@ -91,6 +114,30 @@ class MyYelloFragment : BindingFragment<FragmentMyYelloBinding>(R.layout.fragmen
})
}

private val myYelloReadActivityLauncher = registerForActivityResult(
ActivityResultContracts.StartActivityForResult()
) {
if (it.resultCode == Activity.RESULT_OK) {
it.data?.let { intent ->
val isHintUsed = intent.getBooleanExtra("isHintUsed", false)
val nameIndex = intent.getIntExtra("nameIndex", -1)
val list = adapter?.currentList()
val selectItem = list?.get(viewModel.position)
selectItem?.isRead = true
selectItem?.isHintUsed = isHintUsed
selectItem?.nameHint = nameIndex
selectItem?.apply {
this.isRead = true
this.isHintUsed = isHintUsed
this.nameHint = nameIndex
}
selectItem?.let {
adapter?.changeItem(viewModel.position, selectItem)
}
}
}
}

override fun onDestroyView() {
adapter = null
super.onDestroyView()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import kotlinx.coroutines.flow.asSharedFlow
import kotlinx.coroutines.flow.asStateFlow
import kotlinx.coroutines.launch
import javax.inject.Inject
import kotlin.math.ceil

@HiltViewModel
class MyYelloViewModel @Inject constructor(
Expand All @@ -26,26 +25,36 @@ class MyYelloViewModel @Inject constructor(
private val _totalCount = MutableStateFlow<Int>(0)
val totalCount: StateFlow<Int> = _totalCount.asStateFlow()

var position: Int = -1
private set

private var currentPage = -1
private var isPagingFinish = false
private var totalPage = Int.MAX_VALUE

fun setPosition(pos: Int) {
position = pos
}

fun getMyYelloList() {
if (isPagingFinish) return
_myYelloData.tryEmit(UiState.Loading)
viewModelScope.launch {
repository.getMyYelloList(++currentPage)
.onSuccess {
it ?: return@launch
totalPage = ceil((it.totalCount * 0.1)).toInt()
if (totalPage == currentPage) isPagingFinish = true
_myYelloData.emit(
when {
it.yello.isEmpty() -> UiState.Empty
else -> UiState.Success(it)
}
)
_totalCount.value = it.totalCount
if (it == null) _myYelloData.emit(UiState.Empty)
else {
totalPage = Math.ceil((it.totalCount * 0.1)).toInt() - 1
if (totalPage == currentPage) isPagingFinish = true
_myYelloData.emit(
when {
it.yello.isEmpty() -> UiState.Empty
else -> UiState.Success(it)
}
)
_totalCount.value = it.totalCount
}

}.onFailure {
_myYelloData.emit(UiState.Failure("옐로 리스트 서버 통신 실패"))
}
Expand Down
Loading

0 comments on commit 644b45e

Please sign in to comment.