Commit 036fc405 authored by Ricki Hirner's avatar Ricki Hirner

Make sure the account is seen by OpenTasks

parent 95173dcd
Pipeline #41930566 passed with stages
in 10 minutes and 49 seconds
......@@ -8,12 +8,14 @@
package at.bitfire.davdroid.syncadapter
import android.accounts.Account
import android.accounts.AccountManager
import android.app.PendingIntent
import android.content.*
import android.content.pm.PackageManager
import android.database.DatabaseUtils
import android.graphics.drawable.BitmapDrawable
import android.net.Uri
import android.os.Build
import android.os.Bundle
import androidx.core.app.NotificationCompat
import androidx.core.app.NotificationManagerCompat
......@@ -47,6 +49,11 @@ class TasksSyncAdapterService: SyncAdapterService() {
override fun sync(account: Account, extras: Bundle, authority: String, provider: ContentProviderClient, syncResult: SyncResult) {
try {
val taskProvider = TaskProvider.fromProviderClient(context, provider)
// make sure account can be seen by OpenTasks
if (Build.VERSION.SDK_INT >= 26)
AccountManager.get(context).setAccountVisibility(account, taskProvider.name.packageName, AccountManager.VISIBILITY_VISIBLE)
val accountSettings = AccountSettings(context, account)
/* don't run sync if
- sync conditions (e.g. "sync only in WiFi") are not met AND
......
......@@ -14,7 +14,6 @@ import android.annotation.SuppressLint
import android.app.Activity
import android.content.ContentResolver
import android.content.ContentValues
import android.content.Context
import android.content.Intent
import android.database.sqlite.SQLiteDatabase
import android.os.AsyncTask
......@@ -59,7 +58,7 @@ class AccountDetailsFragment: Fragment() {
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View {
val v = inflater.inflate(R.layout.login_account_details, container, false)
v.back.setOnClickListener { _ ->
v.back.setOnClickListener {
requireFragmentManager().popBackStack()
}
......@@ -77,7 +76,7 @@ class AccountDetailsFragment: Fragment() {
if (settings.has(AccountSettings.KEY_CONTACT_GROUP_METHOD))
v.contact_group_method.isEnabled = false
v.create_account.setOnClickListener { _ ->
v.create_account.setOnClickListener {
val name = v.account_name.text.toString()
if (name.isEmpty())
v.account_name.error = getString(R.string.login_account_name_required)
......@@ -88,7 +87,7 @@ class AccountDetailsFragment: Fragment() {
v.create_account.visibility = View.GONE
v.create_account_progress.visibility = View.VISIBLE
CreateAccountTask(requireActivity().applicationContext, WeakReference(requireActivity()),
CreateAccountTask(requireActivity(),
name,
args.getParcelable(KEY_CONFIG) as DavResourceFinder.Configuration,
GroupMethod.valueOf(groupMethodName)).execute()
......@@ -111,16 +110,18 @@ class AccountDetailsFragment: Fragment() {
}
@SuppressLint("StaticFieldLeak") // we'll only keep the application Context
class CreateAccountTask(
private val appContext: Context,
private val activityRef: WeakReference<Activity>,
activity: Activity,
private val accountName: String,
private val config: DavResourceFinder.Configuration,
private val groupMethod: GroupMethod
): AsyncTask<Void, Void, Boolean>() {
@SuppressLint("StaticFieldLeak") // we'll only keep the application Context
private val appContext = activity.applicationContext
private val activityRef = WeakReference(activity)
override fun doInBackground(vararg params: Void?): Boolean {
val account = Account(accountName, appContext.getString(R.string.account_type))
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment