mirror of
https://github.com/tachiyomiorg/tachiyomi.git
synced 2024-11-19 03:39:18 +01:00
Add update library menu item
This commit is contained in:
parent
441e2a69d8
commit
859e9ca653
@ -146,8 +146,9 @@ class LibraryUpdateService(
|
|||||||
* @param context the application context.
|
* @param context the application context.
|
||||||
* @param category a specific category to update, or null for global update.
|
* @param category a specific category to update, or null for global update.
|
||||||
* @param target defines what should be updated.
|
* @param target defines what should be updated.
|
||||||
|
* @return true if service newly started, false otherwise
|
||||||
*/
|
*/
|
||||||
fun start(context: Context, category: Category? = null, target: Target = Target.CHAPTERS) {
|
fun start(context: Context, category: Category? = null, target: Target = Target.CHAPTERS): Boolean {
|
||||||
if (!isRunning(context)) {
|
if (!isRunning(context)) {
|
||||||
val intent = Intent(context, LibraryUpdateService::class.java).apply {
|
val intent = Intent(context, LibraryUpdateService::class.java).apply {
|
||||||
putExtra(KEY_TARGET, target)
|
putExtra(KEY_TARGET, target)
|
||||||
@ -158,7 +159,11 @@ class LibraryUpdateService(
|
|||||||
} else {
|
} else {
|
||||||
context.startForegroundService(intent)
|
context.startForegroundService(intent)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -96,10 +96,10 @@ class LibraryCategoryView @JvmOverloads constructor(context: Context, attrs: Att
|
|||||||
// Double the distance required to trigger sync
|
// Double the distance required to trigger sync
|
||||||
swipe_refresh.setDistanceToTriggerSync((2 * 64 * resources.displayMetrics.density).toInt())
|
swipe_refresh.setDistanceToTriggerSync((2 * 64 * resources.displayMetrics.density).toInt())
|
||||||
swipe_refresh.setOnRefreshListener {
|
swipe_refresh.setOnRefreshListener {
|
||||||
if (!LibraryUpdateService.isRunning(context)) {
|
if (LibraryUpdateService.start(context, category)) {
|
||||||
LibraryUpdateService.start(context, category)
|
|
||||||
context.toast(R.string.updating_category)
|
context.toast(R.string.updating_category)
|
||||||
}
|
}
|
||||||
|
|
||||||
// It can be a very long operation, so we disable swipe refresh and show a toast.
|
// It can be a very long operation, so we disable swipe refresh and show a toast.
|
||||||
swipe_refresh.isRefreshing = false
|
swipe_refresh.isRefreshing = false
|
||||||
}
|
}
|
||||||
|
@ -362,7 +362,11 @@ class LibraryController(
|
|||||||
R.id.action_search -> expandActionViewFromInteraction = true
|
R.id.action_search -> expandActionViewFromInteraction = true
|
||||||
R.id.action_filter -> showSettingsSheet()
|
R.id.action_filter -> showSettingsSheet()
|
||||||
R.id.action_update_library -> {
|
R.id.action_update_library -> {
|
||||||
activity?.let { LibraryUpdateService.start(it) }
|
activity?.let {
|
||||||
|
if (LibraryUpdateService.start(it)) {
|
||||||
|
it.toast(R.string.updating_library)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2,6 +2,7 @@ package eu.kanade.tachiyomi.ui.recent.updates
|
|||||||
|
|
||||||
import android.view.LayoutInflater
|
import android.view.LayoutInflater
|
||||||
import android.view.Menu
|
import android.view.Menu
|
||||||
|
import android.view.MenuInflater
|
||||||
import android.view.MenuItem
|
import android.view.MenuItem
|
||||||
import android.view.View
|
import android.view.View
|
||||||
import android.view.ViewGroup
|
import android.view.ViewGroup
|
||||||
@ -59,6 +60,10 @@ class UpdatesController : NucleusController<UpdatesPresenter>(),
|
|||||||
var adapter: UpdatesAdapter? = null
|
var adapter: UpdatesAdapter? = null
|
||||||
private set
|
private set
|
||||||
|
|
||||||
|
init {
|
||||||
|
setHasOptionsMenu(true)
|
||||||
|
}
|
||||||
|
|
||||||
override fun getTitle(): String? {
|
override fun getTitle(): String? {
|
||||||
return resources?.getString(R.string.label_recent_updates)
|
return resources?.getString(R.string.label_recent_updates)
|
||||||
}
|
}
|
||||||
@ -94,10 +99,8 @@ class UpdatesController : NucleusController<UpdatesPresenter>(),
|
|||||||
|
|
||||||
swipe_refresh.setDistanceToTriggerSync((2 * 64 * view.resources.displayMetrics.density).toInt())
|
swipe_refresh.setDistanceToTriggerSync((2 * 64 * view.resources.displayMetrics.density).toInt())
|
||||||
swipe_refresh.refreshes().subscribeUntilDestroy {
|
swipe_refresh.refreshes().subscribeUntilDestroy {
|
||||||
if (!LibraryUpdateService.isRunning(view.context)) {
|
updateLibrary()
|
||||||
LibraryUpdateService.start(view.context)
|
|
||||||
view.context.toast(R.string.action_update_library)
|
|
||||||
}
|
|
||||||
// It can be a very long operation, so we disable swipe refresh and show a toast.
|
// It can be a very long operation, so we disable swipe refresh and show a toast.
|
||||||
swipe_refresh.isRefreshing = false
|
swipe_refresh.isRefreshing = false
|
||||||
}
|
}
|
||||||
@ -110,6 +113,26 @@ class UpdatesController : NucleusController<UpdatesPresenter>(),
|
|||||||
super.onDestroyView(view)
|
super.onDestroyView(view)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun onCreateOptionsMenu(menu: Menu, inflater: MenuInflater) {
|
||||||
|
inflater.inflate(R.menu.updates, menu)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onOptionsItemSelected(item: MenuItem): Boolean {
|
||||||
|
when (item.itemId) {
|
||||||
|
R.id.action_update_library -> updateLibrary()
|
||||||
|
}
|
||||||
|
|
||||||
|
return super.onOptionsItemSelected(item)
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun updateLibrary() {
|
||||||
|
activity?.let {
|
||||||
|
if (LibraryUpdateService.start(it)) {
|
||||||
|
it.toast(R.string.updating_library)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns selected chapters
|
* Returns selected chapters
|
||||||
* @return list of selected chapters
|
* @return list of selected chapters
|
||||||
|
13
app/src/main/res/menu/updates.xml
Normal file
13
app/src/main/res/menu/updates.xml
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
<menu xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||||
|
xmlns:tools="http://schemas.android.com/tools"
|
||||||
|
tools:context=".MainActivity">
|
||||||
|
|
||||||
|
<item
|
||||||
|
android:id="@+id/action_update_library"
|
||||||
|
android:icon="@drawable/ic_refresh_24dp"
|
||||||
|
android:title="@string/action_update_library"
|
||||||
|
app:iconTint="?attr/colorOnPrimary"
|
||||||
|
app:showAsAction="ifRoom" />
|
||||||
|
|
||||||
|
</menu>
|
@ -504,6 +504,9 @@
|
|||||||
<string name="transition_pages_loading">Loading pages…</string>
|
<string name="transition_pages_loading">Loading pages…</string>
|
||||||
<string name="transition_pages_error">Failed to load pages: %1$s</string>
|
<string name="transition_pages_error">Failed to load pages: %1$s</string>
|
||||||
|
|
||||||
|
<!-- Updates fragment -->
|
||||||
|
<string name="updating_library">Updating library</string>
|
||||||
|
|
||||||
<!-- History fragment -->
|
<!-- History fragment -->
|
||||||
<string name="recent_manga_source">%1$s - Ch.%2$s</string>
|
<string name="recent_manga_source">%1$s - Ch.%2$s</string>
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user