|
|
@@ -5,14 +5,11 @@ import android.os.Bundle
|
|
|
import android.view.LayoutInflater
|
|
|
import android.view.View
|
|
|
import android.view.ViewGroup
|
|
|
-import androidx.lifecycle.ViewModelProviders
|
|
|
import androidx.navigation.Navigation
|
|
|
import com.sduduzog.slimlauncher.R
|
|
|
-import com.sduduzog.slimlauncher.data.MainViewModel
|
|
|
import com.sduduzog.slimlauncher.data.model.Note
|
|
|
import com.sduduzog.slimlauncher.utils.BaseFragment
|
|
|
import kotlinx.android.synthetic.main.note_fragment.*
|
|
|
-import java.security.MessageDigest
|
|
|
|
|
|
|
|
|
class NoteFragment : BaseFragment() {
|
|
|
@@ -20,96 +17,33 @@ class NoteFragment : BaseFragment() {
|
|
|
override fun getFragmentView(): ViewGroup = note_fragment
|
|
|
|
|
|
private lateinit var note: Note
|
|
|
- private lateinit var viewModel: MainViewModel
|
|
|
- private lateinit var initialDigest: String
|
|
|
|
|
|
override fun onCreate(savedInstanceState: Bundle?) {
|
|
|
super.onCreate(savedInstanceState)
|
|
|
arguments.let {
|
|
|
- note = if (it !=null && it.containsKey("note")) {
|
|
|
- it.get("note") as Note
|
|
|
+ note = if (it != null && it.containsKey(getString(R.string.nav_key_note))) {
|
|
|
+ it.get(getString(R.string.nav_key_note)) as Note
|
|
|
} else {
|
|
|
- Note("", -1L)
|
|
|
+ Note("")
|
|
|
}
|
|
|
}
|
|
|
- initialDigest = hash(note.title + note.body)
|
|
|
- activity?.let {
|
|
|
- viewModel = ViewModelProviders.of(it).get(MainViewModel::class.java)
|
|
|
- } ?: throw Error("Activity null, something here is fucked up")
|
|
|
}
|
|
|
|
|
|
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?,
|
|
|
savedInstanceState: Bundle?): View? {
|
|
|
- // Inflate the layout for this fragment
|
|
|
return inflater.inflate(R.layout.note_fragment, container, false)
|
|
|
}
|
|
|
|
|
|
override fun onActivityCreated(savedInstanceState: Bundle?) {
|
|
|
super.onActivityCreated(savedInstanceState)
|
|
|
- note_fragment_edit.setOnClickListener(Navigation.createNavigateOnClickListener(R.id.action_noteFragment_to_editNoteFragment))
|
|
|
- }
|
|
|
-
|
|
|
-// override fun onActivityCreated(savedInstanceState: Bundle?) {
|
|
|
-// super.onActivityCreated(savedInstanceState)
|
|
|
-// if (note.edited == -1L) {
|
|
|
-// editBody()
|
|
|
-// } else {
|
|
|
-// bodyEditText.visibility = View.GONE
|
|
|
-// textBody.visibility = View.VISIBLE
|
|
|
-// textBody.text = note.body
|
|
|
-// titleEditText.setText(note.title.orEmpty())
|
|
|
-// bodyEditText.setText(note.body)
|
|
|
-// titleEditText.isEnabled = false
|
|
|
-// }
|
|
|
-// titleEditText.setOnEditorActionListener { _, _, _ ->
|
|
|
-// editBody()
|
|
|
-// true
|
|
|
-// }
|
|
|
-// textBody.setOnClickListener(object : DoubleClickListener() {
|
|
|
-// override fun onDoubleClick(v: View) {
|
|
|
-// titleEditText.isEnabled = true
|
|
|
-// editBody()
|
|
|
-// }
|
|
|
-//
|
|
|
-// override fun onSingleClick(v: View) {
|
|
|
-// // Do nothing
|
|
|
-// }
|
|
|
-// })
|
|
|
-// }
|
|
|
-
|
|
|
-// private fun editBody() {
|
|
|
-// textBody.visibility = View.GONE
|
|
|
-// bodyEditText.visibility = View.VISIBLE
|
|
|
-// if (bodyEditText.requestFocus()) {
|
|
|
-// val imm = activity!!.getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager
|
|
|
-// imm.showSoftInput(bodyEditText, InputMethodManager.SHOW_IMPLICIT)
|
|
|
-// bodyEditText.setSelection(note.body.length)
|
|
|
-// }
|
|
|
-// }
|
|
|
-
|
|
|
-// private fun saveNote() {
|
|
|
-// val body = bodyEditText.text.toString()
|
|
|
-// val title = titleEditText.text.toString()
|
|
|
-// val newNote = Note(body, Date().time)
|
|
|
-// newNote.title = if (title.isEmpty()) null else title
|
|
|
-// newNote.body = body.trim()
|
|
|
-// newNote.id = note.id
|
|
|
-// val currentDigest = hash(newNote.title + newNote.body)
|
|
|
-// if (body.isEmpty()) return
|
|
|
-// if (initialDigest == currentDigest) return
|
|
|
-// if (note.id == null) viewModel.add(newNote) else viewModel.update(newNote)
|
|
|
-//
|
|
|
-// }
|
|
|
-
|
|
|
- private fun hash(input: String): String {
|
|
|
- val bytes = input.toByteArray(charset("UTF-8"))
|
|
|
- val md = MessageDigest.getInstance("MD5")
|
|
|
- md.update(bytes)
|
|
|
- return String(md.digest())
|
|
|
+ note.title?.let {
|
|
|
+ note_fragment_title.text = it
|
|
|
+ }
|
|
|
+ note_fragment_body.text = note.body
|
|
|
+ val bundle = Bundle()
|
|
|
+ bundle.putSerializable(getString(R.string.nav_key_note), note)
|
|
|
+ note_fragment_edit.setOnClickListener(Navigation.createNavigateOnClickListener(R.id.action_noteFragment_to_editNoteFragment, bundle))
|
|
|
}
|
|
|
|
|
|
- override fun onBack(): Boolean {
|
|
|
- //saveNote()
|
|
|
- return false
|
|
|
- }
|
|
|
+ override fun onBack(): Boolean = false
|
|
|
}
|