AppPreferences.java 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372
  1. /*
  2. * Nextcloud Android client application
  3. *
  4. * @author Chris Narkiewicz
  5. * Copyright (C) 2019 Chris Narkiewicz, EZ Aquarii
  6. *
  7. * This program is free software: you can redistribute it and/or modify
  8. * it under the terms of the GNU 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 General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  19. */
  20. package com.nextcloud.client.preferences;
  21. import com.owncloud.android.datamodel.OCFile;
  22. import com.owncloud.android.utils.FileSortOrder;
  23. import androidx.annotation.Nullable;
  24. /**
  25. * This interface provides single point of entry for access to all application
  26. * preferences and allows clients to subscribe for specific configuration
  27. * changes.
  28. */
  29. public interface AppPreferences {
  30. /**
  31. * Preferences listener. Callbacks should be invoked on main thread.
  32. *
  33. * Maintainers should extend this interface with callbacks for specific
  34. * events.
  35. */
  36. interface Listener {
  37. default void onDarkThemeModeChanged(DarkMode mode) {
  38. /* default empty implementation */
  39. };
  40. }
  41. /**
  42. * Registers preferences listener. It no-ops if listener
  43. * is already registered.
  44. *
  45. * @param listener application preferences listener
  46. */
  47. void addListener(@Nullable Listener listener);
  48. /**
  49. * Unregister listener. It no-ops if listener is not registered.
  50. *
  51. * @param listener application preferences listener
  52. */
  53. void removeListener(@Nullable Listener listener);
  54. void setKeysReInitEnabled();
  55. boolean isKeysReInitEnabled();
  56. void setPushToken(String pushToken);
  57. String getPushToken();
  58. boolean instantPictureUploadEnabled();
  59. boolean instantVideoUploadEnabled();
  60. boolean isShowHiddenFilesEnabled();
  61. void setShowHiddenFilesEnabled(boolean enabled);
  62. /**
  63. * Gets the selected file extension position the user selected to do the
  64. * last upload of a url file shared from other app.
  65. *
  66. * @return selectedPos the selected file extension position.
  67. */
  68. int getUploadUrlFileExtensionUrlSelectedPos();
  69. /**
  70. * Saves the selected file extension position the user selected to do the
  71. * last upload of a url file shared from other app.
  72. *
  73. * @param selectedPos the selected file extension position.
  74. */
  75. void setUploadUrlFileExtensionUrlSelectedPos(int selectedPos);
  76. /**
  77. * Gets the selected map file extension position the user selected to
  78. * do the last upload of a url file shared from other app.
  79. *
  80. * @return selectedPos the selected file extension position.
  81. */
  82. int getUploadMapFileExtensionUrlSelectedPos();
  83. /**
  84. * Saves the selected map file extension position the user selected to
  85. * do the last upload of a url file shared from other app.
  86. *
  87. * @param selectedPos the selected file extension position.
  88. */
  89. void setUploadMapFileExtensionUrlSelectedPos(int selectedPos);
  90. /**
  91. * Gets the last local path where the user selected to do an upload from.
  92. *
  93. * @return path Absolute path to a folder, as previously stored by
  94. * {@link #setUploadFromLocalLastPath(String)}, or empty String if never saved before.
  95. */
  96. String getUploadFromLocalLastPath();
  97. /**
  98. * Saves the path where the user selected to do the last local upload of a file from.
  99. *
  100. * @param path Absolute path to a folder.
  101. */
  102. void setUploadFromLocalLastPath(String path);
  103. /**
  104. * Gets the path where the user selected to do the last upload of a file shared from other app.
  105. *
  106. * @return path Absolute path to a folder, as previously stored by {@link #setLastUploadPath(String)},
  107. * or empty String if never saved before.
  108. */
  109. String getLastUploadPath();
  110. /**
  111. * Get preferred folder display type.
  112. *
  113. * @param folder Folder
  114. * @return preference value, default is
  115. * {@link com.owncloud.android.ui.fragment.OCFileListFragment#FOLDER_LAYOUT_LIST}
  116. */
  117. String getFolderLayout(OCFile folder);
  118. /**
  119. * Set preferred folder display type.
  120. *
  121. * @param folder Folder which layout is being set or null for root folder
  122. * @param layoutName preference value
  123. */
  124. void setFolderLayout(@Nullable OCFile folder, String layoutName);
  125. /**
  126. * Saves the path where the user selected to do the last upload of a file shared from other app.
  127. *
  128. * @param path Absolute path to a folder.
  129. */
  130. void setLastUploadPath(String path);
  131. String getLockPreference();
  132. void setLockPreference(String lockPreference);
  133. /**
  134. * Set pass code composed of 4 digits (as strings).
  135. *
  136. * @todo This must be refactored further to use a passcode stype
  137. * @param d1 1st digit
  138. * @param d2 2nd digit
  139. * @param d3 3rd digit
  140. * @param d4 4th digit
  141. */
  142. void setPassCode(String d1, String d2, String d3, String d4);
  143. /**
  144. * Get 4-digit passcode as array of strings. Strings may be null.
  145. *
  146. * @return 4 strings with digits or nulls
  147. */
  148. String[] getPassCode();
  149. /**
  150. * Gets the unlock via fingerprint preference configured by the user.
  151. *
  152. * @implNote this is always false
  153. * @return useFingerprint is unlock with fingerprint enabled
  154. */
  155. boolean isFingerprintUnlockEnabled();
  156. /**
  157. * Gets the auto upload paths flag last set.
  158. *
  159. * @return ascending order the legacy cleaning flag, default is false
  160. */
  161. boolean isAutoUploadPathsUpdateEnabled();
  162. /**
  163. * Saves the legacy cleaning flag which the user has set last.
  164. *
  165. * @param pathUpdate flag if it is a auto upload path update
  166. */
  167. void setAutoUploadPathsUpdateEnabled(boolean pathUpdate);
  168. /**
  169. * Gets the auto upload split out flag last set.
  170. *
  171. * @return ascending order the legacy cleaning flag, default is false
  172. */
  173. boolean isAutoUploadSplitEntriesEnabled();
  174. /**
  175. * Saves the flag for split entries magic
  176. *
  177. * @param splitOut flag if it is a auto upload path update
  178. */
  179. void setAutoUploadSplitEntriesEnabled(boolean splitOut);
  180. boolean isAutoUploadInitialized();
  181. void setAutoUploadInit(boolean autoUploadInit);
  182. /**
  183. * Get preferred folder sort order.
  184. *
  185. * @param folder Folder whoch order is being retrieved or null for root folder
  186. * @return sort order the sort order, default is {@link FileSortOrder#sort_a_to_z} (sort by name)
  187. */
  188. FileSortOrder getSortOrderByFolder(@Nullable OCFile folder);
  189. /**
  190. * Set preferred folder sort order.
  191. *
  192. * @param folder Folder which sort order is changed; if null, root folder is assumed
  193. * @param sortOrder the sort order of a folder
  194. */
  195. void setSortOrder(@Nullable OCFile folder, FileSortOrder sortOrder);
  196. /**
  197. * Set preferred folder sort order.
  198. *
  199. * @param sortOrder the sort order
  200. */
  201. void setSortOrder(FileSortOrder.Type type, FileSortOrder sortOrder);
  202. /**
  203. * Get preferred folder sort order.
  204. *
  205. * @return sort order the sort order, default is {@link FileSortOrder#sort_a_to_z} (sort by name)
  206. */
  207. FileSortOrder getSortOrderByType(FileSortOrder.Type type, FileSortOrder defaultOrder);
  208. FileSortOrder getSortOrderByType(FileSortOrder.Type type);
  209. /**
  210. * Gets the legacy cleaning flag last set.
  211. *
  212. * @return ascending order the legacy cleaning flag, default is false
  213. */
  214. boolean isLegacyClean();
  215. /**
  216. * Saves the legacy cleaning flag which the user has set last.
  217. *
  218. * @param legacyClean flag if it is a legacy cleaning
  219. */
  220. void setLegacyClean(boolean legacyClean);
  221. boolean isKeysMigrationEnabled();
  222. void setKeysMigrationEnabled(boolean enabled);
  223. boolean isStoragePathFixEnabled();
  224. void setStoragePathFixEnabled(boolean enabled);
  225. boolean isShowDetailedTimestampEnabled();
  226. void setShowDetailedTimestampEnabled(boolean showDetailedTimestamp);
  227. boolean isShowMediaScanNotifications();
  228. void setShowMediaScanNotifications(boolean showMediaScanNotification);
  229. /**
  230. * Gets the uploader behavior which the user has set last.
  231. *
  232. * @return uploader behavior the uploader behavior
  233. */
  234. int getUploaderBehaviour();
  235. /**
  236. * Changes dark theme mode
  237. *
  238. * This is reactive property. Listeners will be invoked if registered.
  239. *
  240. * @param mode dark mode setting: on, off, system
  241. */
  242. void setDarkThemeMode(DarkMode mode);
  243. /**
  244. * @return dark mode setting: on, off, system
  245. */
  246. DarkMode getDarkThemeMode();
  247. /**
  248. * Saves the uploader behavior which the user has set last.
  249. *
  250. * @param uploaderBehaviour the uploader behavior
  251. */
  252. void setUploaderBehaviour(int uploaderBehaviour);
  253. float getGridColumns();
  254. void setGridColumns(float gridColumns);
  255. long getLockTimestamp();
  256. void setLockTimestamp(long timestamp);
  257. /**
  258. * Gets the last seen version code right before updating.
  259. *
  260. * @return grid columns grid columns
  261. */
  262. int getLastSeenVersionCode();
  263. /**
  264. * Saves the version code as the last seen version code.
  265. *
  266. * @param versionCode the app's version code
  267. */
  268. void setLastSeenVersionCode(int versionCode);
  269. void removeLegacyPreferences();
  270. /**
  271. * Clears all user preferences.
  272. *
  273. * @implNote this clears only shared preferences, not preferences kept in account manager
  274. */
  275. void clear();
  276. String getStoragePath(String defaultPath);
  277. void setStoragePath(String path);
  278. void setStoragePathValid();
  279. boolean isStoragePathValid();
  280. void removeKeysMigrationPreference();
  281. String getCurrentAccountName();
  282. void setCurrentAccountName(String accountName);
  283. /**
  284. * Gets status of migration to user id, default false
  285. *
  286. * @return true: migration done: every account has userId, false: pending accounts without userId
  287. */
  288. boolean isUserIdMigrated();
  289. void setMigratedUserId(boolean value);
  290. void setPhotoSearchTimestamp(long timestamp);
  291. long getPhotoSearchTimestamp();
  292. boolean isPowerCheckDisabled();
  293. void setPowerCheckDisabled(boolean value);
  294. void increasePinWrongAttempts();
  295. void resetPinWrongAttempts();
  296. int pinBruteForceDelay();
  297. String getUidPid();
  298. void setUidPid(String uidPid);
  299. long getCalendarLastBackup();
  300. void setCalendarLastBackup(long timestamp);
  301. }