Alex Saveau | e60da31 | 2020-09-09 23:34:43 +0000 | [diff] [blame] | 1 | <html devsite="true"> |
| 2 | <head> |
| 3 | <title>PagingSource</title> |
| 4 | {% setvar book_path %}/reference/kotlin/androidx/_book.yaml{% endsetvar %} |
| 5 | {% include "_shared/_reference-head-tags.html" %} |
| 6 | </head> |
| 7 | <body> |
| 8 | <h1>PagingSource</h1> |
| 9 | {% setvar page_path %}androidx/paging/PagingSource.html{% endsetvar %} |
| 10 | {% setvar can_switch %}1{% endsetvar %} |
| 11 | {% include "reference/_kotlin_switcher2.md" %} |
| 12 | <p>TODO(b/166518424) class signature</p> |
| 13 | <p>TODO(b/166518951) inheritance hierarchy</p> |
| 14 | <p>TODO(b/166518636) direct subclasses</p> |
| 15 | <p>TODO(b/166518636) indirect subclasses</p> |
| 16 | <hr> |
Alex Saveau | fe9fe47 | 2020-09-10 01:41:31 +0000 | [diff] [blame] | 17 | <p>Base class for an abstraction of pageable static data from some source, where loading pages of data is typically an expensive operation. Some examples of common <code><a href="/reference/kotlin/androidx/paging/PagingSource.html">PagingSource</a></code>s might be from network or from a database.</p> |
| 18 | <p>An instance of a <code><a href="/reference/kotlin/androidx/paging/PagingSource.html">PagingSource</a></code> is used to load pages of data for an instance of <code><a href="/reference/kotlin/androidx/paging/PagingData.html">PagingData</a></code>.</p> |
| 19 | <p>A <code><a href="/reference/kotlin/androidx/paging/PagingData.html">PagingData</a></code> can grow as it loads more data, but the data loaded cannot be updated. If the underlying data set is modified, a new <code><a href="/reference/kotlin/androidx/paging/PagingSource.html">PagingSource</a></code> / <code><a href="/reference/kotlin/androidx/paging/PagingData.html">PagingData</a></code> pair must be created to represent an updated snapshot of the data.</p> |
| 20 | <h3> Loading Pages</h3> |
| 21 | <p><code><a href="/reference/kotlin/androidx/paging/PagingData.html">PagingData</a></code> queries data from its <code><a href="/reference/kotlin/androidx/paging/PagingSource.html">PagingSource</a></code> in response to loading hints generated as the user scrolls in a <code>RecyclerView</code>.</p> |
| 22 | <p>To control how and when a <code><a href="/reference/kotlin/androidx/paging/PagingData.html">PagingData</a></code> queries data from its <code><a href="/reference/kotlin/androidx/paging/PagingSource.html">PagingSource</a></code>, see <code><a href="/reference/kotlin/androidx/paging/PagingConfig.html">PagingConfig</a></code>, which defines behavior such as <code><a href="/reference/kotlin/androidx/paging/PagingConfig.html#pageSize()">pageSize</a></code> and <code><a href="/reference/kotlin/androidx/paging/PagingConfig.html#prefetchDistance()">prefetchDistance</a></code>.</p> |
| 23 | <h3> Updating Data</h3> |
| 24 | <p>A <code><a href="/reference/kotlin/androidx/paging/PagingSource.html">PagingSource</a></code> / <code><a href="/reference/kotlin/androidx/paging/PagingData.html">PagingData</a></code> pair is a snapshot of the data set. A new <code><a href="/reference/kotlin/androidx/paging/PagingData.html">PagingData</a></code> / <code><a href="/reference/kotlin/androidx/paging/PagingData.html">PagingData</a></code> must be created if an update occurs, such as a reorder, insert, delete, or content update occurs. A <code><a href="/reference/kotlin/androidx/paging/PagingSource.html">PagingSource</a></code> must detect that it cannot continue loading its snapshot (for instance, when Database query notices a table being invalidated), and call <code><a href="/reference/kotlin/androidx/paging/PagingSource.html#invalidate()">invalidate</a></code>. Then a new <code><a href="/reference/kotlin/androidx/paging/PagingSource.html">PagingSource</a></code> / <code><a href="/reference/kotlin/androidx/paging/PagingData.html">PagingData</a></code> pair would be created to represent data from the new state of the database query.</p> |
| 25 | <h3> Presenting Data to UI</h3> |
| 26 | <p>To present data loaded by a <code><a href="/reference/kotlin/androidx/paging/PagingSource.html">PagingSource</a></code> to a <code>RecyclerView</code>, create an instance of <code><a href="/reference/kotlin/androidx/paging/Pager.html">Pager</a></code>, which provides a stream of <code><a href="/reference/kotlin/androidx/paging/PagingData.html">PagingData</a></code> that you may collect from and submit to a <code><a href="/reference/kotlin/androidx/paging/PagingDataAdapter.html">PagingDataAdapter</a></code>.</p> |
Alex Saveau | e60da31 | 2020-09-09 23:34:43 +0000 | [diff] [blame] | 27 | <div class="devsite-table-wrapper"> |
| 28 | <table class="responsive"> |
| 29 | <thead> |
| 30 | <tr> |
| 31 | <th colspan="2">Parameters</th> |
| 32 | </tr> |
| 33 | </thead> |
| 34 | <tbody> |
| 35 | <tr> |
| 36 | <td><code>Key</code></td> |
| 37 | <td width="100%"> |
| 38 | <p>Type of key which define what data to load. E.g. <code><a href="/reference/kotlin/kotlin/Int.html">Int</a></code> to represent either a page number or item position, or <code><a href="/reference/kotlin/kotlin/String.html">String</a></code> if your network uses Strings as next tokens returned with each response.</p> |
| 39 | </td> |
| 40 | </tr> |
| 41 | <tr> |
| 42 | <td><code>Value</code></td> |
| 43 | <td width="100%"> |
Alex Saveau | fe9fe47 | 2020-09-10 01:41:31 +0000 | [diff] [blame] | 44 | <p>Type of data loaded in by this <code><a href="/reference/kotlin/androidx/paging/PagingSource.html">PagingSource</a></code>. E.g., the type of data that will be passed to a <code><a href="/reference/kotlin/androidx/paging/PagingDataAdapter.html">PagingDataAdapter</a></code> to be displayed in a <code>RecyclerView</code>.</p> |
Alex Saveau | e60da31 | 2020-09-09 23:34:43 +0000 | [diff] [blame] | 45 | </td> |
| 46 | </tr> |
| 47 | </tbody> |
| 48 | </table> |
| 49 | </div> |
| 50 | <div class="devsite-table-wrapper"> |
| 51 | <table class="responsive"> |
| 52 | <thead> |
| 53 | <tr> |
| 54 | <th colspan="2">See also</th> |
| 55 | </tr> |
| 56 | </thead> |
| 57 | <tbody> |
| 58 | <tr> |
| 59 | <td><code><a href="/reference/kotlin/androidx/paging/Pager.html">Pager</a></code></td> |
| 60 | <td width="100%"> |
| 61 | <p></p> |
| 62 | </td> |
| 63 | </tr> |
| 64 | </tbody> |
| 65 | </table> |
| 66 | </div> |
| 67 | <h2>Summary</h2> |
| 68 | <p>Nested *</p> |
| 69 | <p>Enum values</p> |
Alex Saveau | e60da31 | 2020-09-09 23:34:43 +0000 | [diff] [blame] | 70 | <div class="devsite-table-wrapper"> |
| 71 | <table class="responsive"> |
| 72 | <thead> |
| 73 | <tr> |
Alex Saveau | 65f7317 | 2020-09-09 22:46:21 +0000 | [diff] [blame] | 74 | <th colspan="2"><h3>Public properties</h3></th> |
| 75 | </tr> |
| 76 | </thead> |
| 77 | <tbody> |
| 78 | <tr> |
Alex Saveau | 5c56aab | 2020-09-11 20:30:44 +0000 | [diff] [blame] | 79 | <td><code><a href="/reference/kotlin/kotlin/Boolean.html">Boolean</a></code></td> |
Alex Saveau | 65f7317 | 2020-09-09 22:46:21 +0000 | [diff] [blame] | 80 | <td width="100%"> |
| 81 | <div><code><a href="/reference/kotlin/androidx/paging/PagingSource.html#invalid()">invalid</a></code></div> |
| 82 | <p>Whether this <code><a href="/reference/kotlin/androidx/paging/PagingSource.html">PagingSource</a></code> has been invalidated, which should happen when the data this <code><a href="/reference/kotlin/androidx/paging/PagingSource.html">PagingSource</a></code> represents changes since it was first instantiated.</p> |
| 83 | </td> |
| 84 | </tr> |
| 85 | <tr> |
| 86 | <td><code>open <a href="/reference/kotlin/kotlin/Boolean.html">Boolean</a></code></td> |
| 87 | <td width="100%"> |
| 88 | <div><code><a href="/reference/kotlin/androidx/paging/PagingSource.html#jumpingSupported()">jumpingSupported</a></code></div> |
Alex Saveau | fe9fe47 | 2020-09-10 01:41:31 +0000 | [diff] [blame] | 89 | <p><code>true</code> if this <code><a href="/reference/kotlin/androidx/paging/PagingSource.html">PagingSource</a></code> supports jumping, <code>false</code> otherwise.</p> |
Alex Saveau | 65f7317 | 2020-09-09 22:46:21 +0000 | [diff] [blame] | 90 | </td> |
| 91 | </tr> |
| 92 | <tr> |
| 93 | <td><code>open <a href="/reference/kotlin/kotlin/Boolean.html">Boolean</a></code></td> |
| 94 | <td width="100%"> |
| 95 | <div><code><a href="/reference/kotlin/androidx/paging/PagingSource.html#keyReuseSupported()">keyReuseSupported</a></code></div> |
| 96 | <p><code>true</code> if this <code><a href="/reference/kotlin/androidx/paging/PagingSource.html">PagingSource</a></code> expects to re-use keys to load distinct pages without a call to <code><a href="/reference/kotlin/androidx/paging/PagingSource.html#invalidate()">invalidate</a></code>, <code>false</code> otherwise.</p> |
| 97 | </td> |
| 98 | </tr> |
| 99 | </tbody> |
| 100 | </table> |
| 101 | </div> |
| 102 | <div class="devsite-table-wrapper"> |
| 103 | <table class="responsive"> |
| 104 | <thead> |
| 105 | <tr> |
Alex Saveau | f393e9a | 2020-09-17 21:15:59 +0000 | [diff] [blame^] | 106 | <th colspan="2"><h3>Public constructors</h3></th> |
| 107 | </tr> |
| 108 | </thead> |
| 109 | <tbody> |
| 110 | <tr> |
| 111 | <td> |
| 112 | <div><code><a href="/reference/kotlin/androidx/paging/PagingSource.html#PagingSource()">PagingSource</a>()</code></div> |
| 113 | </td> |
| 114 | </tr> |
| 115 | </tbody> |
| 116 | </table> |
| 117 | </div> |
| 118 | <div class="devsite-table-wrapper"> |
| 119 | <table class="responsive"> |
| 120 | <thead> |
| 121 | <tr> |
Alex Saveau | e60da31 | 2020-09-09 23:34:43 +0000 | [diff] [blame] | 122 | <th colspan="2"><h3>Public functions</h3></th> |
| 123 | </tr> |
| 124 | </thead> |
| 125 | <tbody> |
| 126 | <tr> |
Alex Saveau | 3b6f540 | 2020-09-16 05:44:58 +0000 | [diff] [blame] | 127 | <td><code>open Key</code></td> |
Alex Saveau | e60da31 | 2020-09-09 23:34:43 +0000 | [diff] [blame] | 128 | <td width="100%"> |
| 129 | <div><code><a href="/reference/kotlin/androidx/paging/PagingSource.html#getRefreshKey(androidx.paging.PagingState)">getRefreshKey</a>(state: <a href="/reference/kotlin/androidx/paging/PagingState.html">PagingState</a><Key, Value>)</code></div> |
Alex Saveau | fe9fe47 | 2020-09-10 01:41:31 +0000 | [diff] [blame] | 130 | <p>Request a refresh key given the current <code><a href="/reference/kotlin/androidx/paging/PagingState.html">PagingState</a></code> of the associated <code><a href="/reference/kotlin/androidx/paging/PagingData.html">PagingData</a></code> used to present loaded data from this <code><a href="/reference/kotlin/androidx/paging/PagingSource.html">PagingSource</a></code>.</p> |
Alex Saveau | e60da31 | 2020-09-09 23:34:43 +0000 | [diff] [blame] | 131 | </td> |
| 132 | </tr> |
| 133 | <tr> |
Alex Saveau | 02907a9 | 2020-09-10 00:50:30 +0000 | [diff] [blame] | 134 | <td><code>open <a href="/reference/kotlin/kotlin/Unit.html">Unit</a></code></td> |
Alex Saveau | e60da31 | 2020-09-09 23:34:43 +0000 | [diff] [blame] | 135 | <td width="100%"> |
| 136 | <div><code><a href="/reference/kotlin/androidx/paging/PagingSource.html#invalidate()">invalidate</a>()</code></div> |
Alex Saveau | fe9fe47 | 2020-09-10 01:41:31 +0000 | [diff] [blame] | 137 | <p>Signal the <code><a href="/reference/kotlin/androidx/paging/PagingSource.html">PagingSource</a></code> to stop loading.</p> |
Alex Saveau | e60da31 | 2020-09-09 23:34:43 +0000 | [diff] [blame] | 138 | </td> |
| 139 | </tr> |
| 140 | <tr> |
Alex Saveau | 02907a9 | 2020-09-10 00:50:30 +0000 | [diff] [blame] | 141 | <td><code>suspend abstract <a href="/reference/kotlin/androidx/paging/PagingSource.LoadResult.html">PagingSource.LoadResult</a><Key, Value></code></td> |
Alex Saveau | e60da31 | 2020-09-09 23:34:43 +0000 | [diff] [blame] | 142 | <td width="100%"> |
| 143 | <div><code><a href="/reference/kotlin/androidx/paging/PagingSource.html#load(androidx.paging.PagingSource.LoadParams)">load</a>(params: <a href="/reference/kotlin/androidx/paging/PagingSource.LoadParams.html">PagingSource.LoadParams</a><Key>)</code></div> |
Alex Saveau | fe9fe47 | 2020-09-10 01:41:31 +0000 | [diff] [blame] | 144 | <p>Loading API for <code><a href="/reference/kotlin/androidx/paging/PagingSource.html">PagingSource</a></code>.</p> |
Alex Saveau | e60da31 | 2020-09-09 23:34:43 +0000 | [diff] [blame] | 145 | </td> |
| 146 | </tr> |
| 147 | <tr> |
Alex Saveau | 5c56aab | 2020-09-11 20:30:44 +0000 | [diff] [blame] | 148 | <td><code><a href="/reference/kotlin/kotlin/Unit.html">Unit</a></code></td> |
Alex Saveau | e60da31 | 2020-09-09 23:34:43 +0000 | [diff] [blame] | 149 | <td width="100%"> |
Alex Saveau | 33d4a2d | 2020-09-18 01:03:22 +0000 | [diff] [blame] | 150 | <div><code><a href="/reference/kotlin/androidx/paging/PagingSource.html#registerInvalidatedCallback(kotlin.Function0)">registerInvalidatedCallback</a>(onInvalidatedCallback: () -> <a href="/reference/kotlin/kotlin/Unit.html">Unit</a>)</code></div> |
Alex Saveau | fe9fe47 | 2020-09-10 01:41:31 +0000 | [diff] [blame] | 151 | <p>Add a callback to invoke when the <code><a href="/reference/kotlin/androidx/paging/PagingSource.html">PagingSource</a></code> is first invalidated.</p> |
Alex Saveau | e60da31 | 2020-09-09 23:34:43 +0000 | [diff] [blame] | 152 | </td> |
| 153 | </tr> |
| 154 | <tr> |
Alex Saveau | 5c56aab | 2020-09-11 20:30:44 +0000 | [diff] [blame] | 155 | <td><code><a href="/reference/kotlin/kotlin/Unit.html">Unit</a></code></td> |
Alex Saveau | e60da31 | 2020-09-09 23:34:43 +0000 | [diff] [blame] | 156 | <td width="100%"> |
Alex Saveau | 33d4a2d | 2020-09-18 01:03:22 +0000 | [diff] [blame] | 157 | <div><code><a href="/reference/kotlin/androidx/paging/PagingSource.html#unregisterInvalidatedCallback(kotlin.Function0)">unregisterInvalidatedCallback</a>(onInvalidatedCallback: () -> <a href="/reference/kotlin/kotlin/Unit.html">Unit</a>)</code></div> |
Alex Saveau | fe9fe47 | 2020-09-10 01:41:31 +0000 | [diff] [blame] | 158 | <p>Remove a previously added invalidate callback.</p> |
Alex Saveau | e60da31 | 2020-09-09 23:34:43 +0000 | [diff] [blame] | 159 | </td> |
| 160 | </tr> |
| 161 | </tbody> |
| 162 | </table> |
| 163 | </div> |
Alex Saveau | 65f7317 | 2020-09-09 22:46:21 +0000 | [diff] [blame] | 164 | <h2>Public properties</h2> |
| 165 | <div><a name="getInvalid()"></a><a name="setInvalid()"></a><a name="getInvalid--"></a><a name="setInvalid--"></a> |
| 166 | <h3 class="api-name" id="invalid()">invalid</h3> |
Alex Saveau | 35de436 | 2020-09-12 02:12:48 +0000 | [diff] [blame] | 167 | <pre class="api-signature no-pretty-print">val <a href="/reference/kotlin/androidx/paging/PagingSource.html#invalid()">invalid</a>: <a href="/reference/kotlin/kotlin/Boolean.html">Boolean</a></pre> |
Alex Saveau | 65f7317 | 2020-09-09 22:46:21 +0000 | [diff] [blame] | 168 | <p>Whether this <code><a href="/reference/kotlin/androidx/paging/PagingSource.html">PagingSource</a></code> has been invalidated, which should happen when the data this <code><a href="/reference/kotlin/androidx/paging/PagingSource.html">PagingSource</a></code> represents changes since it was first instantiated.</p> |
| 169 | </div> |
| 170 | <div><a name="getJumpingSupported()"></a><a name="setJumpingSupported()"></a><a name="getJumpingSupported--"></a><a name="setJumpingSupported--"></a> |
| 171 | <h3 class="api-name" id="jumpingSupported()">jumpingSupported</h3> |
Alex Saveau | 35de436 | 2020-09-12 02:12:48 +0000 | [diff] [blame] | 172 | <pre class="api-signature no-pretty-print">open val <a href="/reference/kotlin/androidx/paging/PagingSource.html#jumpingSupported()">jumpingSupported</a>: <a href="/reference/kotlin/kotlin/Boolean.html">Boolean</a></pre> |
Alex Saveau | fe9fe47 | 2020-09-10 01:41:31 +0000 | [diff] [blame] | 173 | <p><code>true</code> if this <code><a href="/reference/kotlin/androidx/paging/PagingSource.html">PagingSource</a></code> supports jumping, <code>false</code> otherwise.</p> |
| 174 | <p>Override this to <code>true</code> if pseudo-fast scrolling via jumps is supported.</p> |
| 175 | <p>A jump occurs when a <code>RecyclerView</code> scrolls through a number of placeholders defined by <code><a href="/reference/kotlin/androidx/paging/PagingConfig.html#jumpThreshold()">jumpThreshold</a></code> and triggers a load with <code><a href="/reference/kotlin/androidx/paging/LoadType.REFRESH.html">LoadType.REFRESH</a></code>.</p> |
| 176 | <p><code><a href="/reference/kotlin/androidx/paging/PagingSource.html">PagingSource</a></code>s that support jumps should override <code><a href="/reference/kotlin/androidx/paging/PagingSource.html#getRefreshKey(androidx.paging.PagingState)">getRefreshKey</a></code> to return a <code><a href="/reference/kotlin/androidx/paging/PagingSource.html">PagingSource</a></code> that would load data fulfilling the viewport given a user's current <code><a href="/reference/kotlin/androidx/paging/PagingState.html#anchorPosition()">anchorPosition</a></code>.</p> |
Alex Saveau | 65f7317 | 2020-09-09 22:46:21 +0000 | [diff] [blame] | 177 | <div class="devsite-table-wrapper"> |
| 178 | <table class="responsive"> |
| 179 | <thead> |
| 180 | <tr> |
| 181 | <th colspan="2">See also</th> |
| 182 | </tr> |
| 183 | </thead> |
| 184 | <tbody> |
| 185 | <tr> |
| 186 | <td><code><a href="/reference/kotlin/androidx/paging/PagingConfig.html#jumpThreshold()">jumpThreshold</a></code></td> |
| 187 | <td width="100%"> |
| 188 | <p></p> |
| 189 | </td> |
| 190 | </tr> |
| 191 | </tbody> |
| 192 | </table> |
| 193 | </div> |
| 194 | </div> |
| 195 | <div><a name="getKeyReuseSupported()"></a><a name="setKeyReuseSupported()"></a><a name="getKeyReuseSupported--"></a><a name="setKeyReuseSupported--"></a> |
| 196 | <h3 class="api-name" id="keyReuseSupported()">keyReuseSupported</h3> |
Alex Saveau | 35de436 | 2020-09-12 02:12:48 +0000 | [diff] [blame] | 197 | <pre class="api-signature no-pretty-print">open val <a href="/reference/kotlin/androidx/paging/PagingSource.html#keyReuseSupported()">keyReuseSupported</a>: <a href="/reference/kotlin/kotlin/Boolean.html">Boolean</a></pre> |
Alex Saveau | 65f7317 | 2020-09-09 22:46:21 +0000 | [diff] [blame] | 198 | <p><code>true</code> if this <code><a href="/reference/kotlin/androidx/paging/PagingSource.html">PagingSource</a></code> expects to re-use keys to load distinct pages without a call to <code><a href="/reference/kotlin/androidx/paging/PagingSource.html#invalidate()">invalidate</a></code>, <code>false</code> otherwise.</p> |
| 199 | </div> |
Alex Saveau | f393e9a | 2020-09-17 21:15:59 +0000 | [diff] [blame^] | 200 | <h2>Public constructors</h2> |
| 201 | <div><a name="PagingSource--"></a> |
| 202 | <h3 class="api-name" id="PagingSource()">PagingSource</h3> |
| 203 | <pre class="api-signature no-pretty-print">fun <a href="/reference/kotlin/androidx/paging/PagingSource.html#PagingSource()">PagingSource</a>(): <a href="/reference/kotlin/androidx/paging/PagingSource.html">PagingSource</a><Key, Value></pre> |
| 204 | <div class="devsite-table-wrapper"> |
| 205 | <table class="responsive"> |
| 206 | <thead> |
| 207 | <tr> |
| 208 | <th colspan="2">Parameters</th> |
| 209 | </tr> |
| 210 | </thead> |
| 211 | <tbody> |
| 212 | <tr> |
| 213 | <td><code>Key</code></td> |
| 214 | <td width="100%"> |
| 215 | <p>Type of key which define what data to load. E.g. <code><a href="/reference/kotlin/kotlin/Int.html">Int</a></code> to represent either a page number or item position, or <code><a href="/reference/kotlin/kotlin/String.html">String</a></code> if your network uses Strings as next tokens returned with each response.</p> |
| 216 | </td> |
| 217 | </tr> |
| 218 | <tr> |
| 219 | <td><code>Value</code></td> |
| 220 | <td width="100%"> |
| 221 | <p>Type of data loaded in by this <code><a href="/reference/kotlin/androidx/paging/PagingSource.html">PagingSource</a></code>. E.g., the type of data that will be passed to a <code><a href="/reference/kotlin/androidx/paging/PagingDataAdapter.html">PagingDataAdapter</a></code> to be displayed in a <code>RecyclerView</code>.</p> |
| 222 | </td> |
| 223 | </tr> |
| 224 | </tbody> |
| 225 | </table> |
| 226 | </div> |
| 227 | </div> |
Alex Saveau | e60da31 | 2020-09-09 23:34:43 +0000 | [diff] [blame] | 228 | <h2>Public functions</h2> |
| 229 | <div><a name="getRefreshKey-androidx.paging.PagingState-"></a> |
| 230 | <h3 class="api-name" id="getRefreshKey(androidx.paging.PagingState)">getRefreshKey</h3> |
Alex Saveau | 3b6f540 | 2020-09-16 05:44:58 +0000 | [diff] [blame] | 231 | <pre class="api-signature no-pretty-print">@<a href="/reference/kotlin/androidx/paging/ExperimentalPagingApi.html">ExperimentalPagingApi</a><br>open fun <a href="/reference/kotlin/androidx/paging/PagingSource.html#getRefreshKey(androidx.paging.PagingState)">getRefreshKey</a>(state: <a href="/reference/kotlin/androidx/paging/PagingState.html">PagingState</a><Key, Value>): Key</pre> |
Alex Saveau | fe9fe47 | 2020-09-10 01:41:31 +0000 | [diff] [blame] | 232 | <p>Request a refresh key given the current <code><a href="/reference/kotlin/androidx/paging/PagingState.html">PagingState</a></code> of the associated <code><a href="/reference/kotlin/androidx/paging/PagingData.html">PagingData</a></code> used to present loaded data from this <code><a href="/reference/kotlin/androidx/paging/PagingSource.html">PagingSource</a></code>.</p> |
| 233 | <p>The <code><a href="/reference/kotlin/androidx/paging/PagingSource.html">PagingSource</a></code> returned by this method is used to populate the <code><a href="/reference/kotlin/androidx/paging/PagingSource.LoadParams.html#key()">key</a></code> for load requests of type <code><a href="/reference/kotlin/androidx/paging/LoadType.REFRESH.html">LoadType.REFRESH</a></code>.</p> |
| 234 | <p>For example, if items are loaded based on position, and keys are positions, <code><a href="/reference/kotlin/androidx/paging/PagingSource.html#getRefreshKey(androidx.paging.PagingState)">getRefreshKey</a></code> should return the position of the item.</p> |
| 235 | <p>Alternately, if items contain a key used to load, get the key from the item in the page at index <code><a href="/reference/kotlin/androidx/paging/PagingState.html#anchorPosition()">anchorPosition</a></code>.</p> |
| 236 | <p>If this operation cannot be supported (generally, because keys cannot be reused across refresh) return <code>null</code> - this is the default behavior.</p> |
| 237 | <p>Note: This method is guaranteed to only be called if the initial load succeeds and the list of loaded pages is not empty. In the case where a refresh is triggered before the initial load succeeds or it errors out, the initial key passed to <code><a href="/reference/kotlin/androidx/paging/Pager.html">Pager</a></code> will be used.</p> |
Alex Saveau | e60da31 | 2020-09-09 23:34:43 +0000 | [diff] [blame] | 238 | </div> |
| 239 | <div><a name="invalidate--"></a> |
| 240 | <h3 class="api-name" id="invalidate()">invalidate</h3> |
Alex Saveau | 35de436 | 2020-09-12 02:12:48 +0000 | [diff] [blame] | 241 | <pre class="api-signature no-pretty-print">open fun <a href="/reference/kotlin/androidx/paging/PagingSource.html#invalidate()">invalidate</a>(): <a href="/reference/kotlin/kotlin/Unit.html">Unit</a></pre> |
Alex Saveau | fe9fe47 | 2020-09-10 01:41:31 +0000 | [diff] [blame] | 242 | <p>Signal the <code><a href="/reference/kotlin/androidx/paging/PagingSource.html">PagingSource</a></code> to stop loading.</p> |
| 243 | <p>This method is idempotent. i.e., If <code><a href="/reference/kotlin/androidx/paging/PagingSource.html#invalidate()">invalidate</a></code> has already been called, subsequent calls to this method should have no effect.</p> |
Alex Saveau | e60da31 | 2020-09-09 23:34:43 +0000 | [diff] [blame] | 244 | </div> |
| 245 | <div><a name="load-androidx.paging.PagingSource.LoadParams-"></a> |
| 246 | <h3 class="api-name" id="load(androidx.paging.PagingSource.LoadParams)">load</h3> |
Alex Saveau | 35de436 | 2020-09-12 02:12:48 +0000 | [diff] [blame] | 247 | <pre class="api-signature no-pretty-print">suspend abstract fun <a href="/reference/kotlin/androidx/paging/PagingSource.html#load(androidx.paging.PagingSource.LoadParams)">load</a>(params: <a href="/reference/kotlin/androidx/paging/PagingSource.LoadParams.html">PagingSource.LoadParams</a><Key>): <a href="/reference/kotlin/androidx/paging/PagingSource.LoadResult.html">PagingSource.LoadResult</a><Key, Value></pre> |
Alex Saveau | fe9fe47 | 2020-09-10 01:41:31 +0000 | [diff] [blame] | 248 | <p>Loading API for <code><a href="/reference/kotlin/androidx/paging/PagingSource.html">PagingSource</a></code>.</p> |
| 249 | <p>Implement this method to trigger your async load (e.g. from database or network).</p> |
Alex Saveau | e60da31 | 2020-09-09 23:34:43 +0000 | [diff] [blame] | 250 | </div> |
| 251 | <div><a name="registerInvalidatedCallback-kotlin.Function0-"></a> |
| 252 | <h3 class="api-name" id="registerInvalidatedCallback(kotlin.Function0)">registerInvalidatedCallback</h3> |
Alex Saveau | 33d4a2d | 2020-09-18 01:03:22 +0000 | [diff] [blame] | 253 | <pre class="api-signature no-pretty-print">fun <a href="/reference/kotlin/androidx/paging/PagingSource.html#registerInvalidatedCallback(kotlin.Function0)">registerInvalidatedCallback</a>(onInvalidatedCallback: () -> <a href="/reference/kotlin/kotlin/Unit.html">Unit</a>): <a href="/reference/kotlin/kotlin/Unit.html">Unit</a></pre> |
Alex Saveau | fe9fe47 | 2020-09-10 01:41:31 +0000 | [diff] [blame] | 254 | <p>Add a callback to invoke when the <code><a href="/reference/kotlin/androidx/paging/PagingSource.html">PagingSource</a></code> is first invalidated.</p> |
| 255 | <p>Once invalidated, a <code><a href="/reference/kotlin/androidx/paging/PagingSource.html">PagingSource</a></code> will not become valid again.</p> |
| 256 | <p>A <code><a href="/reference/kotlin/androidx/paging/PagingSource.html">PagingSource</a></code> will only invoke its callbacks once - the first time <code><a href="/reference/kotlin/androidx/paging/PagingSource.html#invalidate()">invalidate</a></code> is called, on that thread.</p> |
Alex Saveau | e60da31 | 2020-09-09 23:34:43 +0000 | [diff] [blame] | 257 | <div class="devsite-table-wrapper"> |
| 258 | <table class="responsive"> |
| 259 | <thead> |
| 260 | <tr> |
| 261 | <th colspan="2">Parameters</th> |
| 262 | </tr> |
| 263 | </thead> |
| 264 | <tbody> |
| 265 | <tr> |
| 266 | <td><code>onInvalidatedCallback</code></td> |
| 267 | <td width="100%"> |
| 268 | <p>The callback that will be invoked on thread that invalidates the <code><a href="/reference/kotlin/androidx/paging/PagingSource.html">PagingSource</a></code>.</p> |
| 269 | </td> |
| 270 | </tr> |
| 271 | </tbody> |
| 272 | </table> |
| 273 | </div> |
| 274 | </div> |
| 275 | <div><a name="unregisterInvalidatedCallback-kotlin.Function0-"></a> |
| 276 | <h3 class="api-name" id="unregisterInvalidatedCallback(kotlin.Function0)">unregisterInvalidatedCallback</h3> |
Alex Saveau | 33d4a2d | 2020-09-18 01:03:22 +0000 | [diff] [blame] | 277 | <pre class="api-signature no-pretty-print">fun <a href="/reference/kotlin/androidx/paging/PagingSource.html#unregisterInvalidatedCallback(kotlin.Function0)">unregisterInvalidatedCallback</a>(onInvalidatedCallback: () -> <a href="/reference/kotlin/kotlin/Unit.html">Unit</a>): <a href="/reference/kotlin/kotlin/Unit.html">Unit</a></pre> |
Alex Saveau | fe9fe47 | 2020-09-10 01:41:31 +0000 | [diff] [blame] | 278 | <p>Remove a previously added invalidate callback.</p> |
Alex Saveau | e60da31 | 2020-09-09 23:34:43 +0000 | [diff] [blame] | 279 | <div class="devsite-table-wrapper"> |
| 280 | <table class="responsive"> |
| 281 | <thead> |
| 282 | <tr> |
| 283 | <th colspan="2">Parameters</th> |
| 284 | </tr> |
| 285 | </thead> |
| 286 | <tbody> |
| 287 | <tr> |
| 288 | <td><code>onInvalidatedCallback</code></td> |
| 289 | <td width="100%"> |
| 290 | <p>The previously added callback.</p> |
| 291 | </td> |
| 292 | </tr> |
| 293 | </tbody> |
| 294 | </table> |
| 295 | </div> |
| 296 | </div> |
| 297 | </body> |
| 298 | </html> |