Skip to content

Commit

Permalink
file server improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
tonyofrancis committed Jul 9, 2018
1 parent 5a4cf8a commit 3ac42d3
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.tonyodev.fetch2core.transporter

import android.os.Parcel
import android.os.Parcelable
import java.lang.StringBuilder

/**
Expand All @@ -14,7 +16,7 @@ data class FileRequest(val type: Int = TYPE_INVALID,
val customData: String = "",
val page: Int = 0,
val size: Int = 0,
val persistConnection: Boolean = true) {
val persistConnection: Boolean = true) : Parcelable {

val toJsonString: String
get() {
Expand All @@ -34,7 +36,24 @@ data class FileRequest(val type: Int = TYPE_INVALID,
return builder.toString()
}

companion object {
override fun writeToParcel(dest: Parcel, flags: Int) {
dest.writeInt(type)
dest.writeString(fileResourceId)
dest.writeLong(rangeStart)
dest.writeLong(rangeEnd)
dest.writeString(authorization)
dest.writeString(client)
dest.writeString(customData)
dest.writeInt(page)
dest.writeInt(size)
dest.writeInt(if (persistConnection) 1 else 0)
}

override fun describeContents(): Int {
return 0
}

companion object CREATOR : Parcelable.Creator<FileRequest> {

const val TYPE_INVALID = -1
const val TYPE_PING = 0
Expand All @@ -52,6 +71,25 @@ data class FileRequest(val type: Int = TYPE_INVALID,
const val FIELD_SIZE = "Size"
const val FIELD_PERSIST_CONNECTION = "PersistConnection"


override fun createFromParcel(source: Parcel): FileRequest {
return FileRequest(
type = source.readInt(),
fileResourceId = source.readString(),
rangeStart = source.readLong(),
rangeEnd = source.readLong(),
authorization = source.readString(),
client = source.readString(),
customData = source.readString(),
page = source.readInt(),
size = source.readInt(),
persistConnection = source.readInt() == 1)
}

override fun newArray(size: Int): Array<FileRequest?> {
return arrayOfNulls(size)
}

}

}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package com.tonyodev.fetch2downloaders

import com.tonyodev.fetch2core.*

import com.tonyodev.fetch2core.transporter.FileRequest.Companion.TYPE_FILE
import com.tonyodev.fetch2core.transporter.FileRequest.CREATOR.TYPE_FILE
import com.tonyodev.fetch2core.transporter.FetchFileResourceTransporter
import com.tonyodev.fetch2core.transporter.FileRequest
import com.tonyodev.fetch2core.transporter.FileResponse
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ class FetchFileServerImpl(context: Context,
return try {
val id: Long = fileResourceIdentifier.toLong()
if (id == FileRequest.CATALOG_ID) {
val catalog = fileResourceServerDatabase.getRequestedCatalog(-1, -1)
val catalog = fileResourceServerDatabase.getRequestedCatalog()
val catalogFileResourceInfo = FileResourceInfo()
catalogFileResourceInfo.id = FileRequest.CATALOG_ID
catalogFileResourceInfo.customData = catalog
Expand Down Expand Up @@ -393,7 +393,7 @@ class FetchFileServerImpl(context: Context,
override fun getCatalog(func: Func<String>) {
synchronized(lock) {
throwIfTerminated()
val catalog = fileResourceServerDatabase.getRequestedCatalog(-1, -1)
val catalog = fileResourceServerDatabase.getRequestedCatalog()
mainHandler.post {
func.call(catalog)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ class FetchFileResourceInfoDatabase(context: Context,
}
}

fun getRequestedCatalog(page: Int, size: Int): String {
fun getRequestedCatalog(page: Int = -1, size: Int = -1): String {
synchronized(lock) {
throwExceptionIfClosed()
val fileResources = getAll(page, size)
Expand Down

0 comments on commit 3ac42d3

Please sign in to comment.