Create form for numerical habits

pull/605/head
Alinson S. Xavier 5 years ago
parent ecb3978bdd
commit b9850fa085

@ -44,6 +44,7 @@ class EditHabitActivity : AppCompatActivity() {
private lateinit var commandRunner: CommandRunner
var habitId = -1L
var habitType = -1
var paletteColor = 11
var androidColor = 0
var freqNum = 1
@ -66,6 +67,7 @@ class EditHabitActivity : AppCompatActivity() {
binding.toolbar.title = getString(R.string.edit_habit)
habitId = intent.getLongExtra("habitId", -1)
val habit = component.habitList.getById(habitId)!!
habitType = habit.type
paletteColor = habit.color
freqNum = habit.frequency.numerator
freqDen = habit.frequency.denominator
@ -77,10 +79,13 @@ class EditHabitActivity : AppCompatActivity() {
binding.nameInput.setText(habit.name)
binding.questionInput.setText(habit.question)
binding.notesInput.setText(habit.description)
} else {
habitType = intent.getIntExtra("habitType", Habit.YES_NO_HABIT)
}
if (state != null) {
habitId = state.getLong("habitId")
habitType = state.getInt("habitType")
paletteColor = state.getInt("paletteColor")
freqNum = state.getInt("freqNum")
freqDen = state.getInt("freqDen")
@ -91,6 +96,15 @@ class EditHabitActivity : AppCompatActivity() {
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)
supportActionBar?.setDisplayHomeAsUpEnabled(true)
supportActionBar?.setDisplayShowHomeEnabled(true)
@ -238,6 +252,7 @@ class EditHabitActivity : AppCompatActivity() {
super.onSaveInstanceState(state)
with(state) {
putLong("habitId", habitId)
putInt("habitType", habitType)
putInt("paletteColor", paletteColor)
putInt("androidColor", androidColor)
putInt("freqNum", freqNum)

@ -23,6 +23,7 @@ import android.os.*
import android.view.*
import androidx.appcompat.app.*
import org.isoron.uhabits.*
import org.isoron.uhabits.core.models.*
import org.isoron.uhabits.databinding.*
import org.isoron.uhabits.intents.*
@ -35,16 +36,14 @@ class HabitTypeDialog : AppCompatDialogFragment() {
val binding = SelectHabitTypeBinding.inflate(inflater, container, false)
binding.buttonYesNo.setOnClickListener {
val intent = IntentFactory().startEditActivity(activity!!)
val intent = IntentFactory().startEditActivity(activity!!, Habit.YES_NO_HABIT)
startActivity(intent)
dismiss()
}
binding.buttonMeasurable.setOnClickListener {
dismiss()
}
binding.buttonSubjective.setOnClickListener{
val intent = IntentFactory().startEditActivity(activity!!, Habit.NUMBER_HABIT)
startActivity(intent)
dismiss()
}

@ -84,13 +84,20 @@ class IntentFactory
fun codeContributors(context: Context) =
buildViewIntent(context.getString(R.string.codeContributorsURL))
fun startEditActivity(context: Context): Intent {
private fun startEditActivity(context: Context): Intent {
return Intent(context, EditHabitActivity::class.java)
}
fun startEditActivity(context: Context, habit: Habit): Intent {
val intent = startEditActivity(context)
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
}
}

@ -49,55 +49,45 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:paddingTop="8dp">
android:paddingTop="8dp"
android:paddingLeft="4dp"
android:paddingRight="4dp">
<!-- Title and color -->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
android:orientation="horizontal"
android:baselineAligned="false">
<!-- Habit Title -->
<FrameLayout
style="@style/FormOuterBox"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:clipChildren="false"
android:clipToPadding="false"
android:orientation="vertical"
android:padding="8dp">
android:layout_weight="1">
<LinearLayout style="@style/FormInnerBox">
<TextView
style="@style/FormLabel"
android:text="@string/name" />
<EditText
android:id="@+id/nameInput"
style="@style/FormInput"
android:maxLines="1"
android:inputType="textCapSentences"
android:hint="@string/exercise_habit_name"
android:hint="@string/yes_or_no_short_example"
/>
</LinearLayout>
</FrameLayout>
<!-- Habit Color -->
<FrameLayout
style="@style/FormOuterBox"
android:layout_width="80dp"
android:layout_height="match_parent"
android:clipChildren="false"
android:clipToPadding="false"
android:orientation="vertical"
android:padding="8dp"
android:paddingStart="0dp">
android:layout_height="match_parent">
<LinearLayout style="@style/FormInnerBox">
<TextView
style="@style/FormLabel"
android:text="Color" />
android:text="@string/color" />
<androidx.appcompat.widget.AppCompatButton
android:id="@+id/colorButton"
android:layout_width="match_parent"
@ -110,26 +100,14 @@
</LinearLayout>
</FrameLayout>
</LinearLayout>
<!-- Habit Question -->
<FrameLayout
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">
<FrameLayout style="@style/FormOuterBox">
<LinearLayout style="@style/FormInnerBox">
<TextView
style="@style/FormLabel"
android:text="@string/question" />
<EditText
android:id="@+id/questionInput"
style="@style/FormInput"
@ -141,36 +119,74 @@
<!-- Frequency -->
<FrameLayout
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">
android:id="@+id/frequencyOuterBox"
style="@style/FormOuterBox">
<LinearLayout style="@style/FormInnerBox">
<TextView
style="@style/FormLabel"
android:text="@string/frequency" />
<TextView
style="@style/FormDropdown"
android:id="@+id/frequencyPicker"
android:textColor="?attr/highContrastTextColor"
/>
android:text="@string/every_day" />
</LinearLayout>
</FrameLayout>
<!-- Reminder -->
<!-- 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:clipChildren="false"
android:clipToPadding="false"
android:orientation="vertical"
android:padding="8dp">
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"
/>
</LinearLayout>
</FrameLayout>
</LinearLayout>
<!-- Reminder -->
<FrameLayout style="@style/FormOuterBox">
<LinearLayout style="@style/FormInnerBox">
<TextView
style="@style/FormLabel"
@ -194,14 +210,7 @@
<!-- Notes -->
<FrameLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:clipChildren="false"
android:clipToPadding="false"
android:orientation="vertical"
android:padding="8dp">
<FrameLayout style="@style/FormOuterBox">
<LinearLayout style="@style/FormInnerBox">
<TextView
style="@style/FormLabel"

@ -67,23 +67,23 @@
android:text="@string/measurable_example" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/buttonSubjective"
style="@style/SelectHabitTypeButton">
<!-- <LinearLayout-->
<!-- android:layout_width="match_parent"-->
<!-- android:layout_height="wrap_content"-->
<!-- android:id="@+id/buttonSubjective"-->
<!-- style="@style/SelectHabitTypeButton">-->
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
style="@style/SelectHabitTypeButtonTitle"
android:text="@string/subjective" />
<!-- <TextView-->
<!-- android:layout_width="wrap_content"-->
<!-- android:layout_height="wrap_content"-->
<!-- style="@style/SelectHabitTypeButtonTitle"-->
<!-- android:text="@string/subjective" />-->
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
style="@style/SelectHabitTypeButtonBody"
android:text="@string/subjective_example" />
</LinearLayout>
<!-- <TextView-->
<!-- android:layout_width="wrap_content"-->
<!-- android:layout_height="wrap_content"-->
<!-- style="@style/SelectHabitTypeButtonBody"-->
<!-- android:text="@string/subjective_example" />-->
<!-- </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="x_times_per_week">%d times per week</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>

@ -303,7 +303,7 @@
<item name="android:layout_width">wrap_content</item>
<item name="android:layout_height">wrap_content</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:background">?attr/highContrastReverseTextColor</item>
<item name="android:paddingStart">8dp</item>
@ -326,8 +326,10 @@
<item name="android:layout_width">match_parent</item>
<item name="android:layout_height">wrap_content</item>
<item name="android:drawableEnd">@drawable/ic_arrow_drop_down_dark</item>
<item name="android:padding">16dp</item>
<item name="android:text">@string/every_day</item>
<item name="android:paddingTop">16dp</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>
</style>
@ -340,6 +342,18 @@
<item name="android:layout_height">match_parent</item>
</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">
<item name="android:layout_width">match_parent</item>
<item name="android:layout_height">1dp</item>

Loading…
Cancel
Save