Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Setting a Default Weather
class MoodEntryFragment : DialogFragment() {
var weather = Weather.UNKNOWN
...
override fun onResume() {
super.onResume()
...
val logMoodButton = view?.findViewById<Button>(R.id.log_mood_button)
logMoodButton?.setOnClickListener({ view ->
if (!this::currentMood.isInitialized) {
instructGuestToChooseAMood(view)
} else {
submitMoodEntry(checkBoxList, notesEditText)
dismiss()
}
})
}
fun onRadioButtonClicked(view: View) {
if (view is RadioButton) {
val checked = view.isChecked
when (view.getId()) {
R.id.radio_rainy -> if (checked) this.weather = Weather.RAINY else this.weather = Weather.UNKNOWN
R.id.radio_sunny -> if (checked) this.weather = Weather.SUNNY else this.weather = Weather.UNKNOWN
R.id.radio_cloudy -> if (checked) this.weather = Weather.CLOUDY else this.weather = Weather.UNKNOWN
}
}
}
private fun submitMoodEntry(
checkBoxList: ArrayList<CheckBox>,
notesEditText: EditText?
) {
var moodEntry = MoodEntry(currentMood)
moodEntry.recentPastimes = ArrayList(
checkBoxList
.filter { checkBox -> checkBox.isChecked }
.map { checkBox -> Pastime.valueOf(checkBox.text.toString()) })
moodEntry.notes = notesEditText?.text.toString()
moodEntry.weather = weather
Log.i("SUBMITTED MOOD ENTRY", moodEntry.toString())
val databaseHelper = MoodEntrySQLiteDBHelper(activity)
databaseHelper.save(moodEntry)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment