Skip to content

Commit

Permalink
refactor: Move logic to KMP
Browse files Browse the repository at this point in the history
  • Loading branch information
KevinBoulongne committed Dec 4, 2024
1 parent 475b3b3 commit d2615ed
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,10 @@ package com.infomaniak.swisstransfer.ui
import android.app.Application
import androidx.hilt.work.HiltWorkerFactory
import androidx.work.Configuration
import com.infomaniak.multiplatform_swisstransfer.common.interfaces.ui.TransferUi
import com.infomaniak.multiplatform_swisstransfer.common.models.TransferDirection
import com.infomaniak.multiplatform_swisstransfer.managers.AccountManager
import com.infomaniak.multiplatform_swisstransfer.managers.TransferManager
import com.infomaniak.swisstransfer.BuildConfig
import com.infomaniak.swisstransfer.ui.utils.AccountUtils
import com.infomaniak.swisstransfer.ui.utils.getExpiredTransfers
import dagger.hilt.android.HiltAndroidApp
import io.sentry.SentryEvent
import io.sentry.SentryOptions
Expand Down Expand Up @@ -62,7 +59,7 @@ class MainApplication : Application(), Configuration.Provider {

globalCoroutineScope.launch {
accountUtils.init()
collectTransfers()
transferManager.deleteExpiredTransfers()
}

SentryAndroid.init(this) { options: SentryAndroidOptions ->
Expand All @@ -73,17 +70,4 @@ class MainApplication : Application(), Configuration.Provider {
}
}
}

private suspend fun collectTransfers() {
transferManager.getTransfers(TransferDirection.SENT).collect(::deleteExpiredTransfers)
transferManager.getTransfers(TransferDirection.RECEIVED).collect(::deleteExpiredTransfers)
}

private suspend fun deleteExpiredTransfers(transfers: List<TransferUi>) {
deleteTransfers(transfers.getExpiredTransfers(since = 15))
}

private suspend fun deleteTransfers(transfers: List<TransferUi>) {
transfers.forEach { transferManager.deleteTransfer(it.uuid) }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,3 @@ package com.infomaniak.swisstransfer.ui.utils
import com.infomaniak.multiplatform_swisstransfer.common.interfaces.ui.TransferUi

val TransferUi.isExpired: Boolean get() = expiresInDays < 0 || downloadLeft <= 0

/**
* Get Transfers that are expired since a certain amount of days.
*
* @param since The amount of days since this Transfer is expired.
*/
fun List<TransferUi>.getExpiredTransfers(since: Int): List<TransferUi> = filter { it.expiresInDays < -since }

0 comments on commit d2615ed

Please sign in to comment.