allow creating alarms without a day selected

This commit is contained in:
tibbi
2020-11-05 10:11:40 +01:00
parent c73d714e7b
commit 9b55486462
3 changed files with 83 additions and 53 deletions

View File

@ -15,6 +15,7 @@ import com.simplemobiletools.commons.extensions.*
import com.simplemobiletools.commons.helpers.ALARM_SOUND_TYPE_ALARM import com.simplemobiletools.commons.helpers.ALARM_SOUND_TYPE_ALARM
import com.simplemobiletools.commons.models.AlarmSound import com.simplemobiletools.commons.models.AlarmSound
import kotlinx.android.synthetic.main.dialog_edit_alarm.view.* import kotlinx.android.synthetic.main.dialog_edit_alarm.view.*
import java.util.*
class EditAlarmDialog(val activity: SimpleActivity, val alarm: Alarm, val callback: (alarmId: Int) -> Unit) { class EditAlarmDialog(val activity: SimpleActivity, val alarm: Alarm, val callback: (alarmId: Int) -> Unit) {
private val view = activity.layoutInflater.inflate(R.layout.dialog_edit_alarm, null) private val view = activity.layoutInflater.inflate(R.layout.dialog_edit_alarm, null)
@ -80,6 +81,7 @@ class EditAlarmDialog(val activity: SimpleActivity, val alarm: Alarm, val callba
} }
day.background = getProperDayDrawable(selectDay) day.background = getProperDayDrawable(selectDay)
day.setTextColor(if (selectDay) context.config.backgroundColor else textColor) day.setTextColor(if (selectDay) context.config.backgroundColor else textColor)
checkDaylessAlarm()
} }
edit_alarm_days_holder.addView(day) edit_alarm_days_holder.addView(day)
@ -139,6 +141,23 @@ class EditAlarmDialog(val activity: SimpleActivity, val alarm: Alarm, val callba
private fun updateAlarmTime() { private fun updateAlarmTime() {
view.edit_alarm_time.text = activity.getFormattedTime(alarm.timeInMinutes * 60, false, true) view.edit_alarm_time.text = activity.getFormattedTime(alarm.timeInMinutes * 60, false, true)
checkDaylessAlarm()
}
private fun checkDaylessAlarm() {
if (alarm.days == 0) {
val calendar = Calendar.getInstance()
val currentMinutesOfDay = calendar.get(Calendar.HOUR_OF_DAY) * 60 + calendar.get(Calendar.MINUTE)
val textId = if (alarm.timeInMinutes > currentMinutesOfDay) {
R.string.tomorrow
} else {
R.string.today
}
view.edit_alarm_dayless_label.text = "(${activity.getString(textId)})"
}
view.edit_alarm_dayless_label.beVisibleIf(alarm.days == 0)
} }
private fun getProperDayDrawable(selected: Boolean): Drawable { private fun getProperDayDrawable(selected: Boolean): Drawable {

View File

@ -1,6 +1,5 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<ScrollView <ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/edit_alarm_scrollview" android:id="@+id/edit_alarm_scrollview"
android:layout_width="match_parent" android:layout_width="match_parent"
@ -20,6 +19,18 @@
android:textSize="@dimen/alarm_text_size" android:textSize="@dimen/alarm_text_size"
tools:text="07:00" /> tools:text="07:00" />
<com.simplemobiletools.commons.views.MyTextView
android:id="@+id/edit_alarm_dayless_label"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_alignTop="@+id/edit_alarm_time"
android:layout_alignBottom="@+id/edit_alarm_time"
android:layout_marginStart="@dimen/normal_margin"
android:layout_toEndOf="@+id/edit_alarm_time"
android:gravity="center_vertical"
android:textSize="@dimen/bigger_text_size"
tools:text="@string/tomorrow" />
<LinearLayout <LinearLayout
android:id="@+id/edit_alarm_days_holder" android:id="@+id/edit_alarm_days_holder"
android:layout_width="match_parent" android:layout_width="match_parent"
@ -35,7 +46,7 @@
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_below="@+id/edit_alarm_days_holder" android:layout_below="@+id/edit_alarm_days_holder"
android:background="?attr/selectableItemBackground" android:background="?attr/selectableItemBackground"
android:paddingLeft="@dimen/tiny_margin" android:paddingStart="@dimen/tiny_margin"
android:paddingTop="@dimen/normal_margin" android:paddingTop="@dimen/normal_margin"
android:paddingBottom="@dimen/normal_margin"> android:paddingBottom="@dimen/normal_margin">
@ -59,7 +70,7 @@
android:background="?attr/selectableItemBackground" android:background="?attr/selectableItemBackground"
android:drawableLeft="@drawable/ic_bell_vector" android:drawableLeft="@drawable/ic_bell_vector"
android:drawablePadding="@dimen/normal_margin" android:drawablePadding="@dimen/normal_margin"
android:paddingLeft="@dimen/tiny_margin" android:paddingStart="@dimen/tiny_margin"
android:paddingTop="@dimen/normal_margin" android:paddingTop="@dimen/normal_margin"
android:paddingBottom="@dimen/normal_margin" android:paddingBottom="@dimen/normal_margin"
android:textSize="@dimen/normal_text_size" android:textSize="@dimen/normal_text_size"
@ -72,8 +83,8 @@
android:layout_below="@+id/edit_alarm_sound" android:layout_below="@+id/edit_alarm_sound"
android:layout_alignTop="@+id/edit_alarm_label" android:layout_alignTop="@+id/edit_alarm_label"
android:layout_alignBottom="@+id/edit_alarm_label" android:layout_alignBottom="@+id/edit_alarm_label"
android:layout_marginLeft="@dimen/tiny_margin" android:layout_marginStart="@dimen/tiny_margin"
android:layout_marginRight="@dimen/tiny_margin" android:layout_marginEnd="@dimen/tiny_margin"
android:scaleType="fitCenter" android:scaleType="fitCenter"
android:src="@drawable/ic_label_vector" /> android:src="@drawable/ic_label_vector" />
@ -82,9 +93,9 @@
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_below="@+id/edit_alarm_sound" android:layout_below="@+id/edit_alarm_sound"
android:layout_marginLeft="@dimen/medium_margin" android:layout_marginStart="@dimen/medium_margin"
android:layout_marginTop="@dimen/small_margin" android:layout_marginTop="@dimen/small_margin"
android:layout_toRightOf="@+id/edit_alarm_label_image" android:layout_toEndOf="@+id/edit_alarm_label_image"
android:hint="@string/label" android:hint="@string/label"
android:maxLines="1" android:maxLines="1"
android:singleLine="true" android:singleLine="true"

View File

@ -12,7 +12,7 @@
<dimen name="clock_text_size">70sp</dimen> <dimen name="clock_text_size">70sp</dimen>
<dimen name="clock_text_size_smaller">60sp</dimen> <dimen name="clock_text_size_smaller">60sp</dimen>
<dimen name="alarm_text_size">44sp</dimen> <dimen name="alarm_text_size">48sp</dimen>
<dimen name="stopwatch_text_size">60sp</dimen> <dimen name="stopwatch_text_size">60sp</dimen>
<dimen name="widget_time_text_size_small">48sp</dimen> <dimen name="widget_time_text_size_small">48sp</dimen>
<dimen name="widget_details_text_size">14sp</dimen> <dimen name="widget_details_text_size">14sp</dimen>