-
Notifications
You must be signed in to change notification settings - Fork 0
feat: BLE電波強度(RSSI)による検出フィルター機能を追加 #102
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
Merged
Merged
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
b82fdd1
feat: BLE電波強度(RSSI)による検出フィルター機能を追加
2ba4cd2
fix: FakeRepositoryModuleのimport順序をDetekt基準に修正
3346c67
feat: RssiThresholdのデフォルト値をVERY_NEARに変更
e3df5d6
feat: SettingsViewModelにRSSI閾値フィルターのUI状態と操作を追加
433449e
feat: RSSI閾値選択ダイアログを追加
6897cea
test: RssiThresholdDialogのベースラインスクリーンショットを追加
241fb9f
feat: SettingsContentにRSSI閾値フィルター設定項目を追加
73e3363
refactor: RssiThresholdDialogのdismissをScreen側に移動してOverlayPositionDial…
b6aec4d
refactor: GetAppleDevicesUseCaseのALL分岐を削除しフィルター式に一本化
c161fd0
fix: FakeRepositoryModuleのRSSI閾値デフォルト値をVERY_NEARに修正
0260016
fix: RssiThresholdRepositoryImplTestのFQDN使用をimportに置き換え
1e9c2e9
fix: RssiThresholdRepositoryImplTestのテスト名をVERY_NEARに修正
5649eb2
refactor: ラジオボタンダイアログをselectableパターンに統一
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Binary file added
BIN
+55.9 KB
app/src/test/snapshots/RssiThresholdDialogKt.RssiThresholdDialogPreview.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
+2.58 KB
(100%)
...test/snapshots/SettingsContentKt.SettingsContentPreviewBluetoothUnavailable.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
+2.71 KB
(100%)
app/src/test/snapshots/SettingsContentKt.SettingsContentPreviewNoWarning.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
+2.72 KB
(100%)
...rc/test/snapshots/SettingsContentKt.SettingsContentPreviewServiceRestarting.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
+583 Bytes
(100%)
app/src/test/snapshots/SettingsContentKt.SettingsContentPreviewThreeColumns.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains hidden or 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
40 changes: 40 additions & 0 deletions
40
core/data/src/main/java/kurou/androidpods/core/data/RssiThresholdRepositoryImpl.kt
This file contains hidden or 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,40 @@ | ||
| package kurou.androidpods.core.data | ||
|
|
||
| import android.content.Context | ||
| import androidx.datastore.core.DataStore | ||
| import androidx.datastore.preferences.core.Preferences | ||
| import androidx.datastore.preferences.core.edit | ||
| import androidx.datastore.preferences.core.emptyPreferences | ||
| import androidx.datastore.preferences.core.stringPreferencesKey | ||
| import androidx.datastore.preferences.preferencesDataStore | ||
| import kotlinx.coroutines.flow.Flow | ||
| import kotlinx.coroutines.flow.catch | ||
| import kotlinx.coroutines.flow.map | ||
| import kurou.androidpods.core.domain.RssiThreshold | ||
| import kurou.androidpods.core.domain.RssiThresholdRepository | ||
| import java.io.IOException | ||
| import javax.inject.Inject | ||
| import javax.inject.Named | ||
| import javax.inject.Singleton | ||
|
|
||
| internal val Context.rssiThresholdDataStore by preferencesDataStore(name = "rssi_threshold") | ||
|
|
||
| @Singleton | ||
| internal class RssiThresholdRepositoryImpl @Inject constructor( | ||
| @param:Named("rssi_threshold") private val dataStore: DataStore<Preferences>, | ||
| ) : RssiThresholdRepository { | ||
| private val thresholdKey = stringPreferencesKey("rssi_threshold") | ||
|
|
||
| override fun observe(): Flow<RssiThreshold> = | ||
| dataStore.data | ||
| .catch { if (it is IOException) emit(emptyPreferences()) else throw it } | ||
| .map { preferences -> | ||
| preferences[thresholdKey] | ||
| ?.let { try { RssiThreshold.valueOf(it) } catch (_: IllegalArgumentException) { null } } | ||
| ?: RssiThreshold.VERY_NEAR | ||
| } | ||
|
|
||
| override suspend fun update(threshold: RssiThreshold) { | ||
| dataStore.edit { it[thresholdKey] = threshold.name } | ||
| } | ||
| } |
91 changes: 91 additions & 0 deletions
91
core/data/src/test/java/kurou/androidpods/core/data/RssiThresholdRepositoryImplTest.kt
This file contains hidden or 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,91 @@ | ||
| package kurou.androidpods.core.data | ||
|
|
||
| import android.app.Application | ||
| import androidx.datastore.core.DataStore | ||
| import androidx.datastore.preferences.core.PreferenceDataStoreFactory | ||
| import androidx.datastore.preferences.core.Preferences | ||
| import androidx.test.core.app.ApplicationProvider | ||
| import kotlinx.coroutines.flow.Flow | ||
| import kotlinx.coroutines.flow.first | ||
| import kotlinx.coroutines.flow.flow | ||
| import kotlinx.coroutines.test.runTest | ||
| import kurou.androidpods.core.domain.RssiThreshold | ||
| import org.junit.Assert.assertEquals | ||
| import org.junit.Assert.assertNotNull | ||
| import org.junit.Assert.assertTrue | ||
| import org.junit.Before | ||
| import org.junit.Test | ||
| import org.junit.runner.RunWith | ||
| import org.robolectric.RobolectricTestRunner | ||
| import org.robolectric.annotation.Config | ||
| import java.io.File | ||
| import java.io.IOException | ||
| import java.util.UUID | ||
|
|
||
| @RunWith(RobolectricTestRunner::class) | ||
| @Config(sdk = [35]) | ||
| class RssiThresholdRepositoryImplTest { | ||
| private lateinit var repository: RssiThresholdRepositoryImpl | ||
|
|
||
| @Before | ||
| fun setUp() { | ||
| val context = ApplicationProvider.getApplicationContext<Application>() | ||
| val dataStore = PreferenceDataStoreFactory.create { | ||
| File(context.filesDir, "datastore/test_rssi_${UUID.randomUUID()}.preferences_pb") | ||
| } | ||
| repository = RssiThresholdRepositoryImpl(dataStore) | ||
| } | ||
|
|
||
| @Test | ||
| fun `デフォルト値はVERY_NEAR`() = | ||
| runTest { | ||
| val result = repository.observe().first() | ||
|
|
||
| assertEquals(RssiThreshold.VERY_NEAR, result) | ||
| } | ||
|
|
||
| @Test | ||
| fun `updateで保存した値が取得できる`() = | ||
| runTest { | ||
| repository.update(RssiThreshold.NEAR) | ||
|
|
||
| val result = repository.observe().first() | ||
|
|
||
| assertEquals(RssiThreshold.NEAR, result) | ||
| } | ||
|
|
||
| @Test | ||
| fun `IOExceptionが発生した場合はデフォルト値VERY_NEARを返す`() = | ||
| runTest { | ||
| val ioExceptionDataStore = object : DataStore<Preferences> { | ||
| override val data: Flow<Preferences> = flow { throw IOException("Test") } | ||
| override suspend fun updateData(transform: suspend (Preferences) -> Preferences): Preferences = | ||
| throw IOException("Test") | ||
| } | ||
| val repo = RssiThresholdRepositoryImpl(ioExceptionDataStore) | ||
|
|
||
| val result = repo.observe().first() | ||
|
|
||
| assertEquals(RssiThreshold.VERY_NEAR, result) | ||
| } | ||
|
|
||
| @Test | ||
| fun `IOException以外の例外は伝播する`() = | ||
| runTest { | ||
| val runtimeExceptionDataStore = object : DataStore<Preferences> { | ||
| override val data: Flow<Preferences> = flow { throw RuntimeException("Test") } | ||
| override suspend fun updateData(transform: suspend (Preferences) -> Preferences): Preferences = | ||
| throw RuntimeException("Test") | ||
| } | ||
| val repo = RssiThresholdRepositoryImpl(runtimeExceptionDataStore) | ||
|
|
||
| var thrownException: Throwable? = null | ||
| try { | ||
| repo.observe().first() | ||
| } catch (e: RuntimeException) { | ||
| thrownException = e | ||
| } | ||
| assertNotNull(thrownException) | ||
| assertTrue(thrownException is RuntimeException) | ||
| } | ||
| } |
7 changes: 6 additions & 1 deletion
7
core/domain/src/main/java/kurou/androidpods/core/domain/GetAppleDevicesUseCase.kt
This file contains hidden or 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
8 changes: 8 additions & 0 deletions
8
core/domain/src/main/java/kurou/androidpods/core/domain/RssiThreshold.kt
This file contains hidden or 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,8 @@ | ||
| package kurou.androidpods.core.domain | ||
|
|
||
| enum class RssiThreshold(val minRssi: Int) { | ||
| ALL(Int.MIN_VALUE), | ||
| MEDIUM(-75), | ||
| NEAR(-65), | ||
| VERY_NEAR(-55), | ||
| } |
9 changes: 9 additions & 0 deletions
9
core/domain/src/main/java/kurou/androidpods/core/domain/RssiThresholdRepository.kt
This file contains hidden or 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,9 @@ | ||
| package kurou.androidpods.core.domain | ||
|
|
||
| import kotlinx.coroutines.flow.Flow | ||
|
|
||
| interface RssiThresholdRepository { | ||
| fun observe(): Flow<RssiThreshold> | ||
|
|
||
| suspend fun update(threshold: RssiThreshold) | ||
| } |
12 changes: 12 additions & 0 deletions
12
core/domain/src/main/java/kurou/androidpods/core/domain/RssiThresholdUseCase.kt
This file contains hidden or 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 kurou.androidpods.core.domain | ||
|
|
||
| import kotlinx.coroutines.flow.Flow | ||
| import javax.inject.Inject | ||
|
|
||
| class RssiThresholdUseCase @Inject constructor( | ||
| private val repository: RssiThresholdRepository, | ||
| ) { | ||
| fun observe(): Flow<RssiThreshold> = repository.observe() | ||
|
|
||
| suspend fun update(threshold: RssiThreshold) = repository.update(threshold) | ||
| } |
This file contains hidden or 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 hidden or 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
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
境界値テストが不足しています。
現在のテストは「閾値より上(rssi=-60)」と「閾値より下(rssi=-80)」のみ検証しており、「閾値にぴったり等しい値(rssi=-75)」のケースがありません。フィルター条件が
>=から誤って>に変更された場合、境界値テストがなければ気づけません。CLAUDE.md の方針(「境界値の軸を意識する」)に沿って1ケース追加することを推奨します。
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.
修正済み