Add swipe actions for chapters (#9304)

* added chapter swipe

* Rework corner animtion

* Update i18n/src/main/res/values/strings.xml

Co-authored-by: arkon <arkon@users.noreply.github.com>

* Replace LTR/RTL with Start/End layout

* Added label to the animation so the warning will go away

* Getting rid of the swipe threshold setting

* adding disabled option, renaming stuff, other stuff?

* Getting rid of the snackbar

* Getting rid of unecessary strings

* changing enum names as requested

* Renaming Raio to Ratio (I need a better keyboard as well -__-)

* Replacing error with download icon and action

* backup

* minor cleanup

* fixing an nasty edge case

* fixing mistakes in the previous conflict

* space

* fixing bug

fixed bug where the user could dismiss already dismissed item leading to item getting stuck

* fixing lint errors

* fixing lints (hopefully)

* Added "swipe disabled" to the list of actions

* Replacing string value and moving value as requested

* replacing rest of the strings with generic ones

---------

Co-authored-by: arkon <arkon@users.noreply.github.com>
This commit is contained in:
d-najd
2023-04-25 23:29:39 +02:00
committed by GitHub
parent ef3d2c14b4
commit a8f17a3fab
7 changed files with 419 additions and 89 deletions

View File

@@ -101,6 +101,8 @@ class MangaScreen(
dateRelativeTime = screenModel.relativeTime,
dateFormat = screenModel.dateFormat,
isTabletUi = isTabletUi(),
chapterSwipeEndAction = screenModel.chapterSwipeEndAction,
chapterSwipeStartAction = screenModel.chapterSwipeStartAction,
onBackClicked = navigator::pop,
onChapterClicked = { openChapter(context, it) },
onDownloadChapter = screenModel::runChapterDownloadActions.takeIf { !successState.source.isLocalOrStub() },
@@ -125,6 +127,7 @@ class MangaScreen(
onMultiMarkAsReadClicked = screenModel::markChaptersRead,
onMarkPreviousAsReadClicked = screenModel::markPreviousChapterRead,
onMultiDeleteClicked = screenModel::showDeleteChapterDialog,
onChapterSwipe = screenModel::chapterSwipe,
onChapterSelected = screenModel::toggleSelection,
onAllChapterSelected = screenModel::toggleAllSelection,
onInvertSelection = screenModel::invertSelection,

View File

@@ -121,6 +121,9 @@ class MangaInfoScreenModel(
private val filteredChapters: Sequence<ChapterItem>?
get() = successState?.processedChapters
val chapterSwipeEndAction = libraryPreferences.swipeEndAction().get()
val chapterSwipeStartAction = libraryPreferences.swipeStartAction().get()
val relativeTime by uiPreferences.relativeTime().asState(coroutineScope)
val dateFormat by mutableStateOf(UiPreferences.dateFormat(uiPreferences.dateFormat().get()))
private val skipFiltered by readerPreferences.skipFiltered().asState(coroutineScope)
@@ -523,6 +526,49 @@ class MangaInfoScreenModel(
}
}
/**
* @throws IllegalStateException if the swipe action is [LibraryPreferences.ChapterSwipeAction.Disabled]
*/
fun chapterSwipe(chapterItem: ChapterItem, swipeAction: LibraryPreferences.ChapterSwipeAction) {
coroutineScope.launch {
executeChapterSwipeAction(chapterItem, swipeAction)
}
}
/**
* @throws IllegalStateException if the swipe action is [LibraryPreferences.ChapterSwipeAction.Disabled]
*/
private fun executeChapterSwipeAction(
chapterItem: ChapterItem,
swipeAction: LibraryPreferences.ChapterSwipeAction,
) {
val chapter = chapterItem.chapter
when (swipeAction) {
LibraryPreferences.ChapterSwipeAction.ToggleRead -> {
markChaptersRead(listOf(chapter), !chapter.read)
}
LibraryPreferences.ChapterSwipeAction.ToggleBookmark -> {
bookmarkChapters(listOf(chapter), !chapter.bookmark)
}
LibraryPreferences.ChapterSwipeAction.Download -> {
val downloadAction: ChapterDownloadAction = when (chapterItem.downloadState) {
Download.State.ERROR,
Download.State.NOT_DOWNLOADED,
-> ChapterDownloadAction.START_NOW
Download.State.QUEUE,
Download.State.DOWNLOADING,
-> ChapterDownloadAction.CANCEL
Download.State.DOWNLOADED -> ChapterDownloadAction.DELETE
}
runChapterDownloadActions(
items = listOf(chapterItem),
action = downloadAction,
)
}
LibraryPreferences.ChapterSwipeAction.Disabled -> throw IllegalStateException()
}
}
/**
* Returns the next unread chapter or null if everything is read.
*/