@@ -20,16 +20,17 @@ package org.comixedproject.variant.android.view.reading
2020
2121import android.graphics.BitmapFactory
2222import androidx.compose.foundation.Image
23+ import androidx.compose.foundation.clickable
24+ import androidx.compose.foundation.layout.Column
2325import androidx.compose.foundation.layout.Row
2426import androidx.compose.foundation.layout.fillMaxHeight
2527import androidx.compose.foundation.layout.fillMaxSize
2628import androidx.compose.foundation.layout.fillMaxWidth
27- import androidx.compose.foundation.layout.padding
28- import androidx.compose.material3.BottomAppBar
29+ import androidx.compose.foundation.rememberScrollState
30+ import androidx.compose.foundation.verticalScroll
2931import androidx.compose.material3.Icon
3032import androidx.compose.material3.IconButton
3133import androidx.compose.material3.MaterialTheme
32- import androidx.compose.material3.Scaffold
3334import androidx.compose.material3.Slider
3435import androidx.compose.material3.Text
3536import androidx.compose.runtime.Composable
@@ -43,6 +44,7 @@ import androidx.compose.ui.Modifier
4344import androidx.compose.ui.graphics.asImageBitmap
4445import androidx.compose.ui.res.painterResource
4546import androidx.compose.ui.res.stringResource
47+ import androidx.compose.ui.text.style.TextAlign
4648import androidx.compose.ui.text.style.TextOverflow
4749import androidx.compose.ui.tooling.preview.Preview
4850import org.comixedproject.variant.adaptor.ArchiveAPI
@@ -51,42 +53,33 @@ import org.comixedproject.variant.android.R
5153import org.comixedproject.variant.android.VariantTheme
5254import org.comixedproject.variant.platform.Log
5355
54- private const val TAG = " ReadingPageView "
56+ private const val TAG = " PageNavigationView "
5557
5658@Composable
57- fun ReadingPageView (
59+ fun PageNavigationView (
5860 comicFilename : String ,
61+ comicTitle : String ,
5962 pageFilename : String ,
6063 title : String ,
6164 currentPage : Int ,
6265 totalPages : Int ,
66+ showPageOverlay : Boolean ,
6367 onChangePage : (Int ) -> Unit ,
6468 onStopReading : () -> Unit ,
69+ onToggleShowOverlay : () -> Unit ,
6570 modifier : Modifier = Modifier
6671) {
6772 var currentPageContent by remember { mutableStateOf<ByteArray ?>(null ) }
6873
69- Scaffold (
70- content = { padding ->
71- if (currentPageContent == null ) {
72- LaunchedEffect (currentPageContent) {
73- currentPageContent =
74- ArchiveAPI .loadPage(comicFilename, pageFilename)
75- }
76- } else {
77- currentPageContent?.let { content ->
78- Image (
79- bitmap = BitmapFactory .decodeByteArray(content, 0 , content.size)
80- .asImageBitmap(),
81- contentDescription = title,
82- modifier = Modifier
83- .padding(padding)
84- .fillMaxHeight()
85- )
86- }
74+ Column (
75+ modifier = modifier
76+ .verticalScroll(rememberScrollState())
77+ .clickable {
78+ Log .debug(TAG , " Page tapped" )
79+ onToggleShowOverlay()
8780 }
88- },
89- topBar = {
81+ .fillMaxSize()) {
82+ if (showPageOverlay) {
9083 Row (
9184 verticalAlignment = Alignment .CenterVertically ,
9285 modifier = Modifier .fillMaxWidth()
@@ -107,69 +100,113 @@ fun ReadingPageView(
107100 }
108101
109102 Text (
110- title ,
103+ text = comicTitle ,
111104 style = MaterialTheme .typography.titleMedium,
105+ textAlign = TextAlign .Center ,
112106 maxLines = 1 ,
113107 overflow = TextOverflow .Ellipsis ,
114108 modifier = Modifier .fillMaxWidth()
115109 )
116110 }
117- },
118- bottomBar = {
119- BottomAppBar {
120- Row (modifier = Modifier .fillMaxWidth()) {
121- IconButton (onClick = {
122- currentPageContent = null
123- onChangePage(currentPage - 1 )
124- }, enabled = (currentPage > 0 )) {
125- Icon (
126- painterResource(R .drawable.ic_previous_page),
127- contentDescription = stringResource(R .string.previousPageLabel)
128- )
129- }
130111
131- Slider (
132- value = currentPage.toFloat(),
133- valueRange = 0f .. (totalPages - 1 ).toFloat(),
134- steps = totalPages,
135- onValueChange = {
136- currentPageContent = null
137- onChangePage(it.toInt())
138- },
139- modifier = Modifier .weight(0.9f )
112+ Text (
113+ text = pageFilename,
114+ style = MaterialTheme .typography.titleSmall,
115+ textAlign = TextAlign .Center ,
116+ maxLines = 1 , overflow = TextOverflow .Ellipsis ,
117+ modifier = Modifier .fillMaxWidth()
118+ )
119+ Row (modifier = Modifier .fillMaxWidth()) {
120+ IconButton (onClick = {
121+ currentPageContent = null
122+ onChangePage(currentPage - 1 )
123+ }, enabled = (currentPage > 0 )) {
124+ Icon (
125+ painterResource(R .drawable.ic_previous_page),
126+ contentDescription = stringResource(R .string.previousPageLabel)
140127 )
128+ }
141129
142- IconButton (onClick = {
130+ Slider (
131+ value = currentPage.toFloat(),
132+ valueRange = 0f .. (totalPages - 1 ).toFloat(),
133+ steps = totalPages,
134+ onValueChange = {
143135 currentPageContent = null
144- onChangePage(currentPage + 1 )
145- }, enabled = (currentPage < (totalPages - 1 ))) {
146- Icon (
147- painterResource(R .drawable.ic_next_page),
148- contentDescription = stringResource(R .string.nextPageLabel)
149- )
150- }
136+ onChangePage(it.toInt())
137+ },
138+ modifier = Modifier .weight(0.9f )
139+ )
140+
141+ IconButton (onClick = {
142+ currentPageContent = null
143+ onChangePage(currentPage + 1 )
144+ }, enabled = (currentPage < (totalPages - 1 ))) {
145+ Icon (
146+ painterResource(R .drawable.ic_next_page),
147+ contentDescription = stringResource(R .string.nextPageLabel)
148+ )
151149 }
152150 }
153- },
154- modifier = modifier
155- .fillMaxSize()
156- )
151+ }
152+
153+
154+ if (currentPageContent == null ) {
155+ LaunchedEffect (currentPageContent) {
156+ currentPageContent =
157+ ArchiveAPI .loadPage(comicFilename, pageFilename)
158+ }
159+ } else {
160+ currentPageContent?.let { content ->
161+ Image (
162+ bitmap = BitmapFactory .decodeByteArray(content, 0 , content.size)
163+ .asImageBitmap(),
164+ contentDescription = title,
165+ modifier = modifier
166+ .fillMaxHeight()
167+ )
168+ }
169+ }
170+ }
157171}
158172
159173
160174@Composable
161175@Preview
162- fun ReadingPageViewPreview () {
176+ fun PageNavigationPreview () {
163177 val comic = COMIC_BOOK_LIST .get(0 )
178+
164179 VariantTheme {
165- ReadingPageView (
180+ PageNavigationView (
181+ comic.path,
166182 comic.filename,
167183 comic.pages.get(0 ).filename,
168184 " Page Title" ,
169185 5 ,
170186 10 ,
187+ false ,
188+ onChangePage = {},
189+ onStopReading = {},
190+ onToggleShowOverlay = {})
191+ }
192+ }
193+
194+ @Composable
195+ @Preview
196+ fun PageNavigationPreviewWithOverlay () {
197+ val comic = COMIC_BOOK_LIST .get(0 )
198+
199+ VariantTheme {
200+ PageNavigationView (
201+ comic.path,
202+ comic.metadata.title,
203+ comic.pages.get(0 ).filename,
204+ " Page Title" ,
205+ 5 ,
206+ 10 ,
207+ true ,
171208 onChangePage = {},
172- onStopReading = {}
173- )
209+ onStopReading = {},
210+ onToggleShowOverlay = {} )
174211 }
175212}
0 commit comments