Skip to content

Commit e09f8fb

Browse files
authored
Merge pull request #300 from ptkNktq/refactor/test_and_coroutines
Refactor/test and coroutines
2 parents 36c2307 + 31cbb9e commit e09f8fb

12 files changed

Lines changed: 166 additions & 107 deletions

File tree

AndroidApp/.idea/inspectionProfiles/Project_Default.xml

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

AndroidApp/data/repository/src/main/kotlin/me/nya_n/notificationnotifier/data/repository/impl/AppRepositoryImpl.kt

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package me.nya_n.notificationnotifier.data.repository.impl
22

33
import android.content.pm.PackageManager
4+
import kotlinx.coroutines.CoroutineDispatcher
45
import kotlinx.coroutines.Dispatchers
56
import kotlinx.coroutines.withContext
67
import me.nya_n.notificationnotifier.data.repository.AppRepository
@@ -12,16 +13,17 @@ import me.nya_n.notificationnotifier.model.InstalledApp
1213
class AppRepositoryImpl(
1314
private val filterConditionDao: FilterConditionDao,
1415
private val targetAppDao: TargetAppDao,
16+
private val coroutineDispatcher: CoroutineDispatcher = Dispatchers.IO
1517
) : AppRepository {
1618
override suspend fun clearAll() {
17-
withContext(Dispatchers.IO) {
19+
withContext(coroutineDispatcher) {
1820
filterConditionDao.clear()
1921
targetAppDao.clear()
2022
}
2123
}
2224

2325
override suspend fun getFilterCondition(targetPackageName: String): FilterCondition? {
24-
return withContext(Dispatchers.IO) {
26+
return withContext(coroutineDispatcher) {
2527
filterConditionDao.get(targetPackageName)
2628
}
2729
}
@@ -31,31 +33,31 @@ class AppRepositoryImpl(
3133
}
3234

3335
override suspend fun getFilterConditionList(): List<FilterCondition> {
34-
return withContext(Dispatchers.IO) {
36+
return withContext(coroutineDispatcher) {
3537
filterConditionDao.getAll()
3638
}
3739
}
3840

3941
override suspend fun saveFilterCondition(condition: FilterCondition) {
40-
withContext(Dispatchers.IO) {
42+
withContext(coroutineDispatcher) {
4143
filterConditionDao.insert(condition)
4244
}
4345
}
4446

4547
override suspend fun getTargetAppList(): List<InstalledApp> {
46-
return withContext(Dispatchers.IO) {
48+
return withContext(coroutineDispatcher) {
4749
targetAppDao.getAll()
4850
}
4951
}
5052

5153
override suspend fun addTargetApp(target: InstalledApp) {
52-
withContext(Dispatchers.IO) {
54+
withContext(coroutineDispatcher) {
5355
targetAppDao.insert(target)
5456
}
5557
}
5658

5759
override suspend fun deleteTargetApp(target: InstalledApp) {
58-
withContext(Dispatchers.IO) {
60+
withContext(coroutineDispatcher) {
5961
targetAppDao.delete(target)
6062
}
6163
}

AndroidApp/domain/build.gradle.kts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,11 @@ dependencies {
2121
api(libs.androidx.compose.runtime)
2222

2323
// test
24-
implementation(libs.junit)
25-
implementation(libs.com.google.truth)
26-
implementation(libs.androidx.test.ext.junit)
27-
implementation(libs.androidx.test.espresso.core)
24+
androidTestImplementation(libs.junit)
25+
androidTestImplementation(libs.com.google.truth)
26+
androidTestImplementation(libs.androidx.test.ext.junit)
27+
androidTestImplementation(libs.androidx.test.espresso.core)
28+
androidTestImplementation(libs.kotlinx.coroutines.test)
2829

2930
// その他
3031
implementation(libs.com.google.code.gson)
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
package me.nya_n.notificationnotifier
2+
3+
@Target(AnnotationTarget.FUNCTION)
4+
@Retention(AnnotationRetention.RUNTIME)
5+
annotation class LocalOnly

0 commit comments

Comments
 (0)