Skip to content

Commit

Permalink
[FEAT] 알림 삭제영역 디자인 적용
Browse files Browse the repository at this point in the history
  • Loading branch information
kim0hoon committed Aug 22, 2023
1 parent 02adbd0 commit 2ce2b38
Show file tree
Hide file tree
Showing 9 changed files with 253 additions and 142 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.polzzak_android.presentation.common.util

import android.view.ViewGroup
import androidx.annotation.LayoutRes
import androidx.databinding.ViewDataBinding

Expand All @@ -11,11 +10,7 @@ import androidx.databinding.ViewDataBinding
abstract class BindableItem<B : ViewDataBinding> {
@get:LayoutRes
abstract val layoutRes: Int

open fun onCreateViewHolder(parent: ViewGroup, position: Int) {}

abstract fun bind(binding: B, position: Int)

abstract fun areItemsTheSame(other: BindableItem<*>): Boolean
abstract fun areContentsTheSame(other: BindableItem<*>): Boolean
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@ class NotificationItemDecoration(
val nextItem = adapter.currentList.getOrNull(position + 1)
outRect.top =
if (isContentItem(prevItem)) 0 else paddingPx
outRect.left = paddingPx
outRect.right = paddingPx
outRect.bottom =
if (isContentItem(nextItem)) betweenMarginPx else paddingPx
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.polzzak_android.presentation.feature.notification

interface NotificationItemStateController {
fun setHorizontalScrollPosition(id: Int, position: Int)
fun getHorizontalScrollPosition(id: Int): Int
fun getIsRefreshedSuccess(): Boolean
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,16 @@ import javax.inject.Inject

//TODO pull to refresh, 더 불러오기 동시에 일어나면?
@HiltViewModel
class NotificationViewModel @Inject constructor() : ViewModel() {
class NotificationViewModel @Inject constructor() : ViewModel(), NotificationItemStateController {
private val _notificationLiveData = MutableLiveData<ModelState<NotificationsModel>>()
val notificationLiveData: LiveData<ModelState<NotificationsModel>> = _notificationLiveData
private var requestNotificationJobData: NotificationJobData? = null

var isRefreshed = false
private set

private val notificationHorizontalScrollPositionMap = HashMap<Int, Int>()

init {
initNotifications()
}
Expand Down Expand Up @@ -84,6 +86,7 @@ class NotificationViewModel @Inject constructor() : ViewModel() {
//onSuccess
delay(2000)
val nextData = getMockData(prevData.nextOffset, NOTIFICATION_PAGE_SIZE)
if (isRefreshed) notificationHorizontalScrollPositionMap.clear()
_notificationLiveData.value =
ModelState.Success(
nextData.copy(
Expand All @@ -93,10 +96,24 @@ class NotificationViewModel @Inject constructor() : ViewModel() {
)
}

fun deleteNotification() {
//TODO 알림 삭제 문의 중
}

private data class NotificationJobData(val priority: Int, val job: Job)

private fun NotificationJobData?.getPriorityOrZero() = this?.priority ?: 0

override fun setHorizontalScrollPosition(id: Int, position: Int) {
notificationHorizontalScrollPositionMap[id] = position
}

override fun getHorizontalScrollPosition(id: Int): Int =
notificationHorizontalScrollPositionMap[id] ?: 0

override fun getIsRefreshedSuccess(): Boolean =
isRefreshed && notificationLiveData.value is ModelState.Success

companion object {
const val NOTIFICATION_PAGE_SIZE = 10
private const val INIT_NOTIFICATIONS_PRIORITY = 3
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,8 @@ abstract class BaseNotificationFragment : BaseFragment<FragmentNotificationBindi
private fun createNotificationItems(data: List<NotificationModel>?): List<BindableItem<*>> {
return if (data.isNullOrEmpty()) listOf(NotificationEmptyItem()) else data.map {
NotificationItem(
model = it
model = it,
itemStateController = notificationViewModel
)
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,28 @@
package com.polzzak_android.presentation.feature.notification.item

import android.view.View
import androidx.core.view.doOnPreDraw
import androidx.core.view.isVisible
import androidx.core.view.updateLayoutParams
import com.polzzak_android.R
import com.polzzak_android.databinding.ItemNotificationBinding
import com.polzzak_android.presentation.common.util.BindableItem
import com.polzzak_android.presentation.common.util.loadCircleImageUrl
import com.polzzak_android.presentation.common.util.toPx
import com.polzzak_android.presentation.feature.notification.NotificationItemStateController
import com.polzzak_android.presentation.feature.notification.model.NotificationModel

class NotificationItem(private val model: NotificationModel) :
BindableItem<ItemNotificationBinding>() {
//TODO 버튼 클릭 상태 적용
class NotificationItem(
private val model: NotificationModel,
private val itemStateController: NotificationItemStateController
) : BindableItem<ItemNotificationBinding>() {
override val layoutRes: Int = R.layout.item_notification
override fun areItemsTheSame(other: BindableItem<*>): Boolean =
other is NotificationItem && this.model.id == other.model.id

override fun areContentsTheSame(other: BindableItem<*>): Boolean =
other is NotificationItem && this.model == other.model
other is NotificationItem && this.model == other.model && !itemStateController.getIsRefreshedSuccess()

override fun bind(binding: ItemNotificationBinding, position: Int) {
with(binding) {
Expand All @@ -23,8 +31,36 @@ class NotificationItem(private val model: NotificationModel) :
tvTitle.text = context.getString(model.titleStringRes)
tvDate.text = model.date
tvContent.text = model.content
ivBtnRemoveNotification.setOnClickListener {

}
bindBtnLayout(binding = binding)
bindProfile(binding = binding)
bindHorizontalScroll(binding = binding)
}
}

private fun bindHorizontalScroll(binding: ItemNotificationBinding) {
with(binding) {
clNotification.doOnPreDraw {
it.updateLayoutParams {
width = it.width
}
clRemoveNotification.updateLayoutParams {
width =
it.width + NOTIFICATION_REMOVE_LAYOUT_WIDTH_DP.toPx(context = binding.root.context)
}
hsvNotification.doOnPreDraw {
hsvNotification.scrollX =
itemStateController.getHorizontalScrollPosition(id = model.id)
}
}
hsvNotification.setOnScrollChangeListener { _, scrollX, _, _, _ ->
clRemoveNotification.visibility = if (scrollX > 0) View.VISIBLE else View.INVISIBLE
itemStateController.setHorizontalScrollPosition(id = model.id, position = scrollX)
}
clRemoveNotification.visibility =
if (hsvNotification.scrollX == 0) View.INVISIBLE else View.VISIBLE
}
}

Expand All @@ -49,4 +85,7 @@ class NotificationItem(private val model: NotificationModel) :
}
}

companion object {
private const val NOTIFICATION_REMOVE_LAYOUT_WIDTH_DP = 56
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<stroke
android:width="1dp"
android:color="@color/gray_200" />
<solid android:color="@color/white" />
<corners android:radius="8dp" />
</shape>
Loading

0 comments on commit 2ce2b38

Please sign in to comment.