Skip to content

Commit

Permalink
code cleanup.
Browse files Browse the repository at this point in the history
  • Loading branch information
Santosh Pingle committed Nov 25, 2024
1 parent 7c4dd0d commit 59aab15
Show file tree
Hide file tree
Showing 5 changed files with 5 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ import com.google.android.fhir.sync.PeriodicSyncJobStatus
import com.google.android.fhir.sync.RepeatInterval
import com.google.android.fhir.sync.Sync
import com.google.android.fhir.sync.SyncJobStatus
import java.util.*
import java.util.concurrent.TimeUnit
import kotlinx.coroutines.flow.MutableSharedFlow
import kotlinx.coroutines.flow.MutableStateFlow
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ class SyncFragment : Fragment() {
}
observeLastSyncTime()
launchAndRepeatStarted(
{ syncFragmentViewModel.pollState.collect(::updateSyncJobStatus) },
{ syncFragmentViewModel.pollState.collect(::collectSyncJobStatus) },
)
}

Expand All @@ -76,7 +76,7 @@ class SyncFragment : Fragment() {
}
}

private fun updateSyncJobStatus(currentSyncJobStatus: CurrentSyncJobStatus) {
private fun collectSyncJobStatus(currentSyncJobStatus: CurrentSyncJobStatus) {
Timber.d("currentSyncJobStatus: $currentSyncJobStatus")
// Update status text
val statusTextView = requireView().findViewById<TextView>(R.id.current_status)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ import com.google.android.fhir.sync.CurrentSyncJobStatus
import com.google.android.fhir.sync.Sync
import java.time.OffsetDateTime
import java.time.format.DateTimeFormatter
import java.util.*
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.channels.BufferOverflow
import kotlinx.coroutines.flow.MutableSharedFlow
Expand All @@ -41,7 +40,6 @@ import kotlinx.coroutines.launch
/** View model for [MainActivity]. */
@OptIn(ExperimentalCoroutinesApi::class)
class SyncFragmentViewModel(application: Application) : AndroidViewModel(application) {
private var oneTimeSyncUuid: UUID? = null
private val _lastSyncTimestampLiveData = MutableLiveData<String>()
val lastSyncTimestampLiveData: LiveData<String>
get() = _lastSyncTimestampLiveData
Expand Down
16 changes: 3 additions & 13 deletions engine/src/main/java/com/google/android/fhir/sync/FhirDataStore.kt
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import androidx.datastore.preferences.core.stringPreferencesKey
import androidx.datastore.preferences.preferencesDataStore
import java.io.IOException
import java.time.OffsetDateTime
import java.util.*
import java.util.UUID
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.catch
import kotlinx.coroutines.flow.first
Expand Down Expand Up @@ -101,25 +101,15 @@ internal class FhirDataStore(context: Context) {
runBlocking { dataStore.edit { pref -> pref[lastSyncTimestampKey] = datetime.toString() } }
}

/**
* Stores the given UUID in DataStore.
*
* @param uuid The UUID to store.
* @param workIdKey The key used to store the UUID.
*/
/** Stores the given UUID in DataStore. */
@PublishedApi
internal suspend fun storeWorkId(uuid: UUID, workIdKey: String) {
dataStore.edit { preferences ->
preferences[stringPreferencesKey("$workIdKey-key")] = uuid.toString()
}
}

/**
* Fetches the stored UUID from DataStore.
*
* @param workIdKey The key used to fetch the UUID.
* @return The stored UUID, or null if not found.
*/
/** Fetches the stored UUID from DataStore. */
@PublishedApi
internal suspend fun fetchWorkId(workIdKey: String): UUID? {
val preferences = dataStore.data.first()
Expand Down
9 changes: 0 additions & 9 deletions engine/src/main/java/com/google/android/fhir/sync/Sync.kt
Original file line number Diff line number Diff line change
Expand Up @@ -137,10 +137,6 @@ object Sync {
}
}

fun cancelWorkById(context: Context, workId: UUID) {
WorkManager.getInstance(context).cancelWorkById(workId)
}

/**
* Retrieves the work information for a specific unique work name as a flow of pairs containing
* the work state and the corresponding progress data if available.
Expand Down Expand Up @@ -195,7 +191,6 @@ object Sync {
createSyncStateForPeriodicSync(
workerInfoSyncJobStatusPairFromWorkManager.first,
workerInfoSyncJobStatusPairFromWorkManager.second,
syncJobStatusFromDataStore,
),
)
}
Expand Down Expand Up @@ -333,11 +328,7 @@ object Sync {
private fun createSyncStateForPeriodicSync(
workInfoState: WorkInfo.State,
syncJobStatusFromWorkManager: SyncJobStatus?,
syncJobStatusFromDataStore: SyncJobStatus?,
): CurrentSyncJobStatus {
Timber.d(
"currentSyncJobStatus : $syncJobStatusFromWorkManager syncJobStatusFromDataStore: $syncJobStatusFromDataStore workInfoState: $workInfoState",
)
return when (workInfoState) {
WorkInfo.State.ENQUEUED -> Enqueued
WorkInfo.State.RUNNING -> {
Expand Down

0 comments on commit 59aab15

Please sign in to comment.