Convert DescriptionControlSet to compose

pull/1952/head
Alex Baker 3 years ago
parent 1615f215c4
commit f4d69a8a69

@ -26,11 +26,11 @@ import org.tasks.files.ImageHelper
import org.tasks.preferences.Device import org.tasks.preferences.Device
import org.tasks.preferences.Preferences import org.tasks.preferences.Preferences
import org.tasks.themes.ThemeColor import org.tasks.themes.ThemeColor
import org.tasks.ui.TaskEditControlViewFragment import org.tasks.ui.TaskEditControlFragment
import javax.inject.Inject import javax.inject.Inject
@AndroidEntryPoint @AndroidEntryPoint
class CommentBarFragment : TaskEditControlViewFragment() { class CommentBarFragment : TaskEditControlFragment() {
@Inject lateinit var activity: Activity @Inject lateinit var activity: Activity
@Inject lateinit var dialogBuilder: DialogBuilder @Inject lateinit var dialogBuilder: DialogBuilder
@Inject lateinit var device: Device @Inject lateinit var device: Device

@ -1,45 +1,78 @@
package org.tasks.ui package org.tasks.ui
import android.os.Bundle import android.text.InputType
import android.view.ViewGroup import android.util.TypedValue
import android.view.View
import android.view.inputmethod.EditorInfo
import android.widget.EditText import android.widget.EditText
import androidx.compose.foundation.layout.*
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.unit.dp
import androidx.compose.ui.viewinterop.AndroidView
import androidx.core.widget.addTextChangedListener import androidx.core.widget.addTextChangedListener
import dagger.hilt.android.AndroidEntryPoint import dagger.hilt.android.AndroidEntryPoint
import org.tasks.R import org.tasks.R
import org.tasks.databinding.ControlSetDescriptionBinding
import org.tasks.dialogs.Linkify import org.tasks.dialogs.Linkify
import org.tasks.markdown.MarkdownProvider import org.tasks.markdown.MarkdownProvider
import org.tasks.preferences.Preferences import org.tasks.preferences.Preferences
import org.tasks.ui.TaskEditViewModel.Companion.stripCarriageReturns
import javax.inject.Inject import javax.inject.Inject
@AndroidEntryPoint @AndroidEntryPoint
class DescriptionControlSet : TaskEditControlViewFragment() { class DescriptionControlSet : TaskEditControlComposeFragment() {
@Inject lateinit var linkify: Linkify @Inject lateinit var linkify: Linkify
@Inject lateinit var preferences: Preferences @Inject lateinit var preferences: Preferences
@Inject lateinit var markdownProvider: MarkdownProvider @Inject lateinit var markdownProvider: MarkdownProvider
private lateinit var editText: EditText
private val linkifyEnabled: Boolean private val linkifyEnabled: Boolean
get() = preferences.getBoolean(R.string.p_linkify_task_edit, false) get() = preferences.getBoolean(R.string.p_linkify_task_edit, false)
override fun createView(savedInstanceState: Bundle?) { @Composable
viewModel.description?.let(editText::setTextKeepState) override fun Body() {
if (linkifyEnabled) { Column(verticalArrangement = Arrangement.Center) {
linkify.linkify(editText) Spacer(modifier = Modifier.height(11.dp))
} AndroidView(
} modifier = Modifier
.fillMaxWidth()
override fun bind(parent: ViewGroup?) = .wrapContentHeight()
ControlSetDescriptionBinding.inflate(layoutInflater, parent, true).let { .padding(end = 16.dp),
editText = it.notes factory = { context ->
val textWatcher = markdownProvider.markdown(linkifyEnabled).textWatcher(editText) EditText(context).apply {
editText.addTextChangedListener( setText(viewModel.description.stripCarriageReturns())
onTextChanged = { text, _, _, _ -> textChanged(text) }, val textWatcher =
afterTextChanged = { editable -> textWatcher?.invoke(editable) } markdownProvider.markdown(linkifyEnabled).textWatcher(this)
addTextChangedListener(
onTextChanged = { text, _, _, _ -> textChanged(text) },
afterTextChanged = { editable -> textWatcher?.invoke(editable) }
)
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
importantForAutofill = View.IMPORTANT_FOR_AUTOFILL_NO
isVerticalScrollBarEnabled = true
freezesText = true
setHorizontallyScrolling(false)
isHorizontalScrollBarEnabled = false
setHint(R.string.TEA_note_label)
setHintTextColor(context.getColor(R.color.text_tertiary))
setTextSize(TypedValue.COMPLEX_UNIT_PX, context.resources.getDimension(R.dimen.task_edit_text_size))
if (linkifyEnabled) {
linkify.linkify(this)
}
}
},
) )
it.root Spacer(modifier = Modifier.height(11.dp))
} }
}
override val icon = R.drawable.ic_outline_notes_24px override val icon = R.drawable.ic_outline_notes_24px

@ -1,28 +0,0 @@
package org.tasks.ui
import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.ImageView
import androidx.lifecycle.ViewModelProvider
import org.tasks.R
abstract class TaskEditControlViewFragment : TaskEditControlFragment() {
override fun onCreateView(
inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
val view = inflater.inflate(R.layout.control_set_template, null)
viewModel = ViewModelProvider(requireParentFragment())[TaskEditViewModel::class.java]
val content = view.findViewById<ViewGroup>(R.id.content)
bind(content)
val icon = view.findViewById<ImageView>(R.id.icon)
icon.setImageResource(this.icon)
if (isClickable) {
content.setOnClickListener { onRowClick() }
}
createView(savedInstanceState)
return view
}
}

@ -1,15 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<EditText xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/notes"
style="@style/TaskEditTextPrimary"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@android:color/transparent"
android:freezesText="true"
android:gravity="start"
android:hint="@string/TEA_note_label"
android:imeOptions="flagNoExtractUi"
android:inputType="textCapSentences|textMultiLine"
android:importantForAutofill="no"
android:scrollbars="vertical"
android:textAlignment="viewStart"/>

@ -1,27 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/content"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:paddingTop="@dimen/task_edit_spacing"
android:paddingBottom="@dimen/task_edit_spacing"
android:paddingStart="0dp"
android:paddingEnd="@dimen/keyline_first"
android:background="?attr/selectableItemBackground"
android:orientation="horizontal">
<ImageView
android:id="@+id/icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="top"
android:paddingStart="@dimen/keyline_first"
android:paddingEnd="@dimen/keyline_second"
android:alpha="@dimen/alpha_secondary"
android:scaleType="center"
app:tint="@color/icon_tint"
tools:ignore="ContentDescription"/>
</LinearLayout>

@ -25,12 +25,6 @@
<item name="textInputStyle">@style/OutlinedBox</item> <item name="textInputStyle">@style/OutlinedBox</item>
</style> </style>
<style name="TaskEditTextPrimary">
<item name="android:textColor">?android:attr/textColorPrimary</item>
<item name="android:textColorHint">?android:attr/textColorTertiary</item>
<item name="android:textSize">@dimen/task_edit_text_size</item>
</style>
<style name="ToolbarTheme" parent="ThemeOverlay.MaterialComponents.Light"> <style name="ToolbarTheme" parent="ThemeOverlay.MaterialComponents.Light">
<item name="toolbarNavigationButtonStyle">@style/BlackNavigation</item> <item name="toolbarNavigationButtonStyle">@style/BlackNavigation</item>
<item name="iconTint">@color/text_primary</item> <item name="iconTint">@color/text_primary</item>

Loading…
Cancel
Save