Skip to content

Instantly share code, notes, and snippets.

@adrianhall
Created May 13, 2018 03:05
Show Gist options
  • Save adrianhall/08e2d91c0bd5fee070d129f07a9a4978 to your computer and use it in GitHub Desktop.
Save adrianhall/08e2d91c0bd5fee070d129f07a9a4978 to your computer and use it in GitHub Desktop.
package com.shellmonger.apps.mynotes.ui
import android.support.v7.app.AppCompatActivity
import android.os.Bundle
import android.util.Log
import com.shellmonger.apps.mynotes.R
import com.shellmonger.apps.mynotes.extensions.set
import com.shellmonger.apps.mynotes.models.Note
import kotlinx.android.synthetic.main.activity_note_detail.*
/**
* Handles the detail page of a note, allowing the user to edit it.
*/
class NoteDetailActivity : AppCompatActivity() {
companion object {
private val TAG = this::class.java.simpleName
}
/**
* The current note
*/
private val currentNote = Note().apply {
title = "example title"
content = "example content"
}
/**
* Lifecycle event handler, called when the activity is first created.
*/
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_note_detail)
}
/**
* Lifecycle event handler, called when the activity is resumed
*/
override fun onResume() {
super.onResume()
loadNote()
}
/**
* Lifecycle event handler, called when the activity is paused
*/
override fun onPause() {
super.onPause()
saveNote()
}
private fun loadNote() {
Log.d(TAG, "Note is being loaded")
// Load the note
// Fill in the details from the note
detail_id_field.text = currentNote.noteId
detail_title_editor.text.set(currentNote.title)
detail_content_editor.text.set(currentNote.content)
}
private fun saveNote() {
Log.d(TAG, "Note is being saved")
// Store the details back into the note
currentNote.title = detail_title_editor.text.toString()
currentNote.content = detail_content_editor.text.toString()
// Save the note
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment