mirror of https://github.com/tasks/tasks
TaskEditRow composable with slots
parent
2e2e74217e
commit
8c137f6521
@ -0,0 +1,18 @@
|
|||||||
|
package org.tasks.compose
|
||||||
|
|
||||||
|
import androidx.annotation.DrawableRes
|
||||||
|
import androidx.compose.material.ContentAlpha
|
||||||
|
import androidx.compose.material.Icon
|
||||||
|
import androidx.compose.runtime.Composable
|
||||||
|
import androidx.compose.ui.Modifier
|
||||||
|
import androidx.compose.ui.draw.alpha
|
||||||
|
import androidx.compose.ui.res.painterResource
|
||||||
|
|
||||||
|
@Composable
|
||||||
|
fun TaskEditIcon(@DrawableRes id: Int, modifier: Modifier = Modifier) {
|
||||||
|
Icon(
|
||||||
|
painter = painterResource(id = id),
|
||||||
|
contentDescription = null,
|
||||||
|
modifier = modifier.alpha(ContentAlpha.high),
|
||||||
|
)
|
||||||
|
}
|
||||||
@ -0,0 +1,23 @@
|
|||||||
|
package org.tasks.compose
|
||||||
|
|
||||||
|
import androidx.compose.foundation.clickable
|
||||||
|
import androidx.compose.foundation.layout.Row
|
||||||
|
import androidx.compose.runtime.Composable
|
||||||
|
import androidx.compose.ui.Modifier
|
||||||
|
|
||||||
|
@Composable
|
||||||
|
fun TaskEditRow(
|
||||||
|
icon: @Composable () -> Unit,
|
||||||
|
content: @Composable () -> Unit,
|
||||||
|
onClick: (() -> Unit)? = null,
|
||||||
|
) {
|
||||||
|
Row(modifier = Modifier
|
||||||
|
.clickable(
|
||||||
|
enabled = onClick != null,
|
||||||
|
onClick = { onClick?.invoke() }
|
||||||
|
)
|
||||||
|
) {
|
||||||
|
icon()
|
||||||
|
content()
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -1,24 +1,58 @@
|
|||||||
package org.tasks.ui
|
package org.tasks.ui
|
||||||
|
|
||||||
|
import android.os.Bundle
|
||||||
|
import android.view.LayoutInflater
|
||||||
|
import android.view.View
|
||||||
import android.view.ViewGroup
|
import android.view.ViewGroup
|
||||||
|
import androidx.compose.foundation.layout.padding
|
||||||
import androidx.compose.runtime.Composable
|
import androidx.compose.runtime.Composable
|
||||||
|
import androidx.compose.ui.Modifier
|
||||||
import androidx.compose.ui.platform.ComposeView
|
import androidx.compose.ui.platform.ComposeView
|
||||||
|
import androidx.compose.ui.unit.dp
|
||||||
|
import androidx.lifecycle.ViewModelProvider
|
||||||
import com.google.android.material.composethemeadapter.MdcTheme
|
import com.google.android.material.composethemeadapter.MdcTheme
|
||||||
import org.tasks.R
|
import org.tasks.compose.TaskEditIcon
|
||||||
|
import org.tasks.compose.TaskEditRow
|
||||||
|
|
||||||
abstract class TaskEditControlComposeFragment : TaskEditControlFragment() {
|
abstract class TaskEditControlComposeFragment : TaskEditControlFragment() {
|
||||||
|
|
||||||
override fun bind(parent: ViewGroup?) =
|
override fun onCreateView(
|
||||||
(parent?.findViewById(R.id.compose_view) as ComposeView).apply {
|
inflater: LayoutInflater,
|
||||||
|
container: ViewGroup?,
|
||||||
|
savedInstanceState: Bundle?
|
||||||
|
): View? {
|
||||||
|
val composeView = ComposeView(requireActivity())
|
||||||
|
viewModel = ViewModelProvider(requireParentFragment())[TaskEditViewModel::class.java]
|
||||||
|
bind(composeView)
|
||||||
|
createView(savedInstanceState)
|
||||||
|
return composeView
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun bind(parent: ViewGroup?): View =
|
||||||
|
(parent as ComposeView).apply {
|
||||||
setContent {
|
setContent {
|
||||||
MdcTheme {
|
MdcTheme {
|
||||||
Body()
|
TaskEditRow(
|
||||||
|
icon = { Icon() },
|
||||||
|
content = { Body() },
|
||||||
|
onClick = if (this@TaskEditControlComposeFragment.isClickable)
|
||||||
|
this@TaskEditControlComposeFragment::onRowClick
|
||||||
|
else
|
||||||
|
null
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
protected abstract fun Body()
|
protected open fun Icon() {
|
||||||
|
TaskEditIcon(
|
||||||
|
id = icon,
|
||||||
|
modifier = Modifier
|
||||||
|
.padding(start = 16.dp, top = 20.dp, end = 32.dp, bottom = 20.dp),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
override val rootLayout = R.layout.control_set_template_compose
|
@Composable
|
||||||
|
protected abstract fun Body()
|
||||||
}
|
}
|
||||||
@ -1,30 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
|
||||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
|
||||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
|
||||||
xmlns:tools="http://schemas.android.com/tools"
|
|
||||||
android:id="@+id/content"
|
|
||||||
android:layout_width="fill_parent"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
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:alpha="@dimen/alpha_secondary"
|
|
||||||
android:paddingStart="@dimen/keyline_first"
|
|
||||||
android:paddingTop="20dp"
|
|
||||||
android:paddingEnd="@dimen/keyline_second"
|
|
||||||
android:paddingBottom="20dp"
|
|
||||||
android:scaleType="center"
|
|
||||||
app:tint="@color/icon_tint"
|
|
||||||
tools:ignore="ContentDescription" />
|
|
||||||
|
|
||||||
<androidx.compose.ui.platform.ComposeView
|
|
||||||
android:id="@+id/compose_view"
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="wrap_content" />
|
|
||||||
|
|
||||||
</LinearLayout>
|
|
||||||
Loading…
Reference in New Issue