Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ A local-first to-do list with native apps for macOS and Android, a self-hosted w

Lists covers the part of 2Do that a single person uses every day. A task has a list, dates, a priority, tags, a repeat, a reminder, notes in Markdown, attachments and subtasks, which are plain lines with a title; tasks group into projects, and saved filters cut across the lists. A task is closed as done or as "won't do", and stays in view for a few seconds before it leaves. Attachments open inside the app, can be saved or shared, and work in the web interface. The apps for macOS and Android show the calendar events of the day in Today, remind with a sound you choose and keep automatic local backups. Everything works offline; edits made on two devices to different fields of the same task are both kept.

Inbox, each list and Today have their own sort mode. The mode and manual order sync across devices.

The interface is in English with Russian and Chinese (Simplified) localizations and follows the system language.

## Screenshots
Expand Down
2 changes: 1 addition & 1 deletion android/app/src/main/java/org/evsyukov/lists/ui/Editor.kt
Original file line number Diff line number Diff line change
Expand Up @@ -1055,7 +1055,7 @@ fun ListDialog(list: TaskList?, model: MainViewModel, onDismiss: () -> Unit) {
var dueToday by remember { mutableStateOf(list?.defaultDueToday ?: false) }
var archived by remember { mutableStateOf(list?.archived ?: false) }
var confirmDelete by remember { mutableStateOf(false) }
val sorts = listOf(SortMode.MANUAL to str(R.string.sort_manual), SortMode.DUE to str(R.string.sort_due), SortMode.PRIORITY to str(R.string.sort_priority), SortMode.TITLE to str(R.string.sort_title))
val sorts = listOf(SortMode.MANUAL to str(R.string.sort_manual), SortMode.DUE to str(R.string.sort_due), SortMode.START to str(R.string.sort_start), SortMode.PRIORITY to str(R.string.sort_priority), SortMode.TITLE to str(R.string.sort_title))

FormDialog(
title = if (list == null) str(R.string.new_list) else list.displayName(),
Expand Down
58 changes: 49 additions & 9 deletions android/app/src/main/java/org/evsyukov/lists/ui/MainScreen.kt
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ import androidx.compose.material.icons.outlined.MoreVert
import androidx.compose.material.icons.outlined.Repeat
import androidx.compose.material.icons.outlined.Search
import androidx.compose.material.icons.outlined.Settings
import androidx.compose.material.icons.outlined.Sort
import androidx.compose.material.icons.outlined.Tag
import androidx.compose.material3.AlertDialog
import androidx.compose.material3.CircularProgressIndicator
Expand Down Expand Up @@ -207,8 +208,10 @@ import uniffi.lists_core.Priority
import uniffi.lists_core.QuickParse
import uniffi.lists_core.SavedFilter
import uniffi.lists_core.Scope
import uniffi.lists_core.SortMode
import uniffi.lists_core.TaskItem
import uniffi.lists_core.TaskList
import uniffi.lists_core.TodayGroup
import java.time.Duration
import java.time.LocalDateTime
import kotlin.math.abs
Expand Down Expand Up @@ -402,7 +405,7 @@ fun MainScreen(model: MainViewModel, onReminderSet: () -> Unit) {
val eventsShown = state.effectiveScope == Scope.Today && events.isNotEmpty()
if (state.loaded && state.sections.all { it.tasks.isEmpty() }) {
Column(Modifier.fillMaxSize()) {
if (state.search == null) ViewTitle(state)
if (state.search == null) ViewTitle(state, model::setHeaderSort)
// R78: the events of the day are shown on a day without tasks as well.
if (eventsShown) EventsBlock(events)
EmptyState(state.effectiveScope)
Expand All @@ -413,32 +416,41 @@ fun MainScreen(model: MainViewModel, onReminderSet: () -> Unit) {
val reorderable = state.reorderable()
LaunchedEffect(state.sections) { reorder.forget() }
// While a row is dragged, a row held at an edge scrolls the column, frame by frame.
LaunchedEffect(reorder.dragging) {
val section = state.sections.firstOrNull() ?: return@LaunchedEffect
LaunchedEffect(reorder.dragging, reorder.orderGroup) {
val section = state.sections.firstOrNull { it.key == reorder.orderGroup } ?: return@LaunchedEffect
while (reorder.dragging != null) {
withFrameNanos {}
reorder.autoscroll(rows) { rowKey(section.key, it) }
}
}
LazyColumn(Modifier.fillMaxSize(), state = rows, contentPadding = PaddingValues(bottom = 88.dp)) {
if (state.search == null) item(key = "title") { ViewTitle(state) }
if (state.search == null) item(key = "title") { ViewTitle(state, model::setHeaderSort) }
if (eventsShown) item(key = "events") { EventsBlock(events) }
for (section in state.sections) {
section.title?.let { title ->
item(key = "h:${section.key}") {
GroupHeading(title, alert = section.key == "overdue")
}
}
val shown = reorder.order?.takeIf { reorderable }
val shown = reorder.order?.takeIf { reorderable && reorder.orderGroup == section.key }
?.mapNotNull { id -> section.tasks.firstOrNull { it.id == id } }
?.takeIf { it.size == section.tasks.size } ?: section.tasks
val last = shown.lastIndex
itemsIndexed(shown, key = { _, task -> rowKey(section.key, task.id) }) { index, task ->
val drag = if (reorderable) {
RowDrag(
onStart = { reorder.start(task.id, section.tasks.map { it.id }) },
onStart = { reorder.start(task.id, section.tasks.map { it.id }, section.key) },
onDrag = { dy -> reorder.drag(dy, rows) { rowKey(section.key, it) } },
onEnd = { slop -> reorder.drop(slop).also { if (it is Dropped.Moved) model.moveTask(it.id, it.after) } },
onEnd = { slop ->
reorder.drop(slop).also { drop ->
if (drop is Dropped.Moved) {
if (state.effectiveScope == Scope.Today) {
val group = if (drop.group == "overdue") TodayGroup.OVERDUE else TodayGroup.CURRENT
model.moveTodayTasks(group, listOf(drop.id), drop.after)
} else model.moveTask(drop.id, drop.after)
}
}
},
onCancel = reorder::cancel,
)
} else null
Expand Down Expand Up @@ -1538,7 +1550,7 @@ private fun ProjectMark(done: UInt, total: UInt, tint: Color, onComplete: () ->

/** R95: the large title of the view with its icon, at the top of the content. */
@Composable
private fun ViewTitle(state: UiState) {
private fun ViewTitle(state: UiState, onSetSort: (SortMode) -> Unit) {
val plain = MaterialTheme.colorScheme.onSurfaceVariant
val (icon, tint) = when (val scope = state.scope) {
Scope.Inbox -> Icons.Filled.Inbox to viewTint(ViewTint.Blue)
Expand All @@ -1554,18 +1566,46 @@ private fun ViewTitle(state: UiState) {
is Scope.Tag -> Icons.Outlined.Tag to plain
is Scope.Search -> Icons.Outlined.Search to plain
}
var sortExpanded by remember(state.scope) { mutableStateOf(false) }
val sort = state.headerSort
val sortModes = listOf(
SortMode.MANUAL to R.string.sort_manual,
SortMode.DUE to R.string.sort_due,
SortMode.START to R.string.sort_start,
SortMode.PRIORITY to R.string.sort_priority,
SortMode.TITLE to R.string.sort_title,
)
Row(Modifier.fillMaxWidth().padding(start = Space.xxl, end = Space.xxl, top = Space.l, bottom = Space.l), verticalAlignment = Alignment.CenterVertically) {
// R159: the icon stands on a tile of its colour.
Box(Modifier.size(Sizes.viewTile).background(tint.copy(alpha = 0.15f), Corners.viewTile), contentAlignment = Alignment.Center) {
Icon(icon, null, Modifier.size(Sizes.viewIcon), tint = tint)
}
Text(
state.title,
Modifier.padding(start = Space.l).semantics { heading() },
Modifier.weight(1f).padding(start = Space.l).semantics { heading() },
style = MaterialTheme.typography.viewTitle,
maxLines = 2,
overflow = TextOverflow.Ellipsis,
)
if (sort != null) {
Box {
IconButton(onClick = { sortExpanded = true }, modifier = Modifier.semantics { contentDescription = str(R.string.sorting) }) {
Icon(Icons.Outlined.Sort, contentDescription = null)
}
DropdownMenu(expanded = sortExpanded, onDismissRequest = { sortExpanded = false }) {
for ((mode, label) in sortModes) {
DropdownMenuItem(
text = { Text(str(label)) },
onClick = {
sortExpanded = false
if (mode != sort) onSetSort(mode)
},
trailingIcon = if (mode == sort) ({ Icon(Icons.Outlined.Check, null) }) else null,
)
}
}
}
}
}
}

Expand Down
47 changes: 39 additions & 8 deletions android/app/src/main/java/org/evsyukov/lists/ui/MainViewModel.kt
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import org.evsyukov.lists.dateLabel
import org.evsyukov.lists.dayHeading
import org.evsyukov.lists.dayOf
import org.evsyukov.lists.displayName
import org.evsyukov.lists.dueDayPassed
import org.evsyukov.lists.logError
import org.evsyukov.lists.logged
import org.evsyukov.lists.str
Expand All @@ -32,13 +31,16 @@ import uniffi.lists_core.KeepDone
import uniffi.lists_core.NewTask
import uniffi.lists_core.SavedFilter
import uniffi.lists_core.Scope
import uniffi.lists_core.SortMode
import uniffi.lists_core.Store
import uniffi.lists_core.SyncConfig
import uniffi.lists_core.SyncSide
import uniffi.lists_core.SyncStatus
import uniffi.lists_core.TagCount
import uniffi.lists_core.TaskItem
import uniffi.lists_core.TaskList
import uniffi.lists_core.TodayGroup
import uniffi.lists_core.TodaySections

data class TaskSection(val key: String, val title: String?, val tasks: List<TaskItem>)

Expand Down Expand Up @@ -80,6 +82,7 @@ data class UiState(
val selection: Set<String>? = null,
/** R131: whether the menu of the bar offers Undo. */
val canUndo: Boolean = false,
val todaySort: SortMode = SortMode.DUE,
) {
val effectiveScope: Scope get() = search?.takeIf { it.isNotBlank() }?.let { Scope.Search(it) } ?: scope

Expand All @@ -94,6 +97,15 @@ data class UiState(
/** The tasks of the view in the order of their rows. */
val shownIds: List<String> get() = sections.flatMap { section -> section.tasks.map { it.id } }

/** Sort mode offered by the header of Inbox, a list, or Today. */
val headerSort: SortMode?
get() = if (search != null || selection != null) null else when (val view = scope) {
Scope.Inbox -> list("inbox")?.sort
is Scope.List -> list(view.id)?.sort
Scope.Today -> todaySort
else -> null
}

val title: String
get() = when (val s = scope) {
Scope.Inbox -> str(R.string.inbox)
Expand Down Expand Up @@ -195,10 +207,12 @@ class MainViewModel : ViewModel() {
else -> shown
}
val base = current.copy(lists = lists, tags = tags, projects = projects, filters = filters, scope = scope)
val tasks = store.tasks(base.effectiveScope)
val today = if (base.effectiveScope == Scope.Today) store.todaySections() else null
val tasks = today?.let { it.overdue + it.current } ?: store.tasks(base.effectiveScope)
base.copy(
counts = store.counts(),
sections = group(base, tasks),
sections = group(base, tasks, today),
todaySort = store.todaySort(),
found = found(store, base.effectiveScope, tasks),
editing = editingId?.let { id -> load(store, id) },
sync = store.syncStatus(),
Expand Down Expand Up @@ -246,12 +260,13 @@ class MainViewModel : ViewModel() {
.filterValues { it.isNotEmpty() }
}

private fun group(state: UiState, tasks: List<TaskItem>): List<TaskSection> = when (state.effectiveScope) {
private fun group(state: UiState, tasks: List<TaskItem>, today: TodaySections?): List<TaskSection> = when (state.effectiveScope) {
Scope.Today -> {
// R125: a task of a project goes by the project's due date when it has none of its own.
val (overdue, rest) = tasks.partition { dueDayPassed(it.effectiveDue) }
if (overdue.isEmpty()) listOf(TaskSection("today", null, rest))
else listOf(TaskSection("overdue", str(R.string.overdue), overdue), TaskSection("today", str(R.string.today), rest)).filter { it.tasks.isNotEmpty() }
val sections = checkNotNull(today)
val overdue = sections.overdue
val current = sections.current
if (overdue.isEmpty()) listOf(TaskSection("current", null, current))
else listOf(TaskSection("overdue", str(R.string.overdue), overdue), TaskSection("current", str(R.string.today), current)).filter { it.tasks.isNotEmpty() }
}
Scope.Upcoming -> runs(tasks, { dayOf(it.effectiveDue ?: it.effectiveStart ?: "") }, ::dayHeading)
Scope.All -> runs(tasks, { it.listId }, { id -> state.list(id)?.displayName().orEmpty() })
Expand All @@ -274,6 +289,22 @@ class MainViewModel : ViewModel() {
/** R157: a row dragged to another place of a view sorted by hand; it goes right after [after], or first. */
fun moveTask(id: String, after: String?) = act { it.moveTask(id, null, null, after) }

/** R165: moves a task within its manually ordered Today group without changing its list position. */
fun moveTodayTasks(group: TodayGroup, ids: List<String>, after: String?) = act { it.moveTodayTasks(group, ids, after) }

/** R165: the sort choice for the Today view is shared by synced devices. */
fun setHeaderSort(sort: SortMode) {
val view = _state.value.scope
act { store ->
when (view) {
Scope.Inbox -> store.setListSort("inbox", sort)
is Scope.List -> store.setListSort(view.id, sort)
Scope.Today -> store.setTodaySort(sort)
else -> return@act
}
}
}

/** R157: a list dragged to another place in the panel of lists; it goes right after [after], or first. */
fun moveList(id: String, after: String?) = act { it.moveList(id, after) }

Expand Down
32 changes: 22 additions & 10 deletions android/app/src/main/java/org/evsyukov/lists/ui/Reorder.kt
Original file line number Diff line number Diff line change
Expand Up @@ -25,18 +25,18 @@ internal fun <T> List<T>.moved(from: Int, to: Int): List<T> =
*/
internal fun UiState.reorderable(): Boolean {
if (selection != null || !search.isNullOrBlank()) return false
val list = when (val s = scope) {
Scope.Inbox -> list("inbox")
is Scope.List -> list(s.id)
else -> null
return when (val view = scope) {
Scope.Inbox -> list("inbox")?.sort == SortMode.MANUAL
is Scope.List -> list(view.id)?.sort == SortMode.MANUAL
Scope.Today -> todaySort == SortMode.MANUAL
else -> false
}
return list?.sort == SortMode.MANUAL
}

/** How a drag of a row ended (R157). */
sealed interface Dropped {
/** The row went to another place: right after [after], or first. */
data class Moved(val id: String, val after: String?) : Dropped
data class Moved(val id: String, val after: String?, val group: String? = null) : Dropped

/** The finger let go where it pressed: the long press opens what it opened before (the menu). */
data object Still : Dropped
Expand All @@ -56,6 +56,10 @@ class Reorder {
var order by mutableStateOf<List<String>?>(null)
private set

/** The section whose independent manual order is being changed. */
var orderGroup by mutableStateOf<String?>(null)
private set

/** How far the dragged row is drawn from its place in the column, in pixels. */
var offset by mutableFloatStateOf(0f)
private set
Expand All @@ -64,9 +68,10 @@ class Reorder {
private var travel = 0f
private var initial: List<String> = emptyList()

fun start(id: String, ids: List<String>) {
fun start(id: String, ids: List<String>, group: String? = null) {
dragging = id
order = ids
orderGroup = group
initial = ids
offset = 0f
moved = false
Expand Down Expand Up @@ -124,7 +129,7 @@ class Reorder {
val now = order
val result = when {
// Taken away and brought back is no move.
id != null && now != null && moved && now != initial -> Dropped.Moved(id, placedAfter(now, id))
id != null && now != null && moved && now != initial -> Dropped.Moved(id, placedAfter(now, id), orderGroup)
travel < slop -> Dropped.Still
else -> Dropped.Kept
}
Expand All @@ -133,18 +138,25 @@ class Reorder {
moved = false
travel = 0f
// A moved row stays where it was put until the view is read again with it there (see [forget]).
if (result !is Dropped.Moved) order = null
if (result !is Dropped.Moved) {
order = null
orderGroup = null
}
return result
}

/** The view was read again: the order of the store is shown from here on. */
fun forget() {
if (dragging == null) order = null
if (dragging == null) {
order = null
orderGroup = null
}
}

fun cancel() {
dragging = null
order = null
orderGroup = null
offset = 0f
moved = false
travel = 0f
Expand Down
1 change: 1 addition & 0 deletions android/app/src/main/res/values-ru/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@
<string name="sort_manual">Вручную</string>
<string name="sort_due">По сроку</string>
<string name="sort_priority">По приоритету</string>
<string name="sort_start">По дате начала</string>
<string name="sort_title">По названию</string>
<string name="show_completed">Показывать выполненные</string>
<string name="new_tasks">Новые задачи</string>
Expand Down
1 change: 1 addition & 0 deletions android/app/src/main/res/values-zh-rCN/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@
<string name="sort_manual">手动</string>
<string name="sort_due">按到期日</string>
<string name="sort_priority">按优先级</string>
<string name="sort_start">按开始日期</string>
<string name="sort_title">按标题</string>
<string name="show_completed">显示已完成</string>
<string name="new_tasks">新建任务</string>
Expand Down
1 change: 1 addition & 0 deletions android/app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@
<string name="sort_manual">Manually</string>
<string name="sort_due">By due date</string>
<string name="sort_priority">By priority</string>
<string name="sort_start">By start date</string>
<string name="sort_title">By title</string>
<string name="show_completed">Show completed</string>
<string name="new_tasks">New tasks</string>
Expand Down
Loading
Loading