Skip to content
This repository was archived by the owner on Jan 11, 2024. It is now read-only.

Commit a60bbab

Browse files
author
Aleks Haecky
committed
Initial commit for Android Kotlin Fundamentals Starter Apps.
Change-Id: Ie023e44ad1b307280f9c7e01255e32a9b1322cfb
1 parent e85e5ac commit a60bbab

File tree

206 files changed

+6050
-0
lines changed

Some content is hidden

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

206 files changed

+6050
-0
lines changed
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
TrackMySleepQuality - Starter Code
2+
==================================
3+
4+
Starter code for Android Kotlin Fundamentals Codelab 6.1 Room
5+
6+
Introduction
7+
------------
8+
9+
TrackMySleepQuality is an app for recording sleep data for each night.
10+
You can record a start and stop time, assign a quality rating, and clear the database.
11+
12+
In this codelab, working from this starter app,
13+
you will implement the Room database that holds the sleep data.
14+
You will then use instrumented tests to verify that this backend works.
15+
16+
17+
Pre-requisites
18+
--------------
19+
20+
You need to know:
21+
22+
* Building a basic user interface (UI) for an Android app,
23+
using an activity, fragments, and views.
24+
* Navigating between fragments and using Safe Args (a Gradle plugin)
25+
to pass data between fragments.
26+
* View models, view-model factories, and LiveData and its observers.
27+
These Architecture Components topics are covered in an earlier codelab in this course.
28+
* A basic understanding of SQL databases and the SQLite language.
29+
30+
31+
Getting Started
32+
---------------
33+
34+
1. Download and run the app.
35+
36+
License
37+
-------
38+
39+
Copyright 2019 Google, Inc.
40+
41+
Licensed to the Apache Software Foundation (ASF) under one or more contributor
42+
license agreements. See the NOTICE file distributed with this work for
43+
additional information regarding copyright ownership. The ASF licenses this
44+
file to you under the Apache License, Version 2.0 (the "License"); you may not
45+
use this file except in compliance with the License. You may obtain a copy of
46+
the License at
47+
48+
http://www.apache.org/licenses/LICENSE-2.0
49+
50+
Unless required by applicable law or agreed to in writing, software
51+
distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
52+
WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
53+
License for the specific language governing permissions and limitations under
54+
the License.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/build
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
/*
2+
* Copyright 2019, 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+
apply plugin: 'kotlin-android-extensions'
20+
apply plugin: 'kotlin-kapt'
21+
apply plugin: 'androidx.navigation.safeargs'
22+
23+
android {
24+
compileSdkVersion 28
25+
defaultConfig {
26+
applicationId "com.example.android.trackmysleepquality"
27+
minSdkVersion 19
28+
targetSdkVersion 28
29+
versionCode 1
30+
versionName "1.0"
31+
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
32+
vectorDrawables.useSupportLibrary = true
33+
}
34+
buildTypes {
35+
release {
36+
minifyEnabled false
37+
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
38+
}
39+
}
40+
41+
// Enables data binding.
42+
dataBinding {
43+
enabled = true
44+
}
45+
46+
}
47+
48+
dependencies {
49+
50+
implementation fileTree(dir: 'libs', include: ['*.jar'])
51+
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
52+
53+
// Support libraries
54+
implementation "androidx.appcompat:appcompat:1.0.2"
55+
implementation "androidx.fragment:fragment:1.0.0"
56+
implementation "androidx.constraintlayout:constraintlayout:2.0.0-alpha3"
57+
58+
// Android KTX
59+
implementation 'androidx.core:core-ktx:1.0.1'
60+
61+
// Room and Lifecycle dependencies
62+
implementation "androidx.room:room-runtime:$room_version"
63+
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
64+
kapt "androidx.room:room-compiler:$room_version"
65+
implementation "androidx.lifecycle:lifecycle-extensions:2.0.0"
66+
67+
// Coroutines
68+
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core:$coroutine_version"
69+
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-android:$coroutine_version"
70+
71+
// Navigation
72+
implementation "android.arch.navigation:navigation-fragment-ktx:$navigationVersion"
73+
implementation "android.arch.navigation:navigation-ui-ktx:$navigationVersion"
74+
75+
// Testing
76+
testImplementation 'junit:junit:4.12'
77+
androidTestImplementation 'androidx.test.ext:junit:1.1.0'
78+
androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.1'
79+
}
80+
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
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
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
/*
2+
* Copyright 2019, 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 org.junit.Assert.assertEquals
26+
//import org.junit.After
27+
//import org.junit.Before
28+
//import org.junit.Test
29+
//import org.junit.runner.RunWith
30+
//import java.io.IOException
31+
//
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() {
66+
// val night = SleepNight()
67+
// sleepDao.insert(night)
68+
// val tonight = sleepDao.getTonight()
69+
// assertEquals(tonight?.sleepQuality, -1)
70+
// }
71+
//}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
3+
package="com.example.android.trackmysleepquality">
4+
5+
<application
6+
android:allowBackup="true"
7+
android:icon="@mipmap/ic_launcher_sleep_tracker"
8+
android:label="@string/app_name"
9+
android:roundIcon="@mipmap/ic_launcher_sleep_tracker_round"
10+
android:supportsRtl="true"
11+
android:theme="@style/AppTheme">
12+
<activity android:name=".MainActivity">
13+
<intent-filter>
14+
<action android:name="android.intent.action.MAIN" />
15+
16+
<category android:name="android.intent.category.LAUNCHER" />
17+
</intent-filter>
18+
</activity>
19+
<meta-data
20+
android:name="preloaded_fonts"
21+
android:resource="@array/preloaded_fonts" />
22+
</application>
23+
24+
</manifest>
28.7 KB
Loading
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
/*
2+
* Copyright 2019, 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+
}

0 commit comments

Comments
 (0)