Skip to content

Commit

Permalink
Merge pull request #323 from hannesa2/KotlinDownloaders
Browse files Browse the repository at this point in the history
Kotlin downloaders
  • Loading branch information
hannesa2 authored May 17, 2024
2 parents 53d72d4 + 4165f0f commit c59d488
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 118 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.panoramagl.downloaders

interface PLFileDownloaderListener {
fun didBeginDownload(url: String?, startTime: Long)

fun didProgressDownload(url: String?, progress: Int)

fun didStopDownload(url: String?)

fun didEndDownload(url: String?, data: ByteArray?, elapsedTime: Long)

fun didErrorDownload(url: String?, error: String?, responseCode: Int, data: ByteArray?)
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.panoramagl.downloaders

interface PLIFileDownloaderManager {
val isRunning: Boolean

fun add(fileDownloader: PLIFileDownloader?)

fun remove(fileDownloader: PLIFileDownloader?): Boolean

fun removeAll(): Boolean

fun download(fileDownloader: PLIFileDownloader?)

fun start(): Boolean

fun stop(): Boolean
}
Original file line number Diff line number Diff line change
Expand Up @@ -46,15 +46,17 @@ class PLLocalFileDownloader(private var context: Context, url: String?, listener
val file = File(url.substring(7))
if (file.canRead()) `is` = FileInputStream(file)
}
} else throw PLRequestInvalidatedException(url)
} else
throw PLRequestInvalidatedException(url)
if (this.isRunning) {
result = ByteArray(`is`!!.available())
`is`.read(result)
if (hasListener) {
listener!!.didProgressDownload(url, 100)
listener.didEndDownload(url, result, System.currentTimeMillis() - startTime)
}
} else throw PLRequestInvalidatedException(url)
} else
throw PLRequestInvalidatedException(url)
} catch (e: Throwable) {
if (this.isRunning) {
Timber.e(e)
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package com.panoramagl.downloaders

class PLRequestInvalidatedException(url: String) : RuntimeException(String.format("Request to %s was invalidated", url))

0 comments on commit c59d488

Please sign in to comment.