From 04c53950bd9fdbb52b6ae5c43c34b047d3ec8ef2 Mon Sep 17 00:00:00 2001 From: KKJ Date: Thu, 7 Mar 2024 23:24:24 +0900 Subject: [PATCH 01/14] =?UTF-8?q?test:=20=EB=B3=B4=ED=98=B8=EB=8C=80?= =?UTF-8?q?=EC=83=81=EC=9E=90=20=EC=9C=84=EC=B9=98=20=EC=A0=95=EB=B3=B4=20?= =?UTF-8?q?api=20=EC=8B=A4=ED=8C=A8=20=EA=B5=AC=EB=B6=84=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit unexpected end of stream 관련 --- .../java/kr/ac/tukorea/whereareu/di/NetworkModule.kt | 4 ++-- .../whereareu/util/location/DefaultLocationClient.kt | 5 ++++- .../whereareu/util/location/InternalFileStorageUtil.kt | 2 ++ .../tukorea/whereareu/util/location/LocationService.kt | 9 ++++++--- 4 files changed, 14 insertions(+), 6 deletions(-) diff --git a/frontend/app/src/main/java/kr/ac/tukorea/whereareu/di/NetworkModule.kt b/frontend/app/src/main/java/kr/ac/tukorea/whereareu/di/NetworkModule.kt index 7c95cc32..b91a9d9d 100644 --- a/frontend/app/src/main/java/kr/ac/tukorea/whereareu/di/NetworkModule.kt +++ b/frontend/app/src/main/java/kr/ac/tukorea/whereareu/di/NetworkModule.kt @@ -42,8 +42,8 @@ object NetworkModule { } return OkHttpClient.Builder() - .connectTimeout(5, TimeUnit.SECONDS) - .readTimeout(5, TimeUnit.SECONDS) + .connectTimeout(10, TimeUnit.SECONDS) + .readTimeout(10, TimeUnit.SECONDS) .writeTimeout(5, TimeUnit.SECONDS) .addInterceptor(interceptor) .addNetworkInterceptor(closeInterceptor) diff --git a/frontend/app/src/main/java/kr/ac/tukorea/whereareu/util/location/DefaultLocationClient.kt b/frontend/app/src/main/java/kr/ac/tukorea/whereareu/util/location/DefaultLocationClient.kt index 1866fcd4..2adc2bd0 100644 --- a/frontend/app/src/main/java/kr/ac/tukorea/whereareu/util/location/DefaultLocationClient.kt +++ b/frontend/app/src/main/java/kr/ac/tukorea/whereareu/util/location/DefaultLocationClient.kt @@ -5,6 +5,7 @@ import android.content.Context import android.location.Location import android.location.LocationManager import android.os.Looper +import android.util.Log import com.google.android.gms.location.FusedLocationProviderClient import com.google.android.gms.location.LocationCallback import com.google.android.gms.location.LocationResult @@ -56,6 +57,8 @@ class DefaultLocationClient( } } override fun getGpsStatus(): Boolean { - return locationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER) && locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER) + return locationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER) || locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER) + Log.d("network", locationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER).toString()) + Log.d("gps", locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER).toString()) } } \ No newline at end of file diff --git a/frontend/app/src/main/java/kr/ac/tukorea/whereareu/util/location/InternalFileStorageUtil.kt b/frontend/app/src/main/java/kr/ac/tukorea/whereareu/util/location/InternalFileStorageUtil.kt index def9e2e9..0c1f9fd3 100644 --- a/frontend/app/src/main/java/kr/ac/tukorea/whereareu/util/location/InternalFileStorageUtil.kt +++ b/frontend/app/src/main/java/kr/ac/tukorea/whereareu/util/location/InternalFileStorageUtil.kt @@ -22,6 +22,8 @@ class InternalFileStorageUtil(private val context: Context) { try { // 파일이 존재하는지 확인 val file = File(context.filesDir, filename) + Log.d("ab path", file.absolutePath) + Log.d("path", file.path) if (!file.exists()) { storeFileUsingStream(filename, content) diff --git a/frontend/app/src/main/java/kr/ac/tukorea/whereareu/util/location/LocationService.kt b/frontend/app/src/main/java/kr/ac/tukorea/whereareu/util/location/LocationService.kt index 73f1f60d..514c8582 100644 --- a/frontend/app/src/main/java/kr/ac/tukorea/whereareu/util/location/LocationService.kt +++ b/frontend/app/src/main/java/kr/ac/tukorea/whereareu/util/location/LocationService.kt @@ -104,6 +104,7 @@ class LocationService: Service() { if (checkReadyToPost()) { val currentTime = getCurrentTime() var userState = 0 + var isError = false val info = LocationInfo(dementiaKey, locationInfo[LATITUDE], locationInfo[LONGITUDE], currentTime[TIME].trim(), currentTime[DATE], locationExtraInfo[SPEED], accelerationsensor = sensorValueList[ACCELEROMETER_SENSOR], @@ -117,21 +118,23 @@ class LocationService: Service() { Log.d("info", info.toString()) repository.postLocationInfo(info).onSuccess { userState = it.result + isError = true }.onException { + isError = false Log.d("error", it.toString()) } // AI 정보 수집을 위한 함수 - saveFile(currentTime[DATE], currentTime[TIME].trim(), userState.toString()) + saveFile(currentTime[DATE], currentTime[TIME].trim(), userState.toString(), isError.toString()) delay(60000) } } } } - private fun saveFile(date: String, time: String, userState: String){ + private fun saveFile(date: String, time: String, userState: String, isError: String){ val internalFile = InternalFileStorageUtil(applicationContext) internalFile.appendContentToFile("${locationInfo[LATITUDE]}, ${locationInfo[LONGITUDE]}, " + - "$date $time, " + "$userState") + "$date $time, " + "$userState, $isError") } private fun getDementiaKey(): String?{ From 82c1d3fc304188cc1495de62ecf72d209d28a960 Mon Sep 17 00:00:00 2001 From: KKJ Date: Mon, 11 Mar 2024 20:20:51 +0900 Subject: [PATCH 02/14] =?UTF-8?q?refactor:=20api=20=EC=84=B1=EA=B3=B5?= =?UTF-8?q?=EC=97=AC=EB=B6=80=20=EB=B3=80=EC=88=98=EB=AA=85=20=EB=B3=80?= =?UTF-8?q?=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../tukorea/whereareu/util/location/LocationService.kt | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/frontend/app/src/main/java/kr/ac/tukorea/whereareu/util/location/LocationService.kt b/frontend/app/src/main/java/kr/ac/tukorea/whereareu/util/location/LocationService.kt index 514c8582..782badcb 100644 --- a/frontend/app/src/main/java/kr/ac/tukorea/whereareu/util/location/LocationService.kt +++ b/frontend/app/src/main/java/kr/ac/tukorea/whereareu/util/location/LocationService.kt @@ -32,8 +32,6 @@ import kr.ac.tukorea.whereareu.util.sensor.AccelerometerSensor import kr.ac.tukorea.whereareu.util.sensor.GyroScopeSensor import kr.ac.tukorea.whereareu.util.sensor.LightSensor import kr.ac.tukorea.whereareu.util.sensor.MagneticFieldSensor -import java.io.FileWriter -import java.io.IOException import java.text.SimpleDateFormat import java.util.Date import java.util.Locale @@ -104,7 +102,7 @@ class LocationService: Service() { if (checkReadyToPost()) { val currentTime = getCurrentTime() var userState = 0 - var isError = false + var isSuccess = false val info = LocationInfo(dementiaKey, locationInfo[LATITUDE], locationInfo[LONGITUDE], currentTime[TIME].trim(), currentTime[DATE], locationExtraInfo[SPEED], accelerationsensor = sensorValueList[ACCELEROMETER_SENSOR], @@ -118,13 +116,13 @@ class LocationService: Service() { Log.d("info", info.toString()) repository.postLocationInfo(info).onSuccess { userState = it.result - isError = true + isSuccess = true }.onException { - isError = false + isSuccess = false Log.d("error", it.toString()) } // AI 정보 수집을 위한 함수 - saveFile(currentTime[DATE], currentTime[TIME].trim(), userState.toString(), isError.toString()) + saveFile(currentTime[DATE], currentTime[TIME].trim(), userState.toString(), isSuccess.toString()) delay(60000) } } From 29a3b8307a907a7bc8f800f638a8b9745248c919 Mon Sep 17 00:00:00 2001 From: KKJ Date: Thu, 14 Mar 2024 14:20:06 +0900 Subject: [PATCH 03/14] =?UTF-8?q?fix:=20=EB=B3=B4=ED=98=B8=EC=9E=90=20?= =?UTF-8?q?=EC=9E=90=EB=8F=99=EB=A1=9C=EA=B7=B8=EC=9D=B8=20=EC=98=A4?= =?UTF-8?q?=EB=A5=98=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../tukorea/whereareu/presentation/login/nok/NokOtpFragment.kt | 1 + 1 file changed, 1 insertion(+) diff --git a/frontend/app/src/main/java/kr/ac/tukorea/whereareu/presentation/login/nok/NokOtpFragment.kt b/frontend/app/src/main/java/kr/ac/tukorea/whereareu/presentation/login/nok/NokOtpFragment.kt index eb5491bf..b3bea3eb 100644 --- a/frontend/app/src/main/java/kr/ac/tukorea/whereareu/presentation/login/nok/NokOtpFragment.kt +++ b/frontend/app/src/main/java/kr/ac/tukorea/whereareu/presentation/login/nok/NokOtpFragment.kt @@ -32,6 +32,7 @@ class NokOtpFragment : BaseFragment(R.layout.fragment_nok // 보호자 정보 저장 val nokSpf = requireActivity().getSharedPreferences("User", MODE_PRIVATE) nokSpf.edit { + putBoolean("isDementia", false) putString("key", it.nokKey) putString("name", args.name) putString("phone", args.phone) From 3410dd524670d57590fbb80c1c3611c63ef53187 Mon Sep 17 00:00:00 2001 From: KKJ Date: Fri, 15 Mar 2024 23:43:10 +0900 Subject: [PATCH 04/14] =?UTF-8?q?feat:=20=EB=B3=B4=ED=98=B8=EB=8C=80?= =?UTF-8?q?=EC=83=81=EC=9E=90=20=EC=9C=84=EC=B9=98=20=EC=97=85=EB=8D=B0?= =?UTF-8?q?=EC=9D=B4=ED=8A=B8=20=EC=A3=BC=EA=B8=B0=20=EC=84=A4=EC=A0=95=20?= =?UTF-8?q?=EA=B8=B0=EB=8A=A5=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ac/tukorea/whereareu/di/NetworkModule.kt | 7 + .../presentation/nok/NokHomeViewModel.kt | 13 + .../presentation/nok/NokMainActivity.kt | 29 ++- .../presentation/nok/NokSettingFragment.kt | 43 ++++ .../main/res/layout/fragment_nok_setting.xml | 232 ++++++++++++++++++ .../app/src/main/res/menu/nok_main_menu.xml | 2 +- .../app/src/main/res/navigation/nok_graph.xml | 8 +- 7 files changed, 325 insertions(+), 9 deletions(-) create mode 100644 frontend/app/src/main/java/kr/ac/tukorea/whereareu/presentation/nok/NokSettingFragment.kt create mode 100644 frontend/app/src/main/res/layout/fragment_nok_setting.xml diff --git a/frontend/app/src/main/java/kr/ac/tukorea/whereareu/di/NetworkModule.kt b/frontend/app/src/main/java/kr/ac/tukorea/whereareu/di/NetworkModule.kt index b91a9d9d..a0b599a9 100644 --- a/frontend/app/src/main/java/kr/ac/tukorea/whereareu/di/NetworkModule.kt +++ b/frontend/app/src/main/java/kr/ac/tukorea/whereareu/di/NetworkModule.kt @@ -10,6 +10,7 @@ import kr.ac.tukorea.whereareu.WhereAreUApplication import kr.ac.tukorea.whereareu.data.api.DementiaHomeService import kr.ac.tukorea.whereareu.data.api.LoginService import kr.ac.tukorea.whereareu.data.api.NokHomeService +import kr.ac.tukorea.whereareu.util.location.LocationService import okhttp3.Interceptor import okhttp3.Interceptor.* import okhttp3.OkHttpClient @@ -80,6 +81,12 @@ object NetworkModule { return retrofit.buildService() } + @Provides + @Singleton + fun provideLocationService(): LocationService{ + return LocationService() + } + private inline fun Retrofit.buildService(): T { return this.create(T::class.java) } diff --git a/frontend/app/src/main/java/kr/ac/tukorea/whereareu/presentation/nok/NokHomeViewModel.kt b/frontend/app/src/main/java/kr/ac/tukorea/whereareu/presentation/nok/NokHomeViewModel.kt index 11deecaf..ef54d21e 100644 --- a/frontend/app/src/main/java/kr/ac/tukorea/whereareu/presentation/nok/NokHomeViewModel.kt +++ b/frontend/app/src/main/java/kr/ac/tukorea/whereareu/presentation/nok/NokHomeViewModel.kt @@ -5,7 +5,9 @@ import androidx.lifecycle.ViewModel import androidx.lifecycle.viewModelScope import dagger.hilt.android.lifecycle.HiltViewModel import kotlinx.coroutines.flow.MutableSharedFlow +import kotlinx.coroutines.flow.MutableStateFlow import kotlinx.coroutines.flow.asSharedFlow +import kotlinx.coroutines.flow.asStateFlow import kotlinx.coroutines.launch import kr.ac.tukorea.whereareu.data.model.home.GetLocationInfoResponse import kr.ac.tukorea.whereareu.data.repository.home.NokHomeRepositoryImpl @@ -13,6 +15,7 @@ import kr.ac.tukorea.whereareu.util.network.onError import kr.ac.tukorea.whereareu.util.network.onException import kr.ac.tukorea.whereareu.util.network.onFail import kr.ac.tukorea.whereareu.util.network.onSuccess +import java.time.Duration import javax.inject.Inject @HiltViewModel @@ -22,6 +25,16 @@ class NokHomeViewModel @Inject constructor( private val _dementiaLocation = MutableSharedFlow(replay = 1) val dementiaLocation = _dementiaLocation.asSharedFlow() + + private val _updateDuration = MutableStateFlow(60*1000) + val updateDuration = _updateDuration.asStateFlow() + + fun setUpdateDuration(duration: Long){ + viewModelScope.launch { + //Log.d("duration", duration.toString()) + _updateDuration.emit(duration) + } + } fun getDementiaLocation(dementiaKey: String){ viewModelScope.launch { repository.getDementiaLocationInfo(dementiaKey).onSuccess { diff --git a/frontend/app/src/main/java/kr/ac/tukorea/whereareu/presentation/nok/NokMainActivity.kt b/frontend/app/src/main/java/kr/ac/tukorea/whereareu/presentation/nok/NokMainActivity.kt index c1241273..458b8efa 100644 --- a/frontend/app/src/main/java/kr/ac/tukorea/whereareu/presentation/nok/NokMainActivity.kt +++ b/frontend/app/src/main/java/kr/ac/tukorea/whereareu/presentation/nok/NokMainActivity.kt @@ -11,17 +11,21 @@ import androidx.localbroadcastmanager.content.LocalBroadcastManager import androidx.navigation.fragment.NavHostFragment import androidx.navigation.ui.setupWithNavController import dagger.hilt.android.AndroidEntryPoint +import kotlinx.coroutines.Job +import kotlinx.coroutines.cancelAndJoin import kotlinx.coroutines.delay import kotlinx.coroutines.launch import kr.ac.tukorea.whereareu.R import kr.ac.tukorea.whereareu.databinding.ActivityNokMainBinding import kr.ac.tukorea.whereareu.presentation.base.BaseActivity import kr.ac.tukorea.whereareu.util.extension.navigationHeight +import kr.ac.tukorea.whereareu.util.extension.repeatOnStarted import kr.ac.tukorea.whereareu.util.extension.setStatusBarTransparent @AndroidEntryPoint class NokMainActivity : BaseActivity(R.layout.activity_nok_main) { private val viewModel: NokHomeViewModel by viewModels() + private var updateLocationJob: Job? = null override fun initView() { //상태바 투명 설정 this.setStatusBarTransparent() @@ -42,10 +46,27 @@ class NokMainActivity : BaseActivity(R.layout.activity_n val spf = getSharedPreferences("OtherUser", MODE_PRIVATE) val dementiaKey = spf.getString("key", "") if (!dementiaKey.isNullOrEmpty()) { - lifecycleScope.launch { - while (true) { - viewModel.getDementiaLocation(dementiaKey) - delay(60000) + repeatOnStarted { + viewModel.updateDuration.collect{ duration -> + Log.d("duration", duration.toString()) + if(updateLocationJob == null) { + updateLocationJob = lifecycleScope.launch { + while (true) { + viewModel.getDementiaLocation(dementiaKey) + Log.d("duration null test", duration.toString()) + delay(duration) + } + } + } else{ + updateLocationJob?.cancelAndJoin() + updateLocationJob = lifecycleScope.launch { + while (true){ + viewModel.getDementiaLocation(dementiaKey) + Log.d("duration not null test", duration.toString()) + delay(duration) + } + } + } } } } diff --git a/frontend/app/src/main/java/kr/ac/tukorea/whereareu/presentation/nok/NokSettingFragment.kt b/frontend/app/src/main/java/kr/ac/tukorea/whereareu/presentation/nok/NokSettingFragment.kt new file mode 100644 index 00000000..d4098a16 --- /dev/null +++ b/frontend/app/src/main/java/kr/ac/tukorea/whereareu/presentation/nok/NokSettingFragment.kt @@ -0,0 +1,43 @@ +package kr.ac.tukorea.whereareu.presentation.nok + +import android.content.BroadcastReceiver +import android.content.Context +import android.content.Intent +import android.content.IntentFilter +import android.os.Build +import android.util.Log +import androidx.core.content.ContentProviderCompat.requireContext +import androidx.fragment.app.activityViewModels +import androidx.localbroadcastmanager.content.LocalBroadcastManager +import kr.ac.tukorea.whereareu.R +import kr.ac.tukorea.whereareu.data.model.home.LocationInfo +import kr.ac.tukorea.whereareu.databinding.FragmentNokSettingBinding +import kr.ac.tukorea.whereareu.databinding.FragmentSettingBinding +import kr.ac.tukorea.whereareu.presentation.base.BaseFragment +import kr.ac.tukorea.whereareu.util.location.LocationService + +class NokSettingFragment: BaseFragment(R.layout.fragment_nok_setting) { + private val viewModel: NokHomeViewModel by activityViewModels() + override fun initObserver() { + } + override fun initView() { + val spf = requireActivity().getSharedPreferences("User", Context.MODE_PRIVATE) + val otherSpf = requireActivity().getSharedPreferences("OtherUser", Context.MODE_PRIVATE) + binding.userNameTv.text = spf.getString("name", "") + + val isDementia = spf.getBoolean("isDementia", true) + binding.userTypeTv.text = if (isDementia) "보호대상자" else "보호자" + binding.otherNameTv.text = if (isDementia) "보호자 이름" else "보호대상자 이름" + binding.otherPhoneTv.text = if (isDementia) "보호자 전화번호" else "보호대상자 전화번호" + binding.userNameTv.text = spf.getString("name", "") + binding.userPhoneNumberTv.text = spf.getString("phone", "") + + binding.otherNameEditTv.setText(otherSpf.getString("name", "")) + binding.otherPhoneNumberTv.setText((otherSpf.getString("phone", ""))) + + binding.testBtn.setOnClickListener { + val duration = binding.durationEt.text.toString().toLong() + viewModel.setUpdateDuration(duration * 10000) + } + } +} \ No newline at end of file diff --git a/frontend/app/src/main/res/layout/fragment_nok_setting.xml b/frontend/app/src/main/res/layout/fragment_nok_setting.xml new file mode 100644 index 00000000..8e877d9f --- /dev/null +++ b/frontend/app/src/main/res/layout/fragment_nok_setting.xml @@ -0,0 +1,232 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +