Skip to content

Commit d2e62d2

Browse files
authored
Merge branch 'develop' into modify/codereview
2 parents cb043de + e60893b commit d2e62d2

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+1274
-308
lines changed

โ€Ždata/build.gradle

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,12 @@ dependencies {
7373
implementation 'com.tickaroo.tikxml:core:0.8.13'
7474
implementation 'com.tickaroo.tikxml:retrofit-converter:0.8.13'
7575
kapt 'com.tickaroo.tikxml:processor:0.8.13'
76+
77+
// Room
78+
implementation "androidx.room:room-runtime:2.4.3"
79+
annotationProcessor "androidx.room:room-compiler:2.4.3"
80+
kapt "androidx.room:room-compiler:2.4.3"
81+
implementation "androidx.room:room-ktx:2.4.3"
7682
}
7783

7884
kapt {

โ€Ždata/src/main/java/com/stop/data/di/DataSourceModule.kt

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package com.stop.data.di
22

3+
import com.stop.data.local.source.alarm.AlarmLocalDataSource
4+
import com.stop.data.local.source.alarm.AlarmLocalDataSourceImpl
35
import com.stop.data.remote.source.nearplace.NearPlaceRemoteDataSource
46
import com.stop.data.remote.source.nearplace.NearPlaceRemoteDataSourceImpl
57
import com.stop.data.remote.source.route.RouteRemoteDataSource
@@ -14,6 +16,12 @@ import javax.inject.Singleton
1416
@Module
1517
internal interface DataSourceModule {
1618

19+
@Binds
20+
@Singleton
21+
fun provideNearPlaceRemoteDataSource(
22+
nearPlaceRemoteDataSourceImpl: NearPlaceRemoteDataSourceImpl
23+
): NearPlaceRemoteDataSource
24+
1725
@Binds
1826
@Singleton
1927
fun provideRouteRemoteDataSource(
@@ -22,8 +30,8 @@ internal interface DataSourceModule {
2230

2331
@Binds
2432
@Singleton
25-
fun provideNearPlaceDataSource(
26-
nearPlaceRemoteDataSourceImpl: NearPlaceRemoteDataSourceImpl
27-
) : NearPlaceRemoteDataSource
28-
33+
fun provideAlarmLocalDataSource(
34+
alarmLocalDataSourceImpl: AlarmLocalDataSourceImpl
35+
): AlarmLocalDataSourc
36+
2937
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
package com.stop.data.di
2+
3+
import android.content.Context
4+
import androidx.room.Room
5+
import com.stop.data.local.database.dao.AlarmDao
6+
import com.stop.data.local.database.dao.TroubleShooterApplicationDatabase
7+
import com.stop.data.local.database.dao.TroubleShooterApplicationDatabase.Companion.DB_NAME
8+
import dagger.Module
9+
import dagger.Provides
10+
import dagger.hilt.InstallIn
11+
import dagger.hilt.android.qualifiers.ApplicationContext
12+
import dagger.hilt.components.SingletonComponent
13+
import javax.inject.Singleton
14+
15+
@InstallIn(SingletonComponent::class)
16+
@Module
17+
class DatabaseModule {
18+
19+
@Provides
20+
@Singleton
21+
fun provideApplicationDatabase(@ApplicationContext context: Context): TroubleShooterApplicationDatabase {
22+
return Room.databaseBuilder(
23+
context,
24+
TroubleShooterApplicationDatabase::class.java,
25+
DB_NAME
26+
).fallbackToDestructiveMigration()
27+
.build()
28+
}
29+
30+
@Provides
31+
@Singleton
32+
fun provideAlarmDao(troubleShooterApplicationDatabase: TroubleShooterApplicationDatabase): AlarmDao {
33+
return troubleShooterApplicationDatabase.getAlarmDao()
34+
}
35+
}

โ€Ždata/src/main/java/com/stop/data/di/RepositoryModule.kt

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
package com.stop.data.di
22

3-
import com.stop.data.repository.RouteRepositoryImpl
4-
import com.stop.domain.repository.RouteRepository
3+
import com.stop.data.repository.AlarmRepositoryImpl
54
import com.stop.data.repository.NearPlaceRepositoryImpl
5+
import com.stop.data.repository.RouteRepositoryImpl
6+
import com.stop.domain.repository.AlarmRepository
67
import com.stop.domain.repository.NearPlaceRepository
8+
import com.stop.domain.repository.RouteRepository
79
import dagger.Binds
810
import dagger.Module
911
import dagger.hilt.InstallIn
@@ -26,4 +28,9 @@ internal interface RepositoryModule {
2628
nearPlaceRepositoryImpl: NearPlaceRepositoryImpl
2729
): NearPlaceRepository
2830

31+
32+
@Binds
33+
@Singleton
34+
fun provideAlarmRepository(alarmRepositoryImpl: AlarmRepositoryImpl): AlarmRepository
35+
2936
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package com.stop.data.local.database.dao
2+
3+
import androidx.room.Dao
4+
import androidx.room.Insert
5+
import androidx.room.OnConflictStrategy
6+
import androidx.room.Query
7+
import com.stop.data.local.entity.AlarmEntity
8+
import kotlinx.coroutines.flow.Flow
9+
10+
@Dao
11+
interface AlarmDao {
12+
13+
@Insert(onConflict = OnConflictStrategy.REPLACE)
14+
fun insertAlarm(alarmEntity: AlarmEntity)
15+
16+
@Query("DELETE FROM AlarmEntity")
17+
fun deleteAlarm()
18+
19+
@Query("SELECT * FROM AlarmEntity")
20+
fun selectAlarm(): Flow<AlarmEntity>
21+
22+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package com.stop.data.local.database.dao
2+
3+
import androidx.room.Database
4+
import androidx.room.RoomDatabase
5+
import com.stop.data.local.entity.AlarmEntity
6+
7+
@Database(
8+
entities = [AlarmEntity::class],
9+
version = 1
10+
)
11+
abstract class TroubleShooterApplicationDatabase : RoomDatabase() {
12+
13+
abstract fun getAlarmDao(): AlarmDao
14+
15+
companion object {
16+
const val DB_NAME = "TroubleShooter.db"
17+
}
18+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package com.stop.data.local.entity
2+
3+
import androidx.room.Entity
4+
import androidx.room.PrimaryKey
5+
import com.stop.data.model.alarm.AlarmRepositoryItem
6+
7+
@Entity
8+
data class AlarmEntity(
9+
@PrimaryKey
10+
val id: Long,
11+
val routeInfo: String,
12+
val transportInfo: String,
13+
val lastTime: String,
14+
val alarmTime: String,
15+
val walkTime: String,
16+
val alarmMethod: Boolean, // ์†Œ๋ฆฌ : true, ์ง„๋™ : false
17+
val isMission: Boolean
18+
) {
19+
20+
fun toRepositoryModel() = AlarmRepositoryItem(
21+
routeInfo,
22+
transportInfo,
23+
lastTime,
24+
alarmTime,
25+
walkTime,
26+
alarmMethod,
27+
isMission
28+
)
29+
30+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package com.stop.data.local.source.alarm
2+
3+
import com.stop.data.model.alarm.AlarmRepositoryItem
4+
import kotlinx.coroutines.flow.Flow
5+
6+
interface AlarmLocalDataSource {
7+
8+
fun insertAlarm(alarmRepositoryItem: AlarmRepositoryItem)
9+
10+
fun deleteAlarm()
11+
12+
fun selectAlarm(): Flow<AlarmRepositoryItem>
13+
14+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package com.stop.data.local.source.alarm
2+
3+
import com.stop.data.local.database.dao.AlarmDao
4+
import com.stop.data.model.alarm.AlarmRepositoryItem
5+
import kotlinx.coroutines.flow.Flow
6+
import kotlinx.coroutines.flow.map
7+
import javax.inject.Inject
8+
9+
internal class AlarmLocalDataSourceImpl @Inject constructor(
10+
private val alarmDao: AlarmDao
11+
) : AlarmLocalDataSource {
12+
13+
override fun insertAlarm(alarmRepositoryItem: AlarmRepositoryItem) {
14+
alarmDao.insertAlarm(alarmRepositoryItem.toEntity())
15+
}
16+
17+
override fun deleteAlarm() {
18+
alarmDao.deleteAlarm()
19+
}
20+
21+
override fun selectAlarm(): Flow<AlarmRepositoryItem> {
22+
return alarmDao.selectAlarm().map { it.toRepositoryModel() }
23+
}
24+
25+
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
package com.stop.data.model.alarm
2+
3+
import com.stop.data.local.entity.AlarmEntity
4+
import com.stop.domain.model.alarm.AlarmUseCaseItem
5+
6+
data class AlarmRepositoryItem(
7+
val routeInfo: String,
8+
val transportInfo: String,
9+
val lastTime: String,
10+
val alarmTime: String,
11+
val walkTime: String,
12+
val alarmMethod: Boolean, // ์†Œ๋ฆฌ : true, ์ง„๋™ : false
13+
val isMission: Boolean
14+
) {
15+
16+
fun toUseCaseModel() = AlarmUseCaseItem(
17+
routeInfo,
18+
transportInfo,
19+
lastTime,
20+
alarmTime,
21+
walkTime,
22+
alarmMethod,
23+
isMission
24+
)
25+
26+
fun toEntity() = AlarmEntity(
27+
DEFAULT_ID,
28+
routeInfo,
29+
transportInfo,
30+
lastTime,
31+
alarmTime,
32+
walkTime,
33+
alarmMethod,
34+
isMission
35+
)
36+
37+
companion object {
38+
private const val DEFAULT_ID = 1L
39+
}
40+
41+
}

0 commit comments

Comments
ย (0)