mirror of https://github.com/tasks/tasks
New reminder control set
* Custom random reminder intervals * Add multiple random reminderspull/1792/head
parent
dfe64d5f6f
commit
b4315f9beb
@ -1,68 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2012 Todoroo Inc
|
||||
*
|
||||
* See the file "LICENSE" for the full license governing this code.
|
||||
*/
|
||||
package com.todoroo.astrid.ui
|
||||
|
||||
import android.content.Context
|
||||
import android.view.View
|
||||
import android.widget.AdapterView
|
||||
import android.widget.AdapterView.OnItemSelectedListener
|
||||
import android.widget.ArrayAdapter
|
||||
import android.widget.Spinner
|
||||
import com.todoroo.andlib.utility.DateUtilities
|
||||
import org.tasks.R
|
||||
import org.tasks.data.Alarm
|
||||
import org.tasks.data.Alarm.Companion.TYPE_RANDOM
|
||||
import org.tasks.ui.TaskEditViewModel
|
||||
|
||||
/**
|
||||
* Control set dealing with random reminder settings
|
||||
*
|
||||
* @author Tim Su <tim></tim>@todoroo.com>
|
||||
*/
|
||||
internal class RandomReminderControlSet(context: Context, parentView: View, reminderPeriod: Long, vm: TaskEditViewModel) {
|
||||
init {
|
||||
val periodSpinner = parentView.findViewById<Spinner>(R.id.reminder_random_interval)
|
||||
periodSpinner.visibility = View.VISIBLE
|
||||
// create hour array
|
||||
val hourStrings = context.resources.getStringArray(R.array.TEA_reminder_random_hours)
|
||||
val hours = IntArray(hourStrings.size)
|
||||
for (i in hours.indices) {
|
||||
hours[i] = hourStrings[i].toInt()
|
||||
}
|
||||
// create adapter
|
||||
val adapter = ArrayAdapter(
|
||||
context,
|
||||
android.R.layout.simple_spinner_item,
|
||||
context.resources.getStringArray(R.array.TEA_reminder_random))
|
||||
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item)
|
||||
periodSpinner.adapter = adapter
|
||||
periodSpinner.onItemSelectedListener = object : OnItemSelectedListener {
|
||||
override fun onItemSelected(parent: AdapterView<*>?, view: View?, position: Int, id: Long) {
|
||||
val newAlarm =
|
||||
Alarm(vm.task?.id ?: 0, hours[position] * DateUtilities.ONE_HOUR, TYPE_RANDOM)
|
||||
vm.selectedAlarms.value =
|
||||
vm.selectedAlarms.value.toMutableList().apply {
|
||||
find { it.type == TYPE_RANDOM }?.let {
|
||||
newAlarm.id = it.id
|
||||
remove(it)
|
||||
}
|
||||
add(newAlarm)
|
||||
}
|
||||
}
|
||||
|
||||
override fun onNothingSelected(parent: AdapterView<*>?) {}
|
||||
}
|
||||
|
||||
var i = 0
|
||||
while (i < hours.size - 1) {
|
||||
if (hours[i] * DateUtilities.ONE_HOUR >= reminderPeriod) {
|
||||
break
|
||||
}
|
||||
i++
|
||||
}
|
||||
periodSpinner.setSelection(i)
|
||||
}
|
||||
}
|
@ -0,0 +1,68 @@
|
||||
package org.tasks.compose
|
||||
|
||||
import android.content.res.Configuration
|
||||
import androidx.compose.foundation.isSystemInDarkTheme
|
||||
import androidx.compose.foundation.layout.Row
|
||||
import androidx.compose.foundation.layout.Spacer
|
||||
import androidx.compose.foundation.layout.fillMaxWidth
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.foundation.layout.size
|
||||
import androidx.compose.material.Icon
|
||||
import androidx.compose.material.IconButton
|
||||
import androidx.compose.material.MaterialTheme
|
||||
import androidx.compose.material.Text
|
||||
import androidx.compose.material.darkColors
|
||||
import androidx.compose.material.lightColors
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.draw.alpha
|
||||
import androidx.compose.ui.platform.LocalContext
|
||||
import androidx.compose.ui.res.painterResource
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import androidx.compose.ui.tooling.preview.Preview
|
||||
import androidx.compose.ui.unit.dp
|
||||
import androidx.core.content.res.ResourcesCompat
|
||||
import org.tasks.R
|
||||
|
||||
|
||||
@Composable
|
||||
fun AlarmRow(text: String, remove: () -> Unit = {}) {
|
||||
Row(
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
) {
|
||||
Text(
|
||||
text = text,
|
||||
modifier = Modifier.padding(bottom = 16.dp)
|
||||
)
|
||||
Spacer(modifier = Modifier.weight(1f))
|
||||
IconButton(
|
||||
onClick = remove,
|
||||
modifier = Modifier
|
||||
.size(40.dp)
|
||||
.padding(start = 16.dp, bottom = 16.dp)
|
||||
) {
|
||||
Icon(
|
||||
painter = painterResource(id = R.drawable.ic_outline_clear_24px),
|
||||
modifier = Modifier.alpha(
|
||||
ResourcesCompat.getFloat(
|
||||
LocalContext.current.resources,
|
||||
R.dimen.alpha_secondary
|
||||
)
|
||||
),
|
||||
contentDescription = stringResource(id = R.string.delete)
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Preview(showBackground = true)
|
||||
@Preview(showBackground = true, uiMode = Configuration.UI_MODE_NIGHT_YES)
|
||||
@Composable
|
||||
fun AlarmRowPreview() {
|
||||
MaterialTheme(if (isSystemInDarkTheme()) darkColors() else lightColors()) {
|
||||
AlarmRow(text = "When due") {
|
||||
|
||||
}
|
||||
}
|
||||
}
|
@ -1,32 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginBottom="@dimen/keyline_first"
|
||||
android:paddingBottom="@dimen/keyline_first"
|
||||
android:baselineAligned="false"
|
||||
android:orientation="horizontal">
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="100"
|
||||
android:orientation="horizontal">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/alarm_string"
|
||||
style="@style/TaskEditTextPrimary"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"/>
|
||||
|
||||
<Spinner
|
||||
android:id="@+id/reminder_random_interval"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:visibility="gone"/>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<include layout="@layout/control_set_clear_button"/>
|
||||
|
||||
</LinearLayout>
|
@ -1,39 +1,5 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content">
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/alert_container"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/reminder_alarm"
|
||||
style="@style/TaskEditTextPrimary"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_alignParentEnd="true"
|
||||
android:layout_below="@id/alert_container"
|
||||
android:background="?attr/selectableItemBackgroundBorderless"
|
||||
android:gravity="end" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/alarms_add"
|
||||
style="@style/TaskEditTextPrimary"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_alignParentStart="true"
|
||||
android:background="?attr/selectableItemBackgroundBorderless"
|
||||
android:layout_gravity="start"
|
||||
android:layout_alignBaseline="@id/reminder_alarm"
|
||||
android:layout_toStartOf="@id/reminder_alarm"
|
||||
android:layout_height="wrap_content"
|
||||
android:hint="@string/add_reminder" />
|
||||
|
||||
<androidx.compose.ui.platform.ComposeView
|
||||
android:id="@+id/dialog_view"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content" />
|
||||
|
||||
</RelativeLayout>
|
||||
<androidx.compose.ui.platform.ComposeView xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:id="@+id/alert_container"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content" />
|
||||
|
Loading…
Reference in New Issue