Skip to content

Commit

Permalink
Extract hard coded strings in string resources and consume with strin…
Browse files Browse the repository at this point in the history
…gResource(Res.string.*)
  • Loading branch information
opatry committed Oct 7, 2024
1 parent 58a2a2c commit 6f96831
Show file tree
Hide file tree
Showing 14 changed files with 247 additions and 127 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ import net.opatry.tasks.app.ui.component.LoadingPane
import net.opatry.tasks.app.ui.component.NoTaskListEmptyState
import net.opatry.tasks.app.ui.component.NoTaskListSelectedEmptyState
import net.opatry.tasks.resources.Res
import net.opatry.tasks.resources.default_task_list_title
import net.opatry.tasks.resources.task_lists_screen_default_task_list_title
import org.jetbrains.compose.resources.stringResource

@OptIn(ExperimentalMaterial3AdaptiveApi::class)
Expand Down Expand Up @@ -69,7 +69,7 @@ actual fun TaskListsMasterDetail(
list == null -> LoadingPane()

list.isEmpty() -> {
val newTaskListName = stringResource(Res.string.default_task_list_title)
val newTaskListName = stringResource(Res.string.task_lists_screen_default_task_list_title)
NoTaskListEmptyState {
onNewTaskList(newTaskListName)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@
<resources>
<string name="app_name">Taskfolio</string>

<string name="dialog_cancel">Cancel</string>

<string name="edit_text_dialog_title">Title</string>
<string name="edit_text_dialog_empty_title_error">Text cannot be empty</string>

<string name="navigation_tasks">Tasks</string>
<string name="navigation_calendar">Calendar</string>
<string name="navigation_search">Search</string>
Expand All @@ -33,13 +38,78 @@
<string name="onboarding_screen_skip">Skip</string>
<string name="onboarding_screen_authorize_cta">Authorize</string>

<string name="default_task_list_title">My tasks</string>
<string name="profile_popup_no_email">No email information</string>
<string name="profile_popup_sign_explanation">Sign in and authorize access to your Google Tasks to enable sync.</string>
<string name="profile_popup_sign_out">Sign out</string>

<string name="task_lists_screen_default_task_list_title">My tasks</string>
<string name="task_lists_screen_empty_state_no_selection_title">No task list selected</string>
<string name="task_lists_screen_empty_state_no_selection_desc">Select a task list to see its tasks</string>
<string name="task_lists_screen_empty_state_title">No task lists</string>
<string name="task_lists_screen_empty_state_desc">Create a new task list to get started</string>
<string name="task_lists_screen_empty_state_cta">New task list</string>
<string name="task_lists_screen_add_task_list_cta">Add task list…</string>
<string name="task_lists_screen_empty_list_title">No tasks yet</string>
<string name="task_lists_screen_empty_list_desc">Start planning to keep track of your pending tasks.</string>
<string name="task_lists_screen_add_task">Add task</string>
<string name="task_lists_screen_create_task_list_dialog_title">New task list</string>
<string name="task_lists_screen_create_task_list_dialog_confirm">Create</string>

<string name="task_list_pane_task_deleted_snackbar">Task deleted</string>
<string name="task_list_pane_task_deleted_undo_snackbar">Undo</string>
<string name="task_list_pane_task_restored_snackbar">Task restored</string>
<string name="task_list_pane_rename_dialog_title">Rename list</string>
<string name="task_list_pane_rename_dialog_cta">Rename</string>
<string name="task_list_pane_clear_completed_confirm_dialog_title">Clear all completed tasks?</string>
<string name="task_list_pane_clear_completed_confirm_dialog_message">All completed tasks will be permanently deleted from this list.</string>
<string name="task_list_pane_clear_completed_confirm_dialog_confirm">Clear</string>
<string name="task_list_pane_delete_list_confirm_dialog_title">Delete this list?</string>
<string name="task_list_pane_delete_list_confirm_dialog_message">All tasks in this list will be permanently deleted.</string>
<string name="task_list_pane_delete_list_confirm_dialog_confirm">Delete</string>
<string name="task_list_pane_all_tasks_complete_title">All tasks complete</string>
<string name="task_list_pane_all_tasks_complete_desc">Nice work!</string>
<string name="task_list_pane_completed_section_title_with_count">Completed (%1$s)</string>
<string name="task_list_pane_delete_task_icon_content_desc">Delete task</string>
<string name="task_list_pane_task_options_icon_content_desc">Task options</string>

<string name="task_due_date_label_days_ago">%1$s days ago</string>
<string name="task_due_date_label_weeks_ago">%1$s weeks ago</string>
<string name="task_due_date_label_yesterday">Yesterday</string>
<string name="task_due_date_label_today">Today</string>
<string name="task_due_date_label_tomorrow">Tomorrow</string>
<string name="task_due_date_update_cta">Update</string>

<string name="task_editor_sheet_edit_title">Edit task</string>
<string name="task_editor_sheet_new_title">New task</string>
<string name="task_editor_sheet_title_field_label">Title</string>
<string name="task_editor_sheet_title_field_empty_error">Title cannot be empty</string>
<string name="task_editor_sheet_notes_field_label">Notes</string>
<string name="task_editor_sheet_no_due_date_fallback">No due date</string>
<string name="task_editor_sheet_list_dropdown_label">List title</string>
<string name="task_editor_sheet_validate">Validate</string>

<string name="task_list_menu_sort_by">Sort by</string>
<string name="task_list_menu_sort_manual">Manual</string>
<string name="task_list_menu_sort_due_date">Due date</string>
<string name="task_list_menu_rename">Rename</string>
<string name="task_list_menu_clear_all_completed_tasks">Clear all completed tasks</string>
<string name="task_list_menu_delete">Delete list</string>
<string name="task_list_menu_default_list_cannot_be_deleted">Default list can’t be deleted</string>

<string name="task_menu_move_to_top">Move to top</string>
<string name="task_menu_add_subtask">Add subtask</string>
<string name="task_menu_indent">Indent</string>
<string name="task_menu_unindent">Unindent</string>
<string name="task_menu_move_to">Move to…</string>
<string name="task_menu_new_list">New list</string>
<string name="task_menu_delete">Delete</string>

<string name="search_screen_tbd">Search</string>
<string name="about_screen_app_version_subtitle">Version %1$s</string>
<string name="about_screen_website_item">Website</string>
<string name="about_screen_github_item">Github</string>
<string name="about_screen_privacy_policy_item">Privacy Policy</string>
<string name="about_screen_credits_item">Credits</string>

<string name="settings_screen_tbd">Settings</string>
<string name="credits_screen_title">Credits</string>
<string name="credits_screen_license_unknown_authors">Unknown authors</string>
</resources>
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ import net.opatry.tasks.resources.navigation_about
import net.opatry.tasks.resources.navigation_calendar
import net.opatry.tasks.resources.navigation_search
import net.opatry.tasks.resources.navigation_tasks
import net.opatry.tasks.resources.task_lists_screen_create_task_list_dialog_confirm
import net.opatry.tasks.resources.task_lists_screen_create_task_list_dialog_title
import org.jetbrains.compose.resources.StringResource
import org.jetbrains.compose.resources.stringResource

Expand Down Expand Up @@ -138,12 +140,12 @@ fun TasksApp(aboutApp: AboutApp, userViewModel: UserViewModel, tasksViewModel: T
if (showNewTaskListDialog) {
EditTextDialog(
onDismissRequest = { showNewTaskListDialog = false },
validateLabel = "Create",
validateLabel = stringResource(Res.string.task_lists_screen_create_task_list_dialog_confirm),
onValidate = { title ->
showNewTaskListDialog = false
tasksViewModel.createTaskList(title)
},
dialogTitle = "New task list",
dialogTitle = stringResource(Res.string.task_lists_screen_create_task_list_dialog_title),
initialText = newTaskListDefaultTitle,
allowBlank = false
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,11 @@ import androidx.compose.ui.Modifier
import androidx.compose.ui.unit.dp
import androidx.compose.ui.window.Dialog
import androidx.compose.ui.window.DialogProperties
import net.opatry.tasks.resources.Res
import net.opatry.tasks.resources.dialog_cancel
import net.opatry.tasks.resources.edit_text_dialog_empty_title_error
import net.opatry.tasks.resources.edit_text_dialog_title
import org.jetbrains.compose.resources.stringResource

@Composable
fun EditTextDialog(
Expand Down Expand Up @@ -77,12 +82,12 @@ fun EditTextDialog(
OutlinedTextField(
newTitle,
onValueChange = { newTitle = it },
label = { Text("Title") },
label = { Text(stringResource(Res.string.edit_text_dialog_title)) },
maxLines = 1,
supportingText = if (allowBlank) null else {
{
AnimatedVisibility(visible = hasError) {
Text("Text cannot be empty")
Text(stringResource(Res.string.edit_text_dialog_empty_title_error))
}
}
},
Expand All @@ -94,7 +99,7 @@ fun EditTextDialog(
horizontalArrangement = Arrangement.spacedBy(8.dp)
) {
TextButton(onClick = onDismissRequest) {
Text("Cancel")
Text(stringResource(Res.string.dialog_cancel))
}
Button(
onClick = { onValidate(newTitle) },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,15 @@ import androidx.compose.ui.unit.dp
import net.opatry.tasks.app.ui.model.TaskListUIModel
import net.opatry.tasks.app.ui.tooling.TaskfolioPreview
import net.opatry.tasks.app.ui.tooling.TaskfolioThemedPreview
import net.opatry.tasks.resources.Res
import net.opatry.tasks.resources.task_list_menu_clear_all_completed_tasks
import net.opatry.tasks.resources.task_list_menu_default_list_cannot_be_deleted
import net.opatry.tasks.resources.task_list_menu_delete
import net.opatry.tasks.resources.task_list_menu_rename
import net.opatry.tasks.resources.task_list_menu_sort_by
import net.opatry.tasks.resources.task_list_menu_sort_due_date
import net.opatry.tasks.resources.task_list_menu_sort_manual
import org.jetbrains.compose.resources.stringResource

enum class TaskListMenuAction {
Dismiss,
Expand All @@ -71,23 +80,27 @@ fun TaskListMenu(taskList: TaskListUIModel, expanded: Boolean, onAction: (TaskLi
) {
DropdownMenuItem(
text = {
Text(text = "Sort by", style = MaterialTheme.typography.titleSmall)
Text(stringResource(Res.string.task_list_menu_sort_by), style = MaterialTheme.typography.titleSmall)
},
enabled = false,
onClick = {}
)

DropdownMenuItem(
text = {
RowWithIcon("Manual", LucideIcons.Check.takeIf { false/*taskList.sorting == TaskListSorting.Manual*/ })
RowWithIcon(
stringResource(Res.string.task_list_menu_sort_manual),
LucideIcons.Check.takeIf { false/*taskList.sorting == TaskListSorting.Manual*/ })
},
enabled = false, // TODO enable when sorting is implemented
onClick = { onAction(TaskListMenuAction.SortManual) }
)

DropdownMenuItem(
text = {
RowWithIcon("Due date", LucideIcons.Check.takeIf { false/*taskList.sorting == TaskListSorting.Date*/ })
RowWithIcon(
stringResource(Res.string.task_list_menu_sort_due_date),
LucideIcons.Check.takeIf { false/*taskList.sorting == TaskListSorting.Date*/ })
},
enabled = false, // TODO enable when sorting is implemented
onClick = { onAction(TaskListMenuAction.SortDate) }
Expand All @@ -97,14 +110,14 @@ fun TaskListMenu(taskList: TaskListUIModel, expanded: Boolean, onAction: (TaskLi

DropdownMenuItem(
text = {
Text(text = "Rename")
Text(stringResource(Res.string.task_list_menu_rename))
},
onClick = { onAction(TaskListMenuAction.Rename) }
)

DropdownMenuItem(
text = {
Text(text = "Clear all completed tasks")
Text(stringResource(Res.string.task_list_menu_clear_all_completed_tasks))
},
enabled = taskList.hasCompletedTasks,
onClick = { onAction(TaskListMenuAction.ClearCompletedTasks) }
Expand All @@ -120,9 +133,12 @@ fun TaskListMenu(taskList: TaskListUIModel, expanded: Boolean, onAction: (TaskLi
}
CompositionLocalProvider(LocalContentColor provides color) {
Column(Modifier.padding(vertical = 4.dp), verticalArrangement = Arrangement.spacedBy(8.dp)) {
RowWithIcon("Delete list", LucideIcons.Trash2)
RowWithIcon(stringResource(Res.string.task_list_menu_delete), LucideIcons.Trash2)
if (!allowDelete) {
Text("Default list can't be deleted", style = MaterialTheme.typography.bodySmall)
Text(
stringResource(Res.string.task_list_menu_default_list_cannot_be_deleted),
style = MaterialTheme.typography.bodySmall
)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,15 @@ import androidx.compose.runtime.remember
import androidx.compose.ui.text.style.TextOverflow
import net.opatry.tasks.app.ui.model.TaskListUIModel
import net.opatry.tasks.app.ui.model.TaskUIModel
import net.opatry.tasks.resources.Res
import net.opatry.tasks.resources.task_menu_add_subtask
import net.opatry.tasks.resources.task_menu_delete
import net.opatry.tasks.resources.task_menu_indent
import net.opatry.tasks.resources.task_menu_move_to
import net.opatry.tasks.resources.task_menu_move_to_top
import net.opatry.tasks.resources.task_menu_new_list
import net.opatry.tasks.resources.task_menu_unindent
import org.jetbrains.compose.resources.stringResource

sealed class TaskMenuAction {
data object Dismiss : TaskMenuAction()
Expand All @@ -68,7 +77,7 @@ fun TaskMenu(taskLists: List<TaskListUIModel>, task: TaskUIModel, expanded: Bool
if (canMoveToTop) {
DropdownMenuItem(
text = {
RowWithIcon("Move to top")
RowWithIcon(stringResource(Res.string.task_menu_move_to_top))
},
onClick = { onAction(TaskMenuAction.MoveToTop) },
enabled = false
Expand All @@ -78,7 +87,7 @@ fun TaskMenu(taskLists: List<TaskListUIModel>, task: TaskUIModel, expanded: Bool
if (task.canCreateSubTask) {
DropdownMenuItem(
text = {
RowWithIcon("Add subtask", LucideIcons.SquareStack)
RowWithIcon(stringResource(Res.string.task_menu_add_subtask), LucideIcons.SquareStack)
},
onClick = { onAction(TaskMenuAction.AddSubTask) },
enabled = false
Expand All @@ -88,7 +97,7 @@ fun TaskMenu(taskLists: List<TaskListUIModel>, task: TaskUIModel, expanded: Bool
if (task.canIndent && taskPosition > 0) {
DropdownMenuItem(
text = {
RowWithIcon("Indent")
RowWithIcon(stringResource(Res.string.task_menu_indent))
},
onClick = { onAction(TaskMenuAction.Indent) },
enabled = false
Expand All @@ -98,7 +107,7 @@ fun TaskMenu(taskLists: List<TaskListUIModel>, task: TaskUIModel, expanded: Bool
if (task.canUnindent) {
DropdownMenuItem(
text = {
RowWithIcon("Unindent")
RowWithIcon(stringResource(Res.string.task_menu_unindent))
},
onClick = { onAction(TaskMenuAction.Unindent) },
enabled = false
Expand All @@ -109,15 +118,15 @@ fun TaskMenu(taskLists: List<TaskListUIModel>, task: TaskUIModel, expanded: Bool

DropdownMenuItem(
text = {
Text(text = "Move to…", style = MaterialTheme.typography.titleSmall)
Text(stringResource(Res.string.task_menu_move_to), style = MaterialTheme.typography.titleSmall)
},
enabled = false,
onClick = {}
)

DropdownMenuItem(
text = {
RowWithIcon("New list", LucideIcons.ListPlus)
RowWithIcon(stringResource(Res.string.task_menu_new_list), LucideIcons.ListPlus)
},
onClick = { onAction(TaskMenuAction.MoveToNewList) },
enabled = false,
Expand Down Expand Up @@ -148,7 +157,7 @@ fun TaskMenu(taskLists: List<TaskListUIModel>, task: TaskUIModel, expanded: Bool
DropdownMenuItem(
text = {
CompositionLocalProvider(LocalContentColor provides MaterialTheme.colorScheme.error) {
RowWithIcon("Delete", LucideIcons.Trash2)
RowWithIcon(stringResource(Res.string.task_menu_delete), LucideIcons.Trash2)
}
},
onClick = { onAction(TaskMenuAction.Delete) }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,20 @@ import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.unit.dp
import net.opatry.tasks.resources.Res
import net.opatry.tasks.resources.task_lists_screen_empty_state_cta
import net.opatry.tasks.resources.task_lists_screen_empty_state_desc
import net.opatry.tasks.resources.task_lists_screen_empty_state_no_selection_desc
import net.opatry.tasks.resources.task_lists_screen_empty_state_no_selection_title
import net.opatry.tasks.resources.task_lists_screen_empty_state_title
import org.jetbrains.compose.resources.stringResource

@Composable
fun NoTaskListSelectedEmptyState() {
EmptyState(
icon = LucideIcons.CircleOff,
title = "No task list selected",
description = "Select a task list to see its tasks",
title = stringResource(Res.string.task_lists_screen_empty_state_no_selection_title),
description = stringResource(Res.string.task_lists_screen_empty_state_no_selection_desc),
modifier = Modifier.fillMaxSize()
)
}
Expand All @@ -54,12 +61,12 @@ fun NoTaskListEmptyState(onNewTaskListClick: () -> Unit) {
) {
EmptyState(
icon = LucideIcons.CheckCheck,
title = "No task list",
description = "Create a new task list to get started",
title = stringResource(Res.string.task_lists_screen_empty_state_title),
description = stringResource(Res.string.task_lists_screen_empty_state_desc),
modifier = Modifier.fillMaxWidth(1f)
)
Button(onClick = onNewTaskListClick) {
Text("New task list")
Text(stringResource(Res.string.task_lists_screen_empty_state_cta))
}
}
}
Loading

0 comments on commit 6f96831

Please sign in to comment.