SyncedFolder.java 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. /*
  2. * Nextcloud Android client application
  3. *
  4. * @author Tobias Kaminsky
  5. * Copyright (C) 2016 Tobias Kaminsky
  6. * Copyright (C) 2016 Nextcloud
  7. *
  8. * This program is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
  10. * License as published by the Free Software Foundation; either
  11. * version 3 of the License, or any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU AFFERO GENERAL PUBLIC LICENSE for more details.
  17. *
  18. * You should have received a copy of the GNU Affero General Public
  19. * License along with this program. If not, see <http://www.gnu.org/licenses/>.
  20. */
  21. package com.owncloud.android.datamodel;
  22. import java.io.Serializable;
  23. import lombok.Getter;
  24. import lombok.Setter;
  25. /**
  26. * Synced folder entity containing all information per synced folder.
  27. */
  28. public class SyncedFolder implements Serializable, Cloneable {
  29. public static final long UNPERSISTED_ID = Long.MIN_VALUE;
  30. public static final long EMPTY_ENABLED_TIMESTAMP_MS = -1;
  31. private static final long serialVersionUID = -793476118299906429L;
  32. @Getter @Setter private long id;
  33. @Getter @Setter private String localPath;
  34. @Getter @Setter private String remotePath;
  35. @Getter @Setter private boolean wifiOnly;
  36. @Getter @Setter private boolean chargingOnly;
  37. @Getter @Setter private boolean existing;
  38. @Getter @Setter private boolean subfolderByDate;
  39. @Getter @Setter private String account;
  40. @Getter @Setter private int uploadAction;
  41. @Getter private boolean enabled;
  42. @Getter private long enabledTimestampMs;
  43. @Getter @Setter private MediaFolderType type;
  44. @Getter @Setter private boolean hidden;
  45. /**
  46. * constructor for new, to be persisted entity.
  47. *
  48. * @param localPath local path
  49. * @param remotePath remote path
  50. * @param wifiOnly upload on wifi only flag
  51. * @param chargingOnly upload on charging only
  52. * @param existing upload existing files
  53. * @param subfolderByDate create sub-folders by date (month)
  54. * @param account the account owning the synced folder
  55. * @param uploadAction the action to be done after the upload
  56. * @param enabled flag if synced folder config is active
  57. * @param timestampMs the current timestamp in milliseconds
  58. * @param type the type of the folder
  59. * @param hidden hide item flag
  60. */
  61. public SyncedFolder(String localPath,
  62. String remotePath,
  63. boolean wifiOnly,
  64. boolean chargingOnly,
  65. boolean existing,
  66. boolean subfolderByDate,
  67. String account,
  68. int uploadAction,
  69. boolean enabled,
  70. long timestampMs,
  71. MediaFolderType type,
  72. boolean hidden) {
  73. this(UNPERSISTED_ID, localPath, remotePath, wifiOnly, chargingOnly, existing, subfolderByDate, account,
  74. uploadAction, enabled, timestampMs, type, hidden);
  75. }
  76. /**
  77. * constructor for wrapping existing folders.
  78. *
  79. * @param id id
  80. */
  81. protected SyncedFolder(long id,
  82. String localPath,
  83. String remotePath,
  84. boolean wifiOnly,
  85. boolean chargingOnly,
  86. boolean existing,
  87. boolean subfolderByDate,
  88. String account,
  89. int uploadAction,
  90. boolean enabled,
  91. long timestampMs,
  92. MediaFolderType type,
  93. boolean hidden) {
  94. this.id = id;
  95. this.localPath = localPath;
  96. this.remotePath = remotePath;
  97. this.wifiOnly = wifiOnly;
  98. this.chargingOnly = chargingOnly;
  99. this.existing = existing;
  100. this.subfolderByDate = subfolderByDate;
  101. this.account = account;
  102. this.uploadAction = uploadAction;
  103. this.setEnabled(enabled, timestampMs);
  104. this.type = type;
  105. this.hidden = hidden;
  106. }
  107. /**
  108. * @param timestampMs the current timestamp in milliseconds
  109. */
  110. public void setEnabled(boolean enabled, long timestampMs) {
  111. this.enabled = enabled;
  112. this.enabledTimestampMs = enabled ? timestampMs : EMPTY_ENABLED_TIMESTAMP_MS;
  113. }
  114. public Object clone() {
  115. try {
  116. return super.clone();
  117. } catch (CloneNotSupportedException e) {
  118. return null;
  119. }
  120. }
  121. }