mirror of https://github.com/tasks/tasks
Remove AddAccountDialog
parent
e7ef63a8c6
commit
d1f9116e01
@ -1,95 +0,0 @@
|
||||
package org.tasks.compose
|
||||
|
||||
import android.content.res.Configuration
|
||||
import androidx.compose.foundation.layout.Column
|
||||
import androidx.compose.foundation.rememberScrollState
|
||||
import androidx.compose.foundation.verticalScroll
|
||||
import androidx.compose.material3.MaterialTheme
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.tooling.preview.Preview
|
||||
import org.tasks.R
|
||||
import org.tasks.sync.AddAccountDialog.Platform
|
||||
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) }
|
||||
)
|
||||
}
|
||||
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) }
|
||||
)
|
||||
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) }
|
||||
)
|
||||
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 = .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) }
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@Preview(showBackground = true, widthDp = 320)
|
||||
@Preview(showBackground = true, uiMode = Configuration.UI_MODE_NIGHT_YES, widthDp = 320)
|
||||
@Composable
|
||||
fun AddAccountDialogPreview() {
|
||||
TasksTheme {
|
||||
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 = {})
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,122 @@
|
||||
package org.tasks.compose.accounts
|
||||
|
||||
import android.app.Activity
|
||||
import android.content.Intent
|
||||
import android.os.Bundle
|
||||
import androidx.activity.ComponentActivity
|
||||
import androidx.activity.compose.setContent
|
||||
import androidx.activity.result.contract.ActivityResultContracts
|
||||
import androidx.activity.viewModels
|
||||
import androidx.compose.runtime.LaunchedEffect
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.runtime.mutableStateOf
|
||||
import androidx.compose.runtime.remember
|
||||
import androidx.compose.runtime.setValue
|
||||
import androidx.lifecycle.compose.collectAsStateWithLifecycle
|
||||
import com.todoroo.astrid.gtasks.auth.GtasksLoginActivity
|
||||
import dagger.hilt.android.AndroidEntryPoint
|
||||
import org.tasks.R
|
||||
import org.tasks.analytics.Firebase
|
||||
import org.tasks.auth.SignInActivity
|
||||
import org.tasks.billing.Inventory
|
||||
import org.tasks.caldav.CaldavAccountSettingsActivity
|
||||
import org.tasks.data.dao.CaldavDao
|
||||
import org.tasks.etebase.EtebaseAccountSettingsActivity
|
||||
import org.tasks.sync.microsoft.MicrosoftSignInViewModel
|
||||
import org.tasks.themes.TasksTheme
|
||||
import org.tasks.themes.Theme
|
||||
import javax.inject.Inject
|
||||
|
||||
@AndroidEntryPoint
|
||||
class AddAccountActivity : ComponentActivity() {
|
||||
@Inject lateinit var theme: Theme
|
||||
@Inject lateinit var inventory: Inventory
|
||||
@Inject lateinit var firebase: Firebase
|
||||
@Inject lateinit var caldavDao: CaldavDao
|
||||
|
||||
private val viewModel: AddAccountViewModel by viewModels()
|
||||
private val microsoftVM: MicrosoftSignInViewModel by viewModels()
|
||||
|
||||
private val syncLauncher = registerForActivityResult(
|
||||
ActivityResultContracts.StartActivityForResult()
|
||||
) { result ->
|
||||
if (result.resultCode == Activity.RESULT_OK) {
|
||||
setResult(Activity.RESULT_OK)
|
||||
finish()
|
||||
} else {
|
||||
result.data
|
||||
?.getStringExtra(GtasksLoginActivity.EXTRA_ERROR)
|
||||
?.let { /* ignore error, user can try again */ }
|
||||
}
|
||||
}
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
theme.themeBase.set(this)
|
||||
|
||||
setContent {
|
||||
val accounts by caldavDao
|
||||
.watchAccounts()
|
||||
.collectAsStateWithLifecycle(initialValue = emptyList())
|
||||
var initialAccountCount by remember { mutableStateOf<Int?>(null) }
|
||||
var hasTasksAccount by remember { mutableStateOf(inventory.hasTasksAccount) }
|
||||
LaunchedEffect(Unit) {
|
||||
inventory.updateTasksAccount()
|
||||
hasTasksAccount = inventory.hasTasksAccount
|
||||
initialAccountCount = caldavDao.getAccounts().size
|
||||
}
|
||||
LaunchedEffect(accounts, initialAccountCount) {
|
||||
if (initialAccountCount != null && accounts.size > initialAccountCount!!) {
|
||||
setResult(Activity.RESULT_OK)
|
||||
finish()
|
||||
}
|
||||
}
|
||||
TasksTheme(
|
||||
theme = theme.themeBase.index,
|
||||
primary = theme.themeColor.primaryColor,
|
||||
) {
|
||||
AddAccountScreen(
|
||||
hasTasksAccount = hasTasksAccount,
|
||||
hasPro = inventory.hasPro,
|
||||
onBack = { finish() },
|
||||
signIn = { platform ->
|
||||
firebase.logEvent(
|
||||
R.string.event_onboarding_sync,
|
||||
R.string.param_selection to platform
|
||||
)
|
||||
when (platform) {
|
||||
Platform.TASKS_ORG ->
|
||||
syncLauncher.launch(
|
||||
Intent(this, SignInActivity::class.java)
|
||||
)
|
||||
Platform.GOOGLE_TASKS ->
|
||||
syncLauncher.launch(
|
||||
Intent(this, GtasksLoginActivity::class.java)
|
||||
)
|
||||
Platform.MICROSOFT ->
|
||||
microsoftVM.signIn(this)
|
||||
Platform.CALDAV ->
|
||||
syncLauncher.launch(
|
||||
Intent(this, CaldavAccountSettingsActivity::class.java)
|
||||
)
|
||||
Platform.ETESYNC ->
|
||||
syncLauncher.launch(
|
||||
Intent(this, EtebaseAccountSettingsActivity::class.java)
|
||||
)
|
||||
Platform.LOCAL ->
|
||||
viewModel.createLocalAccount()
|
||||
else -> throw IllegalArgumentException()
|
||||
}
|
||||
},
|
||||
openUrl = { platform ->
|
||||
firebase.logEvent(
|
||||
R.string.event_onboarding_sync,
|
||||
R.string.param_selection to platform.name
|
||||
)
|
||||
viewModel.openUrl(this, platform)
|
||||
},
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,12 @@
|
||||
package org.tasks.compose.accounts
|
||||
|
||||
enum class Platform {
|
||||
TASKS_ORG,
|
||||
GOOGLE_TASKS,
|
||||
MICROSOFT,
|
||||
DAVX5,
|
||||
CALDAV,
|
||||
ETESYNC,
|
||||
DECSYNC_CC,
|
||||
LOCAL,
|
||||
}
|
||||
@ -1,85 +0,0 @@
|
||||
package org.tasks.sync
|
||||
|
||||
import android.app.Dialog
|
||||
import android.os.Bundle
|
||||
import androidx.core.os.bundleOf
|
||||
import androidx.fragment.app.DialogFragment
|
||||
import androidx.fragment.app.setFragmentResult
|
||||
import dagger.hilt.android.AndroidEntryPoint
|
||||
import org.tasks.R
|
||||
import org.tasks.compose.AddAccountDialog
|
||||
import org.tasks.dialogs.DialogBuilder
|
||||
import org.tasks.extensions.Context.openUri
|
||||
import org.tasks.preferences.Preferences
|
||||
import org.tasks.themes.TasksTheme
|
||||
import org.tasks.themes.Theme
|
||||
import javax.inject.Inject
|
||||
|
||||
@AndroidEntryPoint
|
||||
class AddAccountDialog : DialogFragment() {
|
||||
|
||||
@Inject lateinit var dialogBuilder: DialogBuilder
|
||||
@Inject lateinit var theme: Theme
|
||||
@Inject lateinit var preferences: Preferences
|
||||
|
||||
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,
|
||||
MICROSOFT,
|
||||
DAVX5,
|
||||
CALDAV,
|
||||
ETESYNC,
|
||||
DECSYNC_CC,
|
||||
LOCAL,
|
||||
}
|
||||
|
||||
override fun onCreateDialog(savedInstanceState: Bundle?): Dialog {
|
||||
return dialogBuilder
|
||||
.newDialog()
|
||||
.setTitle(R.string.choose_synchronization_service)
|
||||
.setContent {
|
||||
TasksTheme(
|
||||
theme = theme.themeBase.index,
|
||||
primary = theme.themeColor.primaryColor,
|
||||
) {
|
||||
AddAccountDialog(
|
||||
hasTasksAccount = hasTasksAccount,
|
||||
hasPro = hasPro,
|
||||
selected = this::selected
|
||||
)
|
||||
}
|
||||
}
|
||||
.setNeutralButton(R.string.help) { _, _ -> activity?.openUri(R.string.help_url_sync) }
|
||||
.setNegativeButton(R.string.cancel, null)
|
||||
.show()
|
||||
}
|
||||
|
||||
private fun selected(platform: Platform) {
|
||||
setFragmentResult(ADD_ACCOUNT, bundleOf(EXTRA_SELECTED to platform))
|
||||
dismiss()
|
||||
}
|
||||
|
||||
companion object {
|
||||
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,
|
||||
hasPro: Boolean,
|
||||
) =
|
||||
AddAccountDialog().apply {
|
||||
arguments = bundleOf(
|
||||
EXTRA_HAS_TASKS_ACCOUNT to hasTasksAccount,
|
||||
EXTRA_HAS_PRO to hasPro,
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue