Update feed by pull-to-refresh

pull/340/head
Koitharu 3 years ago
parent 85710acb3a
commit 32b1ee9e7b
No known key found for this signature in database
GPG Key ID: 8E861F8CE6E7CE27

@ -7,6 +7,7 @@ import android.view.ViewGroup
import androidx.core.graphics.Insets import androidx.core.graphics.Insets
import androidx.core.view.updatePadding import androidx.core.view.updatePadding
import androidx.fragment.app.viewModels import androidx.fragment.app.viewModels
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout
import coil.ImageLoader import coil.ImageLoader
import com.google.android.material.snackbar.Snackbar import com.google.android.material.snackbar.Snackbar
import dagger.hilt.android.AndroidEntryPoint import dagger.hilt.android.AndroidEntryPoint
@ -33,7 +34,7 @@ import javax.inject.Inject
class FeedFragment : class FeedFragment :
BaseFragment<FragmentFeedBinding>(), BaseFragment<FragmentFeedBinding>(),
PaginationScrollListener.Callback, PaginationScrollListener.Callback,
MangaListListener { MangaListListener, SwipeRefreshLayout.OnRefreshListener {
@Inject @Inject
lateinit var coil: ImageLoader lateinit var coil: ImageLoader
@ -64,7 +65,7 @@ class FeedFragment :
with(binding.swipeRefreshLayout) { with(binding.swipeRefreshLayout) {
setProgressBackgroundColorSchemeColor(context.getThemeColor(com.google.android.material.R.attr.colorPrimary)) setProgressBackgroundColorSchemeColor(context.getThemeColor(com.google.android.material.R.attr.colorPrimary))
setColorSchemeColors(context.getThemeColor(com.google.android.material.R.attr.colorOnPrimary)) setColorSchemeColors(context.getThemeColor(com.google.android.material.R.attr.colorOnPrimary))
isEnabled = false setOnRefreshListener(this@FeedFragment)
} }
addMenuProvider( addMenuProvider(
FeedMenuProvider( FeedMenuProvider(
@ -94,6 +95,10 @@ class FeedFragment :
) )
} }
override fun onRefresh() {
TrackWorker.startNow(context ?: return)
}
override fun onRetryClick(error: Throwable) = Unit override fun onRetryClick(error: Throwable) = Unit
override fun onUpdateFilter(tags: Set<MangaTag>) = Unit override fun onUpdateFilter(tags: Set<MangaTag>) = Unit

@ -6,7 +6,6 @@ import android.view.MenuInflater
import android.view.MenuItem import android.view.MenuItem
import android.view.View import android.view.View
import androidx.core.view.MenuProvider import androidx.core.view.MenuProvider
import com.google.android.material.snackbar.Snackbar
import org.koitharu.kotatsu.R import org.koitharu.kotatsu.R
import org.koitharu.kotatsu.base.ui.dialog.CheckBoxAlertDialog import org.koitharu.kotatsu.base.ui.dialog.CheckBoxAlertDialog
import org.koitharu.kotatsu.settings.SettingsActivity import org.koitharu.kotatsu.settings.SettingsActivity
@ -28,13 +27,6 @@ class FeedMenuProvider(
override fun onMenuItemSelected(menuItem: MenuItem): Boolean = when (menuItem.itemId) { override fun onMenuItemSelected(menuItem: MenuItem): Boolean = when (menuItem.itemId) {
R.id.action_update -> { R.id.action_update -> {
TrackWorker.startNow(context) TrackWorker.startNow(context)
val snackbar = Snackbar.make(
snackbarHost,
R.string.feed_will_update_soon,
Snackbar.LENGTH_LONG,
)
snackbar.anchorView = anchorView
snackbar.show()
true true
} }

Loading…
Cancel
Save