@@ -9,19 +9,19 @@ content: |
9
9
10
10
.. code-block:: console
11
11
12
- $ git clone [email protected] :mongodb-university/realm-tutorial-kotlin- android.git
12
+ git clone [email protected] :mongodb-university/realm-tutorial-android-kotlin .git
13
13
14
14
.. important::
15
15
16
- The realm-tutorial-kotlin- android repository contains two branches:
16
+ The realm-tutorial-android-kotlin repository contains two branches:
17
17
``final`` and ``start``. The ``final`` branch is a finished version
18
18
of the app as it should look *after* you complete this tutorial.
19
19
To walk through this tutorial, please check out the ``start``
20
20
branch:
21
21
22
22
.. code-block:: console
23
23
24
- $ git checkout start
24
+ git checkout start
25
25
26
26
---
27
27
title : Open the Project in Android Studio
@@ -38,9 +38,9 @@ content: |
38
38
39
39
3. In the file navigator opened by Android Studio, navigate to the
40
40
directory where, in the previous step, you cloned the
41
- ``realm-tutorial-kotlin- android`` repository.
41
+ ``realm-tutorial-android-kotlin `` repository.
42
42
43
- 4. Select the ``realm-tutorial-kotlin- android`` folder.
43
+ 4. Select the ``realm-tutorial-android-kotlin `` folder.
44
44
45
45
5. Click "Open".
46
46
@@ -216,22 +216,24 @@ content: |
216
216
fields for email and password entry, as well as buttons to either
217
217
register a user account or login to an existing account. We need to
218
218
implement the logic to handle user login and user account creation.
219
-
219
+
220
220
You'll find this logic in the ``login()`` method, where a boolean
221
221
value called ``createuser`` controls where the method submits user
222
222
credentials to create a new account or to login to an existing
223
223
account.
224
224
225
225
First, let's implement the logic that registers a new user:
226
226
227
- .. literalinclude:: FIXME FIXME FIXME
227
+ .. literalinclude:: /tutorial/generated/code/final/LoginActivity.codeblock.create-user.kt
228
+ :language: kotlin
228
229
229
230
Now, implement the logic to log in with an existing user. Once
230
231
logged in successfully, call the ``onLoginSuccess()`` method, which
231
232
closes the ``LoginActivity`` and resumes the calling activity
232
233
(typically ``ProjectActivity``):
233
234
234
- .. literalinclude:: FIXME FIXME FIXME
235
+ .. literalinclude:: /tutorial/generated/code/final/LoginActivity.codeblock.login-user.kt
236
+ :language: kotlin
235
237
236
238
Don't forget to call the ``onLoginFailed()`` method in the event of a
237
239
login or account creation failure with a message describing the error.
@@ -252,7 +254,8 @@ content: |
252
254
the user's {+realm+} in the ``else`` block of the ``onStart()`` method
253
255
of ``ProjectActivity``:
254
256
255
- .. literalinclude:: FIXME FIXME FIXME
257
+ .. literalinclude:: /tutorial/generated/code/final/ProjectActivity.codeblock.set-up-user-realm.kt
258
+ :language: kotlin
256
259
257
260
Next, we need to query the {+realm+} to get a copy of the ``User``
258
261
object containing the user's list of projects. Because each user
@@ -263,7 +266,8 @@ content: |
263
266
object when the user creates an account. Add the code that queries for
264
267
the user object:
265
268
266
- .. literalinclude:: FIXME FIXME FIXME
269
+ .. literalinclude:: /tutorial/generated/code/final/ProjectActivity.codeblock.user-init-change-listener.kt
270
+ :language: kotlin
267
271
268
272
Because it can take a few seconds for the trigger to create this
269
273
object after a login, we should handle the case where the user object
@@ -272,14 +276,19 @@ content: |
272
276
watch the {+realm+} for changes and only set up the project's Recycler
273
277
View once the trigger runs:
274
278
275
- .. literalinclude:: FIXME FIXME FIXME
279
+ .. literalinclude:: /tutorial/generated/code/final/ProjectActivity.codeblock.fetch-synced-user-safely.kt
280
+ :language: kotlin
276
281
277
282
Finally, we need to guarantee that ``ProjectActivity`` always closes
278
283
the user {+realm+} when the app closes or the user logs out. To
279
284
accomplish this, add logic that calls the ``realm.close()`` method
280
285
when ``ProjectActivity`` finishes or stops:
281
286
282
- .. literalinclude:: FIXME FIXME FIXME
287
+ .. literalinclude:: /tutorial/generated/code/final/ProjectActivity.codeblock.on-destroy-close-realm.kt
288
+ :language: kotlin
289
+
290
+ .. literalinclude:: /tutorial/generated/code/final/ProjectActivity.codeblock.on-stop-close-realm.kt
291
+ :language: kotlin
283
292
284
293
---
285
294
title : Implement the Tasks List
@@ -294,7 +303,8 @@ content: |
294
303
the user who owns the project). We'll begin by initializing a
295
304
connection to this {+realm+} when the activity starts:
296
305
297
- .. literalinclude:: FIXME FIXME FIXME
306
+ .. literalinclude:: /tutorial/generated/code/final/TaskActivity.codeblock.set-up-project-realm.kt
307
+ :language: kotlin
298
308
299
309
Next, we'll query the realm for the list of tasks belonging to this
300
310
project. Fortunately the query isn't too complicated: since every task
@@ -307,21 +317,27 @@ content: |
307
317
list of tasks, pass the ``RealmResult`` to the ``TaskAdapter`` and set
308
318
that adapter as the ``RecyclerView's`` adapter:
309
319
310
- .. literalinclude:: FIXME FIXME FIXME
320
+ .. literalinclude:: /tutorial/generated/code/final/TaskActivity.codeblock.fetch-tasks-for-project-sorted-by-id.kt
321
+ :language: kotlin
311
322
312
- ``TaskActivity`` needs allow users to create a new task in the
313
- project. To handle this, write logic in the floating action button's
314
- ``setPositiveButton()`` callback that creates a new task based on the
315
- user's input in ``inputText`` and adds that task to the {+realm+}:
323
+ ``TaskActivity`` needs to allow users to create a new task in the project. To
324
+ handle this, write logic in the floating action button's
325
+ ``setPositiveButton()`` callback that creates a new task based on the user's
326
+ input in ``inputText`` and adds that task to the {+realm+}:
316
327
317
- .. literalinclude:: FIXME FIXME FIXME
328
+ .. literalinclude:: /tutorial/generated/code/final/TaskActivity.codeblock.add-new-task-to-project.kt
329
+ :language: kotlin
318
330
319
331
Finally, we need to guarantee that ``TaskActivity`` always closes
320
332
the user {+realm+} when the app closes or the user logs out. To
321
333
accomplish this, add logic that calls the ``realm.close()`` method
322
334
when ``TaskActivity`` finishes or stops:
323
335
324
- .. literalinclude:: FIXME FIXME FIXME
336
+ .. literalinclude:: /tutorial/generated/code/final/TaskActivity.codeblock.on-destroy-close-realm.kt
337
+ :language: kotlin
338
+
339
+ .. literalinclude:: /tutorial/generated/code/final/TaskActivity.codeblock.on-stop-close-realm.kt
340
+ :language: kotlin
325
341
326
342
---
327
343
title : Add Logic to Update and Delete Tasks to the TaskAdapter
@@ -347,13 +363,15 @@ content: |
347
363
348
364
Don't forget to read and write from the {+realm+} within a transaction!
349
365
350
- .. literalinclude:: FIXME FIXME FIXME
366
+ .. literalinclude:: /tutorial/generated/code/final/TaskAdapter.codeblock.change-task-status.kt
367
+ :language: kotlin
351
368
352
369
The logic that deletes a task is similar to the logic that updates a
353
370
task, but it removes the task from the {+realm+} instead of updating
354
371
any properties:
355
372
356
- .. literalinclude:: FIXME FIXME FIXME
373
+ .. literalinclude:: /tutorial/generated/code/final/TaskAdapter.codeblock.delete-task.kt
374
+ :language: kotlin
357
375
358
376
---
359
377
title : Implement the Manage Team View
@@ -380,7 +398,8 @@ content: |
380
398
access {+service-short+} Functions through the function manager
381
399
found in your project-global {+service-short+} app:
382
400
383
- .. literalinclude:: FIXME FIXME FIXME
401
+ .. literalinclude:: /tutorial/generated/code/final/MemberActivity.codeblock.get-team-members.kt
402
+ :language: kotlin
384
403
385
404
Similar to ``TaskActivity``, we'll use the floating action button in
386
405
``MemberActivity`` to add users to the project. To handle this, write
@@ -396,7 +415,8 @@ content: |
396
415
backend when the ``addTeamMember()`` {+service-short+} Function
397
416
successfully adds a team member:
398
417
399
- .. literalinclude:: FIXME FIXME FIXME
418
+ .. literalinclude:: /tutorial/generated/code/final/MemberActivity.codeblock.add-new-member-to-project.kt
419
+ :language: kotlin
400
420
401
421
---
402
422
title : Handle Team Member Removals in MemberAdapter
@@ -416,7 +436,8 @@ content: |
416
436
position in the dataset and the UI should automatically stop
417
437
displaying the removed team member:
418
438
419
- .. literalinclude:: FIXME FIXME FIXME
439
+ .. literalinclude:: /tutorial/generated/code/final/MemberAdapter.codeblock.remove-user-from-project.kt
440
+ :language: kotlin
420
441
421
442
---
422
443
title : Run and Test
0 commit comments