Request.kt 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. /*
  2. * Nextcloud Android client application
  3. *
  4. * @author Chris Narkiewicz
  5. * Copyright (C) 2020 Chris Narkiewicz <hello@ezaquarii.com>
  6. *
  7. * This program is free software: you can redistribute it and/or modify
  8. * it under the terms of the GNU Affero General Public License as published by
  9. * the Free Software Foundation, either version 3 of the License, or
  10. * (at your option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU Affero General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU Affero General Public License
  18. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  19. */
  20. package com.nextcloud.client.files.downloader
  21. import android.os.Parcel
  22. import android.os.Parcelable
  23. import com.nextcloud.client.account.User
  24. import com.owncloud.android.datamodel.OCFile
  25. import java.util.UUID
  26. /**
  27. * Download request. This class should collect all information
  28. * required to trigger download operation.
  29. *
  30. * Class is immutable by design, although [OCFile] or other
  31. * types might not be immutable. Clients should no modify
  32. * contents of this object.
  33. *
  34. * @property user Download will be triggered for a given user
  35. * @property file Remote file to download
  36. * @property uuid Unique request identifier; this identifier can be set in [Download]
  37. * @property dummy if true, this requests a dummy test download; no real file transfer will occur
  38. */
  39. class Request internal constructor(
  40. val user: User,
  41. val file: OCFile,
  42. val uuid: UUID,
  43. val test: Boolean = false
  44. ) : Parcelable {
  45. constructor(user: User, file: OCFile) : this(user, file, UUID.randomUUID())
  46. constructor(user: User, file: OCFile, test: Boolean) : this(user, file, UUID.randomUUID(), test)
  47. constructor(parcel: Parcel) : this(
  48. user = parcel.readParcelable<User>(User::class.java.classLoader) as User,
  49. file = parcel.readParcelable<OCFile>(OCFile::class.java.classLoader) as OCFile,
  50. uuid = parcel.readSerializable() as UUID,
  51. test = parcel.readInt() != 0
  52. )
  53. override fun writeToParcel(parcel: Parcel, flags: Int) {
  54. parcel.writeParcelable(user, flags)
  55. parcel.writeParcelable(file, flags)
  56. parcel.writeSerializable(uuid)
  57. parcel.writeInt(if (test) 1 else 0)
  58. }
  59. override fun describeContents(): Int {
  60. return 0
  61. }
  62. companion object CREATOR : Parcelable.Creator<Request> {
  63. override fun createFromParcel(parcel: Parcel): Request {
  64. return Request(parcel)
  65. }
  66. override fun newArray(size: Int): Array<Request?> {
  67. return arrayOfNulls(size)
  68. }
  69. }
  70. }