-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
๐ #11 from boostcampwm-2022/feat/running_tab
๋ฌ๋ํญ ํ๋ฉด ๊ตฌํ (ํ์ฌ ๋ฌ๋ ์นด์ดํธ ๋ฐ์์ค๊ธฐ)
- Loading branch information
Showing
20 changed files
with
382 additions
and
5 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
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
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 | ||
} |
12 changes: 12 additions & 0 deletions
12
data/src/main/java/com/whyranoid/data/di/running/RunningDataSource.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,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 | ||
} |
53 changes: 53 additions & 0 deletions
53
data/src/main/java/com/whyranoid/data/di/running/RunningDataSourceImpl.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,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 | ||
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) | ||
} | ||
} | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
data/src/main/java/com/whyranoid/data/di/running/RunningModule.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,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) | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
data/src/main/java/com/whyranoid/data/running/RunningRepositoryImpl.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,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 | ||
} | ||
} |
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
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
33 changes: 33 additions & 0 deletions
33
presentation/src/main/java/com/whyranoid/presentation/runningstart/RunningStartFragment.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,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 { | ||
viewLifecycleOwner.repeatOnLifecycle(Lifecycle.State.STARTED) { | ||
viewModel.runnerCount.collect { runnerCount -> | ||
binding.tvRunnerCountNumber.text = runnerCount.toString() | ||
} | ||
} | ||
} | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
presentation/src/main/java/com/whyranoid/presentation/runningstart/RunningStartViewModel.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,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() | ||
} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Oops, something went wrong.