Skip to content

Commit

Permalink
feat: 공모 상세 페이지 기능 추가 (#94)
Browse files Browse the repository at this point in the history
* chore: 마이페이지 닉네임 임시로 지정

* feat: 바로가기 기능 구현

* feat: 참여버튼 클릭 시 댓글방으로 가도록 기능 구현

* feat: 신고하기 이미지 추가

* style: lint적용

* refactor: 불러오는 공모 페이지 사이즈 변경
  • Loading branch information
Namyunsuk authored Jul 25, 2024
1 parent 9e9de41 commit 86cbb98
Show file tree
Hide file tree
Showing 10 changed files with 130 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package com.zzang.chongdae.presentation.util

import android.animation.ValueAnimator
import android.content.Context
import android.text.util.Linkify
import android.util.TypedValue
import android.view.View
import android.view.ViewGroup
Expand All @@ -14,6 +15,16 @@ import com.zzang.chongdae.domain.model.OfferingCondition
import java.time.LocalDateTime
import java.time.format.DateTimeFormatter
import java.util.Locale
import java.util.regex.Pattern

@BindingAdapter("url")
fun TextView.setHyperlink(url: String?) {
url?.let {
val mTransform = Linkify.TransformFilter { _, _ -> "" }
val pattern = Pattern.compile(this.text.toString())
Linkify.addLinks(this, pattern, it, null, mTransform)
}
}

@BindingAdapter("detailProductImageUrl")
fun ImageView.setImageResource(imageUrl: String?) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.zzang.chongdae.presentation.util

open class Event<out T>(private val content: T) {
var hasBeenHandled = false
private set

fun getContentIfNotHandled(): T? {
return if (hasBeenHandled) {
null
} else {
hasBeenHandled = true
content
}
}

fun peekContent(): T = content
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.zzang.chongdae.presentation.util

class MutableSingleLiveData<T> : SingleLiveData<T> {
constructor() : super()

constructor(value: T) : super(value)

public override fun postValue(value: T) {
super.postValue(value)
}

public override fun setValue(value: T) {
super.setValue(value)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package com.zzang.chongdae.presentation.util

import androidx.lifecycle.LifecycleOwner
import androidx.lifecycle.MutableLiveData

abstract class SingleLiveData<T> {
private val liveData = MutableLiveData<Event<T>>()

protected constructor()

protected constructor(value: T) {
liveData.value = Event(value)
}

protected open fun setValue(value: T) {
liveData.value = Event(value)
}

protected open fun postValue(value: T) {
liveData.postValue(Event(value))
}

fun getValue() = liveData.value?.peekContent()

fun observe(
owner: LifecycleOwner,
onResult: (T) -> Unit,
) {
liveData.observe(owner) { it.getContentIfNotHandled()?.let(onResult) }
}

fun observePeek(
owner: LifecycleOwner,
onResult: (T) -> Unit,
) {
liveData.observe(owner) { onResult(it.peekContent()) }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import com.zzang.chongdae.data.remote.api.NetworkManager
import com.zzang.chongdae.data.remote.source.impl.OfferingDetailDataSourceImpl
import com.zzang.chongdae.data.repository.remote.OfferingDetailRepositoryImpl
import com.zzang.chongdae.databinding.ActivityOfferingDetailBinding
import com.zzang.chongdae.presentation.view.commentdetail.CommentDetailActivity

class OfferingDetailActivity : AppCompatActivity() {
private var _binding: ActivityOfferingDetailBinding? = null
Expand All @@ -31,6 +32,7 @@ class OfferingDetailActivity : AppCompatActivity() {
super.onCreate(savedInstanceState)

initBinding()
setUpMoveCommentDetailEventObserve()
}

override fun onDestroy() {
Expand All @@ -50,6 +52,12 @@ class OfferingDetailActivity : AppCompatActivity() {
EXTRA_DEFAULT_VALUE,
)

private fun setUpMoveCommentDetailEventObserve() {
viewModel.commentDetailEvent.observe(this) { offeringTitle ->
CommentDetailActivity.startActivity(this, offeringId, offeringTitle)
}
}

companion object {
private const val EXTRA_DEFAULT_VALUE = -1L
private const val EXTRA_OFFERING_ID_KEY = "offering_id_key"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import com.zzang.chongdae.domain.model.OfferingCondition
import com.zzang.chongdae.domain.model.OfferingCondition.Companion.isAvailable
import com.zzang.chongdae.domain.model.OfferingDetail
import com.zzang.chongdae.domain.repository.OfferingDetailRepository
import com.zzang.chongdae.presentation.util.MutableSingleLiveData
import com.zzang.chongdae.presentation.util.SingleLiveData
import kotlinx.coroutines.launch

class OfferingDetailViewModel(
Expand All @@ -34,6 +36,9 @@ class OfferingDetailViewModel(
private val _isRepresentative: MutableLiveData<Boolean> = MutableLiveData(true)
val isRepresentative: LiveData<Boolean> get() = _isRepresentative

private val _commentDetailEvent: MutableSingleLiveData<String> = MutableSingleLiveData()
val commentDetailEvent: SingleLiveData<String> get() = _commentDetailEvent

init {
loadArticle()
}
Expand Down Expand Up @@ -66,6 +71,7 @@ class OfferingDetailViewModel(
).onSuccess {
_isParticipated.value = true
_isAvailable.value = false
_commentDetailEvent.setValue(offeringDetail.value?.title ?: "")
}.onFailure {
Log.e("Error", it.message.toString())
}
Expand All @@ -79,4 +85,8 @@ class OfferingDetailViewModel(

// 총대여부를 확인하는 메서드(로그인 기능 구현 시 수정 예정)
private fun isRepresentative(it: OfferingDetail) = it.memberId == BuildConfig.TOKEN

companion object {
private const val DEFAULT_TITLE = ""
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class OfferingViewModel(
// 무한 스크롤 적용 시 수정 예정
fun updateArticles() {
viewModelScope.launch {
offeringsRepository.fetchOfferings(0L, 10).onSuccess {
offeringsRepository.fetchOfferings(0L, 100).onSuccess {
_offerings.value = it
}.onFailure {
}
Expand Down
14 changes: 14 additions & 0 deletions android/app/src/main/res/drawable/ic_detail_report.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="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24">
<group>
<clip-path
android:pathData="M0,0h24v24h-24z"/>
<path
android:pathData="M11.999,7C13.552,7 15.044,7.602 16.162,8.678C17.28,9.755 17.937,11.224 17.995,12.775L17.999,13V20H18.999C19.254,20 19.499,20.098 19.685,20.273C19.87,20.448 19.982,20.687 19.997,20.941C20.011,21.196 19.929,21.446 19.765,21.642C19.601,21.837 19.369,21.963 19.116,21.993L18.999,22H4.999C4.745,22 4.499,21.902 4.314,21.727C4.129,21.552 4.017,21.313 4.002,21.059C3.987,20.804 4.07,20.554 4.234,20.358C4.397,20.163 4.629,20.037 4.882,20.007L4.999,20H5.999V13C5.999,11.409 6.632,9.883 7.757,8.757C8.882,7.632 10.408,7 11.999,7ZM11.142,11.986L9.651,14.47C9.559,14.623 9.51,14.798 9.507,14.977C9.505,15.156 9.55,15.332 9.638,15.488C9.726,15.643 9.854,15.773 10.009,15.863C10.163,15.953 10.339,16 10.517,16H11.733L11.142,16.985C11.012,17.212 10.975,17.481 11.041,17.735C11.106,17.989 11.269,18.207 11.494,18.342C11.718,18.477 11.987,18.518 12.242,18.457C12.497,18.396 12.717,18.237 12.856,18.015L14.347,15.53C14.439,15.377 14.489,15.202 14.491,15.023C14.494,14.844 14.449,14.668 14.361,14.512C14.272,14.357 14.145,14.227 13.99,14.137C13.836,14.047 13.66,14 13.481,14H12.265L12.856,13.015C12.987,12.788 13.024,12.519 12.958,12.265C12.892,12.011 12.73,11.793 12.505,11.658C12.281,11.523 12.012,11.482 11.757,11.543C11.502,11.604 11.281,11.763 11.142,11.985V11.986ZM5.541,5.139L5.635,5.222L6.342,5.929C6.522,6.109 6.626,6.35 6.634,6.604C6.641,6.858 6.552,7.106 6.384,7.296C6.216,7.487 5.982,7.606 5.729,7.63C5.476,7.654 5.223,7.581 5.022,7.426L4.928,7.343L4.221,6.636C4.042,6.456 3.938,6.215 3.93,5.961C3.922,5.707 4.012,5.459 4.18,5.269C4.348,5.078 4.582,4.959 4.835,4.935C5.088,4.911 5.34,4.984 5.541,5.139ZM19.777,5.222C19.965,5.41 20.07,5.664 20.07,5.929C20.07,6.194 19.965,6.448 19.777,6.636L19.07,7.343C18.978,7.439 18.868,7.515 18.746,7.567C18.624,7.62 18.493,7.647 18.36,7.648C18.227,7.649 18.095,7.624 17.972,7.574C17.85,7.524 17.738,7.449 17.644,7.355C17.55,7.261 17.476,7.15 17.426,7.027C17.375,6.904 17.35,6.772 17.351,6.64C17.352,6.507 17.38,6.376 17.432,6.254C17.485,6.132 17.561,6.021 17.656,5.929L18.363,5.222C18.551,5.035 18.805,4.929 19.07,4.929C19.336,4.929 19.59,5.035 19.777,5.222ZM11.999,2C12.265,2 12.519,2.105 12.707,2.293C12.894,2.48 12.999,2.735 12.999,3V4C12.999,4.265 12.894,4.52 12.707,4.707C12.519,4.895 12.265,5 11.999,5C11.734,5 11.48,4.895 11.292,4.707C11.105,4.52 10.999,4.265 10.999,4V3C10.999,2.735 11.105,2.48 11.292,2.293C11.48,2.105 11.734,2 11.999,2Z"
android:fillColor="#F15642"
android:fillType="evenOdd"/>
</group>
</vector>
18 changes: 14 additions & 4 deletions android/app/src/main/res/layout/activity_offering_detail.xml
Original file line number Diff line number Diff line change
Expand Up @@ -45,18 +45,27 @@
tools:src="@drawable/img_detail_product_default" />

<TextView
android:id="@+id/tv_report_comment"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="35dp"
android:layout_marginEnd="25dp"
android:fontFamily="@font/suit_medium"
android:text="@string/detail_report_text"
android:textColor="@color/black_900"
android:textColor="@color/gray_font"
android:textSize="15sp"
app:isVisible="@{!vm.isRepresentative()}"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintEnd_toStartOf="@id/iv_report"
app:layout_constraintTop_toTopOf="parent" />

<ImageView
android:id="@+id/iv_report"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="@dimen/size_10"
android:src="@drawable/ic_detail_report"
app:layout_constraintBottom_toBottomOf="@id/tv_report_comment"
app:layout_constraintEnd_toEndOf="parent" />


<androidx.constraintlayout.widget.ConstraintLayout
android:id="@+id/layout_info"
Expand Down Expand Up @@ -156,7 +165,8 @@
android:textSize="16sp"
app:layout_constraintBottom_toBottomOf="@id/tv_product_link_comment"
app:layout_constraintStart_toEndOf="@id/tv_product_link_comment"
app:layout_constraintTop_toTopOf="@id/tv_product_link_comment" />
app:layout_constraintTop_toTopOf="@id/tv_product_link_comment"
app:url="@{vm.offeringDetail.productUrl}" />

<View
android:id="@+id/horizon_line"
Expand Down
3 changes: 2 additions & 1 deletion android/app/src/main/res/layout/fragment_my_page.xml
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,11 @@
android:layout_height="wrap_content"
android:textColor="@color/main_color"
android:textSize="@dimen/font_size_20"
android:text="총알0328"
android:textStyle="bold"
app:layout_constraintStart_toStartOf="@id/tv_welcome_text"
app:layout_constraintTop_toBottomOf="@id/tv_welcome_text"
tools:text="쿠쿠콧구멍" />
tools:text="총알133" />

<TextView
android:id="@+id/tv_nickname_title"
Expand Down

0 comments on commit 86cbb98

Please sign in to comment.