Skip to content

Commit

Permalink
[WIP] Use swipe-down gesture to start sync
Browse files Browse the repository at this point in the history
  • Loading branch information
sunkup committed Oct 24, 2023
1 parent 07c3c03 commit 5542501
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 7 deletions.
14 changes: 12 additions & 2 deletions app/src/main/kotlin/at/bitfire/davdroid/ui/AccountsActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
package at.bitfire.davdroid.ui

import android.accounts.AccountManager
import android.app.Activity
import android.app.Application
import android.content.Intent
import android.content.pm.ShortcutManager
Expand All @@ -20,6 +19,8 @@ import androidx.appcompat.widget.TooltipCompat
import androidx.core.content.getSystemService
import androidx.core.view.GravityCompat
import androidx.lifecycle.AndroidViewModel
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout
import androidx.work.WorkInfo
import at.bitfire.davdroid.R
import at.bitfire.davdroid.databinding.ActivityAccountsBinding
import at.bitfire.davdroid.settings.SettingsManager
Expand All @@ -36,7 +37,7 @@ import kotlinx.coroutines.launch
import javax.inject.Inject

@AndroidEntryPoint
class AccountsActivity: AppCompatActivity(), NavigationView.OnNavigationItemSelectedListener {
class AccountsActivity: AppCompatActivity(), NavigationView.OnNavigationItemSelectedListener, SwipeRefreshLayout.OnRefreshListener {

@Inject lateinit var accountsDrawerHandler: AccountsDrawerHandler

Expand Down Expand Up @@ -88,6 +89,12 @@ class AccountsActivity: AppCompatActivity(), NavigationView.OnNavigationItemSele
}
}

// Swipe refresh gesture
binding.content.swipeRefresh.setOnRefreshListener(this)
model.isSyncing.observe(this) { nowRefreshing ->
binding.content.swipeRefresh.isRefreshing = nowRefreshing
}

// handle "Sync all" intent from launcher shortcut
if (savedInstanceState == null && intent.action == Intent.ACTION_SYNC)
syncAllAccounts()
Expand Down Expand Up @@ -124,6 +131,7 @@ class AccountsActivity: AppCompatActivity(), NavigationView.OnNavigationItemSele
SyncWorker.enqueueAllAuthorities(this, account)
}

override fun onRefresh() = syncAllAccounts()

@HiltViewModel
class Model @Inject constructor(
Expand All @@ -134,6 +142,8 @@ class AccountsActivity: AppCompatActivity(), NavigationView.OnNavigationItemSele

val networkAvailable = warnings.networkAvailable

val isSyncing = SyncWorker.exists(application, listOf(WorkInfo.State.RUNNING))

}

}
18 changes: 13 additions & 5 deletions app/src/main/res/layout/accounts_content.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,22 @@

</com.google.android.material.appbar.AppBarLayout>

<androidx.fragment.app.FragmentContainerView
android:id="@+id/account_list"
android:name="at.bitfire.davdroid.ui.AccountListFragment"
<androidx.swiperefreshlayout.widget.SwipeRefreshLayout
android:id="@+id/swipe_refresh"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:layout="@layout/account_list"
app:layout_scrollFlags="scroll"
app:layout_behavior="com.google.android.material.appbar.AppBarLayout$ScrollingViewBehavior"/>
app:layout_behavior="com.google.android.material.appbar.AppBarLayout$ScrollingViewBehavior">

<androidx.fragment.app.FragmentContainerView
android:id="@+id/account_list"
android:name="at.bitfire.davdroid.ui.AccountListFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:layout="@layout/account_list" />

</androidx.swiperefreshlayout.widget.SwipeRefreshLayout>

<com.google.android.material.floatingactionbutton.FloatingActionButton
android:id="@+id/fab"
Expand Down

0 comments on commit 5542501

Please sign in to comment.