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: 5차 QA 반영 #461

Open
wants to merge 6 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
Expand Up @@ -5,6 +5,7 @@ enum class ResultFrom {
FeedDetailBack,
FeedDetailRemoved,
FeedDetailRefreshed,
FeedDetailError,
Feed,
CreateFeed,
ChangeUserInfo,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import com.teamwss.websoso.common.ui.model.ResultFrom.BlockUser
import com.teamwss.websoso.common.ui.model.ResultFrom.CreateFeed
import com.teamwss.websoso.common.ui.model.ResultFrom.Feed
import com.teamwss.websoso.common.ui.model.ResultFrom.FeedDetailBack
import com.teamwss.websoso.common.ui.model.ResultFrom.FeedDetailError
import com.teamwss.websoso.common.ui.model.ResultFrom.FeedDetailRefreshed
import com.teamwss.websoso.common.ui.model.ResultFrom.FeedDetailRemoved
import com.teamwss.websoso.common.ui.model.ResultFrom.NovelDetailBack
Expand Down Expand Up @@ -304,10 +305,10 @@ class FeedDetailActivity : BaseActivity<ActivityFeedDetailBinding>(activity_feed
if (::activityResultCallback.isInitialized.not()) {
activityResultCallback = registerForActivityResult(StartActivityForResult()) { result ->
when (result.resultCode) {
NovelDetailBack.RESULT_OK, CreateFeed.RESULT_OK, OtherUserProfileBack.RESULT_OK -> feedDetailViewModel.updateFeedDetail(
feedId,
CreateFeed
)
NovelDetailBack.RESULT_OK,
CreateFeed.RESULT_OK,
OtherUserProfileBack.RESULT_OK,
-> feedDetailViewModel.updateFeedDetail(feedId, CreateFeed)

BlockUser.RESULT_OK -> {
val nickname = result.data?.getStringExtra(USER_NICKNAME).orEmpty()
Expand Down Expand Up @@ -352,15 +353,17 @@ class FeedDetailActivity : BaseActivity<ActivityFeedDetailBinding>(activity_feed
}

binding.ivFeedDetailCommentRegister.setOnClickListener {
binding.etFeedDetailInput.run {
when (feedDetailViewModel.commentId == DEFAULT_FEED_ID) {
true -> feedDetailViewModel.dispatchComment(text.toString())
false -> feedDetailViewModel.modifyComment(text.toString())
if (binding.etFeedDetailInput.text.isNullOrBlank().not()) {
binding.etFeedDetailInput.run {
when (feedDetailViewModel.commentId == DEFAULT_FEED_ID) {
true -> feedDetailViewModel.dispatchComment(text.toString())
false -> feedDetailViewModel.modifyComment(text.toString())
}
text.clear()
clearFocus()
}
text.clear()
clearFocus()
it.hideKeyboard()
}
it.hideKeyboard()
}
}

Expand All @@ -378,10 +381,7 @@ class FeedDetailActivity : BaseActivity<ActivityFeedDetailBinding>(activity_feed
setRefreshViewParams(ViewGroup.LayoutParams(30.toIntPxFromDp(), 30.toIntPxFromDp()))
setLottieAnimation(LOTTIE_IMAGE)
setOnRefreshListener {
feedDetailViewModel.updateFeedDetail(
feedId,
FeedDetailRefreshed,
)
feedDetailViewModel.updateFeedDetail(feedId, FeedDetailRefreshed)
}
}
}
Expand All @@ -407,6 +407,11 @@ class FeedDetailActivity : BaseActivity<ActivityFeedDetailBinding>(activity_feed
}
}

feedDetailUiState.isServerError -> {
setResult(FeedDetailError.RESULT_OK)
if (!isFinishing) finish()
}

!feedDetailUiState.loading -> {
binding.wllFeed.setWebsosoLoadingVisibility(false)
binding.sptrFeedRefresh.setRefreshing(false)
Expand Down Expand Up @@ -451,10 +456,10 @@ class FeedDetailActivity : BaseActivity<ActivityFeedDetailBinding>(activity_feed
val feedDetail = listOf(header) + comments

with(feedDetailAdapter) {
when (itemCount == 0) {
true -> submitList(feedDetail)
false -> submitList(feedDetail).also {
binding.rvFeedDetail.smoothScrollToPosition(itemCount)
submitList(feedDetail).also {
when (feedDetailUiState.isRefreshed) {
true -> binding.rvFeedDetail.smoothScrollToPosition(0)
false -> binding.rvFeedDetail.smoothScrollToPosition(itemCount)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ class FeedDetailViewModel @Inject constructor(

_feedDetailUiState.value = feedDetailUiState.copy(
loading = false,
isRefreshed = true,
feedDetail = FeedDetailModel(
feed = feed.toUi(),
comments = comments.comments.map { it.toUi() },
Expand Down Expand Up @@ -90,7 +91,7 @@ class FeedDetailViewModel @Inject constructor(
}.onFailure {
_feedDetailUiState.value = feedDetailUiState.copy(
loading = false,
error = true,
isReported = true,
)
}
}
Expand All @@ -108,7 +109,7 @@ class FeedDetailViewModel @Inject constructor(
}.onFailure {
_feedDetailUiState.value = feedDetailUiState.copy(
loading = false,
error = true,
isReported = true,
)
}
}
Expand Down Expand Up @@ -153,7 +154,9 @@ class FeedDetailViewModel @Inject constructor(
)
)
}.onFailure {
_feedDetailUiState.value = feedDetailUiState.copy(error = true)
_feedDetailUiState.value = feedDetailUiState.copy(
isServerError = true,
)
}
}
}
Expand All @@ -170,7 +173,7 @@ class FeedDetailViewModel @Inject constructor(
}.onFailure {
_feedDetailUiState.value = feedDetailUiState.copy(
loading = false,
error = true,
isServerError = true,
)
}
}
Expand All @@ -188,7 +191,7 @@ class FeedDetailViewModel @Inject constructor(
}.onFailure {
_feedDetailUiState.value = feedDetailUiState.copy(
loading = false,
error = true,
isServerError = true,
)
}
}
Expand All @@ -205,6 +208,7 @@ class FeedDetailViewModel @Inject constructor(

_feedDetailUiState.value = feedDetailUiState.copy(
loading = false,
isRefreshed = false,
feedDetail = feedDetailUiState.feedDetail.copy(
feed = feedDetailUiState.feedDetail.feed?.copy(commentCount = comments.size),
comments = comments
Expand All @@ -213,7 +217,7 @@ class FeedDetailViewModel @Inject constructor(
}.onFailure {
_feedDetailUiState.value = feedDetailUiState.copy(
loading = false,
error = true,
isServerError = true,
)
}
}
Expand All @@ -231,7 +235,7 @@ class FeedDetailViewModel @Inject constructor(
}.onFailure {
_feedDetailUiState.value = feedDetailUiState.copy(
loading = false,
error = true,
isReported = true,
)
}
}
Expand All @@ -249,7 +253,7 @@ class FeedDetailViewModel @Inject constructor(
}.onFailure {
_feedDetailUiState.value = feedDetailUiState.copy(
loading = false,
error = true,
isReported = true,
)
}
}
Expand All @@ -276,7 +280,7 @@ class FeedDetailViewModel @Inject constructor(
}.onFailure {
_feedDetailUiState.value = feedDetailUiState.copy(
loading = false,
error = true,
isServerError = true,
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ import com.teamwss.websoso.common.ui.model.ResultFrom.Feed
data class FeedDetailUiState(
val loading: Boolean = true,
val error: Boolean = false,
val isReported: Boolean = false,
val isServerError: Boolean = false,
val isRefreshed: Boolean = false,
val previousStack: PreviousStack = PreviousStack(Feed),
val feedDetail: FeedDetailModel = FeedDetailModel(),
) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import javax.inject.Inject
@HiltViewModel
class MainViewModel @Inject constructor(
private val userRepository: UserRepository,
private val savedStateHandle: SavedStateHandle
private val savedStateHandle: SavedStateHandle,
) : ViewModel() {
private var userId: Long = DEFAULT_USER_ID

Expand Down Expand Up @@ -45,8 +45,6 @@ class MainViewModel @Inject constructor(
}
}

fun isUserId(id: Long): Boolean = userId == id

companion object {
const val DEFAULT_USER_ID = -1L
}
Expand Down
52 changes: 31 additions & 21 deletions app/src/main/java/com/teamwss/websoso/ui/main/feed/FeedFragment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,13 @@ import com.teamwss.websoso.R.string.feed_create_done
import com.teamwss.websoso.R.string.feed_popup_menu_content_isMyFeed
import com.teamwss.websoso.R.string.feed_popup_menu_content_report_isNotMyFeed
import com.teamwss.websoso.R.string.feed_removed_feed_snackbar
import com.teamwss.websoso.R.string.feed_server_error
import com.teamwss.websoso.common.ui.base.BaseFragment
import com.teamwss.websoso.common.ui.custom.WebsosoChip
import com.teamwss.websoso.common.ui.model.ResultFrom.BlockUser
import com.teamwss.websoso.common.ui.model.ResultFrom.CreateFeed
import com.teamwss.websoso.common.ui.model.ResultFrom.FeedDetailBack
import com.teamwss.websoso.common.ui.model.ResultFrom.FeedDetailError
import com.teamwss.websoso.common.ui.model.ResultFrom.FeedDetailRemoved
import com.teamwss.websoso.common.ui.model.ResultFrom.NovelDetailBack
import com.teamwss.websoso.common.ui.model.ResultFrom.OtherUserProfileBack
Expand All @@ -49,7 +51,6 @@ import com.teamwss.websoso.databinding.MenuFeedPopupBinding
import com.teamwss.websoso.ui.createFeed.CreateFeedActivity
import com.teamwss.websoso.ui.feedDetail.FeedDetailActivity
import com.teamwss.websoso.ui.feedDetail.model.EditFeedModel
import com.teamwss.websoso.ui.main.MainActivity
import com.teamwss.websoso.ui.main.MainViewModel
import com.teamwss.websoso.ui.main.feed.adapter.FeedAdapter
import com.teamwss.websoso.ui.main.feed.adapter.FeedType.Feed
Expand All @@ -65,6 +66,8 @@ import com.teamwss.websoso.ui.novelDetail.NovelDetailActivity
import com.teamwss.websoso.ui.otherUserPage.BlockUserDialogFragment.Companion.USER_NICKNAME
import com.teamwss.websoso.ui.otherUserPage.OtherUserPageActivity
import dagger.hilt.android.AndroidEntryPoint
import kotlinx.coroutines.delay
import kotlinx.coroutines.launch
import java.io.Serializable

@AndroidEntryPoint
Expand All @@ -88,8 +91,8 @@ class FeedFragment : BaseFragment<FragmentFeedBinding>(fragment_feed) {
}

private fun onClickFeedItem() = object : FeedItemClickListener {
override fun onProfileClick(userId: Long) {
singleEventHandler.throttleFirst(300) { navigateToProfile(userId) }
override fun onProfileClick(userId: Long, isMyFeed: Boolean) {
singleEventHandler.throttleFirst(300) { navigateToProfile(userId, isMyFeed) }
}

override fun onMoreButtonClick(view: View, feedId: Long, isMyFeed: Boolean) {
Expand Down Expand Up @@ -122,23 +125,15 @@ class FeedFragment : BaseFragment<FragmentFeedBinding>(fragment_feed) {
}
}

private fun navigateToProfile(userId: Long) {
when (mainViewModel.isUserId(userId)) {
true -> {
(activity as? MainActivity)?.let { mainActivity ->
mainActivity.binding.bnvMain.selectedItemId = R.id.menu_my_page
}
}
private fun navigateToProfile(userId: Long, isMyFeed: Boolean) {
if (isMyFeed) return

false -> {
activityResultCallback.launch(
OtherUserPageActivity.getIntent(
requireContext(),
userId,
)
)
}
}
activityResultCallback.launch(
OtherUserPageActivity.getIntent(
requireContext(),
userId,
)
)
}

private fun showMenu(view: View, feedId: Long, isMyFeed: Boolean) {
Expand Down Expand Up @@ -287,6 +282,16 @@ class FeedFragment : BaseFragment<FragmentFeedBinding>(fragment_feed) {
)
}

FeedDetailError.RESULT_OK -> {
feedViewModel.updateRefreshedFeeds(false)

showWebsosoSnackBar(
view = binding.root,
message = getString(feed_server_error),
icon = ic_blocked_user_snack_bar,
)
}

BlockUser.RESULT_OK -> {
feedViewModel.updateRefreshedFeeds(false)

Expand Down Expand Up @@ -416,8 +421,13 @@ class FeedFragment : BaseFragment<FragmentFeedBinding>(fragment_feed) {
}
}
}
}.also {
if (feedUiState.isRefreshed) binding.rvFeed.smoothScrollToPosition(0)
}

if (feedUiState.isRefreshed) {
lifecycleScope.launch {
delay(300)
binding.rvFeed.smoothScrollToPosition(0)
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import android.view.View

interface FeedItemClickListener {

fun onProfileClick(userId: Long)
fun onProfileClick(userId: Long, isMyFeed: Boolean)

fun onMoreButtonClick(view: View, feedId: Long, isMyFeed: Boolean)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ import com.teamwss.websoso.ui.common.dialog.LoginRequestDialogFragment
import com.teamwss.websoso.ui.createFeed.CreateFeedActivity
import com.teamwss.websoso.ui.feedDetail.FeedDetailActivity
import com.teamwss.websoso.ui.feedDetail.model.EditFeedModel
import com.teamwss.websoso.ui.main.MainActivity
import com.teamwss.websoso.ui.main.feed.FeedItemClickListener
import com.teamwss.websoso.ui.main.feed.adapter.FeedAdapter
import com.teamwss.websoso.ui.main.feed.adapter.FeedType.Feed
Expand Down Expand Up @@ -75,25 +74,15 @@ class NovelFeedFragment : BaseFragment<FragmentNovelFeedBinding>(layout.fragment
}

private fun onClickFeedItem() = object : FeedItemClickListener {
override fun onProfileClick(userId: Long) {
when (novelFeedViewModel.isUserId(userId)) {
true ->
startActivity(
MainActivity.getIntent(
requireContext(),
MainActivity.FragmentType.MY_PAGE,
)
)

false -> {
activityResultCallback.launch(
OtherUserPageActivity.getIntent(
requireContext(),
userId,
)
)
}
}
override fun onProfileClick(userId: Long, isMyFeed: Boolean) {
if (isMyFeed) return

activityResultCallback.launch(
OtherUserPageActivity.getIntent(
requireContext(),
userId,
)
)
}

override fun onMoreButtonClick(view: View, feedId: Long, isMyFeed: Boolean) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,4 @@ class NovelFeedViewModel @Inject constructor(
}
}
}

fun isUserId(id: Long): Boolean = userId == id
}
2 changes: 1 addition & 1 deletion app/src/main/res/layout/item_feed.xml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
android:layout_height="wrap_content"
android:layout_marginStart="20dp"
android:layout_marginTop="20dp"
android:onClick="@{() -> onClick.onProfileClick(feed.user.id)}"
android:onClick="@{() -> onClick.onProfileClick(feed.user.id, feed.isMyFeed)}"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">

Expand Down
Loading