├── .gitignore
├── README.md
├── app
├── .gitignore
├── build.gradle
├── proguard-rules.pro
└── src
│ ├── androidTest
│ └── java
│ │ └── co
│ │ └── icanteach
│ │ └── apps
│ │ └── android
│ │ └── composenotes
│ │ ├── ComposeNotesTestRunner.kt
│ │ ├── DetailScreenTest.kt
│ │ └── HomeScreenTest.kt
│ ├── main
│ ├── AndroidManifest.xml
│ ├── java
│ │ └── co
│ │ │ └── icanteach
│ │ │ └── apps
│ │ │ └── android
│ │ │ └── composenotes
│ │ │ ├── AppNavigator.kt
│ │ │ ├── ComposeNotesApplication.kt
│ │ │ ├── MainActivity.kt
│ │ │ ├── data
│ │ │ ├── ColorGenerator.kt
│ │ │ ├── DataModule.kt
│ │ │ ├── Note.kt
│ │ │ ├── NoteDao.kt
│ │ │ ├── NoteDatabase.kt
│ │ │ ├── NoteEntity.kt
│ │ │ ├── NoteMapper.kt
│ │ │ ├── NoteRepository.kt
│ │ │ └── NoteRepositoryImpl.kt
│ │ │ ├── detail
│ │ │ ├── DetailPageEvent.kt
│ │ │ ├── DetailPageViewState.kt
│ │ │ ├── DetailScreen.kt
│ │ │ ├── DetailViewModel.kt
│ │ │ └── domain
│ │ │ │ ├── CreateNoteUseCase.kt
│ │ │ │ ├── DeleteNoteUseCase.kt
│ │ │ │ └── GetNoteUseCase.kt
│ │ │ ├── home
│ │ │ ├── HomePageViewState.kt
│ │ │ ├── HomeScreen.kt
│ │ │ ├── HomeViewModel.kt
│ │ │ ├── StaggeredVerticalGrid.kt
│ │ │ └── domain
│ │ │ │ └── FetchHomePageContentUseCase.kt
│ │ │ ├── ui
│ │ │ └── theme
│ │ │ │ ├── Color.kt
│ │ │ │ ├── Shape.kt
│ │ │ │ ├── Theme.kt
│ │ │ │ └── Type.kt
│ │ │ └── util
│ │ │ └── DateFormatter.kt
│ └── res
│ │ ├── drawable-v24
│ │ └── ic_launcher_foreground.xml
│ │ ├── drawable
│ │ ├── ic_back.xml
│ │ ├── ic_check.xml
│ │ ├── ic_launcher_background.xml
│ │ └── ic_trash.xml
│ │ ├── font
│ │ ├── sailec_bold.otf
│ │ ├── sailec_medium.otf
│ │ └── sailec_regular.otf
│ │ ├── mipmap-anydpi-v26
│ │ ├── ic_launcher.xml
│ │ └── ic_launcher_round.xml
│ │ ├── mipmap-hdpi
│ │ ├── ic_launcher.webp
│ │ └── ic_launcher_round.webp
│ │ ├── mipmap-mdpi
│ │ ├── ic_launcher.webp
│ │ └── ic_launcher_round.webp
│ │ ├── mipmap-xhdpi
│ │ ├── ic_launcher.webp
│ │ └── ic_launcher_round.webp
│ │ ├── mipmap-xxhdpi
│ │ ├── ic_launcher.webp
│ │ └── ic_launcher_round.webp
│ │ ├── mipmap-xxxhdpi
│ │ ├── ic_launcher.webp
│ │ └── ic_launcher_round.webp
│ │ └── values
│ │ ├── colors.xml
│ │ ├── strings.xml
│ │ └── themes.xml
│ └── test
│ └── java
│ └── co
│ └── icanteach
│ └── apps
│ └── android
│ └── composenotes
│ ├── FakeRepository.kt
│ ├── TestCoroutineRule.kt
│ └── detail
│ └── domain
│ ├── CreateNoteUseCaseTest.kt
│ └── GetNoteUseCaseTest.kt
├── build.gradle
├── gradle.properties
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── gradlew
├── gradlew.bat
├── screenshots
├── detail_page.png
└── home_page.png
└── settings.gradle
/.gitignore:
--------------------------------------------------------------------------------
1 | # Gradle and Android Studio ignores
2 | .gradle
3 | /local.properties
4 | /.idea
5 | .DS_Store
6 | /build
7 |
8 | # IDEA/Android Studio project files, because
9 | # the project can be imported from settings.gradle
10 | .idea
11 | *.iml
12 |
13 | # Built application files
14 | *.apk
15 | *.ap_
16 |
17 | # Files for the Dalvik VM
18 | *.dex
19 |
20 | # Java class files
21 | *.class
22 |
23 | # Generated files
24 | bin/
25 | gen/
26 |
27 | # Gradle files
28 | .gradle/
29 | build/
30 |
31 | # Local configuration file (sdk path, etc)
32 | local.properties
33 |
34 | # Proguard folder generated by Eclipse
35 | proguard/
36 |
37 | # Log Files
38 | *.log
39 |
40 | /captures
41 | .externalNativeBuild
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 |
2 |
ComposeNotes
3 |
4 | A demo app using compose and Hilt based on modern Android tech-stacks and MVVM architecture.
5 |
6 |
7 | ## Download
8 |
9 | ## Screenshots
10 |
11 |
12 | ## Tech stack & Open-source libraries
13 | - 100% [Kotlin](https://kotlinlang.org/) based + [Coroutines](https://github.com/Kotlin/kotlinx.coroutines) + [Flow](https://kotlin.github.io/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines.flow/) for asynchronous.
14 | - Hilt for dependency injection.
15 | - JetPack
16 | - Compose - A modern toolkit for building native Android UI.
17 | - ViewModel - UI related data holder, lifecycle aware.
18 | - Room Persistence - construct database.
19 | - Architecture
20 | - MVVM
21 |
22 | # License
23 | ```
24 | Licensed under the Apache License, Version 2.0 (the "License");
25 | you may not use this file except in compliance with the License.
26 | You may obtain a copy of the License at
27 |
28 | http://www.apache.org/licenses/LICENSE-2.0
29 |
30 | Unless required by applicable law or agreed to in writing, software
31 | distributed under the License is distributed on an "AS IS" BASIS,
32 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
33 | See the License for the specific language governing permissions and
34 | limitations under the License.
35 | ```
36 |
--------------------------------------------------------------------------------
/app/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 | *.iml
--------------------------------------------------------------------------------
/app/build.gradle:
--------------------------------------------------------------------------------
1 | plugins {
2 | id 'com.android.application'
3 | id 'org.jetbrains.kotlin.android'
4 | id 'kotlin-kapt'
5 | id 'dagger.hilt.android.plugin'
6 | }
7 |
8 | android {
9 | compileSdk 31
10 |
11 | defaultConfig {
12 | applicationId "co.icanteach.apps.android.composenotes"
13 | minSdk 21
14 | targetSdk 31
15 | versionCode 1
16 | versionName "1.0"
17 |
18 | testInstrumentationRunner "co.icanteach.apps.android.composenotes.ComposeNotesTestRunner"
19 | vectorDrawables {
20 | useSupportLibrary true
21 | }
22 | }
23 |
24 | buildTypes {
25 | release {
26 | minifyEnabled false
27 | proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
28 | }
29 | }
30 | compileOptions {
31 | sourceCompatibility JavaVersion.VERSION_1_8
32 | targetCompatibility JavaVersion.VERSION_1_8
33 | }
34 | kotlinOptions {
35 | jvmTarget = '1.8'
36 | }
37 | buildFeatures {
38 | compose true
39 | }
40 | composeOptions {
41 | kotlinCompilerExtensionVersion compose_version
42 | }
43 | packagingOptions {
44 | resources {
45 | excludes += '/META-INF/{AL2.0,LGPL2.1}'
46 | }
47 | }
48 | }
49 |
50 | dependencies {
51 |
52 | implementation 'androidx.core:core-ktx:1.7.0'
53 | implementation "androidx.compose.ui:ui:$compose_version"
54 | implementation "androidx.compose.material:material:$compose_version"
55 | implementation "androidx.compose.ui:ui-tooling-preview:$compose_version"
56 | implementation 'androidx.lifecycle:lifecycle-runtime-ktx:2.3.1'
57 | implementation 'androidx.activity:activity-compose:1.3.1'
58 | testImplementation 'junit:junit:4.13.2'
59 | androidTestImplementation 'androidx.test.ext:junit:1.1.3'
60 | androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
61 | androidTestImplementation "androidx.compose.ui:ui-test-junit4:$compose_version"
62 | debugImplementation "androidx.compose.ui:ui-tooling:$compose_version"
63 |
64 | implementation "com.google.dagger:hilt-android:2.40"
65 | kapt "com.google.dagger:hilt-compiler:2.40"
66 |
67 | def nav_version = "2.4.1"
68 | implementation "androidx.navigation:navigation-compose:$nav_version"
69 |
70 | // room
71 | def room_version = "2.4.2"
72 | implementation "androidx.room:room-runtime:$room_version"
73 | kapt "androidx.room:room-compiler:$room_version"
74 | implementation "androidx.room:room-ktx:$room_version"
75 |
76 | implementation 'androidx.hilt:hilt-navigation-compose:1.0.0'
77 |
78 | // Test rules and transitive dependencies:
79 | androidTestImplementation("androidx.compose.ui:ui-test-junit4:$compose_version")
80 | // Needed for createComposeRule, but not createAndroidComposeRule:
81 | debugImplementation("androidx.compose.ui:ui-test-manifest:$compose_version")
82 |
83 | // For instrumented tests.
84 | androidTestImplementation 'com.google.dagger:hilt-android-testing:2.38.1'
85 | kaptAndroidTest 'com.google.dagger:hilt-android-compiler:2.40'
86 |
87 | testImplementation "com.google.truth:truth:1.1.3"
88 | testImplementation 'org.jetbrains.kotlinx:kotlinx-coroutines-test:1.6.0-native-mt'
89 |
90 | testImplementation 'io.mockk:mockk:1.10.4'
91 |
92 |
93 | }
--------------------------------------------------------------------------------
/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
--------------------------------------------------------------------------------
/app/src/androidTest/java/co/icanteach/apps/android/composenotes/ComposeNotesTestRunner.kt:
--------------------------------------------------------------------------------
1 | package co.icanteach.apps.android.composenotes
2 |
3 | import android.app.Application
4 | import android.content.Context
5 | import androidx.test.runner.AndroidJUnitRunner
6 | import dagger.hilt.android.testing.HiltTestApplication
7 |
8 | class ComposeNotesTestRunner : AndroidJUnitRunner() {
9 |
10 | override fun newApplication(
11 | cl: ClassLoader?,
12 | className: String?,
13 | context: Context?,
14 | ): Application {
15 | return super.newApplication(cl, HiltTestApplication::class.java.name, context)
16 | }
17 | }
--------------------------------------------------------------------------------
/app/src/androidTest/java/co/icanteach/apps/android/composenotes/DetailScreenTest.kt:
--------------------------------------------------------------------------------
1 | package co.icanteach.apps.android.composenotes
2 |
3 | import androidx.compose.ui.test.junit4.createAndroidComposeRule
4 | import dagger.hilt.android.testing.HiltAndroidRule
5 | import dagger.hilt.android.testing.HiltAndroidTest
6 | import org.junit.Before
7 | import org.junit.Rule
8 |
9 | @HiltAndroidTest
10 | class DetailScreenTest {
11 |
12 | @get:Rule(order = 0)
13 | var hiltRule = HiltAndroidRule(this)
14 |
15 | @get:Rule(order = 1)
16 | val composeTestRule = createAndroidComposeRule()
17 |
18 | @Before
19 | fun setUp() {
20 | hiltRule.inject()
21 | }
22 |
23 | }
--------------------------------------------------------------------------------
/app/src/androidTest/java/co/icanteach/apps/android/composenotes/HomeScreenTest.kt:
--------------------------------------------------------------------------------
1 | package co.icanteach.apps.android.composenotes
2 |
3 | import androidx.compose.ui.test.assertIsDisplayed
4 | import androidx.compose.ui.test.assertIsEnabled
5 | import androidx.compose.ui.test.junit4.createAndroidComposeRule
6 | import androidx.compose.ui.test.onNodeWithText
7 | import androidx.navigation.compose.rememberNavController
8 | import co.icanteach.apps.android.composenotes.home.HomeScreen
9 | import co.icanteach.apps.android.composenotes.ui.theme.ComposeNotesTheme
10 | import dagger.hilt.android.testing.HiltAndroidRule
11 | import dagger.hilt.android.testing.HiltAndroidTest
12 | import org.junit.Before
13 | import org.junit.Rule
14 | import org.junit.Test
15 |
16 | @HiltAndroidTest
17 | class HomeScreenTest {
18 |
19 | @get:Rule(order = 0)
20 | var hiltRule = HiltAndroidRule(this)
21 |
22 | @get:Rule(order = 1)
23 | val composeTestRule = createAndroidComposeRule()
24 |
25 | @Before
26 | fun setUp() {
27 | hiltRule.inject()
28 | }
29 |
30 | @Test
31 | fun test_CreateNote_Displayed() {
32 | // Start the app
33 | composeTestRule.setContent {
34 | val navController = rememberNavController()
35 | ComposeNotesTheme {
36 | HomeScreen(navController = navController)
37 | }
38 | }
39 |
40 | composeTestRule.onNodeWithText("NEW NOTE").assertIsDisplayed()
41 | }
42 |
43 | @Test
44 | fun test_CreateNote_Enabled() {
45 | // Start the app
46 | composeTestRule.setContent {
47 | val navController = rememberNavController()
48 | ComposeNotesTheme {
49 | HomeScreen(navController = navController)
50 | }
51 | }
52 |
53 | composeTestRule.onNodeWithText("NEW NOTE").assertIsEnabled()
54 | }
55 | }
--------------------------------------------------------------------------------
/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
13 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
--------------------------------------------------------------------------------
/app/src/main/java/co/icanteach/apps/android/composenotes/AppNavigator.kt:
--------------------------------------------------------------------------------
1 | package co.icanteach.apps.android.composenotes
2 |
3 | import androidx.compose.runtime.Composable
4 | import androidx.compose.ui.graphics.BlendMode.Companion.Screen
5 | import androidx.navigation.NavType
6 | import androidx.navigation.compose.NavHost
7 | import androidx.navigation.compose.composable
8 | import androidx.navigation.compose.rememberNavController
9 | import androidx.navigation.navArgument
10 | import co.icanteach.apps.android.composenotes.detail.DetailScreen
11 | import co.icanteach.apps.android.composenotes.home.HomeScreen
12 |
13 | @Composable
14 | fun AppNavigator() {
15 | val navController = rememberNavController()
16 |
17 | NavHost(
18 | navController = navController,
19 | startDestination = Screens.HomeScreen.route
20 | ) {
21 | composable(Screens.HomeScreen.route) {
22 | HomeScreen(
23 | navController = navController
24 | )
25 | }
26 |
27 | composable(
28 | route = Screens.DetailScreen.route
29 | ) {
30 | DetailScreen(
31 | navController = navController,
32 | )
33 | }
34 |
35 | composable(
36 | route = Screens.DetailScreen.route + "?noteId={noteId}",
37 | arguments = listOf(
38 | navArgument(
39 | name = "noteId"
40 | ) {
41 | type = NavType.IntType
42 | }
43 | )
44 | ) {
45 | DetailScreen(
46 | navController = navController,
47 | )
48 | }
49 | }
50 | }
51 |
52 | sealed class Screens(val route: String) {
53 | object HomeScreen : Screens("home_screen")
54 | object DetailScreen : Screens("detail_screen")
55 | }
--------------------------------------------------------------------------------
/app/src/main/java/co/icanteach/apps/android/composenotes/ComposeNotesApplication.kt:
--------------------------------------------------------------------------------
1 | package co.icanteach.apps.android.composenotes
2 |
3 | import android.app.Application
4 | import dagger.hilt.android.HiltAndroidApp
5 |
6 | @HiltAndroidApp
7 | class ComposeNotesApplication : Application() {
8 | }
--------------------------------------------------------------------------------
/app/src/main/java/co/icanteach/apps/android/composenotes/MainActivity.kt:
--------------------------------------------------------------------------------
1 | package co.icanteach.apps.android.composenotes
2 |
3 | import android.os.Bundle
4 | import androidx.activity.ComponentActivity
5 | import androidx.activity.compose.setContent
6 | import co.icanteach.apps.android.composenotes.ui.theme.ComposeNotesTheme
7 | import dagger.hilt.android.AndroidEntryPoint
8 |
9 | @AndroidEntryPoint
10 | class MainActivity : ComponentActivity() {
11 | override fun onCreate(savedInstanceState: Bundle?) {
12 | super.onCreate(savedInstanceState)
13 | setContent {
14 | ComposeNotesTheme {
15 | AppNavigator()
16 | }
17 | }
18 | }
19 | }
--------------------------------------------------------------------------------
/app/src/main/java/co/icanteach/apps/android/composenotes/data/ColorGenerator.kt:
--------------------------------------------------------------------------------
1 | package co.icanteach.apps.android.composenotes.data
2 |
3 | import co.icanteach.apps.android.composenotes.R
4 |
5 | object ColorGenerator {
6 |
7 | private val colors = listOf(
8 | R.color.card_color_1,
9 | R.color.card_color_2,
10 | R.color.card_color_3,
11 | R.color.card_color_4,
12 | R.color.card_color_5,
13 | R.color.card_color_6,
14 | R.color.card_color_7,
15 | R.color.card_color_8,
16 | R.color.card_color_9,
17 | R.color.card_color_10,
18 | R.color.card_color_11
19 | )
20 |
21 | fun getColor() = colors.random()
22 | }
--------------------------------------------------------------------------------
/app/src/main/java/co/icanteach/apps/android/composenotes/data/DataModule.kt:
--------------------------------------------------------------------------------
1 | package co.icanteach.apps.android.composenotes.data
2 |
3 | import android.app.Application
4 | import androidx.room.Room
5 | import dagger.Module
6 | import dagger.Provides
7 | import dagger.hilt.InstallIn
8 | import dagger.hilt.components.SingletonComponent
9 | import javax.inject.Singleton
10 |
11 | @Module
12 | @InstallIn(SingletonComponent::class)
13 | object AppModule {
14 |
15 | @Provides
16 | @Singleton
17 | fun provideNoteDatabase(app: Application): NoteDatabase {
18 | return Room.databaseBuilder(
19 | app,
20 | NoteDatabase::class.java,
21 | NoteDatabase.DATABASE_NAME
22 | ).build()
23 | }
24 |
25 | @Provides
26 | @Singleton
27 | fun provideNoteRepository(db: NoteDatabase): NoteRepository {
28 | return NoteRepositoryImpl(db.noteDao)
29 | }
30 | }
--------------------------------------------------------------------------------
/app/src/main/java/co/icanteach/apps/android/composenotes/data/Note.kt:
--------------------------------------------------------------------------------
1 | package co.icanteach.apps.android.composenotes.data
2 |
3 | import co.icanteach.apps.android.composenotes.data.ColorGenerator.getColor
4 |
5 | data class Note(
6 | val content: String,
7 | val timestamp: Long,
8 | val color: Int,
9 | val id: Int? = null,
10 | ) {
11 | companion object {
12 |
13 | val Default = Note(
14 | content = "",
15 | timestamp = System.currentTimeMillis(),
16 | color = getColor()
17 | )
18 | }
19 | }
--------------------------------------------------------------------------------
/app/src/main/java/co/icanteach/apps/android/composenotes/data/NoteDao.kt:
--------------------------------------------------------------------------------
1 | package co.icanteach.apps.android.composenotes.data
2 |
3 | import androidx.room.Dao
4 | import androidx.room.Delete
5 | import androidx.room.Insert
6 | import androidx.room.OnConflictStrategy
7 | import androidx.room.Query
8 | import kotlinx.coroutines.flow.Flow
9 |
10 | @Dao
11 | interface NoteDao {
12 |
13 | @Query("SELECT * FROM note")
14 | fun getNotes(): Flow>
15 |
16 | @Query("SELECT * FROM note WHERE id = :id")
17 | suspend fun getNoteById(id: Int): NoteEntity?
18 |
19 | @Insert(onConflict = OnConflictStrategy.REPLACE)
20 | suspend fun insertNote(note: NoteEntity)
21 |
22 | @Query("DELETE FROM note WHERE id = :id")
23 | suspend fun deleteNote(id : Int?)
24 | }
--------------------------------------------------------------------------------
/app/src/main/java/co/icanteach/apps/android/composenotes/data/NoteDatabase.kt:
--------------------------------------------------------------------------------
1 | package co.icanteach.apps.android.composenotes.data
2 |
3 | import androidx.room.Database
4 | import androidx.room.RoomDatabase
5 |
6 |
7 | @Database(
8 | entities = [NoteEntity::class],
9 | version = 1,
10 | exportSchema = false
11 | )
12 | abstract class NoteDatabase: RoomDatabase() {
13 |
14 | abstract val noteDao: NoteDao
15 |
16 | companion object {
17 | const val DATABASE_NAME = "notes_db"
18 | }
19 | }
--------------------------------------------------------------------------------
/app/src/main/java/co/icanteach/apps/android/composenotes/data/NoteEntity.kt:
--------------------------------------------------------------------------------
1 | package co.icanteach.apps.android.composenotes.data
2 |
3 | import androidx.room.Entity
4 | import androidx.room.PrimaryKey
5 |
6 | @Entity(tableName = "note")
7 | data class NoteEntity(
8 | val content: String,
9 | val timestamp: Long,
10 | val color: Int,
11 | @PrimaryKey(autoGenerate = true)
12 | val id: Int? = null,
13 | ) {
14 | companion object {
15 | val Default = NoteEntity(
16 | content = "",
17 | timestamp = System.currentTimeMillis(),
18 | color = ColorGenerator.getColor()
19 | )
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/app/src/main/java/co/icanteach/apps/android/composenotes/data/NoteMapper.kt:
--------------------------------------------------------------------------------
1 | package co.icanteach.apps.android.composenotes.data
2 |
3 | import javax.inject.Inject
4 |
5 | class NoteMapper @Inject constructor() {
6 |
7 | fun map(note: Note): NoteEntity {
8 | return NoteEntity(
9 | content = note.content,
10 | timestamp = note.timestamp,
11 | color = note.color,
12 | id = note.id
13 | )
14 | }
15 |
16 |
17 | fun map(note: NoteEntity): Note {
18 | return Note(
19 | content = note.content,
20 | timestamp = note.timestamp,
21 | id = note.id,
22 | color = note.color
23 | )
24 | }
25 |
26 | fun map(notes: List): List {
27 | return notes.map { note ->
28 | Note(
29 | content = note.content,
30 | timestamp = note.timestamp,
31 | id = note.id,
32 | color = note.color
33 | )
34 | }
35 | }
36 | }
--------------------------------------------------------------------------------
/app/src/main/java/co/icanteach/apps/android/composenotes/data/NoteRepository.kt:
--------------------------------------------------------------------------------
1 | package co.icanteach.apps.android.composenotes.data
2 |
3 | import kotlinx.coroutines.flow.Flow
4 |
5 | interface NoteRepository {
6 |
7 | fun getNotes(): Flow>
8 |
9 | suspend fun getNoteById(id: Int): NoteEntity?
10 |
11 | suspend fun insertNote(note: NoteEntity)
12 |
13 | suspend fun deleteNote(id: Int?)
14 | }
--------------------------------------------------------------------------------
/app/src/main/java/co/icanteach/apps/android/composenotes/data/NoteRepositoryImpl.kt:
--------------------------------------------------------------------------------
1 | package co.icanteach.apps.android.composenotes.data
2 |
3 | import kotlinx.coroutines.flow.Flow
4 |
5 | class NoteRepositoryImpl(
6 | private val dao: NoteDao
7 | ) : NoteRepository {
8 |
9 | override fun getNotes(): Flow> {
10 | return dao.getNotes()
11 | }
12 |
13 | override suspend fun getNoteById(id: Int): NoteEntity? {
14 | return dao.getNoteById(id)
15 | }
16 |
17 | override suspend fun insertNote(note: NoteEntity) {
18 | dao.insertNote(note)
19 | }
20 |
21 | override suspend fun deleteNote(id: Int?) {
22 | dao.deleteNote(id)
23 | }
24 | }
--------------------------------------------------------------------------------
/app/src/main/java/co/icanteach/apps/android/composenotes/detail/DetailPageEvent.kt:
--------------------------------------------------------------------------------
1 | package co.icanteach.apps.android.composenotes.detail
2 |
3 | import androidx.compose.ui.focus.FocusState
4 |
5 | sealed class DetailPageEvent {
6 | data class EnteredContent(val value: String) : DetailPageEvent()
7 | data class ChangeContentFocus(val focusState: FocusState) : DetailPageEvent()
8 | object SaveNote : DetailPageEvent()
9 | object DeleteNote : DetailPageEvent()
10 | }
--------------------------------------------------------------------------------
/app/src/main/java/co/icanteach/apps/android/composenotes/detail/DetailPageViewState.kt:
--------------------------------------------------------------------------------
1 | package co.icanteach.apps.android.composenotes.detail
2 |
3 | import co.icanteach.apps.android.composenotes.data.Note
4 |
5 |
6 | data class DetailPageViewState constructor(
7 | val note: Note,
8 | )
--------------------------------------------------------------------------------
/app/src/main/java/co/icanteach/apps/android/composenotes/detail/DetailScreen.kt:
--------------------------------------------------------------------------------
1 | package co.icanteach.apps.android.composenotes.detail
2 |
3 | import androidx.compose.foundation.layout.Arrangement
4 | import androidx.compose.foundation.layout.Column
5 | import androidx.compose.foundation.layout.PaddingValues
6 | import androidx.compose.foundation.layout.Row
7 | import androidx.compose.foundation.layout.Spacer
8 | import androidx.compose.foundation.layout.fillMaxSize
9 | import androidx.compose.foundation.layout.fillMaxWidth
10 | import androidx.compose.foundation.layout.height
11 | import androidx.compose.foundation.layout.padding
12 | import androidx.compose.foundation.text.BasicTextField
13 | import androidx.compose.material.BottomAppBar
14 | import androidx.compose.material.Icon
15 | import androidx.compose.material.IconButton
16 | import androidx.compose.material.MaterialTheme
17 | import androidx.compose.material.Scaffold
18 | import androidx.compose.material.Text
19 | import androidx.compose.material.TopAppBar
20 | import androidx.compose.material.rememberScaffoldState
21 | import androidx.compose.runtime.Composable
22 | import androidx.compose.runtime.LaunchedEffect
23 | import androidx.compose.ui.Alignment
24 | import androidx.compose.ui.Modifier
25 | import androidx.compose.ui.res.painterResource
26 | import androidx.compose.ui.res.stringResource
27 | import androidx.compose.ui.text.style.TextAlign
28 | import androidx.compose.ui.unit.dp
29 | import androidx.hilt.navigation.compose.hiltViewModel
30 | import androidx.navigation.NavController
31 | import co.icanteach.apps.android.composenotes.R
32 | import co.icanteach.apps.android.composenotes.util.DateFormatter
33 | import kotlinx.coroutines.flow.collectLatest
34 |
35 | @Composable
36 | fun DetailScreen(
37 | navController: NavController,
38 | viewModel: DetailViewModel = hiltViewModel(),
39 | ) {
40 |
41 | val pageState = viewModel.pageState.value
42 | val scaffoldState = rememberScaffoldState()
43 |
44 | LaunchedEffect(key1 = true) {
45 | viewModel.eventFlow.collectLatest { event ->
46 | when (event) {
47 | is DetailViewModel.UiEvent.ShowError -> {
48 | scaffoldState.snackbarHostState.showSnackbar(
49 | message = event.message
50 | )
51 | }
52 | is DetailViewModel.UiEvent.ClosePage -> {
53 | navController.navigateUp()
54 | }
55 | }
56 | }
57 | }
58 |
59 | Scaffold(
60 | topBar = { DetailScreenTopBar(onIconClick = { navController.navigateUp() }) },
61 | bottomBar = {
62 | DetailScreenBottomBar(
63 | timestamp = pageState.note.timestamp,
64 | onSaveClick = {
65 | viewModel.onEvent(DetailPageEvent.SaveNote)
66 | },
67 | onDeleteClick = {
68 | viewModel.onEvent(DetailPageEvent.DeleteNote)
69 | }
70 | )
71 | },
72 | scaffoldState = scaffoldState
73 | ) {
74 | DetailScreenBody(
75 | noteContent = pageState.note.content,
76 | onNoteContentChange = { newText ->
77 | viewModel.onEvent(DetailPageEvent.EnteredContent(newText))
78 | }
79 | )
80 | }
81 | }
82 |
83 | @Composable
84 | fun DetailScreenTopBar(
85 | onIconClick: () -> Unit,
86 | ) {
87 | TopAppBar(
88 | title = {},
89 | navigationIcon = {
90 | IconButton(onClick = onIconClick) {
91 | Icon(
92 | painterResource(id = R.drawable.ic_back),
93 | contentDescription = stringResource(id = R.string.app_name),
94 | )
95 | }
96 | },
97 | backgroundColor = MaterialTheme.colors.background,
98 | elevation = 0.dp
99 | )
100 | }
101 |
102 | @Composable
103 | fun DetailScreenBottomBar(
104 | timestamp: Long,
105 | onSaveClick: () -> Unit,
106 | onDeleteClick: () -> Unit,
107 | ) {
108 | BottomAppBar(
109 | modifier = Modifier.height(46.dp),
110 | backgroundColor = MaterialTheme.colors.background,
111 | contentPadding = PaddingValues(4.dp, 4.dp),
112 | content = {
113 | Row(
114 | verticalAlignment = Alignment.CenterVertically,
115 | horizontalArrangement = Arrangement.SpaceBetween,
116 | modifier = Modifier.fillMaxWidth()
117 | ) {
118 |
119 | val lastUpdatedText =
120 | stringResource(
121 | R.string.last_updated_date_desc,
122 | DateFormatter.getFormattedDate(
123 | timestamp,
124 | DateFormatter.Format.DAY_HOUR_FORMAT
125 | )
126 | )
127 | Text(
128 | text = lastUpdatedText,
129 | textAlign = TextAlign.Center,
130 | style = MaterialTheme.typography.overline,
131 | modifier = Modifier.padding(horizontal = 8.dp)
132 | )
133 |
134 | DetailScreenBottomBarIcons(onSaveClick = onSaveClick, onDeleteClick = onDeleteClick)
135 | }
136 | }
137 | )
138 | }
139 |
140 | @Composable
141 | fun DetailScreenBottomBarIcons(
142 | onSaveClick: () -> Unit,
143 | onDeleteClick: () -> Unit,
144 | ) {
145 | Row(horizontalArrangement = Arrangement.End) {
146 | IconButton(onClick = onSaveClick) {
147 | Icon(
148 | painterResource(id = R.drawable.ic_check),
149 | contentDescription = stringResource(id = R.string.app_name),
150 | )
151 | }
152 | IconButton(onClick = onDeleteClick) {
153 | Icon(
154 | painterResource(id = R.drawable.ic_trash),
155 | contentDescription = stringResource(id = R.string.app_name),
156 | )
157 | }
158 | }
159 | }
160 |
161 | @Composable
162 | fun DetailScreenBody(
163 | noteContent: String,
164 | onNoteContentChange: (String) -> Unit,
165 | ) {
166 | Column {
167 | Spacer(modifier = Modifier.height(8.dp))
168 | BasicTextField(
169 | value = noteContent,
170 | onValueChange = onNoteContentChange,
171 | textStyle = MaterialTheme.typography.subtitle1,
172 | modifier = Modifier
173 | .weight(weight = 1f, fill = true)
174 | .fillMaxSize()
175 | .padding(14.dp, 3.dp, 14.dp, 50.dp)
176 | )
177 | }
178 | }
--------------------------------------------------------------------------------
/app/src/main/java/co/icanteach/apps/android/composenotes/detail/DetailViewModel.kt:
--------------------------------------------------------------------------------
1 | package co.icanteach.apps.android.composenotes.detail
2 |
3 | import androidx.compose.runtime.State
4 | import androidx.compose.runtime.mutableStateOf
5 | import androidx.lifecycle.SavedStateHandle
6 | import androidx.lifecycle.ViewModel
7 | import androidx.lifecycle.viewModelScope
8 | import co.icanteach.apps.android.composenotes.data.ColorGenerator
9 | import co.icanteach.apps.android.composenotes.data.Note
10 | import co.icanteach.apps.android.composenotes.detail.domain.CreateNoteUseCase
11 | import co.icanteach.apps.android.composenotes.detail.domain.DeleteNoteUseCase
12 | import co.icanteach.apps.android.composenotes.detail.domain.GetNoteUseCase
13 | import dagger.hilt.android.lifecycle.HiltViewModel
14 | import kotlinx.coroutines.channels.Channel
15 | import kotlinx.coroutines.flow.MutableSharedFlow
16 | import kotlinx.coroutines.flow.asSharedFlow
17 | import kotlinx.coroutines.flow.receiveAsFlow
18 | import kotlinx.coroutines.launch
19 | import java.lang.IllegalStateException
20 | import javax.inject.Inject
21 |
22 | @HiltViewModel
23 | class DetailViewModel @Inject constructor(
24 | private val createNoteUseCase: CreateNoteUseCase,
25 | private val getNoteUseCase: GetNoteUseCase,
26 | private val deleteNoteUseCase: DeleteNoteUseCase,
27 | savedStateHandle: SavedStateHandle,
28 | ) : ViewModel() {
29 |
30 | private val _pageState = mutableStateOf(DetailPageViewState(note = Note.Default))
31 | private val _eventFlow = Channel(Channel.BUFFERED)
32 | val eventFlow = _eventFlow.receiveAsFlow()
33 | val pageState: State = _pageState
34 |
35 | init {
36 | savedStateHandle.get("noteId")?.let { noteId ->
37 | getNote(noteId)
38 | }
39 | }
40 |
41 | private fun getNote(noteId: Int) {
42 | viewModelScope.launch {
43 | val result = getNoteUseCase.getNote(noteId)
44 | _pageState.value = pageState.value.copy(note = result)
45 | }
46 | }
47 |
48 | fun onEvent(event: DetailPageEvent) {
49 | when (event) {
50 |
51 | is DetailPageEvent.EnteredContent -> {
52 | val oldNote = pageState.value.note
53 | _pageState.value = pageState.value.copy(
54 | note = oldNote.copy(content = event.value)
55 | )
56 | }
57 | is DetailPageEvent.ChangeContentFocus -> {
58 | }
59 |
60 | is DetailPageEvent.SaveNote -> {
61 | saveNote()
62 | }
63 |
64 | is DetailPageEvent.DeleteNote -> {
65 | deleteNote()
66 | }
67 | }
68 | }
69 |
70 | private fun deleteNote() {
71 | viewModelScope.launch {
72 | try {
73 | deleteNoteUseCase.deleteNote(note = pageState.value.note)
74 | _eventFlow.send(UiEvent.ClosePage)
75 | } catch (e: Exception) {
76 | _eventFlow.send(
77 | UiEvent.ShowError(
78 | message = e.message ?: "Couldn't save note"
79 | )
80 | )
81 | }
82 | }
83 | }
84 |
85 | private fun saveNote() {
86 | viewModelScope.launch {
87 | try {
88 | createNoteUseCase.createNote(
89 | note = pageState.value.note.copy(
90 | content = pageState.value.note.content,
91 | timestamp = System.currentTimeMillis(),
92 | color = ColorGenerator.getColor()
93 | )
94 | )
95 | _eventFlow.send(UiEvent.ClosePage)
96 | } catch (e: Exception) {
97 | }
98 | }
99 | }
100 |
101 | sealed class UiEvent {
102 | data class ShowError(val message: String) : UiEvent()
103 | object ClosePage : UiEvent()
104 | }
105 | }
106 |
--------------------------------------------------------------------------------
/app/src/main/java/co/icanteach/apps/android/composenotes/detail/domain/CreateNoteUseCase.kt:
--------------------------------------------------------------------------------
1 | package co.icanteach.apps.android.composenotes.detail.domain
2 |
3 | import co.icanteach.apps.android.composenotes.data.Note
4 | import co.icanteach.apps.android.composenotes.data.NoteMapper
5 | import co.icanteach.apps.android.composenotes.data.NoteRepository
6 | import java.lang.Exception
7 | import javax.inject.Inject
8 |
9 | class CreateNoteUseCase @Inject constructor(
10 | private val repository: NoteRepository,
11 | private val mapper: NoteMapper,
12 | ) {
13 |
14 | suspend fun createNote(note: Note) {
15 | if (note.content.isBlank()) {
16 | throw IllegalNoteException()
17 | }
18 | repository.insertNote(mapper.map(note = note))
19 | }
20 | }
21 |
22 | class IllegalNoteException : Exception()
--------------------------------------------------------------------------------
/app/src/main/java/co/icanteach/apps/android/composenotes/detail/domain/DeleteNoteUseCase.kt:
--------------------------------------------------------------------------------
1 | package co.icanteach.apps.android.composenotes.detail.domain
2 |
3 | import co.icanteach.apps.android.composenotes.data.Note
4 | import co.icanteach.apps.android.composenotes.data.NoteRepository
5 | import javax.inject.Inject
6 |
7 | class DeleteNoteUseCase @Inject constructor(
8 | private val repository: NoteRepository
9 | ) {
10 |
11 | suspend fun deleteNote(note: Note) {
12 | repository.deleteNote(note.id)
13 | }
14 | }
--------------------------------------------------------------------------------
/app/src/main/java/co/icanteach/apps/android/composenotes/detail/domain/GetNoteUseCase.kt:
--------------------------------------------------------------------------------
1 | package co.icanteach.apps.android.composenotes.detail.domain
2 |
3 | import co.icanteach.apps.android.composenotes.data.Note
4 | import co.icanteach.apps.android.composenotes.data.NoteMapper
5 | import co.icanteach.apps.android.composenotes.data.NoteRepository
6 | import javax.inject.Inject
7 |
8 | class GetNoteUseCase @Inject constructor(
9 | private val repository: NoteRepository,
10 | private val mapper: NoteMapper,
11 | ) {
12 |
13 | suspend fun getNote(id: Int): Note {
14 | val result = repository.getNoteById(id)
15 | return mapper.map(result ?: mapper.map(Note.Default))
16 | }
17 | }
--------------------------------------------------------------------------------
/app/src/main/java/co/icanteach/apps/android/composenotes/home/HomePageViewState.kt:
--------------------------------------------------------------------------------
1 | package co.icanteach.apps.android.composenotes.home
2 |
3 | import co.icanteach.apps.android.composenotes.data.Note
4 |
5 | data class HomePageViewState(
6 | val notes: List = emptyList(),
7 | )
--------------------------------------------------------------------------------
/app/src/main/java/co/icanteach/apps/android/composenotes/home/HomeScreen.kt:
--------------------------------------------------------------------------------
1 | package co.icanteach.apps.android.composenotes.home
2 |
3 | import androidx.compose.foundation.clickable
4 | import androidx.compose.foundation.layout.Column
5 | import androidx.compose.foundation.layout.Spacer
6 | import androidx.compose.foundation.layout.fillMaxWidth
7 | import androidx.compose.foundation.layout.height
8 | import androidx.compose.foundation.layout.padding
9 | import androidx.compose.foundation.lazy.LazyColumn
10 | import androidx.compose.foundation.shape.RoundedCornerShape
11 | import androidx.compose.material.ExtendedFloatingActionButton
12 | import androidx.compose.material.Icon
13 | import androidx.compose.material.MaterialTheme
14 | import androidx.compose.material.Scaffold
15 | import androidx.compose.material.Surface
16 | import androidx.compose.material.Text
17 | import androidx.compose.material.TopAppBar
18 | import androidx.compose.material.icons.Icons
19 | import androidx.compose.material.icons.filled.Add
20 | import androidx.compose.runtime.Composable
21 | import androidx.compose.ui.Modifier
22 | import androidx.compose.ui.draw.clip
23 | import androidx.compose.ui.graphics.Color
24 | import androidx.compose.ui.res.colorResource
25 | import androidx.compose.ui.res.stringResource
26 | import androidx.compose.ui.unit.dp
27 | import androidx.hilt.navigation.compose.hiltViewModel
28 | import androidx.navigation.NavController
29 | import co.icanteach.apps.android.composenotes.R
30 | import co.icanteach.apps.android.composenotes.Screens
31 | import co.icanteach.apps.android.composenotes.data.Note
32 | import co.icanteach.apps.android.composenotes.util.DateFormatter
33 |
34 |
35 | @Composable
36 | fun HomeScreen(
37 | viewModel: HomeViewModel = hiltViewModel(),
38 | navController: NavController,
39 | ) {
40 |
41 | val notesState = viewModel.pageState.value
42 |
43 | Scaffold(
44 | topBar = {
45 | TopAppBar(title = { Text(stringResource(id = R.string.app_name)) },
46 | backgroundColor = MaterialTheme.colors.primary)
47 | },
48 | floatingActionButton = {
49 | ExtendedFloatingActionButton(
50 | text =
51 | { Text(text = "NEW NOTE") },
52 | icon = { Icon(Icons.Filled.Add, "") },
53 | onClick = {
54 | navController.navigate(Screens.DetailScreen.route)
55 | })
56 | }
57 | ) {
58 | LazyColumn(content = {
59 | item {
60 | StaggeredVerticalGrid(
61 | modifier = Modifier.padding(vertical = 8.dp, horizontal = 4.dp),
62 | maxColumnWidth = 280.dp,
63 | ) {
64 | notesState.notes.forEachIndexed { index, keepNote ->
65 | NoteListItem(
66 | note = keepNote,
67 | onNoteClicked = { noteId ->
68 | navController.navigate(
69 | Screens.DetailScreen.route +
70 | "?noteId=${noteId}"
71 | )
72 | }
73 | )
74 | }
75 | }
76 | }
77 | })
78 | }
79 | }
80 |
81 | @Composable
82 | fun NoteListItem(
83 | note: Note,
84 | onNoteClicked: (Int?) -> Unit,
85 | ) {
86 | val shape = RoundedCornerShape(12.dp)
87 | Surface(
88 | shape = shape,
89 | color = colorResource(
90 | id = note.color
91 | ),
92 | elevation = 0.dp,
93 | modifier = Modifier
94 | .padding(bottom = 8.dp, end = 4.dp, start = 4.dp)
95 | .clip(shape)
96 | .clickable {
97 | onNoteClicked(note.id)
98 | }
99 | ) {
100 | Column(
101 | modifier = Modifier
102 | .fillMaxWidth()
103 | .padding(16.dp),
104 | ) {
105 |
106 | Text(
107 | text = note.content,
108 | style = MaterialTheme.typography.body2,
109 | )
110 |
111 | val lastUpdatedText =
112 | stringResource(R.string.last_updated_date_desc,
113 | DateFormatter.getFormattedDate(note.timestamp,
114 | DateFormatter.Format.ONLY_DAY_FORMAT))
115 |
116 | Spacer(modifier = Modifier.height(8.dp))
117 | Text(
118 | text = lastUpdatedText,
119 | style = MaterialTheme.typography.caption,
120 | modifier = Modifier.padding(bottom = 8.dp),
121 | color = Color.Gray
122 | )
123 | }
124 | }
125 | }
--------------------------------------------------------------------------------
/app/src/main/java/co/icanteach/apps/android/composenotes/home/HomeViewModel.kt:
--------------------------------------------------------------------------------
1 | package co.icanteach.apps.android.composenotes.home
2 |
3 | import androidx.compose.runtime.State
4 | import androidx.compose.runtime.mutableStateOf
5 | import androidx.lifecycle.ViewModel
6 | import androidx.lifecycle.viewModelScope
7 | import co.icanteach.apps.android.composenotes.home.domain.FetchHomePageContentUseCase
8 | import dagger.hilt.android.lifecycle.HiltViewModel
9 | import kotlinx.coroutines.flow.launchIn
10 | import kotlinx.coroutines.flow.onEach
11 | import javax.inject.Inject
12 |
13 | @HiltViewModel
14 | class HomeViewModel @Inject constructor(
15 | private val getNotesUseCase: FetchHomePageContentUseCase,
16 | ) : ViewModel() {
17 |
18 | private val _pageState = mutableStateOf(HomePageViewState())
19 | val pageState: State = _pageState
20 |
21 |
22 | init {
23 | getNotes()
24 | }
25 |
26 | private fun getNotes() {
27 | getNotesUseCase.getNotes()
28 | .onEach { notes ->
29 | _pageState.value = pageState.value.copy(
30 | notes = notes
31 | )
32 | }
33 | .launchIn(viewModelScope)
34 | }
35 | }
--------------------------------------------------------------------------------
/app/src/main/java/co/icanteach/apps/android/composenotes/home/StaggeredVerticalGrid.kt:
--------------------------------------------------------------------------------
1 | package co.icanteach.apps.android.composenotes.home
2 |
3 | import androidx.compose.runtime.Composable
4 | import androidx.compose.ui.Modifier
5 | import androidx.compose.ui.layout.Layout
6 | import androidx.compose.ui.layout.Placeable
7 | import androidx.compose.ui.unit.Dp
8 | import kotlin.math.ceil
9 |
10 | /*
11 | * Taken from a android compose sample application.
12 | * All compose samples can be found here:
13 | * https://github.com/android/compose-samples
14 | * */
15 |
16 | @Composable
17 | fun StaggeredVerticalGrid(
18 | modifier: Modifier = Modifier,
19 | maxColumnWidth: Dp,
20 | content: @Composable () -> Unit
21 | ) {
22 | Layout(
23 | content = content,
24 | modifier = modifier
25 | ) { measurables, constraints ->
26 | val placeableXY: MutableMap> = mutableMapOf()
27 |
28 | check(constraints.hasBoundedWidth) {
29 | "Unbounded width not supported"
30 | }
31 | val columns = ceil(constraints.maxWidth / maxColumnWidth.toPx()).toInt()
32 | val columnWidth = constraints.maxWidth / columns
33 | val itemConstraints = constraints.copy(maxWidth = columnWidth)
34 | val colHeights = IntArray(columns) { 0 } // track each column's height
35 | val placeables = measurables.map { measurable ->
36 | val column = shortestColumn(colHeights)
37 | val placeable = measurable.measure(itemConstraints)
38 | placeableXY[placeable] = Pair(columnWidth * column, colHeights[column])
39 | colHeights[column] += placeable.height
40 | placeable
41 | }
42 |
43 | val height = colHeights.maxOrNull()
44 | ?.coerceIn(constraints.minHeight, constraints.maxHeight)
45 | ?: constraints.minHeight
46 | layout(
47 | width = constraints.maxWidth,
48 | height = height
49 | ) {
50 | placeables.forEach { placeable ->
51 | placeable.place(
52 | x = placeableXY.getValue(placeable).first,
53 | y = placeableXY.getValue(placeable).second
54 | )
55 | }
56 | }
57 | }
58 | }
59 |
60 | private fun shortestColumn(colHeights: IntArray): Int {
61 | var minHeight = Int.MAX_VALUE
62 | var column = 0
63 | colHeights.forEachIndexed { index, height ->
64 | if (height < minHeight) {
65 | minHeight = height
66 | column = index
67 | }
68 | }
69 | return column
70 | }
--------------------------------------------------------------------------------
/app/src/main/java/co/icanteach/apps/android/composenotes/home/domain/FetchHomePageContentUseCase.kt:
--------------------------------------------------------------------------------
1 | package co.icanteach.apps.android.composenotes.home.domain
2 |
3 | import co.icanteach.apps.android.composenotes.data.Note
4 | import co.icanteach.apps.android.composenotes.data.NoteMapper
5 | import co.icanteach.apps.android.composenotes.data.NoteRepository
6 | import kotlinx.coroutines.flow.Flow
7 | import kotlinx.coroutines.flow.map
8 | import java.util.*
9 | import javax.inject.Inject
10 |
11 | class FetchHomePageContentUseCase @Inject constructor(
12 | private val repository: NoteRepository,
13 | private val mapper: NoteMapper,
14 | ) {
15 |
16 | fun getNotes(
17 | ): Flow> {
18 | return repository.getNotes().map { notes ->
19 | mapper.map(notes)
20 | }
21 | }
22 | }
--------------------------------------------------------------------------------
/app/src/main/java/co/icanteach/apps/android/composenotes/ui/theme/Color.kt:
--------------------------------------------------------------------------------
1 | package co.icanteach.apps.android.composenotes.ui.theme
2 |
3 | import androidx.compose.ui.graphics.Color
4 |
5 | val Purple200 = Color(0xFFBB86FC)
6 | val Purple500 = Color(0xFF6200EE)
7 | val Purple700 = Color(0xFF3700B3)
8 | val Teal200 = Color(0xFF03DAC5)
9 | val white = Color(0xFFFFFFFF)
10 | val blueBGNight = Color(0xFF0C1B3A)
11 | val blueText = Color(0xFF1E3054)
12 | val pinkText = Color(0xFFF5CAC9)
13 | val card = Color(0xFFFFFFFF)
14 | val cardNight = Color(0xFF162544)
15 |
16 | val RedOrange = Color(0xffffab91)
17 | val RedPink = Color(0xfff48fb1)
18 | val BabyBlue = Color(0xff81deea)
19 | val Violet = Color(0xffcf94da)
20 | val LightGreen = Color(0xffe7ed9b)
--------------------------------------------------------------------------------
/app/src/main/java/co/icanteach/apps/android/composenotes/ui/theme/Shape.kt:
--------------------------------------------------------------------------------
1 | package co.icanteach.apps.android.composenotes.ui.theme
2 |
3 | import androidx.compose.foundation.shape.RoundedCornerShape
4 | import androidx.compose.material.Shapes
5 | import androidx.compose.ui.unit.dp
6 |
7 | val shapes = Shapes(
8 | small = RoundedCornerShape(4.dp),
9 | medium = RoundedCornerShape(4.dp),
10 | large = RoundedCornerShape(0.dp)
11 | )
--------------------------------------------------------------------------------
/app/src/main/java/co/icanteach/apps/android/composenotes/ui/theme/Theme.kt:
--------------------------------------------------------------------------------
1 | package co.icanteach.apps.android.composenotes.ui.theme
2 |
3 | import androidx.compose.foundation.isSystemInDarkTheme
4 | import androidx.compose.material.MaterialTheme
5 | import androidx.compose.material.darkColors
6 | import androidx.compose.material.lightColors
7 | import androidx.compose.runtime.Composable
8 |
9 | private val DarkColorPalette = darkColors(
10 | primary = Purple200,
11 | primaryVariant = Purple700,
12 | secondary = Teal200,
13 | background = blueBGNight,
14 | surface = pinkText,
15 | onSurface = cardNight
16 | )
17 |
18 | private val LightColorPalette = lightColors(
19 | primary = Purple500,
20 | primaryVariant = Purple700,
21 | secondary = Teal200,
22 | background = white,
23 | surface = blueText,
24 | onSurface = card
25 |
26 | /* Other default colors to override
27 | background = Color.White,
28 | surface = Color.White,
29 | onPrimary = Color.White,
30 | onSecondary = Color.Black,
31 | onBackground = Color.Black,
32 | onSurface = Color.Black,
33 | */
34 | )
35 |
36 | @Composable
37 | fun ComposeNotesTheme(darkTheme: Boolean = isSystemInDarkTheme(), content: @Composable() () -> Unit) {
38 | val colors = if (darkTheme) {
39 | DarkColorPalette
40 | } else {
41 | LightColorPalette
42 | }
43 |
44 | MaterialTheme(
45 | colors = colors,
46 | typography = typography,
47 | shapes = shapes,
48 | content = content
49 | )
50 | }
--------------------------------------------------------------------------------
/app/src/main/java/co/icanteach/apps/android/composenotes/ui/theme/Type.kt:
--------------------------------------------------------------------------------
1 | package co.icanteach.apps.android.composenotes.ui.theme
2 |
3 | import androidx.compose.material.Typography
4 | import androidx.compose.ui.text.TextStyle
5 | import androidx.compose.ui.text.font.Font
6 | import androidx.compose.ui.text.font.FontFamily
7 | import androidx.compose.ui.text.font.FontWeight
8 | import androidx.compose.ui.unit.sp
9 | import co.icanteach.apps.android.composenotes.R
10 |
11 | // Set of Material typography styles to start with
12 |
13 | private val Sailec = FontFamily(
14 | Font(R.font.sailec_regular),
15 | Font(R.font.sailec_medium, FontWeight.W500),
16 | Font(R.font.sailec_bold, FontWeight.Bold)
17 | )
18 |
19 | // Set of Material typography styles to start with
20 | val typography = Typography(
21 | h4 = TextStyle(
22 | fontFamily = Sailec,
23 | fontWeight = FontWeight.W600,
24 | fontSize = 30.sp
25 | ),
26 | h5 = TextStyle(
27 | fontFamily = Sailec,
28 | fontWeight = FontWeight.W600,
29 | fontSize = 24.sp
30 | ),
31 | h6 = TextStyle(
32 | fontFamily = Sailec,
33 | fontWeight = FontWeight.W600,
34 | fontSize = 20.sp
35 | ),
36 | subtitle1 = TextStyle(
37 | fontFamily = Sailec,
38 | fontWeight = FontWeight.W500,
39 | fontSize = 16.sp
40 | ),
41 | subtitle2 = TextStyle(
42 | fontFamily = Sailec,
43 | fontWeight = FontWeight.W500,
44 | fontSize = 14.sp
45 | ),
46 | body1 = TextStyle(
47 | fontFamily = Sailec,
48 | fontWeight = FontWeight.Normal,
49 | fontSize = 16.sp
50 | ),
51 | body2 = TextStyle(
52 | fontFamily = Sailec,
53 | fontSize = 14.sp,
54 | lineHeight = 20.sp
55 | ),
56 | button = TextStyle(
57 | fontFamily = Sailec,
58 | fontWeight = FontWeight.W500,
59 | fontSize = 14.sp
60 | ),
61 | caption = TextStyle(
62 | fontFamily = Sailec,
63 | fontWeight = FontWeight.Normal,
64 | fontSize = 12.sp
65 | ),
66 | overline = TextStyle(
67 | fontFamily = Sailec,
68 | fontWeight = FontWeight.W500,
69 | fontSize = 12.sp
70 |
71 | )
72 | )
--------------------------------------------------------------------------------
/app/src/main/java/co/icanteach/apps/android/composenotes/util/DateFormatter.kt:
--------------------------------------------------------------------------------
1 | package co.icanteach.apps.android.composenotes.util
2 |
3 | import java.text.SimpleDateFormat
4 | import java.util.*
5 |
6 | object DateFormatter {
7 |
8 | fun getFormattedDate(timeStamp: Long, dateFormat: Format): String {
9 | val sdf = SimpleDateFormat(dateFormat.format, Locale.getDefault())
10 | val netDate = Date(timeStamp)
11 | return sdf.format(netDate)
12 | }
13 |
14 | enum class Format(val format: String) {
15 | DAY_HOUR_FORMAT("dd MMMM, HH:mm"),
16 | ONLY_DAY_FORMAT("dd MMMM")
17 | }
18 | }
--------------------------------------------------------------------------------
/app/src/main/res/drawable-v24/ic_launcher_foreground.xml:
--------------------------------------------------------------------------------
1 |
7 |
8 |
9 |
15 |
18 |
21 |
22 |
23 |
24 |
30 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_back.xml:
--------------------------------------------------------------------------------
1 |
6 |
13 |
20 |
21 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_check.xml:
--------------------------------------------------------------------------------
1 |
6 |
13 |
14 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_launcher_background.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
10 |
15 |
20 |
25 |
30 |
35 |
40 |
45 |
50 |
55 |
60 |
65 |
70 |
75 |
80 |
85 |
90 |
95 |
100 |
105 |
110 |
115 |
120 |
125 |
130 |
135 |
140 |
145 |
150 |
155 |
160 |
165 |
170 |
171 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_trash.xml:
--------------------------------------------------------------------------------
1 |
6 |
13 |
20 |
27 |
34 |
35 |
--------------------------------------------------------------------------------
/app/src/main/res/font/sailec_bold.otf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/androidsamples-page/ComposeNotes/de1e2c11d8c30db79ef180c091fcc42a104aabce/app/src/main/res/font/sailec_bold.otf
--------------------------------------------------------------------------------
/app/src/main/res/font/sailec_medium.otf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/androidsamples-page/ComposeNotes/de1e2c11d8c30db79ef180c091fcc42a104aabce/app/src/main/res/font/sailec_medium.otf
--------------------------------------------------------------------------------
/app/src/main/res/font/sailec_regular.otf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/androidsamples-page/ComposeNotes/de1e2c11d8c30db79ef180c091fcc42a104aabce/app/src/main/res/font/sailec_regular.otf
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher.webp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/androidsamples-page/ComposeNotes/de1e2c11d8c30db79ef180c091fcc42a104aabce/app/src/main/res/mipmap-hdpi/ic_launcher.webp
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher_round.webp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/androidsamples-page/ComposeNotes/de1e2c11d8c30db79ef180c091fcc42a104aabce/app/src/main/res/mipmap-hdpi/ic_launcher_round.webp
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher.webp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/androidsamples-page/ComposeNotes/de1e2c11d8c30db79ef180c091fcc42a104aabce/app/src/main/res/mipmap-mdpi/ic_launcher.webp
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher_round.webp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/androidsamples-page/ComposeNotes/de1e2c11d8c30db79ef180c091fcc42a104aabce/app/src/main/res/mipmap-mdpi/ic_launcher_round.webp
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher.webp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/androidsamples-page/ComposeNotes/de1e2c11d8c30db79ef180c091fcc42a104aabce/app/src/main/res/mipmap-xhdpi/ic_launcher.webp
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher_round.webp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/androidsamples-page/ComposeNotes/de1e2c11d8c30db79ef180c091fcc42a104aabce/app/src/main/res/mipmap-xhdpi/ic_launcher_round.webp
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher.webp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/androidsamples-page/ComposeNotes/de1e2c11d8c30db79ef180c091fcc42a104aabce/app/src/main/res/mipmap-xxhdpi/ic_launcher.webp
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.webp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/androidsamples-page/ComposeNotes/de1e2c11d8c30db79ef180c091fcc42a104aabce/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.webp
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher.webp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/androidsamples-page/ComposeNotes/de1e2c11d8c30db79ef180c091fcc42a104aabce/app/src/main/res/mipmap-xxxhdpi/ic_launcher.webp
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.webp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/androidsamples-page/ComposeNotes/de1e2c11d8c30db79ef180c091fcc42a104aabce/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.webp
--------------------------------------------------------------------------------
/app/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #FFBB86FC
4 | #FF6200EE
5 | #FF3700B3
6 | #FF03DAC5
7 | #FF018786
8 | #FF000000
9 | #FFFFFFFF
10 |
11 | #F28B82
12 | #FBBC05
13 | #FFF475
14 | #CCFF90
15 | #A7FFEB
16 | #CBF0F8
17 | #AECBFA
18 | #D7AEFB
19 | #FDCFE8
20 | #E6C9A8
21 | #E8EAED
22 |
--------------------------------------------------------------------------------
/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | Compose Notes
3 | Enter some content
4 | Last updated : %s
5 |
--------------------------------------------------------------------------------
/app/src/main/res/values/themes.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
7 |
--------------------------------------------------------------------------------
/app/src/test/java/co/icanteach/apps/android/composenotes/FakeRepository.kt:
--------------------------------------------------------------------------------
1 | package co.icanteach.apps.android.composenotes
2 |
3 | import co.icanteach.apps.android.composenotes.data.NoteEntity
4 | import co.icanteach.apps.android.composenotes.data.NoteRepository
5 | import kotlinx.coroutines.flow.Flow
6 | import kotlinx.coroutines.flow.flow
7 |
8 | class FakeRepository : NoteRepository {
9 | override fun getNotes(): Flow> {
10 | return flow {
11 | emit(emptyList())
12 | }
13 | }
14 |
15 | override suspend fun getNoteById(id: Int): NoteEntity {
16 | return NoteEntity.Default
17 | }
18 |
19 | override suspend fun insertNote(note: NoteEntity) {
20 | //
21 | }
22 |
23 | override suspend fun deleteNote(id: Int?) {
24 | //
25 | }
26 | }
--------------------------------------------------------------------------------
/app/src/test/java/co/icanteach/apps/android/composenotes/TestCoroutineRule.kt:
--------------------------------------------------------------------------------
1 | package co.icanteach.apps.android.composenotes
2 |
3 | import kotlinx.coroutines.Dispatchers
4 | import kotlinx.coroutines.ExperimentalCoroutinesApi
5 | import kotlinx.coroutines.test.TestCoroutineDispatcher
6 | import kotlinx.coroutines.test.TestCoroutineScope
7 | import kotlinx.coroutines.test.resetMain
8 | import kotlinx.coroutines.test.runBlockingTest
9 | import kotlinx.coroutines.test.setMain
10 | import org.junit.rules.TestWatcher
11 | import org.junit.runner.Description
12 |
13 | class TestCoroutineRule @OptIn(ExperimentalCoroutinesApi::class) constructor(
14 | private val testDispatcher: TestCoroutineDispatcher = TestCoroutineDispatcher(),
15 | ) : TestWatcher() {
16 |
17 | @OptIn(ExperimentalCoroutinesApi::class)
18 | override fun starting(description: Description?) {
19 | super.starting(description)
20 | Dispatchers.setMain(testDispatcher)
21 | }
22 |
23 | @OptIn(ExperimentalCoroutinesApi::class)
24 | override fun finished(description: Description?) {
25 | super.finished(description)
26 | Dispatchers.resetMain()
27 | testDispatcher.cleanupTestCoroutines()
28 | }
29 |
30 | @OptIn(ExperimentalCoroutinesApi::class)
31 | fun runBlockingTest(block: suspend TestCoroutineScope.() -> Unit) =
32 | testDispatcher.runBlockingTest(block)
33 | }
--------------------------------------------------------------------------------
/app/src/test/java/co/icanteach/apps/android/composenotes/detail/domain/CreateNoteUseCaseTest.kt:
--------------------------------------------------------------------------------
1 | package co.icanteach.apps.android.composenotes.detail.domain
2 |
3 | import co.icanteach.apps.android.composenotes.data.ColorGenerator
4 | import co.icanteach.apps.android.composenotes.data.Note
5 | import co.icanteach.apps.android.composenotes.data.NoteMapper
6 | import co.icanteach.apps.android.composenotes.data.NoteRepositoryImpl
7 | import io.mockk.MockKAnnotations
8 | import io.mockk.coEvery
9 | import io.mockk.coVerify
10 | import io.mockk.impl.annotations.MockK
11 | import io.mockk.just
12 | import io.mockk.runs
13 | import kotlinx.coroutines.ExperimentalCoroutinesApi
14 | import kotlinx.coroutines.test.runTest
15 | import org.junit.Before
16 | import org.junit.Test
17 |
18 | @ExperimentalCoroutinesApi
19 | class CreateNoteUseCaseTest {
20 |
21 |
22 | private lateinit var useCase: CreateNoteUseCase
23 |
24 | @MockK
25 | lateinit var repository: NoteRepositoryImpl
26 |
27 | @Before
28 | fun setUp() {
29 | MockKAnnotations.init(this)
30 | useCase = CreateNoteUseCase(repository, NoteMapper())
31 |
32 | }
33 |
34 | @Test(expected = IllegalNoteException::class)
35 | fun `given blank content, should throw IllegalNoteException`() {
36 | runTest {
37 | // Given
38 | val givenNote =
39 | Note(color = ColorGenerator.getColor(), content = "", timestamp = 12312312312L)
40 |
41 | // When
42 | useCase.createNote(givenNote)
43 | }
44 | }
45 |
46 | @Test(expected = IllegalNoteException::class)
47 | fun `given blank content, should not call NoteRepository`() = runTest {
48 |
49 | // Given
50 | val givenNote =
51 | Note(color = ColorGenerator.getColor(), content = "", timestamp = 12312312312L)
52 |
53 | coEvery { repository.insertNote(any()) } just runs
54 |
55 | // When
56 | useCase.createNote(givenNote)
57 |
58 | coVerify(exactly = 0) { repository.insertNote(any()) }
59 | }
60 |
61 | @Test
62 | fun `given proper content, should call NoteRepository`() {
63 | runTest {
64 | // Given
65 | val givenNote =
66 | Note(color = ColorGenerator.getColor(),
67 | content = "Lorem Ipsum",
68 | timestamp = 12312312312L)
69 |
70 | coEvery { repository.insertNote(any()) } just runs
71 |
72 | // When
73 | useCase.createNote(givenNote)
74 |
75 |
76 | coVerify(exactly = 1) { repository.insertNote(any()) }
77 | }
78 | }
79 | }
--------------------------------------------------------------------------------
/app/src/test/java/co/icanteach/apps/android/composenotes/detail/domain/GetNoteUseCaseTest.kt:
--------------------------------------------------------------------------------
1 | package co.icanteach.apps.android.composenotes.detail.domain
2 |
3 | import co.icanteach.apps.android.composenotes.data.NoteMapper
4 | import co.icanteach.apps.android.composenotes.data.NoteRepositoryImpl
5 | import com.google.common.truth.Truth
6 | import io.mockk.MockKAnnotations
7 | import io.mockk.coEvery
8 | import io.mockk.impl.annotations.MockK
9 | import kotlinx.coroutines.ExperimentalCoroutinesApi
10 | import kotlinx.coroutines.test.runTest
11 | import org.junit.Before
12 | import org.junit.Test
13 |
14 |
15 | class GetNoteUseCaseTest {
16 |
17 | private lateinit var useCase: GetNoteUseCase
18 |
19 | @MockK
20 | lateinit var repository: NoteRepositoryImpl
21 |
22 | @Before
23 | fun setUp() {
24 | MockKAnnotations.init(this)
25 | useCase = GetNoteUseCase(repository = repository, mapper = NoteMapper())
26 |
27 | }
28 |
29 | @OptIn(ExperimentalCoroutinesApi::class)
30 | @Test
31 | fun `given no result from repository, then should return Default Note`() {
32 |
33 | runTest {
34 |
35 | // Given
36 | coEvery { repository.getNoteById(any()) } returns null
37 |
38 | // When
39 | val actualResult = useCase.getNote(10)
40 |
41 | // Then
42 | Truth.assertThat(actualResult.content).isEmpty()
43 |
44 | }
45 | }
46 | }
--------------------------------------------------------------------------------
/build.gradle:
--------------------------------------------------------------------------------
1 | buildscript {
2 | ext {
3 | compose_version = '1.0.1'
4 | }
5 |
6 | dependencies {
7 | classpath 'com.google.dagger:hilt-android-gradle-plugin:2.40'
8 | }
9 | }// Top-level build file where you can add configuration options common to all sub-projects/modules.
10 | plugins {
11 | id 'com.android.application' version '7.1.0' apply false
12 | id 'com.android.library' version '7.1.0' apply false
13 | id 'org.jetbrains.kotlin.android' version '1.5.21' apply false
14 | }
15 |
16 | task clean(type: Delete) {
17 | delete rootProject.buildDir
18 | }
--------------------------------------------------------------------------------
/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=-Xmx2048m -Dfile.encoding=UTF-8
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 | # AndroidX package structure to make it clearer which packages are bundled with the
15 | # Android operating system, and which are packaged with your app"s APK
16 | # https://developer.android.com/topic/libraries/support-library/androidx-rn
17 | android.useAndroidX=true
18 | # Kotlin code style for this project: "official" or "obsolete":
19 | kotlin.code.style=official
20 | # Enables namespacing of each library's R class so that its R class includes only the
21 | # resources declared in the library itself and none from the library's dependencies,
22 | # thereby reducing the size of the R class for that library
23 | android.nonTransitiveRClass=true
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/androidsamples-page/ComposeNotes/de1e2c11d8c30db79ef180c091fcc42a104aabce/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Mon Feb 28 18:20:10 TRT 2022
2 | distributionBase=GRADLE_USER_HOME
3 | distributionUrl=https\://services.gradle.org/distributions/gradle-7.2-bin.zip
4 | distributionPath=wrapper/dists
5 | zipStorePath=wrapper/dists
6 | zipStoreBase=GRADLE_USER_HOME
7 |
--------------------------------------------------------------------------------
/gradlew:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env sh
2 |
3 | #
4 | # Copyright 2015 the original author or authors.
5 | #
6 | # Licensed under the Apache License, Version 2.0 (the "License");
7 | # you may not use this file except in compliance with the License.
8 | # You may obtain a copy of the License at
9 | #
10 | # https://www.apache.org/licenses/LICENSE-2.0
11 | #
12 | # Unless required by applicable law or agreed to in writing, software
13 | # distributed under the License is distributed on an "AS IS" BASIS,
14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | # See the License for the specific language governing permissions and
16 | # limitations under the License.
17 | #
18 |
19 | ##############################################################################
20 | ##
21 | ## Gradle start up script for UN*X
22 | ##
23 | ##############################################################################
24 |
25 | # Attempt to set APP_HOME
26 | # Resolve links: $0 may be a link
27 | PRG="$0"
28 | # Need this for relative symlinks.
29 | while [ -h "$PRG" ] ; do
30 | ls=`ls -ld "$PRG"`
31 | link=`expr "$ls" : '.*-> \(.*\)$'`
32 | if expr "$link" : '/.*' > /dev/null; then
33 | PRG="$link"
34 | else
35 | PRG=`dirname "$PRG"`"/$link"
36 | fi
37 | done
38 | SAVED="`pwd`"
39 | cd "`dirname \"$PRG\"`/" >/dev/null
40 | APP_HOME="`pwd -P`"
41 | cd "$SAVED" >/dev/null
42 |
43 | APP_NAME="Gradle"
44 | APP_BASE_NAME=`basename "$0"`
45 |
46 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
47 | DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
48 |
49 | # Use the maximum available, or set MAX_FD != -1 to use that value.
50 | MAX_FD="maximum"
51 |
52 | warn () {
53 | echo "$*"
54 | }
55 |
56 | die () {
57 | echo
58 | echo "$*"
59 | echo
60 | exit 1
61 | }
62 |
63 | # OS specific support (must be 'true' or 'false').
64 | cygwin=false
65 | msys=false
66 | darwin=false
67 | nonstop=false
68 | case "`uname`" in
69 | CYGWIN* )
70 | cygwin=true
71 | ;;
72 | Darwin* )
73 | darwin=true
74 | ;;
75 | MINGW* )
76 | msys=true
77 | ;;
78 | NONSTOP* )
79 | nonstop=true
80 | ;;
81 | esac
82 |
83 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
84 |
85 |
86 | # Determine the Java command to use to start the JVM.
87 | if [ -n "$JAVA_HOME" ] ; then
88 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
89 | # IBM's JDK on AIX uses strange locations for the executables
90 | JAVACMD="$JAVA_HOME/jre/sh/java"
91 | else
92 | JAVACMD="$JAVA_HOME/bin/java"
93 | fi
94 | if [ ! -x "$JAVACMD" ] ; then
95 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
96 |
97 | Please set the JAVA_HOME variable in your environment to match the
98 | location of your Java installation."
99 | fi
100 | else
101 | JAVACMD="java"
102 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
103 |
104 | Please set the JAVA_HOME variable in your environment to match the
105 | location of your Java installation."
106 | fi
107 |
108 | # Increase the maximum file descriptors if we can.
109 | if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then
110 | MAX_FD_LIMIT=`ulimit -H -n`
111 | if [ $? -eq 0 ] ; then
112 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
113 | MAX_FD="$MAX_FD_LIMIT"
114 | fi
115 | ulimit -n $MAX_FD
116 | if [ $? -ne 0 ] ; then
117 | warn "Could not set maximum file descriptor limit: $MAX_FD"
118 | fi
119 | else
120 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
121 | fi
122 | fi
123 |
124 | # For Darwin, add options to specify how the application appears in the dock
125 | if $darwin; then
126 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
127 | fi
128 |
129 | # For Cygwin or MSYS, switch paths to Windows format before running java
130 | if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then
131 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
132 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
133 |
134 | JAVACMD=`cygpath --unix "$JAVACMD"`
135 |
136 | # We build the pattern for arguments to be converted via cygpath
137 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
138 | SEP=""
139 | for dir in $ROOTDIRSRAW ; do
140 | ROOTDIRS="$ROOTDIRS$SEP$dir"
141 | SEP="|"
142 | done
143 | OURCYGPATTERN="(^($ROOTDIRS))"
144 | # Add a user-defined pattern to the cygpath arguments
145 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
146 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
147 | fi
148 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
149 | i=0
150 | for arg in "$@" ; do
151 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
152 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
153 |
154 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
155 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
156 | else
157 | eval `echo args$i`="\"$arg\""
158 | fi
159 | i=`expr $i + 1`
160 | done
161 | case $i in
162 | 0) set -- ;;
163 | 1) set -- "$args0" ;;
164 | 2) set -- "$args0" "$args1" ;;
165 | 3) set -- "$args0" "$args1" "$args2" ;;
166 | 4) set -- "$args0" "$args1" "$args2" "$args3" ;;
167 | 5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
168 | 6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
169 | 7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
170 | 8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
171 | 9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
172 | esac
173 | fi
174 |
175 | # Escape application args
176 | save () {
177 | for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done
178 | echo " "
179 | }
180 | APP_ARGS=`save "$@"`
181 |
182 | # Collect all arguments for the java command, following the shell quoting and substitution rules
183 | eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS"
184 |
185 | exec "$JAVACMD" "$@"
186 |
--------------------------------------------------------------------------------
/gradlew.bat:
--------------------------------------------------------------------------------
1 | @rem
2 | @rem Copyright 2015 the original author or authors.
3 | @rem
4 | @rem Licensed under the Apache License, Version 2.0 (the "License");
5 | @rem you may not use this file except in compliance with the License.
6 | @rem You may obtain a copy of the License at
7 | @rem
8 | @rem https://www.apache.org/licenses/LICENSE-2.0
9 | @rem
10 | @rem Unless required by applicable law or agreed to in writing, software
11 | @rem distributed under the License is distributed on an "AS IS" BASIS,
12 | @rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | @rem See the License for the specific language governing permissions and
14 | @rem limitations under the License.
15 | @rem
16 |
17 | @if "%DEBUG%" == "" @echo off
18 | @rem ##########################################################################
19 | @rem
20 | @rem Gradle startup script for Windows
21 | @rem
22 | @rem ##########################################################################
23 |
24 | @rem Set local scope for the variables with windows NT shell
25 | if "%OS%"=="Windows_NT" setlocal
26 |
27 | set DIRNAME=%~dp0
28 | if "%DIRNAME%" == "" set DIRNAME=.
29 | set APP_BASE_NAME=%~n0
30 | set APP_HOME=%DIRNAME%
31 |
32 | @rem Resolve any "." and ".." in APP_HOME to make it shorter.
33 | for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi
34 |
35 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
36 | set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m"
37 |
38 | @rem Find java.exe
39 | if defined JAVA_HOME goto findJavaFromJavaHome
40 |
41 | set JAVA_EXE=java.exe
42 | %JAVA_EXE% -version >NUL 2>&1
43 | if "%ERRORLEVEL%" == "0" goto execute
44 |
45 | echo.
46 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
47 | echo.
48 | echo Please set the JAVA_HOME variable in your environment to match the
49 | echo location of your Java installation.
50 |
51 | goto fail
52 |
53 | :findJavaFromJavaHome
54 | set JAVA_HOME=%JAVA_HOME:"=%
55 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
56 |
57 | if exist "%JAVA_EXE%" goto execute
58 |
59 | echo.
60 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
61 | echo.
62 | echo Please set the JAVA_HOME variable in your environment to match the
63 | echo location of your Java installation.
64 |
65 | goto fail
66 |
67 | :execute
68 | @rem Setup the command line
69 |
70 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
71 |
72 |
73 | @rem Execute Gradle
74 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %*
75 |
76 | :end
77 | @rem End local scope for the variables with windows NT shell
78 | if "%ERRORLEVEL%"=="0" goto mainEnd
79 |
80 | :fail
81 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
82 | rem the _cmd.exe /c_ return code!
83 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
84 | exit /b 1
85 |
86 | :mainEnd
87 | if "%OS%"=="Windows_NT" endlocal
88 |
89 | :omega
90 |
--------------------------------------------------------------------------------
/screenshots/detail_page.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/androidsamples-page/ComposeNotes/de1e2c11d8c30db79ef180c091fcc42a104aabce/screenshots/detail_page.png
--------------------------------------------------------------------------------
/screenshots/home_page.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/androidsamples-page/ComposeNotes/de1e2c11d8c30db79ef180c091fcc42a104aabce/screenshots/home_page.png
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | pluginManagement {
2 | repositories {
3 | gradlePluginPortal()
4 | google()
5 | mavenCentral()
6 | }
7 | }
8 | dependencyResolutionManagement {
9 | repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
10 | repositories {
11 | google()
12 | mavenCentral()
13 | }
14 | }
15 | rootProject.name = "ComposeNotes"
16 | include ':app'
--------------------------------------------------------------------------------