Add cost info to sync account dialog

pull/3221/head
Alex Baker 1 year ago
parent 719c117779
commit c227fcc39a

@ -4,7 +4,6 @@ import android.content.res.Configuration
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.rememberScrollState
import androidx.compose.foundation.verticalScroll
import androidx.compose.material.ContentAlpha
import androidx.compose.material3.MaterialTheme
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
@ -17,12 +16,14 @@ import org.tasks.themes.TasksTheme
@Composable
fun AddAccountDialog(
hasTasksAccount: Boolean,
hasPro: Boolean,
selected: (Platform) -> Unit,
) {
Column(modifier = Modifier.verticalScroll(rememberScrollState())) {
if (!hasTasksAccount) {
SyncAccount(
title = R.string.tasks_org,
cost = R.string.cost_more_money,
description = R.string.tasks_org_description,
icon = R.drawable.ic_round_icon,
onClick = { selected(Platform.TASKS_ORG) }
@ -30,6 +31,7 @@ fun AddAccountDialog(
}
SyncAccount(
title = R.string.gtasks_GPr_header,
cost = if (hasPro) null else R.string.cost_free,
description = R.string.google_tasks_selection_description,
icon = R.drawable.ic_google,
onClick = { selected(Platform.GOOGLE_TASKS) }
@ -37,6 +39,7 @@ fun AddAccountDialog(
if (BuildConfig.DEBUG) {
SyncAccount(
title = R.string.microsoft,
cost = if (hasPro) null else R.string.cost_free,
description = R.string.microsoft_selection_description,
icon = R.drawable.ic_microsoft_tasks,
onClick = { selected(Platform.MICROSOFT) }
@ -44,27 +47,31 @@ fun AddAccountDialog(
}
SyncAccount(
title = R.string.davx5,
cost = if (hasPro) null else R.string.cost_money,
description = R.string.davx5_selection_description,
icon = R.drawable.ic_davx5_icon_green_bg,
onClick = { selected(Platform.DAVX5) }
)
SyncAccount(
title = R.string.caldav,
cost = if (hasPro) null else R.string.cost_money,
description = R.string.caldav_selection_description,
icon = R.drawable.ic_webdav_logo,
tint = MaterialTheme.colorScheme.onSurface.copy(
alpha = ContentAlpha.medium
alpha = .8f
),
onClick = { selected(Platform.CALDAV) }
)
SyncAccount(
title = R.string.etesync,
cost = if (hasPro) null else R.string.cost_money,
description = R.string.etesync_selection_description,
icon = R.drawable.ic_etesync,
onClick = { selected(Platform.ETESYNC) }
)
SyncAccount(
title = R.string.decsync,
cost = if (hasPro) null else R.string.cost_money,
description = R.string.decsync_selection_description,
icon = R.drawable.ic_decsync,
onClick = { selected(Platform.DECSYNC_CC) }
@ -77,6 +84,15 @@ fun AddAccountDialog(
@Composable
fun AddAccountDialogPreview() {
TasksTheme {
AddAccountDialog(hasTasksAccount = false, selected = {})
AddAccountDialog(hasTasksAccount = false, hasPro = false, selected = {})
}
}
@Preview(showBackground = true, widthDp = 320)
@Preview(showBackground = true, uiMode = Configuration.UI_MODE_NIGHT_YES, widthDp = 320)
@Composable
fun AddAccountDialogPreviewWithPro() {
TasksTheme {
AddAccountDialog(hasTasksAccount = false, hasPro = true, selected = {})
}
}

@ -22,6 +22,7 @@ import androidx.compose.ui.unit.dp
@Composable
fun SyncAccount(
@StringRes title: Int,
@StringRes cost: Int? = null,
@StringRes description: Int,
@DrawableRes icon: Int,
tint: Color? = null,
@ -46,6 +47,13 @@ fun SyncAccount(
style = MaterialTheme.typography.bodyLarge,
color = MaterialTheme.colorScheme.onSurface,
)
cost?.let {
Text(
text = stringResource(id = it),
style = MaterialTheme.typography.labelSmall,
color = MaterialTheme.colorScheme.primary,
)
}
Text(
text = stringResource(id = description),
style = MaterialTheme.typography.bodyMedium,

@ -1,6 +1,5 @@
package org.tasks.preferences
import org.tasks.filters.CustomFilter
import kotlinx.coroutines.runBlocking
import org.tasks.R
import org.tasks.Strings.isNullOrEmpty
@ -16,6 +15,7 @@ import org.tasks.data.entity.CaldavTask
import org.tasks.data.entity.Task
import org.tasks.data.getLocalList
import org.tasks.filters.CaldavFilter
import org.tasks.filters.CustomFilter
import org.tasks.filters.Filter
import org.tasks.filters.GtasksFilter
import org.tasks.filters.MyTasksFilter
@ -177,6 +177,7 @@ class DefaultFilterProvider @Inject constructor(
} else {
val googleTask = googleTaskDao.getByTaskId(task.id)
val caldavTask = caldavDao.getTask(task.id)
val caldavAccount = caldavDao.getAccountForTask(task.id)
if (googleTask != null) {
val googleTaskList = googleTaskListDao.getByRemoteId(googleTask.calendar!!)
if (googleTaskList != null) {

@ -172,7 +172,10 @@ class MainSettingsFragment : InjectingPreferenceFragment() {
private fun addAccount(): Boolean {
lifecycleScope.launch {
newAccountDialog(hasTasksAccount = viewModel.tasksAccount() != null)
newAccountDialog(
hasTasksAccount = viewModel.tasksAccount() != null,
hasPro = inventory.hasPro,
)
.show(parentFragmentManager, FRAG_TAG_ADD_ACCOUNT)
}
return false

@ -22,6 +22,9 @@ class AddAccountDialog : DialogFragment() {
private val hasTasksAccount: Boolean
get() = arguments?.getBoolean(EXTRA_HAS_TASKS_ACCOUNT) ?: false
private val hasPro: Boolean
get() = arguments?.getBoolean(EXTRA_HAS_PRO) ?: false
enum class Platform {
TASKS_ORG,
GOOGLE_TASKS,
@ -40,6 +43,7 @@ class AddAccountDialog : DialogFragment() {
TasksTheme(theme = theme.themeBase.index) {
org.tasks.compose.AddAccountDialog(
hasTasksAccount = hasTasksAccount,
hasPro = hasPro,
selected = this::selected
)
}
@ -58,10 +62,17 @@ class AddAccountDialog : DialogFragment() {
const val ADD_ACCOUNT = "add_account"
const val EXTRA_SELECTED = "selected"
private const val EXTRA_HAS_TASKS_ACCOUNT = "extra_has_tasks_account"
private const val EXTRA_HAS_PRO = "extra_has_pro"
fun newAccountDialog(hasTasksAccount: Boolean) =
fun newAccountDialog(
hasTasksAccount: Boolean,
hasPro: Boolean,
) =
AddAccountDialog().apply {
arguments = bundleOf(EXTRA_HAS_TASKS_ACCOUNT to hasTasksAccount)
arguments = bundleOf(
EXTRA_HAS_TASKS_ACCOUNT to hasTasksAccount,
EXTRA_HAS_PRO to hasPro,
)
}
}
}

@ -728,4 +728,7 @@ File %1$s contained %2$s.\n\n
<string name="sort_not_available">Not available for tags, filters, or places</string>
<string name="add_shortcut_to_home_screen">Add shortcut to home screen</string>
<string name="add_widget_to_home_screen">Add widget to home screen</string>
<string name="cost_free">Cost: Free</string>
<string name="cost_money">Cost: $</string>
<string name="cost_more_money">Cost: $$$</string>
</resources>

Loading…
Cancel
Save