Skip to content

Commit

Permalink
Merge pull request #123 from team-winey/feature/ui-notification-view
Browse files Browse the repository at this point in the history
[ui] ์•Œ๋ฆผ / ์•Œ๋ฆผ ๋ทฐ ๋””์ž์ธ
  • Loading branch information
Sangwook123 authored Aug 19, 2023
2 parents 04b38ed + d2215bc commit 7a55d33
Show file tree
Hide file tree
Showing 20 changed files with 1,119 additions and 56 deletions.
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
}

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 {
}
}
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

0 comments on commit 7a55d33

Please sign in to comment.