-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c6d380b
commit 08e2ca7
Showing
16 changed files
with
315 additions
and
134 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
app/src/main/java/by/alexandr7035/votekt/data/workers/RefreshSelfBalanceWorker.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package by.alexandr7035.votekt.data.workers | ||
|
||
import android.content.Context | ||
import android.util.Log | ||
import androidx.work.Constraints | ||
import androidx.work.CoroutineWorker | ||
import androidx.work.NetworkType | ||
import androidx.work.WorkerParameters | ||
import by.alexandr7035.votekt.domain.core.OperationResult | ||
import by.alexandr7035.votekt.domain.repository.AccountRepository | ||
|
||
class RefreshSelfBalanceWorker( | ||
appContext: Context, | ||
params: WorkerParameters, | ||
private val accountRepository: AccountRepository | ||
) : CoroutineWorker(appContext, params) { | ||
override suspend fun doWork(): Result { | ||
val result = OperationResult.runWrapped { | ||
accountRepository.refreshBalance() | ||
} | ||
return when (result) { | ||
is OperationResult.Failure -> { | ||
Log.d(TAG, "balance sync error ${result.error.message}") | ||
Result.failure() | ||
} | ||
|
||
is OperationResult.Success -> { | ||
Log.d(TAG, "balance sync success") | ||
Result.success() | ||
} | ||
} | ||
} | ||
|
||
companion object { | ||
val TAG = this::class.java.simpleName | ||
|
||
val CONSTRAINTS = Constraints.Builder() | ||
.setRequiredNetworkType(NetworkType.CONNECTED) | ||
.setRequiresBatteryNotLow(false) | ||
.build() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 11 additions & 0 deletions
11
app/src/main/java/by/alexandr7035/votekt/domain/usecase/account/RefreshBalanceUseCase.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package by.alexandr7035.votekt.domain.usecase.account | ||
|
||
import by.alexandr7035.votekt.domain.repository.AccountRepository | ||
|
||
class RefreshBalanceUseCase( | ||
private val accountRepository: AccountRepository | ||
) { | ||
suspend fun invoke() { | ||
accountRepository.refreshBalance() | ||
} | ||
} |
Oops, something went wrong.