-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Activity를 Fragment로 쪼개고 하나의 뷰모델을 사용해 data를 공유하도록 함. - 누적 흔들기 3초, 최소 2개 이상 데이터 수신 시에만 TopicFragment 노출 설정 - 사용자가 천천히 흔들면 그만큼 data를 미리 받아올 수 있는 여유가 생겨서 좋고, 빠르게 흔들어도 data가 2개는 먼저 들어가있으니까 기다릴 일도 없어져서 좋음
- Loading branch information
Showing
18 changed files
with
379 additions
and
212 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 0 additions & 3 deletions
3
...src/main/java/com/teumteum/teumteum/presentation/familiar/shake/model/InterestViewData.kt
This file was deleted.
Oops, something went wrong.
120 changes: 0 additions & 120 deletions
120
app/src/main/java/com/teumteum/teumteum/presentation/familiar/topic/TopicActivity.kt
This file was deleted.
Oops, something went wrong.
79 changes: 79 additions & 0 deletions
79
app/src/main/java/com/teumteum/teumteum/presentation/shaketopic/ShakeTopicActivity.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
package com.teumteum.teumteum.presentation.shaketopic | ||
|
||
import android.os.Bundle | ||
import androidx.activity.viewModels | ||
import androidx.fragment.app.commit | ||
import com.teumteum.base.BindingActivity | ||
import com.teumteum.domain.entity.Friend | ||
import com.teumteum.teumteum.R | ||
import com.teumteum.teumteum.databinding.ActivityShakeTopicBinding | ||
import com.teumteum.teumteum.presentation.familiar.introduce.IntroduceActivity.Companion.EXTRA_FRIENDS | ||
import com.teumteum.teumteum.presentation.shaketopic.shake.ShakeFragment | ||
import com.teumteum.teumteum.presentation.shaketopic.topic.TopicFragment | ||
import dagger.hilt.android.AndroidEntryPoint | ||
import timber.log.Timber | ||
|
||
@AndroidEntryPoint | ||
class ShakeTopicActivity : | ||
BindingActivity<ActivityShakeTopicBinding>(R.layout.activity_shake_topic) { | ||
|
||
private val viewModel by viewModels<ShakeTopicViewModel>() | ||
private var isShakeCompleted = false | ||
private var isApiDataReceived = false | ||
|
||
override fun onCreate(savedInstanceState: Bundle?) { | ||
super.onCreate(savedInstanceState) | ||
|
||
initView() | ||
passDataToViewModel() | ||
setUpObserver() | ||
} | ||
|
||
private fun initView() { | ||
val initialFragment = ShakeFragment() | ||
supportFragmentManager.commit { | ||
add(R.id.fl_main, initialFragment) | ||
} | ||
} | ||
|
||
private fun setUpObserver() { | ||
viewModel.topics.observe(this) { topics -> | ||
if (topics.size >= 2 && !isApiDataReceived) { | ||
onApiDataReceived() | ||
} | ||
} | ||
} | ||
fun onShakeCompleted() { | ||
Timber.d("흔들기 3초 완료") | ||
isShakeCompleted = true | ||
checkAndShowTopicFragment() | ||
} | ||
|
||
fun onApiDataReceived() { | ||
Timber.d("데이터 최소 2개 수신 완료") | ||
isApiDataReceived = true | ||
checkAndShowTopicFragment() | ||
} | ||
|
||
private fun checkAndShowTopicFragment() { | ||
Timber.d("조건 2개 충족 완료 페이지 이동 실행") | ||
if (isShakeCompleted && isApiDataReceived) { | ||
showTopicFragment() | ||
} | ||
} | ||
|
||
private fun showTopicFragment() { | ||
val topicFragment = TopicFragment() | ||
supportFragmentManager.commit { | ||
replace(R.id.fl_main, topicFragment) | ||
addToBackStack(null) | ||
} | ||
} | ||
|
||
private fun passDataToViewModel() { | ||
val friends = intent.getSerializableExtra(EXTRA_FRIENDS) as? List<Friend> | ||
viewModel.setFriendsData(friends ?: listOf()) | ||
} | ||
|
||
companion object {} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.