-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
-creation -nav graph -addNote, noteDetail and note list fragments added -koin implementation -repository, model and db implemented
- Loading branch information
Showing
21 changed files
with
344 additions
and
0 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
36 changes: 36 additions & 0 deletions
36
Notes/app/src/main/java/com/training/notes/NotesApplication.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
7
Notes/app/src/main/java/com/training/notes/db/FakeDataBase.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
16
Notes/app/src/main/java/com/training/notes/db/impl/NotesDaoImpl.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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')" | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
Notes/app/src/main/java/com/training/notes/repository/NotesRepository.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
16 changes: 16 additions & 0 deletions
16
Notes/app/src/main/java/com/training/notes/repository/impl/NotesRepositoryImpl.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} |
36 changes: 36 additions & 0 deletions
36
Notes/app/src/main/java/com/training/notes/ui/add/AddNoteFragment.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
|
||
} | ||
|
||
} |
15 changes: 15 additions & 0 deletions
15
Notes/app/src/main/java/com/training/notes/ui/add/AddNoteViewModel.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)) | ||
} | ||
|
||
} |
31 changes: 31 additions & 0 deletions
31
Notes/app/src/main/java/com/training/notes/ui/detail/NoteDetailFragment.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
|
||
} | ||
|
||
} |
15 changes: 15 additions & 0 deletions
15
Notes/app/src/main/java/com/training/notes/ui/detail/NoteDetailViewModel.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} | ||
|
||
} |
32 changes: 32 additions & 0 deletions
32
Notes/app/src/main/java/com/training/notes/ui/list/NotesFragment.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
|
||
} | ||
|
||
} |
14 changes: 14 additions & 0 deletions
14
Notes/app/src/main/java/com/training/notes/ui/list/NotesViewModel.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |