-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'develop' into feature-i18n
- Loading branch information
Showing
13 changed files
with
223 additions
and
93 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
61 changes: 61 additions & 0 deletions
61
app/src/main/java/io/numbersprotocol/starlingcapture/collector/CollectWorker.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,61 @@ | ||
package io.numbersprotocol.starlingcapture.collector | ||
|
||
import android.content.Context | ||
import androidx.annotation.StringRes | ||
import androidx.work.CoroutineWorker | ||
import androidx.work.WorkerParameters | ||
import io.numbersprotocol.starlingcapture.util.MimeType | ||
import io.numbersprotocol.starlingcapture.util.NotificationUtil | ||
import org.koin.core.KoinComponent | ||
import org.koin.core.inject | ||
import kotlin.properties.Delegates | ||
|
||
abstract class CollectWorker( | ||
val context: Context, | ||
params: WorkerParameters | ||
) : CoroutineWorker(context, params), KoinComponent { | ||
|
||
abstract val name: String | ||
|
||
lateinit var hash: String | ||
lateinit var mimeType: MimeType | ||
private var notificationId by Delegates.notNull<Int>() | ||
private val notificationUtil: NotificationUtil by inject() | ||
|
||
private fun initialize() { | ||
hash = inputData.getString(ProofCollector.KEY_HASH)!! | ||
mimeType = MimeType.fromString(inputData.getString(ProofCollector.KEY_MIME_TYPE)!!) | ||
|
||
val illegalNotificationId = NotificationUtil.NOTIFICATION_ID_MIN - 1 | ||
notificationId = inputData.getInt(ProofCollector.KEY_NOTIFICATION_ID, illegalNotificationId) | ||
if (notificationId == illegalNotificationId) error("Cannot get notification ID from input data.") | ||
} | ||
|
||
override suspend fun doWork(): Result { | ||
initialize() | ||
return try { | ||
onStarted() | ||
collect() | ||
onCleared() | ||
Result.success() | ||
} catch (e: Exception) { | ||
notificationUtil.notifyException(e, notificationId) | ||
Result.failure() | ||
} finally { | ||
onCleared() | ||
} | ||
} | ||
|
||
open suspend fun onStarted() {} | ||
abstract suspend fun collect() | ||
open suspend fun onCleared() {} | ||
|
||
protected fun notifyStartCollecting(@StringRes stringRes: Int) { | ||
val builder = ProofCollector.getNotificationBuilder(context).apply { | ||
setContentText(context.resources.getString(stringRes)) | ||
setProgress(0, 0, true) | ||
setOngoing(true) | ||
} | ||
notificationUtil.notify(notificationId, builder) | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
app/src/main/java/io/numbersprotocol/starlingcapture/collector/InformationProvider.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,22 @@ | ||
package io.numbersprotocol.starlingcapture.collector | ||
|
||
import android.content.Context | ||
import androidx.work.WorkerParameters | ||
import io.numbersprotocol.starlingcapture.R | ||
import io.numbersprotocol.starlingcapture.data.information.Information | ||
import io.numbersprotocol.starlingcapture.data.information.InformationRepository | ||
import org.koin.core.inject | ||
|
||
abstract class InformationProvider( | ||
context: Context, params: WorkerParameters | ||
) : CollectWorker(context, params) { | ||
|
||
private val informationRepository: InformationRepository by inject() | ||
|
||
override suspend fun collect() { | ||
notifyStartCollecting(R.string.message_collecting_proof_information) | ||
informationRepository.add(*provide().toTypedArray()) | ||
} | ||
|
||
abstract suspend fun provide(): Collection<Information> | ||
} |
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
30 changes: 30 additions & 0 deletions
30
app/src/main/java/io/numbersprotocol/starlingcapture/collector/SignatureProvider.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,30 @@ | ||
package io.numbersprotocol.starlingcapture.collector | ||
|
||
import android.content.Context | ||
import androidx.work.WorkerParameters | ||
import io.numbersprotocol.starlingcapture.R | ||
import io.numbersprotocol.starlingcapture.data.information.InformationRepository | ||
import io.numbersprotocol.starlingcapture.data.proof.ProofRepository | ||
import io.numbersprotocol.starlingcapture.data.serialization.SortedProofInformation | ||
import io.numbersprotocol.starlingcapture.data.signature.Signature | ||
import io.numbersprotocol.starlingcapture.data.signature.SignatureRepository | ||
import org.koin.core.inject | ||
|
||
abstract class SignatureProvider( | ||
context: Context, params: WorkerParameters | ||
) : CollectWorker(context, params) { | ||
|
||
private val proofRepository: ProofRepository by inject() | ||
private val informationRepository: InformationRepository by inject() | ||
private val signatureRepository: SignatureRepository by inject() | ||
|
||
override suspend fun collect() { | ||
notifyStartCollecting(R.string.message_signing_proof_information) | ||
val proof = proofRepository.getByHash(hash)!! | ||
val sortedProofInformation = SortedProofInformation.create(proof, informationRepository) | ||
val json = sortedProofInformation.toJson() | ||
signatureRepository.add(*provide(json).toTypedArray()) | ||
} | ||
|
||
abstract suspend fun provide(serialized: String): Collection<Signature> | ||
} |
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
Oops, something went wrong.