-
Notifications
You must be signed in to change notification settings - Fork 5
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
러닝탭 화면 구현 (현재 러너 카운트 받아오기) #11
Changes from all commits
ea4ac65
a1bd129
eb68274
ebd502b
3f011ba
ff99215
22c5806
92a1b61
5b1e687
5811202
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package com.whyranoid.data.di | ||
|
||
import com.google.firebase.firestore.FirebaseFirestore | ||
import com.google.firebase.firestore.ktx.firestore | ||
import com.google.firebase.ktx.Firebase | ||
import dagger.Module | ||
import dagger.Provides | ||
import dagger.hilt.InstallIn | ||
import dagger.hilt.components.SingletonComponent | ||
import javax.inject.Singleton | ||
|
||
@Module | ||
@InstallIn(SingletonComponent::class) | ||
class NetworkModule { | ||
|
||
@Provides | ||
@Singleton | ||
fun provideFireStoreDatabase(): FirebaseFirestore = | ||
Firebase.firestore | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package com.whyranoid.data.di.running | ||
|
||
import kotlinx.coroutines.flow.Flow | ||
|
||
interface RunningDataSource { | ||
|
||
fun getCurrentRunnerCount(): Flow<Int> | ||
|
||
suspend fun startRunning(uid: String): Boolean | ||
|
||
suspend fun finishRunning(uid: String): Boolean | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package com.whyranoid.data.di.running | ||
|
||
import com.google.firebase.firestore.FieldValue | ||
import com.google.firebase.firestore.FirebaseFirestore | ||
import kotlinx.coroutines.channels.awaitClose | ||
import kotlinx.coroutines.flow.Flow | ||
import kotlinx.coroutines.flow.callbackFlow | ||
import kotlin.coroutines.resume | ||
import kotlin.coroutines.suspendCoroutine | ||
|
||
class RunningDataSourceImpl(private val db: FirebaseFirestore) : RunningDataSource { | ||
|
||
override fun getCurrentRunnerCount(): Flow<Int> = callbackFlow { | ||
db.collection("Runners") | ||
.document("runnersId") | ||
.addSnapshotListener { snapshot, _ -> | ||
snapshot?.let { | ||
val count = it.data?.size ?: -1 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 달리는 사람이 없을 때 -1이라는 값을 플로우로 방출하는 것 같은데 이에 대한 처리가 보이지 않는 것 같습니다! (제가 못 찾는 것일 수도 있지만요..^^) -> 달리고 있는 사람이 -1일 수는 없으니까요! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
trySend(count) | ||
} | ||
} | ||
|
||
awaitClose() | ||
} | ||
|
||
override suspend fun startRunning(uid: String): Boolean { | ||
return suspendCoroutine { continuation -> | ||
db.collection("Runners") | ||
.document("runnersId") | ||
.update(uid, uid) | ||
.addOnSuccessListener { | ||
continuation.resume(true) | ||
} | ||
.addOnFailureListener { | ||
continuation.resume(false) | ||
} | ||
} | ||
} | ||
|
||
override suspend fun finishRunning(uid: String): Boolean { | ||
return suspendCoroutine { continuation -> | ||
db.collection("Runners") | ||
.document("runnersId") | ||
.update(uid, FieldValue.delete()) | ||
.addOnSuccessListener { | ||
continuation.resume(true) | ||
} | ||
.addOnFailureListener { | ||
continuation.resume(false) | ||
} | ||
} | ||
} | ||
Comment on lines
+11
to
+52
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 하드 코딩된 "Runners", "runnersId", -1 등을 변수로 관리하면 가독성이 더 좋을 것 같아요! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package com.whyranoid.data.di.running | ||
|
||
import com.google.firebase.firestore.FirebaseFirestore | ||
import com.whyranoid.data.running.RunningRepositoryImpl | ||
import com.whyranoid.domain.repository.RunningRepository | ||
import dagger.Module | ||
import dagger.Provides | ||
import dagger.hilt.InstallIn | ||
import dagger.hilt.components.SingletonComponent | ||
import javax.inject.Singleton | ||
|
||
@Module | ||
@InstallIn(SingletonComponent::class) | ||
class RunningModule { | ||
|
||
@Provides | ||
@Singleton | ||
fun provideRunningDataSource(db: FirebaseFirestore): RunningDataSource { | ||
return RunningDataSourceImpl(db) | ||
} | ||
|
||
@Provides | ||
@Singleton | ||
fun provideRunningRepository(runningDataSource: RunningDataSource): RunningRepository { | ||
return RunningRepositoryImpl(runningDataSource) | ||
} | ||
Comment on lines
+22
to
+26
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 저희 이번에 인터페이스주입도 그냥 Binds 대신 Provides 사용하기로 했었나요?? 기억이 잘 안나서요! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 확정하지는 않았던거 같은데 오늘 리뷰때 이야기 해보면 좋을거 같아요! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. #13 : Provides 대신 Binds 사용하기로 결정 |
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package com.whyranoid.data.running | ||
|
||
import com.whyranoid.data.di.running.RunningDataSource | ||
import com.whyranoid.domain.repository.RunningRepository | ||
import kotlinx.coroutines.flow.Flow | ||
|
||
class RunningRepositoryImpl(private val runningDataSource: RunningDataSource) : RunningRepository { | ||
override fun getCurrentRunnerCount(): Flow<Int> { | ||
return runningDataSource.getCurrentRunnerCount() | ||
} | ||
|
||
override suspend fun startRunning(uid: String): Boolean { | ||
return true | ||
} | ||
|
||
override suspend fun finishRunning(uid: String): Boolean { | ||
return true | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package com.whyranoid.presentation.runningstart | ||
|
||
import android.os.Bundle | ||
import android.view.View | ||
import androidx.fragment.app.viewModels | ||
import androidx.lifecycle.Lifecycle | ||
import androidx.lifecycle.lifecycleScope | ||
import androidx.lifecycle.repeatOnLifecycle | ||
import com.whyranoid.presentation.R | ||
import com.whyranoid.presentation.base.BaseFragment | ||
import com.whyranoid.presentation.databinding.FragmentRunningStartBinding | ||
import dagger.hilt.android.AndroidEntryPoint | ||
import kotlinx.coroutines.launch | ||
|
||
@AndroidEntryPoint | ||
internal class RunningStartFragment : | ||
BaseFragment<FragmentRunningStartBinding>(R.layout.fragment_running_start) { | ||
|
||
private val viewModel by viewModels<RunningStartViewModel>() | ||
|
||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) { | ||
super.onViewCreated(view, savedInstanceState) | ||
binding.vm = viewModel | ||
|
||
lifecycleScope.launch { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. flow를 collect하는 최상위 스코프는 fragment의 lifecycleScope네요..!! (물론 내부에서 viewLifecycleOwner에서 collect를 하는 범위를 컨트롤 해주시긴하지만) 저는 최상위 스코프도 viewLifecycleOwner.lifecycleScope로 두고 사용했거든요! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. #13 : 달리는 사람 수 라이프사이클 변경 |
||
viewLifecycleOwner.repeatOnLifecycle(Lifecycle.State.STARTED) { | ||
viewModel.runnerCount.collect { runnerCount -> | ||
binding.tvRunnerCountNumber.text = runnerCount.toString() | ||
} | ||
} | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package com.whyranoid.presentation.runningstart | ||
|
||
import androidx.lifecycle.ViewModel | ||
import com.whyranoid.domain.usecase.GetRunnerCountUseCase | ||
import dagger.hilt.android.lifecycle.HiltViewModel | ||
import javax.inject.Inject | ||
|
||
@HiltViewModel | ||
class RunningStartViewModel @Inject constructor( | ||
getRunnerCountUseCase: GetRunnerCountUseCase | ||
) : ViewModel() { | ||
|
||
val runnerCount = getRunnerCountUseCase() | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
저는 error를 사용하지 않음에도 불구하고 error로 표기해놔서 승민님께 리뷰를 받았는데 _ 로 안쓰는 변수임을 잘 표현해주셨네요..!! error가 어떠한 상황에 발생하는 값인지 확인하고 예외처리가 필요하다면 예외처리해주고 그렇지 않다면 _ 로 사용하지 않음을 명시해주는 것이 좋아보이네요!! 나중에 같이 논의해보면 좋을 것 같습니다