Spaces:
Sleeping
Sleeping
File size: 18,974 Bytes
947c08e cd23862 cffd4ca 4af0f6c 947c08e 0ab8c90 947c08e cd23862 947c08e 4af0f6c cd23862 947c08e 4af0f6c 947c08e 4af0f6c 947c08e 4af0f6c 947c08e cd23862 4af0f6c cd23862 4af0f6c cd23862 4af0f6c 0ab8c90 4af0f6c 0ab8c90 4af0f6c 0ab8c90 cd23862 0ab8c90 cd23862 0ab8c90 cd23862 0ab8c90 cd23862 0ab8c90 cd23862 0ab8c90 cd23862 0ab8c90 cd23862 0ab8c90 cd23862 0ab8c90 cd23862 0ab8c90 cd23862 0ab8c90 4af0f6c 947c08e |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 |
import React, { useEffect, useState, useCallback, useContext, useRef } from 'react';
import { Link, router, useLocalSearchParams, useNavigation, useFocusEffect } from 'expo-router';
import { Image as RNImage, StyleSheet, useWindowDimensions, ScrollView, Pressable, RefreshControl, Platform } from 'react-native';
import { SafeAreaView } from 'react-native-safe-area-context';
import { Icon, MD3Colors, Button, Text, TextInput, TouchableRipple } from 'react-native-paper';
import CircularProgress from 'react-native-circular-progress-indicator';
import { ActivityIndicator } from 'react-native-paper';
import uuid from 'react-native-uuid';
import Toast from 'react-native-toast-message';
import { View, AnimatePresence } from 'moti';
import * as Clipboard from 'expo-clipboard';
import * as FileSystem from 'expo-file-system';
import NetInfo from "@react-native-community/netinfo";
import JSZip from 'jszip';
import ComicStorage from '@/constants/module/storages/comic_storage';
import ChapterStorage from '@/constants/module/storages/chapter_storage';
import ChapterDataStorage from '@/constants/module/storages/chapter_data_storage';
import Image from '@/components/Image';
import {CONTEXT} from '@/constants/module/context';
import {blobToBase64, base64ToBlob} from "@/constants/module/file_manager";
import Theme from '@/constants/theme';
import { get_chapter } from '../modules/get_chapter';
const ChapterImage = ({item, zoom, showOptions, setShowOptions, setIsLoading, SET_DATA}:any)=>{
const SOURCE = useLocalSearchParams().source;
const COMIC_ID = useLocalSearchParams().comic_id;
const CHAPTER_IDX = Number(useLocalSearchParams().chapter_idx as string);
const Dimensions = useWindowDimensions();
const {showMenuContext, setShowMenuContext}:any = useContext(CONTEXT)
const {themeTypeContext, setThemeTypeContext}:any = useContext(CONTEXT)
const {showCloudflareTurnstileContext, setShowCloudflareTurnstileContext}:any = useContext(CONTEXT)
const [isReady, setIsReady] = useState(false);
const [isError, setIsError] = useState({state:false,text:""});
const [isNavigate, setIsNavigate] = useState(false);
const image = useRef<any>(null);
const image_layout = useRef<any>(null);
useEffect(()=>{(async () => {
if (item.type === "page"){
const store_chapter_image_data = await ChapterDataStorage.get(item.id)
if (store_chapter_image_data){
image.current = {type:"blob",data:store_chapter_image_data.data}
image_layout.current = store_chapter_image_data.layout
setIsReady(true)
}else{
setIsError({state:true,text:"Image not found!"})
}
}else setIsReady(true)
})()},[])
useFocusEffect(useCallback(() => {
return () => {
image.current = null
};
},[]))
return ( <Pressable
onPress={()=>{
setShowOptions({type:"general",state:!showOptions.state})
}}
style={{
display:"flex",
width:"100%",
height:"auto",
borderWidth:0,
alignItems:"center",
}}
>
<>{isReady
? (<>
{item.type === "page" && (
<Image source={image.current}
contentFit="contain"
style={{
width:Dimensions.width > 720
? 0.8 * Dimensions.width * (1 - zoom / 100)
: `${100 - zoom}%`,
aspectRatio: image_layout.current.width / image_layout.current.height,
}}
onLoadEnd={()=>{
image.current = ""
}}
/>
)}
{item.type === "chapter-info-banner" && (
<View
style={{
display:"flex",
flexDirection:"column",
alignItems:"center",
gap:12,
width:Dimensions.width > 720
? 0.8 * Dimensions.width * (1 - zoom / 100)
: `${100 - zoom}%`,
height:"auto",
backgroundColor:"black",
padding:16,
}}
>
<Text selectable={false}
numberOfLines={1}
style={{
color:Theme[themeTypeContext].text_color,
fontSize:(0.03 * ((Dimensions.width+Dimensions.height)/2)) * (1 - zoom/100),
fontFamily:"roboto-bold",
}}
>
End: {item.value.last}
</Text>
<Text selectable={false}
numberOfLines={1}
style={{
color:Theme[themeTypeContext].text_color,
fontSize:(0.03 * ((Dimensions.width+Dimensions.height)/2)) * (1 - zoom/100),
fontFamily:"roboto-bold",
}}
>
Next: {item.value.next}
</Text>
</View>
)}
{item.type === "no-chapter-banner" && (
<View
style={{
display:"flex",
flexDirection:"column",
alignItems:"center",
gap:12,
width:Dimensions.width > 720
? 0.8 * Dimensions.width * (1 - zoom / 100)
: `${100 - zoom}%`,
height:"auto",
backgroundColor:"black",
padding:16,
}}
>
<Text selectable={false}
numberOfLines={1}
style={{
color:Theme[themeTypeContext].text_color,
fontSize:(0.03 * ((Dimensions.width+Dimensions.height)/2)) * (1 - zoom/100),
fontFamily:"roboto-bold",
}}
>
No more chapters on local.
</Text>
<Text selectable={false}
numberOfLines={1}
style={{
color:Theme[themeTypeContext].text_color,
fontSize:(0.03 * ((Dimensions.width+Dimensions.height)/2)) * (1 - zoom/100),
fontFamily:"roboto-bold",
}}
>
You can go back and download more if available.
</Text>
</View>
)}
{item.type === "chapter-navigate" && (
<View
style={{
display:"flex",
flexDirection:"row",
justifyContent:"space-between",
alignItems:"center",
width:Dimensions.width > 720
? 0.8 * Dimensions.width * (1 - zoom / 100)
: `${100 - zoom}%`,
paddingHorizontal: 12,
paddingVertical: 18,
}}
>
<TouchableRipple disabled={isNavigate}
rippleColor={Theme[themeTypeContext].ripple_color_outlined}
style={{
width:"auto",
display:"flex",
flexDirection:"column",
justifyContent:"center",
alignSelf:"center",
padding:8,
paddingHorizontal:18,
borderRadius:Dimensions.width*0.65/2,
backgroundColor:Theme[themeTypeContext].border_color,
shadowColor: Theme[themeTypeContext].shadow_color,
shadowOffset: { width: 0, height: 2 },
shadowOpacity: 0.25,
shadowRadius: 3.84,
elevation: 5,
}}
onPress={async ()=>{
setIsNavigate(true);
const stored_chapter_info = await ChapterStorage.getByIdx(`${SOURCE}-${COMIC_ID}`,item.chapter_idx-1)
if (stored_chapter_info?.data_state === "completed"){
setIsLoading(true);
router.replace(`/read/${SOURCE}/${COMIC_ID}/${stored_chapter_info.idx}/`)
}else{
Toast.show({
type: 'info',
text1: 'Chapter not download yet.',
text2: "You can go back and download more.",
position: "bottom",
visibilityTime: 4000,
text1Style:{
fontFamily:"roboto-bold",
fontSize:((Dimensions.width+Dimensions.height)/2)*0.025
},
text2Style:{
fontFamily:"roboto-medium",
fontSize:((Dimensions.width+Dimensions.height)/2)*0.0185,
},
});
}
setIsNavigate(false);
}}
>
<Text selectable={false}
style={{
color:Theme[themeTypeContext].text_color,
fontFamily:"roboto-medium",
fontSize:(Dimensions.width+Dimensions.height)/2*0.03 * (1 - zoom / 100)
}}
>Previous</Text>
</TouchableRipple>
<TouchableRipple disabled={isNavigate}
rippleColor={Theme[themeTypeContext].ripple_color_outlined}
style={{
width:"auto",
display:"flex",
flexDirection:"column",
justifyContent:"center",
alignSelf:"center",
padding:8,
paddingHorizontal:18,
borderRadius:Dimensions.width*0.65/2,
backgroundColor:Theme[themeTypeContext].border_color,
shadowColor: Theme[themeTypeContext].shadow_color,
shadowOffset: { width: 0, height: 2 },
shadowOpacity: 0.25,
shadowRadius: 3.84,
elevation: 5,
}}
onPress={async ()=>{
setIsNavigate(true);
const stored_chapter_info = await ChapterStorage.getByIdx(`${SOURCE}-${COMIC_ID}`,item.chapter_idx+1)
if (stored_chapter_info?.data_state === "completed"){
setIsLoading(true)
const stored_comic = await ComicStorage.getByID(SOURCE, COMIC_ID)
if (stored_comic.history.idx && item.chapter_idx+1 > stored_comic.history.idx) {
await ComicStorage.updateHistory(SOURCE, COMIC_ID, {idx:stored_chapter_info?.idx, id:stored_chapter_info?.id, title:stored_chapter_info?.title})
}
router.replace(`/read/${SOURCE}/${COMIC_ID}/${stored_chapter_info.idx}/`)
}else{
Toast.show({
type: 'info',
text1: 'Chapter not download yet.',
text2: "You can go back and download more.",
position: "bottom",
visibilityTime: 4000,
text1Style:{
fontFamily:"roboto-bold",
fontSize:((Dimensions.width+Dimensions.height)/2)*0.025
},
text2Style:{
fontFamily:"roboto-medium",
fontSize:((Dimensions.width+Dimensions.height)/2)*0.0185,
},
});
}
setIsNavigate(false);
}}
>
<Text selectable={false}
style={{
color:Theme[themeTypeContext].text_color,
fontFamily:"roboto-medium",
fontSize:(Dimensions.width+Dimensions.height)/2*0.03 * (1 - zoom / 100)
}}
>Next</Text>
</TouchableRipple>
</View>
)}
</>)
: (
<View
style={{
display:"flex",
justifyContent:"center",
alignItems:"center",
backgroundColor:Theme[themeTypeContext].background_color,
width:Dimensions.width > 720
? 0.8 * Dimensions.width * (1 - zoom / 100)
: `${100 - zoom}%`,
height: Dimensions.height * 0.75
}}
>
{isError.state
? (
<View
style={{
display:'flex',
flexDirection:"column",
justifyContent:"center",
alignItems:"center",
width:"100%",
height:"100%",
gap:12,
}}
>
<Icon source={"alert-circle"} size={25} color={"red"}/>
<Text style={{color:"white",fontSize:12,fontFamily:"roboto-bold"}}>{isError.text}</Text>
</View>
)
: (<ActivityIndicator animating={true}/>)
}
</View>
)
}</>
</Pressable>
)
}
export default ChapterImage |