Skip to content

Commit c5f31d3

Browse files
authored
Tutorials with examples (#505)
* Add generated code blocks * Update literalincludes WIP * Add more literalincludes * Kotlin WIP * Add languages
1 parent b527f31 commit c5f31d3

File tree

79 files changed

+1085
-95
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

79 files changed

+1085
-95
lines changed

source/includes/steps-tutorial-android-kotlin.yaml

Lines changed: 46 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -9,19 +9,19 @@ content: |
99
1010
.. code-block:: console
1111
12-
$ git clone [email protected]:mongodb-university/realm-tutorial-kotlin-android.git
12+
git clone [email protected]:mongodb-university/realm-tutorial-android-kotlin.git
1313
1414
.. important::
1515
16-
The realm-tutorial-kotlin-android repository contains two branches:
16+
The realm-tutorial-android-kotlin repository contains two branches:
1717
``final`` and ``start``. The ``final`` branch is a finished version
1818
of the app as it should look *after* you complete this tutorial.
1919
To walk through this tutorial, please check out the ``start``
2020
branch:
2121
2222
.. code-block:: console
2323
24-
$ git checkout start
24+
git checkout start
2525
2626
---
2727
title: Open the Project in Android Studio
@@ -38,9 +38,9 @@ content: |
3838
3939
3. In the file navigator opened by Android Studio, navigate to the
4040
directory where, in the previous step, you cloned the
41-
``realm-tutorial-kotlin-android`` repository.
41+
``realm-tutorial-android-kotlin`` repository.
4242
43-
4. Select the ``realm-tutorial-kotlin-android`` folder.
43+
4. Select the ``realm-tutorial-android-kotlin`` folder.
4444
4545
5. Click "Open".
4646
@@ -216,22 +216,24 @@ content: |
216216
fields for email and password entry, as well as buttons to either
217217
register a user account or login to an existing account. We need to
218218
implement the logic to handle user login and user account creation.
219-
219+
220220
You'll find this logic in the ``login()`` method, where a boolean
221221
value called ``createuser`` controls where the method submits user
222222
credentials to create a new account or to login to an existing
223223
account.
224224
225225
First, let's implement the logic that registers a new user:
226226
227-
.. literalinclude:: FIXME FIXME FIXME
227+
.. literalinclude:: /tutorial/generated/code/final/LoginActivity.codeblock.create-user.kt
228+
:language: kotlin
228229
229230
Now, implement the logic to log in with an existing user. Once
230231
logged in successfully, call the ``onLoginSuccess()`` method, which
231232
closes the ``LoginActivity`` and resumes the calling activity
232233
(typically ``ProjectActivity``):
233234
234-
.. literalinclude:: FIXME FIXME FIXME
235+
.. literalinclude:: /tutorial/generated/code/final/LoginActivity.codeblock.login-user.kt
236+
:language: kotlin
235237
236238
Don't forget to call the ``onLoginFailed()`` method in the event of a
237239
login or account creation failure with a message describing the error.
@@ -252,7 +254,8 @@ content: |
252254
the user's {+realm+} in the ``else`` block of the ``onStart()`` method
253255
of ``ProjectActivity``:
254256
255-
.. literalinclude:: FIXME FIXME FIXME
257+
.. literalinclude:: /tutorial/generated/code/final/ProjectActivity.codeblock.set-up-user-realm.kt
258+
:language: kotlin
256259
257260
Next, we need to query the {+realm+} to get a copy of the ``User``
258261
object containing the user's list of projects. Because each user
@@ -263,7 +266,8 @@ content: |
263266
object when the user creates an account. Add the code that queries for
264267
the user object:
265268
266-
.. literalinclude:: FIXME FIXME FIXME
269+
.. literalinclude:: /tutorial/generated/code/final/ProjectActivity.codeblock.user-init-change-listener.kt
270+
:language: kotlin
267271
268272
Because it can take a few seconds for the trigger to create this
269273
object after a login, we should handle the case where the user object
@@ -272,14 +276,19 @@ content: |
272276
watch the {+realm+} for changes and only set up the project's Recycler
273277
View once the trigger runs:
274278
275-
.. literalinclude:: FIXME FIXME FIXME
279+
.. literalinclude:: /tutorial/generated/code/final/ProjectActivity.codeblock.fetch-synced-user-safely.kt
280+
:language: kotlin
276281
277282
Finally, we need to guarantee that ``ProjectActivity`` always closes
278283
the user {+realm+} when the app closes or the user logs out. To
279284
accomplish this, add logic that calls the ``realm.close()`` method
280285
when ``ProjectActivity`` finishes or stops:
281286
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
283292
284293
---
285294
title: Implement the Tasks List
@@ -294,7 +303,8 @@ content: |
294303
the user who owns the project). We'll begin by initializing a
295304
connection to this {+realm+} when the activity starts:
296305
297-
.. literalinclude:: FIXME FIXME FIXME
306+
.. literalinclude:: /tutorial/generated/code/final/TaskActivity.codeblock.set-up-project-realm.kt
307+
:language: kotlin
298308
299309
Next, we'll query the realm for the list of tasks belonging to this
300310
project. Fortunately the query isn't too complicated: since every task
@@ -307,21 +317,27 @@ content: |
307317
list of tasks, pass the ``RealmResult`` to the ``TaskAdapter`` and set
308318
that adapter as the ``RecyclerView's`` adapter:
309319
310-
.. literalinclude:: FIXME FIXME FIXME
320+
.. literalinclude:: /tutorial/generated/code/final/TaskActivity.codeblock.fetch-tasks-for-project-sorted-by-id.kt
321+
:language: kotlin
311322
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+}:
316327
317-
.. literalinclude:: FIXME FIXME FIXME
328+
.. literalinclude:: /tutorial/generated/code/final/TaskActivity.codeblock.add-new-task-to-project.kt
329+
:language: kotlin
318330
319331
Finally, we need to guarantee that ``TaskActivity`` always closes
320332
the user {+realm+} when the app closes or the user logs out. To
321333
accomplish this, add logic that calls the ``realm.close()`` method
322334
when ``TaskActivity`` finishes or stops:
323335
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
325341
326342
---
327343
title: Add Logic to Update and Delete Tasks to the TaskAdapter
@@ -347,13 +363,15 @@ content: |
347363
348364
Don't forget to read and write from the {+realm+} within a transaction!
349365
350-
.. literalinclude:: FIXME FIXME FIXME
366+
.. literalinclude:: /tutorial/generated/code/final/TaskAdapter.codeblock.change-task-status.kt
367+
:language: kotlin
351368
352369
The logic that deletes a task is similar to the logic that updates a
353370
task, but it removes the task from the {+realm+} instead of updating
354371
any properties:
355372
356-
.. literalinclude:: FIXME FIXME FIXME
373+
.. literalinclude:: /tutorial/generated/code/final/TaskAdapter.codeblock.delete-task.kt
374+
:language: kotlin
357375
358376
---
359377
title: Implement the Manage Team View
@@ -380,7 +398,8 @@ content: |
380398
access {+service-short+} Functions through the function manager
381399
found in your project-global {+service-short+} app:
382400
383-
.. literalinclude:: FIXME FIXME FIXME
401+
.. literalinclude:: /tutorial/generated/code/final/MemberActivity.codeblock.get-team-members.kt
402+
:language: kotlin
384403
385404
Similar to ``TaskActivity``, we'll use the floating action button in
386405
``MemberActivity`` to add users to the project. To handle this, write
@@ -396,7 +415,8 @@ content: |
396415
backend when the ``addTeamMember()`` {+service-short+} Function
397416
successfully adds a team member:
398417
399-
.. literalinclude:: FIXME FIXME FIXME
418+
.. literalinclude:: /tutorial/generated/code/final/MemberActivity.codeblock.add-new-member-to-project.kt
419+
:language: kotlin
400420
401421
---
402422
title: Handle Team Member Removals in MemberAdapter
@@ -416,7 +436,8 @@ content: |
416436
position in the dataset and the UI should automatically stop
417437
displaying the removed team member:
418438
419-
.. literalinclude:: FIXME FIXME FIXME
439+
.. literalinclude:: /tutorial/generated/code/final/MemberAdapter.codeblock.remove-user-from-project.kt
440+
:language: kotlin
420441
421442
---
422443
title: Run and Test

0 commit comments

Comments
 (0)