mirror of
https://github.com/tachiyomiorg/tachiyomi.git
synced 2024-11-09 19:55:11 +01:00
Share urls of multiple manga in library
closes #119 Also hiding migration button and filtering out local manga when it comes to source migration in library
This commit is contained in:
parent
3bd8f92824
commit
cfbc3156a1
@ -5,6 +5,7 @@ import android.animation.ObjectAnimator
|
||||
import android.annotation.SuppressLint
|
||||
import android.app.Activity
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.graphics.Color
|
||||
import android.os.Bundle
|
||||
import android.os.Handler
|
||||
@ -49,6 +50,7 @@ import eu.kanade.tachiyomi.data.notification.NotificationReceiver
|
||||
import eu.kanade.tachiyomi.data.notification.Notifications
|
||||
import eu.kanade.tachiyomi.data.preference.PreferencesHelper
|
||||
import eu.kanade.tachiyomi.data.preference.getOrDefault
|
||||
import eu.kanade.tachiyomi.source.LocalSource
|
||||
import eu.kanade.tachiyomi.ui.base.MaterialMenuSheet
|
||||
import eu.kanade.tachiyomi.ui.base.controller.BaseController
|
||||
import eu.kanade.tachiyomi.ui.category.ManageCategoryDialog
|
||||
@ -1301,6 +1303,10 @@ class LibraryController(
|
||||
override fun onPrepareActionMode(mode: ActionMode, menu: Menu): Boolean {
|
||||
val count = selectedMangas.size
|
||||
// Destroy action mode if there are no items selected.
|
||||
val migrationItem = menu.findItem(R.id.action_migrate)
|
||||
val shareItem = menu.findItem(R.id.action_share)
|
||||
migrationItem.isVisible = selectedMangas.any { it.source != LocalSource.ID }
|
||||
shareItem.isVisible = migrationItem.isVisible
|
||||
if (count == 0) destroyActionModeIfNeeded()
|
||||
else mode.title = resources?.getString(R.string.selected_, count)
|
||||
return false
|
||||
@ -1310,6 +1316,7 @@ class LibraryController(
|
||||
override fun onActionItemClicked(mode: ActionMode, item: MenuItem): Boolean {
|
||||
when (item.itemId) {
|
||||
R.id.action_move_to_category -> showChangeMangaCategoriesDialog()
|
||||
R.id.action_share -> shareManga()
|
||||
R.id.action_delete -> {
|
||||
MaterialDialog(activity!!).message(R.string.remove_from_library_question)
|
||||
.positiveButton(R.string.remove) {
|
||||
@ -1318,7 +1325,9 @@ class LibraryController(
|
||||
}
|
||||
R.id.action_migrate -> {
|
||||
val skipPre = preferences.skipPreMigration().getOrDefault()
|
||||
PreMigrationController.navigateToMigration(skipPre, router, selectedMangas.mapNotNull { it.id })
|
||||
PreMigrationController.navigateToMigration(skipPre,
|
||||
router,
|
||||
selectedMangas.filter { it.id != LocalSource.ID }.mapNotNull { it.id })
|
||||
destroyActionModeIfNeeded()
|
||||
}
|
||||
else -> return false
|
||||
@ -1326,6 +1335,19 @@ class LibraryController(
|
||||
return true
|
||||
}
|
||||
|
||||
private fun shareManga() {
|
||||
val context = view?.context ?: return
|
||||
val mangas = selectedMangas.toList()
|
||||
val urlList = presenter.getMangaUrls(mangas)
|
||||
if (urlList.isEmpty()) return
|
||||
val urls = presenter.getMangaUrls(mangas).joinToString("\n")
|
||||
val intent = Intent(Intent.ACTION_SEND).apply {
|
||||
type = "text/*"
|
||||
putExtra(Intent.EXTRA_TEXT, urls)
|
||||
}
|
||||
startActivity(Intent.createChooser(intent, context.getString(R.string.share)))
|
||||
}
|
||||
|
||||
private fun deleteMangasFromLibrary() {
|
||||
val mangas = selectedMangas.toList()
|
||||
presenter.removeMangaFromLibrary(mangas)
|
||||
|
@ -685,6 +685,13 @@ class LibraryPresenter(
|
||||
.reduce { set1: Iterable<Category>, set2 -> set1.intersect(set2).toMutableList() }
|
||||
}
|
||||
|
||||
fun getMangaUrls(mangas: List<Manga>): List<String> {
|
||||
return mangas.mapNotNull { manga ->
|
||||
val source = sourceManager.get(manga.source) as? HttpSource ?: return@mapNotNull null
|
||||
source.mangaDetailsRequest(manga).url.toString()
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the selected manga from the library.
|
||||
*
|
||||
|
@ -1,17 +1,19 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
|
||||
<menu xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto">
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto">
|
||||
|
||||
<item android:id="@+id/action_move_to_category"
|
||||
android:title="@string/move_to_categories"
|
||||
android:icon="@drawable/ic_label_24dp"
|
||||
app:showAsAction="ifRoom"/>
|
||||
<item
|
||||
android:id="@+id/action_move_to_category"
|
||||
android:icon="@drawable/ic_label_24dp"
|
||||
android:title="@string/move_to_categories"
|
||||
app:showAsAction="ifRoom" />
|
||||
|
||||
<item android:id="@+id/action_delete"
|
||||
android:title="@string/remove"
|
||||
<item
|
||||
android:id="@+id/action_delete"
|
||||
android:icon="@drawable/ic_delete_24dp"
|
||||
app:showAsAction="ifRoom"/>
|
||||
android:title="@string/remove"
|
||||
app:showAsAction="ifRoom" />
|
||||
|
||||
<item
|
||||
android:id="@+id/action_migrate"
|
||||
@ -19,4 +21,9 @@
|
||||
android:title="@string/source_migration"
|
||||
app:showAsAction="ifRoom" />
|
||||
|
||||
<item
|
||||
android:id="@+id/action_share"
|
||||
android:icon="@drawable/ic_share_24dp"
|
||||
android:title="@string/share"
|
||||
app:showAsAction="ifRoom" />
|
||||
</menu>
|
Loading…
Reference in New Issue
Block a user