├── .github └── FUNDING.yml ├── .gitignore ├── .idea ├── .gitignore ├── .name ├── codeStyles │ ├── Project.xml │ └── codeStyleConfig.xml ├── compiler.xml ├── gradle.xml ├── jarRepositories.xml ├── misc.xml ├── render.experimental.xml └── vcs.xml ├── LICENSE ├── README.md ├── app ├── .gitignore ├── build.gradle ├── proguard-rules.pro └── src │ ├── androidTest │ └── java │ │ └── com │ │ └── bersyte │ │ └── noteapp │ │ ├── ExampleInstrumentedTest.kt │ │ └── fragments │ │ └── HomeFragmentTest.kt │ ├── main │ ├── AndroidManifest.xml │ ├── java │ │ └── com │ │ │ └── bersyte │ │ │ └── noteapp │ │ │ ├── MainActivity.kt │ │ │ ├── adapter │ │ │ └── NoteAdapter.kt │ │ │ ├── db │ │ │ ├── NoteDao.kt │ │ │ └── NoteDatabase.kt │ │ │ ├── fragments │ │ │ ├── HomeFragment.kt │ │ │ ├── NewNoteFragment.kt │ │ │ └── UpdateNoteFragment.kt │ │ │ ├── helper │ │ │ └── ShowToast.kt │ │ │ ├── model │ │ │ └── Note.kt │ │ │ ├── repository │ │ │ └── NoteRepository.kt │ │ │ └── viewmodel │ │ │ ├── NoteViewModel.kt │ │ │ └── NoteViewModelProviderFactory.kt │ └── res │ │ ├── anim │ │ ├── slide_in_left.xml │ │ ├── slide_in_right.xml │ │ ├── slide_in_up.xml │ │ ├── slide_out_left.xml │ │ ├── slide_out_right.xml │ │ └── slide_out_up.xml │ │ ├── drawable-v24 │ │ └── ic_launcher_foreground.xml │ │ ├── drawable │ │ ├── ic_add.xml │ │ ├── ic_delete.xml │ │ ├── ic_done.xml │ │ ├── ic_launcher_background.xml │ │ └── ic_search_black_24dp.xml │ │ ├── layout │ │ ├── activity_main.xml │ │ ├── fragment_home.xml │ │ ├── fragment_new_note.xml │ │ ├── fragment_update_note.xml │ │ └── note_layout_adapter.xml │ │ ├── menu │ │ ├── home_menu.xml │ │ ├── menu_new_note.xml │ │ └── menu_update_note.xml │ │ ├── mipmap-anydpi-v26 │ │ ├── ic_launcher.xml │ │ └── ic_launcher_round.xml │ │ ├── mipmap-hdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ ├── mipmap-mdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ ├── mipmap-xhdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ ├── mipmap-xxhdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ ├── mipmap-xxxhdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ ├── navigation │ │ └── nav_graph.xml │ │ ├── values-night │ │ └── themes.xml │ │ └── values │ │ ├── colors.xml │ │ ├── strings.xml │ │ └── themes.xml │ └── test │ └── java │ └── com │ └── bersyte │ └── noteapp │ └── ExampleUnitTest.kt ├── build.gradle ├── gradle.properties ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat └── settings.gradle /.github/FUNDING.yml: -------------------------------------------------------------------------------- 1 | # These are supported funding model platforms 2 | 3 | github: # Replace with up to 4 GitHub Sponsors-enabled usernames e.g., [user1, user2] 4 | patreon: # Replace with a single Patreon username 5 | open_collective: # Replace with a single Open Collective username 6 | ko_fi: # Replace with a single Ko-fi username 7 | tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel 8 | community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry 9 | liberapay: # Replace with a single Liberapay username 10 | issuehunt: # Replace with a single IssueHunt username 11 | otechie: # Replace with a single Otechie username 12 | lfx_crowdfunding: # Replace with a single LFX Crowdfunding project-name e.g., cloud-foundry 13 | custom: https://paypal.me/cuvula # Replace with up to 4 custom sponsorship URLs e.g., ['link1', 'link2'] 14 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.iml 2 | .gradle 3 | /local.properties 4 | /.idea/caches 5 | /.idea/libraries 6 | /.idea/modules.xml 7 | /.idea/workspace.xml 8 | /.idea/navEditor.xml 9 | /.idea/assetWizardSettings.xml 10 | .DS_Store 11 | /build 12 | /captures 13 | .externalNativeBuild 14 | .cxx 15 | local.properties 16 | -------------------------------------------------------------------------------- /.idea/.gitignore: -------------------------------------------------------------------------------- 1 | # Default ignored files 2 | /shelf/ 3 | /workspace.xml 4 | -------------------------------------------------------------------------------- /.idea/.name: -------------------------------------------------------------------------------- 1 | Note App -------------------------------------------------------------------------------- /.idea/codeStyles/Project.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 11 | 20 | 22 | 23 | 135 | 136 | 138 | 139 | -------------------------------------------------------------------------------- /.idea/codeStyles/codeStyleConfig.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 5 | -------------------------------------------------------------------------------- /.idea/compiler.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /.idea/gradle.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 22 | 23 | -------------------------------------------------------------------------------- /.idea/jarRepositories.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 9 | 10 | 14 | 15 | 19 | 20 | 24 | 25 | -------------------------------------------------------------------------------- /.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 9 | -------------------------------------------------------------------------------- /.idea/render.experimental.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 6 | -------------------------------------------------------------------------------- /.idea/vcs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2023 Isaias Cuvula 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # mvvm_note_app_kotlin_android_studio 2 | This is a Simple but Complete Android Note App with clean architecture, MVVM, Room Database, Navigation Components, Safe Args, and Search View! 3 | 4 | Buy Me A Coffee 5 | 6 | ## MVVM Note App 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /app/.gitignore: -------------------------------------------------------------------------------- 1 | /build -------------------------------------------------------------------------------- /app/build.gradle: -------------------------------------------------------------------------------- 1 | plugins { 2 | id 'com.android.application' 3 | id 'kotlin-android' 4 | id 'kotlin-parcelize' 5 | id 'kotlin-kapt' 6 | id 'androidx.navigation.safeargs.kotlin' 7 | } 8 | 9 | android { 10 | compileSdkVersion 30 11 | buildToolsVersion "30.0.2" 12 | 13 | defaultConfig { 14 | applicationId "com.bersyte.noteapp" 15 | minSdkVersion 26 16 | targetSdkVersion 30 17 | versionCode 1 18 | versionName "1.0" 19 | 20 | testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" 21 | } 22 | buildFeatures{ 23 | viewBinding true 24 | } 25 | 26 | buildTypes { 27 | release { 28 | minifyEnabled false 29 | proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' 30 | } 31 | } 32 | compileOptions { 33 | sourceCompatibility JavaVersion.VERSION_1_8 34 | targetCompatibility JavaVersion.VERSION_1_8 35 | } 36 | kotlinOptions { 37 | jvmTarget = '1.8' 38 | } 39 | } 40 | 41 | dependencies { 42 | 43 | implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version" 44 | implementation 'androidx.core:core-ktx:1.3.2' 45 | implementation 'androidx.appcompat:appcompat:1.2.0' 46 | implementation 'com.google.android.material:material:1.3.0' 47 | implementation 'androidx.constraintlayout:constraintlayout:2.0.4' 48 | implementation 'androidx.legacy:legacy-support-v4:1.0.0' 49 | implementation 'androidx.navigation:navigation-fragment-ktx:2.3.4' 50 | implementation 'androidx.navigation:navigation-ui-ktx:2.3.4' 51 | testImplementation 'junit:junit:4.13.2' 52 | androidTestImplementation 'androidx.test.ext:junit:1.1.2' 53 | androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0' 54 | 55 | // Architectural Components 56 | implementation "androidx.lifecycle:lifecycle-viewmodel-ktx:2.3.1" 57 | implementation "androidx.lifecycle:lifecycle-runtime-ktx:2.3.1" 58 | implementation "androidx.lifecycle:lifecycle-livedata-ktx:2.3.1" 59 | 60 | // Room 61 | implementation "androidx.room:room-runtime:2.2.6" 62 | kapt "androidx.room:room-compiler:2.2.6" 63 | 64 | // Kotlin Extensions and Coroutines support for Room 65 | implementation "androidx.room:room-ktx:2.2.6" 66 | 67 | // Navigation Components 68 | implementation "androidx.navigation:navigation-fragment-ktx:2.3.4" 69 | implementation "androidx.navigation:navigation-ui-ktx:2.3.4" 70 | implementation "androidx.navigation:navigation-dynamic-features-fragment:2.3.4" 71 | 72 | // Espresso 73 | def androidx_test_espresso = "3.3.0" 74 | androidTestImplementation "androidx.test.espresso:espresso-core:$androidx_test_espresso" 75 | androidTestImplementation "androidx.test.espresso:espresso-contrib:$androidx_test_espresso" 76 | 77 | // Mockk.io 78 | def mockk_version = "1.9.3" 79 | androidTestImplementation "io.mockk:mockk-android:$mockk_version" 80 | 81 | // androidx.test 82 | def androidx_test = "1.1.2" 83 | androidTestImplementation "androidx.test:runner:$androidx_test" 84 | androidTestImplementation "androidx.test:core:$androidx_test" 85 | androidTestImplementation "androidx.test.ext:junit-ktx:$androidx_test" 86 | 87 | // androidx.fragment 88 | debugImplementation "androidx.fragment:fragment-testing:1.3.2" 89 | implementation "androidx.fragment:fragment-ktx:1.3.2" 90 | 91 | 92 | } -------------------------------------------------------------------------------- /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/com/bersyte/noteapp/ExampleInstrumentedTest.kt: -------------------------------------------------------------------------------- 1 | package com.bersyte.noteapp 2 | 3 | import androidx.test.platform.app.InstrumentationRegistry 4 | import androidx.test.ext.junit.runners.AndroidJUnit4 5 | 6 | import org.junit.Test 7 | import org.junit.runner.RunWith 8 | 9 | import org.junit.Assert.* 10 | 11 | /** 12 | * Instrumented test, which will execute on an Android device. 13 | * 14 | * See [testing documentation](http://d.android.com/tools/testing). 15 | */ 16 | @RunWith(AndroidJUnit4::class) 17 | class ExampleInstrumentedTest { 18 | @Test 19 | fun useAppContext() { 20 | // Context of the app under test. 21 | val appContext = InstrumentationRegistry.getInstrumentation().targetContext 22 | assertEquals("com.bersyte.noteapp", appContext.packageName) 23 | } 24 | } -------------------------------------------------------------------------------- /app/src/androidTest/java/com/bersyte/noteapp/fragments/HomeFragmentTest.kt: -------------------------------------------------------------------------------- 1 | package com.bersyte.noteapp.fragments 2 | 3 | import androidx.test.espresso.Espresso.onView 4 | import androidx.test.espresso.action.ViewActions 5 | import androidx.test.espresso.action.ViewActions.click 6 | import androidx.test.espresso.action.ViewActions.pressBack 7 | import androidx.test.espresso.assertion.ViewAssertions.matches 8 | import androidx.test.espresso.contrib.RecyclerViewActions.actionOnItemAtPosition 9 | import androidx.test.espresso.matcher.ViewMatchers.* 10 | import androidx.test.ext.junit.rules.ActivityScenarioRule 11 | import androidx.test.internal.runner.junit4.AndroidJUnit4ClassRunner 12 | import com.bersyte.noteapp.MainActivity 13 | import com.bersyte.noteapp.R 14 | import com.bersyte.noteapp.adapter.NoteAdapter.NoteViewHolder 15 | import org.junit.Rule 16 | import org.junit.Test 17 | import org.junit.runner.RunWith 18 | 19 | @RunWith(AndroidJUnit4ClassRunner::class) 20 | class HomeFragmentTest { 21 | 22 | @get: Rule 23 | val activityScenarioRule = ActivityScenarioRule(MainActivity::class.java) 24 | 25 | val LIST_ITEM = 0 26 | val EXPECTED_NAME = "Isaias" 27 | 28 | 29 | @Test 30 | fun test_noNote_CardView() { 31 | 32 | onView(withId(R.id.cardView)) 33 | .check(matches(isDisplayed())) 34 | 35 | onView(withId(R.id.fabAddNote)) 36 | .check(matches(isDisplayed())) 37 | 38 | } 39 | 40 | @Test 41 | fun test_recyclerView_visibility() { 42 | 43 | onView(withId(R.id.recyclerView)) 44 | .check(matches(isDisplayed())) 45 | } 46 | 47 | @Test 48 | fun test_selectedListItem() { 49 | 50 | //Create Note 51 | onView( 52 | withId( 53 | R.id.fabAddNote 54 | ) 55 | ) 56 | .perform(click()) 57 | 58 | //enter some input 59 | onView(withId(R.id.etNoteTitle)) 60 | .perform(ViewActions.typeText(EXPECTED_NAME)) 61 | 62 | 63 | onView(withId(R.id.menu_save)) 64 | .perform(click()) 65 | 66 | onView(withId(R.id.recyclerView)) 67 | .check(matches(isDisplayed())) 68 | 69 | 70 | //test onClick in RecyclerView 71 | onView(withId(R.id.recyclerView)) 72 | .perform( 73 | actionOnItemAtPosition( 74 | LIST_ITEM, click() 75 | 76 | ) 77 | ) 78 | 79 | onView(withId(R.id.etNoteTitleUpdate)) 80 | .check( 81 | matches( 82 | withText("Isaias") 83 | ) 84 | ) 85 | } 86 | 87 | @Test 88 | fun test_backNavigation_to_HomeFragment() { 89 | 90 | onView(withId(R.id.recyclerView)) 91 | .check(matches(isDisplayed())) 92 | 93 | //test onClick in RecyclerView 94 | onView(withId(R.id.recyclerView)) 95 | .perform( 96 | actionOnItemAtPosition( 97 | LIST_ITEM, click() 98 | ) 99 | ) 100 | 101 | onView(withId(R.id.etNoteTitleUpdate)) 102 | .check( 103 | matches( 104 | withText("Isaias") 105 | ) 106 | ) 107 | 108 | pressBack() 109 | 110 | /* onView(withId(R.id.home_frag)) 111 | .check(matches(isDisplayed())) 112 | 113 | onView(withId(R.id.recyclerView)) 114 | .check(matches(isDisplayed())) 115 | */ 116 | } 117 | } -------------------------------------------------------------------------------- /app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /app/src/main/java/com/bersyte/noteapp/MainActivity.kt: -------------------------------------------------------------------------------- 1 | package com.bersyte.noteapp 2 | 3 | import android.os.Bundle 4 | import androidx.appcompat.app.AppCompatActivity 5 | import androidx.lifecycle.ViewModelProvider 6 | import com.bersyte.noteapp.databinding.ActivityMainBinding 7 | import com.bersyte.noteapp.db.NoteDatabase 8 | import com.bersyte.noteapp.repository.NoteRepository 9 | import com.bersyte.noteapp.viewmodel.NoteViewModel 10 | import com.bersyte.noteapp.viewmodel.NoteViewModelProviderFactory 11 | 12 | class MainActivity : AppCompatActivity() { 13 | 14 | private lateinit var binding: ActivityMainBinding 15 | lateinit var noteViewModel: NoteViewModel 16 | 17 | override fun onCreate(savedInstanceState: Bundle?) { 18 | super.onCreate(savedInstanceState) 19 | binding = ActivityMainBinding.inflate(layoutInflater) 20 | setContentView(binding.root) 21 | setSupportActionBar(binding.toolbar) 22 | 23 | setUpViewModel() 24 | } 25 | 26 | private fun setUpViewModel() { 27 | val noteRepository = NoteRepository( 28 | NoteDatabase(this) 29 | ) 30 | 31 | val viewModelProviderFactory = 32 | NoteViewModelProviderFactory( 33 | application, noteRepository 34 | ) 35 | 36 | noteViewModel = ViewModelProvider( 37 | this, 38 | viewModelProviderFactory 39 | ).get(NoteViewModel::class.java) 40 | } 41 | 42 | } -------------------------------------------------------------------------------- /app/src/main/java/com/bersyte/noteapp/adapter/NoteAdapter.kt: -------------------------------------------------------------------------------- 1 | package com.bersyte.noteapp.adapter 2 | 3 | import android.graphics.Color 4 | import android.view.LayoutInflater 5 | import android.view.ViewGroup 6 | import androidx.navigation.findNavController 7 | import androidx.recyclerview.widget.AsyncListDiffer 8 | import androidx.recyclerview.widget.DiffUtil 9 | import androidx.recyclerview.widget.RecyclerView 10 | import com.bersyte.noteapp.databinding.NoteLayoutAdapterBinding 11 | import com.bersyte.noteapp.fragments.HomeFragmentDirections 12 | import com.bersyte.noteapp.model.Note 13 | import java.util.* 14 | 15 | 16 | class NoteAdapter : RecyclerView.Adapter() { 17 | 18 | class NoteViewHolder(val itemBinding: NoteLayoutAdapterBinding) : 19 | RecyclerView.ViewHolder(itemBinding.root) 20 | 21 | 22 | private val differCallback = 23 | object : DiffUtil.ItemCallback() { 24 | override fun areItemsTheSame(oldItem: Note, newItem: Note): Boolean { 25 | return oldItem.id == newItem.id && 26 | oldItem.noteBody == newItem.noteBody && 27 | oldItem.noteTitle == newItem.noteTitle 28 | } 29 | 30 | override fun areContentsTheSame(oldItem: Note, newItem: Note): Boolean { 31 | return oldItem == newItem 32 | } 33 | 34 | } 35 | 36 | val differ = AsyncListDiffer(this, differCallback) 37 | 38 | override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): NoteViewHolder { 39 | return NoteViewHolder( 40 | NoteLayoutAdapterBinding.inflate( 41 | LayoutInflater.from(parent.context), parent, false 42 | ) 43 | ) 44 | 45 | } 46 | 47 | override fun onBindViewHolder(holder: NoteViewHolder, position: Int) { 48 | val currentNote = differ.currentList[position] 49 | 50 | holder.itemBinding.tvNoteTitle.text = currentNote.noteTitle 51 | holder.itemBinding.tvNoteBody.text = currentNote.noteBody 52 | val random = Random() 53 | val color = 54 | Color.argb( 55 | 255, random.nextInt(256), 56 | random.nextInt(256), random.nextInt(256) 57 | ) 58 | holder.itemBinding.ibColor.setBackgroundColor(color) 59 | 60 | holder.itemView.setOnClickListener { view -> 61 | 62 | val direction = HomeFragmentDirections 63 | .actionHomeFragmentToUpdateNoteFragment(currentNote) 64 | view.findNavController().navigate(direction) 65 | } 66 | } 67 | 68 | override fun getItemCount(): Int { 69 | return differ.currentList.size 70 | } 71 | 72 | } -------------------------------------------------------------------------------- /app/src/main/java/com/bersyte/noteapp/db/NoteDao.kt: -------------------------------------------------------------------------------- 1 | package com.bersyte.noteapp.db 2 | 3 | import androidx.lifecycle.LiveData 4 | import androidx.room.* 5 | import com.bersyte.noteapp.model.Note 6 | 7 | @Dao 8 | interface NoteDao { 9 | 10 | @Insert(onConflict = OnConflictStrategy.REPLACE) 11 | suspend fun insertNote(note: Note) 12 | 13 | @Update 14 | suspend fun updateNote(note: Note) 15 | 16 | @Delete 17 | suspend fun deleteNote(note: Note) 18 | 19 | @Query("SELECT * FROM NOTES ORDER BY id DESC") 20 | fun getAllNotes(): LiveData> 21 | 22 | @Query("SELECT * FROM NOTES WHERE noteTitle LIKE :query OR noteBody LIKE:query") 23 | fun searchNote(query: String?): LiveData> 24 | } -------------------------------------------------------------------------------- /app/src/main/java/com/bersyte/noteapp/db/NoteDatabase.kt: -------------------------------------------------------------------------------- 1 | package com.bersyte.noteapp.db 2 | 3 | import android.content.Context 4 | import androidx.room.Database 5 | import androidx.room.Room 6 | import androidx.room.RoomDatabase 7 | import com.bersyte.noteapp.model.Note 8 | 9 | @Database(entities = [Note::class], version = 1) 10 | abstract class NoteDatabase: RoomDatabase() { 11 | 12 | abstract fun getNoteDao(): NoteDao 13 | 14 | companion object { 15 | @Volatile 16 | private var instance: NoteDatabase? = null 17 | private val LOCK = Any() 18 | 19 | operator fun invoke(context: Context) = instance ?: 20 | synchronized(LOCK) { 21 | instance ?: 22 | createDatabase(context).also { instance = it } 23 | } 24 | 25 | private fun createDatabase(context: Context) = 26 | Room.databaseBuilder( 27 | context.applicationContext, 28 | NoteDatabase::class.java, 29 | "note_db" 30 | ).build() 31 | } 32 | 33 | 34 | } -------------------------------------------------------------------------------- /app/src/main/java/com/bersyte/noteapp/fragments/HomeFragment.kt: -------------------------------------------------------------------------------- 1 | package com.bersyte.noteapp.fragments 2 | 3 | 4 | 5 | import android.os.Bundle 6 | import android.view.* 7 | import androidx.appcompat.widget.SearchView 8 | import androidx.fragment.app.Fragment 9 | import androidx.navigation.findNavController 10 | import androidx.recyclerview.widget.StaggeredGridLayoutManager 11 | import com.bersyte.noteapp.MainActivity 12 | import com.bersyte.noteapp.R 13 | import com.bersyte.noteapp.adapter.NoteAdapter 14 | import com.bersyte.noteapp.databinding.FragmentHomeBinding 15 | import com.bersyte.noteapp.model.Note 16 | import com.bersyte.noteapp.viewmodel.NoteViewModel 17 | 18 | 19 | class HomeFragment : Fragment(R.layout.fragment_home), 20 | SearchView.OnQueryTextListener { 21 | 22 | private var _binding: FragmentHomeBinding? = null 23 | private val binding get() = _binding!! 24 | private lateinit var notesViewModel: NoteViewModel 25 | private lateinit var noteAdapter: NoteAdapter 26 | 27 | override fun onCreate(savedInstanceState: Bundle?) { 28 | super.onCreate(savedInstanceState) 29 | setHasOptionsMenu(true) 30 | } 31 | 32 | override fun onCreateView( 33 | inflater: LayoutInflater, container: ViewGroup?, 34 | savedInstanceState: Bundle? 35 | ): View { 36 | _binding = FragmentHomeBinding.inflate(inflater, container, false) 37 | return binding.root 38 | } 39 | 40 | override fun onViewCreated(view: View, savedInstanceState: Bundle?) { 41 | super.onViewCreated(view, savedInstanceState) 42 | notesViewModel = (activity as MainActivity).noteViewModel 43 | setUpRecyclerView() 44 | 45 | binding.fabAddNote.setOnClickListener { 46 | it.findNavController().navigate(R.id.action_homeFragment_to_newNoteFragment) 47 | } 48 | } 49 | 50 | private fun setUpRecyclerView() { 51 | noteAdapter = NoteAdapter() 52 | 53 | binding.recyclerView.apply { 54 | layoutManager = StaggeredGridLayoutManager( 55 | 2, 56 | StaggeredGridLayoutManager.VERTICAL 57 | ) 58 | setHasFixedSize(true) 59 | adapter = noteAdapter 60 | } 61 | 62 | activity?.let { 63 | notesViewModel.getAllNote().observe(viewLifecycleOwner, { note -> 64 | noteAdapter.differ.submitList(note) 65 | updateUI(note) 66 | }) 67 | } 68 | 69 | } 70 | 71 | private fun updateUI(note: List) { 72 | if (note.isNotEmpty()) { 73 | binding.cardView.visibility = View.GONE 74 | binding.recyclerView.visibility = View.VISIBLE 75 | } else { 76 | binding.cardView.visibility = View.VISIBLE 77 | binding.recyclerView.visibility = View.GONE 78 | } 79 | } 80 | 81 | override fun onCreateOptionsMenu(menu: Menu, inflater: MenuInflater) { 82 | super.onCreateOptionsMenu(menu, inflater) 83 | menu.clear() 84 | inflater.inflate(R.menu.home_menu, menu) 85 | val mMenuSearch = menu.findItem(R.id.menu_search).actionView as SearchView 86 | mMenuSearch.isSubmitButtonEnabled = false 87 | mMenuSearch.setOnQueryTextListener(this) 88 | 89 | } 90 | 91 | 92 | override fun onQueryTextSubmit(query: String?): Boolean { 93 | /*if (query != null) { 94 | searchNote(query) 95 | }*/ 96 | return false 97 | } 98 | 99 | override fun onQueryTextChange(newText: String?): Boolean { 100 | 101 | if (newText != null) { 102 | searchNote(newText) 103 | } 104 | return true 105 | } 106 | 107 | 108 | private fun searchNote(query: String?) { 109 | val searchQuery = "%$query%" 110 | notesViewModel.searchNote(searchQuery).observe( 111 | this, { list -> 112 | noteAdapter.differ.submitList(list) 113 | } 114 | ) 115 | } 116 | 117 | 118 | override fun onDestroy() { 119 | super.onDestroy() 120 | _binding = null 121 | } 122 | } -------------------------------------------------------------------------------- /app/src/main/java/com/bersyte/noteapp/fragments/NewNoteFragment.kt: -------------------------------------------------------------------------------- 1 | package com.bersyte.noteapp.fragments 2 | 3 | import android.os.Bundle 4 | import android.view.* 5 | import androidx.fragment.app.Fragment 6 | import androidx.navigation.findNavController 7 | import com.bersyte.noteapp.MainActivity 8 | import com.bersyte.noteapp.R 9 | import com.bersyte.noteapp.databinding.FragmentNewNoteBinding 10 | import com.bersyte.noteapp.model.Note 11 | import com.bersyte.noteapp.toast 12 | import com.bersyte.noteapp.viewmodel.NoteViewModel 13 | import com.google.android.material.snackbar.Snackbar 14 | 15 | 16 | class NewNoteFragment : Fragment(R.layout.fragment_new_note) { 17 | 18 | private var _binding: FragmentNewNoteBinding? = null 19 | private val binding get() = _binding!! 20 | private lateinit var noteViewModel: NoteViewModel 21 | private lateinit var mView: View 22 | 23 | override fun onCreate(savedInstanceState: Bundle?) { 24 | super.onCreate(savedInstanceState) 25 | setHasOptionsMenu(true) 26 | } 27 | 28 | override fun onCreateView( 29 | inflater: LayoutInflater, container: ViewGroup?, 30 | savedInstanceState: Bundle? 31 | ): View { 32 | 33 | _binding = FragmentNewNoteBinding.inflate( 34 | inflater, 35 | container, 36 | false 37 | ) 38 | 39 | return binding.root 40 | } 41 | 42 | 43 | override fun onViewCreated(view: View, savedInstanceState: Bundle?) { 44 | super.onViewCreated(view, savedInstanceState) 45 | noteViewModel = (activity as MainActivity).noteViewModel 46 | mView = view 47 | } 48 | 49 | private fun saveNote(view: View) { 50 | val noteTitle = binding.etNoteTitle.text.toString().trim() 51 | val noteBody = binding.etNoteBody.text.toString().trim() 52 | 53 | if (noteTitle.isNotEmpty()) { 54 | val note = Note(0, noteTitle, noteBody) 55 | 56 | noteViewModel.addNote(note) 57 | Snackbar.make( 58 | view, "Note saved successfully", 59 | Snackbar.LENGTH_SHORT 60 | ).show() 61 | view.findNavController().navigate(R.id.action_newNoteFragment_to_homeFragment) 62 | 63 | } else { 64 | activity?.toast("Please enter note title") 65 | } 66 | } 67 | 68 | 69 | override fun onCreateOptionsMenu(menu: Menu, inflater: MenuInflater) { 70 | menu.clear() 71 | inflater.inflate(R.menu.menu_new_note, menu) 72 | super.onCreateOptionsMenu(menu, inflater) 73 | } 74 | 75 | 76 | override fun onOptionsItemSelected(item: MenuItem): Boolean { 77 | when (item.itemId) { 78 | R.id.menu_save -> { 79 | saveNote(mView) 80 | } 81 | } 82 | return super.onOptionsItemSelected(item) 83 | } 84 | 85 | 86 | override fun onDestroy() { 87 | super.onDestroy() 88 | _binding = null 89 | } 90 | 91 | 92 | } -------------------------------------------------------------------------------- /app/src/main/java/com/bersyte/noteapp/fragments/UpdateNoteFragment.kt: -------------------------------------------------------------------------------- 1 | package com.bersyte.noteapp.fragments 2 | 3 | import android.app.AlertDialog 4 | import android.os.Bundle 5 | import android.view.* 6 | import androidx.fragment.app.Fragment 7 | import androidx.navigation.findNavController 8 | import androidx.navigation.fragment.navArgs 9 | import com.bersyte.noteapp.MainActivity 10 | import com.bersyte.noteapp.R 11 | import com.bersyte.noteapp.databinding.FragmentUpdateNoteBinding 12 | import com.bersyte.noteapp.model.Note 13 | import com.bersyte.noteapp.toast 14 | import com.bersyte.noteapp.viewmodel.NoteViewModel 15 | 16 | 17 | class UpdateNoteFragment : Fragment(R.layout.fragment_update_note) { 18 | 19 | private var _binding: FragmentUpdateNoteBinding? = null 20 | private val binding get() = _binding!! 21 | 22 | private val args: UpdateNoteFragmentArgs by navArgs() 23 | private lateinit var currentNote: Note 24 | private lateinit var noteViewModel: NoteViewModel 25 | 26 | override fun onCreate(savedInstanceState: Bundle?) { 27 | super.onCreate(savedInstanceState) 28 | setHasOptionsMenu(true) 29 | } 30 | 31 | override fun onCreateView( 32 | inflater: LayoutInflater, container: ViewGroup?, 33 | savedInstanceState: Bundle? 34 | ): View { 35 | 36 | _binding = FragmentUpdateNoteBinding.inflate( 37 | inflater, 38 | container, 39 | false 40 | ) 41 | return binding.root 42 | } 43 | 44 | 45 | override fun onViewCreated(view: View, savedInstanceState: Bundle?) { 46 | super.onViewCreated(view, savedInstanceState) 47 | noteViewModel = (activity as MainActivity).noteViewModel 48 | currentNote = args.note!! 49 | 50 | binding.etNoteBodyUpdate.setText(currentNote.noteBody) 51 | binding.etNoteTitleUpdate.setText(currentNote.noteTitle) 52 | 53 | binding.fabDone.setOnClickListener { 54 | val title = binding.etNoteTitleUpdate.text.toString().trim() 55 | val body = binding.etNoteBodyUpdate.text.toString().trim() 56 | 57 | if (title.isNotEmpty()) { 58 | val note = Note(currentNote.id, title, body) 59 | noteViewModel.updateNote(note) 60 | 61 | view.findNavController().navigate(R.id.action_updateNoteFragment_to_homeFragment) 62 | 63 | } else { 64 | activity?.toast("Enter a note title please") 65 | } 66 | } 67 | } 68 | 69 | private fun deleteNote() { 70 | AlertDialog.Builder(activity).apply { 71 | setTitle("Delete Note") 72 | setMessage("Are you sure you want to permanently delete this note?") 73 | setPositiveButton("DELETE") { _, _ -> 74 | noteViewModel.deleteNote(currentNote) 75 | view?.findNavController()?.navigate( 76 | R.id.action_updateNoteFragment_to_homeFragment 77 | ) 78 | } 79 | setNegativeButton("CANCEL", null) 80 | }.create().show() 81 | 82 | } 83 | 84 | 85 | override fun onCreateOptionsMenu(menu: Menu, inflater: MenuInflater) { 86 | menu.clear() 87 | inflater.inflate(R.menu.menu_update_note, menu) 88 | super.onCreateOptionsMenu(menu, inflater) 89 | } 90 | 91 | override fun onOptionsItemSelected(item: MenuItem): Boolean { 92 | when (item.itemId) { 93 | R.id.menu_delete -> { 94 | deleteNote() 95 | } 96 | } 97 | 98 | return super.onOptionsItemSelected(item) 99 | } 100 | 101 | 102 | override fun onDestroy() { 103 | super.onDestroy() 104 | _binding = null 105 | } 106 | 107 | } -------------------------------------------------------------------------------- /app/src/main/java/com/bersyte/noteapp/helper/ShowToast.kt: -------------------------------------------------------------------------------- 1 | package com.bersyte.noteapp 2 | 3 | import android.content.Context 4 | import android.widget.Toast 5 | 6 | 7 | fun Context.toast(message: String){ 8 | Toast.makeText(this, message , Toast.LENGTH_SHORT).show() 9 | } -------------------------------------------------------------------------------- /app/src/main/java/com/bersyte/noteapp/model/Note.kt: -------------------------------------------------------------------------------- 1 | package com.bersyte.noteapp.model 2 | 3 | import android.os.Parcelable 4 | import androidx.room.Entity 5 | import androidx.room.PrimaryKey 6 | import kotlinx.parcelize.Parcelize 7 | 8 | @Entity(tableName = "notes") 9 | @Parcelize 10 | data class Note( 11 | @PrimaryKey(autoGenerate = true) 12 | val id: Int, 13 | val noteTitle: String, 14 | val noteBody: String 15 | ) : Parcelable 16 | -------------------------------------------------------------------------------- /app/src/main/java/com/bersyte/noteapp/repository/NoteRepository.kt: -------------------------------------------------------------------------------- 1 | package com.bersyte.noteapp.repository 2 | 3 | import com.bersyte.noteapp.db.NoteDatabase 4 | import com.bersyte.noteapp.model.Note 5 | 6 | class NoteRepository(private val db: NoteDatabase) { 7 | 8 | suspend fun insertNote(note: Note) = db.getNoteDao().insertNote(note) 9 | suspend fun deleteNote(note: Note) = db.getNoteDao().deleteNote(note) 10 | suspend fun updateNote(note: Note) = db.getNoteDao().updateNote(note) 11 | fun getAllNotes() = db.getNoteDao().getAllNotes() 12 | fun searchNote(query: String?) = db.getNoteDao().searchNote(query) 13 | 14 | } -------------------------------------------------------------------------------- /app/src/main/java/com/bersyte/noteapp/viewmodel/NoteViewModel.kt: -------------------------------------------------------------------------------- 1 | package com.bersyte.noteapp.viewmodel 2 | 3 | import android.app.Application 4 | import androidx.lifecycle.AndroidViewModel 5 | import androidx.lifecycle.asFlow 6 | import androidx.lifecycle.asLiveData 7 | import androidx.lifecycle.viewModelScope 8 | import com.bersyte.noteapp.db.NoteDao 9 | import com.bersyte.noteapp.model.Note 10 | import com.bersyte.noteapp.repository.NoteRepository 11 | import kotlinx.coroutines.launch 12 | 13 | class NoteViewModel( 14 | app: Application, 15 | private val noteRepository: NoteRepository 16 | ) : AndroidViewModel(app) { 17 | 18 | 19 | fun addNote(note: Note) = 20 | viewModelScope.launch { 21 | noteRepository.insertNote(note) 22 | } 23 | 24 | fun deleteNote(note: Note) = 25 | viewModelScope.launch { 26 | noteRepository.deleteNote(note) 27 | } 28 | 29 | fun updateNote(note: Note) = 30 | viewModelScope.launch { 31 | noteRepository.updateNote(note) 32 | } 33 | 34 | fun getAllNote() = noteRepository.getAllNotes() 35 | 36 | fun searchNote(query: String?) = 37 | noteRepository.searchNote(query) 38 | 39 | 40 | 41 | } -------------------------------------------------------------------------------- /app/src/main/java/com/bersyte/noteapp/viewmodel/NoteViewModelProviderFactory.kt: -------------------------------------------------------------------------------- 1 | package com.bersyte.noteapp.viewmodel 2 | 3 | import android.app.Application 4 | import androidx.lifecycle.ViewModel 5 | import androidx.lifecycle.ViewModelProvider 6 | import com.bersyte.noteapp.repository.NoteRepository 7 | 8 | class NoteViewModelProviderFactory( 9 | val app: Application, 10 | private val noteRepository: NoteRepository 11 | ) : ViewModelProvider.Factory { 12 | override fun create(modelClass: Class): T { 13 | return NoteViewModel(app, noteRepository) as T 14 | } 15 | } -------------------------------------------------------------------------------- /app/src/main/res/anim/slide_in_left.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /app/src/main/res/anim/slide_in_right.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /app/src/main/res/anim/slide_in_up.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /app/src/main/res/anim/slide_out_left.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /app/src/main/res/anim/slide_out_right.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /app/src/main/res/anim/slide_out_up.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /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_add.xml: -------------------------------------------------------------------------------- 1 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_delete.xml: -------------------------------------------------------------------------------- 1 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_done.xml: -------------------------------------------------------------------------------- 1 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /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_search_black_24dp.xml: -------------------------------------------------------------------------------- 1 | 6 | 9 | 10 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 | 10 | 20 | 21 | 33 | 34 | 35 | 36 | -------------------------------------------------------------------------------- /app/src/main/res/layout/fragment_home.xml: -------------------------------------------------------------------------------- 1 | 2 | 11 | 12 | 27 | 28 | 37 | 38 | 52 | 53 | 62 | 63 | 64 | 65 | 66 | -------------------------------------------------------------------------------- /app/src/main/res/layout/fragment_new_note.xml: -------------------------------------------------------------------------------- 1 | 2 | 10 | 11 | 27 | 28 | 33 | 34 | 46 | 47 | 60 | 61 | 62 | 63 | 64 | -------------------------------------------------------------------------------- /app/src/main/res/layout/fragment_update_note.xml: -------------------------------------------------------------------------------- 1 | 2 | 9 | 10 | 14 | 15 | 22 | 23 | 28 | 29 | 41 | 42 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 75 | 76 | -------------------------------------------------------------------------------- /app/src/main/res/layout/note_layout_adapter.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 | 17 | 18 | 23 | 24 | 29 | 30 | 39 | 40 | 47 | 48 | 49 | 50 | 59 | 60 | 61 | 62 | 63 | -------------------------------------------------------------------------------- /app/src/main/res/menu/home_menu.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 11 | -------------------------------------------------------------------------------- /app/src/main/res/menu/menu_new_note.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 8 | -------------------------------------------------------------------------------- /app/src/main/res/menu/menu_update_note.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 9 | 10 | -------------------------------------------------------------------------------- /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.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/IsaiasCuvula/mvvm_note_app_kotlin_android_studio/5c877c8e62b9649fed74ad100acb07d23349ad74/app/src/main/res/mipmap-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-hdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/IsaiasCuvula/mvvm_note_app_kotlin_android_studio/5c877c8e62b9649fed74ad100acb07d23349ad74/app/src/main/res/mipmap-hdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/IsaiasCuvula/mvvm_note_app_kotlin_android_studio/5c877c8e62b9649fed74ad100acb07d23349ad74/app/src/main/res/mipmap-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-mdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/IsaiasCuvula/mvvm_note_app_kotlin_android_studio/5c877c8e62b9649fed74ad100acb07d23349ad74/app/src/main/res/mipmap-mdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/IsaiasCuvula/mvvm_note_app_kotlin_android_studio/5c877c8e62b9649fed74ad100acb07d23349ad74/app/src/main/res/mipmap-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/IsaiasCuvula/mvvm_note_app_kotlin_android_studio/5c877c8e62b9649fed74ad100acb07d23349ad74/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/IsaiasCuvula/mvvm_note_app_kotlin_android_studio/5c877c8e62b9649fed74ad100acb07d23349ad74/app/src/main/res/mipmap-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/IsaiasCuvula/mvvm_note_app_kotlin_android_studio/5c877c8e62b9649fed74ad100acb07d23349ad74/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/IsaiasCuvula/mvvm_note_app_kotlin_android_studio/5c877c8e62b9649fed74ad100acb07d23349ad74/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/IsaiasCuvula/mvvm_note_app_kotlin_android_studio/5c877c8e62b9649fed74ad100acb07d23349ad74/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/navigation/nav_graph.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 8 | 13 | 20 | 27 | 28 | 33 | 40 | 41 | 46 | 53 | 57 | 58 | -------------------------------------------------------------------------------- /app/src/main/res/values-night/themes.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 12 | 13 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /app/src/main/res/values/colors.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | #803c94 4 | #803c94 5 | #936B9F 6 | #FF000000 7 | #FFFFFFFF 8 | #EDE9E9 9 | #928E8E 10 | -------------------------------------------------------------------------------- /app/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | Note App 3 | image 4 | bersyte 5 | -------------------------------------------------------------------------------- /app/src/main/res/values/themes.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 9 | 10 | 16 | 17 | -------------------------------------------------------------------------------- /app/src/test/java/com/bersyte/noteapp/ExampleUnitTest.kt: -------------------------------------------------------------------------------- 1 | package com.bersyte.noteapp 2 | 3 | import org.junit.Test 4 | 5 | import org.junit.Assert.* 6 | 7 | /** 8 | * Example local unit test, which will execute on the development machine (host). 9 | * 10 | * See [testing documentation](http://d.android.com/tools/testing). 11 | */ 12 | class ExampleUnitTest { 13 | @Test 14 | fun addition_isCorrect() { 15 | assertEquals(4, 2 + 2) 16 | } 17 | } -------------------------------------------------------------------------------- /build.gradle: -------------------------------------------------------------------------------- 1 | // Top-level build file where you can add configuration options common to all sub-projects/modules. 2 | buildscript { 3 | ext.kotlin_version = "1.4.21" 4 | repositories { 5 | google() 6 | jcenter() 7 | } 8 | dependencies { 9 | classpath 'com.android.tools.build:gradle:4.1.3' 10 | classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" 11 | classpath "androidx.navigation:navigation-safe-args-gradle-plugin:2.3.3" 12 | // NOTE: Do not place your application dependencies here; they belong 13 | // in the individual module build.gradle files 14 | } 15 | } 16 | 17 | allprojects { 18 | repositories { 19 | google() 20 | jcenter() 21 | } 22 | } 23 | 24 | task clean(type: Delete) { 25 | delete rootProject.buildDir 26 | } -------------------------------------------------------------------------------- /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 | # Automatically convert third-party libraries to use AndroidX 19 | android.enableJetifier=true 20 | # Kotlin code style for this project: "official" or "obsolete": 21 | kotlin.code.style=official -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/IsaiasCuvula/mvvm_note_app_kotlin_android_studio/5c877c8e62b9649fed74ad100acb07d23349ad74/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Fri Jan 15 20:12:32 EET 2021 2 | distributionBase=GRADLE_USER_HOME 3 | distributionPath=wrapper/dists 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | distributionUrl=https\://services.gradle.org/distributions/gradle-6.5-bin.zip 7 | -------------------------------------------------------------------------------- /gradlew: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env sh 2 | 3 | ############################################################################## 4 | ## 5 | ## Gradle start up script for UN*X 6 | ## 7 | ############################################################################## 8 | 9 | # Attempt to set APP_HOME 10 | # Resolve links: $0 may be a link 11 | PRG="$0" 12 | # Need this for relative symlinks. 13 | while [ -h "$PRG" ] ; do 14 | ls=`ls -ld "$PRG"` 15 | link=`expr "$ls" : '.*-> \(.*\)$'` 16 | if expr "$link" : '/.*' > /dev/null; then 17 | PRG="$link" 18 | else 19 | PRG=`dirname "$PRG"`"/$link" 20 | fi 21 | done 22 | SAVED="`pwd`" 23 | cd "`dirname \"$PRG\"`/" >/dev/null 24 | APP_HOME="`pwd -P`" 25 | cd "$SAVED" >/dev/null 26 | 27 | APP_NAME="Gradle" 28 | APP_BASE_NAME=`basename "$0"` 29 | 30 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 31 | DEFAULT_JVM_OPTS="" 32 | 33 | # Use the maximum available, or set MAX_FD != -1 to use that value. 34 | MAX_FD="maximum" 35 | 36 | warn () { 37 | echo "$*" 38 | } 39 | 40 | die () { 41 | echo 42 | echo "$*" 43 | echo 44 | exit 1 45 | } 46 | 47 | # OS specific support (must be 'true' or 'false'). 48 | cygwin=false 49 | msys=false 50 | darwin=false 51 | nonstop=false 52 | case "`uname`" in 53 | CYGWIN* ) 54 | cygwin=true 55 | ;; 56 | Darwin* ) 57 | darwin=true 58 | ;; 59 | MINGW* ) 60 | msys=true 61 | ;; 62 | NONSTOP* ) 63 | nonstop=true 64 | ;; 65 | esac 66 | 67 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 68 | 69 | # Determine the Java command to use to start the JVM. 70 | if [ -n "$JAVA_HOME" ] ; then 71 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 72 | # IBM's JDK on AIX uses strange locations for the executables 73 | JAVACMD="$JAVA_HOME/jre/sh/java" 74 | else 75 | JAVACMD="$JAVA_HOME/bin/java" 76 | fi 77 | if [ ! -x "$JAVACMD" ] ; then 78 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 79 | 80 | Please set the JAVA_HOME variable in your environment to match the 81 | location of your Java installation." 82 | fi 83 | else 84 | JAVACMD="java" 85 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 86 | 87 | Please set the JAVA_HOME variable in your environment to match the 88 | location of your Java installation." 89 | fi 90 | 91 | # Increase the maximum file descriptors if we can. 92 | if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then 93 | MAX_FD_LIMIT=`ulimit -H -n` 94 | if [ $? -eq 0 ] ; then 95 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then 96 | MAX_FD="$MAX_FD_LIMIT" 97 | fi 98 | ulimit -n $MAX_FD 99 | if [ $? -ne 0 ] ; then 100 | warn "Could not set maximum file descriptor limit: $MAX_FD" 101 | fi 102 | else 103 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" 104 | fi 105 | fi 106 | 107 | # For Darwin, add options to specify how the application appears in the dock 108 | if $darwin; then 109 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" 110 | fi 111 | 112 | # For Cygwin, switch paths to Windows format before running java 113 | if $cygwin ; then 114 | APP_HOME=`cygpath --path --mixed "$APP_HOME"` 115 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` 116 | JAVACMD=`cygpath --unix "$JAVACMD"` 117 | 118 | # We build the pattern for arguments to be converted via cygpath 119 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` 120 | SEP="" 121 | for dir in $ROOTDIRSRAW ; do 122 | ROOTDIRS="$ROOTDIRS$SEP$dir" 123 | SEP="|" 124 | done 125 | OURCYGPATTERN="(^($ROOTDIRS))" 126 | # Add a user-defined pattern to the cygpath arguments 127 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then 128 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" 129 | fi 130 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 131 | i=0 132 | for arg in "$@" ; do 133 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` 134 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option 135 | 136 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition 137 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` 138 | else 139 | eval `echo args$i`="\"$arg\"" 140 | fi 141 | i=$((i+1)) 142 | done 143 | case $i in 144 | (0) set -- ;; 145 | (1) set -- "$args0" ;; 146 | (2) set -- "$args0" "$args1" ;; 147 | (3) set -- "$args0" "$args1" "$args2" ;; 148 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;; 149 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; 150 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; 151 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; 152 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; 153 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; 154 | esac 155 | fi 156 | 157 | # Escape application args 158 | save () { 159 | for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done 160 | echo " " 161 | } 162 | APP_ARGS=$(save "$@") 163 | 164 | # Collect all arguments for the java command, following the shell quoting and substitution rules 165 | eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS" 166 | 167 | # by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong 168 | if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then 169 | cd "$(dirname "$0")" 170 | fi 171 | 172 | exec "$JAVACMD" "$@" 173 | -------------------------------------------------------------------------------- /gradlew.bat: -------------------------------------------------------------------------------- 1 | @if "%DEBUG%" == "" @echo off 2 | @rem ########################################################################## 3 | @rem 4 | @rem Gradle startup script for Windows 5 | @rem 6 | @rem ########################################################################## 7 | 8 | @rem Set local scope for the variables with windows NT shell 9 | if "%OS%"=="Windows_NT" setlocal 10 | 11 | set DIRNAME=%~dp0 12 | if "%DIRNAME%" == "" set DIRNAME=. 13 | set APP_BASE_NAME=%~n0 14 | set APP_HOME=%DIRNAME% 15 | 16 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 17 | set DEFAULT_JVM_OPTS= 18 | 19 | @rem Find java.exe 20 | if defined JAVA_HOME goto findJavaFromJavaHome 21 | 22 | set JAVA_EXE=java.exe 23 | %JAVA_EXE% -version >NUL 2>&1 24 | if "%ERRORLEVEL%" == "0" goto init 25 | 26 | echo. 27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 28 | echo. 29 | echo Please set the JAVA_HOME variable in your environment to match the 30 | echo location of your Java installation. 31 | 32 | goto fail 33 | 34 | :findJavaFromJavaHome 35 | set JAVA_HOME=%JAVA_HOME:"=% 36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 37 | 38 | if exist "%JAVA_EXE%" goto init 39 | 40 | echo. 41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 42 | echo. 43 | echo Please set the JAVA_HOME variable in your environment to match the 44 | echo location of your Java installation. 45 | 46 | goto fail 47 | 48 | :init 49 | @rem Get command-line arguments, handling Windows variants 50 | 51 | if not "%OS%" == "Windows_NT" goto win9xME_args 52 | 53 | :win9xME_args 54 | @rem Slurp the command line arguments. 55 | set CMD_LINE_ARGS= 56 | set _SKIP=2 57 | 58 | :win9xME_args_slurp 59 | if "x%~1" == "x" goto execute 60 | 61 | set CMD_LINE_ARGS=%* 62 | 63 | :execute 64 | @rem Setup the command line 65 | 66 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 67 | 68 | @rem Execute Gradle 69 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% 70 | 71 | :end 72 | @rem End local scope for the variables with windows NT shell 73 | if "%ERRORLEVEL%"=="0" goto mainEnd 74 | 75 | :fail 76 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 77 | rem the _cmd.exe /c_ return code! 78 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 79 | exit /b 1 80 | 81 | :mainEnd 82 | if "%OS%"=="Windows_NT" endlocal 83 | 84 | :omega 85 | -------------------------------------------------------------------------------- /settings.gradle: -------------------------------------------------------------------------------- 1 | include ':app' 2 | rootProject.name = "Note App" --------------------------------------------------------------------------------