Last active
May 20, 2020 19:27
-
-
Save chelseatroy/c29aa38300ec572043c04075a1292185 to your computer and use it in GitHub Desktop.
Setting a Default Weather
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 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