mirror of
https://github.com/iSoron/uhabits.git
synced 2025-12-06 09:08:52 -06:00
Create form for numerical habits
This commit is contained in:
@@ -44,6 +44,7 @@ class EditHabitActivity : AppCompatActivity() {
|
|||||||
private lateinit var commandRunner: CommandRunner
|
private lateinit var commandRunner: CommandRunner
|
||||||
|
|
||||||
var habitId = -1L
|
var habitId = -1L
|
||||||
|
var habitType = -1
|
||||||
var paletteColor = 11
|
var paletteColor = 11
|
||||||
var androidColor = 0
|
var androidColor = 0
|
||||||
var freqNum = 1
|
var freqNum = 1
|
||||||
@@ -66,6 +67,7 @@ class EditHabitActivity : AppCompatActivity() {
|
|||||||
binding.toolbar.title = getString(R.string.edit_habit)
|
binding.toolbar.title = getString(R.string.edit_habit)
|
||||||
habitId = intent.getLongExtra("habitId", -1)
|
habitId = intent.getLongExtra("habitId", -1)
|
||||||
val habit = component.habitList.getById(habitId)!!
|
val habit = component.habitList.getById(habitId)!!
|
||||||
|
habitType = habit.type
|
||||||
paletteColor = habit.color
|
paletteColor = habit.color
|
||||||
freqNum = habit.frequency.numerator
|
freqNum = habit.frequency.numerator
|
||||||
freqDen = habit.frequency.denominator
|
freqDen = habit.frequency.denominator
|
||||||
@@ -77,10 +79,13 @@ class EditHabitActivity : AppCompatActivity() {
|
|||||||
binding.nameInput.setText(habit.name)
|
binding.nameInput.setText(habit.name)
|
||||||
binding.questionInput.setText(habit.question)
|
binding.questionInput.setText(habit.question)
|
||||||
binding.notesInput.setText(habit.description)
|
binding.notesInput.setText(habit.description)
|
||||||
|
} else {
|
||||||
|
habitType = intent.getIntExtra("habitType", Habit.YES_NO_HABIT)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (state != null) {
|
if (state != null) {
|
||||||
habitId = state.getLong("habitId")
|
habitId = state.getLong("habitId")
|
||||||
|
habitType = state.getInt("habitType")
|
||||||
paletteColor = state.getInt("paletteColor")
|
paletteColor = state.getInt("paletteColor")
|
||||||
freqNum = state.getInt("freqNum")
|
freqNum = state.getInt("freqNum")
|
||||||
freqDen = state.getInt("freqDen")
|
freqDen = state.getInt("freqDen")
|
||||||
@@ -91,6 +96,15 @@ class EditHabitActivity : AppCompatActivity() {
|
|||||||
|
|
||||||
updateColors()
|
updateColors()
|
||||||
|
|
||||||
|
if (habitType == Habit.YES_NO_HABIT) {
|
||||||
|
binding.unitOuterBox.visibility = View.GONE
|
||||||
|
binding.targetOuterBox.visibility = View.GONE
|
||||||
|
} else {
|
||||||
|
binding.nameInput.hint = getString(R.string.measurable_short_example)
|
||||||
|
binding.questionInput.hint = getString(R.string.measurable_question_example)
|
||||||
|
binding.frequencyOuterBox.visibility = View.GONE
|
||||||
|
}
|
||||||
|
|
||||||
setSupportActionBar(binding.toolbar)
|
setSupportActionBar(binding.toolbar)
|
||||||
supportActionBar?.setDisplayHomeAsUpEnabled(true)
|
supportActionBar?.setDisplayHomeAsUpEnabled(true)
|
||||||
supportActionBar?.setDisplayShowHomeEnabled(true)
|
supportActionBar?.setDisplayShowHomeEnabled(true)
|
||||||
@@ -238,6 +252,7 @@ class EditHabitActivity : AppCompatActivity() {
|
|||||||
super.onSaveInstanceState(state)
|
super.onSaveInstanceState(state)
|
||||||
with(state) {
|
with(state) {
|
||||||
putLong("habitId", habitId)
|
putLong("habitId", habitId)
|
||||||
|
putInt("habitType", habitType)
|
||||||
putInt("paletteColor", paletteColor)
|
putInt("paletteColor", paletteColor)
|
||||||
putInt("androidColor", androidColor)
|
putInt("androidColor", androidColor)
|
||||||
putInt("freqNum", freqNum)
|
putInt("freqNum", freqNum)
|
||||||
|
|||||||
@@ -23,6 +23,7 @@ import android.os.*
|
|||||||
import android.view.*
|
import android.view.*
|
||||||
import androidx.appcompat.app.*
|
import androidx.appcompat.app.*
|
||||||
import org.isoron.uhabits.*
|
import org.isoron.uhabits.*
|
||||||
|
import org.isoron.uhabits.core.models.*
|
||||||
import org.isoron.uhabits.databinding.*
|
import org.isoron.uhabits.databinding.*
|
||||||
import org.isoron.uhabits.intents.*
|
import org.isoron.uhabits.intents.*
|
||||||
|
|
||||||
@@ -35,16 +36,14 @@ class HabitTypeDialog : AppCompatDialogFragment() {
|
|||||||
val binding = SelectHabitTypeBinding.inflate(inflater, container, false)
|
val binding = SelectHabitTypeBinding.inflate(inflater, container, false)
|
||||||
|
|
||||||
binding.buttonYesNo.setOnClickListener {
|
binding.buttonYesNo.setOnClickListener {
|
||||||
val intent = IntentFactory().startEditActivity(activity!!)
|
val intent = IntentFactory().startEditActivity(activity!!, Habit.YES_NO_HABIT)
|
||||||
startActivity(intent)
|
startActivity(intent)
|
||||||
dismiss()
|
dismiss()
|
||||||
}
|
}
|
||||||
|
|
||||||
binding.buttonMeasurable.setOnClickListener {
|
binding.buttonMeasurable.setOnClickListener {
|
||||||
dismiss()
|
val intent = IntentFactory().startEditActivity(activity!!, Habit.NUMBER_HABIT)
|
||||||
}
|
startActivity(intent)
|
||||||
|
|
||||||
binding.buttonSubjective.setOnClickListener{
|
|
||||||
dismiss()
|
dismiss()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -84,13 +84,20 @@ class IntentFactory
|
|||||||
fun codeContributors(context: Context) =
|
fun codeContributors(context: Context) =
|
||||||
buildViewIntent(context.getString(R.string.codeContributorsURL))
|
buildViewIntent(context.getString(R.string.codeContributorsURL))
|
||||||
|
|
||||||
fun startEditActivity(context: Context): Intent {
|
private fun startEditActivity(context: Context): Intent {
|
||||||
return Intent(context, EditHabitActivity::class.java)
|
return Intent(context, EditHabitActivity::class.java)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun startEditActivity(context: Context, habit: Habit): Intent {
|
fun startEditActivity(context: Context, habit: Habit): Intent {
|
||||||
val intent = startEditActivity(context)
|
val intent = startEditActivity(context)
|
||||||
intent.putExtra("habitId", habit.id)
|
intent.putExtra("habitId", habit.id)
|
||||||
|
intent.putExtra("habitType", habit.type)
|
||||||
|
return intent
|
||||||
|
}
|
||||||
|
|
||||||
|
fun startEditActivity(context: Context, habitType: Int): Intent {
|
||||||
|
val intent = startEditActivity(context)
|
||||||
|
intent.putExtra("habitType", habitType)
|
||||||
return intent
|
return intent
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -49,55 +49,45 @@
|
|||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:orientation="vertical"
|
android:orientation="vertical"
|
||||||
android:paddingTop="8dp">
|
android:paddingTop="8dp"
|
||||||
|
android:paddingLeft="4dp"
|
||||||
|
android:paddingRight="4dp">
|
||||||
|
|
||||||
<!-- Title and color -->
|
<!-- Title and color -->
|
||||||
<LinearLayout
|
<LinearLayout
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:orientation="horizontal">
|
android:orientation="horizontal"
|
||||||
|
android:baselineAligned="false">
|
||||||
|
|
||||||
<!-- Habit Title -->
|
<!-- Habit Title -->
|
||||||
<FrameLayout
|
<FrameLayout
|
||||||
|
style="@style/FormOuterBox"
|
||||||
android:layout_width="0dp"
|
android:layout_width="0dp"
|
||||||
android:layout_height="wrap_content"
|
android:layout_weight="1">
|
||||||
android:layout_weight="1"
|
|
||||||
android:clipChildren="false"
|
|
||||||
android:clipToPadding="false"
|
|
||||||
android:orientation="vertical"
|
|
||||||
android:padding="8dp">
|
|
||||||
|
|
||||||
<LinearLayout style="@style/FormInnerBox">
|
<LinearLayout style="@style/FormInnerBox">
|
||||||
<TextView
|
<TextView
|
||||||
style="@style/FormLabel"
|
style="@style/FormLabel"
|
||||||
android:text="@string/name" />
|
android:text="@string/name" />
|
||||||
|
|
||||||
<EditText
|
<EditText
|
||||||
android:id="@+id/nameInput"
|
android:id="@+id/nameInput"
|
||||||
style="@style/FormInput"
|
style="@style/FormInput"
|
||||||
android:maxLines="1"
|
android:maxLines="1"
|
||||||
android:inputType="textCapSentences"
|
android:inputType="textCapSentences"
|
||||||
android:hint="@string/exercise_habit_name"
|
android:hint="@string/yes_or_no_short_example"
|
||||||
/>
|
/>
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
</FrameLayout>
|
</FrameLayout>
|
||||||
|
|
||||||
<!-- Habit Color -->
|
<!-- Habit Color -->
|
||||||
<FrameLayout
|
<FrameLayout
|
||||||
|
style="@style/FormOuterBox"
|
||||||
android:layout_width="80dp"
|
android:layout_width="80dp"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent">
|
||||||
android:clipChildren="false"
|
|
||||||
android:clipToPadding="false"
|
|
||||||
android:orientation="vertical"
|
|
||||||
android:padding="8dp"
|
|
||||||
android:paddingStart="0dp">
|
|
||||||
|
|
||||||
<LinearLayout style="@style/FormInnerBox">
|
<LinearLayout style="@style/FormInnerBox">
|
||||||
<TextView
|
<TextView
|
||||||
style="@style/FormLabel"
|
style="@style/FormLabel"
|
||||||
android:text="Color" />
|
android:text="@string/color" />
|
||||||
|
|
||||||
<androidx.appcompat.widget.AppCompatButton
|
<androidx.appcompat.widget.AppCompatButton
|
||||||
android:id="@+id/colorButton"
|
android:id="@+id/colorButton"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
@@ -110,26 +100,14 @@
|
|||||||
|
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
</FrameLayout>
|
</FrameLayout>
|
||||||
|
|
||||||
|
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
|
||||||
|
|
||||||
<!-- Habit Question -->
|
<!-- Habit Question -->
|
||||||
<FrameLayout
|
<FrameLayout style="@style/FormOuterBox">
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:clipChildren="false"
|
|
||||||
android:clipToPadding="false"
|
|
||||||
android:orientation="vertical"
|
|
||||||
android:padding="8dp"
|
|
||||||
android:paddingTop="4dp">
|
|
||||||
|
|
||||||
<LinearLayout style="@style/FormInnerBox">
|
<LinearLayout style="@style/FormInnerBox">
|
||||||
<TextView
|
<TextView
|
||||||
style="@style/FormLabel"
|
style="@style/FormLabel"
|
||||||
android:text="@string/question" />
|
android:text="@string/question" />
|
||||||
|
|
||||||
<EditText
|
<EditText
|
||||||
android:id="@+id/questionInput"
|
android:id="@+id/questionInput"
|
||||||
style="@style/FormInput"
|
style="@style/FormInput"
|
||||||
@@ -141,36 +119,74 @@
|
|||||||
|
|
||||||
<!-- Frequency -->
|
<!-- Frequency -->
|
||||||
<FrameLayout
|
<FrameLayout
|
||||||
android:layout_width="match_parent"
|
android:id="@+id/frequencyOuterBox"
|
||||||
android:layout_height="wrap_content"
|
style="@style/FormOuterBox">
|
||||||
android:clipChildren="false"
|
|
||||||
android:clipToPadding="false"
|
|
||||||
android:orientation="vertical"
|
|
||||||
android:padding="8dp"
|
|
||||||
android:paddingTop="4dp">
|
|
||||||
|
|
||||||
<LinearLayout style="@style/FormInnerBox">
|
<LinearLayout style="@style/FormInnerBox">
|
||||||
<TextView
|
<TextView
|
||||||
style="@style/FormLabel"
|
style="@style/FormLabel"
|
||||||
android:text="@string/frequency" />
|
android:text="@string/frequency" />
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
style="@style/FormDropdown"
|
style="@style/FormDropdown"
|
||||||
android:id="@+id/frequencyPicker"
|
android:id="@+id/frequencyPicker"
|
||||||
|
android:text="@string/every_day" />
|
||||||
|
</LinearLayout>
|
||||||
|
</FrameLayout>
|
||||||
|
|
||||||
|
<!-- Target value, unit and frequency -->
|
||||||
|
<FrameLayout
|
||||||
|
android:id="@+id/unitOuterBox"
|
||||||
|
style="@style/FormOuterBox">
|
||||||
|
<LinearLayout style="@style/FormInnerBox">
|
||||||
|
<TextView
|
||||||
|
style="@style/FormLabel"
|
||||||
|
android:text="@string/unit" />
|
||||||
|
<EditText
|
||||||
|
style="@style/FormInput"
|
||||||
|
android:maxLines="1"
|
||||||
|
android:ems="10"
|
||||||
|
android:hint="@string/measurable_units_example"/>
|
||||||
|
</LinearLayout>
|
||||||
|
</FrameLayout>
|
||||||
|
<LinearLayout
|
||||||
|
android:id="@+id/targetOuterBox"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:orientation="horizontal"
|
||||||
|
android:baselineAligned="false">
|
||||||
|
<FrameLayout
|
||||||
|
style="@style/FormOuterBox"
|
||||||
|
android:layout_width="0dp"
|
||||||
|
android:layout_weight="1">
|
||||||
|
<LinearLayout style="@style/FormInnerBox">
|
||||||
|
<TextView
|
||||||
|
style="@style/FormLabel"
|
||||||
|
android:text="@string/target" />
|
||||||
|
<EditText
|
||||||
|
style="@style/FormInput"
|
||||||
|
android:maxLines="1"
|
||||||
|
android:inputType="number"
|
||||||
|
android:hint="@string/example_target"/>
|
||||||
|
</LinearLayout>
|
||||||
|
</FrameLayout>
|
||||||
|
<FrameLayout
|
||||||
|
style="@style/FormOuterBox"
|
||||||
|
android:layout_width="0dp"
|
||||||
|
android:layout_weight="1">
|
||||||
|
<LinearLayout style="@style/FormInnerBox">
|
||||||
|
<TextView
|
||||||
|
style="@style/FormLabel"
|
||||||
|
android:text="@string/frequency" />
|
||||||
|
<TextView
|
||||||
|
style="@style/FormDropdown"
|
||||||
|
android:text="@string/every_week"
|
||||||
android:textColor="?attr/highContrastTextColor"
|
android:textColor="?attr/highContrastTextColor"
|
||||||
/>
|
/>
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
</FrameLayout>
|
</FrameLayout>
|
||||||
|
</LinearLayout>
|
||||||
|
|
||||||
<!-- Reminder -->
|
<!-- Reminder -->
|
||||||
<FrameLayout
|
<FrameLayout style="@style/FormOuterBox">
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:clipChildren="false"
|
|
||||||
android:clipToPadding="false"
|
|
||||||
android:orientation="vertical"
|
|
||||||
android:padding="8dp">
|
|
||||||
|
|
||||||
<LinearLayout style="@style/FormInnerBox">
|
<LinearLayout style="@style/FormInnerBox">
|
||||||
<TextView
|
<TextView
|
||||||
style="@style/FormLabel"
|
style="@style/FormLabel"
|
||||||
@@ -194,14 +210,7 @@
|
|||||||
|
|
||||||
|
|
||||||
<!-- Notes -->
|
<!-- Notes -->
|
||||||
<FrameLayout
|
<FrameLayout style="@style/FormOuterBox">
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:clipChildren="false"
|
|
||||||
android:clipToPadding="false"
|
|
||||||
android:orientation="vertical"
|
|
||||||
android:padding="8dp">
|
|
||||||
|
|
||||||
<LinearLayout style="@style/FormInnerBox">
|
<LinearLayout style="@style/FormInnerBox">
|
||||||
<TextView
|
<TextView
|
||||||
style="@style/FormLabel"
|
style="@style/FormLabel"
|
||||||
|
|||||||
@@ -67,23 +67,23 @@
|
|||||||
android:text="@string/measurable_example" />
|
android:text="@string/measurable_example" />
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
|
||||||
<LinearLayout
|
<!-- <LinearLayout-->
|
||||||
android:layout_width="match_parent"
|
<!-- android:layout_width="match_parent"-->
|
||||||
android:layout_height="wrap_content"
|
<!-- android:layout_height="wrap_content"-->
|
||||||
android:id="@+id/buttonSubjective"
|
<!-- android:id="@+id/buttonSubjective"-->
|
||||||
style="@style/SelectHabitTypeButton">
|
<!-- style="@style/SelectHabitTypeButton">-->
|
||||||
|
|
||||||
<TextView
|
<!-- <TextView-->
|
||||||
android:layout_width="wrap_content"
|
<!-- android:layout_width="wrap_content"-->
|
||||||
android:layout_height="wrap_content"
|
<!-- android:layout_height="wrap_content"-->
|
||||||
style="@style/SelectHabitTypeButtonTitle"
|
<!-- style="@style/SelectHabitTypeButtonTitle"-->
|
||||||
android:text="@string/subjective" />
|
<!-- android:text="@string/subjective" />-->
|
||||||
|
|
||||||
<TextView
|
<!-- <TextView-->
|
||||||
android:layout_width="wrap_content"
|
<!-- android:layout_width="wrap_content"-->
|
||||||
android:layout_height="wrap_content"
|
<!-- android:layout_height="wrap_content"-->
|
||||||
style="@style/SelectHabitTypeButtonBody"
|
<!-- style="@style/SelectHabitTypeButtonBody"-->
|
||||||
android:text="@string/subjective_example" />
|
<!-- android:text="@string/subjective_example" />-->
|
||||||
</LinearLayout>
|
<!-- </LinearLayout>-->
|
||||||
|
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
@@ -254,6 +254,12 @@
|
|||||||
<string name="subjective_example">e.g. Are you felling happy today? Definitely, somewhat, not at all? How frequently did you snack? Very often, sometimes, never?</string>
|
<string name="subjective_example">e.g. Are you felling happy today? Definitely, somewhat, not at all? How frequently did you snack? Very often, sometimes, never?</string>
|
||||||
<string name="x_times_per_week">%d times per week</string>
|
<string name="x_times_per_week">%d times per week</string>
|
||||||
<string name="x_times_per_month">%d times per month</string>
|
<string name="x_times_per_month">%d times per month</string>
|
||||||
<string name="exercise_habit_name">e.g. Exercise</string>
|
<string name="yes_or_no_short_example">e.g. Exercise</string>
|
||||||
|
<string name="color">Color</string>
|
||||||
|
<string name="example_target">e.g. 15</string>
|
||||||
|
<string name="measurable_short_example">e.g. Run</string>
|
||||||
|
<string name="measurable_question_example">e.g. How many miles did you run today?</string>
|
||||||
|
<string name="measurable_units_example">e.g. miles</string>
|
||||||
|
|
||||||
|
|
||||||
</resources>
|
</resources>
|
||||||
@@ -303,7 +303,7 @@
|
|||||||
<item name="android:layout_width">wrap_content</item>
|
<item name="android:layout_width">wrap_content</item>
|
||||||
<item name="android:layout_height">wrap_content</item>
|
<item name="android:layout_height">wrap_content</item>
|
||||||
<item name="android:layout_marginStart">8dp</item>
|
<item name="android:layout_marginStart">8dp</item>
|
||||||
<item name="android:layout_marginTop">-17dp</item>
|
<item name="android:layout_marginTop">-15dp</item>
|
||||||
<item name="android:layout_marginBottom">-4dp</item>
|
<item name="android:layout_marginBottom">-4dp</item>
|
||||||
<item name="android:background">?attr/highContrastReverseTextColor</item>
|
<item name="android:background">?attr/highContrastReverseTextColor</item>
|
||||||
<item name="android:paddingStart">8dp</item>
|
<item name="android:paddingStart">8dp</item>
|
||||||
@@ -326,8 +326,10 @@
|
|||||||
<item name="android:layout_width">match_parent</item>
|
<item name="android:layout_width">match_parent</item>
|
||||||
<item name="android:layout_height">wrap_content</item>
|
<item name="android:layout_height">wrap_content</item>
|
||||||
<item name="android:drawableEnd">@drawable/ic_arrow_drop_down_dark</item>
|
<item name="android:drawableEnd">@drawable/ic_arrow_drop_down_dark</item>
|
||||||
<item name="android:padding">16dp</item>
|
<item name="android:paddingTop">16dp</item>
|
||||||
<item name="android:text">@string/every_day</item>
|
<item name="android:paddingBottom">14dp</item>
|
||||||
|
<item name="android:paddingLeft">16dp</item>
|
||||||
|
<item name="android:paddingRight">16dp</item>
|
||||||
<item name="android:textSize">@dimen/regularTextSize</item>
|
<item name="android:textSize">@dimen/regularTextSize</item>
|
||||||
</style>
|
</style>
|
||||||
|
|
||||||
@@ -340,6 +342,18 @@
|
|||||||
<item name="android:layout_height">match_parent</item>
|
<item name="android:layout_height">match_parent</item>
|
||||||
</style>
|
</style>
|
||||||
|
|
||||||
|
<style name="FormOuterBox">
|
||||||
|
<item name="android:layout_width">match_parent</item>
|
||||||
|
<item name="android:layout_height">wrap_content</item>
|
||||||
|
<item name="android:clipChildren">false</item>
|
||||||
|
<item name="android:clipToPadding">false</item>
|
||||||
|
<item name="android:orientation">vertical</item>
|
||||||
|
<item name="android:paddingBottom">8dp</item>
|
||||||
|
<item name="android:paddingTop">4dp</item>
|
||||||
|
<item name="android:paddingLeft">4dp</item>
|
||||||
|
<item name="android:paddingRight">4dp</item>
|
||||||
|
</style>
|
||||||
|
|
||||||
<style name="FormDivider">
|
<style name="FormDivider">
|
||||||
<item name="android:layout_width">match_parent</item>
|
<item name="android:layout_width">match_parent</item>
|
||||||
<item name="android:layout_height">1dp</item>
|
<item name="android:layout_height">1dp</item>
|
||||||
|
|||||||
Reference in New Issue
Block a user