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 NoteListActivity : AppCompatActivity() { | |
companion object { | |
private val TAG = this::class.java.simpleName | |
} | |
override fun onCreate(savedInstanceState: Bundle?) { | |
super.onCreate(savedInstanceState) | |
setContentView(R.layout.activity_note_list) | |
note_list_add_note.setOnClickListener { |
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
<?xml version="1.0" encoding="utf-8"?> | |
<android.support.constraint.ConstraintLayout | |
xmlns:android="http://schemas.android.com/apk/res/android" | |
xmlns:app="http://schemas.android.com/apk/res-auto" | |
android:layout_width="match_parent" | |
android:layout_height="match_parent"> | |
<android.support.v7.widget.Toolbar | |
android:id="@+id/note_detail_toolbar" | |
android:layout_width="match_parent" |
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
<?xml version="1.0" encoding="utf-8"?> | |
<android.support.constraint.ConstraintLayout | |
xmlns:android="http://schemas.android.com/apk/res/android" | |
android:layout_width="match_parent" | |
android:layout_height="match_parent"> | |
<TextView | |
android:id="@+id/list_item_title" | |
android:layout_width="wrap_content" | |
android:layout_height="wrap_content" |
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.support.v7.widget.RecyclerView | |
import android.view.View | |
import com.shellmonger.apps.mynotes.models.Note | |
import kotlinx.android.synthetic.main.note_list_item.view.* | |
class ListItemViewHolder(val view: View) : RecyclerView.ViewHolder(view) { | |
var note: Note? = null | |
set(value) { |
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.adapters | |
import android.support.v7.widget.RecyclerView | |
import android.view.LayoutInflater | |
import android.view.ViewGroup | |
import com.shellmonger.apps.mynotes.R | |
import com.shellmonger.apps.mynotes.models.Note | |
import com.shellmonger.apps.mynotes.ui.ListItemViewHolder | |
class NoteListAdapter(val onClick: (Note) -> Unit) : RecyclerView.Adapter<ListItemViewHolder>() { |
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 _notes: MutableMap<String, Note> = HashMap() | |
private val mutableNotes: MutableLiveData<List<Note>> = MutableLiveData() | |
init { | |
mutableNotes.postValue(_notes.values.toList()) |
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 NoteListActivity : AppCompatActivity() { | |
companion object { | |
private val TAG = this::class.java.simpleName | |
} | |
private val viewModel by viewModel<NoteListViewModel>() | |
override fun onCreate(savedInstanceState: Bundle?) { | |
super.onCreate(savedInstanceState) | |
setContentView(R.layout.activity_note_list) |
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 _notes: MutableMap<String, Note> = HashMap() | |
private val mutableNotes: MutableLiveData<List<Note>> = MutableLiveData() | |
init { | |
updateList() |
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.datasources | |
import android.arch.paging.DataSource | |
import android.arch.paging.ItemKeyedDataSource | |
import android.util.Log | |
import com.shellmonger.apps.mynotes.models.Note | |
class MockNotesDataSource : ItemKeyedDataSource<Int, Note>() { | |
companion object { | |
private val TAG = this::class.java.simpleName |
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
/** | |
* Load the initial items | |
*/ | |
override fun loadInitial(params: LoadInitialParams<Int>, callback: LoadInitialCallback<Note>) { | |
Log.d(TAG, "loadInitial: key=${params.requestedInitialKey ?: "undefined"}, size=${params.requestedLoadSize}") | |
val pageSize = minOf(MAX_PAGE_SIZE, params.requestedLoadSize) | |
val firstItem = inRange(params.requestedInitialKey ?: 0,0, items.size) | |
val lastItem = inRange(firstItem + pageSize, 0, items.size) | |
Log.d(TAG, "loadInitial: firstItem = $firstItem, lastItem = $lastItem") | |
val data = if (firstItem == lastItem) emptyList<Note>() else items.subList(firstItem, lastItem) |