This commit is contained in:
Davide Depau 2019-07-24 06:55:55 +02:00
parent 6afef7662b
commit 40ae8639a4
14 changed files with 166 additions and 23 deletions

View file

@ -40,6 +40,7 @@ dependencies {
implementation 'androidx.core:core:1.2.0-alpha02'
implementation 'androidx.fragment:fragment:1.2.0-alpha01'
implementation 'androidx.swiperefreshlayout:swiperefreshlayout:1.1.0-alpha02'
implementation 'com.github.Depau:kotlet-android:v0.2.4'
api 'com.google.guava:guava:27.0.1-android'
api 'com.github.codekidX:storage-chooser:2.0.4.2'

View file

@ -0,0 +1,13 @@
package eu.depau.etchdroid.broadcasts
import android.content.Intent
import eu.depau.etchdroid.worker.dto.ProgressUpdateDTO
object JobProgressUpdateBroadcast {
val action = "eu.depau.etchdroid.broadcast.JOB_PROGRESS_UPDATE"
fun getIntent(dto: ProgressUpdateDTO) = Intent().apply {
action = this@JobProgressUpdateBroadcast.action
putExtra("data", dto)
}
}

View file

@ -0,0 +1,11 @@
package eu.depau.etchdroid.utils.ktexts
import android.content.Context
import android.content.Intent
import androidx.localbroadcastmanager.content.LocalBroadcastManager
fun Intent.sendBroadcast(context: Context) = context.sendBroadcast(this)
fun Intent.sendBroadcast(context: Context, receiverPermission: String) = context.sendBroadcast(this, receiverPermission)
fun Intent.sendLocalBroadcast(context: Context) = LocalBroadcastManager.getInstance(context).sendBroadcast(this)
fun Intent.sendLocalBroadcastSync(context: Context) = LocalBroadcastManager.getInstance(context).sendBroadcastSync(this)

View file

@ -1,6 +1,6 @@
package eu.depau.etchdroid.worker
interface IAsyncWorker: IProgressSender {
suspend fun run()
suspend fun runStep(): Boolean
fun run()
fun runStep(): Boolean
}

View file

@ -1,7 +1,9 @@
package eu.depau.etchdroid.worker
package eu.depau.etchdroid.worker.abstractimpl
import eu.depau.etchdroid.worker.IAsyncWorker
abstract class AbstractAsyncWorker : IAsyncWorker, AbstractProgressSender() {
override suspend fun run() {
override fun run() {
while (runStep()) {
}
}

View file

@ -1,4 +1,4 @@
package eu.depau.etchdroid.worker
package eu.depau.etchdroid.worker.abstractimpl
import eu.depau.etchdroid.worker.dto.ProgressUpdateDTO
@ -26,7 +26,7 @@ abstract class AbstractAutoProgressAsyncWorker(private val totalToDo: Long) : Ab
val timeRemainingMillis: Long = ((totalToDo - doneAccumulator) / speedUnitPerMillis).toLong()
val dto = progressUpdateDTO.copy(
operationProgress = progress,
jobProgress = progress,
stepProgress = progress,
timeRemaining = timeRemainingMillis,
currentRate = speedUnitPerMillis * 1000

View file

@ -1,5 +1,7 @@
package eu.depau.etchdroid.worker
package eu.depau.etchdroid.worker.abstractimpl
import eu.depau.etchdroid.worker.IProgressListener
import eu.depau.etchdroid.worker.IProgressSender
import eu.depau.etchdroid.worker.dto.ProgressDoneDTO
import eu.depau.etchdroid.worker.dto.ProgressStartDTO
import eu.depau.etchdroid.worker.dto.ProgressUpdateDTO

View file

@ -1,10 +1,31 @@
package eu.depau.etchdroid.worker.dto
import android.os.Parcel
import android.os.Parcelable
import eu.depau.etchdroid.worker.enums.ErrorType
import eu.depau.kotlet.android.parcelable.*
data class ProgressDoneDTO(
val operationId: Int,
val jobId: Long,
val error: ErrorType?,
val errorData: Parcelable?
)
) : KotletParcelable {
constructor(parcel: Parcel) : this(
jobId = parcel.readLong(),
error = parcel.readNullable { parcel.readEnum<ErrorType>() },
errorData = parcel.readNullable { parcel.readParcelable(Parcelable::class.java.classLoader) }
)
override fun writeToParcel(parcel: Parcel, flags: Int) {
parcel.apply {
writeLong(jobId)
writeNullable(error) { writeEnum(it) }
writeNullable(errorData) { writeParcelable(errorData, flags) }
}
}
companion object {
@JvmField
val CREATOR = parcelableCreator(::ProgressDoneDTO)
}
}

View file

@ -1,13 +1,41 @@
package eu.depau.etchdroid.worker.dto
import eu.depau.etchdroid.worker.enums.OperationType
import android.os.Parcel
import eu.depau.etchdroid.worker.enums.JobType
import eu.depau.etchdroid.worker.enums.StepType
import java.util.*
import eu.depau.kotlet.android.parcelable.KotletParcelable
import eu.depau.kotlet.android.parcelable.parcelableCreator
import eu.depau.kotlet.android.parcelable.readEnum
import eu.depau.kotlet.android.parcelable.writeEnum
data class ProgressStartDTO(
val operationId: Int,
val operationType: OperationType,
val jobId: Long,
val jobType: JobType,
val inputName: String,
val outputName: String,
val steps: List<Pair<String, StepType>>
)
val stepsNamesResIDs: List<Int>
) : KotletParcelable {
@Suppress("UNCHECKED_CAST")
constructor(parcel: Parcel) : this(
jobId = parcel.readLong(),
jobType = parcel.readEnum<JobType>()!!,
inputName = parcel.readString()!!,
outputName = parcel.readString()!!,
stepsNamesResIDs = (parcel.readSerializable() as Array<Int>).asList()
)
override fun writeToParcel(parcel: Parcel, flags: Int) {
parcel.apply {
writeLong(jobId)
writeEnum(jobType)
writeString(inputName)
writeString(outputName)
writeSerializable(stepsNamesResIDs.toTypedArray())
}
}
companion object {
@JvmField
val CREATOR = parcelableCreator(::ProgressStartDTO)
}
}

View file

@ -1,13 +1,42 @@
package eu.depau.etchdroid.worker.dto
import android.os.Parcel
import eu.depau.etchdroid.worker.enums.RateUnit
import eu.depau.kotlet.android.parcelable.*
data class ProgressUpdateDTO(
val operationId: Int,
val jobId: Long,
val currentStep: Int,
val operationProgress: Double,
val jobProgress: Double,
val stepProgress: Double?,
val timeRemaining: Long?,
val currentRate: Double?,
val rateUnit: RateUnit?
)
) : KotletParcelable {
constructor(parcel: Parcel) : this(
jobId = parcel.readLong(),
currentStep = parcel.readInt(),
jobProgress = parcel.readDouble(),
stepProgress = parcel.readNullable { parcel.readDouble() },
timeRemaining = parcel.readNullable { parcel.readLong() },
currentRate = parcel.readNullable { parcel.readDouble() },
rateUnit = parcel.readNullable { parcel.readEnum<RateUnit>() }
)
override fun writeToParcel(parcel: Parcel, flags: Int) {
parcel.apply {
writeLong(jobId)
writeInt(currentStep)
writeDouble(jobProgress)
writeNullable(stepProgress) { writeDouble(it) }
writeNullable(timeRemaining) { writeLong(it) }
writeNullable(currentRate) { writeDouble(it) }
writeNullable(rateUnit) { writeEnum(rateUnit) }
}
}
companion object {
@JvmField
val CREATOR = parcelableCreator(::ProgressUpdateDTO)
}
}

View file

@ -1,6 +1,6 @@
package eu.depau.etchdroid.worker.enums
enum class OperationType {
enum class JobType {
FLASH_RAW_IMAGE,
FLASH_DMG,
FLASH_ELTORITO,

View file

@ -0,0 +1,29 @@
package eu.depau.etchdroid.worker.impl
import android.content.Context
import eu.depau.etchdroid.worker.IProgressListener
import eu.depau.etchdroid.worker.dto.ProgressDoneDTO
import eu.depau.etchdroid.worker.dto.ProgressStartDTO
import eu.depau.etchdroid.worker.dto.ProgressUpdateDTO
class BroadcastProgressForwarder(
val jobId: Long,
val context: Context
): IProgressListener {
override fun notifyStart(dto: ProgressStartDTO) {
TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
}
override fun notifyProgress(dto: ProgressUpdateDTO) {
TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
}
override fun notifyDone(dto: ProgressDoneDTO) {
TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
}
fun stopForwarding() {
}
}

View file

@ -1,6 +1,13 @@
package eu.depau.etchdroid.worker.impl
import eu.depau.etchdroid.worker.AbstractAutoProgressAsyncWorker
import eu.depau.etchdroid.worker.abstractimpl.AbstractAutoProgressAsyncWorker
import eu.depau.etchdroid.worker.dto.ProgressUpdateDTO
class Dmg2OutputStreamConvertAsyncService: AbstractAutoProgressAsyncWorker() {
class Dmg2OutputStreamConvertAsyncService(private val totalToDo: Long): AbstractAutoProgressAsyncWorker(totalToDo) {
override val progressUpdateDTO: ProgressUpdateDTO
get() = TODO("not implemented") //To change initializer of created properties use File | Settings | File Templates.
override fun runStep(): Boolean {
TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
}
}

View file

@ -1,6 +1,6 @@
package eu.depau.etchdroid.worker.impl
import eu.depau.etchdroid.worker.AbstractAutoProgressAsyncWorker
import eu.depau.etchdroid.worker.abstractimpl.AbstractAutoProgressAsyncWorker
import eu.depau.etchdroid.worker.dto.ProgressUpdateDTO
import java.io.InputStream
import java.io.OutputStream
@ -16,7 +16,7 @@ open class Input2OutputStreamCopyAsyncWorker(
private val buffer = ByteArray(chunkSize)
override suspend fun runStep(): Boolean {
override fun runStep(): Boolean {
val readBytes = source.read(buffer)
if (readBytes < 0)