Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ui] 알림 / 알림 뷰 디자인 #123

Merged
merged 24 commits into from
Aug 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
d57c90c
[add] #117 액티비티, 뷰모델 생성
Sangwook123 Aug 17, 2023
3162942
[ui] #117 알림뷰 앱 바
Sangwook123 Aug 17, 2023
68a38b3
[ui] #117 알림 뷰 리사이클러 뷰
Sangwook123 Aug 17, 2023
bc90616
[add] #117 아이템 레이아웃
Sangwook123 Aug 17, 2023
76e2111
[add] #117 아이콘 리소스 추가
Sangwook123 Aug 17, 2023
5f6ab07
[ui] #117 알림 아이템 레이아웃 완성
Sangwook123 Aug 17, 2023
088792b
[chore] #117 리사이클러뷰 tools:listitem
Sangwook123 Aug 17, 2023
636d7dd
[feat] #117 notification data class 작성
Sangwook123 Aug 17, 2023
9fb2fa9
[add] #117 string 리소스 추가
Sangwook123 Aug 17, 2023
a5fa26a
[feat] #117 바인딩 어댑터 작성
Sangwook123 Aug 17, 2023
f1a6b67
[feat] #117 데이터 바인딩
Sangwook123 Aug 17, 2023
3195437
[feat] #117 어댑터 구현
Sangwook123 Aug 17, 2023
43d0201
[chore] #117 어댑터 초기화
Sangwook123 Aug 17, 2023
d686c29
[mod] #117 바인딩 어댑터 수정
Sangwook123 Aug 18, 2023
94707b6
[chore] #117 Notification viewmodel
Sangwook123 Aug 18, 2023
5c8e1d7
[ui] #117 mypage 리디자인
Sangwook123 Aug 18, 2023
e60dda1
[chore] #117 mainviewmodel 로그아웃 로직 수정
Sangwook123 Aug 18, 2023
a668889
[chore] #117 불필요한 import 제거
Sangwook123 Aug 18, 2023
4384061
Merge branch 'develop' into feature/ui-notification-view
Sangwook123 Aug 18, 2023
9739612
Merge branch 'develop' into feature/ui-notification-view
leeeha Aug 19, 2023
d6cadc7
Merge branch 'develop' into feature/ui-notification-view
Sangwook123 Aug 19, 2023
85517b1
[add] #117 스트링 리소스 추가
Sangwook123 Aug 19, 2023
46ef14e
[chore] #117 PagingDataAdapter -> ListAdapter
Sangwook123 Aug 19, 2023
d2215bc
Merge branch 'develop' into feature/ui-notification-view
Sangwook123 Aug 19, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.android.go.sopt.winey.domain.entity

data class Notification(
val notiId: Int,
val notiReceiver: String,
val notiMessage: String,
val notiType: String,
val isChecked: Boolean,
val timeAgo: String,
val createdAt: String,
val linkId: Int
)
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import com.android.go.sopt.winey.util.view.UiState
import dagger.hilt.android.AndroidEntryPoint
import kotlinx.coroutines.flow.launchIn
import kotlinx.coroutines.flow.onEach
import retrofit2.HttpException

@AndroidEntryPoint
class MainActivity : BindingActivity<ActivityMainBinding>(R.layout.activity_main) {
Expand All @@ -40,7 +39,6 @@ class MainActivity : BindingActivity<ActivityMainBinding>(R.layout.activity_main
syncBottomNavigationSelection()

setupLogoutState()
setupTokenState()
showUploadSuccessSnackbar()
}

Expand Down Expand Up @@ -96,24 +94,6 @@ class MainActivity : BindingActivity<ActivityMainBinding>(R.layout.activity_main
}.launchIn(lifecycleScope)
}

private fun setupTokenState() {
viewModel.getUserState.flowWithLifecycle(lifecycle).onEach { state ->
when (state) {
is UiState.Failure -> {
// todo: 메인 뷰모델에 있는 todo 주석 참고해주세요!
if (state is HttpException) {
if (state.code() == CODE_TOKEN_EXPIRED) {
viewModel.postLogout()
}
}
}

else -> {
}
}
}
}

private fun navigateToLoginScreen() {
Intent(this@MainActivity, LoginActivity::class.java).apply {
addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)
Expand All @@ -129,7 +109,6 @@ class MainActivity : BindingActivity<ActivityMainBinding>(R.layout.activity_main
}

companion object {
private const val CODE_TOKEN_EXPIRED = 401
private const val EXTRA_UPLOAD_KEY = "upload"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,10 @@ class MainViewModel @Inject constructor(
}
.onFailure { t ->
if (t is HttpException) {
Timber.e("FAIL GET USER IN MAIN: ${t.code()}")

// todo: 메인 액티비티가 아니라 여기서 t.code() 이용해서
// 리프레시 토큰 만료되면 로그아웃 되게 해야 될 거 같아요!
Timber.e("HTTP 실패 ${t.code()}")
if (t.code() == CODE_TOKEN_EXPIRED) {
postLogout()
}
}
Timber.e("${t.message}")
_getUserState.value = UiState.Failure("${t.message}")
Expand All @@ -69,4 +69,8 @@ class MainViewModel @Inject constructor(
}
}
}

companion object {
private const val CODE_TOKEN_EXPIRED = 401
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ class MyPageFragment : BindingFragment<FragmentMyPageBinding>(R.layout.fragment_
super.onViewCreated(view, savedInstanceState)

init1On1ButtonClickListener()
initTermsButtonClickListener()
initLevelHelpButtonClickListener()
initToMyFeedButtonClickListener()
initLogoutButtonClickListener()
Expand Down Expand Up @@ -81,6 +82,14 @@ class MyPageFragment : BindingFragment<FragmentMyPageBinding>(R.layout.fragment_
}
}

private fun initTermsButtonClickListener() {
binding.clMypageToTerms.setOnClickListener {
val url = TERMS_URL
val intent = Intent(Intent.ACTION_VIEW, Uri.parse(url))
startActivity(intent)
}
}

private fun initLevelHelpButtonClickListener() {
binding.btnMypageLevelHelp.setOnClickListener {
val intent = Intent(context, MypageHelpActivity::class.java)
Expand Down Expand Up @@ -177,23 +186,26 @@ class MyPageFragment : BindingFragment<FragmentMyPageBinding>(R.layout.fragment_
bottomSheet.show(this.childFragmentManager, bottomSheet.tag)

/*when (data.isOver) {
true -> {
val bottomSheet = TargetAmountBottomSheetFragment()
bottomSheet.show(this.childFragmentManager, bottomSheet.tag)
}
true -> {
val bottomSheet = TargetAmountBottomSheetFragment()
bottomSheet.show(this.childFragmentManager, bottomSheet.tag)
}

false -> {
val dialog = MyPageDialogFragment()
dialog.show(this.childFragmentManager, dialog.tag)
}
}*/
false -> {
val dialog = MyPageDialogFragment()
dialog.show(this.childFragmentManager, dialog.tag)
}
}*/
}
}

// todo: 여기 한 함수에 들어가는 코드량이 많습니다! 함수화 시켜주세요! @우상욱
private fun updateUserInfo(data: User?) {
binding.data = data
handleIsOver(data)
handleUserLevel(data)
}

private fun handleIsOver(data: User?) {
when (data?.isOver) {
true -> {
binding.tvMypageTargetAmount.text = getString(R.string.mypage_not_yet_set)
Expand All @@ -213,6 +225,9 @@ class MyPageFragment : BindingFragment<FragmentMyPageBinding>(R.layout.fragment_
null -> {
}
}
}

private fun handleUserLevel(data: User?) {
when (data?.userLevel) {
LEVEL_COMMON -> {
binding.ivMypageProgressbar.setImageResource(R.drawable.ic_mypage_lv1_progressbar)
Expand Down Expand Up @@ -249,9 +264,9 @@ class MyPageFragment : BindingFragment<FragmentMyPageBinding>(R.layout.fragment_
private const val LEVEL_NOBLESS = "귀족"
private const val LEVEL_KING = "황제"
private const val ONE_ON_ONE_URL = "https://open.kakao.com/o/s751Susf"
private const val TERMS_URL = "https://empty-weaver-a9f.notion.site/62b37962c661488ba5f60958c24753e1?pvs=4"
private const val EXTRA_KEY = "PREV_SCREEN_NAME"
private const val EXTRA_VALUE = "MyPageFragment"

private const val TAG_LOGOUT_DIALOG = "LOGOUT_DIALOG"
private const val TAGE_WITHDRAW_DIALOG = "WITHDRAW_DIALOG"
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package com.android.go.sopt.winey.presentation.main.notification

import android.os.Bundle
import androidx.activity.viewModels
import com.android.go.sopt.winey.R
import com.android.go.sopt.winey.databinding.ActivityNotificationBinding
import com.android.go.sopt.winey.util.binding.BindingActivity
import dagger.hilt.android.AndroidEntryPoint

@AndroidEntryPoint
class NotificationActivity : BindingActivity<ActivityNotificationBinding>(R.layout.activity_notification) {
private lateinit var notificationAdapter: NotificationAdapter
private val viewModel: NotificationViewModel by viewModels()
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
initNotificationAdapter()
}

private fun initNotificationAdapter() {
notificationAdapter = NotificationAdapter()
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package com.android.go.sopt.winey.presentation.main.notification

import android.view.LayoutInflater
import android.view.ViewGroup
import androidx.recyclerview.widget.ListAdapter
import androidx.recyclerview.widget.RecyclerView
import com.android.go.sopt.winey.databinding.ItemNotificationPostBinding
import com.android.go.sopt.winey.domain.entity.Notification
import com.android.go.sopt.winey.util.view.ItemDiffCallback

class NotificationAdapter :
ListAdapter<Notification, NotificationAdapter.NotificationViewHolder>(DiffUtil) {

class NotificationViewHolder(private val binding: ItemNotificationPostBinding) :
RecyclerView.ViewHolder(binding.root) {

fun onBind(data: Notification?) {
binding.apply {
this.data = data
if (data == null) {
return
}
binding.root.setOnClickListener {
}
}
}
}

override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): NotificationViewHolder {
val binding =
ItemNotificationPostBinding.inflate(LayoutInflater.from(parent.context), parent, false)
return NotificationViewHolder(binding)
}

override fun onBindViewHolder(holder: NotificationViewHolder, position: Int) {
holder.onBind(getItem(position))
}

companion object {
private val DiffUtil = ItemDiffCallback<Notification>(
onItemsTheSame = { old, new -> old.notiId == new.notiId },
onContentsTheSame = { old, new -> old == new }
)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package com.android.go.sopt.winey.presentation.main.notification

import androidx.lifecycle.ViewModel

class NotificationViewModel : ViewModel()
Original file line number Diff line number Diff line change
Expand Up @@ -113,3 +113,41 @@ fun setLikeImage(view: ImageView, isLiked: Boolean) {
}
view.setImageResource(imageRes)
}

@BindingAdapter("notiType")
fun TextView.setNotiType(notiType: String) {
val resourceId = when (notiType) {
"RANKUPTO2", "RANKUPTO3", "RANKUPTO4" -> R.string.notification_rankup
"DELETERANKDOWNTO1", "DELETERANKDOWNTO2", "DELETERANKDOWNTO3" -> R.string.notification_rankdown
"GOALFAILED" -> R.string.notification_goal_failed
"LIKENOTI" -> R.string.notification_like
"COMMENTNOTI" -> R.string.notification_comment
"HOWTOLEVELUP" -> R.string.notification_how_to_levelup
else -> null
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

_ (언더바) 이용해서 가독성을 좀더 높여주는 건 어떨까요??
ex) RANK_UP_TO_2 DELETE_RANK_DOWN_TO_1 GOAL_FAILED LIKE_NOTI

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NotiType 이라는 enum 클래스를 만들어서, 타입을 구분하면 좋을 거 같아요! 그러면 이렇게 문자열을 하드코딩 하지 않아도 돼서 매우 편하답니다 :)

util/code 패키지에 있는 NicknameErrorCode 라는 enum class 참고해주세요!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

현재는 서버에서 날아오는 NotiType의 항목들이 코드에 적힌 "RANKUPTO2", "COMMENTNOTI" 등의 문자열로 날아오기 때문에 그에 따라서 분기 처리 해주기 위해서 지금처럼 적어두었습니다 ! enum 클래스를 사용하여 구현하는 방식은 알림 서버통신을 구현하면서 제대로 처리되는지 확인해보면서 시도해보겠습니다 !

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

앗 그렇군요! 화긴화긴


if (resourceId != null) {
text = context.getString(resourceId)
} else {
text = ""
}
}

@BindingAdapter("notiType")
fun ImageView.setNotiType(notiType: String) {
val drawableResourceId = when (notiType) {
"RANKUPTO2", "DELETERANKDOWNTO2" -> R.drawable.ic_notification_lv2
"RANKUPTO3", "DELETERANKDOWNTO3" -> R.drawable.ic_notification_lv3
"RANKUPTO4" -> R.drawable.ic_notification_lv4
"DELETERANKDOWNTO1" -> R.drawable.ic_notification_lv1
"GOALFAILED", "HOWTOLEVELUP" -> R.drawable.ic_notification_logo
"LIKENOTI" -> R.drawable.ic_notification_like
"COMMENTNOTI" -> R.drawable.ic_notification_comment
else -> 0
}

if (drawableResourceId != 0) {
setImageResource(drawableResourceId)
} else {
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

바인딩 어댑터 활용 굿!!

}
34 changes: 19 additions & 15 deletions app/src/main/res/drawable/ic_mypage_lv_help.xml
Original file line number Diff line number Diff line change
@@ -1,17 +1,21 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="25dp"
android:viewportWidth="24"
android:viewportHeight="25">
<path
android:pathData="M13.018,9.83C13.096,9.908 13.096,10.034 13.018,10.112L12.142,10.988C12.063,11.067 11.937,11.067 11.859,10.988L10.983,10.112C10.904,10.034 10.904,9.908 10.983,9.83L11.859,8.953C11.937,8.875 12.063,8.875 12.142,8.953L13.018,9.83Z"
android:fillColor="#BFC7CE"/>
<path
android:pathData="M12,11.917C12.414,11.917 12.75,12.252 12.75,12.667L12.75,16.417C12.75,16.831 12.414,17.167 12,17.167C11.586,17.167 11.25,16.831 11.25,16.417L11.25,12.667C11.25,12.252 11.586,11.917 12,11.917Z"
android:fillColor="#BFC7CE"
android:fillType="evenOdd"/>
<path
android:pathData="M12,19.414C15.59,19.414 18.5,16.504 18.5,12.914C18.5,9.324 15.59,6.414 12,6.414C8.41,6.414 5.5,9.324 5.5,12.914C5.5,16.504 8.41,19.414 12,19.414ZM12,20.914C16.418,20.914 20,17.333 20,12.914C20,8.496 16.418,4.914 12,4.914C7.582,4.914 4,8.496 4,12.914C4,17.333 7.582,20.914 12,20.914Z"
android:fillColor="#BFC7CE"
android:fillType="evenOdd"/>
android:width="30dp"
android:height="30dp"
android:viewportWidth="30"
android:viewportHeight="30">
<group>
<clip-path
android:pathData="M0,0H30V30H0V0Z"/>
<path
android:pathData="M16.017,11.915C16.095,11.993 16.095,12.12 16.017,12.198L15.141,13.074C15.063,13.152 14.936,13.152 14.858,13.074L13.982,12.198C13.904,12.12 13.904,11.993 13.982,11.915L14.858,11.039C14.936,10.961 15.063,10.961 15.141,11.039L16.017,11.915Z"
android:fillColor="#BFC7CE"/>
<path
android:pathData="M15,14.002C15.414,14.002 15.75,14.338 15.75,14.752L15.75,18.503C15.75,18.917 15.414,19.253 15,19.253C14.585,19.253 14.25,18.917 14.25,18.503L14.25,14.752C14.25,14.338 14.585,14.002 15,14.002Z"
android:fillColor="#BFC7CE"
android:fillType="evenOdd"/>
<path
android:pathData="M15,21.5C18.59,21.5 21.5,18.59 21.5,15C21.5,11.41 18.59,8.5 15,8.5C11.41,8.5 8.5,11.41 8.5,15C8.5,18.59 11.41,21.5 15,21.5ZM15,23C19.418,23 23,19.418 23,15C23,10.582 19.418,7 15,7C10.582,7 7,10.582 7,15C7,19.418 10.582,23 15,23Z"
android:fillColor="#BFC7CE"
android:fillType="evenOdd"/>
</group>
</vector>
14 changes: 14 additions & 0 deletions app/src/main/res/drawable/ic_notification_comment.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="40dp"
android:height="40dp"
android:viewportWidth="40"
android:viewportHeight="40">
<path
android:pathData="M8,0L32,0A8,8 0,0 1,40 8L40,32A8,8 0,0 1,32 40L8,40A8,8 0,0 1,0 32L0,8A8,8 0,0 1,8 0z"
android:fillColor="#F0F2F5"/>
<path
android:pathData="M13.929,27.381L13.929,27.381L16.655,25.354H25.191C26.349,25.354 27.287,24.416 27.287,23.258V15.996C27.287,14.838 26.349,13.9 25.191,13.9H14.996C13.838,13.9 12.9,14.838 12.9,15.996V26.864C12.9,27.107 13.037,27.33 13.255,27.44C13.473,27.549 13.733,27.526 13.929,27.381ZM14.189,25.582V15.996C14.189,15.55 14.55,15.189 14.996,15.189H25.191C25.637,15.189 25.999,15.55 25.999,15.996V23.258C25.999,23.704 25.637,24.066 25.191,24.066H16.442C16.303,24.066 16.168,24.11 16.057,24.193L16.057,24.193L14.189,25.582Z"
android:strokeWidth="0.2"
android:fillColor="#7C26FA"
android:strokeColor="#7C26FA"/>
</vector>
20 changes: 20 additions & 0 deletions app/src/main/res/drawable/ic_notification_like.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="40dp"
android:height="40dp"
android:viewportWidth="40"
android:viewportHeight="40">
<path
android:pathData="M8,0L32,0A8,8 0,0 1,40 8L40,32A8,8 0,0 1,32 40L8,40A8,8 0,0 1,0 32L0,8A8,8 0,0 1,8 0z"
android:fillColor="#F0F2F5"/>
<path
android:pathData="M8,8h24v24h-24z"
android:fillColor="#F0F2F5"/>
<path
android:pathData="M17.712,13.439C17.789,13.161 18.053,12.978 18.34,13.002C18.754,13.037 19.372,13.183 19.938,13.518C20.512,13.858 21.076,14.42 21.256,15.287C21.265,15.327 21.269,15.368 21.269,15.409V17.743H26.35C26.681,17.743 26.95,18.012 26.95,18.343V20.601C26.95,20.68 26.934,20.758 26.904,20.83L24.485,26.66C24.392,26.885 24.173,27.031 23.931,27.031H13.6C13.269,27.031 13,26.762 13,26.431V20.288C13,19.957 13.269,19.688 13.6,19.688H15.965L17.712,13.439ZM18.72,14.292L16.999,20.45C16.926,20.709 16.69,20.888 16.421,20.888H14.2V25.83H23.53L25.75,20.481V18.943H20.669C20.337,18.943 20.069,18.675 20.069,18.343V15.476C19.965,15.061 19.688,14.764 19.327,14.551C19.128,14.433 18.915,14.349 18.72,14.292Z"
android:fillColor="#7C26FA"
android:fillType="evenOdd"/>
<path
android:pathData="M15.813,26.395V20.379H17.013V26.395H15.813Z"
android:fillColor="#7C26FA"
android:fillType="evenOdd"/>
</vector>
40 changes: 40 additions & 0 deletions app/src/main/res/drawable/ic_notification_logo.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:aapt="http://schemas.android.com/aapt"
android:width="40dp"
android:height="40dp"
android:viewportWidth="40"
android:viewportHeight="40">
<path
android:pathData="M8,0L32,0A8,8 0,0 1,40 8L40,32A8,8 0,0 1,32 40L8,40A8,8 0,0 1,0 32L0,8A8,8 0,0 1,8 0z"
android:fillColor="#F0F2F5"/>
<group>
<clip-path
android:pathData="M7.803,29.998l23.134,-0l0,-19.998l-23.134,-0z"/>
<path
android:pathData="M19.358,30.907L15.162,10.002H11.068L15.264,30.907H19.358Z"
android:fillColor="#7C26FA"/>
<path
android:pathData="M22.709,9.996H18.615L16.518,20.452H20.611L22.709,9.996Z">
<aapt:attr name="android:fillColor">
<gradient
android:startX="16.518"
android:startY="15.224"
android:endX="22.709"
android:endY="15.224"
android:type="linear">
<item android:offset="0.03" android:color="#FFF0F2F5"/>
<item android:offset="1" android:color="#FF7C26FA"/>
</gradient>
</aapt:attr>
</path>
<path
android:pathData="M26.905,30.907L22.709,10.002H18.615L22.811,30.907H26.905Z"
android:fillColor="#7C26FA"/>
<path
android:pathData="M7.803,18.592L8.341,21.41H27.886V18.592H7.803Z"
android:fillColor="#7C26FA"/>
<path
android:pathData="M26.847,9.996L24.557,21.41H28.65L30.935,9.996H26.847Z"
android:fillColor="#7C26FA"/>
</group>
</vector>
Loading