Skip to content

Commit

Permalink
project:
Browse files Browse the repository at this point in the history
-creation
-nav graph
-addNote, noteDetail and note list fragments added
-koin implementation
-repository, model and db implemented
  • Loading branch information
jclemus91 committed Jul 12, 2019
1 parent b807a26 commit 83359d1
Show file tree
Hide file tree
Showing 21 changed files with 344 additions and 0 deletions.
11 changes: 11 additions & 0 deletions Notes/.idea/codeStyles/Project.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions Notes/.idea/codeStyles/codeStyleConfig.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 18 additions & 0 deletions Notes/.idea/gradle.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions Notes/.idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

36 changes: 36 additions & 0 deletions Notes/app/src/main/java/com/training/notes/NotesApplication.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package com.training.notes

import android.app.Application
import com.training.notes.db.NotesDao
import com.training.notes.db.impl.NotesDaoImpl
import com.training.notes.repository.NotesRepository
import com.training.notes.repository.impl.NotesRepositoryImpl
import com.training.notes.ui.add.AddNoteViewModel
import com.training.notes.ui.detail.NoteDetailViewModel
import com.training.notes.ui.list.NotesViewModel
import org.koin.android.viewmodel.dsl.viewModel
import org.koin.core.context.startKoin
import org.koin.dsl.module

class NotesApplication: Application() {

override fun onCreate() {
super.onCreate()
startKoin {
modules(repositoryModule)
modules(viewModelModule)
}
}

private val repositoryModule = module {
single<NotesDao> { NotesDaoImpl() }
single<NotesRepository> { NotesRepositoryImpl(get()) }
}

private val viewModelModule = module {
viewModel { AddNoteViewModel(get()) }
viewModel { NoteDetailViewModel(get()) }
viewModel { NotesViewModel(get()) }
}

}
7 changes: 7 additions & 0 deletions Notes/app/src/main/java/com/training/notes/db/FakeDataBase.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.training.notes.db

import com.training.notes.model.Note

typealias FakeDataBase = ArrayList<Note>

val dataBase: FakeDataBase = arrayListOf()
9 changes: 9 additions & 0 deletions Notes/app/src/main/java/com/training/notes/db/NotesDao.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.training.notes.db

import com.training.notes.model.Note

interface NotesDao {
fun addNote(note: Note)
fun getNotes(): List<Note>
fun getNote(position: Int): Note
}
16 changes: 16 additions & 0 deletions Notes/app/src/main/java/com/training/notes/db/impl/NotesDaoImpl.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package com.training.notes.db.impl

import com.training.notes.db.NotesDao
import com.training.notes.db.dataBase
import com.training.notes.model.Note

class NotesDaoImpl : NotesDao {

override fun addNote(note: Note) {
dataBase += note
}

override fun getNotes(): List<Note> = dataBase

override fun getNote(position: Int): Note = dataBase[position]
}
10 changes: 10 additions & 0 deletions Notes/app/src/main/java/com/training/notes/model/Note.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.training.notes.model

data class Note(
val title: String,
val message: String
) {
override fun toString(): String {
return "Note(title='$title', message='$message')"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.training.notes.repository

import com.training.notes.model.Note

interface NotesRepository {
fun addNote(note: Note)
fun getNotes(): List<Note>
fun getNote(position: Int): Note
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package com.training.notes.repository.impl

import com.training.notes.db.NotesDao
import com.training.notes.model.Note
import com.training.notes.repository.NotesRepository

class NotesRepositoryImpl(private val notesDao: NotesDao) : NotesRepository {

override fun addNote(note: Note) {
notesDao.addNote(note)
}

override fun getNotes(): List<Note> = notesDao.getNotes()

override fun getNote(position: Int): Note = notesDao.getNote(position)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package com.training.notes.ui.add

import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.fragment.app.Fragment
import com.training.notes.R
import org.koin.android.viewmodel.ext.android.viewModel

class AddNoteFragment : Fragment() {

companion object {
fun newInstance() = AddNoteFragment()
}

private val viewModel: AddNoteViewModel by viewModel()

override fun onCreateView(
inflater: LayoutInflater, container: ViewGroup?,
savedInstanceState: Bundle?
): View? {
return inflater.inflate(R.layout.add_note_fragment, container, false)
}

override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
viewModel.addNote("title", "message")
}

override fun onActivityCreated(savedInstanceState: Bundle?) {
super.onActivityCreated(savedInstanceState)

}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.training.notes.ui.add

import androidx.lifecycle.ViewModel
import com.training.notes.model.Note
import com.training.notes.repository.NotesRepository

class AddNoteViewModel(
private val notesRepository: NotesRepository
) : ViewModel() {

fun addNote(title: String, message: String) {
notesRepository.addNote(Note(title, message))
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package com.training.notes.ui.detail

import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.fragment.app.Fragment
import com.training.notes.R
import org.koin.android.viewmodel.ext.android.viewModel

class NoteDetailFragment : Fragment() {

companion object {
fun newInstance() = NoteDetailFragment()
}

private val viewModel: NoteDetailViewModel by viewModel()

override fun onCreateView(
inflater: LayoutInflater, container: ViewGroup?,
savedInstanceState: Bundle?
): View? {
return inflater.inflate(R.layout.note_detail_fragment, container, false)
}

override fun onActivityCreated(savedInstanceState: Bundle?) {
super.onActivityCreated(savedInstanceState)

}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.training.notes.ui.detail

import androidx.lifecycle.ViewModel;
import com.training.notes.model.Note
import com.training.notes.repository.NotesRepository

class NoteDetailViewModel(
private val notesRepository: NotesRepository
) : ViewModel() {

fun getNote(position: Int): Note {
return notesRepository.getNote(position)
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package com.training.notes.ui.list

import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.fragment.app.Fragment
import com.training.notes.R
import org.koin.android.viewmodel.ext.android.viewModel

class NotesFragment : Fragment() {

companion object {
fun newInstance() = NotesFragment()
}


private val viewModel: NotesViewModel by viewModel()

override fun onCreateView(
inflater: LayoutInflater, container: ViewGroup?,
savedInstanceState: Bundle?
): View? {
return inflater.inflate(R.layout.notes_fragment, container, false)
}

override fun onActivityCreated(savedInstanceState: Bundle?) {
super.onActivityCreated(savedInstanceState)

}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.training.notes.ui.list

import androidx.lifecycle.ViewModel;
import com.training.notes.model.Note
import com.training.notes.repository.NotesRepository

class NotesViewModel(
private val notesRepository: NotesRepository
) : ViewModel() {

fun getNotes() : List<Note> {
return notesRepository.getNotes()
}
}
14 changes: 14 additions & 0 deletions Notes/app/src/main/res/layout/add_note_fragment.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout
xmlns:android="http:https://schemas.android.com/apk/res/android"
xmlns:tools="http:https://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".ui.add.AddNoteFragment">

<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="Add Note"/>

</FrameLayout>
14 changes: 14 additions & 0 deletions Notes/app/src/main/res/layout/note_detail_fragment.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout
xmlns:android="http:https://schemas.android.com/apk/res/android"
xmlns:tools="http:https://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".ui.detail.NoteDetailFragment">

<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="Note Detail"/>

</FrameLayout>
14 changes: 14 additions & 0 deletions Notes/app/src/main/res/layout/notes_fragment.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout
xmlns:android="http:https://schemas.android.com/apk/res/android"
xmlns:tools="http:https://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".ui.list.NotesFragment">

<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="Notes Fragment"/>

</FrameLayout>
16 changes: 16 additions & 0 deletions Notes/app/src/main/res/navigation/nav_graph.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?xml version="1.0" encoding="utf-8"?>
<navigation xmlns:android="http:https://schemas.android.com/apk/res/android"
xmlns:app="http:https://schemas.android.com/apk/res-auto"
xmlns:tools="http:https://schemas.android.com/tools" android:id="@+id/nav_graph"
app:startDestination="@id/notesFragment">

<fragment android:id="@+id/notesFragment" android:name="com.training.notes.ui.list.NotesFragment"
android:label="notes_fragment" tools:layout="@layout/notes_fragment">
<action android:id="@+id/action_notesFragment_to_addNoteFragment" app:destination="@id/addNoteFragment"/>
<action android:id="@+id/action_notesFragment_to_noteDetailFragment" app:destination="@id/noteDetailFragment"/>
</fragment>
<fragment android:id="@+id/addNoteFragment" android:name="com.training.notes.ui.add.AddNoteFragment"
android:label="add_note_fragment" tools:layout="@layout/add_note_fragment"/>
<fragment android:id="@+id/noteDetailFragment" android:name="com.training.notes.ui.detail.NoteDetailFragment"
android:label="note_detail_fragment" tools:layout="@layout/note_detail_fragment"/>
</navigation>

0 comments on commit 83359d1

Please sign in to comment.