This file contains hidden or 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
/** | |
* Obtain an item based on the ID | |
*/ | |
fun getNoteById(noteId: String): Note? | |
= items.first { it.noteId == noteId } | |
/** | |
* Save a new item to the list | |
*/ | |
fun saveItem(item: Note) { |
This file contains hidden or 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
class MockNotesRepository : NotesRepository { | |
companion object { | |
private val TAG = this::class.java.simpleName | |
} | |
private val factory = MockNotesDataSourceFactory() | |
override val notes: LiveData<PagedList<Note>> | |
init { |
This file contains hidden or 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
data class Note(val noteId: String = UUID.randomUUID().toString()) { | |
companion object { | |
val DiffCallback = object : DiffUtil.ItemCallback<Note>() { | |
override fun areItemsTheSame(oldItem: Note?, newItem: Note?): Boolean | |
= oldItem != null && newItem != null && oldItem.noteId == newItem.noteId | |
override fun areContentsTheSame(oldItem: Note?, newItem: Note?): Boolean | |
= oldItem != null && newItem != null | |
&& oldItem.noteId == newItem.noteId | |
&& oldItem.title == newItem.title |
This file contains hidden or 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
class NotesPagedListAdapter(val onClick: (Note) -> Unit) : PagedListAdapter<Note, ListItemViewHolder>(Note.DiffCallback) { | |
companion object { | |
private val TAG = this::class.java.simpleName | |
} | |
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ListItemViewHolder | |
= ListItemViewHolder(LayoutInflater.from(parent.context).inflate(R.layout.note_list_item, parent, false)) | |
override fun onBindViewHolder(holder: ListItemViewHolder, position: Int) { | |
Log.d(TAG, "Binding view holder at position $position") |
This file contains hidden or 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
override fun onCreate(savedInstanceState: Bundle?) { | |
super.onCreate(savedInstanceState) | |
setContentView(R.layout.activity_note_list) | |
setSupportActionBar(note_list_toolbar) | |
note_list_add_note.setOnClickListener { | |
Log.d(TAG, "addNote button pressed") | |
launchNoteDetailActivity(this) | |
} |
This file contains hidden or 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
package com.shellmonger.apps.mynotes.ui | |
import android.content.Context | |
import android.graphics.Canvas | |
import android.graphics.Color | |
import android.graphics.PorterDuff | |
import android.graphics.drawable.ColorDrawable | |
import android.support.v4.content.ContextCompat | |
import android.support.v7.widget.RecyclerView | |
import android.support.v7.widget.helper.ItemTouchHelper |
This file contains hidden or 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
val adapter = NotesPagedListAdapter { | |
launchNoteDetailActivity(this@NoteListActivity, it.noteId) | |
} | |
viewModel.notes.observe(this, Observer { | |
it?.let { adapter.submitList(it) } | |
}) | |
note_list_recyclerview.layoutManager = LinearLayoutManager(this).apply { | |
orientation = LinearLayoutManager.VERTICAL | |
} | |
note_list_recyclerview.adapter = adapter |
This file contains hidden or 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
// Top-level build file where you can add configuration options common to all sub-projects/modules. | |
buildscript { | |
ext.kotlin_version = '1.2.41' | |
ext.appsync_version = '2.6.18' | |
repositories { | |
google() | |
jcenter() | |
} | |
dependencies { |
This file contains hidden or 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
query GetNote($noteId: ID!) { | |
getNote(noteId: $noteId) { | |
noteId | |
title | |
content | |
} | |
} | |
query AllNotes($nextToken: String) { | |
allNotes(nextToken: $nextToken) { |
This file contains hidden or 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
package com.shellmonger.apps.mynotes.repositories.aws | |
import android.content.Context | |
import android.arch.lifecycle.LiveData | |
import android.arch.paging.LivePagedListBuilder | |
import android.arch.paging.PagedList | |
import com.shellmonger.apps.mynotes.models.Note | |
import com.shellmonger.apps.mynotes.repositories.NotesRepository | |
import com.shellmonger.apps.mynotes.services.AnalyticsService | |
import com.shellmonger.apps.mynotes.services.IdentityService |