Skip to content

Commit

Permalink
🔀 #77 from boostcampwm-2022/feat/runningdatamanager_module
Browse files Browse the repository at this point in the history
러닝 상태를 관리하는 RunningDataManager를 모듈로 분리
  • Loading branch information
yonghanJu authored Dec 8, 2022
2 parents ee25b18 + 8b9c7df commit 71768c2
Show file tree
Hide file tree
Showing 27 changed files with 241 additions and 92 deletions.
1 change: 1 addition & 0 deletions presentation/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ android {
dependencies {

implementation project(":domain")
implementation project(":runningdata")

implementation "androidx.core:core-ktx:$coreKtxVersion"
implementation "androidx.appcompat:appcompat:$appcompatVersion"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.whyranoid.presentation.running

import com.whyranoid.runningdata.model.RunningFinishData

sealed interface Event {
data class FinishButtonClick(val runningFinishData: RunningFinishData) : Event
object RunningFinishFailure : Event
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,11 @@ import com.whyranoid.presentation.base.BaseActivity
import com.whyranoid.presentation.databinding.ActivityRunningBinding
import com.whyranoid.presentation.util.dateToString
import com.whyranoid.presentation.util.repeatWhenUiStarted
import com.whyranoid.runningdata.model.RunningData
import com.whyranoid.runningdata.model.RunningFinishData
import com.whyranoid.runningdata.model.RunningState
import dagger.hilt.android.AndroidEntryPoint
import java.util.*
import java.util.Date

@AndroidEntryPoint
internal class RunningActivity :
Expand Down Expand Up @@ -72,7 +75,7 @@ internal class RunningActivity :
}

observeStateOnMapReady()
naverMap.addOnCameraChangeListener { reason, animated ->
naverMap.addOnCameraChangeListener { reason, _ ->
if (reason == CameraUpdate.REASON_GESTURE) {
viewModel.onTrackingCanceledByGesture()
}
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package com.whyranoid.presentation.running

import com.naver.maps.geometry.LatLng
import com.whyranoid.domain.model.RunningHistory
import com.whyranoid.presentation.model.RunningHistoryUiModel
import com.whyranoid.runningdata.model.RunningHistoryModel
import com.whyranoid.runningdata.model.RunningPosition

fun RunningPosition.toLatLng(): LatLng {
return LatLng(
this.latitude,
this.longitude
)
}

fun RunningHistoryModel.toRunningHistoryUiModel() =
RunningHistoryUiModel(
historyId = historyId,
date = startedAt,
startedAt = startedAt,
finishedAt = finishedAt,
totalRunningTime = totalRunningTime,
pace = pace,
totalDistance = totalDistance
)

fun RunningHistoryModel.toRunningHistory() =
RunningHistory(
historyId = historyId,
startedAt = startedAt,
finishedAt = finishedAt,
totalRunningTime = totalRunningTime,
pace = pace,
totalDistance = totalDistance
)
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ import androidx.work.WorkInfo
import androidx.work.WorkManager
import com.whyranoid.domain.usecase.FinishRunningUseCase
import com.whyranoid.domain.usecase.StartRunningUseCase
import com.whyranoid.presentation.model.toRunningHistory
import com.whyranoid.runningdata.RunningDataManager
import com.whyranoid.runningdata.model.RunningState
import dagger.hilt.android.lifecycle.HiltViewModel
import dagger.hilt.android.qualifiers.ApplicationContext
import kotlinx.coroutines.flow.MutableSharedFlow
Expand All @@ -26,10 +27,10 @@ import javax.inject.Inject
class RunningViewModel @Inject constructor(
@ApplicationContext context: Context,
startRunningUseCase: StartRunningUseCase,
private val finishRunningUseCase: FinishRunningUseCase,
private val runningDataManager: RunningDataManager
private val finishRunningUseCase: FinishRunningUseCase
) : ViewModel() {

private val runningDataManager = RunningDataManager.getInstance()
val runningState = runningDataManager.runningState

private val _trackingModeState = MutableStateFlow(TrackingMode.FOLLOW)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,20 @@ import com.google.android.gms.location.LocationServices
import com.google.android.gms.location.Priority
import com.whyranoid.presentation.MainActivity
import com.whyranoid.presentation.R
import com.whyranoid.runningdata.RunningDataManager
import com.whyranoid.runningdata.model.RunningState
import dagger.assisted.Assisted
import dagger.assisted.AssistedInject
import kotlinx.coroutines.delay

@HiltWorker
class RunningWorker @AssistedInject constructor(
@Assisted private val context: Context,
@Assisted params: WorkerParameters,
private val runningDataManager: RunningDataManager
@Assisted params: WorkerParameters
) : CoroutineWorker(context, params) {

private val runningDataManager = RunningDataManager.getInstance()

private val fusedLocationClient = LocationServices.getFusedLocationProviderClient(context)
private val locationRequest =
LocationRequest.Builder(Priority.PRIORITY_HIGH_ACCURACY, UPDATE_INTERVAL_MS).build()
Expand All @@ -59,7 +62,6 @@ class RunningWorker @AssistedInject constructor(
}

private fun createForegroundInfo(progress: String): ForegroundInfo {
val id = context.getString(R.string.running_notification_id)
val title = context.getString(R.string.running_notification_title)

val intent = Intent(context, MainActivity::class.java)
Expand All @@ -70,7 +72,7 @@ class RunningWorker @AssistedInject constructor(
createChannel()
}

val notification = NotificationCompat.Builder(applicationContext, id)
val notification = NotificationCompat.Builder(applicationContext, CHANNEL_ID)
.setContentTitle(title)
.setTicker(title)
.setContentText(progress)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,12 @@ import com.whyranoid.presentation.base.BaseFragment
import com.whyranoid.presentation.databinding.FragmentRunningFinishBinding
import com.whyranoid.presentation.model.RunningHistoryUiModel
import com.whyranoid.presentation.model.UiState
import com.whyranoid.presentation.running.RunningFinishData
import com.whyranoid.presentation.running.RunningPosition
import com.whyranoid.presentation.running.toLatLng
import com.whyranoid.presentation.util.pxdp.PxDpUtil
import com.whyranoid.presentation.running.toRunningHistoryUiModel
import com.whyranoid.presentation.util.converters.UnitConverters
import com.whyranoid.presentation.util.repeatWhenUiStarted
import com.whyranoid.runningdata.model.RunningFinishData
import com.whyranoid.runningdata.model.RunningPosition
import dagger.hilt.android.AndroidEntryPoint
import timber.log.Timber

Expand Down Expand Up @@ -72,7 +73,8 @@ internal class RunningFinishFragment :
}

private fun handleDataStateSuccess(runningFinishData: RunningFinishData) {
binding.runningHistoryItem.runningHistory = runningFinishData.runningHistory
binding.runningHistoryItem.runningHistory =
runningFinishData.runningHistory.toRunningHistoryUiModel()

moveCamera(runningFinishData)
updatePathsOverlay(runningFinishData.runningPositionList)
Expand All @@ -95,9 +97,10 @@ internal class RunningFinishFragment :
}

private fun handlePositiveButtonClicked(runningHistory: RunningHistoryUiModel) {
val direction = RunningFinishFragmentDirections.actionRunningFinishFragmentToCreateRunningPostFragment(
runningHistory
)
val direction =
RunningFinishFragmentDirections.actionRunningFinishFragmentToCreateRunningPostFragment(
runningHistory
)
findNavController().navigate(direction)
}

Expand All @@ -118,7 +121,7 @@ internal class RunningFinishFragment :
position.toLatLng()
}
).build(),
PxDpUtil.pxToDp(requireContext(), 200)
UnitConverters.pxToDp(requireContext(), 200)
)
it.moveCamera(cameraUpdate)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@ import androidx.lifecycle.viewModelScope
import com.whyranoid.domain.model.MoGakRunException
import com.whyranoid.domain.usecase.SaveRunningHistoryUseCase
import com.whyranoid.presentation.model.UiState
import com.whyranoid.presentation.running.RunningFinishData
import com.whyranoid.presentation.running.RunningViewModel.Companion.RUNNING_FINISH_DATA_KEY
import com.whyranoid.presentation.running.toRunningHistoryUiModel
import com.whyranoid.runningdata.model.RunningFinishData
import dagger.hilt.android.lifecycle.HiltViewModel
import kotlinx.coroutines.flow.MutableSharedFlow
import kotlinx.coroutines.flow.MutableStateFlow
Expand Down Expand Up @@ -58,7 +59,7 @@ class RunningFinishViewModel @Inject constructor(

fun onPositiveButtonClicked() {
(runningFinishDataState.value as? UiState.Success<RunningFinishData>)?.value?.let { runningFinishData ->
emitEvent(Event.PositiveButtonClick(runningFinishData.runningHistory))
emitEvent(Event.PositiveButtonClick(runningFinishData.runningHistory.toRunningHistoryUiModel()))
} ?: kotlin.run {
_runningFinishDataState.value = UiState.Failure(
MoGakRunException.FileNotFoundedException
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@ import com.whyranoid.presentation.R
import com.whyranoid.presentation.base.BaseFragment
import com.whyranoid.presentation.databinding.FragmentRunningStartBinding
import com.whyranoid.presentation.running.RunningActivity
import com.whyranoid.presentation.running.RunningFinishData
import com.whyranoid.presentation.running.RunningState
import com.whyranoid.presentation.running.RunningViewModel.Companion.RUNNING_FINISH_DATA_KEY
import com.whyranoid.presentation.util.getSerializableData
import com.whyranoid.presentation.util.gpsstate.GPSState
import com.whyranoid.presentation.util.repeatWhenUiStarted
import com.whyranoid.runningdata.model.RunningFinishData
import com.whyranoid.runningdata.model.RunningState
import dagger.hilt.android.AndroidEntryPoint

@AndroidEntryPoint
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ package com.whyranoid.presentation.runningstart
import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import com.whyranoid.domain.usecase.GetRunnerCountUseCase
import com.whyranoid.presentation.running.RunningDataManager
import com.whyranoid.presentation.util.networkconnection.NetworkConnectionStateHolder
import com.whyranoid.runningdata.RunningDataManager
import dagger.hilt.android.lifecycle.HiltViewModel
import kotlinx.coroutines.flow.MutableSharedFlow
import kotlinx.coroutines.flow.asSharedFlow
Expand All @@ -14,10 +14,11 @@ import javax.inject.Inject
@HiltViewModel
class RunningStartViewModel @Inject constructor(
getRunnerCountUseCase: GetRunnerCountUseCase,
networkConnectionStateHolder: NetworkConnectionStateHolder,
val runningDataManager: RunningDataManager
networkConnectionStateHolder: NetworkConnectionStateHolder
) : ViewModel() {

val runningDataManager = RunningDataManager.getInstance()

val networkState = networkConnectionStateHolder.networkState

val runnerCount = getRunnerCountUseCase()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package com.whyranoid.presentation.util.pxdp
package com.whyranoid.presentation.util.converters

import android.content.Context

object PxDpUtil {
object UnitConverters {
fun dpToPx(context: Context, dp: Int): Int {
val scale: Float = context.resources.displayMetrics.density
return (dp * scale + 0.5f).toInt()
Expand Down
2 changes: 1 addition & 1 deletion presentation/src/main/res/layout/activity_running.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

<data>

<import type="com.whyranoid.presentation.running.RunningState" />
<import type="com.whyranoid.runningdata.model.RunningState" />

<import type="android.view.View" />

Expand Down
2 changes: 1 addition & 1 deletion presentation/src/main/res/navigation/navigation_graph.xml
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@
android:name="com.whyranoid.presentation.runningfinish.RunningFinishFragment">
<argument
android:name="runningFinishData"
app:argType="com.whyranoid.presentation.running.RunningFinishData"
app:argType="com.whyranoid.runningdata.model.RunningFinishData"
app:nullable="true" />
<action
android:id="@+id/action_runningFinishFragment_to_createRunningPostFragment"
Expand Down
1 change: 1 addition & 0 deletions runningdata/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/build
41 changes: 41 additions & 0 deletions runningdata/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
plugins {
id "com.android.library"
id "org.jetbrains.kotlin.android"
}

android {
namespace "com.whyranoid.runningdata"
compileSdk 33

defaultConfig {
minSdk 23
targetSdk 33

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
consumerProguardFiles "consumer-rules.pro"
}

buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile("proguard-android-optimize.txt"), "proguard-rules.pro"
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
kotlinOptions {
jvmTarget = "1.8"
}
}

dependencies {

implementation "androidx.core:core-ktx:$coreKtxVersion"
implementation "androidx.appcompat:appcompat:$appcompatVersion"
implementation "com.google.android.material:material:$materialVersion"
testImplementation "junit:junit:$junitVersion"
androidTestImplementation "androidx.test.ext:junit:$junitUiVersion"
androidTestImplementation "androidx.test.espresso:espresso-core:$espressoCoreVersion"
}
Empty file added runningdata/consumer-rules.pro
Empty file.
21 changes: 21 additions & 0 deletions runningdata/proguard-rules.pro
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Add project specific ProGuard rules here.
# You can control the set of applied configuration files using the
# proguardFiles setting in build.gradle.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html

# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
#}

# Uncomment this to preserve the line number information for
# debugging stack traces.
#-keepattributes SourceFile,LineNumberTable

# If you keep the line number information, uncomment this to
# hide the original source file name.
#-renamesourcefileattribute SourceFile
4 changes: 4 additions & 0 deletions runningdata/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android">

</manifest>
Loading

0 comments on commit 71768c2

Please sign in to comment.