Show download started snackbar
This commit is contained in:
@@ -96,7 +96,7 @@ class ChaptersFragment :
|
||||
return when (item.itemId) {
|
||||
R.id.action_save -> {
|
||||
DownloadService.start(
|
||||
context ?: return false,
|
||||
binding.recyclerViewChapters,
|
||||
viewModel.getRemoteManga() ?: viewModel.manga.value ?: return false,
|
||||
selectionController?.snapshot(),
|
||||
)
|
||||
|
||||
@@ -277,7 +277,7 @@ class DetailsActivity :
|
||||
)
|
||||
}
|
||||
setNeutralButton(R.string.download) { _, _ ->
|
||||
DownloadService.start(this@DetailsActivity, remoteManga, setOf(chapterId))
|
||||
DownloadService.start(binding.appbar, remoteManga, setOf(chapterId))
|
||||
}
|
||||
setCancelable(true)
|
||||
}.show()
|
||||
|
||||
@@ -86,7 +86,7 @@ class DetailsMenuProvider(
|
||||
if (chaptersCount > 5 || branches.size > 1) {
|
||||
showSaveConfirmation(it, chaptersCount, branches)
|
||||
} else {
|
||||
DownloadService.start(activity, it)
|
||||
DownloadService.start(snackbarHost, it)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -140,7 +140,7 @@ class DetailsMenuProvider(
|
||||
val chaptersIds = manga.chapters?.mapNotNullToSet { c ->
|
||||
if (c.branch in selectedBranches) c.id else null
|
||||
}
|
||||
DownloadService.start(activity, manga, chaptersIds)
|
||||
DownloadService.start(snackbarHost, manga, chaptersIds)
|
||||
}
|
||||
} else {
|
||||
dialogBuilder.setMessage(
|
||||
@@ -149,7 +149,7 @@ class DetailsMenuProvider(
|
||||
activity.resources.getQuantityString(R.plurals.chapters, chaptersCount, chaptersCount),
|
||||
),
|
||||
).setPositiveButton(R.string.save) { _, _ ->
|
||||
DownloadService.start(activity, manga)
|
||||
DownloadService.start(snackbarHost, manga)
|
||||
}
|
||||
}
|
||||
dialogBuilder.show()
|
||||
|
||||
@@ -7,7 +7,7 @@ import android.content.IntentFilter
|
||||
import android.os.Binder
|
||||
import android.os.IBinder
|
||||
import android.os.PowerManager
|
||||
import android.widget.Toast
|
||||
import android.view.View
|
||||
import androidx.annotation.MainThread
|
||||
import androidx.core.app.ServiceCompat
|
||||
import androidx.core.content.ContextCompat
|
||||
@@ -15,6 +15,7 @@ import androidx.lifecycle.DefaultLifecycleObserver
|
||||
import androidx.lifecycle.LifecycleOwner
|
||||
import androidx.lifecycle.lifecycleScope
|
||||
import com.google.android.material.dialog.MaterialAlertDialogBuilder
|
||||
import com.google.android.material.snackbar.Snackbar
|
||||
import dagger.hilt.android.AndroidEntryPoint
|
||||
import kotlinx.coroutines.flow.Flow
|
||||
import kotlinx.coroutines.flow.MutableStateFlow
|
||||
@@ -29,6 +30,7 @@ import org.koitharu.kotatsu.base.ui.BaseService
|
||||
import org.koitharu.kotatsu.core.model.parcelable.ParcelableManga
|
||||
import org.koitharu.kotatsu.download.domain.DownloadManager
|
||||
import org.koitharu.kotatsu.download.domain.DownloadState
|
||||
import org.koitharu.kotatsu.download.ui.DownloadsActivity
|
||||
import org.koitharu.kotatsu.parsers.model.Manga
|
||||
import org.koitharu.kotatsu.utils.ext.getParcelableExtraCompat
|
||||
import org.koitharu.kotatsu.utils.ext.throttle
|
||||
@@ -218,37 +220,38 @@ class DownloadService : BaseService() {
|
||||
private const val EXTRA_CHAPTERS_IDS = "chapters_ids"
|
||||
private const val EXTRA_CANCEL_ID = "cancel_id"
|
||||
|
||||
fun start(context: Context, manga: Manga, chaptersIds: Collection<Long>? = null) {
|
||||
fun start(view: View, manga: Manga, chaptersIds: Collection<Long>? = null) {
|
||||
if (chaptersIds?.isEmpty() == true) {
|
||||
return
|
||||
}
|
||||
val intent = Intent(context, DownloadService::class.java)
|
||||
val intent = Intent(view.context, DownloadService::class.java)
|
||||
intent.putExtra(EXTRA_MANGA, ParcelableManga(manga, withChapters = false))
|
||||
if (chaptersIds != null) {
|
||||
intent.putExtra(EXTRA_CHAPTERS_IDS, chaptersIds.toLongArray())
|
||||
}
|
||||
ContextCompat.startForegroundService(context, intent)
|
||||
Toast.makeText(context, R.string.manga_downloading_, Toast.LENGTH_SHORT).show()
|
||||
ContextCompat.startForegroundService(view.context, intent)
|
||||
showStartedSnackbar(view)
|
||||
}
|
||||
|
||||
fun start(context: Context, manga: Collection<Manga>) {
|
||||
fun start(view: View, manga: Collection<Manga>) {
|
||||
if (manga.isEmpty()) {
|
||||
return
|
||||
}
|
||||
for (item in manga) {
|
||||
val intent = Intent(context, DownloadService::class.java)
|
||||
val intent = Intent(view.context, DownloadService::class.java)
|
||||
intent.putExtra(EXTRA_MANGA, ParcelableManga(item, withChapters = false))
|
||||
ContextCompat.startForegroundService(context, intent)
|
||||
ContextCompat.startForegroundService(view.context, intent)
|
||||
}
|
||||
showStartedSnackbar(view)
|
||||
}
|
||||
|
||||
fun confirmAndStart(context: Context, items: Set<Manga>) {
|
||||
MaterialAlertDialogBuilder(context)
|
||||
fun confirmAndStart(view: View, items: Set<Manga>) {
|
||||
MaterialAlertDialogBuilder(view.context)
|
||||
.setTitle(R.string.save_manga)
|
||||
.setMessage(R.string.batch_manga_save_confirm)
|
||||
.setNegativeButton(android.R.string.cancel, null)
|
||||
.setPositiveButton(R.string.save) { _, _ ->
|
||||
start(context, items)
|
||||
start(view, items)
|
||||
}.show()
|
||||
}
|
||||
|
||||
@@ -264,5 +267,12 @@ class DownloadService : BaseService() {
|
||||
}
|
||||
return null
|
||||
}
|
||||
|
||||
private fun showStartedSnackbar(view: View) {
|
||||
Snackbar.make(view, R.string.download_started, Snackbar.LENGTH_LONG)
|
||||
.setAction(R.string.details) {
|
||||
it.context.startActivity(DownloadsActivity.newIntent(it.context))
|
||||
}.show()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -327,7 +327,7 @@ abstract class MangaListFragment :
|
||||
}
|
||||
|
||||
R.id.action_save -> {
|
||||
DownloadService.confirmAndStart(requireContext(), selectedItems)
|
||||
DownloadService.confirmAndStart(binding.recyclerView, selectedItems)
|
||||
mode.finish()
|
||||
true
|
||||
}
|
||||
|
||||
@@ -164,7 +164,7 @@ class MultiSearchActivity :
|
||||
}
|
||||
|
||||
R.id.action_save -> {
|
||||
DownloadService.confirmAndStart(this, collectSelectedItems())
|
||||
DownloadService.confirmAndStart(binding.recyclerView, collectSelectedItems())
|
||||
mode.finish()
|
||||
true
|
||||
}
|
||||
|
||||
@@ -68,7 +68,7 @@ class ShelfSelectionCallback(
|
||||
}
|
||||
|
||||
R.id.action_save -> {
|
||||
DownloadService.confirmAndStart(context, collectSelectedItems(controller))
|
||||
DownloadService.confirmAndStart(recyclerView, collectSelectedItems(controller))
|
||||
mode.finish()
|
||||
true
|
||||
}
|
||||
@@ -125,7 +125,7 @@ class ShelfSelectionCallback(
|
||||
if (ids.isEmpty()) {
|
||||
return
|
||||
}
|
||||
MaterialAlertDialogBuilder(context ?: return)
|
||||
MaterialAlertDialogBuilder(context)
|
||||
.setTitle(R.string.delete_manga)
|
||||
.setMessage(context.getString(R.string.text_delete_local_manga_batch))
|
||||
.setPositiveButton(R.string.delete) { _, _ ->
|
||||
|
||||
@@ -423,4 +423,5 @@
|
||||
<string name="services">Services</string>
|
||||
<string name="allow_unstable_updates">Allow unstable updates</string>
|
||||
<string name="allow_unstable_updates_summary">Propose updates to beta versions of the app</string>
|
||||
<string name="download_started">Download started</string>
|
||||
</resources>
|
||||
|
||||
Reference in New Issue
Block a user