Skip to content

Instantly share code, notes, and snippets.

@adrianhall
Created May 13, 2018 04:50
Show Gist options
  • Save adrianhall/616e0cd7646cb913afe099d850ec1f9a to your computer and use it in GitHub Desktop.
Save adrianhall/616e0cd7646cb913afe099d850ec1f9a 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
class NoteDetailActivity : AppCompatActivity() {
companion object {
private val TAG = this::class.java.simpleName
const val ARG_NOTE = "noteId"
}
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_note_detail)
if (intent.extras.containsKey(ARG_NOTE)) {
val noteId = intent.extras.getString(ARG_NOTE)
loadFragment(noteId)
} else {
loadFragment(null)
}
}
private fun loadFragment(noteId: String?) {
Log.d(TAG, "Loading fragment for note $noteId")
val fragment = NoteDetailFragment()
noteId?.let {
fragment.arguments = Bundle().apply { putString(NoteDetailFragment.ARG_NOTE, noteId) }
}
supportFragmentManager
?.beginTransaction()
?.replace(R.id.note_detail_fragment, fragment)
?.commit()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment