mirror of https://github.com/tasks/tasks
Add Tasks.org to synchronization options
parent
e10d78c712
commit
a67d62f1ea
@ -0,0 +1,3 @@
|
|||||||
|
package org.tasks.auth
|
||||||
|
|
||||||
|
class SignInActivity
|
||||||
@ -0,0 +1,77 @@
|
|||||||
|
package org.tasks.auth
|
||||||
|
|
||||||
|
import android.content.Intent
|
||||||
|
import android.os.Bundle
|
||||||
|
import androidx.activity.viewModels
|
||||||
|
import androidx.lifecycle.lifecycleScope
|
||||||
|
import at.bitfire.dav4jvm.exception.HttpException
|
||||||
|
import dagger.hilt.android.AndroidEntryPoint
|
||||||
|
import kotlinx.coroutines.Dispatchers
|
||||||
|
import kotlinx.coroutines.launch
|
||||||
|
import org.tasks.R
|
||||||
|
import org.tasks.analytics.Firebase
|
||||||
|
import org.tasks.billing.PurchaseDialog.Companion.FRAG_TAG_PURCHASE_DIALOG
|
||||||
|
import org.tasks.billing.PurchaseDialog.Companion.newPurchaseDialog
|
||||||
|
import org.tasks.caldav.CaldavClientProvider
|
||||||
|
import org.tasks.data.CaldavAccount
|
||||||
|
import org.tasks.gtasks.PlayServices
|
||||||
|
import org.tasks.injection.InjectingAppCompatActivity
|
||||||
|
import org.tasks.ui.Toaster
|
||||||
|
import javax.inject.Inject
|
||||||
|
|
||||||
|
@AndroidEntryPoint
|
||||||
|
class SignInActivity : InjectingAppCompatActivity() {
|
||||||
|
|
||||||
|
@Inject lateinit var toaster: Toaster
|
||||||
|
@Inject lateinit var provider: CaldavClientProvider
|
||||||
|
@Inject lateinit var playServices: PlayServices
|
||||||
|
@Inject lateinit var firebase: Firebase
|
||||||
|
|
||||||
|
val viewModel: SignInViewModel by viewModels()
|
||||||
|
|
||||||
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
|
super.onCreate(savedInstanceState)
|
||||||
|
|
||||||
|
viewModel.observe(this, this::onSignIn, this::onError)
|
||||||
|
|
||||||
|
lifecycleScope.launch {
|
||||||
|
playServices
|
||||||
|
.getSignedInAccount()
|
||||||
|
?.let { validate(it) }
|
||||||
|
?: startActivityForResult(playServices.signInIntent, RC_SIGN_IN)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun onSignIn(account: CaldavAccount?) {
|
||||||
|
account?.let { toaster.longToast(getString(R.string.logged_in, it.name)) }
|
||||||
|
finish()
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun onError(t: Throwable) {
|
||||||
|
if (t is HttpException && t.code == 402) {
|
||||||
|
newPurchaseDialog(true).show(supportFragmentManager, FRAG_TAG_PURCHASE_DIALOG)
|
||||||
|
} else {
|
||||||
|
firebase.reportException(t)
|
||||||
|
toaster.longToast(t.message)
|
||||||
|
finish()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
|
||||||
|
if (requestCode == RC_SIGN_IN) {
|
||||||
|
playServices
|
||||||
|
.signInFromIntent(data)
|
||||||
|
?.let { validate(it) }
|
||||||
|
} else {
|
||||||
|
super.onActivityResult(requestCode, resultCode, data)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun validate(account: OauthSignIn) = lifecycleScope.launch(Dispatchers.IO) {
|
||||||
|
viewModel.validate(account.id!!, account.email!!, account.idToken!!)
|
||||||
|
}
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
private const val RC_SIGN_IN = 10000
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,45 @@
|
|||||||
|
package org.tasks.auth
|
||||||
|
|
||||||
|
import android.content.Context
|
||||||
|
import androidx.hilt.lifecycle.ViewModelInject
|
||||||
|
import com.todoroo.astrid.helper.UUIDHelper
|
||||||
|
import dagger.hilt.android.qualifiers.ApplicationContext
|
||||||
|
import org.tasks.R
|
||||||
|
import org.tasks.caldav.CaldavClientProvider
|
||||||
|
import org.tasks.data.CaldavAccount
|
||||||
|
import org.tasks.data.CaldavAccount.Companion.TYPE_TASKS
|
||||||
|
import org.tasks.data.CaldavDao
|
||||||
|
import org.tasks.ui.CompletableViewModel
|
||||||
|
|
||||||
|
class SignInViewModel @ViewModelInject constructor(
|
||||||
|
@ApplicationContext private val context: Context,
|
||||||
|
private val provider: CaldavClientProvider,
|
||||||
|
private val caldavDao: CaldavDao
|
||||||
|
) : CompletableViewModel<CaldavAccount?>() {
|
||||||
|
|
||||||
|
suspend fun validate(id: String, email: String, idToken: String) {
|
||||||
|
run {
|
||||||
|
val homeSet = provider
|
||||||
|
.forUrl(
|
||||||
|
"${context.getString(R.string.tasks_caldav_url)}/google_login",
|
||||||
|
token = idToken
|
||||||
|
)
|
||||||
|
.setForeground()
|
||||||
|
.homeSet(token = idToken)
|
||||||
|
val username = "google_$id"
|
||||||
|
caldavDao.getAccount(TYPE_TASKS, username)
|
||||||
|
?.apply {
|
||||||
|
error = null
|
||||||
|
caldavDao.update(this)
|
||||||
|
}
|
||||||
|
?: CaldavAccount().apply {
|
||||||
|
accountType = TYPE_TASKS
|
||||||
|
uuid = UUIDHelper.newUUID()
|
||||||
|
url = homeSet
|
||||||
|
this.username = username
|
||||||
|
name = email
|
||||||
|
caldavDao.insert(this)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,26 @@
|
|||||||
|
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:width="1146dp"
|
||||||
|
android:height="1146dp"
|
||||||
|
android:viewportWidth="1146"
|
||||||
|
android:viewportHeight="1146">
|
||||||
|
<group>
|
||||||
|
<clip-path
|
||||||
|
android:pathData="M0,0l1145.72,0l0,1145.72l-1145.72,0z"/>
|
||||||
|
<path
|
||||||
|
android:pathData="M572.65,571.88m-572.51,0a572.51,572.51 0,1 1,1145.02 0a572.51,572.51 45,1 1,-1145.02 0"
|
||||||
|
android:fillColor="#2196F3"/>
|
||||||
|
<group>
|
||||||
|
<clip-path
|
||||||
|
android:pathData="M572.65,571.88m-572.51,0a572.51,572.51 0,1 1,1145.02 0a572.51,572.51 45,1 1,-1145.02 0"/>
|
||||||
|
<path
|
||||||
|
android:fillColor="#FF000000"
|
||||||
|
android:pathData="M429.5,771.89L230.23,572.61L162.61,640.23L1146.31,1623.94L1719.76,1050.49L935.33,266.06L429.5,771.89Z"
|
||||||
|
android:fillType="nonZero"
|
||||||
|
android:fillAlpha="0.15"/>
|
||||||
|
</group>
|
||||||
|
</group>
|
||||||
|
<path
|
||||||
|
android:pathData="M429.5,771.88L230.22,572.61L162.61,640.23L429.5,907.12L1002.95,333.67L935.33,266.05L429.5,771.88Z"
|
||||||
|
android:fillColor="#ffffff"
|
||||||
|
android:fillType="nonZero"/>
|
||||||
|
</vector>
|
||||||
@ -1,4 +1,5 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<resources>
|
<resources>
|
||||||
<string name="app_name">Tasks</string>
|
<string name="app_name">Tasks</string>
|
||||||
|
<string name="tasks_caldav_url">https://caldav.tasks.org</string>
|
||||||
</resources>
|
</resources>
|
||||||
Loading…
Reference in New Issue