mirror of
https://github.com/aniyomiorg/aniyomi.git
synced 2024-11-24 13:48:55 +03:00
parent
c6317e9589
commit
2431d8a858
7 changed files with 60 additions and 49 deletions
|
@ -14,7 +14,10 @@ import androidx.compose.material.icons.outlined.ArrowForward
|
|||
import androidx.compose.material.icons.outlined.Close
|
||||
import androidx.compose.material3.LinearProgressIndicator
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.runtime.mutableStateOf
|
||||
import androidx.compose.runtime.remember
|
||||
import androidx.compose.runtime.setValue
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.res.stringResource
|
||||
|
@ -43,13 +46,14 @@ fun WebViewScreenContent(
|
|||
) {
|
||||
val state = rememberWebViewState(url = url, additionalHttpHeaders = headers)
|
||||
val navigator = rememberWebViewNavigator()
|
||||
var currentUrl by remember { mutableStateOf(url) }
|
||||
|
||||
Scaffold(
|
||||
topBar = {
|
||||
Box {
|
||||
AppBar(
|
||||
title = state.pageTitle ?: initialTitle,
|
||||
subtitle = state.lastLoadedUrl,
|
||||
subtitle = currentUrl,
|
||||
navigateUp = onNavigateUp,
|
||||
navigationIcon = Icons.Outlined.Close,
|
||||
actions = {
|
||||
|
@ -81,15 +85,15 @@ fun WebViewScreenContent(
|
|||
),
|
||||
AppBar.OverflowAction(
|
||||
title = stringResource(R.string.action_share),
|
||||
onClick = { onShare(state.lastLoadedUrl ?: url) },
|
||||
onClick = { onShare(currentUrl) },
|
||||
),
|
||||
AppBar.OverflowAction(
|
||||
title = stringResource(R.string.action_open_in_browser),
|
||||
onClick = { onOpenInBrowser(state.lastLoadedUrl ?: url) },
|
||||
onClick = { onOpenInBrowser(currentUrl) },
|
||||
),
|
||||
AppBar.OverflowAction(
|
||||
title = stringResource(R.string.pref_clear_cookies),
|
||||
onClick = { onClearCookies(state.lastLoadedUrl ?: url) },
|
||||
onClick = { onClearCookies(currentUrl) },
|
||||
),
|
||||
),
|
||||
)
|
||||
|
@ -116,7 +120,22 @@ fun WebViewScreenContent(
|
|||
object : AccompanistWebViewClient() {
|
||||
override fun onPageStarted(view: WebView, url: String?, favicon: Bitmap?) {
|
||||
super.onPageStarted(view, url, favicon)
|
||||
url?.let { onUrlChange(it) }
|
||||
url?.let {
|
||||
currentUrl = it
|
||||
onUrlChange(it)
|
||||
}
|
||||
}
|
||||
|
||||
override fun doUpdateVisitedHistory(
|
||||
view: WebView,
|
||||
url: String?,
|
||||
isReload: Boolean,
|
||||
) {
|
||||
super.doUpdateVisitedHistory(view, url, isReload)
|
||||
url?.let {
|
||||
currentUrl = it
|
||||
onUrlChange(it)
|
||||
}
|
||||
}
|
||||
|
||||
override fun shouldOverrideUrlLoading(
|
||||
|
|
|
@ -6,7 +6,7 @@ import androidx.compose.foundation.interaction.collectIsDraggedAsState
|
|||
import androidx.compose.material3.MaterialTheme
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.runtime.mutableStateOf
|
||||
import androidx.compose.runtime.mutableFloatStateOf
|
||||
import androidx.compose.runtime.remember
|
||||
import androidx.compose.runtime.setValue
|
||||
import androidx.compose.ui.graphics.Color
|
||||
|
@ -68,7 +68,7 @@ class Seekbar(
|
|||
) {
|
||||
val range = 0F..duration
|
||||
val validSegments = segments.filter { it.start in range }
|
||||
var mutableValue by remember { mutableStateOf(value) }
|
||||
var mutableValue by remember { mutableFloatStateOf(value) }
|
||||
val interactionSource = remember { MutableInteractionSource() }
|
||||
val isDragging by interactionSource.collectIsDraggedAsState()
|
||||
val gap by animateDpAsState(if (isDragging) 5.dp else 2.dp, label = "gap")
|
||||
|
|
|
@ -297,7 +297,9 @@ class ReaderActivity : BaseActivity() {
|
|||
menu.findItem(R.id.action_bookmark).isVisible = !isChapterBookmarked
|
||||
menu.findItem(R.id.action_remove_bookmark).isVisible = isChapterBookmarked
|
||||
|
||||
menu.findItem(R.id.action_open_in_web_view).isVisible = viewModel.getSource() is HttpSource
|
||||
val isHttpSource = viewModel.getSource() is HttpSource
|
||||
menu.findItem(R.id.action_open_in_web_view).isVisible = isHttpSource
|
||||
menu.findItem(R.id.action_share).isVisible = isHttpSource
|
||||
|
||||
return true
|
||||
}
|
||||
|
@ -309,7 +311,7 @@ class ReaderActivity : BaseActivity() {
|
|||
override fun onOptionsItemSelected(item: MenuItem): Boolean {
|
||||
when (item.itemId) {
|
||||
R.id.action_open_in_web_view -> {
|
||||
openChapterInWebview()
|
||||
openChapterInWebView()
|
||||
}
|
||||
R.id.action_bookmark -> {
|
||||
viewModel.bookmarkCurrentChapter(true)
|
||||
|
@ -319,6 +321,12 @@ class ReaderActivity : BaseActivity() {
|
|||
viewModel.bookmarkCurrentChapter(false)
|
||||
invalidateOptionsMenu()
|
||||
}
|
||||
R.id.action_share -> {
|
||||
assistUrl?.let {
|
||||
val intent = it.toUri().toShareIntent(this, type = "text/plain")
|
||||
startActivity(Intent.createChooser(intent, getString(R.string.action_share)))
|
||||
}
|
||||
}
|
||||
}
|
||||
return super.onOptionsItemSelected(item)
|
||||
}
|
||||
|
@ -664,14 +672,12 @@ class ReaderActivity : BaseActivity() {
|
|||
startPostponedEnterTransition()
|
||||
}
|
||||
|
||||
private fun openChapterInWebview() {
|
||||
private fun openChapterInWebView() {
|
||||
val manga = viewModel.manga ?: return
|
||||
val source = viewModel.getSource() ?: return
|
||||
lifecycleScope.launchIO {
|
||||
viewModel.getChapterUrl()?.let { url ->
|
||||
val intent = WebViewActivity.newIntent(this@ReaderActivity, url, source.id, manga.title)
|
||||
withUIContext { startActivity(intent) }
|
||||
}
|
||||
assistUrl?.let {
|
||||
val intent = WebViewActivity.newIntent(this@ReaderActivity, it, source.id, manga.title)
|
||||
startActivity(intent)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -4,10 +4,13 @@
|
|||
|
||||
<item
|
||||
android:id="@+id/action_bookmark"
|
||||
android:icon="@drawable/ic_bookmark_border_24dp"
|
||||
android:title="@string/action_bookmark"
|
||||
app:iconTint="?attr/colorOnSurface"
|
||||
app:showAsAction="ifRoom" />
|
||||
app:showAsAction="never" />
|
||||
|
||||
<item
|
||||
android:id="@+id/action_share"
|
||||
android:title="@string/action_share"
|
||||
app:showAsAction="never" />
|
||||
|
||||
<item
|
||||
android:id="@+id/action_remove_bookmark"
|
||||
|
|
|
@ -20,15 +20,6 @@ class LibraryFlagsTest {
|
|||
AnimeLibrarySort.directions.size shouldBe 2
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `Test Flag plus operator (LibraryDisplayMode)`() {
|
||||
val current = LibraryDisplayMode.List
|
||||
val new = LibraryDisplayMode.CoverOnlyGrid
|
||||
val flag = current + new
|
||||
|
||||
flag shouldBe 0b00000011
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `Test Flag plus operator (LibrarySort)`() {
|
||||
val mangacurrent = MangaLibrarySort(MangaLibrarySort.Type.LastRead, MangaLibrarySort.Direction.Ascending)
|
||||
|
@ -44,45 +35,37 @@ class LibraryFlagsTest {
|
|||
|
||||
@Test
|
||||
fun `Test Flag plus operator`() {
|
||||
val display = LibraryDisplayMode.CoverOnlyGrid
|
||||
val mangasort = MangaLibrarySort(MangaLibrarySort.Type.DateAdded, MangaLibrarySort.Direction.Ascending)
|
||||
val animesort = AnimeLibrarySort(AnimeLibrarySort.Type.DateAdded, AnimeLibrarySort.Direction.Ascending)
|
||||
val mangaflag = display + mangasort
|
||||
val animeflag = display + animesort
|
||||
|
||||
mangaflag shouldBe 0b01011111
|
||||
animeflag shouldBe 0b01011111
|
||||
mangasort.flag shouldBe 0b01011100
|
||||
animesort.flag shouldBe 0b01011100
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `Test Flag plus operator with old flag as base`() {
|
||||
val currentDisplay = LibraryDisplayMode.List
|
||||
val currentmangaSort = MangaLibrarySort(MangaLibrarySort.Type.UnreadCount, MangaLibrarySort.Direction.Descending)
|
||||
val currentmangaFlag = currentDisplay + currentmangaSort
|
||||
currentmangaSort.flag shouldBe 0b00001100
|
||||
val currentanimeSort = AnimeLibrarySort(AnimeLibrarySort.Type.UnseenCount, AnimeLibrarySort.Direction.Descending)
|
||||
val currentanimeFlag = currentDisplay + currentanimeSort
|
||||
currentanimeSort.flag shouldBe 0b00001100
|
||||
|
||||
val display = LibraryDisplayMode.CoverOnlyGrid
|
||||
val mangasort = MangaLibrarySort(MangaLibrarySort.Type.DateAdded, MangaLibrarySort.Direction.Ascending)
|
||||
val mangaflag = currentmangaFlag + display + mangasort
|
||||
val mangaflag = currentmangaSort.flag + mangasort
|
||||
val animesort = AnimeLibrarySort(AnimeLibrarySort.Type.DateAdded, AnimeLibrarySort.Direction.Ascending)
|
||||
val animeflag = currentanimeFlag + display + animesort
|
||||
val animeflag = animesort.flag + animesort
|
||||
|
||||
currentmangaFlag shouldBe 0b00001110
|
||||
mangaflag shouldBe 0b01011111
|
||||
mangaflag shouldNotBe currentmangaFlag
|
||||
currentanimeFlag shouldBe 0b00001110
|
||||
animeflag shouldBe 0b01011111
|
||||
animeflag shouldNotBe currentanimeFlag
|
||||
mangaflag shouldBe 0b01011100
|
||||
mangaflag shouldNotBe currentmangaSort.flag
|
||||
animeflag shouldBe 0b01011100
|
||||
animeflag shouldNotBe currentanimeSort.flag
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `Test default flags`() {
|
||||
val mangasort = MangaLibrarySort.default
|
||||
val animesort = AnimeLibrarySort.default
|
||||
val display = LibraryDisplayMode.default
|
||||
val mangaflag = display + mangasort.type + mangasort.direction
|
||||
val animeflag = display + animesort.type + animesort.direction
|
||||
val mangaflag = mangasort.type + mangasort.direction
|
||||
val animeflag = animesort.type + animesort.direction
|
||||
|
||||
mangaflag shouldBe 0b01000000
|
||||
animeflag shouldBe 0b01000000
|
||||
|
|
|
@ -9,7 +9,7 @@ annotation = "androidx.annotation:annotation:1.7.0-alpha02"
|
|||
appcompat = "androidx.appcompat:appcompat:1.6.1"
|
||||
biometricktx = "androidx.biometric:biometric-ktx:1.2.0-alpha05"
|
||||
constraintlayout = "androidx.constraintlayout:constraintlayout:2.1.4"
|
||||
corektx = "androidx.core:core-ktx:1.11.0-beta01"
|
||||
corektx = "androidx.core:core-ktx:1.11.0-beta02"
|
||||
splashscreen = "androidx.core:core-splashscreen:1.0.0-alpha02"
|
||||
recyclerview = "androidx.recyclerview:recyclerview:1.3.1-rc01"
|
||||
viewpager = "androidx.viewpager:viewpager:1.1.0-alpha01"
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
[versions]
|
||||
compiler = "1.4.7"
|
||||
compose-bom = "2023.04.00-beta01.1"
|
||||
compose-bom = "2023.04.00-beta02"
|
||||
accompanist = "0.31.2-alpha"
|
||||
|
||||
[libraries]
|
||||
|
|
Loading…
Reference in a new issue