mirror of
https://github.com/iSoron/uhabits.git
synced 2025-12-06 09:08:52 -06:00
Implement reminder day picker
This commit is contained in:
@@ -23,12 +23,14 @@ import android.content.res.*
|
||||
import android.graphics.*
|
||||
import android.os.*
|
||||
import android.text.format.*
|
||||
import android.view.*
|
||||
import androidx.appcompat.app.*
|
||||
import com.android.datetimepicker.time.*
|
||||
import org.isoron.androidbase.utils.*
|
||||
import org.isoron.uhabits.*
|
||||
import org.isoron.uhabits.activities.*
|
||||
import org.isoron.uhabits.activities.common.dialogs.*
|
||||
import org.isoron.uhabits.core.models.*
|
||||
import org.isoron.uhabits.core.preferences.*
|
||||
import org.isoron.uhabits.databinding.*
|
||||
import org.isoron.uhabits.preferences.*
|
||||
@@ -47,6 +49,7 @@ class EditHabitActivity : AppCompatActivity() {
|
||||
var freqDen = 1
|
||||
var reminderHour = -1
|
||||
var reminderMin = -1
|
||||
var reminderDays = WeekdayList.EVERY_DAY
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
@@ -84,6 +87,7 @@ class EditHabitActivity : AppCompatActivity() {
|
||||
dialog.show(supportFragmentManager, "frequencyPicker")
|
||||
}
|
||||
|
||||
populateReminder()
|
||||
binding.reminderTimePicker.setOnClickListener {
|
||||
val currentHour = if (reminderHour >= 0) reminderHour else 8
|
||||
val currentMin = if (reminderMin >= 0) reminderMin else 0
|
||||
@@ -97,12 +101,24 @@ class EditHabitActivity : AppCompatActivity() {
|
||||
override fun onTimeCleared(view: RadialPickerLayout?) {
|
||||
reminderHour = -1
|
||||
reminderMin = -1
|
||||
reminderDays = WeekdayList.EVERY_DAY
|
||||
populateReminder()
|
||||
}
|
||||
}, currentHour, currentMin, is24HourMode, androidColor)
|
||||
dialog.show(supportFragmentManager, "timePicker")
|
||||
}
|
||||
|
||||
binding.reminderDatePicker.setOnClickListener {
|
||||
val dialog = WeekdayPickerDialog()
|
||||
dialog.setListener { days ->
|
||||
reminderDays = days
|
||||
if (reminderDays.isEmpty) reminderDays = WeekdayList.EVERY_DAY
|
||||
populateReminder()
|
||||
}
|
||||
dialog.setSelectedDays(reminderDays)
|
||||
dialog.show(supportFragmentManager, "dayPicker")
|
||||
}
|
||||
|
||||
binding.buttonSave.setOnClickListener {
|
||||
finish()
|
||||
}
|
||||
@@ -111,9 +127,15 @@ class EditHabitActivity : AppCompatActivity() {
|
||||
private fun populateReminder() {
|
||||
if (reminderHour < 0) {
|
||||
binding.reminderTimePicker.text = getString(R.string.reminder_off)
|
||||
binding.reminderDatePicker.visibility = View.GONE
|
||||
binding.reminderDivider.visibility = View.GONE
|
||||
} else {
|
||||
val time = AndroidDateUtils.formatTime(this, reminderHour, reminderMin)
|
||||
val daysArray = reminderDays.toArray()
|
||||
binding.reminderTimePicker.text = time
|
||||
binding.reminderDatePicker.visibility = View.VISIBLE
|
||||
binding.reminderDivider.visibility = View.VISIBLE
|
||||
binding.reminderDatePicker.text = AndroidDateUtils.formatWeekdayList(this, daysArray)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -68,38 +68,20 @@
|
||||
android:orientation="vertical"
|
||||
android:padding="8dp">
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:background="@drawable/bg_input_group"
|
||||
android:clipChildren="false"
|
||||
android:clipToPadding="false"
|
||||
android:orientation="vertical">
|
||||
|
||||
<LinearLayout style="@style/FormInnerBox">
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="8dp"
|
||||
android:layout_marginTop="-17dp"
|
||||
android:layout_marginBottom="-4dp"
|
||||
android:background="?attr/highContrastReverseTextColor"
|
||||
android:paddingStart="8dp"
|
||||
android:paddingEnd="8dp"
|
||||
android:text="@string/name"
|
||||
android:textSize="@dimen/smallTextSize" />
|
||||
style="@style/FormLabel"
|
||||
android:text="@string/name" />
|
||||
|
||||
<EditText
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:background="@color/transparent"
|
||||
android:hint="e.g. Exercise"
|
||||
android:padding="16dp"
|
||||
android:textSize="@dimen/regularTextSize" />
|
||||
style="@style/FormInput"
|
||||
android:hint="@string/exercise_habit_name"
|
||||
/>
|
||||
</LinearLayout>
|
||||
</FrameLayout>
|
||||
|
||||
<!-- Habit Color -->
|
||||
<FrameLayout
|
||||
<FrameLayut
|
||||
android:layout_width="80dp"
|
||||
android:layout_height="match_parent"
|
||||
android:clipChildren="false"
|
||||
@@ -108,25 +90,10 @@
|
||||
android:padding="8dp"
|
||||
android:paddingStart="0dp">
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:background="@drawable/bg_input_group"
|
||||
android:clipChildren="false"
|
||||
android:clipToPadding="false"
|
||||
android:orientation="vertical">
|
||||
|
||||
<LinearLayout style="@style/FormInnerBox">
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="8dp"
|
||||
android:layout_marginTop="-17dp"
|
||||
android:layout_marginBottom="-4dp"
|
||||
android:background="?attr/highContrastReverseTextColor"
|
||||
android:paddingStart="8dp"
|
||||
android:paddingEnd="8dp"
|
||||
android:text="Color"
|
||||
android:textSize="@dimen/smallTextSize" />
|
||||
style="@style/FormLabel"
|
||||
android:text="Color" />
|
||||
|
||||
<androidx.appcompat.widget.AppCompatButton
|
||||
android:id="@+id/colorButton"
|
||||
@@ -139,7 +106,7 @@
|
||||
android:backgroundTint="#E23673" />
|
||||
|
||||
</LinearLayout>
|
||||
</FrameLayout>
|
||||
</FrameLayut>
|
||||
|
||||
|
||||
</LinearLayout>
|
||||
@@ -155,34 +122,15 @@
|
||||
android:padding="8dp"
|
||||
android:paddingTop="4dp">
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:background="@drawable/bg_input_group"
|
||||
android:clipChildren="false"
|
||||
android:clipToPadding="false"
|
||||
android:orientation="vertical">
|
||||
|
||||
<LinearLayout style="@style/FormInnerBox">
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="8dp"
|
||||
android:layout_marginTop="-17dp"
|
||||
android:layout_marginBottom="-4dp"
|
||||
android:background="?attr/highContrastReverseTextColor"
|
||||
android:paddingStart="8dp"
|
||||
android:paddingEnd="8dp"
|
||||
android:text="@string/question"
|
||||
android:textSize="@dimen/smallTextSize" />
|
||||
style="@style/FormLabel"
|
||||
android:text="@string/question" />
|
||||
|
||||
<EditText
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:background="@color/transparent"
|
||||
style="@style/FormInput"
|
||||
android:hint="@string/example_question_boolean"
|
||||
android:padding="16dp"
|
||||
android:text=""
|
||||
android:textSize="@dimen/regularTextSize" />
|
||||
/>
|
||||
</LinearLayout>
|
||||
</FrameLayout>
|
||||
|
||||
@@ -196,35 +144,16 @@
|
||||
android:padding="8dp"
|
||||
android:paddingTop="4dp">
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:background="@drawable/bg_input_group"
|
||||
android:clipChildren="false"
|
||||
android:clipToPadding="false"
|
||||
android:orientation="vertical">
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="8dp"
|
||||
android:layout_marginTop="-17dp"
|
||||
android:layout_marginBottom="-4dp"
|
||||
android:background="?attr/highContrastReverseTextColor"
|
||||
android:paddingStart="8dp"
|
||||
android:paddingEnd="8dp"
|
||||
android:text="@string/frequency"
|
||||
android:textSize="@dimen/smallTextSize" />
|
||||
<LinearLayout style="@style/FormInnerBox">
|
||||
<TextView
|
||||
style="@style/FormLabel"
|
||||
android:text="@string/frequency" />
|
||||
|
||||
<TextView
|
||||
style="@style/FormDropdown"
|
||||
android:id="@+id/frequencyPicker"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:drawableEnd="@drawable/ic_arrow_drop_down_dark"
|
||||
android:padding="16dp"
|
||||
android:text="@string/every_day"
|
||||
android:textColor="?attr/highContrastTextColor"
|
||||
android:textSize="@dimen/regularTextSize" />
|
||||
/>
|
||||
</LinearLayout>
|
||||
</FrameLayout>
|
||||
|
||||
@@ -237,35 +166,24 @@
|
||||
android:orientation="vertical"
|
||||
android:padding="8dp">
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:background="@drawable/bg_input_group"
|
||||
android:clipChildren="false"
|
||||
android:clipToPadding="false"
|
||||
android:orientation="vertical">
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="8dp"
|
||||
android:layout_marginTop="-17dp"
|
||||
android:layout_marginBottom="-4dp"
|
||||
android:background="?attr/highContrastReverseTextColor"
|
||||
android:paddingStart="8dp"
|
||||
android:paddingEnd="8dp"
|
||||
android:text="@string/reminder"
|
||||
android:textSize="@dimen/smallTextSize" />
|
||||
<LinearLayout style="@style/FormInnerBox">
|
||||
<TextView
|
||||
style="@style/FormLabel"
|
||||
android:text="@string/reminder" />
|
||||
|
||||
<TextView
|
||||
style="@style/FormDropdown"
|
||||
android:id="@+id/reminderTimePicker"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:drawableEnd="@drawable/ic_arrow_drop_down_dark"
|
||||
android:padding="16dp"
|
||||
android:text="@string/reminder_off"
|
||||
android:textColor="?attr/highContrastTextColor"
|
||||
android:textSize="@dimen/regularTextSize" />
|
||||
android:text="@string/reminder_off" />
|
||||
|
||||
<View
|
||||
style="@style/FormDivider"
|
||||
android:id="@+id/reminderDivider"/>
|
||||
|
||||
<TextView
|
||||
style="@style/FormDropdown"
|
||||
android:id="@+id/reminderDatePicker"
|
||||
android:text="" />
|
||||
</LinearLayout>
|
||||
</FrameLayout>
|
||||
|
||||
@@ -279,34 +197,14 @@
|
||||
android:orientation="vertical"
|
||||
android:padding="8dp">
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:background="@drawable/bg_input_group"
|
||||
android:clipChildren="false"
|
||||
android:clipToPadding="false"
|
||||
android:orientation="vertical">
|
||||
|
||||
<LinearLayout style="@style/FormInnerBox">
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="8dp"
|
||||
android:layout_marginTop="-17dp"
|
||||
android:layout_marginBottom="-4dp"
|
||||
android:background="?attr/highContrastReverseTextColor"
|
||||
android:paddingStart="8dp"
|
||||
android:paddingEnd="8dp"
|
||||
android:text="Notes"
|
||||
android:textSize="@dimen/smallTextSize" />
|
||||
style="@style/FormLabel"
|
||||
android:text="@string/notes" />
|
||||
|
||||
<EditText
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:background="@color/transparent"
|
||||
android:hint="(Optional)"
|
||||
android:padding="16dp"
|
||||
android:textColor="?attr/highContrastTextColor"
|
||||
android:textSize="@dimen/regularTextSize" />
|
||||
style="@style/FormInput"
|
||||
android:hint="@string/example_notes" />
|
||||
</LinearLayout>
|
||||
</FrameLayout>
|
||||
</LinearLayout>
|
||||
|
||||
@@ -245,7 +245,7 @@
|
||||
<string name="first_day_of_the_week">First day of the week</string>
|
||||
<string name="default_reminder_question">Have you completed this habit today?</string>
|
||||
<string name="notes">Notes</string>
|
||||
<string name="example_notes">You can put whatever you want here!</string>
|
||||
<string name="example_notes">(Optional)</string>
|
||||
|
||||
<string name="yes_or_no_example">e.g. Did you wake up early today? Did you exercise? Did you play chess?</string>
|
||||
<string name="measurable">Measurable</string>
|
||||
@@ -254,5 +254,6 @@
|
||||
<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>
|
||||
|
||||
</resources>
|
||||
@@ -292,4 +292,51 @@
|
||||
<item name="android:windowIsTranslucent">true</item>
|
||||
<item name="android:windowTranslucentStatus">true</item>
|
||||
</style>
|
||||
|
||||
<style name="FormLabel">
|
||||
<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_marginBottom">-4dp</item>
|
||||
<item name="android:background">?attr/highContrastReverseTextColor</item>
|
||||
<item name="android:paddingStart">8dp</item>
|
||||
<item name="android:paddingEnd">8dp</item>
|
||||
<item name="android:textSize">@dimen/smallerTextSize</item>
|
||||
</style>
|
||||
|
||||
<style name="FormInput">
|
||||
<item name="android:layout_width">match_parent</item>
|
||||
<item name="android:layout_height">wrap_content</item>
|
||||
<item name="android:background">@color/transparent</item>
|
||||
<item name="android:paddingLeft">16dp</item>
|
||||
<item name="android:paddingRight">16dp</item>
|
||||
<item name="android:paddingTop">16dp</item>
|
||||
<item name="android:paddingBottom">16dp</item>
|
||||
<item name="android:textSize">@dimen/regularTextSize</item>
|
||||
</style>
|
||||
|
||||
<style name="FormDropdown">
|
||||
<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:textSize">@dimen/regularTextSize</item>
|
||||
</style>
|
||||
|
||||
<style name="FormInnerBox">
|
||||
<item name="android:background">@drawable/bg_input_group</item>
|
||||
<item name="android:clipChildren">false</item>
|
||||
<item name="android:clipToPadding">false</item>
|
||||
<item name="android:orientation">vertical</item>
|
||||
<item name="android:layout_width">match_parent</item>
|
||||
<item name="android:layout_height">match_parent</item>
|
||||
</style>
|
||||
|
||||
<style name="FormDivider">
|
||||
<item name="android:layout_width">match_parent</item>
|
||||
<item name="android:layout_height">1dp</item>
|
||||
<item name="android:background">?attr/lowContrastTextColor</item>
|
||||
</style>
|
||||
</resources>
|
||||
|
||||
Reference in New Issue
Block a user