Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions app/src/main/java/org/dhis2/AppModule.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import dagger.Module
import dagger.Provides
import org.dhis2.commons.resources.ColorUtils
import org.dhis2.data.service.CheckVersionWorker
import org.dhis2.data.service.SyncGranularWorker
import org.dhis2.usescases.main.mainModule
import org.koin.androidx.workmanager.dsl.workerOf
import org.koin.dsl.module
Expand All @@ -27,6 +26,5 @@ class AppModule(
val appModule =
module {
includes(mainModule)
workerOf(::SyncGranularWorker)
workerOf(::CheckVersionWorker)
}

This file was deleted.

31 changes: 0 additions & 31 deletions app/src/main/java/org/dhis2/data/service/SyncGranularRxModule.kt

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ import androidx.core.app.NotificationManagerCompat
import androidx.work.ForegroundInfo
import androidx.work.Worker
import androidx.work.WorkerParameters
import org.dhis2.App
import org.dhis2.R
import org.dhis2.commons.Constants.ATTRIBUTE_OPTION_COMBO
import org.dhis2.commons.Constants.CATEGORY_OPTION_COMBO
Expand All @@ -50,6 +49,7 @@ import javax.inject.Inject
private const val GRANULAR_CHANNEL = "sync_granular_notification"
private const val SYNC_GRANULAR_ID = 8071988

@Deprecated("Use org.dhis2.mobile.sync.data.GranularSyncWorker")
class SyncGranularWorker(
context: Context,
workerParams: WorkerParameters,
Expand All @@ -59,11 +59,6 @@ class SyncGranularWorker(
internal lateinit var presenter: SyncPresenter

override fun doWork(): Result {
(applicationContext as App)
.userComponent()
?.plus(SyncGranularRxModule(syncStatusController))
?.inject(this)

val uid = inputData.getString(UID) ?: return Result.failure()
val conflictType = inputData.getString(CONFLICT_TYPE)?.let { ConflictType.valueOf(it) }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ import androidx.work.WorkInfo
import androidx.work.WorkManager
import androidx.work.await
import org.dhis2.data.service.CheckVersionWorker
import org.dhis2.data.service.SyncGranularWorker
import org.dhis2.mobile.sync.data.GranularSyncWorker
import java.util.concurrent.TimeUnit

class WorkManagerControllerImpl(
Expand Down Expand Up @@ -103,7 +103,7 @@ class WorkManagerControllerImpl(
private fun createOneTimeBuilder(workerItem: WorkerItem): OneTimeWorkRequest.Builder {
val syncBuilder =
when (workerItem.workerType) {
WorkerType.GRANULAR -> OneTimeWorkRequest.Builder(SyncGranularWorker::class.java)
WorkerType.GRANULAR -> OneTimeWorkRequest.Builder(GranularSyncWorker::class.java)
WorkerType.NEW_VERSION -> OneTimeWorkRequest.Builder(CheckVersionWorker::class.java)
}

Expand All @@ -126,7 +126,7 @@ class WorkManagerControllerImpl(
when (workerItem.workerType) {
WorkerType.GRANULAR -> {
PeriodicWorkRequest.Builder(
SyncGranularWorker::class.java,
GranularSyncWorker::class.java,
seconds,
TimeUnit.SECONDS,
)
Expand Down
5 changes: 0 additions & 5 deletions app/src/main/java/org/dhis2/data/user/UserComponent.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@
import org.dhis2.commons.featureconfig.di.FeatureConfigActivityComponent;
import org.dhis2.commons.featureconfig.di.FeatureConfigActivityModule;
import org.dhis2.commons.filters.data.FilterPresenter;
import org.dhis2.data.service.SyncGranularRxComponent;
import org.dhis2.data.service.SyncGranularRxModule;
import org.dhis2.usescases.about.AboutComponent;
import org.dhis2.usescases.about.AboutModule;
import org.dhis2.usescases.datasets.datasetDetail.DataSetDetailComponent;
Expand Down Expand Up @@ -125,9 +123,6 @@ public interface UserComponent {
@NonNull
SmsComponent plus(SmsModule smsModule);

@NonNull
SyncGranularRxComponent plus(SyncGranularRxModule syncGranularRxModule);

@NonNull
SyncComponent plus(SyncModule syncModule);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ import androidx.lifecycle.LiveData
import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import androidx.work.Data
import androidx.work.ExistingWorkPolicy
import androidx.work.WorkInfo
import io.reactivex.disposables.CompositeDisposable
Expand All @@ -39,14 +38,7 @@ import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.flow.update
import kotlinx.coroutines.launch
import org.dhis2.commons.Constants
import org.dhis2.commons.Constants.ATTRIBUTE_OPTION_COMBO
import org.dhis2.commons.Constants.CATEGORY_OPTION_COMBO
import org.dhis2.commons.Constants.CONFLICT_TYPE
import org.dhis2.commons.Constants.ORG_UNIT
import org.dhis2.commons.Constants.PERIOD_ID
import org.dhis2.commons.Constants.UID
import org.dhis2.commons.schedulers.SchedulerProvider
import org.dhis2.commons.sync.ConflictType
import org.dhis2.commons.sync.ConflictType.ALL
import org.dhis2.commons.sync.ConflictType.DATA_SET
import org.dhis2.commons.sync.ConflictType.DATA_VALUES
Expand All @@ -58,7 +50,9 @@ import org.dhis2.commons.viewmodel.DispatcherProvider
import org.dhis2.data.service.workManager.WorkManagerController
import org.dhis2.data.service.workManager.WorkerItem
import org.dhis2.data.service.workManager.WorkerType
import org.dhis2.mobile.sync.data.GranularSyncWorker
import org.dhis2.mobile.sync.data.SyncBackgroundJobAction
import org.dhis2.mobile.sync.model.GranularSyncType
import org.dhis2.usescases.sms.SmsSendingService
import org.dhis2.utils.granularsync.data.GranularSyncRepository
import org.dhis2.utils.granularsync.domain.MissingSyncTargetException
Expand Down Expand Up @@ -140,48 +134,47 @@ class GranularSyncPresenter(

fun initGranularSync(): LiveData<List<WorkInfo>> {
viewModelScope.launch(dispatcher.io()) {
var conflictTypeData: ConflictType? = null
var dataToDataValues: Data? = null

when (syncContext.conflictType()) {
PROGRAM -> conflictTypeData = PROGRAM
TEI -> conflictTypeData = TEI
EVENT -> conflictTypeData = EVENT
DATA_SET -> conflictTypeData = DATA_SET
DATA_VALUES ->
with(syncContext as SyncContext.DataSetInstance) {
dataToDataValues =
Data
.Builder()
.putString(UID, recordUid())
.putString(CONFLICT_TYPE, DATA_VALUES.name)
.putString(ORG_UNIT, orgUnitUid)
.putString(PERIOD_ID, periodId)
.putString(ATTRIBUTE_OPTION_COMBO, attributeOptionComboUid)
.putStringArray(
CATEGORY_OPTION_COMBO,
getDataSetCatOptCombos().toTypedArray(),
).build()
}
val workerData =
when (syncContext.conflictType()) {
PROGRAM,
TEI,
EVENT,
DATA_SET,
->
GranularSyncWorker.buildInputData(
uid = syncContext.recordUid(),
granularSyncType =
when (syncContext.conflictType()) {
PROGRAM -> GranularSyncType.Program
TEI -> GranularSyncType.Tei
EVENT -> GranularSyncType.Event
DATA_SET -> GranularSyncType.DataSet
else -> error("Unsupported conflict type")
},
)

DATA_VALUES ->
with(syncContext as SyncContext.DataSetInstance) {
GranularSyncWorker.buildInputData(
uid = recordUid(),
granularSyncType = GranularSyncType.DataValue,
orgUnitUid = orgUnitUid,
periodId = periodId,
attrOptionComboUid = attributeOptionComboUid,
catOptionCombo = getDataSetCatOptCombos(),
)
}

ALL -> { // Do nothing
ALL -> { // Do nothing
null
}
}
}
if (syncContext.conflictType() != ALL) {
if (dataToDataValues == null) {
dataToDataValues =
Data
.Builder()
.putString(UID, syncContext.recordUid())
.putString(CONFLICT_TYPE, conflictTypeData!!.name)
.build()
}

val workerItem =
WorkerItem(
workerName,
WorkerType.GRANULAR,
data = dataToDataValues,
data = workerData,
policy = ExistingWorkPolicy.KEEP,
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ private const val SYNC_DATA_CHANNEL_NAME = "sync_data"
private const val SYNC_SETTINGS_NOTIFICATION_ID = 28042023
private const val SYNC_SETTINGS_CHANNEL_ID = "sync_settings_notification"
private const val SYNC_SETTINGS_CHANNEL_NAME = "sync_settings"
private const val SYNC_GRANULAR_NOTIFICATION_ID = 85043681
private const val SYNC_GRANULAR_CHANNEL_ID = "sync_granular_notification"
private const val SYNC_GRANULAR_CHANNEL_NAME = "sync_granular"

class NotificationManagerImpl(
private val context: Context,
Expand Down Expand Up @@ -83,6 +86,22 @@ class NotificationManagerImpl(
),
)

override fun getGranularSyncNotification(
smallIcon: Int,
contentTitle: String,
contentText: String,
) = WorkerNotificationInfo(
createForegroundInfo(
notificationId = SYNC_METADATA_NOTIFICATION_ID,
channelId = SYNC_GRANULAR_CHANNEL_ID,
channelName = SYNC_GRANULAR_CHANNEL_NAME,
smallIcon = smallIcon,
contentTitle = contentTitle,
contentText = contentText,
progress = -1,
),
)

override fun displayMetadataSyncNotification(
smallIcon: Int,
contentTitle: String,
Expand Down Expand Up @@ -137,6 +156,24 @@ class NotificationManagerImpl(
notify(foregroundInfo)
}

override fun displayGranularSyncNotification(
smallIcon: Int,
contentTitle: String,
contentText: String,
) {
val foregroundInfo =
createForegroundInfo(
notificationId = SYNC_GRANULAR_NOTIFICATION_ID,
channelId = SYNC_GRANULAR_CHANNEL_ID,
channelName = SYNC_GRANULAR_CHANNEL_NAME,
smallIcon = smallIcon,
contentTitle = contentTitle,
contentText = contentText,
progress = -1,
)
notify(foregroundInfo)
}

override fun cancelMetadataSyncNotification() {
notificationManager.cancel(SYNC_METADATA_NOTIFICATION_ID)
}
Expand All @@ -149,6 +186,10 @@ class NotificationManagerImpl(
notificationManager.cancel(SYNC_DATA_NOTIFICATION_ID)
}

override fun cancelGranularSyncNotification() {
notificationManager.cancel(SYNC_METADATA_NOTIFICATION_ID)
}

private fun createForegroundInfo(
notificationId: Int,
channelId: String,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,18 @@ interface NotificationManager {
fun cancelSyncSettingsNotification()

fun cancelDataSyncNotification()

fun displayGranularSyncNotification(
smallIcon: Int,
contentTitle: String,
contentText: String,
)

fun cancelGranularSyncNotification()

fun getGranularSyncNotification(
smallIcon: Int,
contentTitle: String,
contentText: String,
): NotificationModel
}
Loading