Add configuration option for newlines in title

pull/3223/head
Alex Baker 11 months ago
parent 8493175733
commit 435d276a64

@ -3,6 +3,7 @@
* Microsoft To Do support [#2011](https://github.com/tasks/tasks/issues/2011)
* This feature is in early access, USE AT YOUR OWN RISK
* Enable under 'Advanced' settings
* Add configuration option for new lines in titles
* Subscription changes
* Multiple Google Task accounts are now free to use
* Tasker plugins are now free to use

@ -324,6 +324,7 @@ class TaskEditFragment : Fragment() {
}
},
requestFocus = requestFocus,
multiline = viewState.multilineTitle,
)
}

@ -35,6 +35,7 @@ fun DescriptionRow(
onChanged = onChanged,
linkify = linkify,
markdownProvider = markdownProvider,
multiline = true,
)
Spacer(modifier = Modifier.height(11.dp))
}

@ -38,6 +38,7 @@ fun EditTextView(
markdownProvider: MarkdownProvider?,
strikethrough: Boolean = false,
requestFocus: Boolean = false,
multiline: Boolean = false,
) {
val context = LocalContext.current
var shouldRequestFocus by remember { mutableStateOf(false) }
@ -57,23 +58,48 @@ fun EditTextView(
onTextChanged = { text, _, _, _ -> onChanged(text) },
afterTextChanged = { editable -> textWatcher?.invoke(editable) }
)
if (multiline) {
// Multiline configuration
setRawInputType(
InputType.TYPE_CLASS_TEXT or
InputType.TYPE_TEXT_FLAG_CAP_SENTENCES or
InputType.TYPE_TEXT_FLAG_MULTI_LINE or
InputType.TYPE_TEXT_FLAG_AUTO_CORRECT
)
isSingleLine = false
maxLines = Int.MAX_VALUE
imeOptions = EditorInfo.IME_FLAG_NO_EXTRACT_UI
} else {
// Single line with Done button
setRawInputType(
InputType.TYPE_CLASS_TEXT or
InputType.TYPE_TEXT_FLAG_CAP_SENTENCES or
InputType.TYPE_TEXT_FLAG_AUTO_CORRECT
)
isSingleLine = true
maxLines = 1
imeOptions = EditorInfo.IME_ACTION_DONE or EditorInfo.IME_FLAG_NO_EXTRACT_UI
setImeActionLabel(context.getString(android.R.string.ok), EditorInfo.IME_ACTION_DONE)
setOnEditorActionListener { _, actionId, _ ->
if (actionId == EditorInfo.IME_ACTION_DONE) {
clearFocus()
val imm = context.getSystemService(INPUT_METHOD_SERVICE) as InputMethodManager
imm.hideSoftInputFromWindow(windowToken, 0)
true
} else {
false
}
}
}
setBackgroundColor(context.getColor(android.R.color.transparent))
textAlignment = View.TEXT_ALIGNMENT_VIEW_START
imeOptions = EditorInfo.IME_FLAG_NO_EXTRACT_UI
inputType =
InputType.TYPE_CLASS_TEXT or
InputType.TYPE_TEXT_FLAG_CAP_SENTENCES or
InputType.TYPE_TEXT_FLAG_MULTI_LINE or
InputType.TYPE_TEXT_FLAG_AUTO_CORRECT
isSingleLine = false
maxLines = Int.MAX_VALUE
if (AndroidUtilities.atLeastOreo()) {
importantForAutofill = View.IMPORTANT_FOR_AUTOFILL_NO
}
isVerticalScrollBarEnabled = true
freezesText = true
setHorizontallyScrolling(false)
isHorizontalScrollBarEnabled = false
setHint(hint)
setHintTextColor(context.getColor(R.color.text_tertiary))
setTextSize(

@ -30,6 +30,7 @@ fun TitleRow(
priority: Int,
onComplete: () -> Unit,
requestFocus: Boolean,
multiline: Boolean,
) {
TaskEditRow(
icon = {
@ -55,6 +56,7 @@ fun TitleRow(
markdownProvider = markdownProvider,
strikethrough = isCompleted,
requestFocus = requestFocus,
multiline = multiline,
)
Spacer(modifier = Modifier.height(11.dp))
}
@ -78,6 +80,7 @@ fun EmptyTitlePreview() {
priority = 0,
onComplete = {},
requestFocus = false,
multiline = false,
)
}
}
@ -102,6 +105,7 @@ fun TitlePreview() {
priority = 0,
onComplete = {},
requestFocus = false,
multiline = false,
)
}
}

@ -577,6 +577,9 @@ class Preferences @JvmOverloads constructor(
val linkify: Boolean
get() = getBoolean(R.string.p_linkify_task_edit, false)
val multilineTitle: Boolean
get() = getBoolean(R.string.p_multiline_title, false)
companion object {
private fun getSharedPreferencesName(context: Context): String =
context.packageName + "_preferences"

@ -124,6 +124,7 @@ class TaskEditViewModel @Inject constructor(
val attachments: ImmutableSet<TaskAttachment> = persistentSetOf(),
val alarms: ImmutableSet<Alarm>,
val newSubtasks: ImmutableList<Task> = persistentListOf(),
val multilineTitle: Boolean,
) {
val isNew: Boolean
get() = task.isNew
@ -199,6 +200,7 @@ class TaskEditViewModel @Inject constructor(
} else {
savedStateHandle[TaskEditFragment.EXTRA_ALARMS]!!
}.toPersistentSet(),
multilineTitle = preferences.multilineTitle,
)
)
val viewState: StateFlow<ViewState> = _viewState

@ -436,4 +436,5 @@
<string name="p_shown_beast_mode_hint">shown_beast_mode_hint</string>
<string name="p_last_sync">last_sync_time</string>
<string name="p_microsoft_sync">microsoft_sync</string>
<string name="p_multiline_title">multiline_title</string>
</resources>

@ -730,4 +730,7 @@ File %1$s contained %2$s.\n\n
<string name="cost_free">Cost: Free</string>
<string name="cost_money">Cost: $</string>
<string name="cost_more_money">Cost: $$$</string>
<string name="multiline_title">Allow multiline titles</string>
<string name="multiline_title_on">Press Enter key to add line breaks</string>
<string name="multiline_title_off">Press Done to close keyboard</string>
</resources>

@ -24,6 +24,13 @@
android:key="@string/p_back_button_saves_task"
android:title="@string/back_button_saves_task" />
<SwitchPreferenceCompat
android:defaultValue="false"
android:key="@string/p_multiline_title"
android:title="@string/multiline_title"
android:summaryOn="@string/multiline_title_on"
android:summaryOff="@string/multiline_title_off" />
<SwitchPreferenceCompat
android:defaultValue="false"
android:key="@string/p_show_task_edit_comments"

@ -1,6 +1,7 @@
* Microsoft To Do support
* This feature is in early access, USE AT YOUR OWN RISK
* Enable under 'Advanced' settings
* Add configuration option for new lines in titles
* Subscription changes
* Multiple Google Task accounts are now free to use
* Tasker plugins are now free to use

Loading…
Cancel
Save