fix: 비저빌리티 및 폴링 간격 로직 수정 (v1.11.5)

- MainActivity에서 하드코딩된 폴링 제거 (MainViewModel에서 처리)
- 비저빌리티 로직 개선 - 앱 시작 시 새로고침 추가
- WorkerScheduler 배터리 제약 조건 완화
- BootReceiver 저장된 폴링 간격 사용하도록 수정
- 버전 1.11.5로 업데이트
This commit is contained in:
sanjeok77
2026-03-13 07:47:10 +09:00
parent 4d44d8fb7a
commit 5a14002c1d
5 changed files with 36 additions and 30 deletions

View File

@@ -24,8 +24,8 @@ android {
applicationId = "com.hotdeal.alarm" applicationId = "com.hotdeal.alarm"
minSdk = 31 minSdk = 31
targetSdk = 35 targetSdk = 35
versionCode = 21 versionCode = 22
versionName = "1.11.4" versionName = "1.11.5"
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner" testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
vectorDrawables { vectorDrawables {

View File

@@ -42,8 +42,7 @@ class MainActivity : ComponentActivity() {
// EdgeToEdge 설정 (One UI 7+ 대응) // EdgeToEdge 설정 (One UI 7+ 대응)
setupEdgeToEdge() setupEdgeToEdge()
// 2분 간격으로 폴링 시작 // 폴링은 MainViewModel에서 초기화 시 시작
workerScheduler.schedulePeriodicPolling(2)
setContent { setContent {
HotDealTheme { HotDealTheme {
@@ -176,15 +175,14 @@ class MainActivity : ComponentActivity() {
} }
// 비저빌리티 콜백 - 백그라운드에서 포어그라운드 전환 시 새로고침 // 비저빌리티 콜백 - 백그라운드에서 포어그라운드 전환 시 새로고침
private var isInBackground = false private var isInBackground = true
override fun onResume() { override fun onResume() {
super.onResume() super.onResume()
if (isInBackground) { if (isInBackground) {
// 백그라운드에서 돌아왔을 때 새로고침
workerScheduler.executeOnce() workerScheduler.executeOnce()
isInBackground = false
} }
isInBackground = false
} }
override fun onPause() { override fun onPause() {

View File

@@ -3,25 +3,33 @@ package com.hotdeal.alarm.util
import android.content.BroadcastReceiver import android.content.BroadcastReceiver
import android.content.Context import android.content.Context
import android.content.Intent import android.content.Intent
import androidx.work.WorkManager import com.hotdeal.alarm.data.local.preferences.AppSettings
import com.hotdeal.alarm.worker.HotDealPollingWorker 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() { class BootReceiver : BroadcastReceiver() {
@Inject
lateinit var workerScheduler: WorkerScheduler
@Inject
lateinit var appSettings: AppSettings
override fun onReceive(context: Context, intent: Intent) { override fun onReceive(context: Context, intent: Intent) {
if (intent.action == Intent.ACTION_BOOT_COMPLETED) { if (intent.action == Intent.ACTION_BOOT_COMPLETED) {
// 부팅 완료 시 폴링 재시작 CoroutineScope(Dispatchers.IO).launch {
val workManager = WorkManager.getInstance(context) val savedInterval = appSettings.pollingInterval.first().toLong()
workManager.enqueueUniquePeriodicWork( workerScheduler.schedulePeriodicPolling(savedInterval)
HotDealPollingWorker.WORK_NAME, }
androidx.work.ExistingPeriodicWorkPolicy.KEEP,
androidx.work.PeriodicWorkRequestBuilder<HotDealPollingWorker>(
15, java.util.concurrent.TimeUnit.MINUTES
).build()
)
} }
} }
} }

View File

@@ -31,11 +31,10 @@ class WorkerScheduler @Inject constructor(
// 최소/최대 값 제한 // 최소/최대 값 제한
val safeInterval = intervalMinutes.coerceIn(MIN_INTERVAL_MINUTES, MAX_INTERVAL_MINUTES) val safeInterval = intervalMinutes.coerceIn(MIN_INTERVAL_MINUTES, MAX_INTERVAL_MINUTES)
val constraints = Constraints.Builder() val constraints = Constraints.Builder()
.setRequiredNetworkType(NetworkType.CONNECTED) .setRequiredNetworkType(NetworkType.CONNECTED)
.setRequiresBatteryNotLow(true) // 배터리 부족 시 실행 안 함 .setRequiresDeviceIdle(false)
.setRequiresDeviceIdle(false) // 화면 켜진 상태에서도 실행 .build()
.build()
// 유연한 실행 시간 (±25%) // 유연한 실행 시간 (±25%)
val flexTime = (safeInterval * 0.25).toLong().coerceAtLeast(1) val flexTime = (safeInterval * 0.25).toLong().coerceAtLeast(1)

View File

@@ -1,10 +1,11 @@
{ {
"version": "1.11.4", "version": "1.11.5",
"versionCode": 21, "versionCode": 22,
"updateUrl": "https://git.webpluss.net/sanjeok77/hotdeal_alarm/releases/download/v1.11.4/app-release.apk", "updateUrl": "https://git.webpluss.net/sanjeok77/hotdeal_alarm/releases/download/v1.11.5/app-release.apk",
"changelog": [ "changelog": [
"업데이트 설치 버그 수정", "비저빌리티 새로고침 버그 수정",
"Android 12+ 호환성 개선", "폴링 간격 설정이 저장되지 않던 문제 수정",
"다운로드 리시버 생명주기 관리 개선" "배터리 부족 시에도 폴링 동작하도록 개선",
"부팅 시 저장된 폴링 간격 사용하도록 수정"
] ]
} }