Skip to content

Commit

Permalink
[feat] #192 페이지 로딩 중일 때는 로딩 다이얼로그 뜨도록 구현
Browse files Browse the repository at this point in the history
  • Loading branch information
leeeha committed Sep 13, 2023
1 parent 4a4f7de commit 640d845
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ class WineyFeedFragment :
private lateinit var wineyFeedAdapter: WineyFeedAdapter
private lateinit var wineyFeedHeaderAdapter: WineyFeedHeaderAdapter
private lateinit var wineyFeedLoadAdapter: WineyFeedLoadAdapter
private val loadingDialog by lazy { WineyFeedLoadingDialogFragment() }
private var clickedFeedId = -1
private var deleteFeedId = -1

Expand Down Expand Up @@ -275,21 +276,32 @@ class WineyFeedFragment :
when (loadStates.refresh) {
is LoadState.Loading -> {
Timber.d("LOADING")
binding.rvWineyfeedPost.isVisible = false
showLoadingDialog()
}

is LoadState.NotLoading -> {
Timber.d("NOT LOADING")
dismissLoadingDialog()
binding.rvWineyfeedPost.isVisible = wineyFeedAdapter.itemCount > 0
}

is LoadState.Error -> {
Timber.tag("failure").e(MSG_WINEYFEED_ERROR)
dismissLoadingDialog()
snackBar(binding.root) { stringOf(R.string.error_winey_feed_loading) }
}
}
}
}

private fun showLoadingDialog() {
binding.rvWineyfeedPost.isVisible = false
loadingDialog.show(parentFragmentManager, TAG_LOADING_DIALOG)
}

private fun dismissLoadingDialog() {
if (loadingDialog.isAdded) loadingDialog.dismiss()
}

private fun initPostLikeStateObserver() {
viewModel.postWineyFeedLikeState.flowWithLifecycle(viewLifeCycle).onEach { state ->
when (state) {
Expand Down Expand Up @@ -459,6 +471,7 @@ class WineyFeedFragment :
private const val TAG_GOAL_DIALOG = "NO_GOAL_DIALOG"
private const val TAG_FEED_DELETE_DIALOG = "FEED_DELETE_DIALOG"
private const val TAG_FEED_REPORT_DIALOG = "FEED_REPORT_DIALOG"
private const val TAG_LOADING_DIALOG = "WINEY_FEED_LOADING_DIALOG"
private const val POPUP_MENU_POS_OFFSET = 65
private const val KEY_FEED_ID = "feedId"
private const val KEY_FEED_WRITER_ID = "feedWriterId"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package org.go.sopt.winey.presentation.main.feed

import android.os.Bundle
import org.go.sopt.winey.R
import org.go.sopt.winey.databinding.FragmentWineyFeedLoadingDialogBinding
import org.go.sopt.winey.util.binding.BindingDialogFragment

class WineyFeedLoadingDialogFragment :
BindingDialogFragment<FragmentWineyFeedLoadingDialogBinding>(
R.layout.fragment_winey_feed_loading_dialog
) {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
dialog?.setCanceledOnTouchOutside(false)
}
}
19 changes: 19 additions & 0 deletions app/src/main/res/layout/fragment_winey_feed_loading_dialog.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?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">

<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@android:color/transparent">

<ProgressBar
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />

</androidx.constraintlayout.widget.ConstraintLayout>
</layout>
3 changes: 3 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -228,4 +228,7 @@
<string name="upload_loading_title_first_line2">조금 더 아껴볼까요?</string>
<string name="upload_loading_title_other_line1">오늘은</string>
<string name="upload_loading_title_other_line3">절약했어요</string>

<!-- error -->
<string name="error_winey_feed_loading">Can\'t loading winey feed list…</string>
</resources>

0 comments on commit 640d845

Please sign in to comment.