Compare commits
40 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| fda59f825f | |||
| 67096eb1ff | |||
| 3a156f32a0 | |||
| 555552a64d | |||
| 53fc800b90 | |||
| d1e10433e2 | |||
| cc53e309ad | |||
| 2170b77607 | |||
| 632c2e47c7 | |||
| 5e2c4d4e27 | |||
| a21800f208 | |||
| 5f943fcc92 | |||
| 8f254b4ef5 | |||
| 773913048c | |||
| daf9444e87 | |||
| e4b1b757e6 | |||
| b01e63791e | |||
| ffe4950966 | |||
| caac2c3227 | |||
| 489d5ba714 | |||
| 4251ec7f20 | |||
| c1e0b01df8 | |||
| 66dc1c4bdb | |||
| 1ba88a16ff | |||
| 381c779c36 | |||
| 90df6b5aca | |||
| 87ff17d5e5 | |||
| 913d319222 | |||
| cca143383e | |||
| 4a874b30be | |||
| e958b0fa09 | |||
| a484d550a8 | |||
| 4acafdb741 | |||
| 1e6c4758ff | |||
| 1ed0e8b4c4 | |||
| 458cdb2c2a | |||
| 0a476ba6b4 | |||
| 6e85909f6f | |||
| 5642122a5e | |||
| 77481dfc06 |
|
Before Width: | Height: | Size: 1.3 MiB After Width: | Height: | Size: 1.3 MiB |
@@ -1,55 +1,32 @@
|
||||
import React, { useState, useEffect } from "react";
|
||||
import { StatusBar } from "expo-status-bar";
|
||||
import { NavigationContainer } from "@react-navigation/native";
|
||||
import * as Font from "expo-font";
|
||||
import AppLoading from "expo-app-loading";
|
||||
import React, { useEffect } from "react";
|
||||
import { useFonts } from "expo-font";
|
||||
import { Provider as PaperProvider } from "react-native-paper";
|
||||
import Main from "./src/Navigators/Main";
|
||||
|
||||
import Router from "./src/navigation/Router";
|
||||
|
||||
// Redux
|
||||
import { Provider } from "react-redux";
|
||||
import { persistor, store } from "./src/redux/store";
|
||||
import { PersistGate } from "redux-persist/lib/integration/react";
|
||||
import { createDB, deleteDb } from "./src/database/DBHelper";
|
||||
|
||||
const getFonts = () =>
|
||||
Font.loadAsync({
|
||||
"pt-sans-bold": require("./assets/fonts/PTSansNarrow-Bold.ttf"),
|
||||
"arbutus-slab": require("./assets/fonts/ArbutusSlab-Regular.ttf"),
|
||||
domine: require("./assets/fonts/Domine-VariableFont_wght.ttf"),
|
||||
lato: require("./assets/fonts/Lato-Regular.ttf"),
|
||||
"noto-sans": require("./assets/fonts/NotoSans-Regular.ttf"),
|
||||
"open-sans": require("./assets/fonts/OpenSans-Regular.ttf"),
|
||||
"pt-serif": require("./assets/fonts/PTSerif-Regular.ttf"),
|
||||
});
|
||||
import { createDB, deleteDb } from "./src/Database/DBHelper";
|
||||
import { fonts } from "./src/Theme/fonts";
|
||||
|
||||
const App = () => {
|
||||
const [fontsLoaded, setFontsLoaded] = useState(false);
|
||||
const [loaded] = useFonts(fonts);
|
||||
|
||||
useEffect(() => {
|
||||
createDB();
|
||||
}, []);
|
||||
useEffect(() => createDB(), []);
|
||||
|
||||
if (fontsLoaded) {
|
||||
return (
|
||||
<Provider store={store}>
|
||||
<PersistGate loading={null} persistor={persistor}>
|
||||
<StatusBar />
|
||||
<NavigationContainer>
|
||||
<Router />
|
||||
</NavigationContainer>
|
||||
</PersistGate>
|
||||
</Provider>
|
||||
);
|
||||
} else {
|
||||
return (
|
||||
<AppLoading
|
||||
startAsync={getFonts}
|
||||
onError={() => warn(error)}
|
||||
onFinish={() => setFontsLoaded(true)}
|
||||
/>
|
||||
);
|
||||
if (!loaded) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return (
|
||||
<Provider store={store}>
|
||||
<PersistGate loading={null} persistor={persistor}>
|
||||
<PaperProvider>
|
||||
<Main />
|
||||
</PaperProvider>
|
||||
</PersistGate>
|
||||
</Provider>
|
||||
);
|
||||
};
|
||||
|
||||
export default App;
|
||||
|
||||
@@ -2,18 +2,23 @@
|
||||
"expo": {
|
||||
"name": "LNReader",
|
||||
"slug": "LNReader",
|
||||
"version": "1.0.0",
|
||||
"orientation": "portrait",
|
||||
"scheme": "lnreader",
|
||||
"version": "1.0.16",
|
||||
"orientation": "default",
|
||||
"icon": "./assets/icon.png",
|
||||
"splash": {
|
||||
"image": "./assets/splash.png",
|
||||
"resizeMode": "cover",
|
||||
"backgroundColor": "#000000"
|
||||
"backgroundColor": "#222831"
|
||||
},
|
||||
"updates": {
|
||||
"fallbackToCacheTimeout": 0,
|
||||
"enabled": false
|
||||
},
|
||||
"notification": {
|
||||
"icon": "./assets/notification.png",
|
||||
"color": "#00adb5"
|
||||
},
|
||||
"assetBundlePatterns": ["**/*"],
|
||||
"ios": {
|
||||
"supportsTablet": true
|
||||
|
||||
|
Before Width: | Height: | Size: 8.0 KiB After Width: | Height: | Size: 266 KiB |
|
After Width: | Height: | Size: 19 KiB |
|
After Width: | Height: | Size: 2.1 KiB |
|
Before Width: | Height: | Size: 24 KiB After Width: | Height: | Size: 36 KiB |
@@ -8,46 +8,56 @@
|
||||
"eject": "expo eject"
|
||||
},
|
||||
"dependencies": {
|
||||
"@react-native-async-storage/async-storage": "^1.13.2",
|
||||
"@react-native-async-storage/async-storage": "^1.13.0",
|
||||
"@react-native-community/masked-view": "0.1.10",
|
||||
"@react-native-community/netinfo": "^5.9.7",
|
||||
"@react-native-community/slider": "^3.0.3",
|
||||
"@react-native-community/netinfo": "6.0.0",
|
||||
"@react-native-community/slider": "3.0.3",
|
||||
"@react-navigation/material-bottom-tabs": "^5.3.10",
|
||||
"@react-navigation/native": "^5.8.10",
|
||||
"@react-navigation/stack": "^5.12.8",
|
||||
"expo": "~40.0.0",
|
||||
"expo": "^41.0.1",
|
||||
"expo-app-loading": "^1.0.1",
|
||||
"expo-font": "^8.4.0",
|
||||
"expo-linear-gradient": "^8.4.0",
|
||||
"expo-sharing": "~8.5.0",
|
||||
"expo-sqlite": "~8.5.0",
|
||||
"expo-status-bar": "~1.0.3",
|
||||
"expo-web-browser": "~8.6.0",
|
||||
"expo-background-fetch": "~9.1.0",
|
||||
"expo-document-picker": "^9.1.2",
|
||||
"expo-file-system": "~11.0.2",
|
||||
"expo-font": "~9.1.0",
|
||||
"expo-linear-gradient": "~9.1.0",
|
||||
"expo-linking": "~2.2.3",
|
||||
"expo-media-library": "~12.0.2",
|
||||
"expo-notifications": "~0.11.6",
|
||||
"expo-permissions": "^12.0.1",
|
||||
"expo-sharing": "~9.1.2",
|
||||
"expo-sqlite": "~9.1.0",
|
||||
"expo-status-bar": "~1.0.4",
|
||||
"expo-task-manager": "~9.1.0",
|
||||
"expo-web-browser": "~9.1.0",
|
||||
"moment": "^2.29.1",
|
||||
"qs": "^6.10.1",
|
||||
"react": "16.13.1",
|
||||
"react-dom": "16.13.1",
|
||||
"react-native": "https://github.com/expo/react-native/archive/sdk-40.0.1.tar.gz",
|
||||
"react-native": "https://github.com/expo/react-native/archive/sdk-41.0.0.tar.gz",
|
||||
"react-native-collapsible-header-views": "^1.1.2",
|
||||
"react-native-gesture-handler": "^1.8.0",
|
||||
"react-native-easing-gradient": "^0.1.2",
|
||||
"react-native-gesture-handler": "~1.10.2",
|
||||
"react-native-offline": "^5.7.0",
|
||||
"react-native-paper": "^4.5.0",
|
||||
"react-native-reanimated": "^1.13.2",
|
||||
"react-native-safe-area-context": "3.1.9",
|
||||
"react-native-screens": "~2.15.0",
|
||||
"react-native-picker-scrollview": "^1.0.1",
|
||||
"react-native-reanimated": "~2.1.0",
|
||||
"react-native-safe-area-context": "3.2.0",
|
||||
"react-native-screens": "~3.0.0",
|
||||
"react-native-swipe-list-view": "^3.2.7",
|
||||
"react-native-vector-icons": "^7.1.0",
|
||||
"react-native-web": "~0.13.12",
|
||||
"react-native-webview": "11.0.0",
|
||||
"react-native-webview": "11.2.3",
|
||||
"react-redux": "^7.2.2",
|
||||
"redux": "^4.0.5",
|
||||
"redux-devtools-extension": "^2.13.9",
|
||||
"redux-persist": "^6.0.0",
|
||||
"redux-thunk": "^2.3.0",
|
||||
"reflect-metadata": "^0.1.13",
|
||||
"rn-sliding-up-panel": "^2.4.4"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@babel/core": "~7.9.0",
|
||||
"@types/node": "^14.14.35"
|
||||
"@babel/core": "~7.9.0"
|
||||
},
|
||||
"private": true
|
||||
}
|
||||
|
||||
@@ -11,7 +11,7 @@ import { useNavigation } from "@react-navigation/native";
|
||||
import { useSelector } from "react-redux";
|
||||
|
||||
export const Appbar = ({ title, onBackAction, style }) => {
|
||||
const theme = useSelector((state) => state.themeReducer.theme);
|
||||
const theme = useSelector((state) => state.settingsReducer.theme);
|
||||
|
||||
return (
|
||||
<MaterialAppbar.Header
|
||||
@@ -42,7 +42,7 @@ export const SearchAppbar = ({
|
||||
|
||||
const navigation = useNavigation();
|
||||
|
||||
const theme = useSelector((state) => state.themeReducer.theme);
|
||||
const theme = useSelector((state) => state.settingsReducer.theme);
|
||||
|
||||
return (
|
||||
<TouchableRipple
|
||||
@@ -0,0 +1,17 @@
|
||||
import React from "react";
|
||||
import { View } from "react-native";
|
||||
|
||||
const BottomSheetHandle = ({ theme }) => (
|
||||
<View
|
||||
style={{
|
||||
backgroundColor: theme.textColorHint,
|
||||
height: 5,
|
||||
width: 30,
|
||||
borderRadius: 50,
|
||||
top: 10,
|
||||
alignSelf: "center",
|
||||
}}
|
||||
/>
|
||||
);
|
||||
|
||||
export default BottomSheetHandle;
|
||||
@@ -3,7 +3,7 @@ import { StyleSheet, Text, View } from "react-native";
|
||||
import { useSelector } from "react-redux";
|
||||
|
||||
const EmptyView = ({ icon, description }) => {
|
||||
const theme = useSelector((state) => state.themeReducer.theme);
|
||||
const theme = useSelector((state) => state.settingsReducer.theme);
|
||||
|
||||
return (
|
||||
<View style={styles.emptyViewContainer}>
|
||||
@@ -0,0 +1,87 @@
|
||||
import React from "react";
|
||||
import { StyleSheet } from "react-native";
|
||||
import { List, Divider as PaperDivider } from "react-native-paper";
|
||||
|
||||
const ListSection = ({ children }) => (
|
||||
<List.Section style={styles.listSection}>{children}</List.Section>
|
||||
);
|
||||
|
||||
const ListSubHeader = ({ children, theme }) => (
|
||||
<List.Subheader
|
||||
style={[styles.listSubHeader, { color: theme.colorAccent }]}
|
||||
>
|
||||
{children}
|
||||
</List.Subheader>
|
||||
);
|
||||
|
||||
const ListItem = ({
|
||||
title,
|
||||
description,
|
||||
icon,
|
||||
onPress,
|
||||
theme,
|
||||
right,
|
||||
titleStyle,
|
||||
}) => (
|
||||
<List.Item
|
||||
title={title}
|
||||
style={[!right && { paddingVertical: 12 }]}
|
||||
titleStyle={[{ color: theme.textColorPrimary }, titleStyle]}
|
||||
description={description}
|
||||
descriptionStyle={{ color: theme.textColorSecondary }}
|
||||
descriptionNumberOfLines={1}
|
||||
left={() =>
|
||||
icon && (
|
||||
<List.Icon
|
||||
color={theme.colorAccent}
|
||||
icon={icon}
|
||||
style={{ marginVertical: 0 }}
|
||||
/>
|
||||
)
|
||||
}
|
||||
right={() =>
|
||||
right && (
|
||||
<List.Icon
|
||||
color="#47a84a"
|
||||
icon={right}
|
||||
style={{ marginVertical: 0 }}
|
||||
/>
|
||||
)
|
||||
}
|
||||
onPress={onPress}
|
||||
rippleColor={theme.rippleColor}
|
||||
/>
|
||||
);
|
||||
|
||||
const Divider = ({ theme }) => (
|
||||
<PaperDivider style={{ backgroundColor: theme.dividerColor, height: 1 }} />
|
||||
);
|
||||
|
||||
const InfoItem = ({ title, icon, theme }) => (
|
||||
<List.Item
|
||||
title={title}
|
||||
titleStyle={{ color: theme.textColorSecondary, fontSize: 14 }}
|
||||
titleNumberOfLines={5}
|
||||
left={() =>
|
||||
icon && (
|
||||
<List.Icon
|
||||
color={theme.textColorSecondary}
|
||||
icon={icon}
|
||||
style={{ marginVertical: 0 }}
|
||||
/>
|
||||
)
|
||||
}
|
||||
/>
|
||||
);
|
||||
|
||||
export { ListSection, ListSubHeader, ListItem, Divider, InfoItem };
|
||||
|
||||
const styles = StyleSheet.create({
|
||||
listSection: {
|
||||
flex: 1,
|
||||
marginVertical: 0,
|
||||
},
|
||||
listSubHeader: {
|
||||
paddingBottom: 5,
|
||||
},
|
||||
});
|
||||
@@ -0,0 +1,64 @@
|
||||
import React from "react";
|
||||
import { StyleSheet, View, Text, Image } from "react-native";
|
||||
import { TouchableRipple } from "react-native-paper";
|
||||
|
||||
const ListView = ({ item, downloadBadge, unreadBadge, theme, onPress }) => {
|
||||
return (
|
||||
<TouchableRipple
|
||||
borderless
|
||||
centered
|
||||
rippleColor={theme.rippleColor}
|
||||
style={styles.listView}
|
||||
onPress={onPress}
|
||||
>
|
||||
<>
|
||||
<Image
|
||||
source={{ uri: item.novelCover }}
|
||||
style={styles.extensionIcon}
|
||||
/>
|
||||
<Text
|
||||
style={[
|
||||
{ color: theme.textColorPrimary },
|
||||
styles.novelName,
|
||||
]}
|
||||
numberOfLines={1}
|
||||
>
|
||||
{item.novelName}
|
||||
</Text>
|
||||
<View style={styles.badgeContainer}>
|
||||
{downloadBadge}
|
||||
{unreadBadge}
|
||||
</View>
|
||||
</>
|
||||
</TouchableRipple>
|
||||
);
|
||||
};
|
||||
|
||||
export default ListView;
|
||||
|
||||
const styles = StyleSheet.create({
|
||||
listView: {
|
||||
flex: 1,
|
||||
flexDirection: "row",
|
||||
alignItems: "center",
|
||||
paddingVertical: 8,
|
||||
paddingHorizontal: 12,
|
||||
},
|
||||
extensionIcon: {
|
||||
width: 40,
|
||||
height: 40,
|
||||
borderRadius: 4,
|
||||
},
|
||||
novelName: {
|
||||
flex: 1,
|
||||
marginLeft: 16,
|
||||
fontSize: 15,
|
||||
paddingRight: 8,
|
||||
flexWrap: "wrap",
|
||||
},
|
||||
badgeContainer: {
|
||||
flexDirection: "row",
|
||||
justifyContent: "flex-end",
|
||||
alignItems: "flex-end",
|
||||
},
|
||||
});
|
||||
@@ -0,0 +1,80 @@
|
||||
import React, { useState } from "react";
|
||||
import { StyleSheet, View, Text } from "react-native";
|
||||
import { Portal, Modal, Button } from "react-native-paper";
|
||||
import * as Linking from "expo-linking";
|
||||
import { useTheme } from "../Hooks/reduxHooks";
|
||||
|
||||
const NewUpdateDialog = ({ newVersion }) => {
|
||||
const [newUpdateDialog, showNewUpdateDialog] = useState(true);
|
||||
|
||||
const theme = useTheme();
|
||||
|
||||
return (
|
||||
<Portal>
|
||||
<Modal
|
||||
visible={newUpdateDialog}
|
||||
onDismiss={() => showNewUpdateDialog(false)}
|
||||
contentContainerStyle={[
|
||||
styles.containerStyle,
|
||||
{ backgroundColor: theme.colorPrimaryDark },
|
||||
]}
|
||||
>
|
||||
<Text
|
||||
style={[
|
||||
styles.modalHeader,
|
||||
{ color: theme.textColorPrimary },
|
||||
]}
|
||||
>
|
||||
{`New update available ${newVersion.tag_name}`}
|
||||
</Text>
|
||||
<Text style={{ color: theme.textColorSecondary, fontSize: 16 }}>
|
||||
{newVersion.body}
|
||||
</Text>
|
||||
<View
|
||||
style={{
|
||||
flexDirection: "row",
|
||||
marginTop: 30,
|
||||
justifyContent: "flex-end",
|
||||
}}
|
||||
>
|
||||
<Button
|
||||
labelStyle={{
|
||||
color: theme.colorAccent,
|
||||
letterSpacing: 0,
|
||||
textTransform: "none",
|
||||
}}
|
||||
theme={{ colors: { primary: theme.colorAccent } }}
|
||||
onPress={() => showNewUpdateDialog(false)}
|
||||
>
|
||||
Cancel
|
||||
</Button>
|
||||
<Button
|
||||
labelStyle={{
|
||||
color: theme.colorAccent,
|
||||
letterSpacing: 0,
|
||||
textTransform: "none",
|
||||
}}
|
||||
theme={{ colors: { primary: theme.colorAccent } }}
|
||||
onPress={() => Linking.openURL(newVersion.downloadUrl)}
|
||||
>
|
||||
Install
|
||||
</Button>
|
||||
</View>
|
||||
</Modal>
|
||||
</Portal>
|
||||
);
|
||||
};
|
||||
|
||||
export default NewUpdateDialog;
|
||||
|
||||
const styles = StyleSheet.create({
|
||||
containerStyle: {
|
||||
padding: 20,
|
||||
margin: 20,
|
||||
borderRadius: 6,
|
||||
},
|
||||
modalHeader: {
|
||||
fontSize: 20,
|
||||
marginBottom: 10,
|
||||
},
|
||||
});
|
||||
@@ -0,0 +1,179 @@
|
||||
import React from "react";
|
||||
import { StyleSheet, View, Text, ImageBackground, Image } from "react-native";
|
||||
import { LinearGradient } from "expo-linear-gradient";
|
||||
import { TouchableRipple } from "react-native-paper";
|
||||
|
||||
import { useSelector } from "react-redux";
|
||||
import { useSettings, useTheme } from "../Hooks/reduxHooks";
|
||||
import ListView from "./ListView";
|
||||
|
||||
const NovelCover = ({ item, onPress, libraryStatus }) => {
|
||||
const theme = useTheme();
|
||||
const { displayMode, itemsPerRow } = useSettings();
|
||||
|
||||
const height = {
|
||||
1: 550,
|
||||
2: 280,
|
||||
3: 180,
|
||||
4: 140,
|
||||
5: 100,
|
||||
};
|
||||
|
||||
const comfortableTitle = () =>
|
||||
displayMode === 1 && (
|
||||
<Text
|
||||
numberOfLines={2}
|
||||
style={[
|
||||
styles.title,
|
||||
{
|
||||
color: theme.textColorPrimary,
|
||||
padding: 4,
|
||||
},
|
||||
]}
|
||||
>
|
||||
{item.novelName}
|
||||
</Text>
|
||||
);
|
||||
|
||||
const compactTitle = () =>
|
||||
displayMode === 0 && (
|
||||
<View style={styles.titleContainer}>
|
||||
<LinearGradient
|
||||
colors={["transparent", "rgba(0,0,0,0.6)"]}
|
||||
style={styles.linearGradient}
|
||||
>
|
||||
<Text
|
||||
numberOfLines={2}
|
||||
style={[styles.title, { color: "rgba(255,255,255,1)" }]}
|
||||
>
|
||||
{item.novelName}
|
||||
</Text>
|
||||
</LinearGradient>
|
||||
</View>
|
||||
);
|
||||
|
||||
const unreadBadge = () =>
|
||||
item.chaptersUnread && (
|
||||
<Text
|
||||
style={[
|
||||
styles.unreadBadge,
|
||||
!item.chaptersDownloaded && {
|
||||
borderTopLeftRadius: 4,
|
||||
borderBottomLeftRadius: 4,
|
||||
},
|
||||
]}
|
||||
>
|
||||
{item.chaptersUnread}
|
||||
</Text>
|
||||
);
|
||||
|
||||
const downloadBadge = () =>
|
||||
item.chaptersDownloaded && (
|
||||
<Text
|
||||
style={[
|
||||
styles.downloadBadge,
|
||||
!item.chaptersUnread && {
|
||||
borderTopRightRadius: 4,
|
||||
borderBottomRightRadius: 4,
|
||||
},
|
||||
]}
|
||||
>
|
||||
{item.chaptersDownloaded}
|
||||
</Text>
|
||||
);
|
||||
|
||||
return displayMode !== 2 ? (
|
||||
<View style={{ flex: 1 / itemsPerRow }}>
|
||||
<TouchableRipple
|
||||
borderless
|
||||
centered
|
||||
rippleColor={theme.rippleColor}
|
||||
style={styles.opac}
|
||||
onPress={onPress}
|
||||
>
|
||||
<>
|
||||
<ImageBackground
|
||||
source={{ uri: item.novelCover }}
|
||||
style={{ height: height[itemsPerRow] }}
|
||||
imageStyle={[
|
||||
{ borderRadius: 4 },
|
||||
libraryStatus && { opacity: 0.5 },
|
||||
]}
|
||||
progressiveRenderingEnabled={true}
|
||||
>
|
||||
<View style={{ flexDirection: "row", margin: 4 }}>
|
||||
{downloadBadge()}
|
||||
{unreadBadge()}
|
||||
</View>
|
||||
{compactTitle()}
|
||||
</ImageBackground>
|
||||
{comfortableTitle()}
|
||||
</>
|
||||
</TouchableRipple>
|
||||
</View>
|
||||
) : (
|
||||
<ListView
|
||||
item={item}
|
||||
downloadBadge={downloadBadge()}
|
||||
unreadBadge={unreadBadge()}
|
||||
theme={theme}
|
||||
onPress={onPress}
|
||||
/>
|
||||
);
|
||||
};
|
||||
|
||||
export default NovelCover;
|
||||
|
||||
const styles = StyleSheet.create({
|
||||
titleContainer: {
|
||||
flex: 1,
|
||||
justifyContent: "flex-end",
|
||||
borderRadius: 4,
|
||||
},
|
||||
title: {
|
||||
fontFamily: "pt-sans-bold",
|
||||
fontSize: 14,
|
||||
padding: 8,
|
||||
},
|
||||
linearGradient: {
|
||||
bottom: -1,
|
||||
borderRadius: 4,
|
||||
},
|
||||
opac: {
|
||||
paddingHorizontal: 4.5,
|
||||
paddingVertical: 4,
|
||||
borderRadius: 4,
|
||||
},
|
||||
extensionIcon: {
|
||||
width: 42,
|
||||
height: 42,
|
||||
borderRadius: 4,
|
||||
},
|
||||
listView: {
|
||||
flex: 1,
|
||||
paddingVertical: 8,
|
||||
paddingHorizontal: 12,
|
||||
flexDirection: "row",
|
||||
alignItems: "center",
|
||||
borderRadius: 4,
|
||||
},
|
||||
|
||||
downloadBadge: {
|
||||
backgroundColor: "#47a84a",
|
||||
color: "#FFFFFF",
|
||||
borderTopLeftRadius: 4,
|
||||
borderBottomLeftRadius: 4,
|
||||
paddingTop: 2,
|
||||
paddingHorizontal: 4,
|
||||
fontSize: 12,
|
||||
},
|
||||
unreadBadge: {
|
||||
backgroundColor: "#2979FF",
|
||||
color: "#FFFFFF",
|
||||
borderTopRightRadius: 4,
|
||||
borderBottomRightRadius: 4,
|
||||
paddingTop: 2,
|
||||
paddingHorizontal: 4,
|
||||
fontSize: 12,
|
||||
},
|
||||
});
|
||||
@@ -0,0 +1,42 @@
|
||||
import React from "react";
|
||||
import { RefreshControl, StyleSheet, FlatList } from "react-native";
|
||||
import { useSettings } from "../Hooks/reduxHooks";
|
||||
|
||||
const NovelList = ({
|
||||
data,
|
||||
renderItem,
|
||||
refreshControl,
|
||||
ListEmptyComponent,
|
||||
}) => {
|
||||
const { displayMode, itemsPerRow } = useSettings();
|
||||
const getItemsPerRow = () => {
|
||||
if (displayMode === 2) {
|
||||
return 1;
|
||||
} else {
|
||||
return itemsPerRow;
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<FlatList
|
||||
contentContainerStyle={styles.flatListCont}
|
||||
numColumns={getItemsPerRow()}
|
||||
key={getItemsPerRow()}
|
||||
data={data}
|
||||
keyExtractor={(item) => item.novelUrl}
|
||||
renderItem={renderItem}
|
||||
refreshControl={refreshControl}
|
||||
ListEmptyComponent={ListEmptyComponent}
|
||||
/>
|
||||
);
|
||||
};
|
||||
|
||||
export default NovelList;
|
||||
|
||||
const styles = StyleSheet.create({
|
||||
flatListCont: {
|
||||
flexGrow: 1,
|
||||
paddingVertical: 8,
|
||||
paddingHorizontal: 4,
|
||||
},
|
||||
});
|
||||
@@ -0,0 +1,36 @@
|
||||
import React from "react";
|
||||
import { StyleSheet, View, Text } from "react-native";
|
||||
import { RadioButton as MaterialRadioButton } from "react-native-paper";
|
||||
|
||||
export const RadioButtonGroup = ({ children, value, onValueChange }) => (
|
||||
<MaterialRadioButton.Group onValueChange={onValueChange} value={value}>
|
||||
{children}
|
||||
</MaterialRadioButton.Group>
|
||||
);
|
||||
|
||||
export const RadioButton = ({ value, label, theme }) => (
|
||||
<View style={styles.radioButtonContainer}>
|
||||
<MaterialRadioButton
|
||||
value={value}
|
||||
color={theme.colorAccent}
|
||||
uncheckedColor={theme.textColorSecondary}
|
||||
/>
|
||||
<Text
|
||||
style={[styles.radioButtonLabel, { color: theme.textColorPrimary }]}
|
||||
>
|
||||
{label}
|
||||
</Text>
|
||||
</View>
|
||||
);
|
||||
|
||||
const styles = StyleSheet.create({
|
||||
radioButtonContainer: {
|
||||
flexDirection: "row",
|
||||
alignItems: "center",
|
||||
paddingVertical: 8,
|
||||
},
|
||||
radioButtonLabel: {
|
||||
marginLeft: 16,
|
||||
fontSize: 16,
|
||||
},
|
||||
});
|
||||
@@ -0,0 +1,135 @@
|
||||
import React, { useRef } from "react";
|
||||
import { View, TextInput, StyleSheet } from "react-native";
|
||||
import { TouchableRipple, IconButton } from "react-native-paper";
|
||||
import Constants from "expo-constants";
|
||||
import { useSettings } from "../Hooks/reduxHooks";
|
||||
import { useDispatch } from "react-redux";
|
||||
import { setDisplayMode } from "../redux/settings/settings.actions";
|
||||
|
||||
export const Searchbar = ({
|
||||
theme,
|
||||
placeholder,
|
||||
searchText,
|
||||
left,
|
||||
onPressLeft,
|
||||
right,
|
||||
displayMenu,
|
||||
onPressRight,
|
||||
clearSearchbar,
|
||||
onChangeText,
|
||||
onSubmitEditing,
|
||||
migrate,
|
||||
onPressMigrate,
|
||||
}) => {
|
||||
const searchRef = useRef(null);
|
||||
const dispatch = useDispatch();
|
||||
const { displayMode } = useSettings();
|
||||
|
||||
const displayMenuIcon = () => {
|
||||
const icons = {
|
||||
0: "view-module",
|
||||
1: "view-list",
|
||||
2: "view-module",
|
||||
};
|
||||
|
||||
return icons[displayMode];
|
||||
};
|
||||
|
||||
const getDisplayMode = () =>
|
||||
displayMode === 0 ? 1 : displayMode === 1 ? 2 : displayMode === 2 && 0;
|
||||
|
||||
return (
|
||||
<TouchableRipple
|
||||
borderless
|
||||
onPress={() => searchRef.current.focus()}
|
||||
style={[
|
||||
styles.searchAppbarContainer,
|
||||
{ backgroundColor: theme.searchBarColor },
|
||||
]}
|
||||
rippleColor={theme.rippleColor}
|
||||
>
|
||||
<View style={styles.container}>
|
||||
<View style={{ flex: 1, flexDirection: "row" }}>
|
||||
{left && (
|
||||
<IconButton
|
||||
icon={left}
|
||||
color={theme.textColorSecondary}
|
||||
style={{ marginLeft: 0 }}
|
||||
size={23}
|
||||
onPress={onPressLeft}
|
||||
/>
|
||||
)}
|
||||
<TextInput
|
||||
ref={searchRef}
|
||||
style={{
|
||||
fontSize: 16,
|
||||
color: theme.textColorSecondary,
|
||||
}}
|
||||
placeholder={placeholder}
|
||||
placeholderTextColor={theme.textColorSecondary}
|
||||
onChangeText={onChangeText}
|
||||
onSubmitEditing={onSubmitEditing}
|
||||
defaultValue={searchText}
|
||||
/>
|
||||
</View>
|
||||
{searchText !== "" && (
|
||||
<IconButton
|
||||
icon="close"
|
||||
color={theme.textColorSecondary}
|
||||
style={{ marginRight: 0 }}
|
||||
size={23}
|
||||
onPress={clearSearchbar}
|
||||
/>
|
||||
)}
|
||||
{displayMenu && (
|
||||
<IconButton
|
||||
icon={displayMenuIcon()}
|
||||
color={theme.textColorSecondary}
|
||||
style={{ marginRight: 0 }}
|
||||
size={23}
|
||||
onPress={() =>
|
||||
dispatch(setDisplayMode(getDisplayMode()))
|
||||
}
|
||||
/>
|
||||
)}
|
||||
{right && (
|
||||
<IconButton
|
||||
icon={right}
|
||||
color={theme.textColorSecondary}
|
||||
style={{ marginRight: 0 }}
|
||||
size={23}
|
||||
onPress={onPressRight}
|
||||
/>
|
||||
)}
|
||||
{migrate && (
|
||||
<IconButton
|
||||
icon={migrate}
|
||||
color={theme.textColorSecondary}
|
||||
style={{ marginRight: 0 }}
|
||||
size={23}
|
||||
onPress={onPressMigrate}
|
||||
/>
|
||||
)}
|
||||
</View>
|
||||
</TouchableRipple>
|
||||
);
|
||||
};
|
||||
|
||||
const styles = StyleSheet.create({
|
||||
searchAppbarContainer: {
|
||||
marginTop: Constants.statusBarHeight + 4,
|
||||
height: 48,
|
||||
flexDirection: "row",
|
||||
alignItems: "center",
|
||||
paddingHorizontal: 16,
|
||||
marginBottom: 12,
|
||||
borderRadius: 8,
|
||||
marginHorizontal: 12,
|
||||
elevation: 2,
|
||||
},
|
||||
container: {
|
||||
flex: 1,
|
||||
flexDirection: "row",
|
||||
justifyContent: "space-between",
|
||||
},
|
||||
});
|
||||
@@ -0,0 +1,8 @@
|
||||
import React from "react";
|
||||
import { View, Text as RNText, Image, StyleSheet } from "react-native";
|
||||
|
||||
const Text = () => {};
|
||||
|
||||
export default UpdateCard;
|
||||
|
||||
const styles = StyleSheet.create({});
|
||||
@@ -35,7 +35,9 @@ export const insertChapters = async (novelId, chapters) => {
|
||||
};
|
||||
|
||||
const getChaptersQuery = (sort, filter) =>
|
||||
`SELECT * FROM chapters WHERE novelId = ? ${filter ?? ""} ${sort ?? ""}`;
|
||||
`SELECT * FROM chapters WHERE novelId = ? ${filter || ""} ${
|
||||
sort || "ORDER BY chapterId ASC"
|
||||
}`;
|
||||
|
||||
export const getChapters = (novelId, sort, filter) => {
|
||||
return new Promise((resolve, reject) =>
|
||||
@@ -82,6 +84,19 @@ export const markChapterRead = async (chapterId) => {
|
||||
});
|
||||
};
|
||||
|
||||
const markChapterUnreadQuery = `UPDATE chapters SET \`read\` = 0 WHERE chapterId = ?`;
|
||||
|
||||
export const markChapterUnread = async (chapterId) => {
|
||||
db.transaction((tx) => {
|
||||
tx.executeSql(
|
||||
markChapterUnreadQuery,
|
||||
[chapterId],
|
||||
(tx, res) => {},
|
||||
(tx, error) => console.log(error)
|
||||
);
|
||||
});
|
||||
};
|
||||
|
||||
const isChapterDownloadedQuery = `SELECT * FROM downloads WHERE downloadChapterId=?`;
|
||||
|
||||
export const isChapterDownloaded = async (chapterId) => {
|
||||
@@ -106,14 +121,12 @@ export const isChapterDownloaded = async (chapterId) => {
|
||||
const downloadChapterQuery = `INSERT INTO downloads (downloadChapterId, chapterName, chapterText, prevChapter, nextChapter) VALUES (?, ?, ?, ?, ?)`;
|
||||
|
||||
export const downloadChapter = async (
|
||||
extensionId,
|
||||
sourceId,
|
||||
novelUrl,
|
||||
chapterUrl,
|
||||
chapterId
|
||||
) => {
|
||||
const downloadUrl = `https://lnreader-extensions.herokuapp.com/api/${extensionId}/novel/${novelUrl}${chapterUrl}`;
|
||||
|
||||
// console.log(downloadUrl);
|
||||
const downloadUrl = `https://lnreader-extensions.vercel.app/api/${sourceId}/novel/${novelUrl}${chapterUrl}`;
|
||||
|
||||
const response = await fetch(downloadUrl);
|
||||
const chapter = await response.json();
|
||||
@@ -159,26 +172,6 @@ export const deleteChapter = async (chapterId) => {
|
||||
});
|
||||
};
|
||||
|
||||
// export const deleteAllChapters = async (novelId) => {
|
||||
// const updateIsDownloadedQuery = `UPDATE chapters SET downloaded = 0 WHERE novelId=?`;
|
||||
// const deleteChapterQuery = `DELETE FROM downloads WHERE downloadChapterId=?`;
|
||||
|
||||
// db.transaction((tx) => {
|
||||
// tx.executeSql(
|
||||
// updateIsDownloadedQuery,
|
||||
// [chapterId],
|
||||
// (tx, res) => console.log(`Chaptermarked not downapdeod deleted`),
|
||||
// (txObj, error) => console.log("Error ", error)
|
||||
// );
|
||||
// tx.executeSql(
|
||||
// deleteChapterQuery,
|
||||
// [chapterId],
|
||||
// (tx, res) => console.log(`Chapter deleted`),
|
||||
// (txObj, error) => console.log("Error ", error)
|
||||
// );
|
||||
// });
|
||||
// };
|
||||
|
||||
const getLastReadChapterQuery = `
|
||||
SELECT chapters.*
|
||||
FROM history
|
||||
@@ -199,3 +192,42 @@ export const getLastReadChapter = async (novelId) => {
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
const bookmarkChapterQuery = `UPDATE chapters SET bookmark = ? WHERE chapterId = ?`;
|
||||
|
||||
export const bookmarkChapter = async (bookmark, chapterId) => {
|
||||
db.transaction((tx) => {
|
||||
tx.executeSql(
|
||||
bookmarkChapterQuery,
|
||||
[!bookmark, chapterId],
|
||||
(tx, res) => {},
|
||||
(txObj, error) => console.log("Error ", error)
|
||||
);
|
||||
});
|
||||
};
|
||||
|
||||
const markPreviuschaptersReadQuery = `UPDATE chapters SET \`read\` = 1 WHERE chapterId < ? AND novelId = ?`;
|
||||
|
||||
export const markPreviuschaptersRead = async (chapterId, novelId) => {
|
||||
db.transaction((tx) => {
|
||||
tx.executeSql(
|
||||
markPreviuschaptersReadQuery,
|
||||
[chapterId, novelId],
|
||||
(tx, res) => {},
|
||||
(tx, error) => console.log(error)
|
||||
);
|
||||
});
|
||||
};
|
||||
|
||||
const markPreviousChaptersUnreadQuery = `UPDATE chapters SET \`read\` = 0 WHERE chapterId < ? AND novelId = ?`;
|
||||
|
||||
export const markPreviousChaptersUnread = async (chapterId, novelId) => {
|
||||
db.transaction((tx) => {
|
||||
tx.executeSql(
|
||||
markPreviousChaptersUnreadQuery,
|
||||
[chapterId, novelId],
|
||||
(tx, res) => {},
|
||||
(tx, error) => console.log(error)
|
||||
);
|
||||
});
|
||||
};
|
||||
@@ -1,7 +1,7 @@
|
||||
import * as SQLite from "expo-sqlite";
|
||||
const db = SQLite.openDatabase("lnreader.db");
|
||||
|
||||
const getLibraryQuery = `
|
||||
const getLibraryQuery = (sort, filter) => `
|
||||
SELECT novels.*, C.chaptersUnread, D.chaptersDownloaded
|
||||
FROM novels
|
||||
LEFT JOIN (
|
||||
@@ -18,15 +18,15 @@ const getLibraryQuery = `
|
||||
GROUP BY chapters.novelId
|
||||
) AS D
|
||||
ON novels.novelId = D.novelId
|
||||
WHERE novels.followed = 1
|
||||
GROUP BY novels.novelId
|
||||
WHERE novels.followed = 1 ${filter ? "AND " + filter : ""}
|
||||
${sort ? "ORDER BY " + sort : ""}
|
||||
`;
|
||||
|
||||
export const getLibrary = () => {
|
||||
export const getLibrary = (sort, filter) => {
|
||||
return new Promise((resolve, reject) =>
|
||||
db.transaction((tx) => {
|
||||
tx.executeSql(
|
||||
getLibraryQuery,
|
||||
getLibraryQuery(sort, filter),
|
||||
null,
|
||||
(txObj, { rows: { _array } }) => {
|
||||
// console.log(_array);
|
||||
@@ -0,0 +1,159 @@
|
||||
import * as SQLite from "expo-sqlite";
|
||||
const db = SQLite.openDatabase("lnreader.db");
|
||||
|
||||
import { fetchChapters, fetchNovel } from "../../Services/Source/source";
|
||||
import { insertChapters } from "./ChapterQueries";
|
||||
|
||||
const insertNovelQuery = `INSERT INTO novels (novelUrl, sourceUrl, sourceId, source, novelName, novelCover, novelSummary, author, artist, status, genre) VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`;
|
||||
|
||||
export const insertNovel = async (novel) => {
|
||||
return new Promise((resolve, reject) =>
|
||||
db.transaction((tx) =>
|
||||
tx.executeSql(
|
||||
insertNovelQuery,
|
||||
[
|
||||
novel.novelUrl,
|
||||
novel.sourceUrl,
|
||||
novel.sourceId,
|
||||
novel.source,
|
||||
novel.novelName,
|
||||
novel.novelCover,
|
||||
novel.novelSummary,
|
||||
novel.author,
|
||||
novel.artist,
|
||||
novel.status,
|
||||
novel.genre,
|
||||
],
|
||||
(txObj, { insertId }) => resolve(insertId),
|
||||
(txObj, error) => console.log("Error ", error)
|
||||
)
|
||||
)
|
||||
);
|
||||
};
|
||||
|
||||
export const followNovel = async (followed, novelId) => {
|
||||
db.transaction((tx) => {
|
||||
tx.executeSql(
|
||||
"UPDATE novels SET followed = ? WHERE novelId = ?",
|
||||
[!followed, novelId],
|
||||
(tx, res) => {},
|
||||
(txObj, error) => console.log("Error ", error)
|
||||
);
|
||||
});
|
||||
};
|
||||
|
||||
const checkNovelInCacheQuery = `SELECT * FROM novels WHERE novelUrl=? LIMIT 1`;
|
||||
|
||||
export const checkNovelInCache = (novelUrl) => {
|
||||
return new Promise((resolve, reject) =>
|
||||
db.transaction((tx) => {
|
||||
tx.executeSql(
|
||||
checkNovelInCacheQuery,
|
||||
[novelUrl],
|
||||
(txObj, res) => {
|
||||
if (res.rows.length !== 0) {
|
||||
resolve(true);
|
||||
} else {
|
||||
resolve(false);
|
||||
}
|
||||
},
|
||||
(txObj, error) => console.log("Error ", error)
|
||||
);
|
||||
})
|
||||
);
|
||||
};
|
||||
|
||||
export const getNovel = async (sourceId, novelUrl) => {
|
||||
return new Promise((resolve, reject) =>
|
||||
db.transaction((tx) => {
|
||||
tx.executeSql(
|
||||
`SELECT * FROM novels WHERE novelUrl = ? AND sourceId = ?`,
|
||||
[novelUrl, sourceId],
|
||||
(txObj, { rows }) => resolve(rows.item(0)),
|
||||
(txObj, error) => console.log("Error ", error)
|
||||
);
|
||||
})
|
||||
);
|
||||
};
|
||||
|
||||
export const deleteNovelCache = () => {
|
||||
db.transaction((tx) => {
|
||||
tx.executeSql(
|
||||
"DELETE FROM novels WHERE followed = 0",
|
||||
null,
|
||||
(txObj, res) => {
|
||||
console.log("Cleared Novel Cache");
|
||||
},
|
||||
(txObj, error) => console.log("Error ", error)
|
||||
);
|
||||
});
|
||||
};
|
||||
|
||||
const restoreFromBackupQuery = `INSERT INTO novels (novelUrl, sourceUrl, sourceId, source, novelName, novelCover, novelSummary, author, artist, status, genre, followed, unread) VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`;
|
||||
|
||||
export const restoreLibrary = async (novel) => {
|
||||
return new Promise((resolve, reject) =>
|
||||
db.transaction((tx) =>
|
||||
tx.executeSql(
|
||||
restoreFromBackupQuery,
|
||||
[
|
||||
novel.novelUrl,
|
||||
novel.sourceUrl,
|
||||
novel.sourceId,
|
||||
novel.source,
|
||||
novel.novelName,
|
||||
novel.novelCover,
|
||||
novel.novelSummary,
|
||||
novel.author,
|
||||
novel.artist,
|
||||
novel.status,
|
||||
novel.genre,
|
||||
novel.followed,
|
||||
novel.unread,
|
||||
],
|
||||
async (txObj, { insertId }) => {
|
||||
const chapters = await fetchChapters(
|
||||
novel.sourceId,
|
||||
novel.novelUrl
|
||||
);
|
||||
await insertChapters(insertId, chapters);
|
||||
},
|
||||
(txObj, error) => console.log("Error ", error)
|
||||
)
|
||||
)
|
||||
);
|
||||
};
|
||||
|
||||
const migrateNovelQuery = `INSERT INTO novels (novelUrl, sourceUrl, sourceId, source, novelName, novelCover, novelSummary, author, artist, status, genre, followed) VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`;
|
||||
|
||||
export const migrateNovel = async (sourceId, novelUrl) => {
|
||||
const novel = await fetchNovel(sourceId, novelUrl);
|
||||
|
||||
db.transaction((tx) =>
|
||||
tx.executeSql(
|
||||
migrateNovelQuery,
|
||||
[
|
||||
novel.novelUrl,
|
||||
novel.sourceUrl,
|
||||
novel.sourceId,
|
||||
novel.source,
|
||||
novel.novelName,
|
||||
novel.novelCover,
|
||||
novel.novelSummary,
|
||||
novel.author,
|
||||
novel.artist,
|
||||
novel.status,
|
||||
novel.genre,
|
||||
1,
|
||||
],
|
||||
async (txObj, { insertId }) => {
|
||||
const chapters = await fetchChapters(
|
||||
novel.sourceId,
|
||||
novel.novelUrl
|
||||
);
|
||||
await insertChapters(insertId, chapters);
|
||||
},
|
||||
(txObj, error) => console.log("Error ", error)
|
||||
)
|
||||
);
|
||||
};
|
||||
@@ -1,7 +1,7 @@
|
||||
import * as SQLite from "expo-sqlite";
|
||||
const db = SQLite.openDatabase("lnreader.db");
|
||||
|
||||
const getHistoryQuery = `
|
||||
const getUpdatesQuery = `
|
||||
SELECT chapters.chapterId, chapters.chapterUrl, chapters.chapterName, novels.novelUrl, novels.novelId, novels.novelCover, novels.novelName, novels.sourceId, updates.updateTime, updates.updateId
|
||||
FROM updates
|
||||
JOIN chapters
|
||||
@@ -14,7 +14,7 @@ export const getUpdates = async () => {
|
||||
return new Promise((resolve, reject) => {
|
||||
db.transaction((tx) => {
|
||||
tx.executeSql(
|
||||
getHistoryQuery,
|
||||
getUpdatesQuery,
|
||||
null,
|
||||
(txObj, { rows: { _array } }) => {
|
||||
resolve(_array);
|
||||
@@ -24,3 +24,14 @@ export const getUpdates = async () => {
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
export const deleteNovelUpdates = (novelId) => {
|
||||
db.transaction((tx) => {
|
||||
tx.executeSql(
|
||||
"DELETE FROM updates WHERE novelId = ?",
|
||||
[novelId],
|
||||
(txObj, res) => {},
|
||||
(txObj, error) => console.log("Error ", error)
|
||||
);
|
||||
});
|
||||
};
|
||||
@@ -0,0 +1,46 @@
|
||||
import { useState, useEffect } from "react";
|
||||
|
||||
export const githubUpdateChecker = () => {
|
||||
const latestReleaseUrl =
|
||||
"https://api.github.com/repos/rajarsheechatterjee/lnreader/releases/latest";
|
||||
|
||||
const [checking, setChecking] = useState(true);
|
||||
const [latestRelease, setLatestRelease] = useState();
|
||||
|
||||
const checkForRelease = async () => {
|
||||
let res = await fetch(latestReleaseUrl);
|
||||
res = await res.json();
|
||||
|
||||
const release = {
|
||||
tag_name: res.tag_name,
|
||||
body: res.body,
|
||||
downloadUrl: res.assets[0].browser_download_url,
|
||||
};
|
||||
|
||||
setLatestRelease(release);
|
||||
setChecking(false);
|
||||
};
|
||||
|
||||
const isNewVersion = (versionTag) => {
|
||||
let currentVersion = "v1.0.17";
|
||||
const regex = /[^\\d.]/;
|
||||
|
||||
let newVersion = versionTag.replace(regex, "");
|
||||
currentVersion = currentVersion.replace(regex, "");
|
||||
|
||||
return newVersion !== currentVersion;
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
checkForRelease();
|
||||
}, []);
|
||||
|
||||
if (!checking) {
|
||||
const data = {
|
||||
latestRelease,
|
||||
isNewVersion: isNewVersion(latestRelease.tag_name),
|
||||
};
|
||||
|
||||
return data;
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,116 @@
|
||||
import { shallowEqual, useSelector } from "react-redux";
|
||||
|
||||
const useTheme = () => {
|
||||
const theme = useSelector((state) => state.settingsReducer.theme);
|
||||
|
||||
return theme;
|
||||
};
|
||||
|
||||
const useReaderSettings = () => {
|
||||
const readerSettings = useSelector((state) => state.settingsReducer.reader);
|
||||
|
||||
return readerSettings;
|
||||
};
|
||||
|
||||
const useSettings = () => {
|
||||
const { displayMode, itemsPerRow } = useSelector(
|
||||
(state) => state.settingsReducer
|
||||
);
|
||||
|
||||
return { displayMode, itemsPerRow };
|
||||
};
|
||||
|
||||
const useLibrary = () => {
|
||||
const library = useSelector((state) => state.libraryReducer.novels);
|
||||
|
||||
return library;
|
||||
};
|
||||
|
||||
const useNovel = () => {
|
||||
const novel = useSelector((state) => state.novelReducer);
|
||||
|
||||
return novel;
|
||||
};
|
||||
|
||||
const useChapter = () => {
|
||||
const chapter = useSelector((state) => state.chapterReducer);
|
||||
|
||||
return chapter;
|
||||
};
|
||||
|
||||
const findNovel = (novelId) => {
|
||||
let novel = useSelector((state) => state.preferenceReducer.novelSettings);
|
||||
novel = novel[novelId];
|
||||
|
||||
return novel;
|
||||
};
|
||||
|
||||
const usePreferences = (novelId) => {
|
||||
let sort, filter, position;
|
||||
|
||||
const novel = findNovel(novelId);
|
||||
|
||||
if (novel) {
|
||||
sort = novel.sort;
|
||||
filter = novel.filter;
|
||||
position = novel.position;
|
||||
}
|
||||
|
||||
return { sort, filter, position };
|
||||
};
|
||||
|
||||
const useSavedSettings = () => {
|
||||
const settings = useSelector(
|
||||
(state) => state.preferenceReducer.novelSettings
|
||||
);
|
||||
|
||||
return settings;
|
||||
};
|
||||
|
||||
const useContinueReading = (chapters, novelId) => {
|
||||
let lastReadChapter, chapterId, novel, position;
|
||||
|
||||
novel = findNovel(novelId);
|
||||
if (novel) {
|
||||
chapterId = novel.lastRead;
|
||||
position = novel.position;
|
||||
}
|
||||
|
||||
if (chapterId) {
|
||||
lastReadChapter = chapters.find(
|
||||
(obj) => obj.chapterId === chapterId && obj.read === 0
|
||||
);
|
||||
}
|
||||
|
||||
if (!lastReadChapter) {
|
||||
lastReadChapter = chapters.find((obj) => obj.read === 0);
|
||||
}
|
||||
|
||||
return { lastReadChapter, position };
|
||||
};
|
||||
|
||||
const useTrackingStatus = () => {
|
||||
const tracker = useSelector((state) => state.trackerReducer);
|
||||
|
||||
return tracker;
|
||||
};
|
||||
|
||||
const useLibraryFilters = () => {
|
||||
const filters = useSelector((state) => state.libraryReducer.filters);
|
||||
|
||||
return filters;
|
||||
};
|
||||
|
||||
export {
|
||||
useTheme,
|
||||
useReaderSettings,
|
||||
useLibrary,
|
||||
useSettings,
|
||||
usePreferences,
|
||||
useContinueReading,
|
||||
useTrackingStatus,
|
||||
useNovel,
|
||||
useChapter,
|
||||
useSavedSettings,
|
||||
useLibraryFilters,
|
||||
};
|
||||
@@ -0,0 +1,7 @@
|
||||
import { setStatusBarStyle as setExpoStatusBarStyle } from "expo-status-bar";
|
||||
import { useTheme } from "../Hooks/reduxHooks";
|
||||
|
||||
export const setStatusBarStyle = () => {
|
||||
const theme = useTheme();
|
||||
setExpoStatusBarStyle(theme.id === 1 ? "dark" : "light");
|
||||
};
|
||||
@@ -0,0 +1,5 @@
|
||||
import { ToastAndroid } from "react-native";
|
||||
|
||||
export const showToast = (message) => {
|
||||
ToastAndroid.show(message, ToastAndroid.SHORT);
|
||||
};
|
||||
@@ -0,0 +1,92 @@
|
||||
import React from "react";
|
||||
import { createMaterialBottomTabNavigator } from "@react-navigation/material-bottom-tabs";
|
||||
import MaterialCommunityIcons from "react-native-vector-icons/MaterialCommunityIcons";
|
||||
import { useTheme } from "../Hooks/reduxHooks";
|
||||
|
||||
import Library from "../Screens/Library/Library";
|
||||
import Updates from "../Screens/Updates/Updates";
|
||||
import History from "../Screens/History/History";
|
||||
import Browse from "../Screens/Browse/Browse";
|
||||
import More from "../Screens/More/More";
|
||||
|
||||
const Tab = createMaterialBottomTabNavigator();
|
||||
|
||||
const BottomNavigator = () => {
|
||||
const theme = useTheme();
|
||||
|
||||
return (
|
||||
<Tab.Navigator
|
||||
// shifting={false}
|
||||
barStyle={{ backgroundColor: theme.colorPrimary }}
|
||||
activeColor={theme.colorAccent}
|
||||
>
|
||||
<Tab.Screen
|
||||
name="Library"
|
||||
component={Library}
|
||||
options={{
|
||||
tabBarIcon: ({ color }) => (
|
||||
<MaterialCommunityIcons
|
||||
name="book-variant-multiple"
|
||||
color={color}
|
||||
size={24}
|
||||
/>
|
||||
),
|
||||
}}
|
||||
/>
|
||||
<Tab.Screen
|
||||
name="Updates"
|
||||
component={Updates}
|
||||
options={{
|
||||
tabBarIcon: ({ color }) => (
|
||||
<MaterialCommunityIcons
|
||||
name="alert-decagram-outline"
|
||||
color={color}
|
||||
size={24}
|
||||
/>
|
||||
),
|
||||
}}
|
||||
/>
|
||||
<Tab.Screen
|
||||
name="History"
|
||||
component={History}
|
||||
options={{
|
||||
tabBarIcon: ({ color }) => (
|
||||
<MaterialCommunityIcons
|
||||
name="history"
|
||||
color={color}
|
||||
size={24}
|
||||
/>
|
||||
),
|
||||
}}
|
||||
/>
|
||||
<Tab.Screen
|
||||
name="Browse"
|
||||
component={Browse}
|
||||
options={{
|
||||
tabBarIcon: ({ color }) => (
|
||||
<MaterialCommunityIcons
|
||||
name="compass-outline"
|
||||
color={color}
|
||||
size={24}
|
||||
/>
|
||||
),
|
||||
}}
|
||||
/>
|
||||
<Tab.Screen
|
||||
name="More"
|
||||
component={More}
|
||||
options={{
|
||||
tabBarIcon: ({ color }) => (
|
||||
<MaterialCommunityIcons
|
||||
name="dots-horizontal"
|
||||
color={color}
|
||||
size={24}
|
||||
/>
|
||||
),
|
||||
}}
|
||||
/>
|
||||
</Tab.Navigator>
|
||||
);
|
||||
};
|
||||
|
||||
export default BottomNavigator;
|
||||
@@ -0,0 +1,81 @@
|
||||
import React from "react";
|
||||
import {
|
||||
createStackNavigator,
|
||||
TransitionPresets,
|
||||
} from "@react-navigation/stack";
|
||||
|
||||
import BottomNavigator from "./BottomNavigator";
|
||||
import Novel from "../Screens/Novel/Novel";
|
||||
import Chapter from "../Screens/Chapter/Chapter";
|
||||
import Extension from "../Screens/Extension/Extension";
|
||||
import GlobalSearch from "../Screens/Browse/GlobalSearch";
|
||||
import Migration from "../Screens/Browse/Migration";
|
||||
import SourceNovels from "../Screens/Browse/SourceNovels";
|
||||
import MigrateNovel from "../Screens/Browse/MigrateNovel";
|
||||
import MoreStack from "./More";
|
||||
|
||||
import { setStatusBarStyle } from "../Hooks/setStatusBarStyle";
|
||||
import { View } from "react-native";
|
||||
import { useTheme } from "../Hooks/reduxHooks";
|
||||
import { githubUpdateChecker } from "../Hooks/githubUpdateChecker";
|
||||
import NewUpdateDialog from "../Components/NewUpdateDialog";
|
||||
import { NavigationContainer } from "@react-navigation/native";
|
||||
|
||||
const Stack = createStackNavigator();
|
||||
|
||||
const stackNavigatorConfig = {
|
||||
headerShown: false,
|
||||
};
|
||||
|
||||
const MainNavigator = () => {
|
||||
const theme = useTheme();
|
||||
setStatusBarStyle();
|
||||
const { isNewVersion, latestRelease } = githubUpdateChecker() || {};
|
||||
|
||||
return (
|
||||
<NavigationContainer>
|
||||
<View style={{ flex: 1, backgroundColor: theme.colorPrimary }}>
|
||||
{isNewVersion && <NewUpdateDialog newVersion={latestRelease} />}
|
||||
<Stack.Navigator screenOptions={stackNavigatorConfig}>
|
||||
<Stack.Screen
|
||||
name="BottomNavigator"
|
||||
component={BottomNavigator}
|
||||
/>
|
||||
<Stack.Screen
|
||||
name="Novel"
|
||||
component={Novel}
|
||||
options={{
|
||||
headerTitle: "",
|
||||
headerShown: true,
|
||||
headerTransparent: true,
|
||||
headerTintColor: "white",
|
||||
...TransitionPresets.RevealFromBottomAndroid,
|
||||
}}
|
||||
/>
|
||||
<Stack.Screen
|
||||
name="Chapter"
|
||||
component={Chapter}
|
||||
options={{ ...TransitionPresets.SlideFromRightIOS }}
|
||||
/>
|
||||
<Stack.Screen name="MoreStack" component={MoreStack} />
|
||||
<Stack.Screen name="Extension" component={Extension} />
|
||||
<Stack.Screen
|
||||
name="GlobalSearch"
|
||||
component={GlobalSearch}
|
||||
/>
|
||||
<Stack.Screen name="Migration" component={Migration} />
|
||||
<Stack.Screen
|
||||
name="SourceNovels"
|
||||
component={SourceNovels}
|
||||
/>
|
||||
<Stack.Screen
|
||||
name="MigrateNovel"
|
||||
component={MigrateNovel}
|
||||
/>
|
||||
</Stack.Navigator>
|
||||
</View>
|
||||
</NavigationContainer>
|
||||
);
|
||||
};
|
||||
|
||||
export default MainNavigator;
|
||||
@@ -0,0 +1,28 @@
|
||||
import React from "react";
|
||||
import { createStackNavigator } from "@react-navigation/stack";
|
||||
|
||||
import About from "../Screens/More/About";
|
||||
import Settings from "../Screens/More/Settings";
|
||||
import Trackers from "../Screens/More/Trackers";
|
||||
import { View } from "react-native";
|
||||
import { useTheme } from "../Hooks/reduxHooks";
|
||||
|
||||
const Stack = createStackNavigator();
|
||||
|
||||
const stackNavigatorConfig = { headerShown: false };
|
||||
|
||||
const MoreStack = () => {
|
||||
const theme = useTheme();
|
||||
|
||||
return (
|
||||
<View style={{ flex: 1, backgroundColor: theme.colorPrimary }}>
|
||||
<Stack.Navigator screenOptions={stackNavigatorConfig}>
|
||||
<Stack.Screen name="Settings" component={Settings} />
|
||||
<Stack.Screen name="Trackers" component={Trackers} />
|
||||
<Stack.Screen name="About" component={About} />
|
||||
</Stack.Navigator>
|
||||
</View>
|
||||
);
|
||||
};
|
||||
|
||||
export default MoreStack;
|
||||
@@ -0,0 +1,157 @@
|
||||
import React, { useEffect, useState } from "react";
|
||||
import {
|
||||
StyleSheet,
|
||||
View,
|
||||
ScrollView,
|
||||
Text,
|
||||
FlatList,
|
||||
ActivityIndicator,
|
||||
RefreshControl,
|
||||
} from "react-native";
|
||||
import { useTheme } from "../../Hooks/reduxHooks";
|
||||
import { useDispatch, useSelector } from "react-redux";
|
||||
|
||||
import {
|
||||
getSourcesAction,
|
||||
searchSourcesAction,
|
||||
} from "../../redux/source/source.actions";
|
||||
|
||||
import SourceCard from "./components/SourceCard";
|
||||
import { showToast } from "../../Hooks/showToast";
|
||||
import { Searchbar } from "../../Components/Searchbar";
|
||||
|
||||
const Browse = ({ navigation }) => {
|
||||
const [refreshing, setRefreshing] = useState(false);
|
||||
const [searchText, setSearchText] = useState("");
|
||||
// const [globalSearch, setGlobalSearch] = useState(false);
|
||||
// const [searchResult, setSearchResults] = useState();
|
||||
const { sources, search, loading, pinned } = useSelector(
|
||||
(state) => state.sourceReducer
|
||||
);
|
||||
const theme = useTheme();
|
||||
const dispatch = useDispatch();
|
||||
|
||||
const isPinned = (sourceId) =>
|
||||
pinned.indexOf(sourceId) === -1 ? false : true;
|
||||
|
||||
useEffect(() => {
|
||||
dispatch(getSourcesAction());
|
||||
}, [getSourcesAction]);
|
||||
|
||||
const onRefresh = () => {
|
||||
showToast("Updating extension list");
|
||||
setRefreshing(true);
|
||||
getSourcesAction();
|
||||
setRefreshing(false);
|
||||
};
|
||||
|
||||
const clearSearchbar = () => {
|
||||
setSearchText("");
|
||||
};
|
||||
|
||||
const onChangeText = (text) => {
|
||||
setSearchText(text);
|
||||
dispatch(searchSourcesAction(text));
|
||||
};
|
||||
|
||||
// const onSubmitEditing = () => {};
|
||||
|
||||
const renderItem = ({ item }) => (
|
||||
<SourceCard
|
||||
item={item}
|
||||
isPinned={isPinned(item.sourceId)}
|
||||
theme={theme}
|
||||
/>
|
||||
);
|
||||
|
||||
return (
|
||||
<View
|
||||
style={[
|
||||
styles.container,
|
||||
{ backgroundColor: theme.colorPrimaryDark },
|
||||
]}
|
||||
>
|
||||
<Searchbar
|
||||
theme={theme}
|
||||
placeholder="Search Source"
|
||||
left="magnify"
|
||||
onPressLeft={clearSearchbar}
|
||||
searchText={searchText}
|
||||
onChangeText={onChangeText}
|
||||
clearSearchbar={clearSearchbar}
|
||||
right="book-search"
|
||||
onPressRight={() => navigation.navigate("GlobalSearch")}
|
||||
migrate="weather-cloudy-arrow-right"
|
||||
onPressMigrate={() => navigation.navigate("Migration")}
|
||||
/>
|
||||
|
||||
<FlatList
|
||||
contentContainerStyle={{ flexGrow: 1 }}
|
||||
data={!searchText ? sources : search}
|
||||
keyExtractor={(item) => item.sourceId.toString()}
|
||||
renderItem={renderItem}
|
||||
extraData={pinned}
|
||||
ListHeaderComponent={
|
||||
<View>
|
||||
{pinned.length > 0 && (
|
||||
<FlatList
|
||||
contentContainerStyle={{ paddingBottom: 16 }}
|
||||
data={sources.filter((source) =>
|
||||
isPinned(source.sourceId)
|
||||
)}
|
||||
keyExtractor={(item) =>
|
||||
item.sourceId.toString()
|
||||
}
|
||||
renderItem={renderItem}
|
||||
extraData={pinned}
|
||||
ListHeaderComponent={
|
||||
<Text
|
||||
style={{
|
||||
color: theme.textColorSecondary,
|
||||
paddingHorizontal: 16,
|
||||
paddingVertical: 8,
|
||||
}}
|
||||
>
|
||||
Pinned
|
||||
</Text>
|
||||
}
|
||||
/>
|
||||
)}
|
||||
<Text
|
||||
style={{
|
||||
color: theme.textColorSecondary,
|
||||
paddingHorizontal: 16,
|
||||
paddingVertical: 8,
|
||||
}}
|
||||
>
|
||||
Sources
|
||||
</Text>
|
||||
</View>
|
||||
}
|
||||
ListEmptyComponent={
|
||||
loading && (
|
||||
<ActivityIndicator
|
||||
size="small"
|
||||
color={theme.colorAccent}
|
||||
style={{ marginTop: 16 }}
|
||||
/>
|
||||
)
|
||||
}
|
||||
refreshControl={
|
||||
<RefreshControl
|
||||
refreshing={refreshing}
|
||||
onRefresh={onRefresh}
|
||||
colors={["white"]}
|
||||
progressBackgroundColor={theme.colorAccent}
|
||||
/>
|
||||
}
|
||||
/>
|
||||
</View>
|
||||
);
|
||||
};
|
||||
|
||||
export default Browse;
|
||||
|
||||
const styles = StyleSheet.create({
|
||||
container: { flex: 1 },
|
||||
});
|
||||
@@ -0,0 +1,178 @@
|
||||
import React, { useEffect, useState } from "react";
|
||||
import {
|
||||
StyleSheet,
|
||||
View,
|
||||
Text,
|
||||
FlatList,
|
||||
ActivityIndicator,
|
||||
} from "react-native";
|
||||
import { useLibrary, useTheme } from "../../Hooks/reduxHooks";
|
||||
import { useDispatch, useSelector } from "react-redux";
|
||||
|
||||
import { Searchbar } from "../../Components/Searchbar";
|
||||
import NovelCover from "../../Components/NovelCover";
|
||||
import NovelList from "../../Components/NovelList";
|
||||
import EmptyView from "../../Components/EmptyView";
|
||||
import GlobalSearchNovelList from "./components/GlobalSearchNovelList";
|
||||
import { ProgressBar } from "react-native-paper";
|
||||
import { showToast } from "../../Hooks/showToast";
|
||||
|
||||
const GlobalSearch = ({ navigation }) => {
|
||||
const theme = useTheme();
|
||||
|
||||
const [loading, setLoading] = useState(false);
|
||||
const [searchText, setSearchText] = useState("");
|
||||
const [searchResults, setSearchResults] = useState("");
|
||||
const { sources, pinned } = useSelector((state) => state.sourceReducer);
|
||||
const [progress, setProgress] = useState(0);
|
||||
|
||||
const library = useLibrary();
|
||||
|
||||
const pinnedSources = sources.filter(
|
||||
(source) => pinned.indexOf(source.sourceId) !== -1
|
||||
);
|
||||
|
||||
const clearSearchbar = () => {
|
||||
setSearchText("");
|
||||
};
|
||||
|
||||
const onChangeText = (text) => setSearchText(text);
|
||||
|
||||
const onSubmitEditing = () => {
|
||||
setSearchResults("");
|
||||
|
||||
const getSearchUrl = (sourceId) => {
|
||||
if (sourceId === 1) {
|
||||
return `https://lnreader-extensions.vercel.app/api/1/search/?s=${searchText}&?o=rating`;
|
||||
} else {
|
||||
return `https://lnreader-extensions.vercel.app/api/${sourceId}/search/?s=${searchText}`;
|
||||
}
|
||||
};
|
||||
|
||||
pinnedSources.map((source, index) =>
|
||||
setTimeout(() => {
|
||||
setLoading(true);
|
||||
fetch(getSearchUrl(source.sourceId))
|
||||
.then((response) => response.json())
|
||||
.then((json) => {
|
||||
setSearchResults((searchResults) => [
|
||||
...searchResults,
|
||||
{
|
||||
sourceId: source.sourceId,
|
||||
sourceName: source.sourceName,
|
||||
sourceLanguage: source.sourceLanguage,
|
||||
novels: json,
|
||||
},
|
||||
]);
|
||||
setLoading(false);
|
||||
})
|
||||
.catch((error) => {
|
||||
showToast(error.message);
|
||||
setSearchResults((searchResults) => [
|
||||
...searchResults,
|
||||
{
|
||||
sourceId: source.sourceId,
|
||||
sourceName: source.sourceName,
|
||||
sourceLanguage: source.sourceLanguage,
|
||||
novels: [],
|
||||
},
|
||||
]);
|
||||
setLoading(false);
|
||||
})
|
||||
.finally(() =>
|
||||
setProgress(
|
||||
(progress) => progress + 1 / pinnedSources.length
|
||||
)
|
||||
);
|
||||
}, 1000 * index)
|
||||
);
|
||||
};
|
||||
|
||||
const renderItem = ({ item }) => (
|
||||
<>
|
||||
<View style={{ padding: 8, paddingVertical: 16 }}>
|
||||
<Text style={{ color: theme.textColorPrimary }}>
|
||||
{item.sourceName}
|
||||
</Text>
|
||||
<Text style={{ color: theme.textColorSecondary, fontSize: 12 }}>
|
||||
{item.sourceLanguage}
|
||||
</Text>
|
||||
</View>
|
||||
<GlobalSearchNovelList
|
||||
data={item.novels}
|
||||
theme={theme}
|
||||
library={library}
|
||||
navigation={navigation}
|
||||
/>
|
||||
</>
|
||||
);
|
||||
|
||||
return (
|
||||
<View
|
||||
style={[
|
||||
styles.container,
|
||||
{ backgroundColor: theme.colorPrimaryDark },
|
||||
]}
|
||||
>
|
||||
<Searchbar
|
||||
theme={theme}
|
||||
placeholder="Global Search"
|
||||
left="arrow-left"
|
||||
onPressLeft={() => navigation.goBack()}
|
||||
searchText={searchText}
|
||||
onChangeText={onChangeText}
|
||||
onSubmitEditing={onSubmitEditing}
|
||||
clearSearchbar={clearSearchbar}
|
||||
/>
|
||||
{progress < 1 && progress > 0 && pinned && (
|
||||
<ProgressBar color={theme.colorAccent} progress={progress} />
|
||||
)}
|
||||
<FlatList
|
||||
contentContainerStyle={{
|
||||
flexGrow: 1,
|
||||
padding: 4,
|
||||
}}
|
||||
data={searchResults}
|
||||
keyExtractor={(item) => item.sourceId.toString()}
|
||||
renderItem={renderItem}
|
||||
extraData={pinned}
|
||||
ListEmptyComponent={
|
||||
<>
|
||||
{!loading && (
|
||||
<EmptyView
|
||||
icon="__φ(..)"
|
||||
description={`Search a novel in your pinned sources ${
|
||||
pinned.length === 0
|
||||
? "(No sources pinned)"
|
||||
: ""
|
||||
}`}
|
||||
/>
|
||||
)}
|
||||
</>
|
||||
}
|
||||
ListFooterComponent={
|
||||
loading && (
|
||||
<View
|
||||
style={{
|
||||
flex: 1,
|
||||
justifyContent: "center",
|
||||
padding: 16,
|
||||
}}
|
||||
>
|
||||
<ActivityIndicator
|
||||
size="large"
|
||||
color={theme.colorAccent}
|
||||
/>
|
||||
</View>
|
||||
)
|
||||
}
|
||||
/>
|
||||
</View>
|
||||
);
|
||||
};
|
||||
|
||||
export default GlobalSearch;
|
||||
|
||||
const styles = StyleSheet.create({
|
||||
container: { flex: 1 },
|
||||
});
|
||||
@@ -0,0 +1,164 @@
|
||||
import React, { useEffect, useState } from "react";
|
||||
import {
|
||||
StyleSheet,
|
||||
View,
|
||||
Text,
|
||||
FlatList,
|
||||
ActivityIndicator,
|
||||
} from "react-native";
|
||||
import { ProgressBar } from "react-native-paper";
|
||||
import { useLibrary, useTheme } from "../../Hooks/reduxHooks";
|
||||
import { useSelector } from "react-redux";
|
||||
|
||||
import EmptyView from "../../Components/EmptyView";
|
||||
import MigrationNovelList from "./components/MigrationNovelList";
|
||||
import { Appbar } from "../../Components/Appbar";
|
||||
import { showToast } from "../../Hooks/showToast";
|
||||
|
||||
const GlobalSearch = ({ navigation, route }) => {
|
||||
const { sourceId, novelName } = route.params;
|
||||
const theme = useTheme();
|
||||
|
||||
const [progress, setProgress] = useState(0);
|
||||
const [loading, setLoading] = useState(false);
|
||||
const [searchResults, setSearchResults] = useState("");
|
||||
const { sources, pinned } = useSelector((state) => state.sourceReducer);
|
||||
|
||||
const library = useLibrary();
|
||||
|
||||
const pinnedSources = sources.filter(
|
||||
(source) =>
|
||||
pinned.indexOf(source.sourceId) !== -1 &&
|
||||
source.sourceId !== sourceId
|
||||
);
|
||||
|
||||
const getSearchResults = () => {
|
||||
const getSearchUrl = (sourceId) => {
|
||||
if (sourceId === 1) {
|
||||
return `https://lnreader-extensions.vercel.app/api/1/search/?s=${novelName}&?o=rating`;
|
||||
} else {
|
||||
return `https://lnreader-extensions.vercel.app/api/${sourceId}/search/?s=${novelName}`;
|
||||
}
|
||||
};
|
||||
|
||||
pinnedSources.map((source, index) =>
|
||||
setTimeout(() => {
|
||||
setLoading(true);
|
||||
fetch(getSearchUrl(source.sourceId))
|
||||
.then((response) => response.json())
|
||||
.then((json) => {
|
||||
setSearchResults((searchResults) => [
|
||||
...searchResults,
|
||||
{
|
||||
sourceId: source.sourceId,
|
||||
sourceName: source.sourceName,
|
||||
sourceLanguage: source.sourceLanguage,
|
||||
novels: json,
|
||||
},
|
||||
]);
|
||||
setLoading(false);
|
||||
})
|
||||
.catch((error) => {
|
||||
showToast(error.message);
|
||||
setSearchResults((searchResults) => [
|
||||
...searchResults,
|
||||
{
|
||||
sourceId: source.sourceId,
|
||||
sourceName: source.sourceName,
|
||||
sourceLanguage: source.sourceLanguage,
|
||||
novels: [],
|
||||
},
|
||||
]);
|
||||
setLoading(false);
|
||||
});
|
||||
setProgress((progress) => progress + 1 / pinnedSources.length);
|
||||
}, 1000 * index)
|
||||
);
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
getSearchResults();
|
||||
}, []);
|
||||
|
||||
const renderItem = ({ item }) => (
|
||||
<>
|
||||
<View style={{ padding: 8, paddingVertical: 16 }}>
|
||||
<Text style={{ color: theme.textColorPrimary }}>
|
||||
{item.sourceName}
|
||||
</Text>
|
||||
<Text style={{ color: theme.textColorSecondary, fontSize: 12 }}>
|
||||
{item.sourceLanguage}
|
||||
</Text>
|
||||
</View>
|
||||
<MigrationNovelList
|
||||
data={item.novels}
|
||||
theme={theme}
|
||||
library={library}
|
||||
navigation={navigation}
|
||||
/>
|
||||
</>
|
||||
);
|
||||
|
||||
return (
|
||||
<View
|
||||
style={[
|
||||
styles.container,
|
||||
{ backgroundColor: theme.colorPrimaryDark },
|
||||
]}
|
||||
>
|
||||
<Appbar
|
||||
title={novelName}
|
||||
onBackAction={() => navigation.goBack()}
|
||||
/>
|
||||
{progress < 1 && pinned && (
|
||||
<ProgressBar color={theme.colorAccent} progress={progress} />
|
||||
)}
|
||||
<FlatList
|
||||
contentContainerStyle={{
|
||||
flexGrow: 1,
|
||||
padding: 4,
|
||||
}}
|
||||
data={searchResults}
|
||||
keyExtractor={(item) => item.sourceId.toString()}
|
||||
renderItem={renderItem}
|
||||
extraData={pinned}
|
||||
ListEmptyComponent={
|
||||
<>
|
||||
{!loading && (
|
||||
<EmptyView
|
||||
icon="__φ(..)"
|
||||
description={`Search a novel in your pinned sources ${
|
||||
pinned.length === 0
|
||||
? "(No sources pinned)"
|
||||
: ""
|
||||
}`}
|
||||
/>
|
||||
)}
|
||||
</>
|
||||
}
|
||||
ListFooterComponent={
|
||||
loading && (
|
||||
<View
|
||||
style={{
|
||||
flex: 1,
|
||||
justifyContent: "center",
|
||||
padding: 16,
|
||||
}}
|
||||
>
|
||||
<ActivityIndicator
|
||||
size="large"
|
||||
color={theme.colorAccent}
|
||||
/>
|
||||
</View>
|
||||
)
|
||||
}
|
||||
/>
|
||||
</View>
|
||||
);
|
||||
};
|
||||
|
||||
export default GlobalSearch;
|
||||
|
||||
const styles = StyleSheet.create({
|
||||
container: { flex: 1 },
|
||||
});
|
||||
@@ -0,0 +1,69 @@
|
||||
import React from "react";
|
||||
import { StyleSheet, View, FlatList, Text } from "react-native";
|
||||
import { useLibrary, useTheme } from "../../Hooks/reduxHooks";
|
||||
import { useSelector } from "react-redux";
|
||||
import { Appbar } from "../../Components/Appbar";
|
||||
import MigrationSourceCard from "./components/MigrationSourceCard";
|
||||
|
||||
const GlobalSearch = ({ navigation }) => {
|
||||
const theme = useTheme();
|
||||
|
||||
const { sources } = useSelector((state) => state.sourceReducer);
|
||||
|
||||
const library = useLibrary();
|
||||
|
||||
const novelsPerSource = (sourceId) =>
|
||||
library.filter((novel) => novel.sourceId === sourceId).length;
|
||||
|
||||
const renderItem = ({ item }) => (
|
||||
<MigrationSourceCard
|
||||
item={item}
|
||||
theme={theme}
|
||||
noOfNovels={novelsPerSource(item.sourceId)}
|
||||
buttonLabel="All"
|
||||
onPress={() => navigation.navigate("SourceNovels", item.sourceId)}
|
||||
/>
|
||||
);
|
||||
|
||||
return (
|
||||
<View
|
||||
style={[
|
||||
styles.container,
|
||||
{ backgroundColor: theme.colorPrimaryDark },
|
||||
]}
|
||||
>
|
||||
<Appbar
|
||||
title="Select Source"
|
||||
onBackAction={() => navigation.goBack()}
|
||||
/>
|
||||
<FlatList
|
||||
data={sources}
|
||||
keyExtractor={(item) => item.sourceId.toString()}
|
||||
renderItem={renderItem}
|
||||
ListHeaderComponent={
|
||||
<Text
|
||||
style={{
|
||||
color: theme.textColorSecondary,
|
||||
padding: 20,
|
||||
paddingBottom: 10,
|
||||
textTransform: "uppercase",
|
||||
}}
|
||||
>
|
||||
Select a Source To Migrate From
|
||||
</Text>
|
||||
}
|
||||
/>
|
||||
</View>
|
||||
);
|
||||
};
|
||||
|
||||
export default GlobalSearch;
|
||||
|
||||
const styles = StyleSheet.create({
|
||||
container: { flex: 1 },
|
||||
containerStyle: {
|
||||
padding: 20,
|
||||
margin: 20,
|
||||
borderRadius: 6,
|
||||
},
|
||||
});
|
||||
@@ -0,0 +1,83 @@
|
||||
import React from "react";
|
||||
import { StyleSheet, View, FlatList, Text } from "react-native";
|
||||
import { useLibrary, useTheme } from "../../Hooks/reduxHooks";
|
||||
|
||||
import EmptyView from "../../Components/EmptyView";
|
||||
import { Appbar } from "../../Components/Appbar";
|
||||
import ListView from "../../Components/ListView";
|
||||
|
||||
const SourceNovels = ({ navigation, route }) => {
|
||||
const sourceId = route.params;
|
||||
const theme = useTheme();
|
||||
const library = useLibrary();
|
||||
|
||||
const sourceNovels = library.filter((novel) => novel.sourceId === sourceId);
|
||||
|
||||
const renderItem = ({ item }) => (
|
||||
<ListView
|
||||
item={item}
|
||||
theme={theme}
|
||||
onPress={() =>
|
||||
navigation.navigate("MigrateNovel", {
|
||||
sourceId: item.sourceId,
|
||||
novelName: item.novelName,
|
||||
})
|
||||
}
|
||||
/>
|
||||
);
|
||||
|
||||
return (
|
||||
<View
|
||||
style={[
|
||||
styles.container,
|
||||
{ backgroundColor: theme.colorPrimaryDark },
|
||||
]}
|
||||
>
|
||||
<Appbar
|
||||
title="Select Novel"
|
||||
onBackAction={() => navigation.goBack()}
|
||||
/>
|
||||
<FlatList
|
||||
data={sourceNovels}
|
||||
keyExtractor={(item) => item.novelId.toString()}
|
||||
renderItem={renderItem}
|
||||
ListEmptyComponent={
|
||||
<Text
|
||||
style={{
|
||||
color: theme.textColorSecondary,
|
||||
padding: 20,
|
||||
textAlign: "center",
|
||||
}}
|
||||
>
|
||||
Your library does not have any novels from this source
|
||||
</Text>
|
||||
}
|
||||
/>
|
||||
{/* <Portal>
|
||||
<MigrationDialog
|
||||
migrationDialog={migrationDialog}
|
||||
hideMigrationDialog={hideMigrationDIalog}
|
||||
theme={theme}
|
||||
selectedNovel={selectedNovel}
|
||||
loading={loading}
|
||||
migrationNovel={migrationNovel}
|
||||
/>
|
||||
<SourceToMigrateDialog
|
||||
selectedNovel={selectedNovel}
|
||||
sourceToMigrateDialog={sourceToMigrateDialog}
|
||||
hideSourceToMigrateDialog={hideSourceToMigrateDialog}
|
||||
sources={sources}
|
||||
theme={theme}
|
||||
showMigrationDialog={showMigrationDialog}
|
||||
selectSourceToMigrate={selectSourceToMigrate}
|
||||
/>
|
||||
</Portal> */}
|
||||
</View>
|
||||
);
|
||||
};
|
||||
|
||||
export default SourceNovels;
|
||||
|
||||
const styles = StyleSheet.create({
|
||||
container: { flex: 1 },
|
||||
});
|
||||
@@ -0,0 +1,71 @@
|
||||
import React from "react";
|
||||
import { StyleSheet, View, Text, ImageBackground } from "react-native";
|
||||
import { TouchableRipple } from "react-native-paper";
|
||||
|
||||
import { useSettings, useTheme } from "../../../Hooks/reduxHooks";
|
||||
|
||||
const GlobalSearchNovelCover = ({ item, onPress, libraryStatus }) => {
|
||||
const theme = useTheme();
|
||||
|
||||
const comfortableTitle = () => (
|
||||
<Text
|
||||
numberOfLines={2}
|
||||
style={[
|
||||
styles.title,
|
||||
{
|
||||
width: 115,
|
||||
color: theme.textColorPrimary,
|
||||
padding: 4,
|
||||
flexWrap: "wrap",
|
||||
},
|
||||
]}
|
||||
>
|
||||
{item.novelName}
|
||||
</Text>
|
||||
);
|
||||
|
||||
return (
|
||||
<View style={{ flex: 1 }}>
|
||||
<TouchableRipple
|
||||
borderless
|
||||
centered
|
||||
rippleColor={theme.rippleColor}
|
||||
style={styles.opac}
|
||||
onPress={onPress}
|
||||
>
|
||||
<>
|
||||
<ImageBackground
|
||||
source={{ uri: item.novelCover }}
|
||||
style={{ height: 150, width: 115 }}
|
||||
imageStyle={[
|
||||
{ borderRadius: 4 },
|
||||
libraryStatus && { opacity: 0.5 },
|
||||
]}
|
||||
progressiveRenderingEnabled={true}
|
||||
/>
|
||||
{comfortableTitle()}
|
||||
</>
|
||||
</TouchableRipple>
|
||||
</View>
|
||||
);
|
||||
};
|
||||
|
||||
export default GlobalSearchNovelCover;
|
||||
|
||||
const styles = StyleSheet.create({
|
||||
titleContainer: {
|
||||
flex: 1,
|
||||
justifyContent: "flex-end",
|
||||
borderRadius: 4,
|
||||
},
|
||||
title: {
|
||||
fontFamily: "pt-sans-bold",
|
||||
fontSize: 14,
|
||||
padding: 8,
|
||||
},
|
||||
opac: {
|
||||
paddingHorizontal: 5,
|
||||
paddingVertical: 4,
|
||||
borderRadius: 4,
|
||||
},
|
||||
});
|
||||
@@ -0,0 +1,55 @@
|
||||
import React from "react";
|
||||
import { StyleSheet, FlatList, Text } from "react-native";
|
||||
import GlobalSearchNovelCover from "./GlobalSearchNovelCover";
|
||||
|
||||
const GlobalSearchNovelList = ({ data, theme, library, navigation }) => {
|
||||
const checkIFInLibrary = (sourceId, novelUrl) => {
|
||||
return library.some(
|
||||
(obj) => obj.novelUrl === novelUrl && obj.sourceId === sourceId
|
||||
);
|
||||
};
|
||||
|
||||
const renderItem = ({ item }) => (
|
||||
<GlobalSearchNovelCover
|
||||
item={item}
|
||||
onPress={() =>
|
||||
navigation.navigate("Novel", {
|
||||
...item,
|
||||
sourceId: item.extensionId,
|
||||
})
|
||||
}
|
||||
libraryStatus={checkIFInLibrary(item.extensionId, item.novelUrl)}
|
||||
/>
|
||||
);
|
||||
|
||||
return (
|
||||
<FlatList
|
||||
contentContainerStyle={styles.flatListCont}
|
||||
horizontal={true}
|
||||
data={data}
|
||||
keyExtractor={(item) => item.novelUrl}
|
||||
renderItem={renderItem}
|
||||
ListEmptyComponent={
|
||||
<Text
|
||||
style={{
|
||||
color: theme.textColorSecondary,
|
||||
padding: 8,
|
||||
paddingVertical: 4,
|
||||
}}
|
||||
>
|
||||
No results found
|
||||
</Text>
|
||||
}
|
||||
/>
|
||||
);
|
||||
};
|
||||
|
||||
export default GlobalSearchNovelList;
|
||||
|
||||
const styles = StyleSheet.create({
|
||||
flatListCont: {
|
||||
flexGrow: 1,
|
||||
paddingVertical: 8,
|
||||
paddingHorizontal: 4,
|
||||
},
|
||||
});
|
||||
@@ -0,0 +1,132 @@
|
||||
import React, { useState } from "react";
|
||||
import { StyleSheet, FlatList, Text, View } from "react-native";
|
||||
import { Portal, Modal, Button } from "react-native-paper";
|
||||
import { migrateNovel } from "../../../Database/queries/NovelQueries";
|
||||
import { showToast } from "../../../Hooks/showToast";
|
||||
import GlobalSearchNovelCover from "./GlobalSearchNovelCover";
|
||||
|
||||
const MigrationNovelList = ({ data, theme, library, navigation }) => {
|
||||
const [selectedNovel, setSelectedNovel] = useState(false);
|
||||
|
||||
const [migrateNovelDialog, setMigrateNovelDialog] = useState(false);
|
||||
const showMigrateNovelDialog = () => setMigrateNovelDialog(true);
|
||||
const hideMigrateNovelDialog = () => setMigrateNovelDialog(false);
|
||||
|
||||
const checkIFInLibrary = (sourceId, novelUrl) => {
|
||||
return library.some(
|
||||
(obj) => obj.novelUrl === novelUrl && obj.sourceId === sourceId
|
||||
);
|
||||
};
|
||||
|
||||
const renderItem = ({ item }) => (
|
||||
<GlobalSearchNovelCover
|
||||
item={item}
|
||||
onPress={() =>
|
||||
showModal(item.extensionId, item.novelUrl, item.novelName)
|
||||
}
|
||||
libraryStatus={checkIFInLibrary(item.extensionId, item.novelUrl)}
|
||||
/>
|
||||
);
|
||||
|
||||
const showModal = (sourceId, novelUrl, novelName) => {
|
||||
if (checkIFInLibrary(sourceId, novelUrl)) {
|
||||
showToast("Novel already in library");
|
||||
} else {
|
||||
setSelectedNovel({ sourceId, novelUrl, novelName });
|
||||
showMigrateNovelDialog();
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<>
|
||||
<FlatList
|
||||
contentContainerStyle={styles.flatListCont}
|
||||
horizontal={true}
|
||||
data={data}
|
||||
keyExtractor={(item) => item.novelUrl}
|
||||
renderItem={renderItem}
|
||||
ListEmptyComponent={
|
||||
<Text
|
||||
style={{
|
||||
color: theme.textColorSecondary,
|
||||
padding: 8,
|
||||
paddingVertical: 4,
|
||||
}}
|
||||
>
|
||||
No results found
|
||||
</Text>
|
||||
}
|
||||
/>
|
||||
<Portal>
|
||||
<Modal
|
||||
visible={migrateNovelDialog}
|
||||
onDismiss={hideMigrateNovelDialog}
|
||||
contentContainerStyle={{
|
||||
padding: 20,
|
||||
margin: 20,
|
||||
borderRadius: 6,
|
||||
backgroundColor: theme.colorPrimaryDark,
|
||||
}}
|
||||
>
|
||||
<Text
|
||||
style={{
|
||||
color: theme.textColorPrimary,
|
||||
fontSize: 18,
|
||||
}}
|
||||
>
|
||||
{`Migrate ${selectedNovel.novelName}?`}
|
||||
</Text>
|
||||
<View
|
||||
style={{
|
||||
flexDirection: "row",
|
||||
justifyContent: "flex-end",
|
||||
}}
|
||||
>
|
||||
<Button
|
||||
style={{ marginTop: 30 }}
|
||||
labelStyle={{
|
||||
color: theme.colorAccent,
|
||||
letterSpacing: 0,
|
||||
textTransform: "none",
|
||||
}}
|
||||
onPress={hideMigrateNovelDialog}
|
||||
>
|
||||
Cancel
|
||||
</Button>
|
||||
<Button
|
||||
style={{ marginTop: 30 }}
|
||||
labelStyle={{
|
||||
color: theme.colorAccent,
|
||||
letterSpacing: 0,
|
||||
textTransform: "none",
|
||||
}}
|
||||
theme={{ colors: { primary: theme.colorAccent } }}
|
||||
onPress={() => {
|
||||
migrateNovel(
|
||||
selectedNovel.sourceId,
|
||||
selectedNovel.novelUrl
|
||||
);
|
||||
hideMigrateNovelDialog();
|
||||
showToast(
|
||||
`${selectedNovel.novelName} migrated to new source.`
|
||||
);
|
||||
}}
|
||||
>
|
||||
Migrate
|
||||
</Button>
|
||||
</View>
|
||||
</Modal>
|
||||
</Portal>
|
||||
</>
|
||||
);
|
||||
};
|
||||
|
||||
export default MigrationNovelList;
|
||||
|
||||
const styles = StyleSheet.create({
|
||||
flatListCont: {
|
||||
flexGrow: 1,
|
||||
paddingVertical: 8,
|
||||
paddingHorizontal: 4,
|
||||
},
|
||||
});
|
||||
@@ -0,0 +1,74 @@
|
||||
import React from "react";
|
||||
import { View, Text, Image, StyleSheet } from "react-native";
|
||||
import { TouchableRipple } from "react-native-paper";
|
||||
|
||||
const MigrationSourceCard = ({ item, theme, noOfNovels, onPress }) => {
|
||||
const { sourceId, sourceName, sourceCover, sourceLanguage, status } = item;
|
||||
|
||||
return (
|
||||
<TouchableRipple
|
||||
style={styles.extensionCard}
|
||||
onPress={onPress}
|
||||
rippleColor={theme.rippleColor}
|
||||
>
|
||||
<>
|
||||
<Image
|
||||
source={{ uri: sourceCover }}
|
||||
style={styles.extensionIcon}
|
||||
resizeMode="contain"
|
||||
/>
|
||||
<View style={styles.extensionDetails}>
|
||||
<View>
|
||||
<Text
|
||||
style={{
|
||||
color: theme.textColorPrimary,
|
||||
fontSize: 14,
|
||||
}}
|
||||
>
|
||||
{sourceName} {` (${noOfNovels || 0})`}
|
||||
</Text>
|
||||
<View style={{ flexDirection: "row" }}>
|
||||
<Text
|
||||
style={{
|
||||
color: theme.textColorSecondary,
|
||||
fontSize: 12,
|
||||
}}
|
||||
>
|
||||
{sourceLanguage}
|
||||
</Text>
|
||||
</View>
|
||||
</View>
|
||||
</View>
|
||||
</>
|
||||
</TouchableRipple>
|
||||
);
|
||||
};
|
||||
|
||||
export default MigrationSourceCard;
|
||||
|
||||
const styles = StyleSheet.create({
|
||||
extensionCard: {
|
||||
flexDirection: "row",
|
||||
alignItems: "center",
|
||||
marginVertical: 4,
|
||||
paddingVertical: 8,
|
||||
paddingHorizontal: 20,
|
||||
},
|
||||
extensionIcon: {
|
||||
width: 40,
|
||||
height: 40,
|
||||
borderRadius: 8,
|
||||
},
|
||||
extensionDetails: {
|
||||
flex: 1,
|
||||
flexDirection: "row",
|
||||
justifyContent: "space-between",
|
||||
alignItems: "center",
|
||||
marginLeft: 16,
|
||||
},
|
||||
sourceStatus: {
|
||||
color: "#C14033",
|
||||
fontSize: 12,
|
||||
marginLeft: 5,
|
||||
},
|
||||
});
|
||||
@@ -1,29 +1,28 @@
|
||||
import React from "react";
|
||||
import { View, Text, Image, StyleSheet } from "react-native";
|
||||
import { TouchableRipple, Button } from "react-native-paper";
|
||||
|
||||
import { TouchableRipple, Button, IconButton } from "react-native-paper";
|
||||
import { useNavigation } from "@react-navigation/native";
|
||||
import { useSelector } from "react-redux";
|
||||
import { useDispatch } from "react-redux";
|
||||
import { pinSourceAction } from "../../../redux/source/source.actions";
|
||||
|
||||
const ExtensionCard = ({ item }) => {
|
||||
const { sourceName, sourceCover, sourceLanguage, status } = item;
|
||||
const ExtensionCard = ({ item, theme, isPinned }) => {
|
||||
const { sourceId, sourceName, sourceCover, sourceLanguage, status } = item;
|
||||
|
||||
const navigation = useNavigation();
|
||||
const dispatch = useDispatch();
|
||||
|
||||
const theme = useSelector((state) => state.themeReducer.theme);
|
||||
const navigateToExtension = () =>
|
||||
navigation.navigate("Extension", {
|
||||
sourceId: item.sourceId,
|
||||
sourceName: item.sourceName,
|
||||
sourceUrl: item.sourceUrl,
|
||||
});
|
||||
|
||||
return (
|
||||
<TouchableRipple
|
||||
style={styles.extensionCard}
|
||||
onPress={() =>
|
||||
navigation.navigate("Extension", {
|
||||
sourceId: item.sourceId,
|
||||
sourceName: item.sourceName,
|
||||
sourceUrl: item.sourceUrl,
|
||||
})
|
||||
}
|
||||
onPress={navigateToExtension}
|
||||
rippleColor={theme.rippleColor}
|
||||
borderless
|
||||
>
|
||||
<>
|
||||
<Image
|
||||
@@ -50,34 +49,34 @@ const ExtensionCard = ({ item }) => {
|
||||
>
|
||||
{sourceLanguage}
|
||||
</Text>
|
||||
<Text
|
||||
style={{
|
||||
color: "#D63B2F",
|
||||
fontSize: 12,
|
||||
marginLeft: 5,
|
||||
}}
|
||||
>
|
||||
{status === 0 && "(Not Working)"}
|
||||
<Text style={styles.sourceStatus}>
|
||||
{status === 0 && "• Down"}
|
||||
</Text>
|
||||
</View>
|
||||
</View>
|
||||
<View>
|
||||
<View
|
||||
style={{ flexDirection: "row", alignItems: "center" }}
|
||||
>
|
||||
<Button
|
||||
labelStyle={{
|
||||
letterSpacing: 0,
|
||||
}}
|
||||
labelStyle={{ letterSpacing: 0 }}
|
||||
uppercase={false}
|
||||
color={theme.colorAccentDark}
|
||||
onPress={() =>
|
||||
navigation.navigate("Extension", {
|
||||
sourceId: item.sourceId,
|
||||
sourceName: item.sourceName,
|
||||
sourceUrl: item.sourceUrl,
|
||||
})
|
||||
}
|
||||
color={theme.colorAccent}
|
||||
onPress={navigateToExtension}
|
||||
>
|
||||
Browse
|
||||
</Button>
|
||||
<IconButton
|
||||
icon={isPinned ? "pin" : "pin-outline"}
|
||||
animated
|
||||
size={21}
|
||||
onPress={() => dispatch(pinSourceAction(sourceId))}
|
||||
color={
|
||||
isPinned
|
||||
? theme.colorAccent
|
||||
: theme.textColorSecondary
|
||||
}
|
||||
style={{ margin: 2 }}
|
||||
/>
|
||||
</View>
|
||||
</View>
|
||||
</>
|
||||
@@ -107,4 +106,9 @@ const styles = StyleSheet.create({
|
||||
alignItems: "center",
|
||||
marginLeft: 16,
|
||||
},
|
||||
sourceStatus: {
|
||||
color: "#C14033",
|
||||
fontSize: 12,
|
||||
marginLeft: 5,
|
||||
},
|
||||
});
|
||||
@@ -0,0 +1,240 @@
|
||||
import React, { useState, useEffect, useRef } from "react";
|
||||
import {
|
||||
StyleSheet,
|
||||
View,
|
||||
Text,
|
||||
ActivityIndicator,
|
||||
ScrollView,
|
||||
} from "react-native";
|
||||
import Constants from "expo-constants";
|
||||
|
||||
import { Appbar, Portal } from "react-native-paper";
|
||||
import { CollapsibleHeaderScrollView } from "react-native-collapsible-header-views";
|
||||
|
||||
import ReaderSheet from "./components/ReaderSheet";
|
||||
|
||||
import { insertHistoryAction } from "../../redux/history/history.actions";
|
||||
import {
|
||||
getChapterAction,
|
||||
saveScrollPosition,
|
||||
} from "../../redux/chapter/chapter.actions";
|
||||
import { markChapterReadAction } from "../../redux/novel/novel.actions";
|
||||
import { updateChaptersRead } from "../../redux/tracker/tracker.actions";
|
||||
|
||||
import { useDispatch } from "react-redux";
|
||||
import { parseChapterNumber } from "../../Services/updates";
|
||||
import {
|
||||
useChapter,
|
||||
useReaderSettings,
|
||||
useTheme,
|
||||
useTrackingStatus,
|
||||
} from "../../Hooks/reduxHooks";
|
||||
import {
|
||||
readerBackground,
|
||||
readerLineHeight,
|
||||
readerTextColor,
|
||||
} from "./readerStyleController";
|
||||
|
||||
const Chapter = ({ route, navigation }) => {
|
||||
const { chapterId, sourceId, chapterUrl, novelUrl, novelId, position } =
|
||||
route.params;
|
||||
let readerSheetRef = useRef(null);
|
||||
|
||||
const theme = useTheme();
|
||||
const reader = useReaderSettings();
|
||||
const dispatch = useDispatch();
|
||||
const { tracker, trackedNovels } = useTrackingStatus();
|
||||
|
||||
const isTracked = trackedNovels.find((obj) => obj.novelId === novelId);
|
||||
|
||||
const { chapter, loading } = useChapter();
|
||||
|
||||
const [scrollPercentage, setScrollPercentage] = useState(0);
|
||||
|
||||
useEffect(() => {
|
||||
dispatch(getChapterAction(sourceId, novelUrl, chapterUrl, chapterId));
|
||||
dispatch(insertHistoryAction(novelId, chapterId));
|
||||
}, []);
|
||||
|
||||
let chapterNumber;
|
||||
|
||||
if (!loading) {
|
||||
chapterNumber = parseChapterNumber(chapter.chapterName);
|
||||
}
|
||||
|
||||
const isCloseToBottom = ({
|
||||
layoutMeasurement,
|
||||
contentOffset,
|
||||
contentSize,
|
||||
}) => {
|
||||
const paddingToBottom = 40;
|
||||
return (
|
||||
layoutMeasurement.height + contentOffset.y >=
|
||||
contentSize.height - paddingToBottom
|
||||
);
|
||||
};
|
||||
|
||||
const updateTracker = () =>
|
||||
isTracked &&
|
||||
chapterNumber &&
|
||||
chapterNumber > isTracked.my_list_status.num_chapters_read &&
|
||||
dispatch(
|
||||
updateChaptersRead(
|
||||
isTracked.id,
|
||||
tracker.access_token,
|
||||
chapterNumber
|
||||
)
|
||||
);
|
||||
|
||||
const navigateToPreviousChapter = () =>
|
||||
navigation.replace("Chapter", {
|
||||
chapterUrl: chapter.prevChapter,
|
||||
chapterId: chapterId - 1,
|
||||
sourceId,
|
||||
novelUrl,
|
||||
novelId,
|
||||
chapterName: chapter.chapterName,
|
||||
});
|
||||
|
||||
const navigateToNextChapter = () =>
|
||||
navigation.replace("Chapter", {
|
||||
chapterUrl: chapter.nextChapter,
|
||||
sourceId,
|
||||
novelUrl,
|
||||
novelId,
|
||||
chapterId: chapterId + 1,
|
||||
chapterName: chapter.chapterName,
|
||||
});
|
||||
|
||||
const readerStyles = [
|
||||
{
|
||||
paddingVertical: 16,
|
||||
paddingBottom: 32,
|
||||
fontSize: reader.textSize,
|
||||
color: readerTextColor(reader.theme),
|
||||
lineHeight: readerLineHeight(reader.textSize),
|
||||
textAlign: reader.textAlign,
|
||||
paddingHorizontal: `${reader.padding}%`,
|
||||
},
|
||||
reader.fontFamily && {
|
||||
fontFamily: reader.fontFamily,
|
||||
},
|
||||
];
|
||||
|
||||
const onScroll = ({ nativeEvent }) => {
|
||||
const position =
|
||||
nativeEvent.contentOffset.y + nativeEvent.layoutMeasurement.height;
|
||||
|
||||
const percentage = Math.round(
|
||||
(position / nativeEvent.contentSize.height) * 100
|
||||
);
|
||||
|
||||
setScrollPercentage(percentage);
|
||||
dispatch(saveScrollPosition(position, percentage, chapterId, novelId));
|
||||
|
||||
if (isCloseToBottom(nativeEvent)) {
|
||||
dispatch(markChapterReadAction(chapterId, novelId));
|
||||
updateTracker();
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<>
|
||||
<CollapsibleHeaderScrollView
|
||||
headerContainerBackgroundColor="rgba(0,0,0,0.4)"
|
||||
CollapsibleHeaderComponent={
|
||||
<Appbar.Header
|
||||
style={{ backgroundColor: "transparent", elevation: 0 }}
|
||||
>
|
||||
<Appbar.BackAction
|
||||
onPress={() => navigation.goBack()}
|
||||
color="#FFFFFF"
|
||||
size={26}
|
||||
style={{ marginRight: 0 }}
|
||||
/>
|
||||
<Appbar.Content
|
||||
title={loading ? "Chapter" : chapter.chapterName}
|
||||
titleStyle={{ color: "#FFFFFF" }}
|
||||
/>
|
||||
{!loading && (
|
||||
<>
|
||||
<Appbar.Action
|
||||
icon="chevron-left"
|
||||
size={26}
|
||||
disabled={!chapter.prevChapter}
|
||||
onPress={navigateToPreviousChapter}
|
||||
color="#FFFFFF"
|
||||
/>
|
||||
<Appbar.Action
|
||||
icon="chevron-right"
|
||||
size={26}
|
||||
disabled={!chapter.nextChapter}
|
||||
onPress={navigateToNextChapter}
|
||||
color="#FFFFFF"
|
||||
/>
|
||||
</>
|
||||
)}
|
||||
<Appbar.Action
|
||||
icon="dots-vertical"
|
||||
size={26}
|
||||
onPress={() => readerSheetRef.current.show()}
|
||||
color="#FFFFFF"
|
||||
/>
|
||||
</Appbar.Header>
|
||||
}
|
||||
headerHeight={Constants.statusBarHeight + 60}
|
||||
contentContainerStyle={[
|
||||
styles.container,
|
||||
{ backgroundColor: readerBackground(reader.theme) },
|
||||
]}
|
||||
onScroll={onScroll}
|
||||
>
|
||||
{loading ? (
|
||||
<View style={{ flex: 1, justifyContent: "center" }}>
|
||||
<ActivityIndicator
|
||||
size={50}
|
||||
color={theme.colorAccent}
|
||||
/>
|
||||
</View>
|
||||
) : (
|
||||
<Text style={readerStyles}>
|
||||
{chapter.chapterText.trim()}
|
||||
</Text>
|
||||
)}
|
||||
<Portal>
|
||||
<ReaderSheet
|
||||
theme={theme}
|
||||
reader={reader}
|
||||
dispatch={dispatch}
|
||||
bottomSheetRef={readerSheetRef}
|
||||
/>
|
||||
</Portal>
|
||||
</CollapsibleHeaderScrollView>
|
||||
<Text
|
||||
style={[
|
||||
styles.scrollPercentage,
|
||||
{ color: readerTextColor(reader.theme) },
|
||||
]}
|
||||
>
|
||||
{scrollPercentage + "%"}
|
||||
</Text>
|
||||
</>
|
||||
);
|
||||
};
|
||||
|
||||
export default Chapter;
|
||||
|
||||
const styles = StyleSheet.create({
|
||||
container: {
|
||||
flexGrow: 1,
|
||||
paddingVertical: 10,
|
||||
},
|
||||
scrollPercentage: {
|
||||
position: "absolute",
|
||||
bottom: 12,
|
||||
alignSelf: "center",
|
||||
fontFamily: "noto-sans",
|
||||
fontWeight: "bold",
|
||||
zIndex: 1,
|
||||
},
|
||||
});
|
||||
@@ -1,11 +1,9 @@
|
||||
import React from "react";
|
||||
import { Animated, StyleSheet, View, Text, Dimensions } from "react-native";
|
||||
import { StyleSheet, View, Text, Dimensions } from "react-native";
|
||||
import { ToggleButton, IconButton, Chip } from "react-native-paper";
|
||||
import Slider from "@react-native-community/slider";
|
||||
import Bottomsheet from "rn-sliding-up-panel";
|
||||
import { fonts } from "../../../utils/constants";
|
||||
|
||||
import { connect } from "react-redux";
|
||||
import { fonts } from "../../../Services/utils/constants";
|
||||
|
||||
import {
|
||||
setReaderFont,
|
||||
@@ -14,28 +12,19 @@ import {
|
||||
updateReaderTextSize,
|
||||
updateReaderTheme,
|
||||
} from "../../../redux/settings/settings.actions";
|
||||
import BottomSheetHandle from "../../../components/BottomSheetHandle";
|
||||
import BottomSheetHandle from "../../../Components/BottomSheetHandle";
|
||||
|
||||
const ChapterBottomSheet = ({
|
||||
bottomSheetRef,
|
||||
theme,
|
||||
reader,
|
||||
updateReaderTextSize,
|
||||
updateReaderTheme,
|
||||
updateReaderTextAlign,
|
||||
updateReaderPadding,
|
||||
setReaderFont,
|
||||
}) => {
|
||||
const ReaderSheet = ({ theme, reader, dispatch, bottomSheetRef }) => {
|
||||
return (
|
||||
<Bottomsheet
|
||||
animatedValue={new Animated.Value(0)}
|
||||
ref={bottomSheetRef}
|
||||
draggableRange={{ top: 400, bottom: 0 }}
|
||||
snappingPoints={[0, 400]}
|
||||
showBackdrop={false}
|
||||
showBackdrop={true}
|
||||
backdropOpacity={0}
|
||||
>
|
||||
<View style={styles.contentContainer}>
|
||||
<BottomSheetHandle />
|
||||
<BottomSheetHandle theme={theme} />
|
||||
<View style={styles.readerSettingsContainer}>
|
||||
<Text
|
||||
style={{
|
||||
@@ -54,10 +43,12 @@ const ChapterBottomSheet = ({
|
||||
minimumValue={12}
|
||||
maximumValue={20}
|
||||
step={2}
|
||||
minimumTrackTintColor={theme.colorAccentDark}
|
||||
minimumTrackTintColor={theme.colorAccent}
|
||||
maximumTrackTintColor="#000000"
|
||||
thumbTintColor={theme.colorAccentDark}
|
||||
onValueChange={(value) => updateReaderTextSize(value)}
|
||||
thumbTintColor={theme.colorAccent}
|
||||
onValueChange={(value) =>
|
||||
dispatch(updateReaderTextSize(value))
|
||||
}
|
||||
/>
|
||||
<View
|
||||
style={{
|
||||
@@ -81,7 +72,7 @@ const ChapterBottomSheet = ({
|
||||
</Text>
|
||||
<ToggleButton.Row
|
||||
onValueChange={(value) =>
|
||||
updateReaderTheme(value)
|
||||
dispatch(updateReaderTheme(value))
|
||||
}
|
||||
value={reader.theme}
|
||||
style={{ marginTop: 10 }}
|
||||
@@ -131,7 +122,9 @@ const ChapterBottomSheet = ({
|
||||
</Text>
|
||||
<ToggleButton.Row
|
||||
onValueChange={(value) =>
|
||||
updateReaderTextAlign(value ?? "left")
|
||||
dispatch(
|
||||
updateReaderTextAlign(value ?? "left")
|
||||
)
|
||||
}
|
||||
value={reader.textAlign}
|
||||
style={{ marginTop: 10 }}
|
||||
@@ -185,11 +178,13 @@ const ChapterBottomSheet = ({
|
||||
>
|
||||
<IconButton
|
||||
icon="minus"
|
||||
color={theme.colorAccentDark}
|
||||
color={theme.colorAccent}
|
||||
size={26}
|
||||
disabled={reader.padding <= 0 ? true : false}
|
||||
onPress={() =>
|
||||
updateReaderPadding(reader.padding - 1)
|
||||
dispatch(
|
||||
updateReaderPadding(reader.padding - 1)
|
||||
)
|
||||
}
|
||||
/>
|
||||
<Text
|
||||
@@ -202,11 +197,13 @@ const ChapterBottomSheet = ({
|
||||
</Text>
|
||||
<IconButton
|
||||
icon="plus"
|
||||
color={theme.colorAccentDark}
|
||||
color={theme.colorAccent}
|
||||
size={26}
|
||||
disabled={reader.padding >= 10 ? true : false}
|
||||
onPress={() =>
|
||||
updateReaderPadding(reader.padding + 1)
|
||||
dispatch(
|
||||
updateReaderPadding(reader.padding + 1)
|
||||
)
|
||||
}
|
||||
/>
|
||||
</View>
|
||||
@@ -229,7 +226,9 @@ const ChapterBottomSheet = ({
|
||||
{fonts.map((font, index) => (
|
||||
<Chip
|
||||
key={index}
|
||||
onPress={() => setReaderFont(font.fontFamily)}
|
||||
onPress={() =>
|
||||
dispatch(setReaderFont(font.fontFamily))
|
||||
}
|
||||
textStyle={{ fontFamily: font.fontFamily }}
|
||||
style={{
|
||||
borderWidth: 0,
|
||||
@@ -252,18 +251,9 @@ const ChapterBottomSheet = ({
|
||||
);
|
||||
};
|
||||
|
||||
const mapStateToProps = (state) => ({
|
||||
theme: state.themeReducer.theme,
|
||||
reader: state.settingsReducer.reader,
|
||||
});
|
||||
const mapStateToProps = (state) => ({});
|
||||
|
||||
export default connect(mapStateToProps, {
|
||||
updateReaderTextSize,
|
||||
updateReaderTheme,
|
||||
updateReaderTextAlign,
|
||||
updateReaderPadding,
|
||||
setReaderFont,
|
||||
})(ChapterBottomSheet);
|
||||
export default ReaderSheet;
|
||||
|
||||
const styles = StyleSheet.create({
|
||||
contentContainer: {
|
||||
@@ -0,0 +1,27 @@
|
||||
export const readerBackground = (val) => {
|
||||
const backgroundColor = {
|
||||
1: "#000000",
|
||||
2: "#FFFFFF",
|
||||
3: "#F4ECD8",
|
||||
};
|
||||
|
||||
return backgroundColor[val];
|
||||
};
|
||||
|
||||
export const readerTextColor = (val) => {
|
||||
const textColor = val === 1 ? "rgba(255,255,255,0.7)" : "#000000";
|
||||
|
||||
return textColor;
|
||||
};
|
||||
|
||||
export const readerLineHeight = (val) => {
|
||||
const lineHeight = {
|
||||
12: 20,
|
||||
14: 22,
|
||||
16: 25,
|
||||
18: 26,
|
||||
20: 28,
|
||||
};
|
||||
|
||||
return lineHeight[val];
|
||||
};
|
||||
@@ -0,0 +1,150 @@
|
||||
import React, { useEffect, useState } from "react";
|
||||
import { StyleSheet, View, ActivityIndicator } from "react-native";
|
||||
import * as WebBrowser from "expo-web-browser";
|
||||
|
||||
import NovelCover from "../../Components/NovelCover";
|
||||
import EmptyView from "../../Components/EmptyView";
|
||||
|
||||
import { Searchbar } from "../../Components/Searchbar";
|
||||
import { useTheme, useLibrary } from "../../Hooks/reduxHooks";
|
||||
import NovelList from "../../Components/NovelList";
|
||||
import { showToast } from "../../Hooks/showToast";
|
||||
|
||||
const Extension = ({ navigation, route }) => {
|
||||
const { sourceId, sourceName, sourceUrl } = route.params;
|
||||
|
||||
const theme = useTheme();
|
||||
const library = useLibrary();
|
||||
|
||||
const [loading, setLoading] = useState(true);
|
||||
const [novels, setNovels] = useState();
|
||||
|
||||
const [searchText, setSearchText] = useState("");
|
||||
|
||||
const getSourceUrl = () => {
|
||||
if (sourceId === 1) {
|
||||
return `https://lnreader-extensions.vercel.app/api/1/novels/1/?o=rating`;
|
||||
} else {
|
||||
return `https://lnreader-extensions.vercel.app/api/${sourceId}/novels/`;
|
||||
}
|
||||
};
|
||||
|
||||
const getSearchUrl = () => {
|
||||
if (sourceId === 1) {
|
||||
return `https://lnreader-extensions.vercel.app/api/1/search/?s=${searchText}&?o=rating`;
|
||||
} else {
|
||||
return `https://lnreader-extensions.vercel.app/api/${sourceId}/search/?s=${searchText}`;
|
||||
}
|
||||
};
|
||||
|
||||
const getNovels = () => {
|
||||
fetch(getSourceUrl())
|
||||
.then((response) => response.json())
|
||||
.then((json) => {
|
||||
setNovels(json);
|
||||
setLoading(false);
|
||||
})
|
||||
.catch((error) => {
|
||||
setNovels([]);
|
||||
setLoading(false);
|
||||
showToast(error.message);
|
||||
});
|
||||
};
|
||||
|
||||
const clearSearchbar = () => {
|
||||
getNovels();
|
||||
setLoading(true);
|
||||
setSearchText("");
|
||||
};
|
||||
|
||||
const getSearchResults = () => {
|
||||
setLoading(true);
|
||||
fetch(getSearchUrl())
|
||||
.then((response) => response.json())
|
||||
.then((json) => {
|
||||
setNovels(json);
|
||||
setLoading(false);
|
||||
})
|
||||
.catch((error) => {
|
||||
setNovels([]);
|
||||
setLoading(false);
|
||||
showToast(error.message);
|
||||
});
|
||||
};
|
||||
|
||||
const checkIFInLibrary = (sourceId, novelUrl) => {
|
||||
return library.some(
|
||||
(obj) => obj.novelUrl === novelUrl && obj.sourceId === sourceId
|
||||
);
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
getNovels();
|
||||
}, []);
|
||||
|
||||
const renderItem = ({ item }) => (
|
||||
<NovelCover
|
||||
item={item}
|
||||
onPress={() =>
|
||||
navigation.navigate("Novel", {
|
||||
novelName: item.novelName,
|
||||
novelCover: item.novelCover,
|
||||
novelUrl: item.novelUrl,
|
||||
sourceId: item.extensionId,
|
||||
})
|
||||
}
|
||||
libraryStatus={checkIFInLibrary(item.extensionId, item.novelUrl)}
|
||||
/>
|
||||
);
|
||||
|
||||
const listEmptyComponent = () =>
|
||||
novels.length === 0 && (
|
||||
<EmptyView icon="(; ̄Д ̄)" description="No results found" />
|
||||
);
|
||||
|
||||
return (
|
||||
<View
|
||||
style={[
|
||||
styles.container,
|
||||
{ backgroundColor: theme.colorPrimaryDark },
|
||||
]}
|
||||
>
|
||||
<Searchbar
|
||||
theme={theme}
|
||||
placeholder={`Search ${sourceName}`}
|
||||
left="arrow-left"
|
||||
onPressLeft={() => navigation.goBack()}
|
||||
searchText={searchText}
|
||||
onChangeText={(text) => setSearchText(text)}
|
||||
onSubmitEditing={getSearchResults}
|
||||
clearSearchbar={clearSearchbar}
|
||||
right="earth"
|
||||
displayMenu={true}
|
||||
onPressRight={() => WebBrowser.openBrowserAsync(sourceUrl)}
|
||||
/>
|
||||
|
||||
{loading ? (
|
||||
<View style={{ flex: 1, justifyContent: "center" }}>
|
||||
<ActivityIndicator size={60} color={theme.colorAccent} />
|
||||
</View>
|
||||
) : (
|
||||
<NovelList
|
||||
data={novels}
|
||||
renderItem={renderItem}
|
||||
ListEmptyComponent={listEmptyComponent()}
|
||||
/>
|
||||
)}
|
||||
</View>
|
||||
);
|
||||
};
|
||||
|
||||
export default Extension;
|
||||
|
||||
const styles = StyleSheet.create({
|
||||
container: {
|
||||
flex: 1,
|
||||
},
|
||||
contentContainer: {
|
||||
flex: 1,
|
||||
},
|
||||
});
|
||||
@@ -1,13 +1,11 @@
|
||||
import React, { useState, useCallback } from "react";
|
||||
import { useFocusEffect } from "@react-navigation/native";
|
||||
|
||||
import React, { useEffect } from "react";
|
||||
import { StyleSheet, View, FlatList, ActivityIndicator } from "react-native";
|
||||
|
||||
import { Appbar } from "../../components/Appbar";
|
||||
import { Appbar } from "../../Components/Appbar";
|
||||
import HistoryCard from "./components/HistoryCard";
|
||||
|
||||
import { connect } from "react-redux";
|
||||
import EmptyView from "../../components/EmptyView";
|
||||
import EmptyView from "../../Components/EmptyView";
|
||||
|
||||
import {
|
||||
getHistoryAction,
|
||||
@@ -22,15 +20,14 @@ const History = ({
|
||||
getHistoryAction,
|
||||
deleteHistoryAction,
|
||||
}) => {
|
||||
useFocusEffect(
|
||||
useCallback(() => {
|
||||
getHistoryAction();
|
||||
}, [getHistoryAction])
|
||||
);
|
||||
useEffect(() => {
|
||||
getHistoryAction();
|
||||
}, [getHistoryAction]);
|
||||
|
||||
const renderHistoryCard = ({ item }) => (
|
||||
<HistoryCard
|
||||
item={item}
|
||||
theme={theme}
|
||||
deleteHistoryAction={deleteHistoryAction}
|
||||
navigation={navigation}
|
||||
/>
|
||||
@@ -46,15 +43,15 @@ const History = ({
|
||||
]}
|
||||
>
|
||||
<FlatList
|
||||
contentContainerStyle={{ flexGrow: 1 }}
|
||||
contentContainerStyle={{ flexGrow: 1, padding: 8 }}
|
||||
data={history}
|
||||
keyExtractor={(item) => item.novelUrl.toString()}
|
||||
keyExtractor={(item) => item.novelId.toString()}
|
||||
renderItem={renderHistoryCard}
|
||||
ListFooterComponent={
|
||||
loading && (
|
||||
<ActivityIndicator
|
||||
size="small"
|
||||
color={theme.colorAccentDark}
|
||||
color={theme.colorAccent}
|
||||
/>
|
||||
)
|
||||
}
|
||||
@@ -73,7 +70,7 @@ const History = ({
|
||||
};
|
||||
|
||||
const mapStateToProps = (state) => ({
|
||||
theme: state.themeReducer.theme,
|
||||
theme: state.settingsReducer.theme,
|
||||
history: state.historyReducer.history,
|
||||
loading: state.historyReducer.loading,
|
||||
});
|
||||
@@ -86,6 +83,5 @@ export default connect(mapStateToProps, {
|
||||
const styles = StyleSheet.create({
|
||||
container: {
|
||||
flex: 1,
|
||||
padding: 10,
|
||||
},
|
||||
});
|
||||
@@ -5,24 +5,20 @@ import { TouchableRipple, IconButton } from "react-native-paper";
|
||||
|
||||
import moment from "moment";
|
||||
|
||||
import { useSelector } from "react-redux";
|
||||
|
||||
const HistoryCard = ({ item, deleteHistoryAction, navigation }) => {
|
||||
const theme = useSelector((state) => state.themeReducer.theme);
|
||||
import { useDispatch } from "react-redux";
|
||||
import { setNovel } from "../../../redux/novel/novel.actions";
|
||||
|
||||
const HistoryCard = ({ item, deleteHistoryAction, navigation, theme }) => {
|
||||
const dispatch = useDispatch();
|
||||
return (
|
||||
<TouchableRipple
|
||||
style={styles.historyCard}
|
||||
rippleColor={theme.rippleColor}
|
||||
borderless
|
||||
onPress={() =>
|
||||
navigation.navigate("NovelItem", {
|
||||
novelName: item.novelName,
|
||||
novelCover: item.novelCover,
|
||||
extensionId: item.extensionId,
|
||||
novelUrl: item.novelUrl,
|
||||
})
|
||||
}
|
||||
onPress={() => {
|
||||
navigation.navigate("Novel", item);
|
||||
dispatch(setNovel(item));
|
||||
}}
|
||||
>
|
||||
<>
|
||||
<Image
|
||||
@@ -74,10 +70,10 @@ const HistoryCard = ({ item, deleteHistoryAction, navigation }) => {
|
||||
color={theme.textColorPrimary}
|
||||
style={{ marginRight: 10 }}
|
||||
onPress={() =>
|
||||
navigation.navigate("ChapterItem", {
|
||||
navigation.navigate("Chapter", {
|
||||
chapterId: item.historyChapterId,
|
||||
chapterUrl: item.chapterUrl,
|
||||
extensionId: item.sourceId,
|
||||
sourceId: item.sourceId,
|
||||
novelUrl: item.novelUrl,
|
||||
novelId: item.novelId,
|
||||
chapterName: item.chapterName,
|
||||
@@ -0,0 +1,155 @@
|
||||
import React, { useState, useCallback, useRef } from "react";
|
||||
import {
|
||||
StyleSheet,
|
||||
Text,
|
||||
View,
|
||||
RefreshControl,
|
||||
ActivityIndicator,
|
||||
} from "react-native";
|
||||
import { useFocusEffect } from "@react-navigation/native";
|
||||
import { useSelector, useDispatch } from "react-redux";
|
||||
|
||||
import { Searchbar } from "../../Components/Searchbar";
|
||||
import NovelList from "../../Components/NovelList";
|
||||
import NovelCover from "../../Components/NovelCover";
|
||||
import EmptyView from "../../Components/EmptyView";
|
||||
|
||||
import {
|
||||
getLibraryAction,
|
||||
searchLibraryAction,
|
||||
} from "../../redux/library/library.actions";
|
||||
import { updateLibraryAction } from "../../redux/updates/updates.actions";
|
||||
import { useTheme } from "../../Hooks/reduxHooks";
|
||||
import { setNovel } from "../../redux/novel/novel.actions";
|
||||
import { Portal } from "react-native-paper";
|
||||
import LibraryFilterSheet from "./components/LibraryFilterSheet";
|
||||
|
||||
const LibraryScreen = ({ navigation }) => {
|
||||
const theme = useTheme();
|
||||
const dispatch = useDispatch();
|
||||
|
||||
const libraryFilterSheetRef = useRef(null);
|
||||
|
||||
const {
|
||||
loading,
|
||||
novels,
|
||||
filters: { sort, filter },
|
||||
} = useSelector((state) => state.libraryReducer);
|
||||
|
||||
const [refreshing, setRefreshing] = useState(false);
|
||||
const [searchText, setSearchText] = useState("");
|
||||
|
||||
useFocusEffect(
|
||||
useCallback(() => {
|
||||
setSearchText("");
|
||||
dispatch(getLibraryAction(sort, filter));
|
||||
}, [getLibraryAction, sort, filter])
|
||||
);
|
||||
|
||||
const onRefresh = () => {
|
||||
setRefreshing(true);
|
||||
dispatch(updateLibraryAction());
|
||||
setRefreshing(false);
|
||||
};
|
||||
|
||||
const clearSearchbar = () => {
|
||||
dispatch(getLibraryAction(sort, filter));
|
||||
setSearchText("");
|
||||
};
|
||||
|
||||
const onChangeText = (text) => {
|
||||
setSearchText(text);
|
||||
dispatch(searchLibraryAction(text, sort, filter));
|
||||
};
|
||||
|
||||
const renderItem = ({ item }) => (
|
||||
<NovelCover
|
||||
item={item}
|
||||
onPress={() => {
|
||||
navigation.navigate("Novel", item);
|
||||
dispatch(setNovel(item));
|
||||
}}
|
||||
/>
|
||||
);
|
||||
|
||||
const refreshControl = () => (
|
||||
<RefreshControl
|
||||
refreshing={refreshing}
|
||||
onRefresh={onRefresh}
|
||||
colors={["white"]}
|
||||
progressBackgroundColor={theme.colorAccent}
|
||||
/>
|
||||
);
|
||||
|
||||
// if (!loading) {
|
||||
// console.log(novels);
|
||||
// }
|
||||
|
||||
const listEmptyComponent = () =>
|
||||
searchText !== "" ? (
|
||||
<Text style={[styles.emptySearch, { color: theme.colorAccent }]}>
|
||||
{`"${searchText}" not in library`}
|
||||
</Text>
|
||||
) : (
|
||||
<EmptyView
|
||||
icon="Σ(ಠ_ಠ)"
|
||||
description="Your library is empty. Add series to your library from Browse."
|
||||
/>
|
||||
);
|
||||
|
||||
return (
|
||||
<>
|
||||
<View
|
||||
style={[
|
||||
styles.container,
|
||||
{ backgroundColor: theme.colorPrimaryDark },
|
||||
]}
|
||||
>
|
||||
<Searchbar
|
||||
placeholder="Search Library"
|
||||
searchText={searchText}
|
||||
clearSearchbar={clearSearchbar}
|
||||
onChangeText={onChangeText}
|
||||
left="magnify"
|
||||
right="dots-vertical"
|
||||
onPressRight={() => libraryFilterSheetRef.current.show()}
|
||||
theme={theme}
|
||||
/>
|
||||
{loading ? (
|
||||
<ActivityIndicator size="small" color={theme.colorAccent} />
|
||||
) : (
|
||||
<>
|
||||
<NovelList
|
||||
data={novels}
|
||||
renderItem={renderItem}
|
||||
refreshControl={refreshControl()}
|
||||
ListEmptyComponent={listEmptyComponent}
|
||||
/>
|
||||
<Portal>
|
||||
<LibraryFilterSheet
|
||||
bottomSheetRef={libraryFilterSheetRef}
|
||||
theme={theme}
|
||||
dispatch={dispatch}
|
||||
sort={sort}
|
||||
filter={filter}
|
||||
/>
|
||||
</Portal>
|
||||
</>
|
||||
)}
|
||||
</View>
|
||||
</>
|
||||
);
|
||||
};
|
||||
|
||||
export default LibraryScreen;
|
||||
|
||||
const styles = StyleSheet.create({
|
||||
container: {
|
||||
flex: 1,
|
||||
},
|
||||
emptySearch: {
|
||||
marginTop: 8,
|
||||
textAlign: "center",
|
||||
paddingHorizontal: 16,
|
||||
},
|
||||
});
|
||||
@@ -0,0 +1,254 @@
|
||||
import React, { useState } from "react";
|
||||
import { StyleSheet, View, Text, Animated } from "react-native";
|
||||
|
||||
import { List, RadioButton, Checkbox } from "react-native-paper";
|
||||
|
||||
import Bottomsheet from "rn-sliding-up-panel";
|
||||
import BottomSheetHandle from "../../../Components/BottomSheetHandle";
|
||||
import { ListItem } from "../../../Components/List";
|
||||
import { filterLibrary } from "../../../redux/library/library.actions";
|
||||
|
||||
const LibraryFilterSheet = ({
|
||||
bottomSheetRef,
|
||||
dispatch,
|
||||
sort,
|
||||
filter,
|
||||
theme,
|
||||
}) => {
|
||||
const [animatedValue] = useState(new Animated.Value(0));
|
||||
|
||||
return (
|
||||
<Bottomsheet
|
||||
animatedValue={animatedValue}
|
||||
ref={bottomSheetRef}
|
||||
draggableRange={{ top: 540, bottom: 0 }}
|
||||
snappingPoints={[0, 540]}
|
||||
>
|
||||
<View
|
||||
style={[
|
||||
styles.contentContainer,
|
||||
{ backgroundColor: theme.colorPrimary },
|
||||
]}
|
||||
>
|
||||
<BottomSheetHandle theme={theme} />
|
||||
<View style={{ marginTop: 24 }}>
|
||||
<Text
|
||||
style={{
|
||||
color: theme.colorAccent,
|
||||
paddingHorizontal: 16,
|
||||
paddingBottom: 8,
|
||||
textTransform: "uppercase",
|
||||
}}
|
||||
>
|
||||
SORT
|
||||
</Text>
|
||||
<ListItem
|
||||
title="Date Added"
|
||||
theme={theme}
|
||||
right={
|
||||
sort === "novels.novelId ASC"
|
||||
? "arrow-up"
|
||||
: sort === "novels.novelId DESC"
|
||||
? "arrow-down"
|
||||
: null
|
||||
}
|
||||
onPress={() =>
|
||||
sort === "novels.novelId ASC"
|
||||
? dispatch(
|
||||
filterLibrary(
|
||||
"novels.novelId DESC",
|
||||
filter
|
||||
)
|
||||
)
|
||||
: dispatch(
|
||||
filterLibrary(
|
||||
"novels.novelId ASC",
|
||||
filter
|
||||
)
|
||||
)
|
||||
}
|
||||
/>
|
||||
<ListItem
|
||||
title="Alphabetically"
|
||||
theme={theme}
|
||||
right={
|
||||
sort === "novels.novelName ASC"
|
||||
? "arrow-up"
|
||||
: sort === "novels.novelName DESC"
|
||||
? "arrow-down"
|
||||
: null
|
||||
}
|
||||
onPress={() =>
|
||||
sort === "novels.novelName ASC"
|
||||
? dispatch(
|
||||
filterLibrary(
|
||||
"novels.novelName DESC",
|
||||
filter
|
||||
)
|
||||
)
|
||||
: dispatch(
|
||||
filterLibrary(
|
||||
"novels.novelName ASC",
|
||||
filter
|
||||
)
|
||||
)
|
||||
}
|
||||
/>
|
||||
<ListItem
|
||||
title="Unread"
|
||||
theme={theme}
|
||||
right={
|
||||
sort === "novels.unread ASC"
|
||||
? "arrow-up"
|
||||
: sort === "novels.unread DESC"
|
||||
? "arrow-down"
|
||||
: null
|
||||
}
|
||||
onPress={() =>
|
||||
sort === "novels.unread ASC"
|
||||
? dispatch(
|
||||
filterLibrary(
|
||||
"novels.unread DESC",
|
||||
filter
|
||||
)
|
||||
)
|
||||
: dispatch(
|
||||
filterLibrary("novels.unread ASC", filter)
|
||||
)
|
||||
}
|
||||
/>
|
||||
<ListItem
|
||||
title="Downloaded"
|
||||
theme={theme}
|
||||
right={
|
||||
sort === "chaptersDownloaded ASC"
|
||||
? "arrow-up"
|
||||
: sort === "chaptersDownloaded DESC"
|
||||
? "arrow-down"
|
||||
: null
|
||||
}
|
||||
onPress={() =>
|
||||
sort === "chaptersDownloaded ASC"
|
||||
? dispatch(
|
||||
filterLibrary(
|
||||
"chaptersDownloaded DESC",
|
||||
filter
|
||||
)
|
||||
)
|
||||
: dispatch(
|
||||
filterLibrary(
|
||||
"chaptersDownloaded ASC",
|
||||
filter
|
||||
)
|
||||
)
|
||||
}
|
||||
/>
|
||||
<ListItem
|
||||
title="Total Chapters"
|
||||
theme={theme}
|
||||
right={
|
||||
sort === "chaptersUnread ASC"
|
||||
? "arrow-up"
|
||||
: sort === "chaptersUnread DESC"
|
||||
? "arrow-down"
|
||||
: null
|
||||
}
|
||||
onPress={() =>
|
||||
sort === "chaptersUnread ASC"
|
||||
? dispatch(
|
||||
filterLibrary(
|
||||
"chaptersUnread DESC",
|
||||
filter
|
||||
)
|
||||
)
|
||||
: dispatch(
|
||||
filterLibrary(
|
||||
"chaptersUnread ASC",
|
||||
filter
|
||||
)
|
||||
)
|
||||
}
|
||||
/>
|
||||
</View>
|
||||
<View>
|
||||
<Text
|
||||
style={{
|
||||
color: theme.colorAccent,
|
||||
paddingHorizontal: 16,
|
||||
paddingVertical: 8,
|
||||
textTransform: "uppercase",
|
||||
}}
|
||||
>
|
||||
Filter
|
||||
</Text>
|
||||
<Checkbox.Item
|
||||
label="Downloaded"
|
||||
labelStyle={{ color: theme.textColorPrimary }}
|
||||
color={theme.colorAccent}
|
||||
uncheckedColor={theme.textColorHint}
|
||||
status={
|
||||
filter === "chaptersDownloaded > 0"
|
||||
? "checked"
|
||||
: "unchecked"
|
||||
}
|
||||
onPress={() =>
|
||||
filter === "chaptersDownloaded > 0"
|
||||
? dispatch(filterLibrary(sort, ""))
|
||||
: dispatch(
|
||||
filterLibrary(
|
||||
sort,
|
||||
"chaptersDownloaded > 0"
|
||||
)
|
||||
)
|
||||
}
|
||||
/>
|
||||
<Checkbox.Item
|
||||
label="Unread"
|
||||
labelStyle={{ color: theme.textColorPrimary }}
|
||||
color={theme.colorAccent}
|
||||
uncheckedColor={theme.textColorHint}
|
||||
status={
|
||||
filter === "unread = 1" ? "checked" : "unchecked"
|
||||
}
|
||||
onPress={() =>
|
||||
filter === "unread = 1"
|
||||
? dispatch(filterLibrary(sort, ""))
|
||||
: dispatch(filterLibrary(sort, "unread = 1"))
|
||||
}
|
||||
/>
|
||||
<Checkbox.Item
|
||||
label="Completed"
|
||||
labelStyle={{ color: theme.textColorPrimary }}
|
||||
color={theme.colorAccent}
|
||||
uncheckedColor={theme.textColorHint}
|
||||
status={
|
||||
filter === "chaptersUnread IS NULL"
|
||||
? "checked"
|
||||
: "unchecked"
|
||||
}
|
||||
onPress={() =>
|
||||
filter === "chaptersUnread IS NULL"
|
||||
? dispatch(filterLibrary(sort, ""))
|
||||
: dispatch(
|
||||
filterLibrary(
|
||||
sort,
|
||||
"chaptersUnread IS NULL"
|
||||
)
|
||||
)
|
||||
}
|
||||
/>
|
||||
</View>
|
||||
</View>
|
||||
</Bottomsheet>
|
||||
);
|
||||
};
|
||||
|
||||
export default LibraryFilterSheet;
|
||||
|
||||
const styles = StyleSheet.create({
|
||||
contentContainer: {
|
||||
flex: 1,
|
||||
borderTopRightRadius: 8,
|
||||
borderTopLeftRadius: 8,
|
||||
},
|
||||
});
|
||||
@@ -2,13 +2,13 @@ import React from "react";
|
||||
import { View } from "react-native";
|
||||
import * as Linking from "expo-linking";
|
||||
|
||||
import { Appbar } from "../../components/Appbar";
|
||||
import { Appbar } from "../../Components/Appbar";
|
||||
|
||||
import { useSelector } from "react-redux";
|
||||
import { Divider, ListItem, ListSection } from "../../components/List";
|
||||
import { Divider, ListItem, ListSection } from "../../Components/List";
|
||||
|
||||
const AboutScreen = ({ navigation }) => {
|
||||
const theme = useSelector((state) => state.themeReducer.theme);
|
||||
const theme = useSelector((state) => state.settingsReducer.theme);
|
||||
|
||||
return (
|
||||
<>
|
||||
@@ -17,12 +17,12 @@ const AboutScreen = ({ navigation }) => {
|
||||
<ListSection>
|
||||
<ListItem
|
||||
title="Version"
|
||||
description="Stable 1.0.13"
|
||||
description="Stable 1.0.17"
|
||||
theme={theme}
|
||||
/>
|
||||
<ListItem
|
||||
title="Build Time"
|
||||
description="24-04-21 21:00 PM"
|
||||
description="06-05-21 21:00 PM"
|
||||
theme={theme}
|
||||
/>
|
||||
<ListItem
|
||||
@@ -2,11 +2,11 @@ import React from "react";
|
||||
import { StyleSheet, View, Image } from "react-native";
|
||||
import { useSelector } from "react-redux";
|
||||
|
||||
import { Appbar } from "../../components/Appbar";
|
||||
import { ListItem, ListSection } from "../../components/List";
|
||||
import { Appbar } from "../../Components/Appbar";
|
||||
import { ListItem, ListSection } from "../../Components/List";
|
||||
|
||||
const MoreScreen = ({ navigation }) => {
|
||||
const theme = useSelector((state) => state.themeReducer.theme);
|
||||
const theme = useSelector((state) => state.settingsReducer.theme);
|
||||
|
||||
return (
|
||||
<>
|
||||
@@ -37,17 +37,27 @@ const MoreScreen = ({ navigation }) => {
|
||||
title="Settings"
|
||||
icon="cog-outline"
|
||||
onPress={() =>
|
||||
navigation.navigate("SettingsStack", {
|
||||
navigation.navigate("MoreStack", {
|
||||
screen: "Settings",
|
||||
})
|
||||
}
|
||||
theme={theme}
|
||||
/>
|
||||
<ListItem
|
||||
title="Tracking"
|
||||
icon="sync"
|
||||
onPress={() =>
|
||||
navigation.navigate("MoreStack", {
|
||||
screen: "Trackers",
|
||||
})
|
||||
}
|
||||
theme={theme}
|
||||
/>
|
||||
<ListItem
|
||||
title="About"
|
||||
icon="information-outline"
|
||||
onPress={() =>
|
||||
navigation.navigate("SettingsStack", {
|
||||
navigation.navigate("MoreStack", {
|
||||
screen: "About",
|
||||
})
|
||||
}
|
||||
@@ -1,30 +1,32 @@
|
||||
import React, { useState } from "react";
|
||||
import { View } from "react-native";
|
||||
import { connect } from "react-redux";
|
||||
import { connect, useDispatch } from "react-redux";
|
||||
|
||||
import { switchTheme } from "../../redux/theme/theme.actions";
|
||||
import { switchTheme } from "../../redux/settings/settings.actions";
|
||||
import {
|
||||
setDisplayMode,
|
||||
setItemsPerRow,
|
||||
} from "../../redux/settings/settings.actions";
|
||||
import { deleteAllHistory } from "../../database/queries/HistoryQueries";
|
||||
import { deleteNovelCache } from "../../database/queries/NovelQueries";
|
||||
import { deleteNovelCache } from "../../Database/queries/NovelQueries";
|
||||
|
||||
import { Appbar } from "../../components/Appbar";
|
||||
import { Appbar } from "../../Components/Appbar";
|
||||
import {
|
||||
Divider,
|
||||
ListItem,
|
||||
ListSection,
|
||||
ListSubHeader,
|
||||
} from "../../components/List";
|
||||
InfoItem,
|
||||
} from "../../Components/List";
|
||||
import DisplayModeModal from "./components/DisplayModeModal";
|
||||
import GridSizeModal from "./components/GridSizeModal";
|
||||
import ThemeModal from "./components/ThemeModal";
|
||||
import { createBackup, restoreBackup } from "../../Services/backup";
|
||||
import { useTheme } from "../../Hooks/reduxHooks";
|
||||
import { restoreLibraryAction } from "../../redux/library/library.actions";
|
||||
import { clearAllHistoryAction } from "../../redux/history/history.actions";
|
||||
|
||||
const SettingsScreen = ({
|
||||
navigation,
|
||||
theme,
|
||||
themeCode,
|
||||
displayMode,
|
||||
itemsPerRow,
|
||||
switchTheme,
|
||||
@@ -41,6 +43,10 @@ const SettingsScreen = ({
|
||||
return label[displayMode];
|
||||
};
|
||||
|
||||
const theme = useTheme();
|
||||
|
||||
const dispatch = useDispatch();
|
||||
|
||||
// Display Mode Modal
|
||||
const [displayModalVisible, setDisplayModalVisible] = useState(false);
|
||||
const showDisplayModal = () => setDisplayModalVisible(true);
|
||||
@@ -77,7 +83,7 @@ const SettingsScreen = ({
|
||||
<ListItem
|
||||
title="Clear history"
|
||||
description="Delete reading history for all novels"
|
||||
onPress={() => deleteAllHistory()}
|
||||
onPress={() => dispatch(clearAllHistoryAction())}
|
||||
theme={theme}
|
||||
/>
|
||||
<Divider theme={theme} />
|
||||
@@ -102,6 +108,26 @@ const SettingsScreen = ({
|
||||
onPress={showthemeModal}
|
||||
theme={theme}
|
||||
/>
|
||||
<Divider theme={theme} />
|
||||
<ListSubHeader theme={theme}>Backup</ListSubHeader>
|
||||
<ListItem
|
||||
title="Create backup"
|
||||
description="Can be used to restore current library"
|
||||
onPress={createBackup}
|
||||
theme={theme}
|
||||
/>
|
||||
<ListItem
|
||||
title="Restore backup"
|
||||
description="Restore library from backup file"
|
||||
onPress={() => dispatch(restoreLibraryAction())}
|
||||
theme={theme}
|
||||
/>
|
||||
<InfoItem
|
||||
title="Create backup may not work on devices with Android 9 or lower."
|
||||
icon="information-outline"
|
||||
description="Restore library from backup file"
|
||||
theme={theme}
|
||||
/>
|
||||
</ListSection>
|
||||
<DisplayModeModal
|
||||
displayMode={displayMode}
|
||||
@@ -129,7 +155,6 @@ const SettingsScreen = ({
|
||||
};
|
||||
|
||||
const mapStateToProps = (state) => ({
|
||||
theme: state.themeReducer.theme,
|
||||
displayMode: state.settingsReducer.displayMode,
|
||||
itemsPerRow: state.settingsReducer.itemsPerRow,
|
||||
});
|
||||
@@ -0,0 +1,158 @@
|
||||
import React, { useState } from "react";
|
||||
import { View } from "react-native";
|
||||
import { Modal, Portal, Text, Button, Provider } from "react-native-paper";
|
||||
|
||||
import * as WebBrowser from "expo-web-browser";
|
||||
import {
|
||||
myAnimeListConfig,
|
||||
getAccessToken,
|
||||
malTokenWatcher,
|
||||
} from "../../Services/Trackers/myAnimeList";
|
||||
import { Appbar } from "../../Components/Appbar";
|
||||
|
||||
import { useSelector, useDispatch } from "react-redux";
|
||||
import {
|
||||
Divider,
|
||||
ListItem,
|
||||
ListSection,
|
||||
ListSubHeader,
|
||||
} from "../../Components/List";
|
||||
import { removeTracker, setTracker } from "../../redux/tracker/tracker.actions";
|
||||
|
||||
const TrackerScreen = ({ navigation }) => {
|
||||
const theme = useSelector((state) => state.settingsReducer.theme);
|
||||
const tracker = useSelector((state) => state.trackerReducer.tracker);
|
||||
const dispatch = useDispatch();
|
||||
|
||||
// Tracker Modal
|
||||
const [visible, setVisible] = useState(false);
|
||||
const showModal = () => setVisible(true);
|
||||
const hideModal = () => setVisible(false);
|
||||
|
||||
return (
|
||||
<Provider>
|
||||
<Appbar title="Tacking" onBackAction={() => navigation.goBack()} />
|
||||
<View
|
||||
style={{
|
||||
flex: 1,
|
||||
backgroundColor: theme.colorPrimaryDark,
|
||||
paddingVertical: 8,
|
||||
}}
|
||||
>
|
||||
<ListSection>
|
||||
<ListSubHeader theme={theme}>Services</ListSubHeader>
|
||||
<ListItem
|
||||
title="MyAnimeList"
|
||||
onPress={async () => {
|
||||
if (tracker) {
|
||||
showModal();
|
||||
} else {
|
||||
await WebBrowser.openAuthSessionAsync(
|
||||
myAnimeListConfig.authUrl,
|
||||
myAnimeListConfig.redirectUri
|
||||
).then((res) => {
|
||||
console.log(res.type);
|
||||
if (res.type === "success") {
|
||||
const { url } = res;
|
||||
|
||||
const codeExtractor = new RegExp(
|
||||
/=([^&]+)/
|
||||
);
|
||||
let code = url.match(codeExtractor);
|
||||
|
||||
console.log(code);
|
||||
|
||||
if (code) {
|
||||
code = code[1];
|
||||
getAccessToken(
|
||||
code,
|
||||
myAnimeListConfig.codeChallenge
|
||||
).then((objects) => {
|
||||
console.log(objects);
|
||||
dispatch(setTracker(objects));
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}}
|
||||
right={tracker && "check"}
|
||||
theme={theme}
|
||||
/>
|
||||
{tracker && tracker.expires_in < new Date(Date.now()) && (
|
||||
<>
|
||||
<Divider theme={theme} />
|
||||
<ListSubHeader theme={theme}>
|
||||
Settings
|
||||
</ListSubHeader>
|
||||
<ListItem
|
||||
title="Revalidate MyAnimeList"
|
||||
onPress={() => {
|
||||
const res = malTokenWatcher(tracker);
|
||||
dispatch(setTracker(res));
|
||||
}}
|
||||
theme={theme}
|
||||
/>
|
||||
</>
|
||||
)}
|
||||
</ListSection>
|
||||
|
||||
<Portal>
|
||||
<Modal
|
||||
visible={visible}
|
||||
onDismiss={hideModal}
|
||||
contentContainerStyle={{
|
||||
padding: 20,
|
||||
margin: 20,
|
||||
borderRadius: 6,
|
||||
backgroundColor: theme.colorPrimaryDark,
|
||||
}}
|
||||
>
|
||||
<Text
|
||||
style={{
|
||||
color: theme.textColorPrimary,
|
||||
fontSize: 20,
|
||||
}}
|
||||
>
|
||||
Log out from MyAnimeList?
|
||||
</Text>
|
||||
<View
|
||||
style={{
|
||||
flexDirection: "row",
|
||||
justifyContent: "flex-end",
|
||||
}}
|
||||
>
|
||||
<Button
|
||||
style={{ marginTop: 30 }}
|
||||
labelStyle={{
|
||||
color: theme.colorAccent,
|
||||
letterSpacing: 0,
|
||||
textTransform: "none",
|
||||
}}
|
||||
onPress={hideModal}
|
||||
>
|
||||
Cancel
|
||||
</Button>
|
||||
<Button
|
||||
style={{ marginTop: 30 }}
|
||||
labelStyle={{
|
||||
color: theme.colorAccent,
|
||||
letterSpacing: 0,
|
||||
textTransform: "none",
|
||||
}}
|
||||
onPress={() => {
|
||||
dispatch(removeTracker());
|
||||
hideModal();
|
||||
}}
|
||||
>
|
||||
Logout
|
||||
</Button>
|
||||
</View>
|
||||
</Modal>
|
||||
</Portal>
|
||||
</View>
|
||||
</Provider>
|
||||
);
|
||||
};
|
||||
|
||||
export default TrackerScreen;
|
||||
@@ -26,7 +26,7 @@ const DisplayModeModal = ({
|
||||
}
|
||||
mode="ios"
|
||||
uncheckedColor={theme.textColorSecondary}
|
||||
color={theme.colorAccentDark}
|
||||
color={theme.colorAccent}
|
||||
onPress={() => setDisplayMode(mode.displayMode)}
|
||||
/>
|
||||
));
|
||||
@@ -2,6 +2,7 @@ import React from "react";
|
||||
import { Text, StyleSheet } from "react-native";
|
||||
import { Portal, Modal } from "react-native-paper";
|
||||
import Slider from "@react-native-community/slider";
|
||||
import { RadioButton, RadioButtonGroup } from "../../../Components/RadioButton";
|
||||
|
||||
const GridSizeModal = ({
|
||||
itemsPerRow,
|
||||
@@ -10,6 +11,14 @@ const GridSizeModal = ({
|
||||
setItemsPerRow,
|
||||
theme,
|
||||
}) => {
|
||||
const gridSizes = {
|
||||
1: "XS",
|
||||
2: "S",
|
||||
3: "M",
|
||||
4: "L",
|
||||
5: "XL",
|
||||
};
|
||||
|
||||
return (
|
||||
<Portal>
|
||||
<Modal
|
||||
@@ -42,11 +51,24 @@ const GridSizeModal = ({
|
||||
minimumValue={1}
|
||||
maximumValue={5}
|
||||
step={1}
|
||||
minimumTrackTintColor={theme.colorAccentDark}
|
||||
minimumTrackTintColor={theme.colorAccent}
|
||||
maximumTrackTintColor="#000000"
|
||||
thumbTintColor={theme.colorAccentDark}
|
||||
thumbTintColor={theme.colorAccent}
|
||||
onValueChange={(value) => setItemsPerRow(value)}
|
||||
/>
|
||||
{/* <RadioButtonGroup
|
||||
onValueChange={(value) => setItemsPerRow(value)}
|
||||
value={itemsPerRow}
|
||||
>
|
||||
{Object.keys(gridSizes).map((item) => (
|
||||
<RadioButton
|
||||
key={item}
|
||||
value={item}
|
||||
label={gridSizes[item]}
|
||||
theme={theme}
|
||||
/>
|
||||
))}
|
||||
</RadioButtonGroup> */}
|
||||
</Modal>
|
||||
</Portal>
|
||||
);
|
||||
@@ -65,7 +87,7 @@ const styles = StyleSheet.create({
|
||||
marginBottom: 10,
|
||||
},
|
||||
modalDescription: {
|
||||
marginBottom: 4,
|
||||
marginBottom: 16,
|
||||
},
|
||||
slider: {
|
||||
width: "100%",
|
||||
@@ -15,6 +15,8 @@ const ThemeModal = ({
|
||||
{ id: 1, name: "Light", statusBar: "dark" },
|
||||
{ id: 2, name: "Dark", statusBar: "light" },
|
||||
{ id: 3, name: "Midnight Dusk", statusBar: "light" },
|
||||
{ id: 4, name: "Lime", statusBar: "light" },
|
||||
{ id: 5, name: "Iris Blue", statusBar: "light" },
|
||||
];
|
||||
|
||||
const renderThemeCheckboxes = () =>
|
||||
@@ -25,7 +27,7 @@ const ThemeModal = ({
|
||||
labelStyle={{ color: theme.textColorPrimary }}
|
||||
status={theme.id === item.id ? "checked" : "unchecked"}
|
||||
mode="ios"
|
||||
color={theme.colorAccentDark}
|
||||
color={theme.colorAccent}
|
||||
onPress={() => {
|
||||
switchTheme(item.id);
|
||||
setStatusBarStyle(item.statusBar);
|
||||
@@ -0,0 +1,168 @@
|
||||
import React, { useEffect, useRef, useState } from "react";
|
||||
import { StyleSheet, View, FlatList, RefreshControl } from "react-native";
|
||||
|
||||
import { Provider, Portal } from "react-native-paper";
|
||||
import { useDispatch } from "react-redux";
|
||||
|
||||
import {
|
||||
bookmarkChapterAction,
|
||||
getNovelAction,
|
||||
markChapterReadAction,
|
||||
markChapterUnreadAction,
|
||||
sortAndFilterChapters,
|
||||
updateNovelAction,
|
||||
} from "../../redux/novel/novel.actions";
|
||||
import {
|
||||
useContinueReading,
|
||||
useNovel,
|
||||
usePreferences,
|
||||
useTheme,
|
||||
} from "../../Hooks/reduxHooks";
|
||||
import { showToast } from "../../Hooks/showToast";
|
||||
|
||||
import ChapterItem from "./components/ChapterItem";
|
||||
import NovelInfoHeader from "./components/NovelHeader";
|
||||
import ChaptersSettingsSheet from "./components/ChaptersSettingsSheet";
|
||||
import TrackSheet from "./components/Tracker/TrackSheet";
|
||||
import ChapterActionsSheet from "./components/ChapterActionsSheet";
|
||||
|
||||
const Novel = ({ route, navigation }) => {
|
||||
const item = route.params;
|
||||
const { sourceId, novelUrl, novelName, followed, novelId } = item;
|
||||
|
||||
const theme = useTheme();
|
||||
const dispatch = useDispatch();
|
||||
const { novel, chapters, loading, updating, downloading } = useNovel();
|
||||
|
||||
const [selected, setSelected] = useState();
|
||||
|
||||
let chaptersSettingsSheetRef = useRef(null);
|
||||
let trackerSheetRef = useRef(null);
|
||||
let chapterActionsSheetRef = useRef(null);
|
||||
|
||||
const { sort = "ORDER BY chapterId ASC", filter = "" } = usePreferences(
|
||||
novel.novelId
|
||||
);
|
||||
|
||||
let { lastReadChapter, position } = useContinueReading(
|
||||
chapters,
|
||||
novel.novelId
|
||||
);
|
||||
|
||||
useEffect(() => {
|
||||
dispatch(
|
||||
getNovelAction(followed, sourceId, novelUrl, novelId, sort, filter)
|
||||
);
|
||||
}, [getNovelAction]);
|
||||
|
||||
const onRefresh = () => {
|
||||
dispatch(updateNovelAction(sourceId, novelUrl, novelId, sort, filter));
|
||||
showToast(`Updated ${novelName}`);
|
||||
};
|
||||
|
||||
const refreshControl = () => (
|
||||
<RefreshControl
|
||||
onRefresh={onRefresh}
|
||||
refreshing={updating}
|
||||
colors={[theme.textColorPrimary]}
|
||||
progressBackgroundColor={theme.colorPrimary}
|
||||
/>
|
||||
);
|
||||
|
||||
const renderItem = ({ item }) => (
|
||||
<ChapterItem
|
||||
theme={theme}
|
||||
chapter={item}
|
||||
novelUrl={novelUrl}
|
||||
dispatch={dispatch}
|
||||
sourceId={sourceId}
|
||||
navigation={navigation}
|
||||
lastReadChapter={lastReadChapter}
|
||||
position={position}
|
||||
downloading={downloading}
|
||||
selected={selected}
|
||||
setSelected={setSelected}
|
||||
chapterActionsSheetRef={chapterActionsSheetRef}
|
||||
/>
|
||||
);
|
||||
|
||||
return (
|
||||
<Provider>
|
||||
<View
|
||||
style={[
|
||||
styles.container,
|
||||
{ backgroundColor: theme.colorPrimaryDark },
|
||||
]}
|
||||
>
|
||||
<FlatList
|
||||
data={!loading && chapters}
|
||||
keyExtractor={(item) => item.chapterId.toString()}
|
||||
removeClippedSubviews={true}
|
||||
maxToRenderPerBatch={5}
|
||||
windowSize={15}
|
||||
initialNumToRender={7}
|
||||
renderItem={renderItem}
|
||||
ListHeaderComponent={
|
||||
<NovelInfoHeader
|
||||
item={item}
|
||||
novel={novel}
|
||||
theme={theme}
|
||||
filter={filter}
|
||||
loading={loading}
|
||||
lastRead={lastReadChapter}
|
||||
dispatch={dispatch}
|
||||
chapters={chapters}
|
||||
navigation={navigation}
|
||||
trackerSheetRef={trackerSheetRef}
|
||||
chaptersSettingsSheetRef={chaptersSettingsSheetRef}
|
||||
/>
|
||||
}
|
||||
refreshControl={refreshControl()}
|
||||
/>
|
||||
{!loading && (
|
||||
<Portal>
|
||||
<ChaptersSettingsSheet
|
||||
novelUrl={novelUrl}
|
||||
bottomSheetRef={chaptersSettingsSheetRef}
|
||||
dispatch={dispatch}
|
||||
sortAndFilterChapters={sortAndFilterChapters}
|
||||
novelId={novel.novelId}
|
||||
sort={sort}
|
||||
theme={theme}
|
||||
filter={filter}
|
||||
/>
|
||||
<TrackSheet
|
||||
bottomSheetRef={trackerSheetRef}
|
||||
novelId={novel.novelId}
|
||||
novelName={novel.novelName}
|
||||
theme={theme}
|
||||
/>
|
||||
<ChapterActionsSheet
|
||||
theme={theme}
|
||||
selected={selected}
|
||||
chapters={chapters}
|
||||
dispatch={dispatch}
|
||||
setSelected={setSelected}
|
||||
bottomSheetRef={chapterActionsSheetRef}
|
||||
markChapterReadAction={markChapterReadAction}
|
||||
markChapterUnreadAction={markChapterUnreadAction}
|
||||
bookmarkChapterAction={bookmarkChapterAction}
|
||||
/>
|
||||
</Portal>
|
||||
)}
|
||||
</View>
|
||||
</Provider>
|
||||
);
|
||||
};
|
||||
|
||||
export default Novel;
|
||||
|
||||
const styles = StyleSheet.create({
|
||||
container: { flex: 1 },
|
||||
rowBack: {
|
||||
alignItems: "center",
|
||||
flex: 1,
|
||||
flexDirection: "row",
|
||||
justifyContent: "space-between",
|
||||
},
|
||||
});
|
||||
@@ -0,0 +1,175 @@
|
||||
import React, { useState } from "react";
|
||||
import { StyleSheet, View, Text, Animated } from "react-native";
|
||||
import { List } from "react-native-paper";
|
||||
|
||||
import Bottomsheet from "rn-sliding-up-panel";
|
||||
import BottomSheetHandle from "../../../Components/BottomSheetHandle";
|
||||
import { ListItem } from "../../../Components/List";
|
||||
import {
|
||||
markPreviousChaptersReadAction,
|
||||
markPreviousChaptersUnreadAction,
|
||||
} from "../../../redux/novel/novel.actions";
|
||||
|
||||
const ChapterActionsSheet = ({
|
||||
bottomSheetRef,
|
||||
selected,
|
||||
theme,
|
||||
markChapterReadAction,
|
||||
markChapterUnreadAction,
|
||||
dispatch,
|
||||
bookmarkChapterAction,
|
||||
setSelected,
|
||||
}) => {
|
||||
const [animatedValue] = useState(new Animated.Value(0));
|
||||
|
||||
return (
|
||||
<Bottomsheet
|
||||
animatedValue={animatedValue}
|
||||
ref={bottomSheetRef}
|
||||
draggableRange={{ top: 270, bottom: 0 }}
|
||||
snappingPoints={[0, 270]}
|
||||
>
|
||||
<View
|
||||
style={[
|
||||
styles.contentContainer,
|
||||
{ backgroundColor: theme.colorPrimary },
|
||||
]}
|
||||
>
|
||||
<Text
|
||||
style={{
|
||||
color: theme.textColorPrimary,
|
||||
textAlign: "center",
|
||||
paddingTop: 16,
|
||||
paddingBottom: 8,
|
||||
fontSize: 16,
|
||||
}}
|
||||
>
|
||||
{selected?.chapterName}
|
||||
</Text>
|
||||
<List.Item
|
||||
title="Mark previous chapters as read"
|
||||
titleStyle={{ color: theme.textColorPrimary, fontSize: 15 }}
|
||||
left={() => (
|
||||
<List.Icon
|
||||
color={theme.textColorPrimary}
|
||||
icon="eye-check"
|
||||
style={{ marginVertical: 0 }}
|
||||
/>
|
||||
)}
|
||||
onPress={() => {
|
||||
dispatch(
|
||||
markPreviousChaptersReadAction(
|
||||
selected?.chapterId,
|
||||
selected?.novelId
|
||||
)
|
||||
);
|
||||
// bottomSheetRef.current.hide();
|
||||
}}
|
||||
rippleColor={theme.rippleColor}
|
||||
/>
|
||||
<List.Item
|
||||
title="Mark previous chapters as unread"
|
||||
titleStyle={{ color: theme.textColorPrimary, fontSize: 15 }}
|
||||
left={() => (
|
||||
<List.Icon
|
||||
color={theme.textColorPrimary}
|
||||
icon="eye-off"
|
||||
style={{ marginVertical: 0 }}
|
||||
/>
|
||||
)}
|
||||
onPress={() => {
|
||||
dispatch(
|
||||
markPreviousChaptersUnreadAction(
|
||||
selected?.chapterId,
|
||||
selected?.novelId
|
||||
)
|
||||
);
|
||||
// bottomSheetRef.current.hide();
|
||||
}}
|
||||
rippleColor={theme.rippleColor}
|
||||
/>
|
||||
<List.Item
|
||||
title={
|
||||
selected?.read
|
||||
? "Mark chapter as unread"
|
||||
: "Mark chapter as read"
|
||||
}
|
||||
titleStyle={{ color: theme.textColorPrimary, fontSize: 15 }}
|
||||
left={() => (
|
||||
<List.Icon
|
||||
color={theme.textColorPrimary}
|
||||
icon={selected?.read ? "eye-off" : "eye"}
|
||||
style={{ marginVertical: 0 }}
|
||||
/>
|
||||
)}
|
||||
onPress={() => {
|
||||
if (selected?.read) {
|
||||
dispatch(
|
||||
markChapterUnreadAction(selected?.chapterId)
|
||||
);
|
||||
setSelected((selected) => ({
|
||||
...selected,
|
||||
read: 0,
|
||||
}));
|
||||
} else {
|
||||
dispatch(
|
||||
markChapterReadAction(
|
||||
selected?.chapterId,
|
||||
selected?.novelId
|
||||
)
|
||||
);
|
||||
setSelected((selected) => ({
|
||||
...selected,
|
||||
read: 1,
|
||||
}));
|
||||
}
|
||||
// bottomSheetRef.current.hide();
|
||||
}}
|
||||
rippleColor={theme.rippleColor}
|
||||
/>
|
||||
<List.Item
|
||||
title={
|
||||
selected?.bookmark
|
||||
? "Remove bookmark"
|
||||
: "Bookmark chapter"
|
||||
}
|
||||
titleStyle={{ color: theme.textColorPrimary, fontSize: 15 }}
|
||||
left={() => (
|
||||
<List.Icon
|
||||
color={theme.textColorPrimary}
|
||||
icon={
|
||||
selected?.bookmark ? "bookmark-off" : "bookmark"
|
||||
}
|
||||
style={{ marginVertical: 0 }}
|
||||
/>
|
||||
)}
|
||||
onPress={() => {
|
||||
dispatch(
|
||||
bookmarkChapterAction(
|
||||
selected?.bookmark,
|
||||
selected?.chapterId
|
||||
)
|
||||
);
|
||||
setSelected((selected) => ({
|
||||
...selected,
|
||||
bookmark: !selected.bookmark,
|
||||
}));
|
||||
|
||||
// bottomSheetRef.current.hide();
|
||||
}}
|
||||
rippleColor={theme.rippleColor}
|
||||
/>
|
||||
</View>
|
||||
</Bottomsheet>
|
||||
);
|
||||
};
|
||||
|
||||
export default ChapterActionsSheet;
|
||||
|
||||
const styles = StyleSheet.create({
|
||||
contentContainer: {
|
||||
flex: 1,
|
||||
borderTopRightRadius: 8,
|
||||
borderTopLeftRadius: 8,
|
||||
},
|
||||
});
|
||||
@@ -0,0 +1,216 @@
|
||||
import React, { useState } from "react";
|
||||
import { View, Text, ActivityIndicator, StyleSheet } from "react-native";
|
||||
import { TouchableRipple, IconButton, Menu } from "react-native-paper";
|
||||
|
||||
import {
|
||||
deleteChapterAction,
|
||||
downloadChapterAction,
|
||||
} from "../../../redux/novel/novel.actions";
|
||||
|
||||
const ChapterItem = ({
|
||||
novelUrl,
|
||||
chapter,
|
||||
sourceId,
|
||||
dispatch,
|
||||
theme,
|
||||
navigation,
|
||||
downloading,
|
||||
position,
|
||||
setSelected,
|
||||
chapterActionsSheetRef,
|
||||
}) => {
|
||||
const [deleteChapterMenu, setDeleteChapterMenu] = useState(false);
|
||||
const showDeleteChapterMenu = () => setDeleteChapterMenu(true);
|
||||
const hideDeleteChapterMenu = () => setDeleteChapterMenu(false);
|
||||
|
||||
const navigateToChapter = () =>
|
||||
navigation.navigate("Chapter", {
|
||||
sourceId,
|
||||
novelUrl,
|
||||
novelId: chapter.novelId,
|
||||
chapterId: chapter.chapterId,
|
||||
chapterUrl: chapter.chapterUrl,
|
||||
chapterName: chapter.chapterName,
|
||||
position:
|
||||
(position &&
|
||||
position[chapter.chapterId] &&
|
||||
position[chapter.chapterId].position) ||
|
||||
0,
|
||||
});
|
||||
|
||||
const displayDownloadButton = () => {
|
||||
if (downloading.indexOf(chapter.chapterId) !== -1) {
|
||||
return (
|
||||
<ActivityIndicator
|
||||
color={theme.textColorHint}
|
||||
size={25}
|
||||
style={{ margin: 3.5, padding: 5 }}
|
||||
/>
|
||||
);
|
||||
} else if (chapter.downloaded === 1) {
|
||||
return (
|
||||
<Menu
|
||||
visible={deleteChapterMenu}
|
||||
onDismiss={hideDeleteChapterMenu}
|
||||
anchor={
|
||||
<IconButton
|
||||
icon="check-circle"
|
||||
animated
|
||||
color={theme.textColorPrimary}
|
||||
size={25}
|
||||
onPress={showDeleteChapterMenu}
|
||||
style={{ margin: 2 }}
|
||||
/>
|
||||
}
|
||||
contentStyle={{ backgroundColor: theme.menuColor }}
|
||||
>
|
||||
<Menu.Item
|
||||
onPress={() =>
|
||||
dispatch(
|
||||
deleteChapterAction(
|
||||
chapter.chapterId,
|
||||
chapter.chapterName
|
||||
)
|
||||
)
|
||||
}
|
||||
title="Delete"
|
||||
titleStyle={{ color: theme.textColorPrimary }}
|
||||
/>
|
||||
</Menu>
|
||||
);
|
||||
} else {
|
||||
return (
|
||||
<IconButton
|
||||
icon="arrow-down-circle-outline"
|
||||
animated
|
||||
color={theme.textColorHint}
|
||||
size={25}
|
||||
onPress={() =>
|
||||
dispatch(
|
||||
downloadChapterAction(
|
||||
sourceId,
|
||||
novelUrl,
|
||||
chapter.chapterUrl,
|
||||
chapter.chapterName,
|
||||
chapter.chapterId
|
||||
)
|
||||
)
|
||||
}
|
||||
style={{ margin: 2 }}
|
||||
/>
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
const bookmarkButton = () => {
|
||||
if (chapter.bookmark) {
|
||||
return (
|
||||
<IconButton
|
||||
icon="bookmark"
|
||||
color={theme.colorAccent}
|
||||
size={18}
|
||||
style={{ marginLeft: 2 }}
|
||||
/>
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<TouchableRipple
|
||||
style={[
|
||||
styles.chapterCardContainer,
|
||||
{ backgroundColor: theme.colorPrimaryDark },
|
||||
]}
|
||||
onPress={navigateToChapter}
|
||||
onLongPress={() => {
|
||||
setSelected(chapter);
|
||||
chapterActionsSheetRef.current.show();
|
||||
}}
|
||||
rippleColor={theme.rippleColor}
|
||||
>
|
||||
<>
|
||||
<View>
|
||||
<View
|
||||
style={{
|
||||
flexDirection: "row",
|
||||
alignItems: "center",
|
||||
}}
|
||||
>
|
||||
{bookmarkButton()}
|
||||
<View>
|
||||
<Text
|
||||
style={[
|
||||
{ color: theme.textColorPrimary },
|
||||
chapter.read && {
|
||||
color: theme.textColorHint,
|
||||
},
|
||||
]}
|
||||
numberOfLines={1}
|
||||
>
|
||||
{chapter.chapterName.substring(0, 50)}
|
||||
</Text>
|
||||
<View
|
||||
style={{
|
||||
flexDirection: "row",
|
||||
marginTop: 5,
|
||||
}}
|
||||
>
|
||||
{chapter.releaseDate && (
|
||||
<Text
|
||||
style={[
|
||||
{
|
||||
color: theme.textColorSecondary,
|
||||
fontSize: 12,
|
||||
},
|
||||
chapter.read && {
|
||||
color: theme.textColorHint,
|
||||
},
|
||||
]}
|
||||
numberOfLines={1}
|
||||
>
|
||||
{chapter.releaseDate}
|
||||
</Text>
|
||||
)}
|
||||
{position &&
|
||||
!chapter.read &&
|
||||
position[chapter.chapterId] &&
|
||||
position[chapter.chapterId].percentage <
|
||||
95 && (
|
||||
<Text
|
||||
style={[
|
||||
{
|
||||
color: theme.textColorSecondary,
|
||||
fontSize: 12,
|
||||
marginLeft: 0,
|
||||
},
|
||||
chapter.releaseDate && {
|
||||
marginLeft: 5,
|
||||
},
|
||||
]}
|
||||
numberOfLines={1}
|
||||
>
|
||||
{position[chapter.chapterId]
|
||||
.percentage + "%"}
|
||||
</Text>
|
||||
)}
|
||||
</View>
|
||||
</View>
|
||||
</View>
|
||||
</View>
|
||||
<View>{displayDownloadButton()}</View>
|
||||
</>
|
||||
</TouchableRipple>
|
||||
);
|
||||
};
|
||||
|
||||
export default ChapterItem;
|
||||
|
||||
const styles = StyleSheet.create({
|
||||
chapterCardContainer: {
|
||||
paddingHorizontal: 15,
|
||||
paddingVertical: 7,
|
||||
flexDirection: "row",
|
||||
justifyContent: "space-between",
|
||||
alignItems: "center",
|
||||
},
|
||||
});
|
||||
@@ -1,24 +1,32 @@
|
||||
import React, { useState } from "react";
|
||||
import { StyleSheet, View, Text } from "react-native";
|
||||
import { StyleSheet, View, Text, Animated } from "react-native";
|
||||
|
||||
import { List, RadioButton, Checkbox } from "react-native-paper";
|
||||
import Bottomsheet from "rn-sliding-up-panel";
|
||||
import BottomSheetHandle from "../../../Components/BottomSheetHandle";
|
||||
|
||||
import { useSelector } from "react-redux";
|
||||
|
||||
export const BottomSheet = ({
|
||||
const ChaptersSettingsSheet = ({
|
||||
bottomSheetRef,
|
||||
novelId,
|
||||
sortAndFilterChapters,
|
||||
dispatch,
|
||||
sort,
|
||||
filter,
|
||||
setSort,
|
||||
setFilter,
|
||||
novelUrl,
|
||||
theme,
|
||||
}) => {
|
||||
const sortChapters = (val) =>
|
||||
dispatch(sortAndFilterChapters(novelId, val, filter));
|
||||
|
||||
const filterChapters = (val) =>
|
||||
dispatch(sortAndFilterChapters(novelId, sort, val));
|
||||
|
||||
const checkBoxStyle = { flexDirection: "row", alignItems: "center" };
|
||||
|
||||
const theme = useSelector((state) => state.themeReducer.theme);
|
||||
const [animatedValue] = useState(new Animated.Value(0));
|
||||
|
||||
return (
|
||||
<Bottomsheet
|
||||
animatedValue={animatedValue}
|
||||
ref={bottomSheetRef}
|
||||
draggableRange={{ top: 370, bottom: 0 }}
|
||||
snappingPoints={[0, 370]}
|
||||
@@ -26,12 +34,10 @@ export const BottomSheet = ({
|
||||
<View
|
||||
style={[
|
||||
styles.contentContainer,
|
||||
{
|
||||
backgroundColor: theme.colorPrimary,
|
||||
},
|
||||
{ backgroundColor: theme.colorPrimary },
|
||||
]}
|
||||
>
|
||||
<View style={styles.bottomSheetHandle} />
|
||||
<BottomSheetHandle theme={theme} />
|
||||
<List.Subheader
|
||||
style={{
|
||||
color: theme.textColorPrimary,
|
||||
@@ -42,7 +48,9 @@ export const BottomSheet = ({
|
||||
</List.Subheader>
|
||||
<View>
|
||||
<RadioButton.Group
|
||||
onValueChange={(newValue) => setSort(newValue)}
|
||||
onValueChange={(newValue) =>
|
||||
sortChapters(newValue, filter)
|
||||
}
|
||||
value={sort}
|
||||
>
|
||||
<View
|
||||
@@ -58,8 +66,8 @@ export const BottomSheet = ({
|
||||
}}
|
||||
>
|
||||
<RadioButton.Item
|
||||
uncheckedColor={theme.textColorHintDark}
|
||||
color={theme.colorAccentDark}
|
||||
uncheckedColor={theme.textColorHint}
|
||||
color={theme.colorAccent}
|
||||
value="ORDER BY chapterId DESC"
|
||||
/>
|
||||
<Text
|
||||
@@ -77,8 +85,8 @@ export const BottomSheet = ({
|
||||
}}
|
||||
>
|
||||
<RadioButton.Item
|
||||
uncheckedColor={theme.textColorHintDark}
|
||||
color={theme.colorAccentDark}
|
||||
uncheckedColor={theme.textColorHint}
|
||||
color={theme.colorAccent}
|
||||
value="ORDER BY chapterId ASC"
|
||||
/>
|
||||
<Text
|
||||
@@ -105,9 +113,9 @@ export const BottomSheet = ({
|
||||
<View style={checkBoxStyle}>
|
||||
<Checkbox.Item
|
||||
status={filter === "" ? "checked" : "unchecked"}
|
||||
uncheckedColor={theme.textColorHintDark}
|
||||
color={theme.colorAccentDark}
|
||||
onPress={() => setFilter("")}
|
||||
uncheckedColor={theme.textColorHint}
|
||||
color={theme.colorAccent}
|
||||
onPress={() => filterChapters("")}
|
||||
/>
|
||||
<Text style={{ color: theme.textColorPrimary }}>
|
||||
Show all
|
||||
@@ -118,9 +126,9 @@ export const BottomSheet = ({
|
||||
status={
|
||||
filter === "AND `read`=1" ? "checked" : "unchecked"
|
||||
}
|
||||
uncheckedColor={theme.textColorHintDark}
|
||||
color={theme.colorAccentDark}
|
||||
onPress={() => setFilter("AND `read`=1")}
|
||||
uncheckedColor={theme.textColorHint}
|
||||
color={theme.colorAccent}
|
||||
onPress={() => filterChapters("AND `read`=1")}
|
||||
/>
|
||||
<Text style={{ color: theme.textColorPrimary }}>
|
||||
Show read chapters
|
||||
@@ -131,9 +139,9 @@ export const BottomSheet = ({
|
||||
status={
|
||||
filter === "AND `read`=0" ? "checked" : "unchecked"
|
||||
}
|
||||
uncheckedColor={theme.textColorHintDark}
|
||||
color={theme.colorAccentDark}
|
||||
onPress={() => setFilter("AND `read`=0")}
|
||||
uncheckedColor={theme.textColorHint}
|
||||
color={theme.colorAccent}
|
||||
onPress={() => filterChapters("AND `read`=0")}
|
||||
/>
|
||||
<Text style={{ color: theme.textColorPrimary }}>
|
||||
Show unread chapters
|
||||
@@ -146,9 +154,9 @@ export const BottomSheet = ({
|
||||
? "checked"
|
||||
: "unchecked"
|
||||
}
|
||||
uncheckedColor={theme.textColorHintDark}
|
||||
color={theme.colorAccentDark}
|
||||
onPress={() => setFilter("AND downloaded=1")}
|
||||
uncheckedColor={theme.textColorHint}
|
||||
color={theme.colorAccent}
|
||||
onPress={() => filterChapters("AND downloaded=1")}
|
||||
/>
|
||||
<Text style={{ color: theme.textColorPrimary }}>
|
||||
Show downloaded chapters
|
||||
@@ -159,18 +167,12 @@ export const BottomSheet = ({
|
||||
);
|
||||
};
|
||||
|
||||
export default ChaptersSettingsSheet;
|
||||
|
||||
const styles = StyleSheet.create({
|
||||
contentContainer: {
|
||||
flex: 1,
|
||||
borderTopRightRadius: 8,
|
||||
borderTopLeftRadius: 8,
|
||||
},
|
||||
bottomSheetHandle: {
|
||||
backgroundColor: "rgba(255,255,255,0.25)",
|
||||
height: 4,
|
||||
width: 50,
|
||||
borderRadius: 50,
|
||||
top: 10,
|
||||
alignSelf: "center",
|
||||
},
|
||||
});
|
||||
@@ -0,0 +1,49 @@
|
||||
import React from "react";
|
||||
import { StyleSheet } from "react-native";
|
||||
import { Chip } from "react-native-paper";
|
||||
import { MaterialCommunityIcons } from "@expo/vector-icons";
|
||||
|
||||
import { followNovelAction } from "../../../../redux/novel/novel.actions";
|
||||
|
||||
const FollowChip = ({ followed, novel, theme, dispatch }) => {
|
||||
const getIconName = () => (followed ? "heart" : "heart-outline");
|
||||
const getChipLabel = () => (followed ? "In Library" : "Add to library");
|
||||
|
||||
return (
|
||||
<Chip
|
||||
mode="outlined"
|
||||
icon={() => (
|
||||
<MaterialCommunityIcons
|
||||
name={getIconName()}
|
||||
size={21}
|
||||
color={theme.colorAccent}
|
||||
/>
|
||||
)}
|
||||
onPress={() => dispatch(followNovelAction(novel))}
|
||||
style={[
|
||||
{ backgroundColor: theme.colorPrimaryDark },
|
||||
styles.toggleFavourite,
|
||||
]}
|
||||
textStyle={{
|
||||
fontWeight: "bold",
|
||||
color: theme.textColorPrimary,
|
||||
}}
|
||||
>
|
||||
{getChipLabel()}
|
||||
</Chip>
|
||||
);
|
||||
};
|
||||
|
||||
export default FollowChip;
|
||||
|
||||
const styles = StyleSheet.create({
|
||||
toggleFavourite: {
|
||||
height: 32,
|
||||
justifyContent: "center",
|
||||
alignItems: "center",
|
||||
marginLeft: 16,
|
||||
paddingLeft: 4,
|
||||
borderWidth: 0,
|
||||
elevation: 0,
|
||||
},
|
||||
});
|
||||
@@ -0,0 +1,30 @@
|
||||
import React from "react";
|
||||
import { Text, StyleSheet } from "react-native";
|
||||
|
||||
export const GenreChip = ({ children, theme }) => (
|
||||
<Text
|
||||
style={[
|
||||
styles.genreChip,
|
||||
{
|
||||
color: theme.colorAccent,
|
||||
borderColor: theme.colorAccent,
|
||||
backgroundColor: theme.colorPrimary,
|
||||
},
|
||||
]}
|
||||
>
|
||||
{children}
|
||||
</Text>
|
||||
);
|
||||
|
||||
const styles = StyleSheet.create({
|
||||
genreChip: {
|
||||
flex: 1,
|
||||
justifyContent: "center",
|
||||
paddingVertical: 2,
|
||||
paddingHorizontal: 10,
|
||||
marginHorizontal: 2,
|
||||
fontSize: 13,
|
||||
borderWidth: 1,
|
||||
borderRadius: 50,
|
||||
},
|
||||
});
|
||||
@@ -0,0 +1,36 @@
|
||||
import React from "react";
|
||||
import { ImageBackground, StyleSheet } from "react-native";
|
||||
import { LinearGradient } from "expo-linear-gradient";
|
||||
import easeGradient from "react-native-easing-gradient";
|
||||
|
||||
const NovelCoverImage = ({ children, source, theme }) => {
|
||||
const { colors, locations } = easeGradient({
|
||||
colorStops: {
|
||||
0: {
|
||||
color: "rgba(0,0,0,0.2)",
|
||||
},
|
||||
1: {
|
||||
color: theme.colorPrimaryDark,
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
return (
|
||||
<ImageBackground source={source} style={styles.background}>
|
||||
<LinearGradient
|
||||
colors={colors}
|
||||
locations={locations}
|
||||
style={styles.linearGradient}
|
||||
>
|
||||
{children}
|
||||
</LinearGradient>
|
||||
</ImageBackground>
|
||||
);
|
||||
};
|
||||
|
||||
export default NovelCoverImage;
|
||||
|
||||
const styles = StyleSheet.create({
|
||||
background: { height: 285 },
|
||||
linearGradient: { height: 286 },
|
||||
});
|
||||
@@ -0,0 +1,66 @@
|
||||
import React, { useState } from "react";
|
||||
import { View, Text, StyleSheet } from "react-native";
|
||||
|
||||
const NovelSummary = ({ summary, followed, theme }) => {
|
||||
const [more, showMore] = useState(!followed);
|
||||
|
||||
return (
|
||||
summary !== "" && (
|
||||
<View style={styles.summaryContainer}>
|
||||
<Text
|
||||
style={[
|
||||
{ color: theme.textColorPrimary },
|
||||
styles.summaryHeader,
|
||||
]}
|
||||
>
|
||||
About
|
||||
</Text>
|
||||
<Text
|
||||
style={{
|
||||
color: theme.textColorSecondary,
|
||||
lineHeight: 20,
|
||||
}}
|
||||
numberOfLines={more ? 200 : 2}
|
||||
onPress={() => showMore(!more)}
|
||||
ellipsizeMode="clip"
|
||||
>
|
||||
{summary}
|
||||
</Text>
|
||||
<Text
|
||||
style={[
|
||||
{
|
||||
color: theme.colorAccent,
|
||||
backgroundColor: theme.colorPrimaryDark,
|
||||
},
|
||||
styles.showMoreButton,
|
||||
]}
|
||||
onPress={() => showMore(!more)}
|
||||
>
|
||||
{more ? "Less" : "More"}
|
||||
</Text>
|
||||
</View>
|
||||
)
|
||||
);
|
||||
};
|
||||
|
||||
export default NovelSummary;
|
||||
|
||||
const styles = StyleSheet.create({
|
||||
summaryContainer: {
|
||||
paddingHorizontal: 16,
|
||||
marginBottom: 8,
|
||||
},
|
||||
summaryHeader: {
|
||||
marginTop: 5,
|
||||
paddingVertical: 5,
|
||||
fontSize: 15,
|
||||
fontWeight: "bold",
|
||||
},
|
||||
showMoreButton: {
|
||||
fontWeight: "bold",
|
||||
position: "absolute",
|
||||
bottom: 0,
|
||||
right: 18,
|
||||
paddingLeft: 6,
|
||||
},
|
||||
});
|
||||
@@ -0,0 +1,56 @@
|
||||
import React from "react";
|
||||
import { StyleSheet } from "react-native";
|
||||
import { Button } from "react-native-paper";
|
||||
import { useContinueReading } from "../../../../Hooks/reduxHooks";
|
||||
|
||||
const ReadButton = ({ navigation, novel, chapters, theme, lastRead }) => {
|
||||
return (
|
||||
chapters.length > 0 &&
|
||||
(lastRead ? (
|
||||
<Button
|
||||
color="white"
|
||||
style={[
|
||||
{ backgroundColor: theme.colorAccent },
|
||||
styles.startButton,
|
||||
]}
|
||||
uppercase={false}
|
||||
labelStyle={{ letterSpacing: 0, color: theme.colorButtonText }}
|
||||
onPress={() => {
|
||||
navigation.navigate("Chapter", {
|
||||
chapterId: lastRead.chapterId,
|
||||
chapterUrl: lastRead.chapterUrl,
|
||||
novelUrl: novel.novelUrl,
|
||||
novelId: lastRead.novelId,
|
||||
sourceId: novel.sourceId,
|
||||
chapterName: lastRead.chapterName,
|
||||
});
|
||||
}}
|
||||
>
|
||||
{novel.unread ? `Start reading ` : `Continue reading `}
|
||||
{lastRead.chapterName}
|
||||
</Button>
|
||||
) : (
|
||||
<Button
|
||||
color={theme.textColorHint}
|
||||
style={[
|
||||
styles.startButton,
|
||||
{ backgroundColor: theme.colorDisabled },
|
||||
]}
|
||||
uppercase={false}
|
||||
labelStyle={{ letterSpacing: 0 }}
|
||||
>
|
||||
All chapters read
|
||||
</Button>
|
||||
))
|
||||
);
|
||||
};
|
||||
|
||||
export default ReadButton;
|
||||
|
||||
const styles = StyleSheet.create({
|
||||
startButton: {
|
||||
marginTop: 8,
|
||||
marginBottom: 16,
|
||||
marginHorizontal: 16,
|
||||
},
|
||||
});
|
||||
@@ -0,0 +1,47 @@
|
||||
import React from "react";
|
||||
import { StyleSheet } from "react-native";
|
||||
import { Chip } from "react-native-paper";
|
||||
import { MaterialCommunityIcons } from "@expo/vector-icons";
|
||||
|
||||
const TrackerChip = ({ isTracked, trackerSheetRef, theme }) => {
|
||||
const getIconName = () => (isTracked ? "check" : "sync");
|
||||
const getChipLabel = () => (isTracked ? "Tracked" : "Tracking");
|
||||
|
||||
return (
|
||||
<Chip
|
||||
mode="outlined"
|
||||
icon={() => (
|
||||
<MaterialCommunityIcons
|
||||
name={getIconName(isTracked)}
|
||||
size={21}
|
||||
color={theme.colorAccent}
|
||||
/>
|
||||
)}
|
||||
onPress={() => trackerSheetRef.current.show()}
|
||||
style={[
|
||||
styles.toggleFavourite,
|
||||
{ backgroundColor: theme.colorPrimaryDark },
|
||||
]}
|
||||
textStyle={{
|
||||
fontWeight: "bold",
|
||||
color: theme.textColorPrimary,
|
||||
}}
|
||||
>
|
||||
{getChipLabel()}
|
||||
</Chip>
|
||||
);
|
||||
};
|
||||
|
||||
export default TrackerChip;
|
||||
|
||||
const styles = StyleSheet.create({
|
||||
toggleFavourite: {
|
||||
height: 32,
|
||||
justifyContent: "center",
|
||||
alignItems: "center",
|
||||
paddingLeft: 4,
|
||||
marginLeft: 0,
|
||||
borderWidth: 0,
|
||||
elevation: 0,
|
||||
},
|
||||
});
|
||||
@@ -0,0 +1,286 @@
|
||||
import React, { useState } from "react";
|
||||
import { View, Text, StyleSheet, Image, FlatList, Share } from "react-native";
|
||||
import { TouchableRipple, IconButton, Button, Menu } from "react-native-paper";
|
||||
import { useNavigation } from "@react-navigation/native";
|
||||
import * as WebBrowser from "expo-web-browser";
|
||||
import { useSelector, useDispatch } from "react-redux";
|
||||
|
||||
import {
|
||||
downloadAllChaptersAction,
|
||||
deleteAllChaptersAction,
|
||||
} from "../../../redux/novel/novel.actions";
|
||||
import { GenreChip } from "./Info/GenreChip";
|
||||
import NovelCoverImage from "./Info/NovelCoverImage";
|
||||
import FollowChip from "./Info/FollowChip";
|
||||
import TrackerChip from "./Info/TrackerChip";
|
||||
import NovelSummary from "./Info/NovelSummary";
|
||||
import ReadButton from "./Info/ReadButton";
|
||||
import { useTrackingStatus } from "../../../Hooks/reduxHooks";
|
||||
|
||||
const NovelInfoHeader = ({
|
||||
item,
|
||||
novel,
|
||||
theme,
|
||||
filter,
|
||||
loading,
|
||||
dispatch,
|
||||
chapters,
|
||||
lastRead,
|
||||
navigation,
|
||||
trackerSheetRef,
|
||||
chaptersSettingsSheetRef,
|
||||
}) => {
|
||||
const [downloadMenu, showDownloadMenu] = useState(false);
|
||||
|
||||
const { tracker, trackedNovels } = useTrackingStatus();
|
||||
|
||||
let isTracked = false;
|
||||
|
||||
if (!loading) {
|
||||
isTracked = trackedNovels.find((obj) => obj.novelId === novel.novelId);
|
||||
}
|
||||
|
||||
const getGenres = ({ item }) => <GenreChip theme={theme}>{item}</GenreChip>;
|
||||
|
||||
return (
|
||||
<View style={{ flexGrow: 1 }}>
|
||||
<NovelCoverImage source={{ uri: item.novelCover }} theme={theme}>
|
||||
<View style={styles.detailsContainer}>
|
||||
<View>
|
||||
<Image
|
||||
source={{ uri: item.novelCover }}
|
||||
style={styles.logo}
|
||||
/>
|
||||
</View>
|
||||
<View style={styles.nameContainer}>
|
||||
<Text
|
||||
numberOfLines={2}
|
||||
style={[
|
||||
styles.name,
|
||||
{ color: theme.textColorPrimary },
|
||||
]}
|
||||
>
|
||||
{item.novelName}
|
||||
</Text>
|
||||
<>
|
||||
<Text
|
||||
style={{
|
||||
color: theme.textColorSecondary,
|
||||
marginVertical: 3,
|
||||
fontSize: 14,
|
||||
fontWeight: "bold",
|
||||
}}
|
||||
numberOfLines={2}
|
||||
>
|
||||
{(item.author &&
|
||||
item.author.replace(",", ", ")) ||
|
||||
(!loading &&
|
||||
novel.author.replace(",", ", "))}
|
||||
</Text>
|
||||
|
||||
<Text
|
||||
style={{
|
||||
color: theme.textColorSecondary,
|
||||
marginVertical: 3,
|
||||
fontSize: 14,
|
||||
}}
|
||||
numberOfLines={1}
|
||||
>
|
||||
{item.status || (!loading && novel.status)}
|
||||
</Text>
|
||||
<Text
|
||||
style={{
|
||||
color: theme.textColorSecondary,
|
||||
fontSize: 14,
|
||||
}}
|
||||
numberOfLines={1}
|
||||
>
|
||||
{item.source || (!loading && novel.source)}
|
||||
</Text>
|
||||
</>
|
||||
</View>
|
||||
</View>
|
||||
</NovelCoverImage>
|
||||
{!loading && (
|
||||
<>
|
||||
<View style={styles.buttonsContainer}>
|
||||
<FollowChip
|
||||
theme={theme}
|
||||
followed={novel.followed}
|
||||
novel={novel}
|
||||
dispatch={dispatch}
|
||||
/>
|
||||
{tracker && (
|
||||
<TrackerChip
|
||||
theme={theme}
|
||||
isTracked={isTracked}
|
||||
trackerSheetRef={trackerSheetRef}
|
||||
/>
|
||||
)}
|
||||
<IconButton
|
||||
onPress={() =>
|
||||
WebBrowser.openBrowserAsync(novel.sourceUrl)
|
||||
}
|
||||
icon="earth"
|
||||
color={theme.colorAccent}
|
||||
size={21}
|
||||
/>
|
||||
<IconButton
|
||||
onPress={() =>
|
||||
Share.share({ message: novel.sourceUrl })
|
||||
}
|
||||
icon="share-variant"
|
||||
color={theme.colorAccent}
|
||||
size={21}
|
||||
/>
|
||||
<Menu
|
||||
visible={downloadMenu}
|
||||
onDismiss={() => showDownloadMenu(false)}
|
||||
anchor={
|
||||
<IconButton
|
||||
icon="download"
|
||||
color={theme.colorAccent}
|
||||
size={21}
|
||||
onPress={() => showDownloadMenu(true)}
|
||||
/>
|
||||
}
|
||||
contentStyle={{ backgroundColor: theme.menuColor }}
|
||||
>
|
||||
<Menu.Item
|
||||
title="Download all"
|
||||
style={{ backgroundColor: theme.menuColor }}
|
||||
titleStyle={{ color: theme.textColorPrimary }}
|
||||
onPress={() =>
|
||||
dispatch(
|
||||
downloadAllChaptersAction(
|
||||
novel.sourceId,
|
||||
novel.novelUrl,
|
||||
chapters
|
||||
)
|
||||
)
|
||||
}
|
||||
/>
|
||||
<Menu.Item
|
||||
title="Delete downloads"
|
||||
style={{ backgroundColor: theme.menuColor }}
|
||||
titleStyle={{ color: theme.textColorPrimary }}
|
||||
onPress={() =>
|
||||
dispatch(deleteAllChaptersAction(chapters))
|
||||
}
|
||||
/>
|
||||
</Menu>
|
||||
{/* <IconButton
|
||||
onPress={() =>
|
||||
navigation.navigate("MigrateNovel", {
|
||||
sourceId: novel.sourceId,
|
||||
novelName: novel.novelName,
|
||||
})
|
||||
}
|
||||
icon="weather-cloudy-arrow-right"
|
||||
color={theme.colorAccent}
|
||||
size={21}
|
||||
/> */}
|
||||
</View>
|
||||
<NovelSummary
|
||||
summary={novel.novelSummary}
|
||||
followed={novel.followed}
|
||||
theme={theme}
|
||||
/>
|
||||
<FlatList
|
||||
style={
|
||||
novel.novelSummary === ""
|
||||
? { marginTop: 20 }
|
||||
: { marginTop: 12 }
|
||||
}
|
||||
contentContainerStyle={styles.genreContainer}
|
||||
horizontal
|
||||
data={novel.genre.split(",")}
|
||||
keyExtractor={(item) => item}
|
||||
renderItem={getGenres}
|
||||
showsHorizontalScrollIndicator={false}
|
||||
/>
|
||||
<ReadButton
|
||||
novel={novel}
|
||||
chapters={chapters}
|
||||
navigation={navigation}
|
||||
theme={theme}
|
||||
lastRead={lastRead}
|
||||
/>
|
||||
<TouchableRipple
|
||||
style={styles.bottomsheet}
|
||||
onPress={() => chaptersSettingsSheetRef.current.show()}
|
||||
rippleColor={theme.rippleColor}
|
||||
>
|
||||
<>
|
||||
<Text
|
||||
style={[
|
||||
{ color: theme.textColorPrimary },
|
||||
styles.chapters,
|
||||
]}
|
||||
>
|
||||
{`${chapters.length} Chapters`}
|
||||
</Text>
|
||||
<IconButton
|
||||
icon="filter-variant"
|
||||
color={
|
||||
filter
|
||||
? theme.filterColor
|
||||
: theme.textColorPrimary
|
||||
}
|
||||
size={24}
|
||||
/>
|
||||
</>
|
||||
</TouchableRipple>
|
||||
</>
|
||||
)}
|
||||
</View>
|
||||
);
|
||||
};
|
||||
|
||||
export default NovelInfoHeader;
|
||||
|
||||
const styles = StyleSheet.create({
|
||||
nameContainer: {
|
||||
flex: 1,
|
||||
marginHorizontal: 16,
|
||||
paddingTop: 8,
|
||||
},
|
||||
detailsContainer: {
|
||||
flex: 1,
|
||||
flexDirection: "row",
|
||||
margin: 16,
|
||||
paddingTop: 90,
|
||||
},
|
||||
logo: {
|
||||
height: 160,
|
||||
width: 110,
|
||||
margin: 3.2,
|
||||
borderRadius: 6,
|
||||
},
|
||||
name: {
|
||||
fontWeight: "bold",
|
||||
fontSize: 18,
|
||||
},
|
||||
buttonsContainer: {
|
||||
flexDirection: "row",
|
||||
alignItems: "center",
|
||||
},
|
||||
|
||||
chapters: {
|
||||
paddingHorizontal: 16,
|
||||
paddingVertical: 4,
|
||||
fontSize: 16,
|
||||
fontWeight: "bold",
|
||||
},
|
||||
bottomsheet: {
|
||||
flexDirection: "row",
|
||||
justifyContent: "space-between",
|
||||
alignItems: "center",
|
||||
paddingRight: 12,
|
||||
},
|
||||
|
||||
genreContainer: {
|
||||
paddingHorizontal: 15,
|
||||
paddingBottom: 15,
|
||||
},
|
||||
});
|
||||
@@ -0,0 +1,194 @@
|
||||
import React from "react";
|
||||
import { StyleSheet, View, Text, Image } from "react-native";
|
||||
import { TouchableRipple, IconButton } from "react-native-paper";
|
||||
import { useDispatch } from "react-redux";
|
||||
import { untrackNovel } from "../../../../redux/tracker/tracker.actions";
|
||||
|
||||
export const AddMalTrackingCard = ({ theme, setTrackSearchDialog }) => (
|
||||
<View
|
||||
style={[
|
||||
styles.addCardContainer,
|
||||
{ backgroundColor: theme.colorPrimary },
|
||||
]}
|
||||
>
|
||||
<Image
|
||||
source={require("../../../../../assets/mal.png")}
|
||||
style={styles.trackerIcon}
|
||||
/>
|
||||
<TouchableRipple
|
||||
style={styles.rippleContainer}
|
||||
borderless
|
||||
onPress={() => setTrackSearchDialog(true)}
|
||||
rippleColor={theme.colorAccent}
|
||||
>
|
||||
<Text
|
||||
style={{
|
||||
flex: 1,
|
||||
textAlignVertical: "center",
|
||||
color: theme.colorAccent,
|
||||
}}
|
||||
>
|
||||
Add Tracking
|
||||
</Text>
|
||||
</TouchableRipple>
|
||||
</View>
|
||||
);
|
||||
|
||||
export const MalTrackItemCard = ({
|
||||
trackItem,
|
||||
setTrackStatusDialog,
|
||||
setTrackChaptersDialog,
|
||||
setTrackScoreDialog,
|
||||
getStatus,
|
||||
theme,
|
||||
}) => {
|
||||
const dispatch = useDispatch();
|
||||
|
||||
return (
|
||||
<View
|
||||
style={[
|
||||
styles.cardContainer,
|
||||
{ backgroundColor: theme.colorPrimary },
|
||||
]}
|
||||
>
|
||||
<View
|
||||
style={[
|
||||
styles.titleContainer,
|
||||
{ borderBottomColor: theme.dividerColor },
|
||||
]}
|
||||
>
|
||||
<Image
|
||||
source={require("../../../../../assets/mal.png")}
|
||||
style={[styles.trackerIcon, { borderBottomLeftRadius: 0 }]}
|
||||
/>
|
||||
<View style={styles.listItemContainer}>
|
||||
<Text
|
||||
style={[
|
||||
styles.listItem,
|
||||
{ color: theme.textColorSecondary },
|
||||
]}
|
||||
>
|
||||
{trackItem.title}
|
||||
</Text>
|
||||
<IconButton
|
||||
icon="close"
|
||||
color={theme.textColorSecondary}
|
||||
size={21}
|
||||
onPress={() => dispatch(untrackNovel(trackItem.id))}
|
||||
/>
|
||||
</View>
|
||||
</View>
|
||||
<View style={{ height: 50, flexDirection: "row" }}>
|
||||
<TouchableRipple
|
||||
style={[
|
||||
styles.listItemLeft,
|
||||
{ borderRightColor: theme.dividerColor },
|
||||
]}
|
||||
borderless
|
||||
onPress={() => setTrackStatusDialog(true)}
|
||||
rippleColor={theme.rippleColor}
|
||||
>
|
||||
<Text
|
||||
style={[
|
||||
styles.listItem,
|
||||
{ color: theme.textColorSecondary },
|
||||
]}
|
||||
>
|
||||
{getStatus(trackItem.my_list_status.status)}
|
||||
</Text>
|
||||
</TouchableRipple>
|
||||
<TouchableRipple
|
||||
style={{ flex: 1 }}
|
||||
borderless
|
||||
onPress={() => setTrackChaptersDialog(true)}
|
||||
rippleColor={theme.rippleColor}
|
||||
>
|
||||
<Text
|
||||
style={[
|
||||
styles.listItem,
|
||||
{ color: theme.textColorSecondary },
|
||||
]}
|
||||
>
|
||||
{`${trackItem.my_list_status.num_chapters_read}/${
|
||||
trackItem.num_chapters !== 0
|
||||
? trackItem.num_chapters
|
||||
: "-"
|
||||
}`}
|
||||
</Text>
|
||||
</TouchableRipple>
|
||||
<TouchableRipple
|
||||
style={[
|
||||
styles.listItemRight,
|
||||
{ borderLeftColor: theme.dividerColor },
|
||||
]}
|
||||
borderless
|
||||
onPress={() => setTrackScoreDialog(true)}
|
||||
rippleColor={theme.rippleColor}
|
||||
>
|
||||
<Text
|
||||
style={[
|
||||
styles.listItem,
|
||||
{ color: theme.textColorSecondary },
|
||||
]}
|
||||
>
|
||||
{trackItem.my_list_status.score === 0
|
||||
? "-"
|
||||
: trackItem.my_list_status.score}
|
||||
</Text>
|
||||
</TouchableRipple>
|
||||
</View>
|
||||
</View>
|
||||
);
|
||||
};
|
||||
|
||||
const styles = StyleSheet.create({
|
||||
trackerIcon: {
|
||||
height: 50,
|
||||
width: 50,
|
||||
borderTopLeftRadius: 4,
|
||||
borderBottomLeftRadius: 4,
|
||||
},
|
||||
rippleContainer: {
|
||||
flex: 1,
|
||||
alignItems: "center",
|
||||
borderTopRightRadius: 4,
|
||||
borderBottomRightRadius: 4,
|
||||
},
|
||||
addCardContainer: {
|
||||
flexDirection: "row",
|
||||
alignItems: "center",
|
||||
margin: 8,
|
||||
borderRadius: 4,
|
||||
elevation: 2,
|
||||
},
|
||||
cardContainer: {
|
||||
margin: 8,
|
||||
elevation: 2,
|
||||
borderRadius: 4,
|
||||
},
|
||||
titleContainer: {
|
||||
flexDirection: "row",
|
||||
alignItems: "center",
|
||||
borderBottomWidth: 1,
|
||||
},
|
||||
listItemContainer: {
|
||||
flex: 1,
|
||||
flexDirection: "row",
|
||||
borderTopRightRadius: 4,
|
||||
},
|
||||
listItem: {
|
||||
flex: 1,
|
||||
textAlign: "center",
|
||||
textAlignVertical: "center",
|
||||
},
|
||||
listItemLeft: {
|
||||
flex: 1,
|
||||
borderRightWidth: 1,
|
||||
borderBottomLeftRadius: 4,
|
||||
},
|
||||
listItemRight: {
|
||||
flex: 1,
|
||||
borderLeftWidth: 1,
|
||||
borderBottomRightRadius: 4,
|
||||
},
|
||||
});
|
||||
@@ -0,0 +1,67 @@
|
||||
import React, { useState } from "react";
|
||||
import { StyleSheet, Text } from "react-native";
|
||||
import { Modal, TextInput } from "react-native-paper";
|
||||
import {
|
||||
RadioButton,
|
||||
RadioButtonGroup,
|
||||
} from "../../../../Components/RadioButton";
|
||||
|
||||
const SetTrackChaptersDialog = ({
|
||||
trackItem,
|
||||
trackChaptersDialog,
|
||||
setTrackChaptersDialog,
|
||||
updateTrackChapters,
|
||||
theme,
|
||||
}) => {
|
||||
const [trackChapters, setTrackChapters] = useState(
|
||||
trackItem.my_list_status.num_chapters_read
|
||||
);
|
||||
|
||||
return (
|
||||
<Modal
|
||||
visible={trackChaptersDialog}
|
||||
onDismiss={() => setTrackChaptersDialog(false)}
|
||||
contentContainerStyle={[
|
||||
styles.containerStyle,
|
||||
{ backgroundColor: theme.colorPrimary },
|
||||
]}
|
||||
>
|
||||
<Text
|
||||
style={[styles.dialogTitle, { color: theme.textColorPrimary }]}
|
||||
>
|
||||
Chapters
|
||||
</Text>
|
||||
<TextInput
|
||||
value={trackChapters.toString()}
|
||||
onChangeText={(text) => setTrackChapters(text ? +text : "")}
|
||||
onSubmitEditing={() => updateTrackChapters(trackChapters)}
|
||||
mode="outlined"
|
||||
keyboardType="numeric"
|
||||
theme={{
|
||||
colors: {
|
||||
primary: theme.colorAccent,
|
||||
placeholder: theme.textColorHint,
|
||||
text: theme.textColorPrimary,
|
||||
background: "transparent",
|
||||
},
|
||||
}}
|
||||
underlineColor={theme.textColorHint}
|
||||
dense
|
||||
/>
|
||||
</Modal>
|
||||
);
|
||||
};
|
||||
|
||||
export default SetTrackChaptersDialog;
|
||||
|
||||
const styles = StyleSheet.create({
|
||||
containerStyle: {
|
||||
margin: 30,
|
||||
padding: 20,
|
||||
borderRadius: 8,
|
||||
},
|
||||
dialogTitle: {
|
||||
fontSize: 18,
|
||||
marginBottom: 16,
|
||||
},
|
||||
});
|
||||
@@ -0,0 +1,78 @@
|
||||
import React from "react";
|
||||
import { StyleSheet, Text } from "react-native";
|
||||
import { Modal } from "react-native-paper";
|
||||
import {
|
||||
RadioButton,
|
||||
RadioButtonGroup,
|
||||
} from "../../../../Components/RadioButton";
|
||||
|
||||
const SetTrackScoreDialog = ({
|
||||
trackItem,
|
||||
trackScoreDialog,
|
||||
setTrackScoreDialog,
|
||||
updateTrackScore,
|
||||
theme,
|
||||
}) => {
|
||||
const getScoreLabel = (score) => {
|
||||
const myanimeListScores = {
|
||||
0: "No Score",
|
||||
1: "Apalling",
|
||||
2: "Horrible",
|
||||
3: "Very Bad",
|
||||
4: "Bad",
|
||||
5: "Average",
|
||||
6: "Fine",
|
||||
7: "Good",
|
||||
8: "Very Good",
|
||||
9: "Great",
|
||||
10: "Masterpiece",
|
||||
};
|
||||
|
||||
return `(${score}) ${myanimeListScores[score]}`;
|
||||
};
|
||||
|
||||
return (
|
||||
<Modal
|
||||
visible={trackScoreDialog}
|
||||
onDismiss={() => setTrackScoreDialog(false)}
|
||||
contentContainerStyle={[
|
||||
styles.containerStyle,
|
||||
{ backgroundColor: theme.colorPrimary },
|
||||
]}
|
||||
theme={{ colors: { backdrop: "rgba(0,0,0,0.25)" } }}
|
||||
>
|
||||
<Text
|
||||
style={[styles.dialogTitle, { color: theme.textColorPrimary }]}
|
||||
>
|
||||
Score
|
||||
</Text>
|
||||
<RadioButtonGroup
|
||||
onValueChange={updateTrackScore}
|
||||
value={trackItem.my_list_status.score}
|
||||
>
|
||||
{[...Array(11).keys()].map((item, index) => (
|
||||
<RadioButton
|
||||
key={index}
|
||||
value={item}
|
||||
label={getScoreLabel(item)}
|
||||
theme={theme}
|
||||
/>
|
||||
))}
|
||||
</RadioButtonGroup>
|
||||
</Modal>
|
||||
);
|
||||
};
|
||||
|
||||
export default SetTrackScoreDialog;
|
||||
|
||||
const styles = StyleSheet.create({
|
||||
containerStyle: {
|
||||
margin: 30,
|
||||
padding: 20,
|
||||
borderRadius: 8,
|
||||
},
|
||||
dialogTitle: {
|
||||
fontSize: 18,
|
||||
marginBottom: 16,
|
||||
},
|
||||
});
|
||||
@@ -0,0 +1,67 @@
|
||||
import React from "react";
|
||||
import { StyleSheet, Text } from "react-native";
|
||||
import { Modal } from "react-native-paper";
|
||||
import {
|
||||
RadioButton,
|
||||
RadioButtonGroup,
|
||||
} from "../../../../Components/RadioButton";
|
||||
|
||||
const SetTrackStatusDialog = ({
|
||||
trackItem,
|
||||
trackStatusDialog,
|
||||
setTrackStatusDialog,
|
||||
updateTrackStatus,
|
||||
theme,
|
||||
}) => {
|
||||
const myAnimeListStatus = {
|
||||
reading: "Reading",
|
||||
completed: "Completed",
|
||||
on_hold: "On Hold",
|
||||
dropped: "Dropped",
|
||||
plan_to_read: "Plan to read",
|
||||
};
|
||||
|
||||
return (
|
||||
<Modal
|
||||
visible={trackStatusDialog}
|
||||
onDismiss={() => setTrackStatusDialog(false)}
|
||||
contentContainerStyle={[
|
||||
styles.containerStyle,
|
||||
{ backgroundColor: theme.colorPrimary },
|
||||
]}
|
||||
>
|
||||
<Text
|
||||
style={[styles.dialogTitle, { color: theme.textColorPrimary }]}
|
||||
>
|
||||
Status
|
||||
</Text>
|
||||
<RadioButtonGroup
|
||||
onValueChange={updateTrackStatus}
|
||||
value={trackItem.my_list_status.status}
|
||||
>
|
||||
{Object.keys(myAnimeListStatus).map((key, index) => (
|
||||
<RadioButton
|
||||
key={index}
|
||||
value={key}
|
||||
label={myAnimeListStatus[key]}
|
||||
theme={theme}
|
||||
/>
|
||||
))}
|
||||
</RadioButtonGroup>
|
||||
</Modal>
|
||||
);
|
||||
};
|
||||
|
||||
export default SetTrackStatusDialog;
|
||||
|
||||
const styles = StyleSheet.create({
|
||||
containerStyle: {
|
||||
margin: 30,
|
||||
padding: 20,
|
||||
borderRadius: 8,
|
||||
},
|
||||
dialogTitle: {
|
||||
fontSize: 18,
|
||||
marginBottom: 16,
|
||||
},
|
||||
});
|
||||
@@ -0,0 +1,184 @@
|
||||
import React, { useEffect, useState } from "react";
|
||||
import { StyleSheet, Text, View, Image, ActivityIndicator } from "react-native";
|
||||
import { Button, Modal, TextInput, TouchableRipple } from "react-native-paper";
|
||||
import { searchNovels } from "../../../../Services/Trackers/myAnimeList";
|
||||
import { useSelector, useDispatch } from "react-redux";
|
||||
import { ScrollView } from "react-native-gesture-handler";
|
||||
import { trackNovel } from "../../../../redux/tracker/tracker.actions";
|
||||
|
||||
const TrackSearchDialog = ({
|
||||
trackSearchDialog,
|
||||
setTrackSearchDialog,
|
||||
novelId,
|
||||
novelName,
|
||||
theme,
|
||||
}) => {
|
||||
const [loading, setLoading] = useState(true);
|
||||
const [searchResults, setSearchResults] = useState([]);
|
||||
const [searchText, setSearchText] = useState(novelName);
|
||||
|
||||
const [selectedNovel, setSelectedNovel] = useState();
|
||||
|
||||
const tracker = useSelector((state) => state.trackerReducer.tracker);
|
||||
|
||||
const dispatch = useDispatch();
|
||||
|
||||
const getSearchresults = async () => {
|
||||
const res = await searchNovels(searchText, tracker.access_token);
|
||||
setSearchResults(res);
|
||||
setLoading(false);
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
trackSearchDialog && getSearchresults();
|
||||
}, [trackSearchDialog]);
|
||||
|
||||
const renderSearchResultCard = (item) => (
|
||||
<TouchableRipple
|
||||
style={[
|
||||
{ flexDirection: "row", borderRadius: 4, margin: 8 },
|
||||
selectedNovel &&
|
||||
selectedNovel.id === item.node.id && {
|
||||
backgroundColor: theme.rippleColor,
|
||||
},
|
||||
]}
|
||||
key={item.node.id}
|
||||
onPress={() => setSelectedNovel(item.node)}
|
||||
rippleColor={theme.rippleColor}
|
||||
borderless
|
||||
>
|
||||
<>
|
||||
<Image
|
||||
source={{ uri: item.node.main_picture.large }}
|
||||
style={{ height: 150, width: 100, borderRadius: 4 }}
|
||||
/>
|
||||
<Text
|
||||
style={{
|
||||
flex: 1,
|
||||
color: theme.textColorPrimary,
|
||||
marginLeft: 20,
|
||||
fontSize: 16,
|
||||
flexWrap: "wrap",
|
||||
padding: 8,
|
||||
paddingLeft: 0,
|
||||
}}
|
||||
>
|
||||
{item.node.title}
|
||||
</Text>
|
||||
</>
|
||||
</TouchableRipple>
|
||||
);
|
||||
|
||||
return (
|
||||
<Modal
|
||||
visible={trackSearchDialog}
|
||||
onDismiss={() => setTrackSearchDialog(false)}
|
||||
contentContainerStyle={[
|
||||
styles.containerStyle,
|
||||
{ backgroundColor: theme.colorPrimary },
|
||||
]}
|
||||
theme={{ colors: { backdrop: "rgba(0,0,0,0.25)" } }}
|
||||
>
|
||||
<TextInput
|
||||
value={searchText}
|
||||
onChangeText={(text) => setSearchText(text)}
|
||||
onSubmitEditing={getSearchresults}
|
||||
theme={{
|
||||
colors: {
|
||||
primary: theme.colorAccent,
|
||||
text: theme.textColorPrimary,
|
||||
background: "transparent",
|
||||
},
|
||||
}}
|
||||
underlineColor={theme.textColorHint}
|
||||
right={
|
||||
<TextInput.Icon
|
||||
color={theme.textColorSecondary}
|
||||
icon="close"
|
||||
onPress={() => setSearchText("")}
|
||||
/>
|
||||
}
|
||||
/>
|
||||
<ScrollView
|
||||
style={{ flexGrow: 1, maxHeight: 500, marginVertical: 8 }}
|
||||
>
|
||||
{loading ? (
|
||||
<ActivityIndicator
|
||||
color={theme.colorAccent}
|
||||
size={45}
|
||||
style={{ margin: 16 }}
|
||||
/>
|
||||
) : (
|
||||
searchResults &&
|
||||
searchResults.data &&
|
||||
searchResults.data.map((result) =>
|
||||
renderSearchResultCard(result)
|
||||
)
|
||||
)}
|
||||
</ScrollView>
|
||||
<View
|
||||
style={{
|
||||
flexDirection: "row",
|
||||
justifyContent: "space-between",
|
||||
marginTop: 30,
|
||||
}}
|
||||
>
|
||||
<Button
|
||||
labelStyle={{
|
||||
color: theme.colorAccent,
|
||||
letterSpacing: 0,
|
||||
textTransform: "none",
|
||||
}}
|
||||
theme={{ colors: { primary: theme.colorAccent } }}
|
||||
onPress={() => setSelectedNovel(null)}
|
||||
>
|
||||
Remove
|
||||
</Button>
|
||||
<View style={{ flexDirection: "row" }}>
|
||||
<Button
|
||||
labelStyle={{
|
||||
color: theme.colorAccent,
|
||||
letterSpacing: 0,
|
||||
textTransform: "none",
|
||||
}}
|
||||
theme={{ colors: { primary: theme.colorAccent } }}
|
||||
onPress={() => setTrackSearchDialog(false)}
|
||||
>
|
||||
Cancel
|
||||
</Button>
|
||||
<Button
|
||||
labelStyle={{
|
||||
color: theme.colorAccent,
|
||||
letterSpacing: 0,
|
||||
textTransform: "none",
|
||||
}}
|
||||
theme={{ colors: { primary: theme.colorAccent } }}
|
||||
onPress={() => {
|
||||
if (selectedNovel) {
|
||||
dispatch(
|
||||
trackNovel(
|
||||
{ ...selectedNovel, novelId },
|
||||
tracker.access_token
|
||||
)
|
||||
);
|
||||
}
|
||||
setTrackSearchDialog(false);
|
||||
}}
|
||||
>
|
||||
OK
|
||||
</Button>
|
||||
</View>
|
||||
</View>
|
||||
</Modal>
|
||||
);
|
||||
};
|
||||
|
||||
export default TrackSearchDialog;
|
||||
|
||||
const styles = StyleSheet.create({
|
||||
containerStyle: {
|
||||
padding: 20,
|
||||
margin: 20,
|
||||
borderRadius: 6,
|
||||
},
|
||||
});
|
||||
@@ -0,0 +1,180 @@
|
||||
import React, { useState, useEffect } from "react";
|
||||
import { StyleSheet, View, ToastAndroid } from "react-native";
|
||||
import { Portal } from "react-native-paper";
|
||||
import Bottomsheet from "rn-sliding-up-panel";
|
||||
|
||||
import { useSelector, useDispatch } from "react-redux";
|
||||
import { updateTracker } from "../../../../redux/tracker/tracker.actions";
|
||||
|
||||
import TrackSearchDialog from "./TrackSearchDialog";
|
||||
import SetTrackStatusDialog from "./SetTrackStatusDialog";
|
||||
import SetTrackScoreDialog from "./SetTrackScoreDialog";
|
||||
import SetTrackChaptersDialog from "./SetTrackChaptersDialog";
|
||||
import { AddMalTrackingCard, MalTrackItemCard } from "./MyAnimeListCards";
|
||||
|
||||
const TrackSheet = ({ bottomSheetRef, novelId, novelName, theme }) => {
|
||||
const tracker = useSelector((state) => state.trackerReducer.tracker);
|
||||
const trackedNovels = useSelector(
|
||||
(state) => state.trackerReducer.trackedNovels
|
||||
);
|
||||
const dispatch = useDispatch();
|
||||
|
||||
const [trackItem, setTrackItem] = useState();
|
||||
|
||||
useEffect(() => {
|
||||
setTrackItem(trackedNovels.find((obj) => obj.novelId === novelId));
|
||||
}, [trackedNovels, novelId]);
|
||||
|
||||
const [trackSearchDialog, setTrackSearchDialog] = useState(false);
|
||||
const [trackStatusDialog, setTrackStatusDialog] = useState(false);
|
||||
const [trackChaptersDialog, setTrackChaptersDialog] = useState(false);
|
||||
const [trackScoreDialog, setTrackScoreDialog] = useState(false);
|
||||
|
||||
const getStatus = (status) => {
|
||||
const myAnimeListStatus = {
|
||||
reading: "Reading",
|
||||
completed: "Completed",
|
||||
on_hold: "On Hold",
|
||||
dropped: "Dropped",
|
||||
plan_to_read: "Plan to read",
|
||||
};
|
||||
|
||||
return myAnimeListStatus[status];
|
||||
};
|
||||
|
||||
const updateTrackChapters = (newChapters) => {
|
||||
if (newChapters !== "") {
|
||||
setTrackItem({
|
||||
...trackItem,
|
||||
my_list_status: {
|
||||
...trackItem.my_list_status,
|
||||
num_chapters_read: newChapters,
|
||||
},
|
||||
});
|
||||
|
||||
dispatch(
|
||||
updateTracker(trackItem.id, tracker.access_token, {
|
||||
...trackItem.my_list_status,
|
||||
num_chapters_read: newChapters,
|
||||
})
|
||||
);
|
||||
|
||||
setTrackChaptersDialog(false);
|
||||
} else {
|
||||
ToastAndroid.show("Enter a valid number", ToastAndroid.SHORT);
|
||||
}
|
||||
};
|
||||
|
||||
const updateTrackStatus = (newStatus) => {
|
||||
setTrackItem({
|
||||
...trackItem,
|
||||
my_list_status: {
|
||||
...trackItem.my_list_status,
|
||||
status: newStatus,
|
||||
},
|
||||
});
|
||||
|
||||
dispatch(
|
||||
updateTracker(trackItem.id, tracker.access_token, {
|
||||
...trackItem.my_list_status,
|
||||
status: newStatus,
|
||||
})
|
||||
);
|
||||
|
||||
setTrackStatusDialog(false);
|
||||
};
|
||||
|
||||
const updateTrackScore = (newScore) => {
|
||||
setTrackItem({
|
||||
...trackItem,
|
||||
my_list_status: {
|
||||
...trackItem.my_list_status,
|
||||
score: newScore,
|
||||
},
|
||||
});
|
||||
|
||||
dispatch(
|
||||
updateTracker(trackItem.id, tracker.access_token, {
|
||||
...trackItem.my_list_status,
|
||||
score: newScore,
|
||||
})
|
||||
);
|
||||
|
||||
setTrackScoreDialog(false);
|
||||
};
|
||||
|
||||
return (
|
||||
<>
|
||||
<Bottomsheet
|
||||
ref={bottomSheetRef}
|
||||
draggableRange={{ top: 120, bottom: 0 }}
|
||||
snappingPoints={[0, 120]}
|
||||
backdropOpacity={0.25}
|
||||
>
|
||||
<View
|
||||
style={[
|
||||
styles.contentContainer,
|
||||
{ backgroundColor: theme.colorPrimary },
|
||||
]}
|
||||
>
|
||||
{!trackItem ? (
|
||||
<AddMalTrackingCard
|
||||
theme={theme}
|
||||
setTrackSearchDialog={setTrackSearchDialog}
|
||||
/>
|
||||
) : (
|
||||
<MalTrackItemCard
|
||||
trackItem={trackItem}
|
||||
setTrackStatusDialog={setTrackStatusDialog}
|
||||
setTrackChaptersDialog={setTrackChaptersDialog}
|
||||
setTrackScoreDialog={setTrackScoreDialog}
|
||||
theme={theme}
|
||||
getStatus={getStatus}
|
||||
/>
|
||||
)}
|
||||
</View>
|
||||
</Bottomsheet>
|
||||
<Portal>
|
||||
{trackItem ? (
|
||||
<>
|
||||
<SetTrackStatusDialog
|
||||
trackItem={trackItem}
|
||||
trackStatusDialog={trackStatusDialog}
|
||||
setTrackStatusDialog={setTrackStatusDialog}
|
||||
updateTrackStatus={updateTrackStatus}
|
||||
theme={theme}
|
||||
/>
|
||||
<SetTrackChaptersDialog
|
||||
trackItem={trackItem}
|
||||
trackChaptersDialog={trackChaptersDialog}
|
||||
setTrackChaptersDialog={setTrackChaptersDialog}
|
||||
updateTrackChapters={updateTrackChapters}
|
||||
theme={theme}
|
||||
/>
|
||||
<SetTrackScoreDialog
|
||||
trackItem={trackItem}
|
||||
trackScoreDialog={trackScoreDialog}
|
||||
setTrackScoreDialog={setTrackScoreDialog}
|
||||
updateTrackScore={updateTrackScore}
|
||||
theme={theme}
|
||||
/>
|
||||
</>
|
||||
) : (
|
||||
<TrackSearchDialog
|
||||
trackSearchDialog={trackSearchDialog}
|
||||
setTrackSearchDialog={setTrackSearchDialog}
|
||||
novelId={novelId}
|
||||
novelName={novelName}
|
||||
theme={theme}
|
||||
/>
|
||||
)}
|
||||
</Portal>
|
||||
</>
|
||||
);
|
||||
};
|
||||
|
||||
export default TrackSheet;
|
||||
|
||||
const styles = StyleSheet.create({
|
||||
contentContainer: { flex: 1 },
|
||||
});
|
||||
@@ -0,0 +1,120 @@
|
||||
import React, { useState, useEffect, useCallback } from "react";
|
||||
import {
|
||||
StyleSheet,
|
||||
View,
|
||||
FlatList,
|
||||
ActivityIndicator,
|
||||
RefreshControl,
|
||||
} from "react-native";
|
||||
import { useFocusEffect } from "@react-navigation/native";
|
||||
import { useDispatch, useSelector } from "react-redux";
|
||||
import EmptyView from "../../Components/EmptyView";
|
||||
import {
|
||||
getUpdatesAction,
|
||||
updateLibraryAction,
|
||||
} from "../../redux/updates/updates.actions";
|
||||
import { Appbar } from "./components/Appbar";
|
||||
import UpdatesItem from "./components/UpdatesItem";
|
||||
import { useTheme } from "../../Hooks/reduxHooks";
|
||||
import { Searchbar } from "../../Components/Searchbar";
|
||||
|
||||
const Updates = ({ navigation }) => {
|
||||
const theme = useTheme();
|
||||
const dispatch = useDispatch();
|
||||
const { updates, loading } = useSelector((state) => state.updatesReducer);
|
||||
|
||||
const [searchText, setSearchText] = useState("");
|
||||
const [searchResults, setSearchResults] = useState([]);
|
||||
const [refreshing, setRefreshing] = useState(false);
|
||||
|
||||
useFocusEffect(
|
||||
useCallback(() => {
|
||||
dispatch(getUpdatesAction());
|
||||
}, [getUpdatesAction])
|
||||
);
|
||||
|
||||
const onRefresh = async () => {
|
||||
setRefreshing(true);
|
||||
dispatch(updateLibraryAction());
|
||||
setRefreshing(false);
|
||||
};
|
||||
|
||||
const onPress = (item) =>
|
||||
navigation.navigate("Chapter", {
|
||||
chapterId: item.chapterId,
|
||||
chapterUrl: item.chapterUrl,
|
||||
sourceId: item.sourceId,
|
||||
novelUrl: item.novelUrl,
|
||||
chapterName: item.chapterName,
|
||||
novelId: item.novelId,
|
||||
});
|
||||
|
||||
const renderItem = ({ item }) => (
|
||||
<UpdatesItem item={item} theme={theme} onPress={() => onPress(item)} />
|
||||
);
|
||||
|
||||
const ListFooterComponent = () =>
|
||||
loading && <ActivityIndicator size="small" color={theme.colorAccent} />;
|
||||
|
||||
const ListEmptyComponent = () =>
|
||||
!loading && (
|
||||
<EmptyView icon="(˘・_・˘)" description="No recent updates" />
|
||||
);
|
||||
|
||||
const refreshControl = () => (
|
||||
<RefreshControl
|
||||
refreshing={refreshing}
|
||||
onRefresh={onRefresh}
|
||||
colors={["white"]}
|
||||
progressBackgroundColor={theme.colorAccent}
|
||||
/>
|
||||
);
|
||||
|
||||
const clearSearchbar = () => {
|
||||
setSearchText("");
|
||||
};
|
||||
|
||||
const onChangeText = (text) => {
|
||||
setSearchText(text);
|
||||
let results = updates.filter((update) =>
|
||||
update.novelName.toLowerCase().includes(text.toLowerCase())
|
||||
);
|
||||
setSearchResults(results);
|
||||
};
|
||||
|
||||
return (
|
||||
<View
|
||||
style={[
|
||||
styles.container,
|
||||
{ backgroundColor: theme.colorPrimaryDark },
|
||||
]}
|
||||
>
|
||||
<Searchbar
|
||||
placeholder="Search Updates"
|
||||
searchText={searchText}
|
||||
clearSearchbar={clearSearchbar}
|
||||
onChangeText={onChangeText}
|
||||
left="magnify"
|
||||
theme={theme}
|
||||
right="reload"
|
||||
onPressRight={() => dispatch(updateLibraryAction())}
|
||||
/>
|
||||
<FlatList
|
||||
contentContainerStyle={styles.flatList}
|
||||
data={searchText ? searchResults : updates}
|
||||
keyExtractor={(item) => item.updateId.toString()}
|
||||
renderItem={renderItem}
|
||||
ListFooterComponent={ListFooterComponent()}
|
||||
ListEmptyComponent={ListEmptyComponent()}
|
||||
refreshControl={refreshControl()}
|
||||
/>
|
||||
</View>
|
||||
);
|
||||
};
|
||||
|
||||
export default Updates;
|
||||
|
||||
const styles = StyleSheet.create({
|
||||
container: { flex: 1 },
|
||||
flatList: { flexGrow: 1, paddingVertical: 8 },
|
||||
});
|
||||
@@ -0,0 +1,17 @@
|
||||
import React from "react";
|
||||
import { Appbar as MaterialAppbar } from "react-native-paper";
|
||||
|
||||
import { updateLibraryAction } from "../../../redux/updates/updates.actions";
|
||||
|
||||
export const Appbar = ({ theme, dispatch }) => (
|
||||
<MaterialAppbar.Header style={{ backgroundColor: theme.colorPrimary }}>
|
||||
<MaterialAppbar.Content
|
||||
title="Updates"
|
||||
titleStyle={{ color: theme.textColorPrimary }}
|
||||
/>
|
||||
<MaterialAppbar.Action
|
||||
icon="reload"
|
||||
onPress={() => dispatch(updateLibraryAction())}
|
||||
/>
|
||||
</MaterialAppbar.Header>
|
||||
);
|
||||
@@ -0,0 +1,66 @@
|
||||
import React from "react";
|
||||
import { View, Text, Image, StyleSheet } from "react-native";
|
||||
import { TouchableRipple } from "react-native-paper";
|
||||
import moment from "moment";
|
||||
|
||||
const UpdateCard = ({ item, theme, onPress }) => {
|
||||
return (
|
||||
<TouchableRipple
|
||||
style={styles.updateCard}
|
||||
onPress={onPress}
|
||||
rippleColor={theme.rippleColor}
|
||||
borderless
|
||||
>
|
||||
<>
|
||||
<Image
|
||||
source={{ uri: item.novelCover }}
|
||||
style={styles.updateIcon}
|
||||
/>
|
||||
<View style={styles.chapterDetails}>
|
||||
<Text
|
||||
style={{
|
||||
color: theme.textColorPrimary,
|
||||
fontSize: 14,
|
||||
}}
|
||||
numberOfLines={1}
|
||||
>
|
||||
{item.novelName}
|
||||
</Text>
|
||||
<View style={{ flexDirection: "row" }}>
|
||||
<Text
|
||||
style={{
|
||||
color: theme.textColorPrimary,
|
||||
fontSize: 12,
|
||||
}}
|
||||
numberOfLines={1}
|
||||
>
|
||||
{`${item.chapterName} · ${moment(
|
||||
item.updateTime
|
||||
).calendar()}`}
|
||||
</Text>
|
||||
</View>
|
||||
</View>
|
||||
</>
|
||||
</TouchableRipple>
|
||||
);
|
||||
};
|
||||
|
||||
export default UpdateCard;
|
||||
|
||||
const styles = StyleSheet.create({
|
||||
updateCard: {
|
||||
flexDirection: "row",
|
||||
alignItems: "center",
|
||||
paddingVertical: 8,
|
||||
paddingHorizontal: 12,
|
||||
},
|
||||
updateIcon: {
|
||||
width: 42,
|
||||
height: 42,
|
||||
borderRadius: 4,
|
||||
},
|
||||
chapterDetails: {
|
||||
flex: 1,
|
||||
marginLeft: 16,
|
||||
},
|
||||
});
|
||||
@@ -1,5 +1,7 @@
|
||||
import { showToast } from "../../Hooks/showToast";
|
||||
|
||||
export const fetchSources = async () => {
|
||||
const url = `https://lnreader-extensions.herokuapp.com/api/`;
|
||||
const url = `https://lnreader-extensions.vercel.app/api/`;
|
||||
|
||||
let res = await fetch(url);
|
||||
let sources = await res.json();
|
||||
@@ -8,7 +10,7 @@ export const fetchSources = async () => {
|
||||
};
|
||||
|
||||
export const fetchNovel = async (sourceId, novelUrl) => {
|
||||
const url = `https://lnreader-extensions.herokuapp.com/api/${sourceId}/novel/${novelUrl}`;
|
||||
const url = `https://lnreader-extensions.vercel.app/api/${sourceId}/novel/${novelUrl}`;
|
||||
|
||||
let data = await fetch(url);
|
||||
let res = await data.json();
|
||||
@@ -33,10 +35,21 @@ export const fetchNovel = async (sourceId, novelUrl) => {
|
||||
};
|
||||
|
||||
export const fetchChapter = async (sourceId, novelUrl, chapterUrl) => {
|
||||
const url = `https://lnreader-extensions.herokuapp.com/api/${sourceId}/novel/${novelUrl}${chapterUrl}`;
|
||||
const url = `https://lnreader-extensions.vercel.app/api/${sourceId}/novel/${novelUrl}${chapterUrl}`;
|
||||
|
||||
let res = await fetch(url);
|
||||
let chapter = await res.json();
|
||||
|
||||
return chapter;
|
||||
};
|
||||
|
||||
export const fetchChapters = async (sourceId, novelUrl) => {
|
||||
const url = `https://lnreader-extensions.vercel.app/api/${sourceId}/novel/${novelUrl}`;
|
||||
|
||||
let data = await fetch(url);
|
||||
let res = await data.json();
|
||||
|
||||
const chapters = res.novelChapters;
|
||||
|
||||
return chapters;
|
||||
};
|
||||
@@ -0,0 +1,171 @@
|
||||
import * as Linking from "expo-linking";
|
||||
import qs from "qs";
|
||||
|
||||
const clientId = "d2f499825d64b0213bb77e78193ccbb1";
|
||||
|
||||
const baseOAuthUrl = "https://myanimelist.net/v1/oauth2/authorize";
|
||||
const baseApiUrl = "https://api.myanimelist.net/v2";
|
||||
|
||||
const pkceChallenger = () => {
|
||||
const MAX_LENGTH = 88;
|
||||
let code = "";
|
||||
|
||||
const codes =
|
||||
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
|
||||
|
||||
const randomPicker = () => Math.floor(Math.random() * codes.length);
|
||||
|
||||
for (let index = 0; index < MAX_LENGTH; index++) {
|
||||
code += codes.charAt(randomPicker());
|
||||
}
|
||||
return code;
|
||||
};
|
||||
|
||||
const codeChallenge = pkceChallenger();
|
||||
|
||||
const redirectUri = Linking.makeUrl();
|
||||
|
||||
export const authUrl = `${baseOAuthUrl}?response_type=code&client_id=${clientId}&code_challenge_method=plain&code_challenge=${codeChallenge}`;
|
||||
|
||||
const tokenUrl = `https://myanimelist.net/v1/oauth2/token`;
|
||||
|
||||
export const myAnimeListConfig = {
|
||||
clientId,
|
||||
redirectUri,
|
||||
authUrl,
|
||||
codeChallenge,
|
||||
tokenUrl,
|
||||
};
|
||||
|
||||
export const getAccessToken = async (code, codeChallenge) => {
|
||||
const headers = {
|
||||
"Content-Type": "application/x-www-form-urlencoded",
|
||||
};
|
||||
|
||||
const body = {
|
||||
client_id: myAnimeListConfig.clientId,
|
||||
grant_type: "authorization_code",
|
||||
code,
|
||||
code_verifier: codeChallenge,
|
||||
};
|
||||
|
||||
const response = await fetch(myAnimeListConfig.tokenUrl, {
|
||||
headers,
|
||||
method: "POST",
|
||||
body: qs.stringify(body),
|
||||
});
|
||||
|
||||
let tokenResponse = await response.json();
|
||||
|
||||
tokenResponse = {
|
||||
...tokenResponse,
|
||||
expires_in: new Date(Date.now() + tokenResponse.expires_in),
|
||||
};
|
||||
|
||||
console.log(tokenResponse);
|
||||
|
||||
return tokenResponse;
|
||||
};
|
||||
|
||||
export const searchNovels = async (novelName, bearerToken) => {
|
||||
const searchrl = `${baseApiUrl}/manga?q=${novelName}`;
|
||||
|
||||
const headers = {
|
||||
Authorization: "Bearer " + bearerToken,
|
||||
"Content-Type": "application/x-www-form-urlencoded",
|
||||
};
|
||||
|
||||
const res = await fetch(searchrl, { method: "GET", headers });
|
||||
const searchResults = await res.json();
|
||||
|
||||
return searchResults;
|
||||
};
|
||||
|
||||
export const findListItem = async (malId, bearerToken) => {
|
||||
const url = `${baseApiUrl}/manga/${malId}?fields=id,num_chapters,my_list_status{start_date,finish_date}`;
|
||||
|
||||
const headers = {
|
||||
Authorization: "Bearer " + bearerToken,
|
||||
"Content-Type": "application/x-www-form-urlencoded",
|
||||
};
|
||||
|
||||
const res = await fetch(url, { method: "GET", headers });
|
||||
const listItem = await res.json();
|
||||
|
||||
if (!listItem.my_list_status) {
|
||||
listItem.my_list_status = {
|
||||
status: "reading",
|
||||
score: 0,
|
||||
num_chapters_read: 0,
|
||||
};
|
||||
}
|
||||
return listItem;
|
||||
};
|
||||
|
||||
export const updateItem = async (malId, bearerToken, body) => {
|
||||
const url = `${baseApiUrl}/manga/${malId}/my_list_status`;
|
||||
|
||||
const headers = {
|
||||
Authorization: "Bearer " + bearerToken,
|
||||
"Content-Type": "application/x-www-form-urlencoded",
|
||||
};
|
||||
|
||||
const res = await fetch(url, {
|
||||
method: "PUT",
|
||||
headers,
|
||||
body: qs.stringify(body),
|
||||
});
|
||||
|
||||
const listItem = await res.json();
|
||||
console.log(listItem);
|
||||
return listItem;
|
||||
};
|
||||
|
||||
export const updateMalChaptersRead = async (malId, bearerToken, body) => {
|
||||
const url = `${baseApiUrl}/manga/${malId}/my_list_status`;
|
||||
|
||||
const headers = {
|
||||
Authorization: "Bearer " + bearerToken,
|
||||
"Content-Type": "application/x-www-form-urlencoded",
|
||||
};
|
||||
|
||||
const res = await fetch(url, {
|
||||
method: "PUT",
|
||||
headers,
|
||||
body: qs.stringify(body),
|
||||
});
|
||||
|
||||
const listItem = await res.json();
|
||||
console.log(listItem.num_chapters_read);
|
||||
return listItem.num_chapters_read;
|
||||
};
|
||||
|
||||
const revalidateMalToken = async (refreshToken) => {
|
||||
const headers = {
|
||||
"Content-Type": "application/x-www-form-urlencoded",
|
||||
};
|
||||
|
||||
const body = {
|
||||
grant_type: "refresh_token",
|
||||
refresh_token: refreshToken,
|
||||
};
|
||||
|
||||
const res = await fetch(url, {
|
||||
headers,
|
||||
method: "POST",
|
||||
body: qs.stringify(body),
|
||||
});
|
||||
|
||||
let tokenResponse = res.json();
|
||||
|
||||
return tokenResponse;
|
||||
};
|
||||
|
||||
export const malTokenWatcher = async (tracker) => {
|
||||
if (tracker) {
|
||||
const date = new Date(Date.now());
|
||||
if (tracker.expires_in < date) {
|
||||
return await revalidateMalToken(tracker.refresh_token);
|
||||
}
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,76 @@
|
||||
import * as DocumentPicker from "expo-document-picker";
|
||||
import { StorageAccessFramework } from "expo-file-system";
|
||||
|
||||
import { getLibrary } from "../Database/queries/LibraryQueries";
|
||||
import { restoreLibrary } from "../Database/queries/NovelQueries";
|
||||
import { showToast } from "../Hooks/showToast";
|
||||
|
||||
import * as Notifications from "expo-notifications";
|
||||
|
||||
Notifications.setNotificationHandler({
|
||||
handleNotification: async () => {
|
||||
return {
|
||||
shouldShowAlert: true,
|
||||
shouldPlaySound: true,
|
||||
shouldSetBadge: true,
|
||||
};
|
||||
},
|
||||
});
|
||||
|
||||
export const createBackup = async () => {
|
||||
const novels = await getLibrary();
|
||||
|
||||
const permissions =
|
||||
await StorageAccessFramework.requestDirectoryPermissionsAsync();
|
||||
|
||||
if (!permissions.granted) {
|
||||
return;
|
||||
}
|
||||
|
||||
const uri = permissions.directoryUri;
|
||||
|
||||
if (uri) {
|
||||
const fileUri = await StorageAccessFramework.createFileAsync(
|
||||
uri,
|
||||
"backup",
|
||||
"application/json"
|
||||
);
|
||||
|
||||
await StorageAccessFramework.writeAsStringAsync(
|
||||
fileUri,
|
||||
JSON.stringify(novels)
|
||||
);
|
||||
|
||||
showToast("Backup created");
|
||||
}
|
||||
};
|
||||
|
||||
export const restoreBackup = async () => {
|
||||
const backup = await DocumentPicker.getDocumentAsync();
|
||||
|
||||
Notifications.scheduleNotificationAsync({
|
||||
content: { title: "Restoring backup" },
|
||||
trigger: null,
|
||||
});
|
||||
|
||||
if (backup.uri) {
|
||||
let novels = await StorageAccessFramework.readAsStringAsync(backup.uri);
|
||||
novels = await JSON.parse(novels);
|
||||
|
||||
novels.map((novel, index) => {
|
||||
setTimeout(async () => {
|
||||
if (index + 1 === novels.length) {
|
||||
Notifications.scheduleNotificationAsync({
|
||||
content: {
|
||||
title: "Library Updated",
|
||||
body: novels.length + " novels restored",
|
||||
},
|
||||
trigger: null,
|
||||
});
|
||||
}
|
||||
|
||||
await restoreLibrary(novel);
|
||||
}, 1000 * index);
|
||||
});
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,159 @@
|
||||
import * as SQLite from "expo-sqlite";
|
||||
const db = SQLite.openDatabase("lnreader.db");
|
||||
|
||||
import { getLibrary } from "../Database/queries/LibraryQueries";
|
||||
import { fetchChapters, fetchNovel } from "../Services/Source/source";
|
||||
import * as Notifications from "expo-notifications";
|
||||
|
||||
Notifications.setNotificationHandler({
|
||||
handleNotification: async () => {
|
||||
return {
|
||||
shouldShowAlert: true,
|
||||
shouldPlaySound: true,
|
||||
shouldSetBadge: true,
|
||||
};
|
||||
},
|
||||
});
|
||||
|
||||
const updateNovelDetails = async (novel, novelId) => {
|
||||
db.transaction((tx) => {
|
||||
tx.executeSql(
|
||||
"UPDATE novels SET novelName = ?, novelCover = ?, novelSummary = ?, author = ?, artist = ?, genre = ?, status = ? WHERE novelId = ?",
|
||||
[
|
||||
novel.novelName,
|
||||
novel.novelCover,
|
||||
novel.novelSummary,
|
||||
novel.author,
|
||||
novel.artist,
|
||||
novel.genre,
|
||||
novel.status,
|
||||
novelId,
|
||||
],
|
||||
(txObj, res) => {},
|
||||
(txObj, error) => console.log("Error ", error)
|
||||
);
|
||||
});
|
||||
};
|
||||
|
||||
export const updateNovel = async (extensionId, novelUrl, novelId) => {
|
||||
let novel = await fetchNovel(extensionId, novelUrl);
|
||||
|
||||
await updateNovelDetails(novel, novelId);
|
||||
|
||||
db.transaction((tx) => {
|
||||
novel.chapters.map((chapter) =>
|
||||
tx.executeSql(
|
||||
"INSERT OR IGNORE INTO chapters (chapterUrl, chapterName, releaseDate, novelId) values (?, ?, ?, ?)",
|
||||
[
|
||||
chapter.chapterUrl,
|
||||
chapter.chapterName,
|
||||
chapter.releaseDate,
|
||||
novelId,
|
||||
],
|
||||
(txObj, { insertId }) => {
|
||||
if (insertId !== -1) {
|
||||
tx.executeSql(
|
||||
"INSERT OR IGNORE INTO updates (chapterId, novelId, updateTime) values (?, ?, (datetime('now','localtime')))",
|
||||
[insertId, novelId],
|
||||
(txObj, res) => {
|
||||
console.log(
|
||||
"Inserted Chapter Id -> " +
|
||||
insertId +
|
||||
" Novel Id " +
|
||||
novelId
|
||||
);
|
||||
},
|
||||
(txObj, error) => console.log("Error ", error)
|
||||
);
|
||||
}
|
||||
},
|
||||
(txObj, error) => console.log("Error ", error)
|
||||
)
|
||||
);
|
||||
});
|
||||
};
|
||||
|
||||
export const updateNovelChapters = async (extensionId, novelUrl, novelId) => {
|
||||
let chapters = await fetchChapters(extensionId, novelUrl);
|
||||
|
||||
db.transaction((tx) => {
|
||||
chapters.map((chapter) =>
|
||||
tx.executeSql(
|
||||
"INSERT OR IGNORE INTO chapters (chapterUrl, chapterName, releaseDate, novelId) values (?, ?, ?, ?)",
|
||||
[
|
||||
chapter.chapterUrl,
|
||||
chapter.chapterName,
|
||||
chapter.releaseDate,
|
||||
novelId,
|
||||
],
|
||||
(txObj, { insertId }) => {
|
||||
if (insertId !== -1) {
|
||||
console.log(
|
||||
"Inserted Chapter " +
|
||||
chapter.chapterUrl +
|
||||
" Chapter Name " +
|
||||
chapter.chapterName +
|
||||
" Novel Id " +
|
||||
novelId
|
||||
);
|
||||
tx.executeSql(
|
||||
"INSERT OR IGNORE INTO updates (chapterId, novelId, updateTime) values (?, ?, (datetime('now','localtime')))",
|
||||
[insertId, novelId],
|
||||
(txObj, res) => {},
|
||||
(txObj, error) => console.log("Error ", error)
|
||||
);
|
||||
}
|
||||
},
|
||||
(txObj, error) => console.log("Error ", error)
|
||||
)
|
||||
);
|
||||
});
|
||||
};
|
||||
|
||||
export const updateAllNovels = async () => {
|
||||
const libraryNovels = await getLibrary();
|
||||
|
||||
Notifications.scheduleNotificationAsync({
|
||||
identifier: "updatingNotif",
|
||||
content: { title: "Updating library" },
|
||||
trigger: null,
|
||||
});
|
||||
|
||||
libraryNovels.map((novel, index) =>
|
||||
setTimeout(async () => {
|
||||
await updateNovelChapters(
|
||||
novel.sourceId,
|
||||
novel.novelUrl,
|
||||
novel.novelId
|
||||
);
|
||||
console.log(novel.novelName + " Updated");
|
||||
|
||||
if (index + 1 === libraryNovels.length) {
|
||||
Notifications.scheduleNotificationAsync({
|
||||
content: {
|
||||
title: "Library Updated",
|
||||
body: libraryNovels.length + " novels updated",
|
||||
},
|
||||
trigger: null,
|
||||
});
|
||||
}
|
||||
}, 3000 * index)
|
||||
);
|
||||
};
|
||||
|
||||
export const parseChapterNumber = (chapterName) => {
|
||||
chapterName = chapterName.toLowerCase();
|
||||
chapterName = chapterName.replace(/volume (\d+)/, "");
|
||||
|
||||
const basic = chapterName.match(/ch (\d+)/);
|
||||
|
||||
const occurrence = chapterName.match(/\d+/);
|
||||
|
||||
if (basic) {
|
||||
return basic[0];
|
||||
} else if (occurrence) {
|
||||
return occurrence[0];
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,15 @@
|
||||
export const parseChapterNumber = (chapterName) => {
|
||||
chapterName = chapterName.toLowerCase();
|
||||
chapterName = chapterName.replace(/volume (\d+)/, "");
|
||||
|
||||
const basic = chapterName.match(/ch (\d+)/);
|
||||
const occurrence = chapterName.match(/\d+/);
|
||||
|
||||
if (basic) {
|
||||
return basic[0];
|
||||
} else if (occurrence) {
|
||||
return occurrence[0];
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,14 @@
|
||||
/**
|
||||
* Reader fonts
|
||||
*/
|
||||
|
||||
export const fonts = {
|
||||
"pt-sans-bold": require("../../assets/fonts/PTSansNarrow-Bold.ttf"),
|
||||
"arbutus-slab": require("../../assets/fonts/ArbutusSlab-Regular.ttf"),
|
||||
domine: require("../../assets/fonts/Domine-VariableFont_wght.ttf"),
|
||||
lato: require("../../assets/fonts/Lato-Regular.ttf"),
|
||||
"noto-sans": require("../../assets/fonts/NotoSans-Regular.ttf"),
|
||||
"noto-sans-bold": require("../../assets/fonts/NotoSans-Bold.ttf"),
|
||||
"open-sans": require("../../assets/fonts/OpenSans-Regular.ttf"),
|
||||
"pt-serif": require("../../assets/fonts/PTSerif-Regular.ttf"),
|
||||
};
|
||||
@@ -0,0 +1,142 @@
|
||||
/**
|
||||
* Application Colors
|
||||
*/
|
||||
export const theme = {
|
||||
colorPrimary: "#000000",
|
||||
colorPrimaryDark: "#000000",
|
||||
colorAccent: "#3399FF",
|
||||
textColorPrimary: "#FFFFFF",
|
||||
textColorSecondary: "rgba(255,255,255,0.7)",
|
||||
textColorHint: "rgba(255,255,255,0.5)",
|
||||
rippleColor: "rgba(255,255,255,0.2)",
|
||||
};
|
||||
|
||||
/**
|
||||
* Light
|
||||
*/
|
||||
export const lightTheme = {
|
||||
id: 1,
|
||||
name: "Light",
|
||||
colorPrimary: "#FFFFFF",
|
||||
colorPrimaryDark: "#FAFAFA",
|
||||
colorAccent: "#2979FF",
|
||||
textColorPrimary: "#000000",
|
||||
textColorSecondary: "rgba(0,0,0,0.54)",
|
||||
textColorHint: "rgba(0,0,0,0.38)",
|
||||
rippleColor: "rgba(0,0,0,0.12)",
|
||||
searchBarColor: "#FFFFFF",
|
||||
menuColor: "#FFFFFF",
|
||||
dividerColor: "rgba(0,0,0,0.1)",
|
||||
filterColor: "#FFC107",
|
||||
colorDisabled: "rgba(220,220,220,255)",
|
||||
colorButtonText: "#000000",
|
||||
statusBar: "dark",
|
||||
};
|
||||
|
||||
/**
|
||||
* Dark
|
||||
*/
|
||||
export const darkTheme = {
|
||||
id: 2,
|
||||
name: "Dark",
|
||||
colorPrimary: "#242529",
|
||||
colorPrimaryDark: "#202125",
|
||||
colorAccent: "#3399FF",
|
||||
textColorPrimary: "#FFFFFF",
|
||||
textColorSecondary: "rgba(255,255,255,0.7)",
|
||||
textColorHint: "rgba(255,255,255,0.5)",
|
||||
rippleColor: "rgba(255,255,255,0.2)",
|
||||
searchBarColor: "#303135",
|
||||
menuColor: "#242529",
|
||||
filterColor: "#FFEB3B",
|
||||
dividerColor: "rgba(255,255,255,0.1)",
|
||||
colorDisabled: "rgba(57,57,57,255)",
|
||||
colorButtonText: "#FFFFFF",
|
||||
statusBar: "light",
|
||||
};
|
||||
|
||||
/**
|
||||
* Amoled Dark
|
||||
*/
|
||||
export const amoledDarkTheme = {
|
||||
id: 0,
|
||||
name: "AMOLED Dark",
|
||||
colorPrimary: "#000000",
|
||||
colorPrimaryDark: "#000000",
|
||||
colorAccent: "#3399FF",
|
||||
textColorPrimary: "#FFFFFF",
|
||||
textColorSecondary: "rgba(255,255,255,0.7)",
|
||||
textColorHint: "rgba(255,255,255,0.5)",
|
||||
rippleColor: "rgba(255,255,255,0.2)",
|
||||
searchBarColor: "#1F1F1F",
|
||||
menuColor: "#242529",
|
||||
filterColor: "#FFEB3B",
|
||||
dividerColor: "rgba(255,255,255,0.15)",
|
||||
colorDisabled: "rgba(33,33,33,255)",
|
||||
colorButtonText: "#FFFFFF",
|
||||
statusBar: "light",
|
||||
};
|
||||
|
||||
/**
|
||||
* Midnight Dusk
|
||||
*/
|
||||
export const midnightDuskTheme = {
|
||||
id: 3,
|
||||
name: "Midnight Dusk",
|
||||
colorPrimary: "#201F27",
|
||||
colorPrimaryDark: "#16151D",
|
||||
colorAccent: "#F02475",
|
||||
textColorPrimary: "#FFFFFF",
|
||||
textColorSecondary: "rgba(255,255,255,0.7)",
|
||||
textColorHint: "rgba(255,255,255,0.5)",
|
||||
rippleColor: "rgba(255,255,255,0.2)",
|
||||
searchBarColor: "#201F27",
|
||||
menuColor: "#201F27",
|
||||
filterColor: "#FFEB3B",
|
||||
dividerColor: "rgba(255,255,255,0.1)",
|
||||
colorDisabled: "rgba(57,57,57,255)",
|
||||
colorButtonText: "#FFFFFF",
|
||||
statusBar: "light",
|
||||
};
|
||||
|
||||
/**
|
||||
* Lime
|
||||
*/
|
||||
|
||||
export const limeTheme = {
|
||||
id: 4,
|
||||
name: "Lime",
|
||||
colorPrimary: "#201F27",
|
||||
colorPrimaryDark: "#16151D",
|
||||
colorAccent: "#4AF88A",
|
||||
textColorPrimary: "#FFFFFF",
|
||||
textColorSecondary: "rgba(255,255,255,0.7)",
|
||||
textColorHint: "rgba(255,255,255,0.5)",
|
||||
rippleColor: "rgba(255,255,255,0.2)",
|
||||
searchBarColor: "#201F27",
|
||||
menuColor: "#201F27",
|
||||
filterColor: "#FFEB3B",
|
||||
dividerColor: "rgba(255,255,255,0.1)",
|
||||
colorDisabled: "rgba(57,57,57,255)",
|
||||
colorButtonText: "#16151D",
|
||||
statusBar: "light",
|
||||
};
|
||||
|
||||
export const irisBlueTheme = {
|
||||
id: 5,
|
||||
name: "Iris Blue",
|
||||
colorPrimary: "#393e46",
|
||||
colorPrimaryDark: "#222831",
|
||||
colorAccent: "#00adb5",
|
||||
textColorPrimary: "#FFFFFF",
|
||||
textColorSecondary: "rgba(255,255,255,0.7)",
|
||||
textColorHint: "rgba(255,255,255,0.5)",
|
||||
rippleColor: "rgba(255,255,255,0.2)",
|
||||
searchBarColor: "#393e46",
|
||||
menuColor: "#393e46",
|
||||
filterColor: "#FFEB3B",
|
||||
dividerColor: "rgba(255,255,255,0.1)",
|
||||
colorDisabled: "#393e46",
|
||||
colorButtonText: "#16151D",
|
||||
statusBar: "light",
|
||||
};
|
||||
@@ -1,23 +0,0 @@
|
||||
import React from "react";
|
||||
import { View } from "react-native";
|
||||
import { useSelector } from "react-redux";
|
||||
|
||||
const BottomSheetHandle = () => {
|
||||
const theme = useSelector((state) => state.themeReducer.theme);
|
||||
return (
|
||||
<>
|
||||
<View
|
||||
style={{
|
||||
backgroundColor: theme.textColorHintDark,
|
||||
height: 5,
|
||||
width: 30,
|
||||
borderRadius: 50,
|
||||
top: 10,
|
||||
alignSelf: "center",
|
||||
}}
|
||||
/>
|
||||
</>
|
||||
);
|
||||
};
|
||||
|
||||
export default BottomSheetHandle;
|
||||
@@ -1,57 +0,0 @@
|
||||
import React from "react";
|
||||
import { StyleSheet } from "react-native";
|
||||
import { List, Divider as PaperDivider } from "react-native-paper";
|
||||
|
||||
const ListSection = ({ children }) => (
|
||||
<List.Section style={styles.listSection}>{children}</List.Section>
|
||||
);
|
||||
|
||||
const ListSubHeader = ({ children, theme }) => (
|
||||
<List.Subheader
|
||||
style={[styles.listSubHeader, { color: theme.colorAccentDark }]}
|
||||
>
|
||||
{children}
|
||||
</List.Subheader>
|
||||
);
|
||||
|
||||
const ListItem = ({ title, description, icon, onPress, theme }) => (
|
||||
<List.Item
|
||||
title={title}
|
||||
titleStyle={{ color: theme.textColorPrimary }}
|
||||
description={description}
|
||||
descriptionStyle={{ color: theme.textColorSecondary }}
|
||||
descriptionNumberOfLines={1}
|
||||
left={() =>
|
||||
icon && (
|
||||
<List.Icon
|
||||
color={theme.colorAccentDark}
|
||||
icon={icon}
|
||||
style={{ marginVertical: 0 }}
|
||||
/>
|
||||
)
|
||||
}
|
||||
onPress={onPress}
|
||||
rippleColor={theme.rippleColor}
|
||||
/>
|
||||
);
|
||||
|
||||
const Divider = ({ theme }) => (
|
||||
<PaperDivider
|
||||
style={{
|
||||
backgroundColor: theme.dividerColor,
|
||||
height: 1,
|
||||
}}
|
||||
/>
|
||||
);
|
||||
|
||||
export { ListSection, ListSubHeader, ListItem, Divider };
|
||||
|
||||
const styles = StyleSheet.create({
|
||||
listSection: {
|
||||
flex: 1,
|
||||
marginVertical: 0,
|
||||
},
|
||||
listSubHeader: {
|
||||
paddingBottom: 5,
|
||||
},
|
||||
});
|
||||
@@ -1,212 +0,0 @@
|
||||
import React from "react";
|
||||
import { StyleSheet, View, Text, ImageBackground, Image } from "react-native";
|
||||
import { LinearGradient } from "expo-linear-gradient";
|
||||
import { TouchableRipple } from "react-native-paper";
|
||||
|
||||
import { useSelector } from "react-redux";
|
||||
|
||||
const NovelCover = ({ item, onPress, libraryStatus }) => {
|
||||
const displayMode = useSelector(
|
||||
(state) => state.settingsReducer.displayMode
|
||||
);
|
||||
|
||||
const theme = useSelector((state) => state.themeReducer.theme);
|
||||
|
||||
const itemsPerRow = useSelector(
|
||||
(state) => state.settingsReducer.itemsPerRow
|
||||
);
|
||||
|
||||
const height = {
|
||||
1: 550,
|
||||
2: 280,
|
||||
3: 180,
|
||||
4: 140,
|
||||
5: 100,
|
||||
6: 80,
|
||||
7: 70,
|
||||
8: 58,
|
||||
9: 55,
|
||||
10: 50,
|
||||
};
|
||||
|
||||
return displayMode !== 2 ? (
|
||||
<View style={{ flex: 1 / itemsPerRow }}>
|
||||
<TouchableRipple
|
||||
borderless
|
||||
centered
|
||||
rippleColor={theme.rippleColor}
|
||||
style={styles.opac}
|
||||
onPress={onPress}
|
||||
>
|
||||
<>
|
||||
{item.novelCover && (
|
||||
<ImageBackground
|
||||
source={{ uri: item.novelCover }}
|
||||
style={{ height: height[itemsPerRow] }}
|
||||
imageStyle={[
|
||||
{ borderRadius: 4 },
|
||||
libraryStatus && { opacity: 0.5 },
|
||||
]}
|
||||
progressiveRenderingEnabled={true}
|
||||
>
|
||||
<View style={{ flexDirection: "row", margin: 4 }}>
|
||||
{item.chaptersDownloaded && (
|
||||
<Text
|
||||
style={[
|
||||
{
|
||||
flex: 0,
|
||||
backgroundColor: "#47a84a",
|
||||
color: "#FFFFFF",
|
||||
borderTopLeftRadius: 4,
|
||||
borderBottomLeftRadius: 4,
|
||||
paddingTop: 2,
|
||||
paddingHorizontal: 4,
|
||||
alignSelf: "flex-start",
|
||||
fontSize: 12,
|
||||
},
|
||||
!item.chaptersUnread && {
|
||||
borderTopRightRadius: 4,
|
||||
borderBottomRightRadius: 4,
|
||||
},
|
||||
]}
|
||||
>
|
||||
{item.chaptersDownloaded}
|
||||
</Text>
|
||||
)}
|
||||
{item.chaptersUnread && (
|
||||
<Text
|
||||
style={[
|
||||
{
|
||||
flex: 0,
|
||||
backgroundColor: "#2979FF",
|
||||
color: "#FFFFFF",
|
||||
borderTopRightRadius: 4,
|
||||
borderBottomRightRadius: 4,
|
||||
paddingTop: 2,
|
||||
paddingHorizontal: 4,
|
||||
alignSelf: "flex-start",
|
||||
fontSize: 12,
|
||||
},
|
||||
!item.chaptersDownloaded && {
|
||||
borderTopLeftRadius: 4,
|
||||
borderBottomLeftRadius: 4,
|
||||
},
|
||||
]}
|
||||
>
|
||||
{item.chaptersUnread}
|
||||
</Text>
|
||||
)}
|
||||
</View>
|
||||
{displayMode === 0 && (
|
||||
<View style={styles.titleContainer}>
|
||||
<LinearGradient
|
||||
colors={[
|
||||
"transparent",
|
||||
"rgba(0,0,0,0.6)",
|
||||
]}
|
||||
style={styles.linearGradient}
|
||||
>
|
||||
<Text
|
||||
numberOfLines={2}
|
||||
style={[
|
||||
styles.title,
|
||||
{
|
||||
color:
|
||||
"rgba(255,255,255,1)",
|
||||
},
|
||||
]}
|
||||
>
|
||||
{item.novelName}
|
||||
</Text>
|
||||
</LinearGradient>
|
||||
</View>
|
||||
)}
|
||||
</ImageBackground>
|
||||
)}
|
||||
{displayMode === 1 && (
|
||||
<Text
|
||||
numberOfLines={2}
|
||||
style={[
|
||||
styles.title,
|
||||
{
|
||||
color: theme.textColorPrimary,
|
||||
padding: 4,
|
||||
},
|
||||
]}
|
||||
>
|
||||
{item.novelName}
|
||||
</Text>
|
||||
)}
|
||||
</>
|
||||
</TouchableRipple>
|
||||
</View>
|
||||
) : (
|
||||
<TouchableRipple
|
||||
borderless
|
||||
centered
|
||||
rippleColor={theme.rippleColor}
|
||||
style={styles.listView}
|
||||
onPress={onPress}
|
||||
>
|
||||
<>
|
||||
<Image
|
||||
source={{ uri: item.novelCover }}
|
||||
style={styles.extensionIcon}
|
||||
/>
|
||||
<Text
|
||||
style={{
|
||||
flex: 1,
|
||||
color: theme.textColorPrimary,
|
||||
marginLeft: 16,
|
||||
fontSize: 15,
|
||||
paddingRight: 8,
|
||||
}}
|
||||
numberOfLines={1}
|
||||
>
|
||||
{item.novelName}
|
||||
</Text>
|
||||
</>
|
||||
</TouchableRipple>
|
||||
);
|
||||
};
|
||||
|
||||
export default NovelCover;
|
||||
|
||||
const styles = StyleSheet.create({
|
||||
// logo: {
|
||||
// height: 180,
|
||||
// },
|
||||
titleContainer: {
|
||||
flex: 1,
|
||||
justifyContent: "flex-end",
|
||||
borderRadius: 4,
|
||||
},
|
||||
title: {
|
||||
fontFamily: "pt-sans-bold",
|
||||
fontSize: 14,
|
||||
padding: 8,
|
||||
},
|
||||
|
||||
linearGradient: {
|
||||
bottom: -1,
|
||||
borderRadius: 4,
|
||||
},
|
||||
opac: {
|
||||
paddingHorizontal: 4.5,
|
||||
paddingVertical: 4,
|
||||
borderRadius: 4,
|
||||
},
|
||||
extensionIcon: {
|
||||
width: 42,
|
||||
height: 42,
|
||||
borderRadius: 4,
|
||||
},
|
||||
listView: {
|
||||
flex: 1,
|
||||
paddingVertical: 8,
|
||||
paddingHorizontal: 12,
|
||||
flexDirection: "row",
|
||||
alignItems: "center",
|
||||
borderRadius: 4,
|
||||
},
|
||||
});
|
||||
@@ -1,87 +0,0 @@
|
||||
import * as SQLite from "expo-sqlite";
|
||||
const db = SQLite.openDatabase("lnreader.db");
|
||||
|
||||
const insertNovelQuery = `INSERT INTO novels (novelUrl, sourceUrl, sourceId, source, novelName, novelCover, novelSummary, author, artist, status, genre) VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`;
|
||||
|
||||
export const insertNovel = async (novel) => {
|
||||
return new Promise((resolve, reject) =>
|
||||
db.transaction((tx) =>
|
||||
tx.executeSql(
|
||||
insertNovelQuery,
|
||||
[
|
||||
novel.novelUrl,
|
||||
novel.sourceUrl,
|
||||
novel.sourceId,
|
||||
novel.source,
|
||||
novel.novelName,
|
||||
novel.novelCover,
|
||||
novel.novelSummary,
|
||||
novel.author,
|
||||
novel.artist,
|
||||
novel.status,
|
||||
novel.genre,
|
||||
],
|
||||
(txObj, { insertId }) => resolve(insertId),
|
||||
(txObj, error) => console.log("Error ", error)
|
||||
)
|
||||
)
|
||||
);
|
||||
};
|
||||
|
||||
export const followNovel = async (followed, novelId) => {
|
||||
db.transaction((tx) => {
|
||||
tx.executeSql(
|
||||
"UPDATE novels SET followed = ? WHERE novelId = ?",
|
||||
[!followed, novelId],
|
||||
(tx, res) => {},
|
||||
(txObj, error) => console.log("Error ", error)
|
||||
);
|
||||
});
|
||||
};
|
||||
|
||||
const checkNovelInCacheQuery = `SELECT * FROM novels WHERE novelUrl=? LIMIT 1`;
|
||||
|
||||
export const checkNovelInCache = (novelUrl) => {
|
||||
return new Promise((resolve, reject) =>
|
||||
db.transaction((tx) => {
|
||||
tx.executeSql(
|
||||
checkNovelInCacheQuery,
|
||||
[novelUrl],
|
||||
(txObj, res) => {
|
||||
if (res.rows.length !== 0) {
|
||||
resolve(true);
|
||||
} else {
|
||||
resolve(false);
|
||||
}
|
||||
},
|
||||
(txObj, error) => console.log("Error ", error)
|
||||
);
|
||||
})
|
||||
);
|
||||
};
|
||||
|
||||
export const getNovel = async (novelUrl) => {
|
||||
return new Promise((resolve, reject) =>
|
||||
db.transaction((tx) => {
|
||||
tx.executeSql(
|
||||
`SELECT * FROM novels WHERE novelUrl = ?`,
|
||||
[novelUrl],
|
||||
(txObj, { rows }) => resolve(rows.item(0)),
|
||||
(txObj, error) => console.log("Error ", error)
|
||||
);
|
||||
})
|
||||
);
|
||||
};
|
||||
|
||||
export const deleteNovelCache = () => {
|
||||
db.transaction((tx) => {
|
||||
tx.executeSql(
|
||||
"DELETE FROM novels WHERE followed = 0",
|
||||
null,
|
||||
(txObj, res) => {
|
||||
console.log("Cleared Novel Cache");
|
||||
},
|
||||
(txObj, error) => console.log("Error ", error)
|
||||
);
|
||||
});
|
||||
};
|
||||
@@ -1,160 +0,0 @@
|
||||
import React, { useEffect } from "react";
|
||||
import {
|
||||
createStackNavigator,
|
||||
TransitionPresets,
|
||||
} from "@react-navigation/stack";
|
||||
import { createMaterialBottomTabNavigator } from "@react-navigation/material-bottom-tabs";
|
||||
import { Provider } from "react-native-paper";
|
||||
import { setStatusBarStyle } from "expo-status-bar";
|
||||
|
||||
import MaterialCommunityIcons from "react-native-vector-icons/MaterialCommunityIcons";
|
||||
|
||||
import Library from "../screens/Library/Library";
|
||||
import Updates from "../screens/Updates/Updates";
|
||||
import History from "../screens/History/History";
|
||||
import Browse from "../screens/Browse/Browse";
|
||||
|
||||
import More from "../screens/More/More";
|
||||
import About from "../screens/More/About";
|
||||
import Settings from "../screens/More/Settings";
|
||||
|
||||
import NovelItem from "../screens/Novel/Novel";
|
||||
import ChapterItem from "../screens/Chapter/Chapter";
|
||||
|
||||
import Extension from "../screens/Extension/Extension";
|
||||
|
||||
const Stack = createStackNavigator();
|
||||
|
||||
const Tab = createMaterialBottomTabNavigator();
|
||||
|
||||
const stackNavigatorConfig = {
|
||||
headerShown: false,
|
||||
...TransitionPresets.RevealFromBottomAndroid,
|
||||
};
|
||||
|
||||
const SettingsStack = () => {
|
||||
return (
|
||||
<Stack.Navigator screenOptions={stackNavigatorConfig}>
|
||||
<Stack.Screen name="About" component={About} />
|
||||
<Stack.Screen name="Settings" component={Settings} />
|
||||
</Stack.Navigator>
|
||||
);
|
||||
};
|
||||
|
||||
import { useSelector } from "react-redux";
|
||||
|
||||
const BottomNavigator = () => {
|
||||
const theme = useSelector((state) => state.themeReducer.theme);
|
||||
|
||||
return (
|
||||
<Tab.Navigator
|
||||
shifting={false}
|
||||
barStyle={{ backgroundColor: theme.colorPrimary }}
|
||||
activeColor={theme.colorAccentDark}
|
||||
>
|
||||
<Tab.Screen
|
||||
name="My Library"
|
||||
component={Library}
|
||||
options={{
|
||||
tabBarIcon: ({ color }) => (
|
||||
<MaterialCommunityIcons
|
||||
name="book-variant-multiple"
|
||||
color={color}
|
||||
size={24}
|
||||
/>
|
||||
),
|
||||
}}
|
||||
/>
|
||||
|
||||
<Tab.Screen
|
||||
name="Updates"
|
||||
component={Updates}
|
||||
options={{
|
||||
tabBarIcon: ({ color }) => (
|
||||
<MaterialCommunityIcons
|
||||
name="alert-decagram-outline"
|
||||
color={color}
|
||||
size={24}
|
||||
/>
|
||||
),
|
||||
}}
|
||||
/>
|
||||
<Tab.Screen
|
||||
name="History"
|
||||
component={History}
|
||||
options={{
|
||||
tabBarIcon: ({ color }) => (
|
||||
<MaterialCommunityIcons
|
||||
name="history"
|
||||
color={color}
|
||||
size={24}
|
||||
/>
|
||||
),
|
||||
}}
|
||||
/>
|
||||
<Tab.Screen
|
||||
name="Browse"
|
||||
component={Browse}
|
||||
options={{
|
||||
tabBarIcon: ({ color }) => (
|
||||
<MaterialCommunityIcons
|
||||
name="compass-outline"
|
||||
color={color}
|
||||
size={24}
|
||||
/>
|
||||
),
|
||||
}}
|
||||
/>
|
||||
<Tab.Screen
|
||||
name="More"
|
||||
component={More}
|
||||
options={{
|
||||
tabBarIcon: ({ color }) => (
|
||||
<MaterialCommunityIcons
|
||||
name="dots-horizontal"
|
||||
color={color}
|
||||
size={24}
|
||||
/>
|
||||
),
|
||||
}}
|
||||
/>
|
||||
</Tab.Navigator>
|
||||
);
|
||||
};
|
||||
|
||||
const Router = () => {
|
||||
const theme = useSelector((state) => state.themeReducer.theme);
|
||||
|
||||
useEffect(() => setStatusBarStyle(theme.id === 1 ? "dark" : "light"), []);
|
||||
|
||||
return (
|
||||
<Provider>
|
||||
<Stack.Navigator screenOptions={stackNavigatorConfig}>
|
||||
<Stack.Screen name="Router" component={BottomNavigator} />
|
||||
<Stack.Screen
|
||||
name="ChapterItem"
|
||||
component={ChapterItem}
|
||||
options={{ ...TransitionPresets.SlideFromRightIOS }}
|
||||
/>
|
||||
<Stack.Screen
|
||||
name="NovelItem"
|
||||
component={NovelItem}
|
||||
options={{
|
||||
headerTitle: "",
|
||||
headerShown: true,
|
||||
headerTransparent: true,
|
||||
headerTintColor: "white",
|
||||
}}
|
||||
/>
|
||||
<Stack.Screen name="SettingsStack" component={SettingsStack} />
|
||||
<Stack.Screen name="Extension" component={Extension} />
|
||||
{/* <Stack.Screen
|
||||
name="ExtensionStack"
|
||||
component={ExtensionStack}
|
||||
/> */}
|
||||
</Stack.Navigator>
|
||||
</Provider>
|
||||
);
|
||||
};
|
||||
|
||||
export default Router;
|
||||
@@ -1,82 +1,31 @@
|
||||
import { ToastAndroid } from "react-native";
|
||||
import { getChapter } from "../../Database/queries/ChapterQueries";
|
||||
import { fetchChapter } from "../../Services/Source/source";
|
||||
import { SAVE_SCROLL_POSITION } from "../preferences/preference.types";
|
||||
import { CHAPTER_LOADING, GET_CHAPTER } from "./chapter.types";
|
||||
|
||||
import {
|
||||
CHAPTER_READ,
|
||||
GET_CHAPTER,
|
||||
CHAPTER_LOADING,
|
||||
CHAPTER_DOWNLOADING,
|
||||
CHAPTER_DOWNLOADED,
|
||||
CHAPTER_DELETED,
|
||||
} from "./chapter.types";
|
||||
export const getChapterAction =
|
||||
(sourceId, novelUrl, chapterUrl, chapterId) => async (dispatch) => {
|
||||
dispatch({ type: CHAPTER_LOADING });
|
||||
|
||||
import { fetchChapter } from "../../source/Source";
|
||||
/**
|
||||
* Check if chapter is downloaded.
|
||||
*/
|
||||
let chapter = await getChapter(chapterId);
|
||||
|
||||
import {
|
||||
markChapterRead,
|
||||
isChapterDownloaded,
|
||||
getChapter,
|
||||
downloadChapter,
|
||||
deleteChapter,
|
||||
} from "../../database/queries/ChapterQueries";
|
||||
if (!chapter) {
|
||||
/**
|
||||
* Fetch chapter from source.
|
||||
*/
|
||||
chapter = await fetchChapter(sourceId, novelUrl, chapterUrl);
|
||||
}
|
||||
|
||||
export const getChapterAction = (
|
||||
extensionId,
|
||||
chapterUrl,
|
||||
novelUrl,
|
||||
novelId
|
||||
) => async (dispatch) => {
|
||||
dispatch({ type: CHAPTER_LOADING });
|
||||
dispatch({ type: GET_CHAPTER, payload: chapter });
|
||||
};
|
||||
|
||||
const isDownloaded = await isChapterDownloaded(novelId);
|
||||
let chapter;
|
||||
|
||||
if (isDownloaded) {
|
||||
chapter = await getChapter(novelId);
|
||||
} else {
|
||||
chapter = await fetchChapter(extensionId, novelUrl, chapterUrl);
|
||||
}
|
||||
console.log(isDownloaded);
|
||||
dispatch({ type: GET_CHAPTER, payload: chapter });
|
||||
};
|
||||
|
||||
export const markChapterReadAction = (chapterId) => async (dispatch) => {
|
||||
await markChapterRead(chapterId);
|
||||
dispatch({ type: CHAPTER_READ, payload: { chapterId } });
|
||||
};
|
||||
|
||||
export const downloadChapterAction = (
|
||||
extensionId,
|
||||
novelUrl,
|
||||
chapterUrl,
|
||||
chapterName,
|
||||
chapterId
|
||||
) => async (dispatch) => {
|
||||
dispatch({
|
||||
type: CHAPTER_DOWNLOADING,
|
||||
payload: {
|
||||
chapterId,
|
||||
},
|
||||
});
|
||||
|
||||
await downloadChapter(extensionId, novelUrl, chapterUrl, chapterId);
|
||||
|
||||
dispatch({
|
||||
type: CHAPTER_DOWNLOADED,
|
||||
payload: { chapterId },
|
||||
});
|
||||
|
||||
ToastAndroid.show(`Downloaded ${chapterName}`, ToastAndroid.SHORT);
|
||||
};
|
||||
|
||||
export const deleteChapterAction = (chapterId, chapterName) => async (
|
||||
dispatch
|
||||
) => {
|
||||
await deleteChapter(chapterId);
|
||||
|
||||
dispatch({
|
||||
type: CHAPTER_DELETED,
|
||||
payload: { chapterId },
|
||||
});
|
||||
|
||||
ToastAndroid.show(`Deleted ${chapterName}`, ToastAndroid.SHORT);
|
||||
};
|
||||
export const saveScrollPosition =
|
||||
(position, percentage, chapterId, novelId) => async (dispatch) => {
|
||||
dispatch({
|
||||
type: SAVE_SCROLL_POSITION,
|
||||
payload: { position, percentage, chapterId, novelId },
|
||||
});
|
||||
};
|
||||
|
||||
@@ -1,15 +1,7 @@
|
||||
import {
|
||||
CHAPTER_READ,
|
||||
GET_CHAPTER,
|
||||
CHAPTER_LOADING,
|
||||
CHAPTER_DOWNLOADING,
|
||||
CHAPTER_DOWNLOADED,
|
||||
CHAPTER_DELETED,
|
||||
} from "./chapter.types";
|
||||
import { CHAPTER_LOADING, GET_CHAPTER } from "./chapter.types";
|
||||
|
||||
const initialState = {
|
||||
chapter: null,
|
||||
downloading: [],
|
||||
chapter: {},
|
||||
loading: true,
|
||||
};
|
||||
|
||||
@@ -17,46 +9,10 @@ const chapterReducer = (state = initialState, action) => {
|
||||
const { type, payload } = action;
|
||||
|
||||
switch (type) {
|
||||
case CHAPTER_READ:
|
||||
return {
|
||||
...state,
|
||||
chapters: state.chapters.map((chapter) =>
|
||||
chapter.chapterId === payload.chapterId
|
||||
? { ...chapter, read: 1 }
|
||||
: chapter
|
||||
),
|
||||
};
|
||||
case CHAPTER_LOADING:
|
||||
return {
|
||||
...state,
|
||||
chapterLoading: true,
|
||||
};
|
||||
return { ...state, loading: true };
|
||||
case GET_CHAPTER:
|
||||
return { ...state, chapter: payload, chapterLoading: false };
|
||||
case CHAPTER_DOWNLOADING:
|
||||
return {
|
||||
...state,
|
||||
downloading: payload.chapterId,
|
||||
};
|
||||
case CHAPTER_DOWNLOADED:
|
||||
return {
|
||||
...state,
|
||||
downloading: null,
|
||||
chapters: state.chapters.map((chapter) =>
|
||||
chapter.chapterId === payload.chapterId
|
||||
? { ...chapter, downloaded: 1 }
|
||||
: chapter
|
||||
),
|
||||
};
|
||||
case CHAPTER_DELETED:
|
||||
return {
|
||||
...state,
|
||||
chapters: state.chapters.map((chapter) =>
|
||||
chapter.chapterId === payload.chapterId
|
||||
? { ...chapter, downloaded: 0 }
|
||||
: chapter
|
||||
),
|
||||
};
|
||||
return { ...state, chapter: payload, loading: false };
|
||||
default:
|
||||
return state;
|
||||
}
|
||||
|
||||
@@ -1,6 +1,2 @@
|
||||
export const CHAPTER_DOWNLOADED = "CHAPTER_DOWNLOADED";
|
||||
export const CHAPTER_DELETED = "CHAPTER_DELETED";
|
||||
export const CHAPTER_DOWNLOADING = "CHAPTER_DOWNLOADING";
|
||||
export const CHAPTER_READ = "CHAPTER_READ";
|
||||
export const CHAPTER_LOADING = "CHAPTER_LOADING";
|
||||
export const GET_CHAPTER = "GET_CHAPTER";
|
||||
export const CHAPTER_LOADING = "CHAPTER_LOADING";
|
||||
|
||||