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

Commit eebd21a0 authored by Ricki Hirner's avatar Ricki Hirner
Browse files

AccountActivity: don't show "Create addressbook/calendar" when there's no bind...

AccountActivity: don't show "Create addressbook/calendar" when there's no bind privilege on any homeset
parent 8323ea18
Loading
Loading
Loading
Loading
+4 −1
Original line number Diff line number Diff line
package at.bitfire.davdroid.model

import androidx.lifecycle.LiveData
import androidx.room.Dao
import androidx.room.Insert
import androidx.room.OnConflictStrategy
@@ -14,8 +15,10 @@ interface HomeSetDao: SyncableDao<HomeSet> {
    @Query("SELECT * FROM homeset WHERE serviceId=:serviceId AND privBind")
    fun getBindableByService(serviceId: Long): List<HomeSet>

    @Query("SELECT COUNT(*) FROM homeset WHERE serviceId=:serviceId AND privBind")
    fun hasBindableByService(serviceId: Long): LiveData<Boolean>

    @Insert(onConflict = OnConflictStrategy.REPLACE)
    fun insertOrReplace(homeSet: HomeSet): Long


}
 No newline at end of file
+5 −0
Original line number Diff line number Diff line
@@ -15,6 +15,11 @@ class AddressBooksFragment: CollectionsFragment() {
    override fun onCreateOptionsMenu(menu: Menu, inflater: MenuInflater) =
            inflater.inflate(R.menu.carddav_actions, menu)

    override fun onPrepareOptionsMenu(menu: Menu) {
        menu.findItem(R.id.create_address_book).setVisible(model.hasWriteableCollections.value ?: false)
        super.onPrepareOptionsMenu(menu)
    }

    override fun onOptionsItemSelected(item: MenuItem): Boolean {
        if (super.onOptionsItemSelected(item))
            return true
+6 −1
Original line number Diff line number Diff line
@@ -17,11 +17,16 @@ class CalendarsFragment: CollectionsFragment() {
    override fun onCreateOptionsMenu(menu: Menu, inflater: MenuInflater) =
            inflater.inflate(R.menu.caldav_actions, menu)

    override fun onPrepareOptionsMenu(menu: Menu) {
        menu.findItem(R.id.create_calendar).setVisible(model.hasWriteableCollections.value ?: false)
        super.onPrepareOptionsMenu(menu)
    }

    override fun onOptionsItemSelected(item: MenuItem): Boolean {
        if (super.onOptionsItemSelected(item))
            return true

        if (item.itemId == R.id.create) {
        if (item.itemId == R.id.create_calendar) {
            val intent = Intent(requireActivity(), CreateCalendarActivity::class.java)
            intent.putExtra(CreateCalendarActivity.EXTRA_ACCOUNT, accountModel.account)
            startActivity(intent)
+6 −0
Original line number Diff line number Diff line
@@ -71,6 +71,9 @@ abstract class CollectionsFragment: Fragment(), SwipeRefreshLayout.OnRefreshList
        model.isRefreshing.observe(viewLifecycleOwner, Observer { nowRefreshing ->
            swipe_refresh.isRefreshing = nowRefreshing
        })
        model.hasWriteableCollections.observe(viewLifecycleOwner, Observer {
            requireActivity().invalidateOptionsMenu()
        })
        model.collections.observe(viewLifecycleOwner, Observer { collections ->
            val colors = collections.orEmpty()
                    .filterNotNull()
@@ -244,6 +247,9 @@ abstract class CollectionsFragment: Fragment(), SwipeRefreshLayout.OnRefreshList
        // cache task provider
        val taskProvider by lazy { TaskUtils.currentProvider(context) }

        val hasWriteableCollections: LiveData<Boolean> = Transformations.switchMap(serviceId) { service ->
            db.homeSetDao().hasBindableByService(service)
        }
        val collections: LiveData<PagedList<Collection>> =
                Transformations.switchMap(accountModel.showOnlyPersonal) { onlyPersonal ->
                    if (onlyPersonal)
+1 −1
Original line number Diff line number Diff line
@@ -62,7 +62,7 @@ class WebcalFragment: CollectionsFragment() {

    override fun onPrepareOptionsMenu(menu: Menu) {
        super.onPrepareOptionsMenu(menu)
        menu.findItem(R.id.create).isVisible = false
        menu.findItem(R.id.create_calendar).isVisible = false
    }


Loading