From 0bb32b893b02b4fc2a0d5d731643938f096d901b Mon Sep 17 00:00:00 2001 From: Sangho Kim Date: Wed, 28 Aug 2024 22:41:43 +0900 Subject: [PATCH 1/5] =?UTF-8?q?[FIX/#51]=20wearable=20manager=20=EB=84=A4?= =?UTF-8?q?=EC=9D=B4=EB=B0=8D=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- core-di/src/main/java/com/kkkk/di/ManagerModule.kt | 6 +++--- .../kkkk/presentation/main/rhythm/RhythmFragment.kt | 10 +++++----- .../{WearableDataManager.kt => PhoneDataManager.kt} | 2 +- 3 files changed, 9 insertions(+), 9 deletions(-) rename presentation/src/main/java/com/kkkk/presentation/manager/{WearableDataManager.kt => PhoneDataManager.kt} (96%) diff --git a/core-di/src/main/java/com/kkkk/di/ManagerModule.kt b/core-di/src/main/java/com/kkkk/di/ManagerModule.kt index c6cb993..6932d54 100644 --- a/core-di/src/main/java/com/kkkk/di/ManagerModule.kt +++ b/core-di/src/main/java/com/kkkk/di/ManagerModule.kt @@ -3,7 +3,7 @@ package com.kkkk.di import android.content.Context import com.google.android.gms.wearable.DataClient import com.google.android.gms.wearable.Wearable -import com.kkkk.presentation.manager.WearableDataManager +import com.kkkk.presentation.manager.PhoneDataManager import dagger.Module import dagger.Provides import dagger.hilt.InstallIn @@ -23,7 +23,7 @@ object ManagerModule{ @Provides @Singleton - fun provideWearableDataManager(dataClient: DataClient): WearableDataManager { - return WearableDataManager(dataClient) + fun providePhoneDataManager(dataClient: DataClient): PhoneDataManager { + return PhoneDataManager(dataClient) } } \ No newline at end of file diff --git a/presentation/src/main/java/com/kkkk/presentation/main/rhythm/RhythmFragment.kt b/presentation/src/main/java/com/kkkk/presentation/main/rhythm/RhythmFragment.kt index 0235579..9736981 100644 --- a/presentation/src/main/java/com/kkkk/presentation/main/rhythm/RhythmFragment.kt +++ b/presentation/src/main/java/com/kkkk/presentation/main/rhythm/RhythmFragment.kt @@ -23,9 +23,9 @@ import com.kkkk.core.extension.stringOf import com.kkkk.core.extension.toast import com.kkkk.core.state.UiState import com.kkkk.presentation.main.rhythm.RhythmViewModel.Companion.LEVEL_UNDEFINED -import com.kkkk.presentation.manager.WearableDataManager -import com.kkkk.presentation.manager.WearableDataManager.Companion.KEY_BPM -import com.kkkk.presentation.manager.WearableDataManager.Companion.PATH_BPM +import com.kkkk.presentation.manager.PhoneDataManager +import com.kkkk.presentation.manager.PhoneDataManager.Companion.KEY_BPM +import com.kkkk.presentation.manager.PhoneDataManager.Companion.PATH_BPM import com.kkkk.presentation.onboarding.onbarding.OnboardingViewModel.Companion.SPEED_CALC_INTERVAL import dagger.hilt.android.AndroidEntryPoint import kotlinx.coroutines.flow.distinctUntilChanged @@ -49,7 +49,7 @@ class RhythmFragment : BaseFragment(R.layout.fragment_rhy private lateinit var mediaPlayer: MediaPlayer @Inject - lateinit var wearableDataManager: WearableDataManager + lateinit var phoneDataManager: PhoneDataManager override fun onViewCreated( view: View, @@ -109,7 +109,7 @@ class RhythmFragment : BaseFragment(R.layout.fragment_rhy private fun initWearableSyncBtnListener() { binding.tvRhythmTitle.setOnSingleClickListener { - wearableDataManager.sendIntToWearable(PATH_BPM, KEY_BPM, viewModel.getBpmFromDataStore()) + phoneDataManager.sendIntToWearable(PATH_BPM, KEY_BPM, viewModel.getBpmFromDataStore()) } } diff --git a/presentation/src/main/java/com/kkkk/presentation/manager/WearableDataManager.kt b/presentation/src/main/java/com/kkkk/presentation/manager/PhoneDataManager.kt similarity index 96% rename from presentation/src/main/java/com/kkkk/presentation/manager/WearableDataManager.kt rename to presentation/src/main/java/com/kkkk/presentation/manager/PhoneDataManager.kt index 2c4129b..c54fe48 100644 --- a/presentation/src/main/java/com/kkkk/presentation/manager/WearableDataManager.kt +++ b/presentation/src/main/java/com/kkkk/presentation/manager/PhoneDataManager.kt @@ -10,7 +10,7 @@ import javax.inject.Inject import javax.inject.Singleton @Singleton -class WearableDataManager @Inject constructor( +class PhoneDataManager @Inject constructor( private val dataClient: DataClient ) { From 8e5f3679390495fa57ed0507067dcae23d3fd095 Mon Sep 17 00:00:00 2001 From: Sangho Kim Date: Wed, 28 Aug 2024 22:44:49 +0900 Subject: [PATCH 2/5] =?UTF-8?q?[FEAT/#51]=20WearableDataManager=20?= =?UTF-8?q?=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../manager/WearableDataManger.kt | 38 +++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 stempo/src/main/java/com/kkkk/stempo/presentation/manager/WearableDataManger.kt diff --git a/stempo/src/main/java/com/kkkk/stempo/presentation/manager/WearableDataManger.kt b/stempo/src/main/java/com/kkkk/stempo/presentation/manager/WearableDataManger.kt new file mode 100644 index 0000000..ef3b261 --- /dev/null +++ b/stempo/src/main/java/com/kkkk/stempo/presentation/manager/WearableDataManger.kt @@ -0,0 +1,38 @@ +package com.kkkk.stempo.presentation.manager + +import com.google.android.gms.tasks.Task +import com.google.android.gms.wearable.DataClient +import com.google.android.gms.wearable.DataItem +import com.google.android.gms.wearable.PutDataMapRequest +import com.google.android.gms.wearable.PutDataRequest +import timber.log.Timber +import javax.inject.Inject +import javax.inject.Singleton + +@Singleton +class WearableDataManager @Inject constructor( + private val dataClient: DataClient +) { + + fun sendIntToPhone(path: String, key: String, value: Int): Task { + + Timber.tag("okhttp").d("START SENDING DATA TO WEARABLE") + + val putDataReq: PutDataRequest = PutDataMapRequest.create(path).run { + dataMap.putInt(key, value) + asPutDataRequest().setUrgent() + } + + return dataClient.putDataItem(putDataReq).addOnSuccessListener { dataItem -> + Timber.tag("okhttp").d("SEND DATA TO WEARABLE SUCCESS : ${dataItem.uri}") + }.addOnFailureListener { exception -> + Timber.tag("okhttp").d("SEND DATA TO WEARABLE FAIL : ${exception.message}") + } + } + + companion object { + const val KEY_RECORD = "KEY_RECORD" + + const val PATH_RECORD = "/record" + } +} \ No newline at end of file From 3985343af253e3fb2a1ea8fb8b340b1d3ea54136 Mon Sep 17 00:00:00 2001 From: Sangho Kim Date: Wed, 28 Aug 2024 22:52:28 +0900 Subject: [PATCH 3/5] =?UTF-8?q?[FIX/#51]=20WearableDataManager=20=ED=9E=90?= =?UTF-8?q?=ED=8A=B8=20=EC=A0=9C=EA=B1=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/kkkk/presentation/main/MainActivity.kt | 2 +- .../com/kkkk/stempo/presentation/WatchActivity.kt | 9 +++++++++ .../presentation/manager/WearableDataManger.kt | 13 ++++--------- 3 files changed, 14 insertions(+), 10 deletions(-) diff --git a/presentation/src/main/java/com/kkkk/presentation/main/MainActivity.kt b/presentation/src/main/java/com/kkkk/presentation/main/MainActivity.kt index fb1d20c..43c890d 100644 --- a/presentation/src/main/java/com/kkkk/presentation/main/MainActivity.kt +++ b/presentation/src/main/java/com/kkkk/presentation/main/MainActivity.kt @@ -22,7 +22,7 @@ class MainActivity : BaseActivity(R.layout.activity_main) { initBnvItemSelectedListener() } - fun initBnvItemIconTintList() { + private fun initBnvItemIconTintList() { with(binding.bnvMain) { itemIconTintList = null selectedItemId = R.id.menu_rhythm diff --git a/stempo/src/main/java/com/kkkk/stempo/presentation/WatchActivity.kt b/stempo/src/main/java/com/kkkk/stempo/presentation/WatchActivity.kt index 4d3f401..b63756a 100644 --- a/stempo/src/main/java/com/kkkk/stempo/presentation/WatchActivity.kt +++ b/stempo/src/main/java/com/kkkk/stempo/presentation/WatchActivity.kt @@ -16,6 +16,9 @@ import com.google.android.gms.wearable.DataEventBuffer import com.google.android.gms.wearable.DataMapItem import com.google.android.gms.wearable.Wearable import com.kkkk.stempo.presentation.home.HomeScreen +import com.kkkk.stempo.presentation.manager.WearableDataManager +import com.kkkk.stempo.presentation.manager.WearableDataManager.Companion.KEY_RECORD +import com.kkkk.stempo.presentation.manager.WearableDataManager.Companion.PATH_RECORD import com.kkkk.stempo.presentation.theme.StempoandroidTheme import dagger.hilt.android.AndroidEntryPoint import timber.log.Timber @@ -34,6 +37,12 @@ class WatchActivity : ComponentActivity(), DataClient.OnDataChangedListener { HomeScreen() } } + + WearableDataManager(Wearable.getDataClient(this)).sendIntToPhone( + PATH_RECORD, + KEY_RECORD, + 50 + ) } override fun onResume() { diff --git a/stempo/src/main/java/com/kkkk/stempo/presentation/manager/WearableDataManger.kt b/stempo/src/main/java/com/kkkk/stempo/presentation/manager/WearableDataManger.kt index ef3b261..234a3bf 100644 --- a/stempo/src/main/java/com/kkkk/stempo/presentation/manager/WearableDataManger.kt +++ b/stempo/src/main/java/com/kkkk/stempo/presentation/manager/WearableDataManger.kt @@ -6,17 +6,12 @@ import com.google.android.gms.wearable.DataItem import com.google.android.gms.wearable.PutDataMapRequest import com.google.android.gms.wearable.PutDataRequest import timber.log.Timber -import javax.inject.Inject -import javax.inject.Singleton -@Singleton -class WearableDataManager @Inject constructor( - private val dataClient: DataClient -) { +class WearableDataManager(private val dataClient: DataClient) { fun sendIntToPhone(path: String, key: String, value: Int): Task { - Timber.tag("okhttp").d("START SENDING DATA TO WEARABLE") + Timber.tag("okhttp").d("START SENDING DATA TO PHONE") val putDataReq: PutDataRequest = PutDataMapRequest.create(path).run { dataMap.putInt(key, value) @@ -24,9 +19,9 @@ class WearableDataManager @Inject constructor( } return dataClient.putDataItem(putDataReq).addOnSuccessListener { dataItem -> - Timber.tag("okhttp").d("SEND DATA TO WEARABLE SUCCESS : ${dataItem.uri}") + Timber.tag("okhttp").d("SEND DATA TO PHONE SUCCESS : ${dataItem.uri}") }.addOnFailureListener { exception -> - Timber.tag("okhttp").d("SEND DATA TO WEARABLE FAIL : ${exception.message}") + Timber.tag("okhttp").d("SEND DATA TO PHONE FAIL : ${exception.message}") } } From eb52ed9883dae70a610f3ab9639e6a9416d7e5b8 Mon Sep 17 00:00:00 2001 From: Sangho Kim Date: Thu, 29 Aug 2024 00:23:38 +0900 Subject: [PATCH 4/5] =?UTF-8?q?[FEAT/#51]=20DataClient.OnDataChangedListen?= =?UTF-8?q?er=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/rhythm/RhythmFragment.kt | 32 ++++++++++++++++++- .../stempo/presentation/home/HomeViewModel.kt | 1 - 2 files changed, 31 insertions(+), 2 deletions(-) diff --git a/presentation/src/main/java/com/kkkk/presentation/main/rhythm/RhythmFragment.kt b/presentation/src/main/java/com/kkkk/presentation/main/rhythm/RhythmFragment.kt index 9736981..6a657dd 100644 --- a/presentation/src/main/java/com/kkkk/presentation/main/rhythm/RhythmFragment.kt +++ b/presentation/src/main/java/com/kkkk/presentation/main/rhythm/RhythmFragment.kt @@ -14,6 +14,11 @@ import androidx.core.view.isVisible import androidx.fragment.app.activityViewModels import androidx.lifecycle.flowWithLifecycle import androidx.lifecycle.lifecycleScope +import com.google.android.gms.wearable.DataClient +import com.google.android.gms.wearable.DataEvent +import com.google.android.gms.wearable.DataEventBuffer +import com.google.android.gms.wearable.DataMapItem +import com.google.android.gms.wearable.Wearable import com.kkkk.core.base.BaseFragment import com.kkkk.core.extension.colorOf import com.kkkk.core.extension.drawableOf @@ -33,13 +38,14 @@ import kotlinx.coroutines.flow.launchIn import kotlinx.coroutines.flow.onEach import kr.genti.presentation.R import kr.genti.presentation.databinding.FragmentRhythmBinding +import timber.log.Timber import java.io.File import java.nio.file.Files import javax.inject.Inject @AndroidEntryPoint class RhythmFragment : BaseFragment(R.layout.fragment_rhythm), - SensorEventListener { + SensorEventListener, DataClient.OnDataChangedListener { private lateinit var sensorManager: SensorManager private var stepDetectorSensor: Sensor? = null @@ -271,6 +277,8 @@ class RhythmFragment : BaseFragment(R.layout.fragment_rhy stepDetectorSensor?.let { sensorManager.registerListener(this, it, SensorManager.SENSOR_DELAY_NORMAL) } + Timber.tag("okhttp").d("LISTENER : ADDED") + Wearable.getDataClient(requireActivity()).addListener(this) } override fun onPause() { @@ -278,6 +286,8 @@ class RhythmFragment : BaseFragment(R.layout.fragment_rhy if (::sensorManager.isInitialized) { sensorManager.unregisterListener(this) } + Timber.tag("okhttp").d("LISTENER : REMOVED") + Wearable.getDataClient(requireActivity()).removeListener(this) } override fun onSensorChanged(event: SensorEvent?) { @@ -295,6 +305,23 @@ class RhythmFragment : BaseFragment(R.layout.fragment_rhy stepDetectorSensor = sensorManager.getDefaultSensor(Sensor.TYPE_STEP_DETECTOR) } + override fun onDataChanged(dataEvents: DataEventBuffer) { + Timber.tag("okhttp").d("LISTENER : ON DATA CHANGED") + + dataEvents.forEach { event -> + if (event.type == DataEvent.TYPE_CHANGED) { + event.dataItem.also { item -> + if (item.uri.path?.compareTo(PATH_RECORD) == 0) { + DataMapItem.fromDataItem(item).dataMap.apply { + val record = getInt(KEY_RECORD) + Timber.tag("okhttp").d("LISTENER : DATA RECEIVED : $record") + } + } + } + } + } + } + private fun calculateSpeed() { val currentTime = System.currentTimeMillis() val lastStepTime = viewModel.lastStepTime.value @@ -321,6 +348,9 @@ class RhythmFragment : BaseFragment(R.layout.fragment_rhy private const val DRAWABLE = "drawable" private const val RAW = "raw" + const val KEY_RECORD = "KEY_RECORD" + const val PATH_RECORD = "/record" + private const val FLOAT_120 = 120.00000000000000000000F private const val SUCCESS_CODE = 200 diff --git a/stempo/src/main/java/com/kkkk/stempo/presentation/home/HomeViewModel.kt b/stempo/src/main/java/com/kkkk/stempo/presentation/home/HomeViewModel.kt index bfde5c5..129353c 100644 --- a/stempo/src/main/java/com/kkkk/stempo/presentation/home/HomeViewModel.kt +++ b/stempo/src/main/java/com/kkkk/stempo/presentation/home/HomeViewModel.kt @@ -1,6 +1,5 @@ package com.kkkk.stempo.presentation.home -import android.util.Log import androidx.lifecycle.ViewModel import androidx.lifecycle.viewModelScope import com.kkkk.domain.repository.UserRepository From 856a43477e0601da4a9406ec4a9d20551c1b01ae Mon Sep 17 00:00:00 2001 From: Sangho Kim Date: Thu, 29 Aug 2024 00:25:17 +0900 Subject: [PATCH 5/5] =?UTF-8?q?[ADD/#51]=20=EB=8F=99=EB=AF=BC=EC=9D=84=20?= =?UTF-8?q?=EC=9C=84=ED=95=9C=20=ED=88=AC=EB=91=90=20=EC=84=A4=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/kkkk/presentation/main/rhythm/RhythmFragment.kt | 1 + .../src/main/java/com/kkkk/stempo/presentation/WatchActivity.kt | 2 ++ 2 files changed, 3 insertions(+) diff --git a/presentation/src/main/java/com/kkkk/presentation/main/rhythm/RhythmFragment.kt b/presentation/src/main/java/com/kkkk/presentation/main/rhythm/RhythmFragment.kt index 6a657dd..b5d08a0 100644 --- a/presentation/src/main/java/com/kkkk/presentation/main/rhythm/RhythmFragment.kt +++ b/presentation/src/main/java/com/kkkk/presentation/main/rhythm/RhythmFragment.kt @@ -315,6 +315,7 @@ class RhythmFragment : BaseFragment(R.layout.fragment_rhy DataMapItem.fromDataItem(item).dataMap.apply { val record = getInt(KEY_RECORD) Timber.tag("okhttp").d("LISTENER : DATA RECEIVED : $record") + // TODO 여기서 기록 받아서 서버통신으로 기록 } } } diff --git a/stempo/src/main/java/com/kkkk/stempo/presentation/WatchActivity.kt b/stempo/src/main/java/com/kkkk/stempo/presentation/WatchActivity.kt index b63756a..78954ed 100644 --- a/stempo/src/main/java/com/kkkk/stempo/presentation/WatchActivity.kt +++ b/stempo/src/main/java/com/kkkk/stempo/presentation/WatchActivity.kt @@ -38,6 +38,7 @@ class WatchActivity : ComponentActivity(), DataClient.OnDataChangedListener { } } + // TODO 이 함수로 정지 시 결과값 전송 WearableDataManager(Wearable.getDataClient(this)).sendIntToPhone( PATH_RECORD, KEY_RECORD, @@ -66,6 +67,7 @@ class WatchActivity : ComponentActivity(), DataClient.OnDataChangedListener { DataMapItem.fromDataItem(item).dataMap.apply { val bpm = getInt(KEY_BPM) Timber.tag("okhttp").d("LISTENER : DATA RECEIVED : $bpm") + // TODO 여기서 bpm 받아서 초기값으로 설정 } } }