Implement reminder time picker; customize picker color

This commit is contained in:
2020-06-18 07:43:58 -05:00
parent 72ad14119a
commit 309b6cbcaf
10 changed files with 488 additions and 378 deletions

View File

@@ -22,8 +22,11 @@ package org.isoron.uhabits.activities.habits.edit
import android.content.res.*
import android.graphics.*
import android.os.*
import android.text.format.*
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.preferences.*
@@ -38,8 +41,12 @@ class EditHabitActivity : AppCompatActivity() {
private lateinit var binding: ActivityEditHabitBinding
var paletteColor = 11
var androidColor = 0
var freqNum = 1
var freqDen = 1
var reminderHour = -1
var reminderMin = -1
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
@@ -69,7 +76,7 @@ class EditHabitActivity : AppCompatActivity() {
populateFrequency()
binding.frequencyPicker.setOnClickListener {
val dialog = FrequencyPickerDialog(freqNum, freqDen)
dialog.onFrequencyPicked = {num, den ->
dialog.onFrequencyPicked = { num, den ->
freqNum = num
freqDen = den
populateFrequency()
@@ -77,27 +84,55 @@ class EditHabitActivity : AppCompatActivity() {
dialog.show(supportFragmentManager, "frequencyPicker")
}
binding.reminderTimePicker.setOnClickListener {
val currentHour = if (reminderHour >= 0) reminderHour else 8
val currentMin = if (reminderMin >= 0) reminderMin else 0
val is24HourMode = DateFormat.is24HourFormat(this)
val dialog = TimePickerDialog.newInstance(object : TimePickerDialog.OnTimeSetListener {
override fun onTimeSet(view: RadialPickerLayout?, hourOfDay: Int, minute: Int) {
reminderHour = hourOfDay
reminderMin = minute
populateReminder()
}
override fun onTimeCleared(view: RadialPickerLayout?) {
reminderHour = -1
reminderMin = -1
populateReminder()
}
}, currentHour, currentMin, is24HourMode, androidColor)
dialog.show(supportFragmentManager, "timePicker")
}
binding.buttonSave.setOnClickListener {
finish()
}
}
private fun populateReminder() {
if (reminderHour < 0) {
binding.reminderTimePicker.text = getString(R.string.reminder_off)
} else {
val time = AndroidDateUtils.formatTime(this, reminderHour, reminderMin)
binding.reminderTimePicker.text = time
}
}
private fun populateFrequency() {
val label = when {
freqNum == 1 && freqDen == 1 -> "Every day"
freqNum == 1 && freqDen == 7 -> "Every week"
freqNum == 1 && freqDen > 1 -> "Every $freqDen days"
freqDen == 7 -> "$freqNum times per week"
freqDen == 31 -> "$freqNum times per month"
freqNum == 1 && freqDen == 1 -> getString(R.string.every_day)
freqNum == 1 && freqDen == 7 -> getString(R.string.every_week)
freqNum == 1 && freqDen > 1 -> getString(R.string.every_x_days, freqDen)
freqDen == 7 -> getString(R.string.x_times_per_week, freqNum)
freqDen == 31 -> getString(R.string.x_times_per_month, freqNum)
else -> "Unknown"
}
binding.frequencyPicker.text = label
}
private fun updateColors() {
val androidColor = PaletteUtils.getColor(this, paletteColor)
androidColor = PaletteUtils.getColor(this, paletteColor)
binding.colorButton.backgroundTintList = ColorStateList.valueOf(androidColor)
if(!themeSwitcher.isNightMode) {
if (!themeSwitcher.isNightMode) {
val darkerAndroidColor = ColorUtils.mixColors(Color.BLACK, androidColor, 0.15f)
window.statusBarColor = darkerAndroidColor
binding.toolbar.setBackgroundColor(androidColor)

View File

@@ -21,6 +21,7 @@ package org.isoron.uhabits.activities.habits.edit;
import android.app.*;
import android.content.*;
import android.graphics.*;
import android.os.*;
import androidx.annotation.NonNull;
@@ -265,7 +266,7 @@ public class EditHabitDialog extends AppCompatDialogFragment
boolean is24HourMode = DateFormat.is24HourFormat(getContext());
timePicker =
TimePickerDialog.newInstance(reminderPanel, currentHour,
currentMin, is24HourMode);
currentMin, is24HourMode, Color.BLUE);
timePicker.show(getFragmentManager(), "timePicker");
}

View File

@@ -2,6 +2,7 @@ package org.isoron.uhabits.notifications;
import android.app.*;
import android.graphics.*;
import android.os.*;
import androidx.annotation.Nullable;
@@ -66,7 +67,8 @@ public class SnoozeDelayPickerActivity extends FragmentActivity
},
calendar.get(Calendar.HOUR_OF_DAY),
calendar.get(Calendar.MINUTE),
DateFormat.is24HourFormat(this));
DateFormat.is24HourFormat(this),
Color.BLUE);
dialog.show(getSupportFragmentManager(), "timePicker");
}

View File

@@ -1,142 +1,142 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.coordinatorlayout.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="?attr/highContrastReverseTextColor"
android:fitsSystemWindows="true"
android:orientation="vertical"
tools:context=".activities.habits.edit.EditHabitActivity">
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="?attr/highContrastReverseTextColor"
android:fitsSystemWindows="true"
android:orientation="vertical"
tools:context=".activities.habits.edit.EditHabitActivity">
<com.google.android.material.appbar.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
android:layout_width="match_parent"
android:layout_height="wrap_content">
<androidx.appcompat.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?attr/colorPrimary"
android:elevation="2dp"
android:gravity="end"
android:minHeight="?attr/actionBarSize"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
app:title="@string/create_habit"
app:titleTextColor="@color/white">
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?attr/colorPrimary"
android:elevation="2dp"
android:gravity="end"
android:minHeight="?attr/actionBarSize"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
app:title="@string/create_habit"
app:titleTextColor="@color/white">
<com.google.android.material.button.MaterialButton
android:id="@+id/buttonSave"
style="@style/Widget.MaterialComponents.Button.OutlinedButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="end"
android:layout_marginEnd="16dp"
android:text="@string/save"
android:textColor="@color/white"
app:rippleColor="@color/white"
app:strokeColor="@color/white" />
android:id="@+id/buttonSave"
style="@style/Widget.MaterialComponents.Button.OutlinedButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="end"
android:layout_marginEnd="16dp"
android:text="@string/save"
android:textColor="@color/white"
app:rippleColor="@color/white"
app:strokeColor="@color/white" />
</androidx.appcompat.widget.Toolbar>
</com.google.android.material.appbar.AppBarLayout>
<ScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_behavior="@string/appbar_scrolling_view_behavior">
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_behavior="@string/appbar_scrolling_view_behavior">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingTop="8dp"
android:orientation="vertical">
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:paddingTop="8dp">
<!-- Title and color -->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<!-- Habit Title -->
<FrameLayout
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_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:clipChildren="false"
android:clipToPadding="false"
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">
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:textSize="@dimen/smallTextSize"
android:text="@string/name" />
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" />
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/transparent"
android:textSize="@dimen/regularTextSize"
android:padding="16dp"
android:hint="e.g. Exercise" />
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" />
</LinearLayout>
</FrameLayout>
<!-- Habit Color -->
<FrameLayout
android:layout_width="80dp"
android:layout_height="match_parent"
android:paddingStart="0dp"
android:clipChildren="false"
android:clipToPadding="false"
android:orientation="vertical"
android:padding="8dp">
android:layout_width="80dp"
android:layout_height="match_parent"
android:clipChildren="false"
android:clipToPadding="false"
android:orientation="vertical"
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">
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">
<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:textSize="@dimen/smallTextSize"
android:text="Color" />
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" />
<androidx.appcompat.widget.AppCompatButton
android:id="@+id/colorButton"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginLeft="16dp"
android:layout_marginRight="16dp"
android:layout_marginTop="8dp"
android:layout_marginBottom="8dp"
android:backgroundTint="#E23673"/>
android:id="@+id/colorButton"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginLeft="16dp"
android:layout_marginTop="8dp"
android:layout_marginRight="16dp"
android:layout_marginBottom="8dp"
android:backgroundTint="#E23673" />
</LinearLayout>
</FrameLayout>
@@ -147,166 +147,166 @@
<!-- 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">
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
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">
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:textSize="@dimen/smallTextSize"
android:text="@string/question" />
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" />
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/transparent"
android:textSize="@dimen/regularTextSize"
android:hint="@string/example_question_boolean"
android:padding="16dp"
android:text="" />
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/transparent"
android:hint="@string/example_question_boolean"
android:padding="16dp"
android:text=""
android:textSize="@dimen/regularTextSize" />
</LinearLayout>
</FrameLayout>
<!-- 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: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
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" />
<TextView
android:id="@+id/frequencyPicker"
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:textSize="@dimen/smallTextSize"
android:paddingStart="8dp"
android:paddingEnd="8dp"
android:text="@string/frequency" />
<TextView
android:id="@+id/frequencyPicker"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:drawableEnd="@drawable/ic_arrow_drop_down_dark"
android:textSize="@dimen/regularTextSize"
android:padding="16dp"
android:text="@string/every_day"
android:textColor="?attr/highContrastTextColor" />
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>
<!-- Reminder -->
<FrameLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:clipChildren="false"
android:clipToPadding="false"
android:orientation="vertical"
android:padding="8dp">
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:clipChildren="false"
android:clipToPadding="false"
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" />
<TextView
android:id="@+id/reminderTimePicker"
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:textSize="@dimen/smallTextSize"
android:paddingStart="8dp"
android:paddingEnd="8dp"
android:text="@string/reminder" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?attr/selectableItemBackground"
android:drawableEnd="@drawable/ic_arrow_drop_down_dark"
android:textSize="@dimen/regularTextSize"
android:textColor="?attr/highContrastTextColor"
android:padding="16dp"
android:text="@string/reminder_off" />
android:drawableEnd="@drawable/ic_arrow_drop_down_dark"
android:padding="16dp"
android:text="@string/reminder_off"
android:textColor="?attr/highContrastTextColor"
android:textSize="@dimen/regularTextSize" />
</LinearLayout>
</FrameLayout>
<!-- Notes -->
<FrameLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:clipChildren="false"
android:clipToPadding="false"
android:orientation="vertical"
android:padding="8dp">
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:clipChildren="false"
android:clipToPadding="false"
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">
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:textSize="@dimen/smallTextSize"
android:paddingStart="8dp"
android:paddingEnd="8dp"
android:text="Notes" />
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" />
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/transparent"
android:textSize="@dimen/regularTextSize"
android:textColor="?attr/highContrastTextColor"
android:padding="16dp"
android:hint="(Optional)" />
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" />
</LinearLayout>
</FrameLayout>
</LinearLayout>

View File

@@ -252,5 +252,7 @@
<string name="measurable_example">e.g. How many miles did you run today? How many pages did you read? How many calories did you eat?</string>
<string name="subjective">Subjective</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_month">%d times per month</string>
</resources>