forked from penguin86/luna-tracker
Compare commits
1 Commits
bottle_tim
...
fixpuke
| Author | SHA1 | Date | |
|---|---|---|---|
| 6f3061974d |
@@ -21,7 +21,6 @@ import android.widget.Toast
|
|||||||
import androidx.appcompat.app.AlertDialog
|
import androidx.appcompat.app.AlertDialog
|
||||||
import androidx.appcompat.app.AppCompatActivity
|
import androidx.appcompat.app.AppCompatActivity
|
||||||
import androidx.core.content.ContextCompat
|
import androidx.core.content.ContextCompat
|
||||||
import androidx.core.widget.doOnTextChanged
|
|
||||||
import androidx.recyclerview.widget.LinearLayoutManager
|
import androidx.recyclerview.widget.LinearLayoutManager
|
||||||
import androidx.recyclerview.widget.RecyclerView
|
import androidx.recyclerview.widget.RecyclerView
|
||||||
import com.google.android.material.progressindicator.LinearProgressIndicator
|
import com.google.android.material.progressindicator.LinearProgressIndicator
|
||||||
@@ -196,59 +195,23 @@ class MainActivity : AppCompatActivity() {
|
|||||||
super.onStop()
|
super.onStop()
|
||||||
}
|
}
|
||||||
|
|
||||||
fun getAllEvents(): ArrayList<LunaEvent> {
|
|
||||||
return logbook?.logs ?: arrayListOf()
|
|
||||||
}
|
|
||||||
|
|
||||||
fun askBabyBottleContent() {
|
fun askBabyBottleContent() {
|
||||||
// Show number picker dialog
|
// Show number picker dialog
|
||||||
val event = LunaEvent(LunaEvent.TYPE_BABY_BOTTLE)
|
val localSettings = LocalSettingsRepository(this)
|
||||||
val previous = getPreviousSameEvent(event, getAllEvents())
|
|
||||||
val d = AlertDialog.Builder(this)
|
val d = AlertDialog.Builder(this)
|
||||||
val dialogView = layoutInflater.inflate(R.layout.number_picker_dialog, null)
|
val dialogView = layoutInflater.inflate(R.layout.number_picker_dialog, null)
|
||||||
d.setTitle(R.string.log_bottle_dialog_title)
|
d.setTitle(R.string.log_bottle_dialog_title)
|
||||||
d.setMessage(R.string.log_bottle_dialog_description)
|
d.setMessage(R.string.log_bottle_dialog_description)
|
||||||
d.setView(dialogView)
|
d.setView(dialogView)
|
||||||
|
|
||||||
val numberPicker = dialogView.findViewById<NumberPicker>(R.id.dialog_number_picker)
|
val numberPicker = dialogView.findViewById<NumberPicker>(R.id.dialog_number_picker)
|
||||||
numberPicker.minValue = 1 // "10"
|
numberPicker.minValue = 1 // "10"
|
||||||
numberPicker.maxValue = 25 // "250
|
numberPicker.maxValue = 25 // "250
|
||||||
numberPicker.displayedValues = ((10..250 step 10).map { it.toString() }.toTypedArray())
|
numberPicker.displayedValues = ((10..250 step 10).map { it.toString() }.toTypedArray())
|
||||||
numberPicker.wrapSelectorWheel = false
|
numberPicker.wrapSelectorWheel = false
|
||||||
if (previous != null) {
|
numberPicker.value = localSettings.loadBabyBottleContent()
|
||||||
numberPicker.value = previous.quantity / 10
|
|
||||||
}
|
|
||||||
|
|
||||||
val currentDateTime = Calendar.getInstance()
|
|
||||||
currentDateTime.time = Date(event.time * 1000)
|
|
||||||
val dateTextView = dialogView.findViewById<TextView>(R.id.dialog_date_picker)
|
|
||||||
dateTextView.text =
|
|
||||||
String.format(getString(R.string.dialog_event_detail_datetime_icon), DateUtils.formatDateTime(event.time))
|
|
||||||
dateTextView.setOnClickListener {
|
|
||||||
// Show datetime picker
|
|
||||||
val startYear = currentDateTime.get(Calendar.YEAR)
|
|
||||||
val startMonth = currentDateTime.get(Calendar.MONTH)
|
|
||||||
val startDay = currentDateTime.get(Calendar.DAY_OF_MONTH)
|
|
||||||
val startHour = currentDateTime.get(Calendar.HOUR_OF_DAY)
|
|
||||||
val startMinute = currentDateTime.get(Calendar.MINUTE)
|
|
||||||
|
|
||||||
DatePickerDialog(this, { _, year, month, day ->
|
|
||||||
TimePickerDialog(this, { _, hour, minute ->
|
|
||||||
val pickedDateTime = Calendar.getInstance()
|
|
||||||
pickedDateTime.set(year, month, day, hour, minute)
|
|
||||||
// Save event and move it to the right position in the logbook
|
|
||||||
event.time = pickedDateTime.time.time / 1000 // Seconds since epoch
|
|
||||||
dateTextView.text = String.format(getString(R.string.dialog_event_detail_datetime_icon), DateUtils.formatDateTime(event.time))
|
|
||||||
}, startHour, startMinute, android.text.format.DateFormat.is24HourFormat(this@MainActivity)).show()
|
|
||||||
}, startYear, startMonth, startDay).show()
|
|
||||||
}
|
|
||||||
|
|
||||||
d.setPositiveButton(android.R.string.ok) { dialogInterface, i ->
|
d.setPositiveButton(android.R.string.ok) { dialogInterface, i ->
|
||||||
event.quantity = numberPicker.value * 10
|
logEvent(LunaEvent(LunaEvent.TYPE_BABY_BOTTLE, numberPicker.value * 10))
|
||||||
logEvent(event)
|
localSettings.saveBabyBottleContent(numberPicker.value)
|
||||||
logbook?.sort()
|
|
||||||
recyclerView.adapter?.notifyDataSetChanged()
|
|
||||||
saveLogbook()
|
|
||||||
}
|
}
|
||||||
d.setNegativeButton(android.R.string.cancel) { dialogInterface, i -> dialogInterface.dismiss() }
|
d.setNegativeButton(android.R.string.cancel) { dialogInterface, i -> dialogInterface.dismiss() }
|
||||||
val alertDialog = d.create()
|
val alertDialog = d.create()
|
||||||
@@ -312,7 +275,7 @@ class MainActivity : AppCompatActivity() {
|
|||||||
|
|
||||||
d.setPositiveButton(android.R.string.ok) { dialogInterface, i ->
|
d.setPositiveButton(android.R.string.ok) { dialogInterface, i ->
|
||||||
val pos = spinner.selectedItemPosition
|
val pos = spinner.selectedItemPosition
|
||||||
logEvent(LunaEvent(LunaEvent.TYPE_PUKE, pos))
|
logEvent(LunaEvent(LunaEvent.TYPE_PUKE, pos + 1))
|
||||||
}
|
}
|
||||||
d.setNegativeButton(android.R.string.cancel) { dialogInterface, i -> dialogInterface.dismiss() }
|
d.setNegativeButton(android.R.string.cancel) { dialogInterface, i -> dialogInterface.dismiss() }
|
||||||
val alertDialog = d.create()
|
val alertDialog = d.create()
|
||||||
|
|||||||
@@ -23,6 +23,14 @@ class LocalSettingsRepository(val context: Context) {
|
|||||||
sharedPreferences = context.getSharedPreferences(SHARED_PREFS_FILE_NAME, MODE_PRIVATE)
|
sharedPreferences = context.getSharedPreferences(SHARED_PREFS_FILE_NAME, MODE_PRIVATE)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun saveBabyBottleContent(content: Int) {
|
||||||
|
sharedPreferences.edit { putInt(SHARED_PREFS_BB_CONTENT, content) }
|
||||||
|
}
|
||||||
|
|
||||||
|
fun loadBabyBottleContent(): Int {
|
||||||
|
return sharedPreferences.getInt(SHARED_PREFS_BB_CONTENT, 1)
|
||||||
|
}
|
||||||
|
|
||||||
fun saveSignature(content: String) {
|
fun saveSignature(content: String) {
|
||||||
sharedPreferences.edit { putString(SHARED_PREFS_SIGNATURE, content) }
|
sharedPreferences.edit { putString(SHARED_PREFS_SIGNATURE, content) }
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -67,7 +67,7 @@ class NumericUtils (val context: Context) {
|
|||||||
LunaEvent.TYPE_TEMPERATURE ->
|
LunaEvent.TYPE_TEMPERATURE ->
|
||||||
(item.quantity / 10.0f).toString()
|
(item.quantity / 10.0f).toString()
|
||||||
LunaEvent.TYPE_PUKE ->
|
LunaEvent.TYPE_PUKE ->
|
||||||
context.resources.getStringArray(R.array.AmountLabels)[item.quantity]
|
context.resources.getStringArray(R.array.AmountLabels)[item.quantity - 1]
|
||||||
else ->
|
else ->
|
||||||
item.quantity
|
item.quantity
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -1,16 +1,10 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<LinearLayout
|
<LinearLayout
|
||||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="match_parent"
|
|
||||||
android:orientation="vertical">
|
|
||||||
|
|
||||||
<LinearLayout
|
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
android:layout_gravity="center"
|
android:layout_gravity="center"
|
||||||
android:gravity="center"
|
android:gravity="center">
|
||||||
android:orientation="horizontal">
|
|
||||||
|
|
||||||
<NumberPicker
|
<NumberPicker
|
||||||
android:id="@+id/dialog_number_picker"
|
android:id="@+id/dialog_number_picker"
|
||||||
@@ -22,14 +16,4 @@
|
|||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_marginStart="10dp"
|
android:layout_marginStart="10dp"
|
||||||
android:text="ml"/>
|
android:text="ml"/>
|
||||||
|
|
||||||
</LinearLayout>
|
|
||||||
|
|
||||||
<TextView
|
|
||||||
android:id="@+id/dialog_date_picker"
|
|
||||||
android:layout_width="wrap_content"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:layout_gravity="center"
|
|
||||||
android:layout_marginEnd = "20dp"/>
|
|
||||||
|
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
|||||||
Reference in New Issue
Block a user