Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 94a8c4c2 authored by Ricki Hirner's avatar Ricki Hirner
Browse files

Make AccountActivity2 fully working again

parent efa168b9
Loading
Loading
Loading
Loading
+3 −3
Original line number Diff line number Diff line
@@ -47,7 +47,7 @@ data class Collection(
    var supportsVJOURNAL: Boolean? = null,

    /** Webcal subscription source URL */
    var source: String? = null,
    var source: HttpUrl? = null,

    /** whether this collection has been selected for synchronization */
    var sync: Boolean = false
@@ -95,7 +95,7 @@ data class Collection(
            var supportsVEVENT: Boolean? = null
            var supportsVTODO: Boolean? = null
            var supportsVJOURNAL: Boolean? = null
            var source: String? = null
            var source: HttpUrl? = null
            when (type) {
                Collection.TYPE_ADDRESSBOOK -> {
                    dav[AddressbookDescription::class.java]?.let { description = it.description }
@@ -115,7 +115,7 @@ data class Collection(
                            supportsVJOURNAL = it.supportsJournal
                        }
                    } else { // Type.WEBCAL
                        dav[Source::class.java]?.let { source = it.hrefs.firstOrNull() }
                        dav[Source::class.java]?.let { source = it.hrefs.firstOrNull()?.let { HttpUrl.parse(it) } }
                        supportsVEVENT = true
                    }
                }
+6 −6
Original line number Diff line number Diff line
@@ -10,11 +10,14 @@ interface CollectionDao {
    @Query("SELECT * FROM collection WHERE id=:id")
    fun get(id: Long): Collection?

    @Query("SELECT * FROM collection WHERE serviceId=:serviceId ORDER BY displayName, url")
    @Query("SELECT * FROM collection WHERE serviceId=:serviceId")
    fun getByService(serviceId: Long): List<Collection>

    @Query("SELECT * FROM collection WHERE serviceId=:serviceId ORDER BY displayName, url")
    fun pageByService(serviceId: Long): DataSource.Factory<Int, Collection>
    @Query("SELECT * FROM collection WHERE serviceId=:serviceId AND type=:type")
    fun getByServiceAndType(serviceId: Long, type: String): List<Collection>

    @Query("SELECT * FROM collection WHERE serviceId=:serviceId AND type=:type ORDER BY displayName, url")
    fun pageByServiceAndType(serviceId: Long, type: String): DataSource.Factory<Int, Collection>

    @Query("SELECT * FROM collection WHERE serviceId=:serviceId AND sync ORDER BY displayName, url")
    fun getByServiceAndSync(serviceId: Long): List<Collection>
@@ -22,9 +25,6 @@ interface CollectionDao {
    @Query("SELECT * FROM collection WHERE serviceId=:serviceId AND type=:type ORDER BY displayName, url")
    fun observeByServiceAndType(serviceId: Long, type: String): LiveData<List<Collection>>

    /*@Query("SELECT COUNT(*) FROM collection WHERE serviceId=:serviceId AND type=:type AND sync")
    fun observeHasSyncByServiceAndType(serviceId: Long, type: String): LiveData<Boolean>*/

    @Query("SELECT COUNT(*) FROM collection WHERE serviceId=:serviceId AND sync")
    fun observeHasSyncByService(serviceId: Long): LiveData<Boolean>

+36 −22
Original line number Diff line number Diff line
@@ -6,6 +6,7 @@ import android.accounts.AccountManager
import android.app.AlertDialog
import android.app.Application
import android.content.Context
import android.content.Intent
import android.content.pm.PackageManager
import android.os.Build
import android.os.Bundle
@@ -18,7 +19,7 @@ import androidx.appcompat.app.AppCompatActivity
import androidx.core.app.ActivityCompat
import androidx.core.content.ContextCompat
import androidx.fragment.app.Fragment
import androidx.fragment.app.FragmentPagerAdapter
import androidx.fragment.app.FragmentStatePagerAdapter
import androidx.lifecycle.*
import at.bitfire.davdroid.DavUtils
import at.bitfire.davdroid.R
@@ -27,6 +28,7 @@ import at.bitfire.davdroid.model.AppDatabase
import at.bitfire.davdroid.model.Collection
import at.bitfire.davdroid.model.Service
import at.bitfire.davdroid.resource.LocalTaskList
import at.bitfire.davdroid.ui.AccountSettingsActivity
import at.bitfire.ical4android.TaskProvider
import com.google.android.material.snackbar.Snackbar
import kotlinx.android.synthetic.main.activity_account2.*
@@ -96,6 +98,12 @@ class AccountActivity2: AppCompatActivity() {

    // menu actions

    fun openAccountSettings(menuItem: MenuItem) {
        val intent = Intent(this, AccountSettingsActivity::class.java)
        intent.putExtra(AccountSettingsActivity.EXTRA_ACCOUNT, model.account)
        startActivity(intent, null)
    }

    fun renameAccount(menuItem: MenuItem) {
        if (Build.VERSION.SDK_INT >= 21)
            RenameAccountFragment.newInstance(model.account).show(supportFragmentManager, null)
@@ -145,7 +153,7 @@ class AccountActivity2: AppCompatActivity() {

    class TabsAdapter(
            val activity: AppCompatActivity
    ): FragmentPagerAdapter(activity.supportFragmentManager) {
    ): FragmentStatePagerAdapter(activity.supportFragmentManager) {
        
        var cardDavSvcId: Long? = null
            set(value) {
@@ -158,61 +166,67 @@ class AccountActivity2: AppCompatActivity() {
                recalculate()
            }

        private var idxContacts: Int? = null
        private var idxEventsTasks: Int? = null
        private var idxWebcals: Int? = null
        private var idxCardDav: Int? = null
        private var idxCalDav: Int? = null
        private var idxWebcal: Int? = null

        private fun recalculate() {
            var currentIndex = 0

            idxContacts = if (cardDavSvcId != null)
            idxCardDav = if (cardDavSvcId != null)
                currentIndex++
            else
                null

            if (calDavSvcId != null) {
                idxEventsTasks = currentIndex++
                idxWebcals = currentIndex
                idxCalDav = currentIndex++
                idxWebcal = currentIndex
            } else {
                idxEventsTasks = null
                idxWebcals = null
                idxCalDav = null
                idxWebcal = null
            }

            notifyDataSetChanged()
        }

        override fun getCount() =
                (if (idxContacts != null) 1 else 0) +
                (if (idxEventsTasks != null) 1 else 0) +
                (if (idxWebcals != null) 1 else 0)
                (if (idxCardDav != null) 1 else 0) +
                (if (idxCalDav != null) 1 else 0) +
                (if (idxWebcal != null) 1 else 0)

        override fun getItem(position: Int): Fragment {
            val args = Bundle(1)
            when (position) {
                idxContacts -> {
                idxCardDav -> {
                    val frag = AddressBooksFragment()
                    val args = Bundle(1)
                    args.putLong(CollectionsFragment.EXTRA_SERVICE_ID, cardDavSvcId!!)
                    args.putString(CollectionsFragment.EXTRA_COLLECTION_TYPE, Collection.TYPE_ADDRESSBOOK)
                    frag.arguments = args
                    return frag
                }
                idxEventsTasks -> {
                idxCalDav -> {
                    val frag = CalendarsFragment()
                    val args = Bundle(1)
                    args.putLong(CollectionsFragment.EXTRA_SERVICE_ID, calDavSvcId!!)
                    args.putString(CollectionsFragment.EXTRA_COLLECTION_TYPE, Collection.TYPE_CALENDAR)
                    frag.arguments = args
                    return frag
                }
                idxWebcal -> {
                    val frag = WebcalFragment()
                    args.putLong(CollectionsFragment.EXTRA_SERVICE_ID, calDavSvcId!!)
                    args.putString(CollectionsFragment.EXTRA_COLLECTION_TYPE, Collection.TYPE_WEBCAL)
                    frag.arguments = args
                    return frag
                }
                idxWebcals ->
                    return Fragment()
            }
            throw IllegalArgumentException()
        }

        override fun getPageTitle(position: Int): String =
                when (position) {
                    idxContacts -> activity.getString(R.string.account_carddav)
                    idxEventsTasks -> activity.getString(R.string.account_caldav)
                    idxWebcals -> activity.getString(R.string.account_webcal)
                    idxCardDav -> activity.getString(R.string.account_carddav)
                    idxCalDav -> activity.getString(R.string.account_caldav)
                    idxWebcal -> activity.getString(R.string.account_webcal)
                    else -> throw IllegalArgumentException()
                }

+3 −34
Original line number Diff line number Diff line
@@ -2,13 +2,9 @@ package at.bitfire.davdroid.ui.account

import android.content.Intent
import android.view.*
import android.widget.PopupMenu
import androidx.appcompat.app.AppCompatActivity
import at.bitfire.davdroid.R
import at.bitfire.davdroid.model.Collection
import at.bitfire.davdroid.ui.CollectionInfoFragment
import at.bitfire.davdroid.ui.CreateAddressBookActivity
import at.bitfire.davdroid.ui.DeleteCollectionFragment
import kotlinx.android.synthetic.main.account_carddav_item.view.*

class AddressBooksFragment: CollectionsFragment() {
@@ -38,11 +34,7 @@ class AddressBooksFragment: CollectionsFragment() {
            accountModel: AccountActivity2.Model
    ): CollectionViewHolder(parent, R.layout.account_carddav_item, accountModel) {

        private val fragmentManager = (parent.context as AppCompatActivity).supportFragmentManager

        override fun bindTo(item: Collection) {
            super.bindTo(item)

            val v = itemView
            v.sync.isChecked = item.sync
            v.title.text = item.title()
@@ -56,34 +48,11 @@ class AddressBooksFragment: CollectionsFragment() {

            v.read_only.visibility = if (item.readOnly()) View.VISIBLE else View.GONE

            v.action_overflow.setOnClickListener { anchor ->
                val popup = PopupMenu(v.context, anchor, Gravity.RIGHT)
                popup.inflate(R.menu.account_collection_operations)

                with(popup.menu.findItem(R.id.force_read_only)) {
                    if (item.privWriteContent)
                        isChecked = item.forceReadOnly
                    else
                        isVisible = false
                }
                popup.menu.findItem(R.id.delete_collection).isVisible = item.privUnbind

                popup.setOnMenuItemClickListener { menuItem ->
                    when (menuItem.itemId) {
                        R.id.force_read_only -> {
                            accountModel.toggleReadOnly(item)
            itemView.setOnClickListener {
                accountModel.toggleSync(item)
            }
                        R.id.properties ->
                            CollectionInfoFragment.newInstance(item.id).show(fragmentManager, null)
                        R.id.delete_collection ->
                            DeleteCollectionFragment.newInstance(accountModel.account, item.id).show(fragmentManager, null)
            v.action_overflow.setOnClickListener(CollectionPopupListener(accountModel, item))
        }
                    true
                }
                popup.show()
            }
        }

    }

    class AddressBookAdapter(
+4 −6
Original line number Diff line number Diff line
@@ -4,7 +4,6 @@ import android.content.Intent
import android.view.*
import at.bitfire.davdroid.Constants
import at.bitfire.davdroid.R
import at.bitfire.davdroid.log.Logger
import at.bitfire.davdroid.model.Collection
import at.bitfire.davdroid.ui.CreateCalendarActivity
import kotlinx.android.synthetic.main.account_caldav_item.view.*
@@ -18,7 +17,7 @@ class CalendarsFragment: CollectionsFragment() {
        if (super.onOptionsItemSelected(item))
            return true

        if (item.itemId == R.id.create_calendar) {
        if (item.itemId == R.id.create) {
            val intent = Intent(requireActivity(), CreateCalendarActivity::class.java)
            intent.putExtra(CreateCalendarActivity.EXTRA_ACCOUNT, accountModel.account)
            startActivity(intent)
@@ -37,8 +36,6 @@ class CalendarsFragment: CollectionsFragment() {
    ): CollectionViewHolder(parent, R.layout.account_caldav_item, accountModel) {

        override fun bindTo(item: Collection) {
            super.bindTo(item)

            val v = itemView
            v.color.setBackgroundColor(item.color ?: Constants.DAVDROID_GREEN_RGBA)

@@ -56,9 +53,10 @@ class CalendarsFragment: CollectionsFragment() {
            v.events.visibility = if (item.supportsVEVENT == true) View.VISIBLE else View.GONE
            v.tasks.visibility = if (item.supportsVTODO == true) View.VISIBLE else View.GONE

            v.action_overflow.setOnClickListener {
                Logger.log.info("Action click")
            itemView.setOnClickListener {
                accountModel.toggleSync(item)
            }
            v.action_overflow.setOnClickListener(CollectionPopupListener(accountModel, item))
        }

    }
Loading