├── app
├── .gitignore
├── src
│ ├── main
│ │ ├── ic_launcher_sleep_tracker-web.png
│ │ ├── res
│ │ │ ├── mipmap-hdpi
│ │ │ │ ├── ic_launcher.png
│ │ │ │ ├── ic_launcher_round.png
│ │ │ │ ├── ic_launcher_sleep_tracker.png
│ │ │ │ └── ic_launcher_sleep_tracker_round.png
│ │ │ ├── mipmap-mdpi
│ │ │ │ ├── ic_launcher.png
│ │ │ │ ├── ic_launcher_round.png
│ │ │ │ ├── ic_launcher_sleep_tracker.png
│ │ │ │ └── ic_launcher_sleep_tracker_round.png
│ │ │ ├── mipmap-xhdpi
│ │ │ │ ├── ic_launcher.png
│ │ │ │ ├── ic_launcher_round.png
│ │ │ │ ├── ic_launcher_sleep_tracker.png
│ │ │ │ └── ic_launcher_sleep_tracker_round.png
│ │ │ ├── mipmap-xxhdpi
│ │ │ │ ├── ic_launcher.png
│ │ │ │ ├── ic_launcher_round.png
│ │ │ │ ├── ic_launcher_sleep_tracker.png
│ │ │ │ └── ic_launcher_sleep_tracker_round.png
│ │ │ ├── mipmap-xxxhdpi
│ │ │ │ ├── ic_launcher.png
│ │ │ │ ├── ic_launcher_round.png
│ │ │ │ ├── ic_launcher_sleep_tracker.png
│ │ │ │ └── ic_launcher_sleep_tracker_round.png
│ │ │ ├── font
│ │ │ │ └── roboto.xml
│ │ │ ├── values
│ │ │ │ ├── preloaded_fonts.xml
│ │ │ │ ├── dimens.xml
│ │ │ │ ├── colors.xml
│ │ │ │ ├── styles.xml
│ │ │ │ ├── strings.xml
│ │ │ │ └── font_certs.xml
│ │ │ ├── anim
│ │ │ │ └── slide_in_right.xml
│ │ │ ├── mipmap-anydpi-v26
│ │ │ │ ├── ic_launcher.xml
│ │ │ │ ├── ic_launcher_round.xml
│ │ │ │ ├── ic_launcher_sleep_tracker.xml
│ │ │ │ └── ic_launcher_sleep_tracker_round.xml
│ │ │ ├── layout
│ │ │ │ ├── activity_main.xml
│ │ │ │ ├── fragment_sleep_tracker.xml
│ │ │ │ └── fragment_sleep_quality.xml
│ │ │ ├── drawable
│ │ │ │ ├── ic_sleep_1.xml
│ │ │ │ ├── ic_sleep_4.xml
│ │ │ │ ├── ic_sleep_2.xml
│ │ │ │ ├── ic_sleep_0.xml
│ │ │ │ ├── ic_sleep_5.xml
│ │ │ │ ├── ic_sleep_3.xml
│ │ │ │ ├── ic_launcher_sleep_tracker_background.xml
│ │ │ │ └── ic_launcher_sleep_tracker_foreground.xml
│ │ │ └── navigation
│ │ │ │ └── navigation.xml
│ │ ├── AndroidManifest.xml
│ │ └── java
│ │ │ └── com
│ │ │ └── example
│ │ │ └── android
│ │ │ └── trackmysleepquality
│ │ │ ├── database
│ │ │ ├── SleepNight.kt
│ │ │ ├── SleepDatabaseDao.kt
│ │ │ └── SleepDatabase.kt
│ │ │ ├── sleepquality
│ │ │ ├── SleepQualityViewModelFactory.kt
│ │ │ ├── SleepQualityViewModel.kt
│ │ │ └── SleepQualityFragment.kt
│ │ │ ├── sleeptracker
│ │ │ ├── SleepTrackerViewModelFactory.kt
│ │ │ ├── SleepTrackerFragment.kt
│ │ │ └── SleepTrackerViewModel.kt
│ │ │ ├── MainActivity.kt
│ │ │ └── Util.kt
│ └── androidTest
│ │ └── java
│ │ └── com
│ │ └── example
│ │ └── android
│ │ └── trackmysleepquality
│ │ └── SleepDatabaseTest.kt
├── proguard-rules.pro
└── build.gradle
├── settings.gradle
├── CODEOWNERS
├── .gitignore
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── screenshots
├── sleep_quality_tracker_start.png
├── sleep_quality_tracker_stop.png
└── sleep_quality_tracker_quality.png
├── gradle.properties
├── .github
└── workflows
│ └── manual.yml
├── gradlew.bat
├── README.md
├── gradlew
└── LICENSE.txt
/app/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':app'
2 |
--------------------------------------------------------------------------------
/CODEOWNERS:
--------------------------------------------------------------------------------
1 | * @udacity/active-public-content
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | *.iml
2 | .gradle
3 | /local.properties
4 | .idea
5 | .DS_Store
6 | /build
7 | /captures
8 | .externalNativeBuild
9 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/udacity/andfun-kotlin-sleep-tracker/HEAD/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/screenshots/sleep_quality_tracker_start.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/udacity/andfun-kotlin-sleep-tracker/HEAD/screenshots/sleep_quality_tracker_start.png
--------------------------------------------------------------------------------
/screenshots/sleep_quality_tracker_stop.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/udacity/andfun-kotlin-sleep-tracker/HEAD/screenshots/sleep_quality_tracker_stop.png
--------------------------------------------------------------------------------
/app/src/main/ic_launcher_sleep_tracker-web.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/udacity/andfun-kotlin-sleep-tracker/HEAD/app/src/main/ic_launcher_sleep_tracker-web.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/udacity/andfun-kotlin-sleep-tracker/HEAD/app/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/udacity/andfun-kotlin-sleep-tracker/HEAD/app/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/udacity/andfun-kotlin-sleep-tracker/HEAD/app/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/udacity/andfun-kotlin-sleep-tracker/HEAD/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/screenshots/sleep_quality_tracker_quality.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/udacity/andfun-kotlin-sleep-tracker/HEAD/screenshots/sleep_quality_tracker_quality.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/udacity/andfun-kotlin-sleep-tracker/HEAD/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/udacity/andfun-kotlin-sleep-tracker/HEAD/app/src/main/res/mipmap-hdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/udacity/andfun-kotlin-sleep-tracker/HEAD/app/src/main/res/mipmap-mdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/udacity/andfun-kotlin-sleep-tracker/HEAD/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/udacity/andfun-kotlin-sleep-tracker/HEAD/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/udacity/andfun-kotlin-sleep-tracker/HEAD/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher_sleep_tracker.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/udacity/andfun-kotlin-sleep-tracker/HEAD/app/src/main/res/mipmap-hdpi/ic_launcher_sleep_tracker.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher_sleep_tracker.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/udacity/andfun-kotlin-sleep-tracker/HEAD/app/src/main/res/mipmap-mdpi/ic_launcher_sleep_tracker.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher_sleep_tracker.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/udacity/andfun-kotlin-sleep-tracker/HEAD/app/src/main/res/mipmap-xhdpi/ic_launcher_sleep_tracker.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher_sleep_tracker.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/udacity/andfun-kotlin-sleep-tracker/HEAD/app/src/main/res/mipmap-xxhdpi/ic_launcher_sleep_tracker.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher_sleep_tracker.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/udacity/andfun-kotlin-sleep-tracker/HEAD/app/src/main/res/mipmap-xxxhdpi/ic_launcher_sleep_tracker.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher_sleep_tracker_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/udacity/andfun-kotlin-sleep-tracker/HEAD/app/src/main/res/mipmap-hdpi/ic_launcher_sleep_tracker_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher_sleep_tracker_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/udacity/andfun-kotlin-sleep-tracker/HEAD/app/src/main/res/mipmap-mdpi/ic_launcher_sleep_tracker_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher_sleep_tracker_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/udacity/andfun-kotlin-sleep-tracker/HEAD/app/src/main/res/mipmap-xhdpi/ic_launcher_sleep_tracker_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher_sleep_tracker_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/udacity/andfun-kotlin-sleep-tracker/HEAD/app/src/main/res/mipmap-xxhdpi/ic_launcher_sleep_tracker_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher_sleep_tracker_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/udacity/andfun-kotlin-sleep-tracker/HEAD/app/src/main/res/mipmap-xxxhdpi/ic_launcher_sleep_tracker_round.png
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Tue Aug 11 17:39:48 PDT 2020
2 | distributionBase=GRADLE_USER_HOME
3 | distributionPath=wrapper/dists
4 | zipStoreBase=GRADLE_USER_HOME
5 | zipStorePath=wrapper/dists
6 | distributionUrl=https\://services.gradle.org/distributions/gradle-8.8-bin.zip
7 |
--------------------------------------------------------------------------------
/app/src/main/res/font/roboto.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
--------------------------------------------------------------------------------
/gradle.properties:
--------------------------------------------------------------------------------
1 | # Project-wide Gradle settings.
2 | # IDE (e.g. Android Studio) users:
3 | # Gradle settings configured through the IDE *will override*
4 | # any settings specified in this file.
5 | # For more details on how to configure your build environment visit
6 | # http://www.gradle.org/docs/current/userguide/build_environment.html
7 | # Specifies the JVM arguments used for the daemon process.
8 | # The setting is particularly useful for tweaking memory settings.
9 | org.gradle.jvmargs=-Xmx1536m
10 | # When configured, Gradle will run in incubating parallel mode.
11 | # This option should only be used with decoupled projects. More details, visit
12 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
13 | # org.gradle.parallel=true
14 | android.useAndroidX=true
15 | android.enableJetifier=true
16 |
--------------------------------------------------------------------------------
/app/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # You can control the set of applied configuration files using the
3 | # proguardFiles setting in build.gradle.
4 | #
5 | # For more details, see
6 | # http://developer.android.com/guide/developing/tools/proguard.html
7 |
8 | # If your project uses WebView with JS, uncomment the following
9 | # and specify the fully qualified class name to the JavaScript interface
10 | # class:
11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
12 | # public *;
13 | #}
14 |
15 | # Uncomment this to preserve the line number information for
16 | # debugging stack traces.
17 | #-keepattributes SourceFile,LineNumberTable
18 |
19 | # If you keep the line number information, uncomment this to
20 | # hide the original source file name.
21 | #-renamesourcefileattribute SourceFile
22 |
--------------------------------------------------------------------------------
/app/src/main/res/values/preloaded_fonts.xml:
--------------------------------------------------------------------------------
1 |
16 |
17 |
18 |
19 | @font/roboto
20 |
21 |
22 |
--------------------------------------------------------------------------------
/app/src/main/res/values/dimens.xml:
--------------------------------------------------------------------------------
1 |
16 |
17 |
18 | 16dp
19 | 64dp
20 | 20sp
21 | 48dp
22 |
23 |
--------------------------------------------------------------------------------
/app/src/main/res/anim/slide_in_right.xml:
--------------------------------------------------------------------------------
1 |
16 |
17 |
18 |
19 |
25 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml:
--------------------------------------------------------------------------------
1 |
2 |
17 |
18 |
19 |
20 |
21 |
22 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml:
--------------------------------------------------------------------------------
1 |
2 |
17 |
18 |
19 |
20 |
21 |
22 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-anydpi-v26/ic_launcher_sleep_tracker.xml:
--------------------------------------------------------------------------------
1 |
2 |
17 |
18 |
19 |
20 |
21 |
22 |
--------------------------------------------------------------------------------
/app/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
16 |
17 |
18 |
19 | #6ab343
20 | #388310
21 | #6ab343
22 |
23 | #388310
24 | #f0f0f0
25 |
26 |
27 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-anydpi-v26/ic_launcher_sleep_tracker_round.xml:
--------------------------------------------------------------------------------
1 |
2 |
17 |
18 |
19 |
20 |
21 |
22 |
--------------------------------------------------------------------------------
/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
12 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
23 |
24 |
25 |
26 |
--------------------------------------------------------------------------------
/app/src/main/java/com/example/android/trackmysleepquality/database/SleepNight.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2018, The Android Open Source Project
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.example.android.trackmysleepquality.database
18 |
19 | import androidx.room.ColumnInfo
20 | import androidx.room.Entity
21 | import androidx.room.PrimaryKey
22 |
23 | @Entity(tableName = "daily_sleep_quality_table")
24 | data class SleepNight(
25 | @PrimaryKey(autoGenerate = true)
26 | var nightId: Long = 0L,
27 |
28 | @ColumnInfo(name = "start_time_milli")
29 | val startTimeMilli: Long = System.currentTimeMillis(),
30 |
31 | @ColumnInfo(name = "end_time_milli")
32 | var endTimeMilli: Long = startTimeMilli,
33 |
34 | @ColumnInfo(name = "quality_rating")
35 | var sleepQuality: Int = -1
36 | )
37 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
16 |
17 |
20 |
21 |
23 |
24 |
31 |
32 |
33 |
--------------------------------------------------------------------------------
/app/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
16 |
17 |
18 |
19 |
20 |
25 |
26 |
27 |
33 |
34 |
35 |
--------------------------------------------------------------------------------
/app/src/main/java/com/example/android/trackmysleepquality/sleepquality/SleepQualityViewModelFactory.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2018, The Android Open Source Project
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.example.android.trackmysleepquality.sleepquality
18 |
19 | import androidx.lifecycle.ViewModel
20 | import androidx.lifecycle.ViewModelProvider
21 | import com.example.android.trackmysleepquality.database.SleepDatabaseDao
22 |
23 | /**
24 | * This is pretty much boiler plate code for a ViewModel Factory.
25 | *
26 | * Provides the key for the night and the SleepDatabaseDao to the ViewModel.
27 | */
28 | class SleepQualityViewModelFactory(
29 | private val sleepNightKey: Long,
30 | private val dataSource: SleepDatabaseDao) : ViewModelProvider.Factory {
31 | @Suppress("unchecked_cast")
32 | override fun create(modelClass: Class): T {
33 | if (modelClass.isAssignableFrom(SleepQualityViewModel::class.java)) {
34 | return SleepQualityViewModel(sleepNightKey, dataSource) as T
35 | }
36 | throw IllegalArgumentException("Unknown ViewModel class")
37 | }
38 | }
39 |
--------------------------------------------------------------------------------
/app/src/main/java/com/example/android/trackmysleepquality/sleeptracker/SleepTrackerViewModelFactory.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2018, The Android Open Source Project
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.example.android.trackmysleepquality.sleeptracker
18 |
19 | import android.app.Application
20 | import androidx.lifecycle.ViewModel
21 | import androidx.lifecycle.ViewModelProvider
22 | import com.example.android.trackmysleepquality.database.SleepDatabaseDao
23 |
24 | /**
25 | * This is pretty much boiler plate code for a ViewModel Factory.
26 | *
27 | * Provides the SleepDatabaseDao and context to the ViewModel.
28 | */
29 | class SleepTrackerViewModelFactory(
30 | private val dataSource: SleepDatabaseDao,
31 | private val application: Application) : ViewModelProvider.Factory {
32 | @Suppress("unchecked_cast")
33 | override fun create(modelClass: Class): T {
34 | if (modelClass.isAssignableFrom(SleepTrackerViewModel::class.java)) {
35 | return SleepTrackerViewModel(dataSource, application) as T
36 | }
37 | throw IllegalArgumentException("Unknown ViewModel class")
38 | }
39 | }
40 |
41 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_sleep_1.xml:
--------------------------------------------------------------------------------
1 |
3 |
4 |
5 |
6 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_sleep_4.xml:
--------------------------------------------------------------------------------
1 |
3 |
4 |
5 |
6 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
--------------------------------------------------------------------------------
/.github/workflows/manual.yml:
--------------------------------------------------------------------------------
1 | # Workflow to ensure whenever a Github PR is submitted,
2 | # a JIRA ticket gets created automatically.
3 | name: Manual Workflow
4 |
5 | # Controls when the action will run.
6 | on:
7 | # Triggers the workflow on pull request events but only for the master branch
8 | pull_request_target:
9 | types: [opened, reopened]
10 |
11 | # Allows you to run this workflow manually from the Actions tab
12 | workflow_dispatch:
13 |
14 | jobs:
15 | test-transition-issue:
16 | name: Convert Github Issue to Jira Issue
17 | runs-on: ubuntu-latest
18 | steps:
19 | - name: Checkout
20 | uses: actions/checkout@master
21 |
22 | - name: Login
23 | uses: atlassian/gajira-login@master
24 | env:
25 | JIRA_BASE_URL: ${{ secrets.JIRA_BASE_URL }}
26 | JIRA_USER_EMAIL: ${{ secrets.JIRA_USER_EMAIL }}
27 | JIRA_API_TOKEN: ${{ secrets.JIRA_API_TOKEN }}
28 |
29 | - name: Create NEW JIRA ticket
30 | id: create
31 | uses: atlassian/gajira-create@master
32 | with:
33 | project: CONUPDATE
34 | issuetype: Task
35 | summary: |
36 | Github PR nd940 - Android Kotlin Developer | Repo: ${{ github.repository }} | PR# ${{github.event.number}}
37 | description: |
38 | Repo link: https://github.com/${{ github.repository }}
39 | PR no. ${{ github.event.pull_request.number }}
40 | PR title: ${{ github.event.pull_request.title }}
41 | PR description: ${{ github.event.pull_request.description }}
42 | In addition, please resolve other issues, if any.
43 | fields: '{"components": [{"name":"nd940 - Android Kotlin Developer"}], "customfield_16449":"https://classroom.udacity.com/", "customfield_16450":"Resolve the PR", "labels": ["github"], "priority":{"id": "4"}}'
44 |
45 | - name: Log created issue
46 | run: echo "Issue ${{ steps.create.outputs.issue }} was created"
47 |
--------------------------------------------------------------------------------
/app/src/main/java/com/example/android/trackmysleepquality/MainActivity.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2018, The Android Open Source Project
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.example.android.trackmysleepquality
18 |
19 | import android.os.Bundle
20 | import androidx.appcompat.app.AppCompatActivity
21 |
22 |
23 | /**
24 | * This is the toy app for lesson 6 of the
25 | * Android App Development in Kotlin course on Udacity(https://www.udacity.com/course/???).
26 | *
27 | * The SleepQualityTracker app is a demo app that helps you collect information about your sleep.
28 | * - Start time, end time, quality, and time slept
29 | *
30 | * This app demonstrates the following views and techniques:
31 | * - Room database, DAO, and Coroutines
32 | *
33 | * It also uses and builds on the following techniques from previous lessons:
34 | * - Transformation map
35 | * - Data Binding in XML files
36 | * - ViewModel Factory
37 | * - Using Backing Properties to protect MutableLiveData
38 | * - Observable state LiveData variables to trigger navigation
39 | */
40 |
41 | /**
42 | * This main activity is just a container for our fragments,
43 | * where the real action is.
44 | */
45 | class MainActivity : AppCompatActivity() {
46 |
47 | override fun onCreate(savedInstanceState: Bundle?) {
48 | super.onCreate(savedInstanceState)
49 |
50 | setContentView(R.layout.activity_main)
51 | }
52 | }
53 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_sleep_2.xml:
--------------------------------------------------------------------------------
1 |
3 |
4 |
5 |
6 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_sleep_0.xml:
--------------------------------------------------------------------------------
1 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_sleep_5.xml:
--------------------------------------------------------------------------------
1 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_sleep_3.xml:
--------------------------------------------------------------------------------
1 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
14 |
15 |
--------------------------------------------------------------------------------
/app/src/main/java/com/example/android/trackmysleepquality/database/SleepDatabaseDao.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2018, The Android Open Source Project
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.example.android.trackmysleepquality.database
18 |
19 | import androidx.lifecycle.LiveData
20 | import androidx.room.Dao
21 | import androidx.room.Insert
22 | import androidx.room.Query
23 | import androidx.room.Update
24 |
25 | /**
26 | * Defines methods for using the SleepNight class with Room.
27 | */
28 | @Dao
29 | interface SleepDatabaseDao {
30 |
31 | @Insert
32 | suspend fun insert(night: SleepNight)
33 |
34 | /**
35 | * When updating a row with a value already set in a column,
36 | * replaces the old value with the new one.
37 | *
38 | * @param night new value to write
39 | */
40 | @Update
41 | suspend fun update(night: SleepNight)
42 |
43 | /**
44 | * Selects and returns the row that matches the supplied start time, which is our key.
45 | *
46 | * @param key startTimeMilli to match
47 | */
48 | @Query("SELECT * from daily_sleep_quality_table WHERE nightId = :key")
49 | suspend fun get(key: Long): SleepNight?
50 |
51 | /**
52 | * Deletes all values from the table.
53 | *
54 | * This does not delete the table, only its contents.
55 | */
56 | @Query("DELETE FROM daily_sleep_quality_table")
57 | suspend fun clear()
58 |
59 | /**
60 | * Selects and returns all rows in the table,
61 | *
62 | * sorted by start time in descending order.
63 | */
64 | @Query("SELECT * FROM daily_sleep_quality_table ORDER BY nightId DESC")
65 | fun getAllNights(): LiveData>
66 |
67 | /**
68 | * Selects and returns the latest night.
69 | */
70 | @Query("SELECT * FROM daily_sleep_quality_table ORDER BY nightId DESC LIMIT 1")
71 | suspend fun getTonight(): SleepNight?
72 |
73 | }
74 |
75 |
--------------------------------------------------------------------------------
/app/src/main/res/navigation/navigation.xml:
--------------------------------------------------------------------------------
1 |
16 |
17 |
19 |
20 |
25 |
26 |
31 |
36 |
37 |
38 |
43 |
46 |
52 |
53 |
54 |
55 |
--------------------------------------------------------------------------------
/gradlew.bat:
--------------------------------------------------------------------------------
1 | @if "%DEBUG%" == "" @echo off
2 | @rem ##########################################################################
3 | @rem
4 | @rem Gradle startup script for Windows
5 | @rem
6 | @rem ##########################################################################
7 |
8 | @rem Set local scope for the variables with windows NT shell
9 | if "%OS%"=="Windows_NT" setlocal
10 |
11 | set DIRNAME=%~dp0
12 | if "%DIRNAME%" == "" set DIRNAME=.
13 | set APP_BASE_NAME=%~n0
14 | set APP_HOME=%DIRNAME%
15 |
16 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
17 | set DEFAULT_JVM_OPTS=
18 |
19 | @rem Find java.exe
20 | if defined JAVA_HOME goto findJavaFromJavaHome
21 |
22 | set JAVA_EXE=java.exe
23 | %JAVA_EXE% -version >NUL 2>&1
24 | if "%ERRORLEVEL%" == "0" goto init
25 |
26 | echo.
27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
28 | echo.
29 | echo Please set the JAVA_HOME variable in your environment to match the
30 | echo location of your Java installation.
31 |
32 | goto fail
33 |
34 | :findJavaFromJavaHome
35 | set JAVA_HOME=%JAVA_HOME:"=%
36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
37 |
38 | if exist "%JAVA_EXE%" goto init
39 |
40 | echo.
41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
42 | echo.
43 | echo Please set the JAVA_HOME variable in your environment to match the
44 | echo location of your Java installation.
45 |
46 | goto fail
47 |
48 | :init
49 | @rem Get command-line arguments, handling Windows variants
50 |
51 | if not "%OS%" == "Windows_NT" goto win9xME_args
52 |
53 | :win9xME_args
54 | @rem Slurp the command line arguments.
55 | set CMD_LINE_ARGS=
56 | set _SKIP=2
57 |
58 | :win9xME_args_slurp
59 | if "x%~1" == "x" goto execute
60 |
61 | set CMD_LINE_ARGS=%*
62 |
63 | :execute
64 | @rem Setup the command line
65 |
66 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
67 |
68 | @rem Execute Gradle
69 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
70 |
71 | :end
72 | @rem End local scope for the variables with windows NT shell
73 | if "%ERRORLEVEL%"=="0" goto mainEnd
74 |
75 | :fail
76 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
77 | rem the _cmd.exe /c_ return code!
78 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
79 | exit /b 1
80 |
81 | :mainEnd
82 | if "%OS%"=="Windows_NT" endlocal
83 |
84 | :omega
85 |
--------------------------------------------------------------------------------
/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
16 |
17 |
18 |
19 |
20 | Track My Sleep Quality
21 | SleepTrackerFragment
22 | SleepQualityFragment
23 |
24 |
25 | Start
26 | Stop
27 | Clear
28 |
29 |
30 | Sleep Quality 0
31 | Sleep Quality 1
32 | Sleep Quality 2
33 | Sleep Quality 3
34 | Sleep Quality 4
35 | Sleep Quality 5
36 |
37 |
38 | HERE IS YOUR SLEEP DATA]]>
39 | Start:]]>
40 | End:]]>
41 | Quality:]]>
42 | Hours:Minutes:Seconds]]>
43 |
44 |
45 | How was your sleep?
46 | Very bad
47 | Poor
48 | So-so
49 | OK
50 | Pretty good
51 | Excellent!
52 |
53 |
54 | All your data is gone forever.
55 |
56 |
57 |
--------------------------------------------------------------------------------
/app/src/androidTest/java/com/example/android/trackmysleepquality/SleepDatabaseTest.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2018, The Android Open Source Project
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.example.android.trackmysleepquality
18 |
19 | import androidx.room.Room
20 | import androidx.test.ext.junit.runners.AndroidJUnit4
21 | import androidx.test.platform.app.InstrumentationRegistry
22 | import com.example.android.trackmysleepquality.database.SleepDatabase
23 | import com.example.android.trackmysleepquality.database.SleepDatabaseDao
24 | import com.example.android.trackmysleepquality.database.SleepNight
25 | import kotlinx.coroutines.runBlocking
26 | import org.junit.Assert.assertEquals
27 | import org.junit.After
28 | import org.junit.Before
29 | import org.junit.Test
30 | import org.junit.runner.RunWith
31 | import java.io.IOException
32 |
33 | /**
34 | * This is not meant to be a full set of tests. For simplicity, most of your samples do not
35 | * include tests. However, when building the Room, it is helpful to make sure it works before
36 | * adding the UI.
37 | */
38 |
39 | @RunWith(AndroidJUnit4::class)
40 | class SleepDatabaseTest {
41 |
42 | private lateinit var sleepDao: SleepDatabaseDao
43 | private lateinit var db: SleepDatabase
44 |
45 | @Before
46 | fun createDb() {
47 | val context = InstrumentationRegistry.getInstrumentation().targetContext
48 | // Using an in-memory database because the information stored here disappears when the
49 | // process is killed.
50 | db = Room.inMemoryDatabaseBuilder(context, SleepDatabase::class.java)
51 | // Allowing main thread queries, just for testing.
52 | .allowMainThreadQueries()
53 | .build()
54 | sleepDao = db.sleepDatabaseDao
55 | }
56 |
57 | @After
58 | @Throws(IOException::class)
59 | fun closeDb() {
60 | db.close()
61 | }
62 |
63 | @Test
64 | @Throws(Exception::class)
65 | fun insertAndGetNight() = runBlocking {
66 | val night = SleepNight()
67 | sleepDao.insert(night)
68 | val tonight = sleepDao.getTonight()
69 | assertEquals(tonight?.sleepQuality, -1)
70 | }
71 | }
72 |
73 |
--------------------------------------------------------------------------------
/app/src/main/java/com/example/android/trackmysleepquality/sleepquality/SleepQualityViewModel.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2018, The Android Open Source Project
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.example.android.trackmysleepquality.sleepquality
18 |
19 | import androidx.lifecycle.LiveData
20 | import androidx.lifecycle.MutableLiveData
21 | import androidx.lifecycle.ViewModel
22 | import androidx.lifecycle.viewModelScope
23 | import com.example.android.trackmysleepquality.database.SleepDatabaseDao
24 | import kotlinx.coroutines.*
25 |
26 | /**
27 | * ViewModel for SleepQualityFragment.
28 | *
29 | * @param sleepNightKey The key of the current night we are working on.
30 | */
31 | class SleepQualityViewModel(
32 | private val sleepNightKey: Long = 0L,
33 | val database: SleepDatabaseDao) : ViewModel() {
34 |
35 |
36 | /**
37 | */
38 |
39 | /**
40 | *
41 | *
42 | */
43 |
44 | /**
45 | * Variable that tells the fragment whether it should navigate to [SleepTrackerFragment].
46 | *
47 | * This is `private` because we don't want to expose the ability to set [MutableLiveData] to
48 | * the [Fragment]
49 | */
50 | private val _navigateToSleepTracker = MutableLiveData()
51 |
52 | /**
53 | * When true immediately navigate back to the [SleepTrackerFragment]
54 | */
55 | val navigateToSleepTracker: LiveData
56 | get() = _navigateToSleepTracker
57 |
58 | /**
59 | *
60 | */
61 |
62 | /**
63 | * Call this immediately after navigating to [SleepTrackerFragment]
64 | */
65 | fun doneNavigating() {
66 | _navigateToSleepTracker.value = null
67 | }
68 |
69 | /**
70 | * Sets the sleep quality and updates the database.
71 | *
72 | * Then navigates back to the SleepTrackerFragment.
73 | */
74 | fun onSetSleepQuality(quality: Int) {
75 | viewModelScope.launch {
76 | val tonight = database.get(sleepNightKey) ?: return@launch
77 | tonight.sleepQuality = quality
78 | database.update(tonight)
79 |
80 | // Setting this state variable to true will alert the observer and trigger navigation.
81 | _navigateToSleepTracker.value = true
82 | }
83 | }
84 | }
85 |
86 |
--------------------------------------------------------------------------------
/app/build.gradle:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2018, The Android Open Source Project
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | apply plugin: 'com.android.application'
18 | apply plugin: 'kotlin-android'
19 | // Kotlin Android Extensions is deprecated, which means that using Kotlin synthetics for view binding is no longer supported.
20 | // apply plugin: 'kotlin-android-extensions'
21 | apply plugin: 'kotlin-kapt'
22 | apply plugin: 'androidx.navigation.safeargs'
23 |
24 | android {
25 | compileSdk 34
26 | defaultConfig {
27 | applicationId "com.example.android.trackmysleepquality"
28 | minSdkVersion 21
29 | targetSdkVersion 34
30 | versionCode 1
31 | versionName "1.0"
32 | multiDexEnabled true
33 | vectorDrawables.useSupportLibrary = true
34 | testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
35 | }
36 | buildTypes {
37 | release {
38 | minifyEnabled false
39 | proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
40 | }
41 | }
42 |
43 | // Enables data binding.
44 | buildFeatures {
45 | dataBinding true
46 | }
47 | namespace = "com.example.android.trackmysleepquality"
48 |
49 | compileOptions {
50 | sourceCompatibility = JavaVersion.VERSION_21
51 | targetCompatibility = JavaVersion.VERSION_21
52 | }
53 | }
54 |
55 | dependencies {
56 | implementation fileTree(dir: 'libs', include: ['*.jar'])
57 | implementation 'androidx.legacy:legacy-support-v4:1.0.0'
58 | implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$version_kotlin"
59 |
60 | // Support libraries
61 | implementation "androidx.constraintlayout:constraintlayout:$version_constraint_layout"
62 |
63 | // Android KTX
64 | implementation "androidx.core:core-ktx:$version_core"
65 |
66 | // Room and Lifecycle dependencies
67 | implementation "androidx.room:room-runtime:$version_room"
68 | kapt "androidx.room:room-compiler:$version_room"
69 | // The APIs in lifecycle-extensions have been deprecated. Instead, add dependencies for the specific Lifecycle artifacts you need.
70 | // implementation "androidx.lifecycle:lifecycle-extensions:$version_lifecycle_extensions"
71 |
72 | // Coroutines
73 | implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core:$version_coroutine"
74 | implementation "org.jetbrains.kotlinx:kotlinx-coroutines-android:$version_coroutine"
75 |
76 | // Navigation
77 | implementation "androidx.navigation:navigation-fragment-ktx:$version_navigation"
78 | implementation "androidx.navigation:navigation-ui-ktx:$version_navigation"
79 |
80 | // ViewModel and LiveData
81 | implementation "androidx.lifecycle:lifecycle-viewmodel-ktx:$version_lifecycle"
82 |
83 | // Kotlin Extensions and Coroutines support for Room
84 | implementation "androidx.room:room-ktx:$version_room"
85 |
86 |
87 | // Testing
88 | testImplementation 'junit:junit:4.13.2'
89 | androidTestImplementation 'androidx.test.ext:junit:1.1.5'
90 | androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1'
91 | }
92 |
93 |
--------------------------------------------------------------------------------
/app/src/main/java/com/example/android/trackmysleepquality/sleepquality/SleepQualityFragment.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2018, The Android Open Source Project
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.example.android.trackmysleepquality.sleepquality
18 |
19 | import android.os.Bundle
20 | import android.view.LayoutInflater
21 | import android.view.View
22 | import android.view.ViewGroup
23 | import androidx.databinding.DataBindingUtil
24 | import androidx.fragment.app.Fragment
25 | import androidx.lifecycle.Observer
26 | import androidx.lifecycle.ViewModelProvider
27 | import androidx.navigation.fragment.findNavController
28 | import com.example.android.trackmysleepquality.R
29 | import com.example.android.trackmysleepquality.database.SleepDatabase
30 | import com.example.android.trackmysleepquality.databinding.FragmentSleepQualityBinding
31 |
32 | /**
33 | * Fragment that displays a list of clickable icons,
34 | * each representing a sleep quality rating.
35 | * Once the user taps an icon, the quality is set in the current sleepNight
36 | * and the database is updated.
37 | */
38 | class SleepQualityFragment : Fragment() {
39 |
40 | /**
41 | * Called when the Fragment is ready to display content to the screen.
42 | *
43 | * This function uses DataBindingUtil to inflate R.layout.fragment_sleep_quality.
44 | */
45 | override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?,
46 | savedInstanceState: Bundle?): View? {
47 |
48 | // Get a reference to the binding object and inflate the fragment views.
49 | val binding: FragmentSleepQualityBinding = DataBindingUtil.inflate(
50 | inflater, R.layout.fragment_sleep_quality, container, false)
51 |
52 | val application = requireNotNull(this.activity).application
53 |
54 | val arguments = SleepQualityFragmentArgs.fromBundle(arguments!!)
55 |
56 | // Create an instance of the ViewModel Factory.
57 | val dataSource = SleepDatabase.getInstance(application).sleepDatabaseDao
58 | val viewModelFactory = SleepQualityViewModelFactory(arguments.sleepNightKey, dataSource)
59 |
60 | // Get a reference to the ViewModel associated with this fragment.
61 | val sleepQualityViewModel =
62 | ViewModelProvider(
63 | this, viewModelFactory).get(SleepQualityViewModel::class.java)
64 |
65 | // To use the View Model with data binding, you have to explicitly
66 | // give the binding object a reference to it.
67 | binding.sleepQualityViewModel = sleepQualityViewModel
68 |
69 | // Add an Observer to the state variable for Navigating when a Quality icon is tapped.
70 | sleepQualityViewModel.navigateToSleepTracker.observe(viewLifecycleOwner, Observer {
71 | if (it == true) { // Observed state is true.
72 | this.findNavController().navigate(
73 | SleepQualityFragmentDirections.actionSleepQualityFragmentToSleepTrackerFragment())
74 | // Reset state to make sure we only navigate once, even if the device
75 | // has a configuration change.
76 | sleepQualityViewModel.doneNavigating()
77 | }
78 | })
79 |
80 | return binding.root
81 | }
82 | }
83 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_launcher_sleep_tracker_background.xml:
--------------------------------------------------------------------------------
1 |
16 |
17 |
22 |
25 |
28 |
31 |
34 |
35 |
36 |
39 |
42 |
45 |
48 |
49 |
50 |
51 |
54 |
55 |
56 |
--------------------------------------------------------------------------------
/app/src/main/res/values/font_certs.xml:
--------------------------------------------------------------------------------
1 |
16 |
17 |
18 |
19 | @array/com_google_android_gms_fonts_certs_dev
20 | @array/com_google_android_gms_fonts_certs_prod
21 |
22 |
23 |
24 | MIIEqDCCA5CgAwIBAgIJANWFuGx90071MA0GCSqGSIb3DQEBBAUAMIGUMQswCQYDVQQGEwJVUzETMBEGA1UECBMKQ2FsaWZvcm5pYTEWMBQGA1UEBxMNTW91bnRhaW4gVmlldzEQMA4GA1UEChMHQW5kcm9pZDEQMA4GA1UECxMHQW5kcm9pZDEQMA4GA1UEAxMHQW5kcm9pZDEiMCAGCSqGSIb3DQEJARYTYW5kcm9pZEBhbmRyb2lkLmNvbTAeFw0wODA0MTUyMzM2NTZaFw0zNTA5MDEyMzM2NTZaMIGUMQswCQYDVQQGEwJVUzETMBEGA1UECBMKQ2FsaWZvcm5pYTEWMBQGA1UEBxMNTW91bnRhaW4gVmlldzEQMA4GA1UEChMHQW5kcm9pZDEQMA4GA1UECxMHQW5kcm9pZDEQMA4GA1UEAxMHQW5kcm9pZDEiMCAGCSqGSIb3DQEJARYTYW5kcm9pZEBhbmRyb2lkLmNvbTCCASAwDQYJKoZIhvcNAQEBBQADggENADCCAQgCggEBANbOLggKv+IxTdGNs8/TGFy0PTP6DHThvbbR24kT9ixcOd9W+EaBPWW+wPPKQmsHxajtWjmQwWfna8mZuSeJS48LIgAZlKkpFeVyxW0qMBujb8X8ETrWy550NaFtI6t9+u7hZeTfHwqNvacKhp1RbE6dBRGWynwMVX8XW8N1+UjFaq6GCJukT4qmpN2afb8sCjUigq0GuMwYXrFVee74bQgLHWGJwPmvmLHC69EH6kWr22ijx4OKXlSIx2xT1AsSHee70w5iDBiK4aph27yH3TxkXy9V89TDdexAcKk/cVHYNnDBapcavl7y0RiQ4biu8ymM8Ga/nmzhRKya6G0cGw8CAQOjgfwwgfkwHQYDVR0OBBYEFI0cxb6VTEM8YYY6FbBMvAPyT+CyMIHJBgNVHSMEgcEwgb6AFI0cxb6VTEM8YYY6FbBMvAPyT+CyoYGapIGXMIGUMQswCQYDVQQGEwJVUzETMBEGA1UECBMKQ2FsaWZvcm5pYTEWMBQGA1UEBxMNTW91bnRhaW4gVmlldzEQMA4GA1UEChMHQW5kcm9pZDEQMA4GA1UECxMHQW5kcm9pZDEQMA4GA1UEAxMHQW5kcm9pZDEiMCAGCSqGSIb3DQEJARYTYW5kcm9pZEBhbmRyb2lkLmNvbYIJANWFuGx90071MAwGA1UdEwQFMAMBAf8wDQYJKoZIhvcNAQEEBQADggEBABnTDPEF+3iSP0wNfdIjIz1AlnrPzgAIHVvXxunW7SBrDhEglQZBbKJEk5kT0mtKoOD1JMrSu1xuTKEBahWRbqHsXclaXjoBADb0kkjVEJu/Lh5hgYZnOjvlba8Ld7HCKePCVePoTJBdI4fvugnL8TsgK05aIskyY0hKI9L8KfqfGTl1lzOv2KoWD0KWwtAWPoGChZxmQ+nBli+gwYMzM1vAkP+aayLe0a1EQimlOalO762r0GXO0ks+UeXde2Z4e+8S/pf7pITEI/tP+MxJTALw9QUWEv9lKTk+jkbqxbsh8nfBUapfKqYn0eidpwq2AzVp3juYl7//fKnaPhJD9gs=
25 |
26 |
27 |
28 |
29 | MIIEQzCCAyugAwIBAgIJAMLgh0ZkSjCNMA0GCSqGSIb3DQEBBAUAMHQxCzAJBgNVBAYTAlVTMRMwEQYDVQQIEwpDYWxpZm9ybmlhMRYwFAYDVQQHEw1Nb3VudGFpbiBWaWV3MRQwEgYDVQQKEwtHb29nbGUgSW5jLjEQMA4GA1UECxMHQW5kcm9pZDEQMA4GA1UEAxMHQW5kcm9pZDAeFw0wODA4MjEyMzEzMzRaFw0zNjAxMDcyMzEzMzRaMHQxCzAJBgNVBAYTAlVTMRMwEQYDVQQIEwpDYWxpZm9ybmlhMRYwFAYDVQQHEw1Nb3VudGFpbiBWaWV3MRQwEgYDVQQKEwtHb29nbGUgSW5jLjEQMA4GA1UECxMHQW5kcm9pZDEQMA4GA1UEAxMHQW5kcm9pZDCCASAwDQYJKoZIhvcNAQEBBQADggENADCCAQgCggEBAKtWLgDYO6IIrgqWbxJOKdoR8qtW0I9Y4sypEwPpt1TTcvZApxsdyxMJZ2JORland2qSGT2y5b+3JKkedxiLDmpHpDsz2WCbdxgxRczfey5YZnTJ4VZbH0xqWVW/8lGmPav5xVwnIiJS6HXk+BVKZF+JcWjAsb/GEuq/eFdpuzSqeYTcfi6idkyugwfYwXFU1+5fZKUaRKYCwkkFQVfcAs1fXA5V+++FGfvjJ/CxURaSxaBvGdGDhfXE28LWuT9ozCl5xw4Yq5OGazvV24mZVSoOO0yZ31j7kYvtwYK6NeADwbSxDdJEqO4k//0zOHKrUiGYXtqw/A0LFFtqoZKFjnkCAQOjgdkwgdYwHQYDVR0OBBYEFMd9jMIhF1Ylmn/Tgt9r45jk14alMIGmBgNVHSMEgZ4wgZuAFMd9jMIhF1Ylmn/Tgt9r45jk14aloXikdjB0MQswCQYDVQQGEwJVUzETMBEGA1UECBMKQ2FsaWZvcm5pYTEWMBQGA1UEBxMNTW91bnRhaW4gVmlldzEUMBIGA1UEChMLR29vZ2xlIEluYy4xEDAOBgNVBAsTB0FuZHJvaWQxEDAOBgNVBAMTB0FuZHJvaWSCCQDC4IdGZEowjTAMBgNVHRMEBTADAQH/MA0GCSqGSIb3DQEBBAUAA4IBAQBt0lLO74UwLDYKqs6Tm8/yzKkEu116FmH4rkaymUIE0P9KaMftGlMexFlaYjzmB2OxZyl6euNXEsQH8gjwyxCUKRJNexBiGcCEyj6z+a1fuHHvkiaai+KL8W1EyNmgjmyy8AW7P+LLlkR+ho5zEHatRbM/YAnqGcFh5iZBqpknHf1SKMXFh4dd239FJ1jWYfbMDMy3NS5CTMQ2XFI1MvcyUTdZPErjQfTbQe3aDQsQcafEQPD+nqActifKZ0Np0IS9L9kR/wbNvyz6ENwPiTrjV2KRkEjH78ZMcUQXg0L3BYHJ3lc69Vs5Ddf9uUGGMYldX3WfMBEmh/9iFBDAaTCK
30 |
31 |
32 |
33 |
--------------------------------------------------------------------------------
/app/src/main/java/com/example/android/trackmysleepquality/Util.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2018, The Android Open Source Project
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.example.android.trackmysleepquality
18 |
19 | import android.annotation.SuppressLint
20 | import android.content.res.Resources
21 | import android.os.Build
22 | import android.text.Html
23 | import android.text.Spanned
24 | import androidx.core.text.HtmlCompat
25 | import com.example.android.trackmysleepquality.database.SleepNight
26 | import java.text.SimpleDateFormat
27 |
28 | /**
29 | * These functions create a formatted string that can be set in a TextView.
30 | */
31 |
32 | /**
33 | * Returns a string representing the numeric quality rating.
34 | */
35 | fun convertNumericQualityToString(quality: Int, resources: Resources): String {
36 | var qualityString = resources.getString(R.string.three_ok)
37 | when (quality) {
38 | -1 -> qualityString = "--"
39 | 0 -> qualityString = resources.getString(R.string.zero_very_bad)
40 | 1 -> qualityString = resources.getString(R.string.one_poor)
41 | 2 -> qualityString = resources.getString(R.string.two_soso)
42 | 4 -> qualityString = resources.getString(R.string.four_pretty_good)
43 | 5 -> qualityString = resources.getString(R.string.five_excellent)
44 | }
45 | return qualityString
46 | }
47 |
48 |
49 | /**
50 | * Take the Long milliseconds returned by the system and stored in Room,
51 | * and convert it to a nicely formatted string for display.
52 | *
53 | * EEEE - Display the long letter version of the weekday
54 | * MMM - Display the letter abbreviation of the nmotny
55 | * dd-yyyy - day in month and full year numerically
56 | * HH:mm - Hours and minutes in 24hr format
57 | */
58 | @SuppressLint("SimpleDateFormat")
59 | fun convertLongToDateString(systemTime: Long): String {
60 | return SimpleDateFormat("EEEE MMM-dd-yyyy' Time: 'HH:mm")
61 | .format(systemTime).toString()
62 | }
63 |
64 | /**
65 | * Takes a list of SleepNights and converts and formats it into one string for display.
66 | *
67 | * For display in a TextView, we have to supply one string, and styles are per TextView, not
68 | * applicable per word. So, we build a formatted string using HTML. This is handy, but we will
69 | * learn a better way of displaying this data in a future lesson.
70 | *
71 | * @param nights - List of all SleepNights in the database.
72 | * @param resources - Resources object for all the resources defined for our app.
73 | *
74 | * @return Spanned - An interface for text that has formatting attached to it.
75 | * See: https://developer.android.com/reference/android/text/Spanned
76 | */
77 |
78 | fun formatNights(nights: List, resources: Resources): Spanned {
79 | val sb = StringBuilder()
80 | sb.apply {
81 | append(resources.getString(R.string.title))
82 | nights.forEach {
83 | append(" ")
84 | append(resources.getString(R.string.start_time))
85 | append("\t${convertLongToDateString(it.startTimeMilli)} ")
86 | if (it.endTimeMilli != it.startTimeMilli) {
87 | append(resources.getString(R.string.end_time))
88 | append("\t${convertLongToDateString(it.endTimeMilli)} ")
89 | append(resources.getString(R.string.quality))
90 | append("\t${convertNumericQualityToString(it.sleepQuality, resources)} ")
91 | append(resources.getString(R.string.hours_slept))
92 | // Hours
93 | append("\t ${it.endTimeMilli.minus(it.startTimeMilli) / 1000 / 60 / 60}:")
94 | // Minutes
95 | append("${it.endTimeMilli.minus(it.startTimeMilli) / 1000 / 60}:")
96 | // Seconds
97 | append("${it.endTimeMilli.minus(it.startTimeMilli) / 1000}
")
98 | }
99 | }
100 | }
101 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
102 | return Html.fromHtml(sb.toString(), Html.FROM_HTML_MODE_LEGACY)
103 | } else {
104 | return HtmlCompat.fromHtml(sb.toString(), HtmlCompat.FROM_HTML_MODE_LEGACY)
105 | }
106 | }
107 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_launcher_sleep_tracker_foreground.xml:
--------------------------------------------------------------------------------
1 |
16 |
17 |
22 |
25 |
28 |
31 |
38 |
45 |
50 |
51 |
52 |
55 |
58 |
61 |
64 |
67 |
70 |
71 |
72 |
73 |
76 |
77 |
78 |
--------------------------------------------------------------------------------
/app/src/main/java/com/example/android/trackmysleepquality/database/SleepDatabase.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2018, The Android Open Source Project
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.example.android.trackmysleepquality.database
18 |
19 | import android.content.Context
20 | import androidx.room.Database
21 | import androidx.room.Room
22 | import androidx.room.RoomDatabase
23 |
24 | /**
25 | * A database that stores SleepNight information.
26 | * And a global method to get access to the database.
27 | *
28 | * This pattern is pretty much the same for any database,
29 | * so you can reuse it.
30 | */
31 | @Database(entities = [SleepNight::class], version = 1, exportSchema = false)
32 | abstract class SleepDatabase : RoomDatabase() {
33 |
34 | /**
35 | * Connects the database to the DAO.
36 | */
37 | abstract val sleepDatabaseDao: SleepDatabaseDao
38 |
39 | /**
40 | * Define a companion object, this allows us to add functions on the SleepDatabase class.
41 | *
42 | * For example, clients can call `SleepDatabase.getInstance(context)` to instantiate
43 | * a new SleepDatabase.
44 | */
45 | companion object {
46 | /**
47 | * INSTANCE will keep a reference to any database returned via getInstance.
48 | *
49 | * This will help us avoid repeatedly initializing the database, which is expensive.
50 | *
51 | * The value of a volatile variable will never be cached, and all writes and
52 | * reads will be done to and from the main memory. It means that changes made by one
53 | * thread to shared data are visible to other threads.
54 | */
55 | @Volatile
56 | private var INSTANCE: SleepDatabase? = null
57 |
58 | /**
59 | * Helper function to get the database.
60 | *
61 | * If a database has already been retrieved, the previous database will be returned.
62 | * Otherwise, create a new database.
63 | *
64 | * This function is threadsafe, and callers should cache the result for multiple database
65 | * calls to avoid overhead.
66 | *
67 | * This is an example of a simple Singleton pattern that takes another Singleton as an
68 | * argument in Kotlin.
69 | *
70 | * To learn more about Singleton read the wikipedia article:
71 | * https://en.wikipedia.org/wiki/Singleton_pattern
72 | *
73 | * @param context The application context Singleton, used to get access to the filesystem.
74 | */
75 | fun getInstance(context: Context): SleepDatabase {
76 | // Multiple threads can ask for the database at the same time, ensure we only initialize
77 | // it once by using synchronized. Only one thread may enter a synchronized block at a
78 | // time.
79 | synchronized(this) {
80 | // Copy the current value of INSTANCE to a local variable so Kotlin can smart cast.
81 | // Smart cast is only available to local variables.
82 | var instance = INSTANCE
83 | // If instance is `null` make a new database instance.
84 | if (instance == null) {
85 | instance = Room.databaseBuilder(
86 | context.applicationContext,
87 | SleepDatabase::class.java,
88 | "sleep_history_database"
89 | )
90 | // Wipes and rebuilds instead of migrating if no Migration object.
91 | // Migration is not part of this lesson. You can learn more about
92 | // migration with Room in this blog post:
93 | // https://medium.com/androiddevelopers/understanding-migrations-with-room-f01e04b07929
94 | .fallbackToDestructiveMigration()
95 | .build()
96 | // Assign INSTANCE to the newly created database.
97 | INSTANCE = instance
98 | }
99 | // Return instance; smart cast to be non-null.
100 | return instance
101 | }
102 | }
103 | }
104 | }
105 |
--------------------------------------------------------------------------------
/app/src/main/java/com/example/android/trackmysleepquality/sleeptracker/SleepTrackerFragment.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2018, The Android Open Source Project
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.example.android.trackmysleepquality.sleeptracker
18 |
19 | import android.os.Bundle
20 | import android.view.LayoutInflater
21 | import android.view.View
22 | import android.view.ViewGroup
23 | import androidx.databinding.DataBindingUtil
24 | import androidx.fragment.app.Fragment
25 | import androidx.lifecycle.Observer
26 | import androidx.lifecycle.ViewModelProvider
27 | import androidx.navigation.fragment.findNavController
28 | import com.example.android.trackmysleepquality.R
29 | import com.example.android.trackmysleepquality.database.SleepDatabase
30 | import com.example.android.trackmysleepquality.databinding.FragmentSleepTrackerBinding
31 | import com.google.android.material.snackbar.Snackbar
32 |
33 | /**
34 | * A fragment with buttons to record start and end times for sleep, which are saved in
35 | * a database. Cumulative data is displayed in a simple scrollable TextView.
36 | * (Because we have not learned about RecyclerView yet.)
37 | */
38 | class SleepTrackerFragment : Fragment() {
39 |
40 | /**
41 | * Called when the Fragment is ready to display content to the screen.
42 | *
43 | * This function uses DataBindingUtil to inflate R.layout.fragment_sleep_quality.
44 | */
45 | override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?,
46 | savedInstanceState: Bundle?): View {
47 |
48 | // Get a reference to the binding object and inflate the fragment views.
49 | val binding: FragmentSleepTrackerBinding = DataBindingUtil.inflate(
50 | inflater, R.layout.fragment_sleep_tracker, container, false)
51 |
52 | val application = requireNotNull(this.activity).application
53 |
54 | val dataSource = SleepDatabase.getInstance(application).sleepDatabaseDao
55 |
56 | val viewModelFactory = SleepTrackerViewModelFactory(dataSource, application)
57 |
58 | val sleepTrackerViewModel =
59 | ViewModelProvider(
60 | this, viewModelFactory).get(SleepTrackerViewModel::class.java)
61 |
62 | binding.sleepTrackerViewModel = sleepTrackerViewModel
63 |
64 | // binding.setLifecycleOwner(this)
65 | binding.lifecycleOwner = this
66 |
67 |
68 |
69 | // Add an Observer on the state variable for showing a Snackbar message
70 | // when the CLEAR button is pressed.
71 | sleepTrackerViewModel.showSnackBarEvent.observe(viewLifecycleOwner, Observer {
72 | if (it == true) { // Observed state is true.
73 | Snackbar.make(
74 | binding.root,
75 | getString(R.string.cleared_message),
76 | Snackbar.LENGTH_SHORT // How long to display the message.
77 | ).show()
78 | // Reset state to make sure the snackbar is only shown once, even if the device
79 | // has a configuration change.
80 | sleepTrackerViewModel.doneShowingSnackbar()
81 | }
82 | })
83 |
84 | // Add an Observer on the state variable for Navigating when STOP button is pressed.
85 | sleepTrackerViewModel.navigateToSleepQuality.observe(viewLifecycleOwner, Observer { night ->
86 | night?.let {
87 | // We need to get the navController from this, because button is not ready, and it
88 | // just has to be a view. For some reason, this only matters if we hit stop again
89 | // after using the back button, not if we hit stop and choose a quality.
90 | // Also, in the Navigation Editor, for Quality -> Tracker, check "Inclusive" for
91 | // popping the stack to get the correct behavior if we press stop multiple times
92 | // followed by back.
93 | // Also: https://stackoverflow.com/questions/28929637/difference-and-uses-of-oncreate-oncreateview-and-onactivitycreated-in-fra
94 | this.findNavController().navigate(
95 | SleepTrackerFragmentDirections
96 | .actionSleepTrackerFragmentToSleepQualityFragment(night.nightId))
97 | // Reset state to make sure we only navigate once, even if the device
98 | // has a configuration change.
99 | sleepTrackerViewModel.doneNavigating()
100 | }
101 | })
102 |
103 | return binding.root
104 | }
105 | }
106 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Room - SleepQualityTracker app
2 |
3 | This is the toy app for Lesson 6 of the [Android App Development in Kotlin course on Udacity](https://www.udacity.com/course/???).
4 |
5 | ## SleepQualityTracker
6 |
7 | The SleepQualityTracker app is a demo app that helps you collect information about your sleep.
8 | * Start time
9 | * End time
10 | * Quality
11 | * Time slept
12 |
13 | This app demonstrates the following views and techniques:
14 | * Room database
15 | * DAO
16 | * Coroutines
17 |
18 | It also uses and builds on the following techniques from previous lessons:
19 | * Transformation map
20 | * Data Binding in XML files
21 | * ViewModel Factory
22 | * Using Backing Properties to protect MutableLiveData
23 | * Observable state LiveData variables to trigger navigation
24 |
25 | ## Screenshots
26 |
27 | 
28 | 
29 | 
30 |
31 | ## How to use this repo while taking the course
32 |
33 |
34 | Each code repository in this class has a chain of commits that looks like this:
35 |
36 | 
37 |
38 | These commits show every step you'll take to create the app. Each commit contains instructions for completing the that step.
39 |
40 | Each commit also has a **branch** associated with it of the same name as the commit message, as seen below:
41 |
42 | 
44 | Access all branches from this tab.
45 |
46 | 
48 |
49 |
50 | 
52 |
53 | The branches are also accessible from the drop-down in the "Code" tab.
54 |
55 | ## Requirements
56 |
57 | 1. Android Studio (Jellyfish or above)
58 | 2. JDK 21 with `JAVA_HOME` environment variable set. If you don't have JDK 21 installed or `JAVA_HOME` is not set, consider using a tool like `sdkman` to simplify the process. Refer to the sdkman documentation for installation instructions: [sdkman installation](https://sdkman.io/install)
59 |
60 | ## Working with the Course Code
61 |
62 | Here are the basic steps for working with and completing exercises in the repo.
63 |
64 | The basic steps are:
65 |
66 | 1. Clone the repo.
67 | 2. Check out the branch corresponding to the step you want to attempt.
68 | 3. Find and complete the TODOs.
69 | 4. Optionally commit your code changes.
70 | 5. Compare your code with the solution.
71 | 6. Repeat steps 2-5 until you've gone trough all the steps to complete the toy app.
72 |
73 |
74 | **Step 1: Clone the repo**
75 |
76 | As you go through the course, you'll be instructed to clone the different exercise repositories, so you don't need to set these up now. You can clone a repository from github in a folder of your choice with the command:
77 |
78 | ```bash
79 | git clone https://github.com/udacity/REPOSITORY_NAME.git
80 | ```
81 |
82 | **Step 2: Check out the step branch**
83 |
84 | As you go through different steps in the code, you'll be told which step you're on, as well as a link to the corresponding branch.
85 |
86 | You'll want to check out the branch associated with that step. The command to check out a branch would be:
87 |
88 | ```bash
89 | git checkout BRANCH_NAME
90 | ```
91 |
92 | **Step 3: Find and complete the TODOs**
93 |
94 | Once you've checked out the branch, you'll have the code in the exact state you need. You'll even have TODOs, which are special comments that tell you all the steps you need to complete the exercise. You can easily navigate to all the TODOs using Android Studio's TODO tool. To open the TODO tool, click the button at the bottom of the screen that says TODO. This will display a list of all comments with TODO in the project.
95 |
96 | We've numbered the TODO steps so you can do them in order:
97 | 
99 |
100 | **Step 4: Commit your code changes**
101 |
102 | After You've completed the TODOs, you can optionally commit your changes. This will allow you to see the code you wrote whenever you return to the branch. The following git code will add and save **all** your changes.
103 |
104 | ```bash
105 | git add .
106 | git commit -m "Your commit message"
107 | ```
108 |
109 | **Step 5: Compare with the solution**
110 |
111 | Most exercises will have a list of steps for you to check off in the classroom. Once you've checked these off, you'll see a pop up window with a link to the solution code. Note the **Diff** link:
112 |
113 | 
115 |
116 | The **Diff** link will take you to a Github diff as seen below:
117 | 
119 |
120 | All of the code that was added in the solution is in green, and the removed code (which will usually be the TODO comments) is in red.
121 |
122 | You can also compare your code locally with the branch of the following step.
123 |
124 | ## Report Issues
125 | Notice any issues with a repository? Please file a github issue in the repository.
126 |
127 |
128 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/fragment_sleep_tracker.xml:
--------------------------------------------------------------------------------
1 |
16 |
17 |
18 |
21 |
22 |
25 |
26 |
27 |
30 |
31 |
32 |
33 |
37 |
38 |
41 |
42 |
50 |
51 |
54 |
55 |
63 |
64 |
65 |
68 |
69 |
82 |
83 |
96 |
97 |
111 |
112 |
113 |
114 |
--------------------------------------------------------------------------------
/gradlew:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env sh
2 |
3 | ##############################################################################
4 | ##
5 | ## Gradle start up script for UN*X
6 | ##
7 | ##############################################################################
8 |
9 | # Attempt to set APP_HOME
10 | # Resolve links: $0 may be a link
11 | PRG="$0"
12 | # Need this for relative symlinks.
13 | while [ -h "$PRG" ] ; do
14 | ls=`ls -ld "$PRG"`
15 | link=`expr "$ls" : '.*-> \(.*\)$'`
16 | if expr "$link" : '/.*' > /dev/null; then
17 | PRG="$link"
18 | else
19 | PRG=`dirname "$PRG"`"/$link"
20 | fi
21 | done
22 | SAVED="`pwd`"
23 | cd "`dirname \"$PRG\"`/" >/dev/null
24 | APP_HOME="`pwd -P`"
25 | cd "$SAVED" >/dev/null
26 |
27 | APP_NAME="Gradle"
28 | APP_BASE_NAME=`basename "$0"`
29 |
30 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
31 | DEFAULT_JVM_OPTS=""
32 |
33 | # Use the maximum available, or set MAX_FD != -1 to use that value.
34 | MAX_FD="maximum"
35 |
36 | warn () {
37 | echo "$*"
38 | }
39 |
40 | die () {
41 | echo
42 | echo "$*"
43 | echo
44 | exit 1
45 | }
46 |
47 | # OS specific support (must be 'true' or 'false').
48 | cygwin=false
49 | msys=false
50 | darwin=false
51 | nonstop=false
52 | case "`uname`" in
53 | CYGWIN* )
54 | cygwin=true
55 | ;;
56 | Darwin* )
57 | darwin=true
58 | ;;
59 | MINGW* )
60 | msys=true
61 | ;;
62 | NONSTOP* )
63 | nonstop=true
64 | ;;
65 | esac
66 |
67 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
68 |
69 | # Determine the Java command to use to start the JVM.
70 | if [ -n "$JAVA_HOME" ] ; then
71 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
72 | # IBM's JDK on AIX uses strange locations for the executables
73 | JAVACMD="$JAVA_HOME/jre/sh/java"
74 | else
75 | JAVACMD="$JAVA_HOME/bin/java"
76 | fi
77 | if [ ! -x "$JAVACMD" ] ; then
78 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
79 |
80 | Please set the JAVA_HOME variable in your environment to match the
81 | location of your Java installation."
82 | fi
83 | else
84 | JAVACMD="java"
85 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
86 |
87 | Please set the JAVA_HOME variable in your environment to match the
88 | location of your Java installation."
89 | fi
90 |
91 | # Increase the maximum file descriptors if we can.
92 | if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then
93 | MAX_FD_LIMIT=`ulimit -H -n`
94 | if [ $? -eq 0 ] ; then
95 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
96 | MAX_FD="$MAX_FD_LIMIT"
97 | fi
98 | ulimit -n $MAX_FD
99 | if [ $? -ne 0 ] ; then
100 | warn "Could not set maximum file descriptor limit: $MAX_FD"
101 | fi
102 | else
103 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
104 | fi
105 | fi
106 |
107 | # For Darwin, add options to specify how the application appears in the dock
108 | if $darwin; then
109 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
110 | fi
111 |
112 | # For Cygwin, switch paths to Windows format before running java
113 | if $cygwin ; then
114 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
115 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
116 | JAVACMD=`cygpath --unix "$JAVACMD"`
117 |
118 | # We build the pattern for arguments to be converted via cygpath
119 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
120 | SEP=""
121 | for dir in $ROOTDIRSRAW ; do
122 | ROOTDIRS="$ROOTDIRS$SEP$dir"
123 | SEP="|"
124 | done
125 | OURCYGPATTERN="(^($ROOTDIRS))"
126 | # Add a user-defined pattern to the cygpath arguments
127 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
128 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
129 | fi
130 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
131 | i=0
132 | for arg in "$@" ; do
133 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
134 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
135 |
136 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
137 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
138 | else
139 | eval `echo args$i`="\"$arg\""
140 | fi
141 | i=$((i+1))
142 | done
143 | case $i in
144 | (0) set -- ;;
145 | (1) set -- "$args0" ;;
146 | (2) set -- "$args0" "$args1" ;;
147 | (3) set -- "$args0" "$args1" "$args2" ;;
148 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
149 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
150 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
151 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
152 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
153 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
154 | esac
155 | fi
156 |
157 | # Escape application args
158 | save () {
159 | for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done
160 | echo " "
161 | }
162 | APP_ARGS=$(save "$@")
163 |
164 | # Collect all arguments for the java command, following the shell quoting and substitution rules
165 | eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS"
166 |
167 | # by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong
168 | if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then
169 | cd "$(dirname "$0")"
170 | fi
171 |
172 | exec "$JAVACMD" "$@"
173 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/fragment_sleep_quality.xml:
--------------------------------------------------------------------------------
1 |
16 |
17 |
18 |
21 |
22 |
25 |
26 |
27 |
30 |
31 |
32 |
33 |
37 |
38 |
51 |
52 |
64 |
65 |
75 |
76 |
87 |
88 |
103 |
104 |
115 |
116 |
128 |
129 |
130 |
131 |
--------------------------------------------------------------------------------
/app/src/main/java/com/example/android/trackmysleepquality/sleeptracker/SleepTrackerViewModel.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2018, The Android Open Source Project
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.example.android.trackmysleepquality.sleeptracker
18 |
19 | import android.app.Application
20 | import androidx.lifecycle.viewModelScope
21 | import androidx.lifecycle.AndroidViewModel
22 | import androidx.lifecycle.LiveData
23 | import androidx.lifecycle.MutableLiveData
24 | import androidx.lifecycle.map
25 | import com.example.android.trackmysleepquality.database.SleepDatabaseDao
26 | import com.example.android.trackmysleepquality.database.SleepNight
27 | import com.example.android.trackmysleepquality.formatNights
28 | import kotlinx.coroutines.*
29 |
30 | /**
31 | * ViewModel for SleepTrackerFragment.
32 | */
33 | class SleepTrackerViewModel(
34 | val database: SleepDatabaseDao,
35 | application: Application) : AndroidViewModel(application) {
36 |
37 |
38 | private var tonight = MutableLiveData()
39 |
40 | private val nights = database.getAllNights()
41 |
42 | /**
43 | * Converted nights to Spanned for displaying.
44 | */
45 | val nightsString = nights.map { nights ->
46 | formatNights(nights, application.resources)
47 | }
48 |
49 | /**
50 | * If tonight has not been set, then the START button should be visible.
51 | */
52 | val startButtonVisible = tonight.map {
53 | null == it
54 | }
55 |
56 | /**
57 | * If tonight has been set, then the STOP button should be visible.
58 | */
59 | val stopButtonVisible = tonight.map {
60 | null != it
61 | }
62 |
63 | /**
64 | * If there are any nights in the database, show the CLEAR button.
65 | */
66 | val clearButtonVisible = nights.map {
67 | it.isNotEmpty()
68 | }
69 |
70 | /**
71 | * Request a toast by setting this value to true.
72 | *
73 | * This is private because we don't want to expose setting this value to the Fragment.
74 | */
75 | private var _showSnackbarEvent = MutableLiveData()
76 |
77 | /**
78 | * If this is true, immediately `show()` a toast and call `doneShowingSnackbar()`.
79 | */
80 | val showSnackBarEvent: LiveData
81 | get() = _showSnackbarEvent
82 |
83 | /**
84 | * Variable that tells the Fragment to navigate to a specific [SleepQualityFragment]
85 | *
86 | * This is private because we don't want to expose setting this value to the Fragment.
87 | */
88 |
89 | private val _navigateToSleepQuality = MutableLiveData()
90 | /**
91 | * Call this immediately after calling `show()` on a toast.
92 | *
93 | * It will clear the toast request, so if the user rotates their phone it won't show a duplicate
94 | * toast.
95 | */
96 |
97 | fun doneShowingSnackbar() {
98 | _showSnackbarEvent.value = false
99 | }
100 | /**
101 | * If this is non-null, immediately navigate to [SleepQualityFragment] and call [doneNavigating]
102 | */
103 | val navigateToSleepQuality: LiveData
104 | get() = _navigateToSleepQuality
105 |
106 | /**
107 | * Call this immediately after navigating to [SleepQualityFragment]
108 | *
109 | * It will clear the navigation request, so if the user rotates their phone it won't navigate
110 | * twice.
111 | */
112 | fun doneNavigating() {
113 | _navigateToSleepQuality.value = null
114 | }
115 |
116 | init {
117 | initializeTonight()
118 | }
119 |
120 | private fun initializeTonight() {
121 | viewModelScope.launch {
122 | tonight.value = getTonightFromDatabase()
123 | }
124 | }
125 |
126 | /**
127 | * Handling the case of the stopped app or forgotten recording,
128 | * the start and end times will be the same.j
129 | *
130 | * If the start time and end time are not the same, then we do not have an unfinished
131 | * recording.
132 | */
133 | private suspend fun getTonightFromDatabase(): SleepNight? {
134 | var night = database.getTonight()
135 | if (night?.endTimeMilli != night?.startTimeMilli) {
136 | night = null
137 | }
138 | return night
139 | }
140 |
141 | private suspend fun clear() {
142 | database.clear()
143 | }
144 |
145 | private suspend fun update(night: SleepNight) {
146 | database.update(night)
147 | }
148 |
149 | private suspend fun insert(night: SleepNight) {
150 | database.insert(night)
151 | }
152 |
153 | /**
154 | * Executes when the START button is clicked.
155 | */
156 | fun onStartTracking() {
157 | viewModelScope.launch {
158 | // Create a new night, which captures the current time,
159 | // and insert it into the database.
160 | val newNight = SleepNight()
161 |
162 | insert(newNight)
163 |
164 | tonight.value = getTonightFromDatabase()
165 | }
166 | }
167 |
168 | /**
169 | * Executes when the STOP button is clicked.
170 | */
171 | fun onStopTracking() {
172 | viewModelScope.launch {
173 | // In Kotlin, the return@label syntax is used for specifying which function among
174 | // several nested ones this statement returns from.
175 | // In this case, we are specifying to return from launch(),
176 | // not the lambda.
177 | val oldNight = tonight.value ?: return@launch
178 |
179 | // Update the night in the database to add the end time.
180 | oldNight.endTimeMilli = System.currentTimeMillis()
181 |
182 | update(oldNight)
183 |
184 | // Set state to navigate to the SleepQualityFragment.
185 | _navigateToSleepQuality.value = oldNight
186 | }
187 | }
188 |
189 | /**
190 | * Executes when the CLEAR button is clicked.
191 | */
192 | fun onClear() {
193 | viewModelScope.launch {
194 | // Clear the database table.
195 | clear()
196 |
197 | // And clear tonight since it's no longer in the database
198 | tonight.value = null
199 | }
200 |
201 | // Show a snackbar message, because it's friendly.
202 | _showSnackbarEvent.value = true
203 | }
204 |
205 | }
206 |
--------------------------------------------------------------------------------
/LICENSE.txt:
--------------------------------------------------------------------------------
1 | All image and audio files (including *.png, *.jpg, *.svg, *.mp3, *.wav
2 | and *.ogg) are licensed under the CC BY 4.0 license. All other files are
3 | licensed under the Apache 2 license.
4 |
5 | =======================================================================
6 |
7 | Apache License
8 | --------------
9 |
10 | Version 2.0, January 2004
11 | http://www.apache.org/licenses/
12 |
13 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
14 |
15 | 1. Definitions.
16 |
17 | "License" shall mean the terms and conditions for use, reproduction,
18 | and distribution as defined by Sections 1 through 9 of this document.
19 |
20 | "Licensor" shall mean the copyright owner or entity authorized by
21 | the copyright owner that is granting the License.
22 |
23 | "Legal Entity" shall mean the union of the acting entity and all
24 | other entities that control, are controlled by, or are under common
25 | control with that entity. For the purposes of this definition,
26 | "control" means (i) the power, direct or indirect, to cause the
27 | direction or management of such entity, whether by contract or
28 | otherwise, or (ii) ownership of fifty percent (50%) or more of the
29 | outstanding shares, or (iii) beneficial ownership of such entity.
30 |
31 | "You" (or "Your") shall mean an individual or Legal Entity
32 | exercising permissions granted by this License.
33 |
34 | "Source" form shall mean the preferred form for making modifications,
35 | including but not limited to software source code, documentation
36 | source, and configuration files.
37 |
38 | "Object" form shall mean any form resulting from mechanical
39 | transformation or translation of a Source form, including but
40 | not limited to compiled object code, generated documentation,
41 | and conversions to other media types.
42 |
43 | "Work" shall mean the work of authorship, whether in Source or
44 | Object form, made available under the License, as indicated by a
45 | copyright notice that is included in or attached to the work
46 | (an example is provided in the Appendix below).
47 |
48 | "Derivative Works" shall mean any work, whether in Source or Object
49 | form, that is based on (or derived from) the Work and for which the
50 | editorial revisions, annotations, elaborations, or other modifications
51 | represent, as a whole, an original work of authorship. For the purposes
52 | of this License, Derivative Works shall not include works that remain
53 | separable from, or merely link (or bind by name) to the interfaces of,
54 | the Work and Derivative Works thereof.
55 |
56 | "Contribution" shall mean any work of authorship, including
57 | the original version of the Work and any modifications or additions
58 | to that Work or Derivative Works thereof, that is intentionally
59 | submitted to Licensor for inclusion in the Work by the copyright owner
60 | or by an individual or Legal Entity authorized to submit on behalf of
61 | the copyright owner. For the purposes of this definition, "submitted"
62 | means any form of electronic, verbal, or written communication sent
63 | to the Licensor or its representatives, including but not limited to
64 | communication on electronic mailing lists, source code control systems,
65 | and issue tracking systems that are managed by, or on behalf of, the
66 | Licensor for the purpose of discussing and improving the Work, but
67 | excluding communication that is conspicuously marked or otherwise
68 | designated in writing by the copyright owner as "Not a Contribution."
69 |
70 | "Contributor" shall mean Licensor and any individual or Legal Entity
71 | on behalf of whom a Contribution has been received by Licensor and
72 | subsequently incorporated within the Work.
73 |
74 | 2. Grant of Copyright License. Subject to the terms and conditions of
75 | this License, each Contributor hereby grants to You a perpetual,
76 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77 | copyright license to reproduce, prepare Derivative Works of,
78 | publicly display, publicly perform, sublicense, and distribute the
79 | Work and such Derivative Works in Source or Object form.
80 |
81 | 3. Grant of Patent License. Subject to the terms and conditions of
82 | this License, each Contributor hereby grants to You a perpetual,
83 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
84 | (except as stated in this section) patent license to make, have made,
85 | use, offer to sell, sell, import, and otherwise transfer the Work,
86 | where such license applies only to those patent claims licensable
87 | by such Contributor that are necessarily infringed by their
88 | Contribution(s) alone or by combination of their Contribution(s)
89 | with the Work to which such Contribution(s) was submitted. If You
90 | institute patent litigation against any entity (including a
91 | cross-claim or counterclaim in a lawsuit) alleging that the Work
92 | or a Contribution incorporated within the Work constitutes direct
93 | or contributory patent infringement, then any patent licenses
94 | granted to You under this License for that Work shall terminate
95 | as of the date such litigation is filed.
96 |
97 | 4. Redistribution. You may reproduce and distribute copies of the
98 | Work or Derivative Works thereof in any medium, with or without
99 | modifications, and in Source or Object form, provided that You
100 | meet the following conditions:
101 |
102 | (a) You must give any other recipients of the Work or
103 | Derivative Works a copy of this License; and
104 |
105 | (b) You must cause any modified files to carry prominent notices
106 | stating that You changed the files; and
107 |
108 | (c) You must retain, in the Source form of any Derivative Works
109 | that You distribute, all copyright, patent, trademark, and
110 | attribution notices from the Source form of the Work,
111 | excluding those notices that do not pertain to any part of
112 | the Derivative Works; and
113 |
114 | (d) If the Work includes a "NOTICE" text file as part of its
115 | distribution, then any Derivative Works that You distribute must
116 | include a readable copy of the attribution notices contained
117 | within such NOTICE file, excluding those notices that do not
118 | pertain to any part of the Derivative Works, in at least one
119 | of the following places: within a NOTICE text file distributed
120 | as part of the Derivative Works; within the Source form or
121 | documentation, if provided along with the Derivative Works; or,
122 | within a display generated by the Derivative Works, if and
123 | wherever such third-party notices normally appear. The contents
124 | of the NOTICE file are for informational purposes only and
125 | do not modify the License. You may add Your own attribution
126 | notices within Derivative Works that You distribute, alongside
127 | or as an addendum to the NOTICE text from the Work, provided
128 | that such additional attribution notices cannot be construed
129 | as modifying the License.
130 |
131 | You may add Your own copyright statement to Your modifications and
132 | may provide additional or different license terms and conditions
133 | for use, reproduction, or distribution of Your modifications, or
134 | for any such Derivative Works as a whole, provided Your use,
135 | reproduction, and distribution of the Work otherwise complies with
136 | the conditions stated in this License.
137 |
138 | 5. Submission of Contributions. Unless You explicitly state otherwise,
139 | any Contribution intentionally submitted for inclusion in the Work
140 | by You to the Licensor shall be under the terms and conditions of
141 | this License, without any additional terms or conditions.
142 | Notwithstanding the above, nothing herein shall supersede or modify
143 | the terms of any separate license agreement you may have executed
144 | with Licensor regarding such Contributions.
145 |
146 | 6. Trademarks. This License does not grant permission to use the trade
147 | names, trademarks, service marks, or product names of the Licensor,
148 | except as required for reasonable and customary use in describing the
149 | origin of the Work and reproducing the content of the NOTICE file.
150 |
151 | 7. Disclaimer of Warranty. Unless required by applicable law or
152 | agreed to in writing, Licensor provides the Work (and each
153 | Contributor provides its Contributions) on an "AS IS" BASIS,
154 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
155 | implied, including, without limitation, any warranties or conditions
156 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
157 | PARTICULAR PURPOSE. You are solely responsible for determining the
158 | appropriateness of using or redistributing the Work and assume any
159 | risks associated with Your exercise of permissions under this License.
160 |
161 | 8. Limitation of Liability. In no event and under no legal theory,
162 | whether in tort (including negligence), contract, or otherwise,
163 | unless required by applicable law (such as deliberate and grossly
164 | negligent acts) or agreed to in writing, shall any Contributor be
165 | liable to You for damages, including any direct, indirect, special,
166 | incidental, or consequential damages of any character arising as a
167 | result of this License or out of the use or inability to use the
168 | Work (including but not limited to damages for loss of goodwill,
169 | work stoppage, computer failure or malfunction, or any and all
170 | other commercial damages or losses), even if such Contributor
171 | has been advised of the possibility of such damages.
172 |
173 | 9. Accepting Warranty or Additional Liability. While redistributing
174 | the Work or Derivative Works thereof, You may choose to offer,
175 | and charge a fee for, acceptance of support, warranty, indemnity,
176 | or other liability obligations and/or rights consistent with this
177 | License. However, in accepting such obligations, You may act only
178 | on Your own behalf and on Your sole responsibility, not on behalf
179 | of any other Contributor, and only if You agree to indemnify,
180 | defend, and hold each Contributor harmless for any liability
181 | incurred by, or claims asserted against, such Contributor by reason
182 | of your accepting any such warranty or additional liability.
183 |
184 | END OF TERMS AND CONDITIONS
185 |
186 | APPENDIX: How to apply the Apache License to your work.
187 |
188 | To apply the Apache License to your work, attach the following
189 | boilerplate notice, with the fields enclosed by brackets "{}"
190 | replaced with your own identifying information. (Don't include
191 | the brackets!) The text should be enclosed in the appropriate
192 | comment syntax for the file format. We also recommend that a
193 | file or class name and description of purpose be included on the
194 | same "printed page" as the copyright notice for easier
195 | identification within third-party archives.
196 |
197 | Copyright {yyyy} {name of copyright owner}
198 |
199 | Licensed under the Apache License, Version 2.0 (the "License");
200 | you may not use this file except in compliance with the License.
201 | You may obtain a copy of the License at
202 |
203 | http://www.apache.org/licenses/LICENSE-2.0
204 |
205 | Unless required by applicable law or agreed to in writing, software
206 | distributed under the License is distributed on an "AS IS" BASIS,
207 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
208 | See the License for the specific language governing permissions and
209 | limitations under the License.
210 |
211 | All image and audio files (including *.png, *.jpg, *.svg, *.mp3, *.wav
212 | and *.ogg) are licensed under the CC BY 4.0 license. All other files are
213 | licensed under the Apache 2 license.
214 |
215 | CC-BY License
216 | ----------------
217 |
218 | Attribution 4.0 International
219 |
220 | =======================================================================
221 |
222 | Creative Commons Corporation ("Creative Commons") is not a law firm and
223 | does not provide legal services or legal advice. Distribution of
224 | Creative Commons public licenses does not create a lawyer-client or
225 | other relationship. Creative Commons makes its licenses and related
226 | information available on an "as-is" basis. Creative Commons gives no
227 | warranties regarding its licenses, any material licensed under their
228 | terms and conditions, or any related information. Creative Commons
229 | disclaims all liability for damages resulting from their use to the
230 | fullest extent possible.
231 |
232 | Using Creative Commons Public Licenses
233 |
234 | Creative Commons public licenses provide a standard set of terms and
235 | conditions that creators and other rights holders may use to share
236 | original works of authorship and other material subject to copyright
237 | and certain other rights specified in the public license below. The
238 | following considerations are for informational purposes only, are not
239 | exhaustive, and do not form part of our licenses.
240 |
241 | Considerations for licensors: Our public licenses are
242 | intended for use by those authorized to give the public
243 | permission to use material in ways otherwise restricted by
244 | copyright and certain other rights. Our licenses are
245 | irrevocable. Licensors should read and understand the terms
246 | and conditions of the license they choose before applying it.
247 | Licensors should also secure all rights necessary before
248 | applying our licenses so that the public can reuse the
249 | material as expected. Licensors should clearly mark any
250 | material not subject to the license. This includes other CC-
251 | licensed material, or material used under an exception or
252 | limitation to copyright. More considerations for licensors:
253 | wiki.creativecommons.org/Considerations_for_licensors
254 |
255 | Considerations for the public: By using one of our public
256 | licenses, a licensor grants the public permission to use the
257 | licensed material under specified terms and conditions. If
258 | the licensor's permission is not necessary for any reason--for
259 | example, because of any applicable exception or limitation to
260 | copyright--then that use is not regulated by the license. Our
261 | licenses grant only permissions under copyright and certain
262 | other rights that a licensor has authority to grant. Use of
263 | the licensed material may still be restricted for other
264 | reasons, including because others have copyright or other
265 | rights in the material. A licensor may make special requests,
266 | such as asking that all changes be marked or described.
267 | Although not required by our licenses, you are encouraged to
268 | respect those requests where reasonable. More_considerations
269 | for the public:
270 | wiki.creativecommons.org/Considerations_for_licensees
271 |
272 | =======================================================================
273 |
274 | Creative Commons Attribution 4.0 International Public License
275 |
276 | By exercising the Licensed Rights (defined below), You accept and agree
277 | to be bound by the terms and conditions of this Creative Commons
278 | Attribution 4.0 International Public License ("Public License"). To the
279 | extent this Public License may be interpreted as a contract, You are
280 | granted the Licensed Rights in consideration of Your acceptance of
281 | these terms and conditions, and the Licensor grants You such rights in
282 | consideration of benefits the Licensor receives from making the
283 | Licensed Material available under these terms and conditions.
284 |
285 |
286 | Section 1 -- Definitions.
287 |
288 | a. Adapted Material means material subject to Copyright and Similar
289 | Rights that is derived from or based upon the Licensed Material
290 | and in which the Licensed Material is translated, altered,
291 | arranged, transformed, or otherwise modified in a manner requiring
292 | permission under the Copyright and Similar Rights held by the
293 | Licensor. For purposes of this Public License, where the Licensed
294 | Material is a musical work, performance, or sound recording,
295 | Adapted Material is always produced where the Licensed Material is
296 | synched in timed relation with a moving image.
297 |
298 | b. Adapter's License means the license You apply to Your Copyright
299 | and Similar Rights in Your contributions to Adapted Material in
300 | accordance with the terms and conditions of this Public License.
301 |
302 | c. Copyright and Similar Rights means copyright and/or similar rights
303 | closely related to copyright including, without limitation,
304 | performance, broadcast, sound recording, and Sui Generis Database
305 | Rights, without regard to how the rights are labeled or
306 | categorized. For purposes of this Public License, the rights
307 | specified in Section 2(b)(1)-(2) are not Copyright and Similar
308 | Rights.
309 |
310 | d. Effective Technological Measures means those measures that, in the
311 | absence of proper authority, may not be circumvented under laws
312 | fulfilling obligations under Article 11 of the WIPO Copyright
313 | Treaty adopted on December 20, 1996, and/or similar international
314 | agreements.
315 |
316 | e. Exceptions and Limitations means fair use, fair dealing, and/or
317 | any other exception or limitation to Copyright and Similar Rights
318 | that applies to Your use of the Licensed Material.
319 |
320 | f. Licensed Material means the artistic or literary work, database,
321 | or other material to which the Licensor applied this Public
322 | License.
323 |
324 | g. Licensed Rights means the rights granted to You subject to the
325 | terms and conditions of this Public License, which are limited to
326 | all Copyright and Similar Rights that apply to Your use of the
327 | Licensed Material and that the Licensor has authority to license.
328 |
329 | h. Licensor means the individual(s) or entity(ies) granting rights
330 | under this Public License.
331 |
332 | i. Share means to provide material to the public by any means or
333 | process that requires permission under the Licensed Rights, such
334 | as reproduction, public display, public performance, distribution,
335 | dissemination, communication, or importation, and to make material
336 | available to the public including in ways that members of the
337 | public may access the material from a place and at a time
338 | individually chosen by them.
339 |
340 | j. Sui Generis Database Rights means rights other than copyright
341 | resulting from Directive 96/9/EC of the European Parliament and of
342 | the Council of 11 March 1996 on the legal protection of databases,
343 | as amended and/or succeeded, as well as other essentially
344 | equivalent rights anywhere in the world.
345 |
346 | k. You means the individual or entity exercising the Licensed Rights
347 | under this Public License. Your has a corresponding meaning.
348 |
349 |
350 | Section 2 -- Scope.
351 |
352 | a. License grant.
353 |
354 | 1. Subject to the terms and conditions of this Public License,
355 | the Licensor hereby grants You a worldwide, royalty-free,
356 | non-sublicensable, non-exclusive, irrevocable license to
357 | exercise the Licensed Rights in the Licensed Material to:
358 |
359 | a. reproduce and Share the Licensed Material, in whole or
360 | in part; and
361 |
362 | b. produce, reproduce, and Share Adapted Material.
363 |
364 | 2. Exceptions and Limitations. For the avoidance of doubt, where
365 | Exceptions and Limitations apply to Your use, this Public
366 | License does not apply, and You do not need to comply with
367 | its terms and conditions.
368 |
369 | 3. Term. The term of this Public License is specified in Section
370 | 6(a).
371 |
372 | 4. Media and formats; technical modifications allowed. The
373 | Licensor authorizes You to exercise the Licensed Rights in
374 | all media and formats whether now known or hereafter created,
375 | and to make technical modifications necessary to do so. The
376 | Licensor waives and/or agrees not to assert any right or
377 | authority to forbid You from making technical modifications
378 | necessary to exercise the Licensed Rights, including
379 | technical modifications necessary to circumvent Effective
380 | Technological Measures. For purposes of this Public License,
381 | simply making modifications authorized by this Section 2(a)
382 | (4) never produces Adapted Material.
383 |
384 | 5. Downstream recipients.
385 |
386 | a. Offer from the Licensor -- Licensed Material. Every
387 | recipient of the Licensed Material automatically
388 | receives an offer from the Licensor to exercise the
389 | Licensed Rights under the terms and conditions of this
390 | Public License.
391 |
392 | b. No downstream restrictions. You may not offer or impose
393 | any additional or different terms or conditions on, or
394 | apply any Effective Technological Measures to, the
395 | Licensed Material if doing so restricts exercise of the
396 | Licensed Rights by any recipient of the Licensed
397 | Material.
398 |
399 | 6. No endorsement. Nothing in this Public License constitutes or
400 | may be construed as permission to assert or imply that You
401 | are, or that Your use of the Licensed Material is, connected
402 | with, or sponsored, endorsed, or granted official status by,
403 | the Licensor or others designated to receive attribution as
404 | provided in Section 3(a)(1)(A)(i).
405 |
406 | b. Other rights.
407 |
408 | 1. Moral rights, such as the right of integrity, are not
409 | licensed under this Public License, nor are publicity,
410 | privacy, and/or other similar personality rights; however, to
411 | the extent possible, the Licensor waives and/or agrees not to
412 | assert any such rights held by the Licensor to the limited
413 | extent necessary to allow You to exercise the Licensed
414 | Rights, but not otherwise.
415 |
416 | 2. Patent and trademark rights are not licensed under this
417 | Public License.
418 |
419 | 3. To the extent possible, the Licensor waives any right to
420 | collect royalties from You for the exercise of the Licensed
421 | Rights, whether directly or through a collecting society
422 | under any voluntary or waivable statutory or compulsory
423 | licensing scheme. In all other cases the Licensor expressly
424 | reserves any right to collect such royalties.
425 |
426 |
427 | Section 3 -- License Conditions.
428 |
429 | Your exercise of the Licensed Rights is expressly made subject to the
430 | following conditions.
431 |
432 | a. Attribution.
433 |
434 | 1. If You Share the Licensed Material (including in modified
435 | form), You must:
436 |
437 | a. retain the following if it is supplied by the Licensor
438 | with the Licensed Material:
439 |
440 | i. identification of the creator(s) of the Licensed
441 | Material and any others designated to receive
442 | attribution, in any reasonable manner requested by
443 | the Licensor (including by pseudonym if
444 | designated);
445 |
446 | ii. a copyright notice;
447 |
448 | iii. a notice that refers to this Public License;
449 |
450 | iv. a notice that refers to the disclaimer of
451 | warranties;
452 |
453 | v. a URI or hyperlink to the Licensed Material to the
454 | extent reasonably practicable;
455 |
456 | b. indicate if You modified the Licensed Material and
457 | retain an indication of any previous modifications; and
458 |
459 | c. indicate the Licensed Material is licensed under this
460 | Public License, and include the text of, or the URI or
461 | hyperlink to, this Public License.
462 |
463 | 2. You may satisfy the conditions in Section 3(a)(1) in any
464 | reasonable manner based on the medium, means, and context in
465 | which You Share the Licensed Material. For example, it may be
466 | reasonable to satisfy the conditions by providing a URI or
467 | hyperlink to a resource that includes the required
468 | information.
469 |
470 | 3. If requested by the Licensor, You must remove any of the
471 | information required by Section 3(a)(1)(A) to the extent
472 | reasonably practicable.
473 |
474 | 4. If You Share Adapted Material You produce, the Adapter's
475 | License You apply must not prevent recipients of the Adapted
476 | Material from complying with this Public License.
477 |
478 |
479 | Section 4 -- Sui Generis Database Rights.
480 |
481 | Where the Licensed Rights include Sui Generis Database Rights that
482 | apply to Your use of the Licensed Material:
483 |
484 | a. for the avoidance of doubt, Section 2(a)(1) grants You the right
485 | to extract, reuse, reproduce, and Share all or a substantial
486 | portion of the contents of the database;
487 |
488 | b. if You include all or a substantial portion of the database
489 | contents in a database in which You have Sui Generis Database
490 | Rights, then the database in which You have Sui Generis Database
491 | Rights (but not its individual contents) is Adapted Material; and
492 |
493 | c. You must comply with the conditions in Section 3(a) if You Share
494 | all or a substantial portion of the contents of the database.
495 |
496 | For the avoidance of doubt, this Section 4 supplements and does not
497 | replace Your obligations under this Public License where the Licensed
498 | Rights include other Copyright and Similar Rights.
499 |
500 |
501 | Section 5 -- Disclaimer of Warranties and Limitation of Liability.
502 |
503 | a. UNLESS OTHERWISE SEPARATELY UNDERTAKEN BY THE LICENSOR, TO THE
504 | EXTENT POSSIBLE, THE LICENSOR OFFERS THE LICENSED MATERIAL AS-IS
505 | AND AS-AVAILABLE, AND MAKES NO REPRESENTATIONS OR WARRANTIES OF
506 | ANY KIND CONCERNING THE LICENSED MATERIAL, WHETHER EXPRESS,
507 | IMPLIED, STATUTORY, OR OTHER. THIS INCLUDES, WITHOUT LIMITATION,
508 | WARRANTIES OF TITLE, MERCHANTABILITY, FITNESS FOR A PARTICULAR
509 | PURPOSE, NON-INFRINGEMENT, ABSENCE OF LATENT OR OTHER DEFECTS,
510 | ACCURACY, OR THE PRESENCE OR ABSENCE OF ERRORS, WHETHER OR NOT
511 | KNOWN OR DISCOVERABLE. WHERE DISCLAIMERS OF WARRANTIES ARE NOT
512 | ALLOWED IN FULL OR IN PART, THIS DISCLAIMER MAY NOT APPLY TO YOU.
513 |
514 | b. TO THE EXTENT POSSIBLE, IN NO EVENT WILL THE LICENSOR BE LIABLE
515 | TO YOU ON ANY LEGAL THEORY (INCLUDING, WITHOUT LIMITATION,
516 | NEGLIGENCE) OR OTHERWISE FOR ANY DIRECT, SPECIAL, INDIRECT,
517 | INCIDENTAL, CONSEQUENTIAL, PUNITIVE, EXEMPLARY, OR OTHER LOSSES,
518 | COSTS, EXPENSES, OR DAMAGES ARISING OUT OF THIS PUBLIC LICENSE OR
519 | USE OF THE LICENSED MATERIAL, EVEN IF THE LICENSOR HAS BEEN
520 | ADVISED OF THE POSSIBILITY OF SUCH LOSSES, COSTS, EXPENSES, OR
521 | DAMAGES. WHERE A LIMITATION OF LIABILITY IS NOT ALLOWED IN FULL OR
522 | IN PART, THIS LIMITATION MAY NOT APPLY TO YOU.
523 |
524 | c. The disclaimer of warranties and limitation of liability provided
525 | above shall be interpreted in a manner that, to the extent
526 | possible, most closely approximates an absolute disclaimer and
527 | waiver of all liability.
528 |
529 |
530 | Section 6 -- Term and Termination.
531 |
532 | a. This Public License applies for the term of the Copyright and
533 | Similar Rights licensed here. However, if You fail to comply with
534 | this Public License, then Your rights under this Public License
535 | terminate automatically.
536 |
537 | b. Where Your right to use the Licensed Material has terminated under
538 | Section 6(a), it reinstates:
539 |
540 | 1. automatically as of the date the violation is cured, provided
541 | it is cured within 30 days of Your discovery of the
542 | violation; or
543 |
544 | 2. upon express reinstatement by the Licensor.
545 |
546 | For the avoidance of doubt, this Section 6(b) does not affect any
547 | right the Licensor may have to seek remedies for Your violations
548 | of this Public License.
549 |
550 | c. For the avoidance of doubt, the Licensor may also offer the
551 | Licensed Material under separate terms or conditions or stop
552 | distributing the Licensed Material at any time; however, doing so
553 | will not terminate this Public License.
554 |
555 | d. Sections 1, 5, 6, 7, and 8 survive termination of this Public
556 | License.
557 |
558 |
559 | Section 7 -- Other Terms and Conditions.
560 |
561 | a. The Licensor shall not be bound by any additional or different
562 | terms or conditions communicated by You unless expressly agreed.
563 |
564 | b. Any arrangements, understandings, or agreements regarding the
565 | Licensed Material not stated herein are separate from and
566 | independent of the terms and conditions of this Public License.
567 |
568 |
569 | Section 8 -- Interpretation.
570 |
571 | a. For the avoidance of doubt, this Public License does not, and
572 | shall not be interpreted to, reduce, limit, restrict, or impose
573 | conditions on any use of the Licensed Material that could lawfully
574 | be made without permission under this Public License.
575 |
576 | b. To the extent possible, if any provision of this Public License is
577 | deemed unenforceable, it shall be automatically reformed to the
578 | minimum extent necessary to make it enforceable. If the provision
579 | cannot be reformed, it shall be severed from this Public License
580 | without affecting the enforceability of the remaining terms and
581 | conditions.
582 |
583 | c. No term or condition of this Public License will be waived and no
584 | failure to comply consented to unless expressly agreed to by the
585 | Licensor.
586 |
587 | d. Nothing in this Public License constitutes or may be interpreted
588 | as a limitation upon, or waiver of, any privileges and immunities
589 | that apply to the Licensor or You, including from the legal
590 | processes of any jurisdiction or authority.
591 |
592 |
593 | =======================================================================
594 |
595 | Creative Commons is not a party to its public
596 | licenses. Notwithstanding, Creative Commons may elect to apply one of
597 | its public licenses to material it publishes and in those instances
598 | will be considered the “Licensor.” The text of the Creative Commons
599 | public licenses is dedicated to the public domain under the CC0 Public
600 | Domain Dedication. Except for the limited purpose of indicating that
601 | material is shared under a Creative Commons public license or as
602 | otherwise permitted by the Creative Commons policies published at
603 | creativecommons.org/policies, Creative Commons does not authorize the
604 | use of the trademark "Creative Commons" or any other trademark or logo
605 | of Creative Commons without its prior written consent including,
606 | without limitation, in connection with any unauthorized modifications
607 | to any of its public licenses or any other arrangements,
608 | understandings, or agreements concerning use of licensed material. For
609 | the avoidance of doubt, this paragraph does not form part of the
610 | public licenses.
611 |
612 | Creative Commons may be contacted at creativecommons.org.
613 |
614 |
--------------------------------------------------------------------------------