Skip to content

Commit

Permalink
refactor: AreaCodeWorker & SplashActivity refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
ksw4015 committed Oct 5, 2024
1 parent 74bec00 commit 9c6cae1
Show file tree
Hide file tree
Showing 5 changed files with 5 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@ data class AreaCodeEntity(
@PrimaryKey(autoGenerate = true)
val id: Int? = null,
val code: String,
val name: String
val name: String,
)
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@ data class SigunguCodeEntity(
val id: Int? = null,
val areaCode: String,
val code: String,
val name: String
val name: String,
)
Original file line number Diff line number Diff line change
@@ -1,15 +1,11 @@
package kr.ksw.visitkorea.data.workmanager

import android.app.Notification
import android.content.Context
import androidx.core.app.NotificationCompat
import androidx.hilt.work.HiltWorker
import androidx.work.CoroutineWorker
import androidx.work.ForegroundInfo
import androidx.work.WorkerParameters
import dagger.assisted.Assisted
import dagger.assisted.AssistedInject
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.withContext
import kr.ksw.visitkorea.data.local.databases.AreaCodeDatabase
Expand Down Expand Up @@ -48,23 +44,4 @@ class AreaCodeWorker @AssistedInject constructor(
return Result.success()
}

override suspend fun getForegroundInfo(): ForegroundInfo {
return ForegroundInfo(
NOTIFICATION_ID,
createNotification()
)
}

private fun createNotification(): Notification {
return NotificationCompat.Builder(
appContext,
NOTIFICATION_CHANNEL
).build()
}

companion object {
private const val NOTIFICATION_ID = 1000
private const val NOTIFICATION_CHANNEL = "Save AreaCode"
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ class SplashActivity : ComponentActivity() {

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
viewModel.initAreaCode(applicationContext)
setContent {
VisitKoreaTheme {
Surface {
Expand All @@ -48,6 +47,7 @@ class SplashActivity : ComponentActivity() {
}
observeSideEffect()
viewModel.checkPermission(this)
viewModel.initAreaCode(applicationContext)
}

private fun observeSideEffect() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import androidx.activity.result.contract.ActivityResultContracts
import androidx.core.content.ContextCompat
import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import androidx.work.OneTimeWorkRequest
import androidx.work.OneTimeWorkRequestBuilder
import androidx.work.WorkManager
import dagger.hilt.android.lifecycle.HiltViewModel
Expand Down Expand Up @@ -58,15 +59,10 @@ class SplashViewModel @Inject constructor(
viewModelScope.launch {
val areaCodeItems = areaCodeDatabase.areaCodeDao.getAllAreaCodeEntities()
if(areaCodeItems.isEmpty()) {
val workRequest = OneTimeWorkRequestBuilder<AreaCodeWorker>().build()
val workRequest = OneTimeWorkRequest.Companion.from(AreaCodeWorker::class.java)
WorkManager
.getInstance(context)
.enqueue(workRequest)
} else {
Log.d("SplashViewModel", areaCodeItems.toString())
areaCodeItems.forEach {
Log.d("SplashViewModel", areaCodeDatabase.areaCodeDao.getSigunguCodeByAreaCode(it.code).toString())
}
}
}
}
Expand Down

0 comments on commit 9c6cae1

Please sign in to comment.