Skip to content

Commit

Permalink
fix(FeedDetailActivity): 처음으로 데이터를 가져왔는지에 대한 정보는 뷰모델이 가지고 있도록 하여 구성 변…
Browse files Browse the repository at this point in the history
…경에 대응할 수 있도록 변경
  • Loading branch information
ki960213 committed Nov 1, 2023
1 parent 0f9f24a commit 41853fe
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ import com.emmsale.presentation.ui.feedDetail.recyclerView.FeedDetailAdapter
import com.emmsale.presentation.ui.feedDetail.uiState.FeedDetailUiEvent
import com.emmsale.presentation.ui.profile.ProfileActivity
import dagger.hilt.android.AndroidEntryPoint
import kotlin.properties.Delegates

@AndroidEntryPoint
class FeedDetailActivity : AppCompatActivity() {
Expand All @@ -37,10 +36,6 @@ class FeedDetailActivity : AppCompatActivity() {
intent.getLongExtra(KEY_HIGHLIGHT_COMMENT_ID, INVALID_COMMENT_ID)
}

private var justEntered: Boolean by Delegates.vetoable(true) { _, oldValue, newValue ->
oldValue && !newValue
}

private val inputMethodManager: InputMethodManager by lazy {
getSystemService(INPUT_METHOD_SERVICE) as InputMethodManager
}
Expand All @@ -61,22 +56,21 @@ class FeedDetailActivity : AppCompatActivity() {
).apply {
registerAdapterDataObserver(object : RecyclerView.AdapterDataObserver() {
override fun onItemRangeInserted(positionStart: Int, itemCount: Int) {
if (highlightCommentId == INVALID_COMMENT_ID || !justEntered || itemCount == 0) return
if (highlightCommentId == INVALID_COMMENT_ID || viewModel.isAlreadyFirstFetched || itemCount == 0) return
val position = viewModel.feedDetail.value.comments
.indexOfFirst { it.comment.id == highlightCommentId } + FEED_DETAIL_COUNT
binding.rvFeeddetailFeedAndComments.scrollToPosition(position)

viewModel.highlightComment(highlightCommentId)

justEntered = false
viewModel.isAlreadyFirstFetched = true
}
})
}

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(binding.root)
if (savedInstanceState != null) justEntered = false

setUpDataBinding()
setUpToolbar()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import com.emmsale.presentation.ui.feedDetail.uiState.FeedDetailUiState
import dagger.hilt.android.lifecycle.HiltViewModel
import kotlinx.coroutines.launch
import javax.inject.Inject
import kotlin.properties.Delegates

@HiltViewModel
class FeedDetailViewModel @Inject constructor(
Expand All @@ -33,6 +34,10 @@ class FeedDetailViewModel @Inject constructor(
private val commentRepository: CommentRepository,
private val tokenRepository: TokenRepository,
) : ViewModel(), Refreshable {
var isAlreadyFirstFetched: Boolean by Delegates.vetoable(false) { _, _, newValue ->
newValue
}

val feedId = savedStateHandle[KEY_FEED_ID] ?: DEFAULT_FEED_ID

private val uid: Long by lazy { tokenRepository.getMyUid()!! }
Expand Down

0 comments on commit 41853fe

Please sign in to comment.