Skip to content

Commit 14e2771

Browse files
Initial commit
0 parents  commit 14e2771

File tree

72 files changed

+2224
-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.

72 files changed

+2224
-0
lines changed

.gitattributes

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# Auto detect text files and perform LF normalization
2+
* text=auto

.gitignore

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
*.iml
2+
.gradle
3+
/local.properties
4+
.idea
5+
.DS_Store
6+
/build
7+
/captures
8+
.externalNativeBuild

LICENSE.txt

Lines changed: 613 additions & 0 deletions
Large diffs are not rendered by default.

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# vjournal-calendar
2+

app/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/build

app/build.gradle

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
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+
apply plugin: 'kotlin-android-extensions'
20+
apply plugin: 'kotlin-kapt'
21+
apply plugin: 'androidx.navigation.safeargs'
22+
23+
android {
24+
compileSdkVersion 30
25+
defaultConfig {
26+
applicationId "com.example.android.vjournalcalendar"
27+
minSdkVersion 19
28+
targetSdkVersion 30
29+
versionCode 1
30+
versionName "1.0"
31+
multiDexEnabled true
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+
buildFeatures {
43+
dataBinding true
44+
}
45+
}
46+
47+
dependencies {
48+
implementation fileTree(dir: 'libs', include: ['*.jar'])
49+
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$version_kotlin"
50+
51+
// Support libraries
52+
implementation "androidx.constraintlayout:constraintlayout:$version_constraint_layout"
53+
54+
// Android KTX
55+
implementation "androidx.core:core-ktx:$version_core"
56+
57+
// Room and Lifecycle dependencies
58+
implementation "androidx.room:room-runtime:$version_room"
59+
kapt "androidx.room:room-compiler:$version_room"
60+
implementation "androidx.lifecycle:lifecycle-extensions:$version_lifecycle_extensions"
61+
62+
// Coroutines
63+
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core:$version_coroutine"
64+
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-android:$version_coroutine"
65+
66+
// Navigation
67+
implementation "android.arch.navigation:navigation-fragment-ktx:$version_navigation"
68+
implementation "android.arch.navigation:navigation-ui-ktx:$version_navigation"
69+
70+
// ViewModel and LiveData
71+
implementation "androidx.lifecycle:lifecycle-viewmodel-ktx:$version_lifecycle"
72+
73+
// Kotlin Extensions and Coroutines support for Room
74+
implementation "androidx.room:room-ktx:$version_room"
75+
76+
77+
// Testing
78+
testImplementation 'junit:junit:4.12'
79+
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
80+
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
81+
}

app/proguard-rules.pro

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: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
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.vjournalcalendar
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.vjournalcalendar.database.VJournalDatabase
23+
import com.example.android.vjournalcalendar.database.VJournalDatabaseDao
24+
import com.example.android.vjournalcalendar.database.vJournalItem
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+
* This is not meant to be a full set of tests. For simplicity, most of your samples do not
34+
* include tests. However, when building the Room, it is helpful to make sure it works before
35+
* adding the UI.
36+
*/
37+
38+
@RunWith(AndroidJUnit4::class)
39+
class SleepDatabaseTest {
40+
41+
private lateinit var VJournalDao: VJournalDatabaseDao
42+
private lateinit var db: VJournalDatabase
43+
44+
@Before
45+
fun createDb() {
46+
val context = InstrumentationRegistry.getInstrumentation().targetContext
47+
// Using an in-memory database because the information stored here disappears when the
48+
// process is killed.
49+
db = Room.inMemoryDatabaseBuilder(context, VJournalDatabase::class.java)
50+
// Allowing main thread queries, just for testing.
51+
.allowMainThreadQueries()
52+
.build()
53+
VJournalDao = db.vJournalDatabaseDao
54+
}
55+
56+
@Test
57+
@Throws(Exception::class)
58+
suspend fun insert() {
59+
var vJournalItem = vJournalItem()
60+
vJournalItem.description = "asdf"
61+
vJournalItem.comment = "asfd"
62+
vJournalItem = VJournalDao.insert(vJournalItem)
63+
val retrievedItem = VJournalDao.get(vJournalItem.id)
64+
assertEquals(vJournalItem, retrievedItem)
65+
}
66+
67+
68+
69+
@After
70+
@Throws(IOException::class)
71+
fun closeDb() {
72+
db.close()
73+
}
74+
75+
}
76+

app/src/main/AndroidManifest.xml

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.vjournalcalendar">
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="com.example.android.vjournalcalendar.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 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.vjournalcalendar
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+
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
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.vjournalcalendar
18+
19+
import android.annotation.SuppressLint
20+
import java.text.SimpleDateFormat
21+
22+
23+
/**
24+
* Take the Long milliseconds returned by the system and stored in Room,
25+
* and convert it to a nicely formatted string for display.
26+
*
27+
* EEEE - Display the long letter version of the weekday
28+
* MMM - Display the letter abbreviation of the nmotny
29+
* dd-yyyy - day in month and full year numerically
30+
* HH:mm - Hours and minutes in 24hr format
31+
*/
32+
@SuppressLint("SimpleDateFormat")
33+
fun convertLongToDateString(systemTime: Long): String {
34+
return SimpleDateFormat("EEEE MMM-dd-yyyy' Time: 'HH:mm")
35+
.format(systemTime).toString()
36+
}
37+
38+

0 commit comments

Comments
 (0)