fix: 비저빌리티 및 폴링 간격 로직 수정 (v1.11.5)
- MainActivity에서 하드코딩된 폴링 제거 (MainViewModel에서 처리) - 비저빌리티 로직 개선 - 앱 시작 시 새로고침 추가 - WorkerScheduler 배터리 제약 조건 완화 - BootReceiver 저장된 폴링 간격 사용하도록 수정 - 버전 1.11.5로 업데이트
This commit is contained in:
@@ -24,8 +24,8 @@ android {
|
||||
applicationId = "com.hotdeal.alarm"
|
||||
minSdk = 31
|
||||
targetSdk = 35
|
||||
versionCode = 21
|
||||
versionName = "1.11.4"
|
||||
versionCode = 22
|
||||
versionName = "1.11.5"
|
||||
|
||||
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
|
||||
vectorDrawables {
|
||||
|
||||
@@ -42,8 +42,7 @@ class MainActivity : ComponentActivity() {
|
||||
// EdgeToEdge 설정 (One UI 7+ 대응)
|
||||
setupEdgeToEdge()
|
||||
|
||||
// 2분 간격으로 폴링 시작
|
||||
workerScheduler.schedulePeriodicPolling(2)
|
||||
// 폴링은 MainViewModel에서 초기화 시 시작됨
|
||||
|
||||
setContent {
|
||||
HotDealTheme {
|
||||
@@ -176,15 +175,14 @@ class MainActivity : ComponentActivity() {
|
||||
}
|
||||
|
||||
// 비저빌리티 콜백 - 백그라운드에서 포어그라운드 전환 시 새로고침
|
||||
private var isInBackground = false
|
||||
private var isInBackground = true
|
||||
|
||||
override fun onResume() {
|
||||
super.onResume()
|
||||
if (isInBackground) {
|
||||
// 백그라운드에서 돌아왔을 때 새로고침
|
||||
workerScheduler.executeOnce()
|
||||
isInBackground = false
|
||||
}
|
||||
isInBackground = false
|
||||
}
|
||||
|
||||
override fun onPause() {
|
||||
|
||||
@@ -3,25 +3,33 @@ package com.hotdeal.alarm.util
|
||||
import android.content.BroadcastReceiver
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import androidx.work.WorkManager
|
||||
import com.hotdeal.alarm.worker.HotDealPollingWorker
|
||||
import com.hotdeal.alarm.data.local.preferences.AppSettings
|
||||
import com.hotdeal.alarm.worker.WorkerScheduler
|
||||
import dagger.hilt.android.AndroidEntryPoint
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.flow.first
|
||||
import kotlinx.coroutines.launch
|
||||
import javax.inject.Inject
|
||||
|
||||
/**
|
||||
* 부팅 완료 시 자동 시작 리시버
|
||||
*/
|
||||
@AndroidEntryPoint
|
||||
class BootReceiver : BroadcastReceiver() {
|
||||
|
||||
|
||||
@Inject
|
||||
lateinit var workerScheduler: WorkerScheduler
|
||||
|
||||
@Inject
|
||||
lateinit var appSettings: AppSettings
|
||||
|
||||
override fun onReceive(context: Context, intent: Intent) {
|
||||
if (intent.action == Intent.ACTION_BOOT_COMPLETED) {
|
||||
// 부팅 완료 시 폴링 재시작
|
||||
val workManager = WorkManager.getInstance(context)
|
||||
workManager.enqueueUniquePeriodicWork(
|
||||
HotDealPollingWorker.WORK_NAME,
|
||||
androidx.work.ExistingPeriodicWorkPolicy.KEEP,
|
||||
androidx.work.PeriodicWorkRequestBuilder<HotDealPollingWorker>(
|
||||
15, java.util.concurrent.TimeUnit.MINUTES
|
||||
).build()
|
||||
)
|
||||
CoroutineScope(Dispatchers.IO).launch {
|
||||
val savedInterval = appSettings.pollingInterval.first().toLong()
|
||||
workerScheduler.schedulePeriodicPolling(savedInterval)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -31,11 +31,10 @@ class WorkerScheduler @Inject constructor(
|
||||
// 최소/최대 값 제한
|
||||
val safeInterval = intervalMinutes.coerceIn(MIN_INTERVAL_MINUTES, MAX_INTERVAL_MINUTES)
|
||||
|
||||
val constraints = Constraints.Builder()
|
||||
.setRequiredNetworkType(NetworkType.CONNECTED)
|
||||
.setRequiresBatteryNotLow(true) // 배터리 부족 시 실행 안 함
|
||||
.setRequiresDeviceIdle(false) // 화면 켜진 상태에서도 실행
|
||||
.build()
|
||||
val constraints = Constraints.Builder()
|
||||
.setRequiredNetworkType(NetworkType.CONNECTED)
|
||||
.setRequiresDeviceIdle(false)
|
||||
.build()
|
||||
|
||||
// 유연한 실행 시간 (±25%)
|
||||
val flexTime = (safeInterval * 0.25).toLong().coerceAtLeast(1)
|
||||
|
||||
Reference in New Issue
Block a user