mirror of https://github.com/tasks/tasks
Send share invites for Tasks.org & sabre/dav
parent
5201bca714
commit
5513d42777
@ -1,9 +1,43 @@
|
||||
package org.tasks.compose
|
||||
|
||||
import androidx.annotation.StringRes
|
||||
import androidx.compose.material.ButtonDefaults
|
||||
import androidx.compose.material.ContentAlpha
|
||||
import androidx.compose.material.MaterialTheme
|
||||
import androidx.compose.material.Text
|
||||
import androidx.compose.material.TextFieldDefaults
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import androidx.compose.ui.unit.dp
|
||||
import java.util.*
|
||||
|
||||
object Constants {
|
||||
const val ICON_ALPHA = 0.54f
|
||||
val KEYLINE_FIRST = 16.dp
|
||||
val HALF_KEYLINE = 8.dp
|
||||
|
||||
@Composable
|
||||
fun TextButton(@StringRes text: Int, onClick: () -> Unit) {
|
||||
androidx.compose.material.TextButton(
|
||||
onClick = onClick,
|
||||
colors = textButtonColors()
|
||||
) {
|
||||
Text(
|
||||
stringResource(text).toUpperCase(Locale.getDefault()),
|
||||
style = MaterialTheme.typography.button
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
fun textButtonColors() = ButtonDefaults.textButtonColors(
|
||||
contentColor = MaterialTheme.colors.secondary
|
||||
)
|
||||
|
||||
@Composable
|
||||
fun textFieldColors() = TextFieldDefaults.textFieldColors(
|
||||
cursorColor = MaterialTheme.colors.secondary,
|
||||
focusedLabelColor = MaterialTheme.colors.secondary.copy(alpha = ContentAlpha.high),
|
||||
focusedIndicatorColor = MaterialTheme.colors.secondary.copy(alpha = ContentAlpha.high),
|
||||
)
|
||||
}
|
||||
@ -0,0 +1,111 @@
|
||||
package org.tasks.compose
|
||||
|
||||
import androidx.compose.foundation.layout.Column
|
||||
import androidx.compose.foundation.layout.Spacer
|
||||
import androidx.compose.foundation.layout.fillMaxWidth
|
||||
import androidx.compose.foundation.layout.height
|
||||
import androidx.compose.foundation.text.KeyboardOptions
|
||||
import androidx.compose.material.AlertDialog
|
||||
import androidx.compose.material.Icon
|
||||
import androidx.compose.material.MaterialTheme
|
||||
import androidx.compose.material.OutlinedTextField
|
||||
import androidx.compose.material.Text
|
||||
import androidx.compose.material.darkColors
|
||||
import androidx.compose.material.icons.Icons
|
||||
import androidx.compose.material.icons.outlined.Email
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.MutableState
|
||||
import androidx.compose.runtime.mutableStateOf
|
||||
import androidx.compose.runtime.saveable.rememberSaveable
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import androidx.compose.ui.text.input.KeyboardType
|
||||
import androidx.compose.ui.tooling.preview.Preview
|
||||
import org.tasks.R
|
||||
import org.tasks.compose.Constants.TextButton
|
||||
import org.tasks.compose.Constants.textFieldColors
|
||||
import org.tasks.compose.ShareInvite.ShareInvite
|
||||
|
||||
@Preview(showBackground = true, backgroundColor = 0xFFFFFF)
|
||||
@Composable
|
||||
private fun Invite() = MaterialTheme {
|
||||
ShareInvite(mutableStateOf(""))
|
||||
}
|
||||
|
||||
@Preview(showBackground = true, backgroundColor = 0x202124)
|
||||
@Composable
|
||||
private fun InviteDark() = MaterialTheme(darkColors()) {
|
||||
ShareInvite(mutableStateOf(""))
|
||||
}
|
||||
|
||||
@Preview(showBackground = true, backgroundColor = 0xFFFFFF)
|
||||
@Composable
|
||||
private fun InviteFilled() = MaterialTheme {
|
||||
ShareInvite(mutableStateOf("user@example.com"))
|
||||
}
|
||||
|
||||
@Preview(showBackground = true, backgroundColor = 0x202124)
|
||||
@Composable
|
||||
private fun InviteDarkFilled() = MaterialTheme(darkColors()) {
|
||||
ShareInvite(mutableStateOf("user@example.com"))
|
||||
}
|
||||
|
||||
object ShareInvite {
|
||||
@Composable
|
||||
fun ShareInviteDialog(
|
||||
openDialog: MutableState<Boolean>,
|
||||
invite: (String?) -> Unit,
|
||||
) {
|
||||
val email = rememberSaveable { mutableStateOf("") }
|
||||
// TODO: remove after beta02 release: https://issuetracker.google.com/issues/181282423
|
||||
val enableHack = rememberSaveable { mutableStateOf(true) }
|
||||
if (openDialog.value) {
|
||||
AlertDialog(
|
||||
onDismissRequest = {},
|
||||
text = { ShareInvite(email, enableHack) },
|
||||
confirmButton = {
|
||||
TextButton(text = R.string.invite, onClick = {
|
||||
enableHack.value = false
|
||||
invite(email.value)
|
||||
})
|
||||
},
|
||||
dismissButton = {
|
||||
TextButton(text = R.string.cancel, onClick = {
|
||||
enableHack.value = false
|
||||
invite(null as String?)
|
||||
})
|
||||
},
|
||||
)
|
||||
} else {
|
||||
email.value = ""
|
||||
enableHack.value = true
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
fun ShareInvite(email: MutableState<String>, enableHack: MutableState<Boolean> = mutableStateOf(true)) {
|
||||
Column(modifier = Modifier.fillMaxWidth()) {
|
||||
Text(
|
||||
stringResource(R.string.share_list),
|
||||
style = MaterialTheme.typography.h6,
|
||||
)
|
||||
Spacer(Modifier.height(Constants.KEYLINE_FIRST))
|
||||
OutlinedTextField(
|
||||
modifier = Modifier.fillMaxWidth(),
|
||||
value = email.value,
|
||||
label = { Text(stringResource(R.string.email)) },
|
||||
keyboardOptions = KeyboardOptions(keyboardType = KeyboardType.Email),
|
||||
onValueChange = { email.value = it },
|
||||
leadingIcon = {
|
||||
Icon(
|
||||
imageVector = Icons.Outlined.Email,
|
||||
contentDescription = stringResource(id = R.string.email)
|
||||
)
|
||||
},
|
||||
enabled = enableHack.value,
|
||||
textStyle = MaterialTheme.typography.body1,
|
||||
colors = textFieldColors(),
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,10 @@
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="24dp"
|
||||
android:height="24dp"
|
||||
android:viewportWidth="24"
|
||||
android:viewportHeight="24"
|
||||
android:tint="?attr/colorControlNormal">
|
||||
<path
|
||||
android:fillColor="@android:color/white"
|
||||
android:pathData="M15,12c2.21,0 4,-1.79 4,-4s-1.79,-4 -4,-4 -4,1.79 -4,4 1.79,4 4,4zM15,6c1.1,0 2,0.9 2,2s-0.9,2 -2,2 -2,-0.9 -2,-2 0.9,-2 2,-2zM15,14c-2.67,0 -8,1.34 -8,4v2h16v-2c0,-2.66 -5.33,-4 -8,-4zM9,18c0.22,-0.72 3.31,-2 6,-2 2.7,0 5.8,1.29 6,2L9,18zM6,15v-3h3v-2L6,10L6,7L4,7v3L1,10v2h3v3z"/>
|
||||
</vector>
|
||||
@ -1,48 +1,64 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:id="@+id/root_layout"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:descendantFocusability="beforeDescendants"
|
||||
android:focusableInTouchMode="true"
|
||||
android:orientation="vertical">
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:id="@+id/root_layout"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:descendantFocusability="beforeDescendants"
|
||||
android:focusableInTouchMode="true"
|
||||
android:orientation="vertical">
|
||||
|
||||
<include layout="@layout/toolbar"/>
|
||||
|
||||
<include layout="@layout/progress_view"/>
|
||||
|
||||
<ScrollView
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content">
|
||||
|
||||
<LinearLayout
|
||||
<FrameLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical">
|
||||
android:layout_height="match_parent">
|
||||
|
||||
<com.google.android.material.textfield.TextInputLayout
|
||||
android:id="@+id/name_layout"
|
||||
style="@style/TagSettingsRow"
|
||||
android:hint="@string/display_name">
|
||||
<ScrollView
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content">
|
||||
|
||||
<com.google.android.material.textfield.TextInputEditText
|
||||
android:id="@+id/name"
|
||||
style="@style/TagSettingsEditText"
|
||||
android:inputType="textCapSentences|textAutoCorrect" />
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical">
|
||||
|
||||
</com.google.android.material.textfield.TextInputLayout>
|
||||
<com.google.android.material.textfield.TextInputLayout
|
||||
android:id="@+id/name_layout"
|
||||
style="@style/TagSettingsRow"
|
||||
android:hint="@string/display_name">
|
||||
|
||||
<include layout="@layout/list_settings_color"/>
|
||||
<com.google.android.material.textfield.TextInputEditText
|
||||
android:id="@+id/name"
|
||||
style="@style/TagSettingsEditText"
|
||||
android:inputType="textCapSentences|textAutoCorrect" />
|
||||
|
||||
<include layout="@layout/list_settings_icon"/>
|
||||
</com.google.android.material.textfield.TextInputLayout>
|
||||
|
||||
<androidx.compose.ui.platform.ComposeView
|
||||
android:id="@+id/people"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"/>
|
||||
<include layout="@layout/list_settings_color"/>
|
||||
|
||||
<include layout="@layout/list_settings_icon"/>
|
||||
|
||||
<androidx.compose.ui.platform.ComposeView
|
||||
android:id="@+id/people"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"/>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
</LinearLayout>
|
||||
</ScrollView>
|
||||
|
||||
</ScrollView>
|
||||
<androidx.compose.ui.platform.ComposeView
|
||||
android:id="@+id/fab"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_margin="@dimen/keyline_first"
|
||||
android:layout_gravity="end|bottom"
|
||||
android:padding="0dp"
|
||||
android:visibility="gone" />
|
||||
|
||||
</FrameLayout>
|
||||
</LinearLayout>
|
||||
|
||||
Loading…
Reference in New Issue