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

refactor: 공모 상세 페이지 진입 시 로딩이 된 후에 화면을 보여주도록 수정 #609

Merged
merged 8 commits into from
Oct 22, 2024
6 changes: 5 additions & 1 deletion android/app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ android {
versionName = "1.1.4"

testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
testInstrumentationRunnerArguments["runnerBuilder"] = "de.mannodermaus.junit5.AndroidJUnit5Builder"
testInstrumentationRunnerArguments["runnerBuilder"] =
"de.mannodermaus.junit5.AndroidJUnit5Builder"
vectorDrawables {
useSupportLibrary = true
}
Expand Down Expand Up @@ -168,6 +169,9 @@ dependencies {
// Hilt
implementation(libs.hilt.android)
kapt(libs.hilt.compiler)

// Skeleton-UI
implementation(libs.shimmer)
Comment on lines +173 to +174
Copy link
Contributor

Choose a reason for hiding this comment

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

오 시머~~

}

kapt {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,8 @@ class OfferingDetailFragment : Fragment(), OnOfferingDeleteAlertClickListener {

viewModel.showAlertEvent.observe(viewLifecycleOwner) {
val alertBinding = DialogAlertBinding.inflate(layoutInflater, null, false)
alertBinding.tvDialogMessage.text = getString(R.string.offering_detail_participate_alert)
alertBinding.tvDialogMessage.text =
getString(R.string.offering_detail_participate_alert)
alertBinding.listener = viewModel

dialog.setContentView(alertBinding.root)
Expand All @@ -126,6 +127,10 @@ class OfferingDetailFragment : Fragment(), OnOfferingDeleteAlertClickListener {
viewModel.alertCancelEvent.observe(viewLifecycleOwner) {
dialog.dismiss()
}

viewModel.loading.observe(viewLifecycleOwner) {
startShimmer(it)
}
}

override fun onClickConfirm() {
Expand Down Expand Up @@ -207,6 +212,14 @@ class OfferingDetailFragment : Fragment(), OnOfferingDeleteAlertClickListener {
toast?.show()
}

private fun startShimmer(isLoading: Boolean) {
if (isLoading) {
binding.sflOfferingDetail.startShimmer()
return
}
binding.sflOfferingDetail.stopShimmer()
}

companion object {
const val OFFERING_DETAIL_BUNDLE_KEY = "offering_detail_bundle_key"
const val UPDATED_OFFERING_ID_KEY = "updated_offering_id"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,19 +95,27 @@ class OfferingDetailViewModel
private val _alertCancelEvent = MutableSingleLiveData<Unit>()
val alertCancelEvent: SingleLiveData<Unit> get() = _alertCancelEvent

private val _loading: MutableLiveData<Boolean> = MutableLiveData(false)
val loading: LiveData<Boolean> get() = _loading

init {
loadOffering()
}

fun loadOffering() {
viewModelScope.launch {
_loading.value = true
when (val result = offeringDetailRepository.fetchOfferingDetail(offeringId)) {
is Result.Error ->
when (result.error) {
DataError.Network.UNAUTHORIZED -> {
when (authRepository.saveRefresh()) {
is Result.Success -> loadOffering()
is Result.Success -> {
loadOffering()
}

is Result.Error -> {
_loading.value = false
userPreferencesDataStore.removeAllData()
_refreshTokenExpiredEvent.setValue(Unit)
return@launch
Expand All @@ -125,6 +133,7 @@ class OfferingDetailViewModel
}

is Result.Success -> {
_loading.value = false
_offeringDetail.value = result.data
_currentCount.value = result.data.currentCount.value
_offeringCondition.value = result.data.condition
Expand Down
17 changes: 15 additions & 2 deletions android/app/src/main/res/layout/fragment_offering_detail.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
android:layout_height="0dp"
android:overScrollMode="never"
android:scrollbars="none"
app:isVisible="@{!vm.loading}"
app:layout_constraintBottom_toTopOf="@id/btn_participate"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
Expand Down Expand Up @@ -362,7 +363,7 @@
app:condition="@{vm.offeringCondition}"
app:currentCount="@{vm.currentCount}"
app:debouncedOnClick="@{() -> vm.onParticipateClick()}"
app:isVisible="@{!vm.isParticipated}"
app:isVisible="@{vm.isParticipated &amp;&amp; !vm.loading}"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
Expand All @@ -382,11 +383,23 @@
android:text="@string/offering_detail_move_comment_detail"
android:textColor="@color/white"
app:debouncedOnClick="@{() -> vm.onClickMoveCommentDetail()}"
app:isVisible="@{vm.isParticipated}"
app:isVisible="@{vm.isParticipated &amp;&amp; !vm.loading}"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/sv_layout" />

<com.facebook.shimmer.ShimmerFrameLayout
android:id="@+id/sfl_offering_detail"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:isVisible="@{vm.loading}"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">

<include layout="@layout/fragment_offering_detail_shimmer" />

</com.facebook.shimmer.ShimmerFrameLayout>

</androidx.constraintlayout.widget.ConstraintLayout>
</layout>
197 changes: 197 additions & 0 deletions android/app/src/main/res/layout/fragment_offering_detail_shimmer.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,197 @@
<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools">

<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent">

<ImageView
android:id="@+id/iv_product"
android:layout_width="match_parent"
android:layout_height="250dp"
android:adjustViewBounds="true"
android:background="@color/gray_300"
android:scaleType="centerCrop"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />


<TextView
android:id="@+id/tv_title"
android:layout_width="@dimen/size_200"
android:layout_height="@dimen/size_44"
android:layout_marginStart="23dp"
android:layout_marginTop="18dp"
android:background="@color/gray_300"
android:paddingBottom="12dp"
app:layout_constraintBottom_toTopOf="@id/iv_user_emoticon"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/iv_product" />

<ImageView
android:id="@+id/iv_user_emoticon"
android:layout_width="15dp"
android:layout_height="11dp"
app:layout_constraintStart_toStartOf="@id/tv_title"
app:layout_constraintTop_toBottomOf="@id/tv_title" />

<TextView
android:id="@+id/tv_nickname"
android:layout_width="@dimen/size_80"
android:layout_height="@dimen/size_20"
android:layout_marginStart="8dp"
android:fontFamily="@font/suit_medium"
android:textColor="@color/gray_900"
android:textSize="14sp"
app:layout_constraintStart_toEndOf="@id/iv_user_emoticon"
app:layout_constraintTop_toBottomOf="@id/tv_title" />

<TextView
android:id="@+id/tv_product_link_comment"
android:layout_width="@dimen/size_60"
android:layout_height="@dimen/size_20"
android:layout_marginTop="18dp"
app:layout_constraintBottom_toTopOf="@id/horizon_line"
app:layout_constraintStart_toStartOf="@id/tv_title"
app:layout_constraintTop_toBottomOf="@id/tv_nickname" />


<View
android:id="@+id/horizon_line"
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_marginHorizontal="16dp"
android:layout_marginTop="12dp"
android:background="@color/horizon_line"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/tv_product_link_comment" />

<ImageView
android:id="@+id/iv_money"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="15dp"
app:layout_constraintStart_toStartOf="@id/tv_title"
app:layout_constraintTop_toBottomOf="@id/horizon_line" />

<TextView
android:id="@+id/tv_moeny_comment"
android:layout_width="@dimen/size_50"
android:layout_height="@dimen/size_18"
android:layout_marginStart="8dp"
android:layout_marginTop="15dp"
app:layout_constraintBottom_toBottomOf="@id/iv_money"
app:layout_constraintStart_toEndOf="@id/iv_money"
app:layout_constraintTop_toBottomOf="@id/horizon_line" />

<TextView
android:id="@+id/tv_divided_price"
android:layout_width="@dimen/size_70"
android:layout_height="@dimen/size_24"
android:layout_marginTop="8dp"
android:textSize="18sp"
app:layout_constraintStart_toStartOf="@id/tv_title"
app:layout_constraintTop_toBottomOf="@id/iv_money" />

<TextView
android:id="@+id/tv_total_price"
android:layout_width="@dimen/size_80"
android:layout_height="@dimen/size_15"
android:layout_marginStart="5dp"
android:layout_marginTop="8dp"
app:layout_constraintBottom_toBottomOf="@id/tv_divided_price"
app:layout_constraintStart_toEndOf="@id/tv_divided_price"
app:layout_constraintTop_toBottomOf="@id/iv_money" />

<ImageView
android:id="@+id/iv_time"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="23dp"
app:layout_constraintStart_toStartOf="@id/tv_title"
app:layout_constraintTop_toBottomOf="@id/tv_divided_price" />

<TextView
android:id="@+id/tv_meeting_date_comment"
android:layout_width="@dimen/size_60"
android:layout_height="@dimen/size_20"
android:layout_marginStart="8dp"
android:layout_marginTop="23dp"
app:layout_constraintBottom_toBottomOf="@id/iv_time"
app:layout_constraintStart_toEndOf="@id/iv_time"
app:layout_constraintTop_toBottomOf="@id/tv_divided_price" />

<TextView
android:id="@+id/tv_meeting_date"
android:layout_width="90dp"
android:layout_height="@dimen/size_18"
android:layout_marginTop="8dp"
app:layout_constraintStart_toStartOf="@id/tv_title"
app:layout_constraintTop_toBottomOf="@id/iv_time" />

<ImageView
android:id="@+id/iv_location"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="60dp"
android:layout_marginTop="23dp"
app:layout_constraintStart_toEndOf="@id/tv_meeting_date_comment"
app:layout_constraintTop_toBottomOf="@id/tv_divided_price" />

<TextView
android:id="@+id/tv_recruit_location_comment"
android:layout_width="90dp"
android:layout_height="@dimen/size_18"
android:layout_marginTop="23dp"
app:layout_constraintBottom_toBottomOf="@id/iv_location"
app:layout_constraintStart_toEndOf="@id/iv_location"
app:layout_constraintTop_toBottomOf="@id/tv_divided_price" />

<TextView
android:id="@+id/tv_meeting_address"
android:layout_width="@dimen/size_70"
android:layout_height="@dimen/size_18"
android:layout_marginTop="8dp"
android:ellipsize="end"
android:maxLines="2"
android:paddingEnd="@dimen/size_5"
app:layout_constraintStart_toStartOf="@id/iv_location"
app:layout_constraintTop_toBottomOf="@id/iv_location" />

<TextView
android:id="@+id/tv_content_comment"
android:layout_width="@dimen/size_40"
android:layout_height="@dimen/size_20"
android:layout_marginTop="30dp"
app:layout_constraintStart_toStartOf="@id/tv_meeting_date"
app:layout_constraintTop_toBottomOf="@id/tv_meeting_date" />

<TextView
android:id="@+id/tv_content"
android:layout_width="0dp"
android:layout_height="@dimen/size_150"
android:layout_marginTop="18dp"
android:layout_marginEnd="18dp"
android:background="@color/gray_300"
android:paddingBottom="@dimen/size_50"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="@id/tv_title"
app:layout_constraintTop_toBottomOf="@id/tv_content_comment" />

<Button
android:id="@+id/btn_participate"
android:layout_width="0dp"
android:layout_height="@dimen/size_60"
android:layout_marginHorizontal="19dp"
android:layout_marginBottom="20dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" />

</androidx.constraintlayout.widget.ConstraintLayout>
</layout>
4 changes: 4 additions & 0 deletions android/gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ paging = "3.3.0"
swiperefreshlayout = "1.1.0"
datastore = "1.0.0"
junit-jupiter = "5.10.2"
shimmer = "0.5.0"
#assert-core = "3.25.3"
#core-testing = "2.1.0"
#mannodermaus = "1.3.0"
Expand Down Expand Up @@ -98,6 +99,9 @@ kakao-sdk = { group = "com.kakao.sdk", name = "v2-all", version.ref = "kakaoSdk"
# Kotlin Serialization
kotlinx-serialization-json = { group = "org.jetbrains.kotlinx", name = "kotlinx-serialization-json", version.ref = "kotlinxSerialization" }

# Skeleton-UI
shimmer = { group = "com.facebook.shimmer", name = "shimmer", version.ref = "shimmer" }

[plugins]
androidApplication = { id = "com.android.application", version.ref = "agp" }
jetbrainsKotlinAndroid = { id = "org.jetbrains.kotlin.android", version.ref = "kotlin" }
Loading