Add update library on start option and save select text option

This commit is contained in:
Rajarshee Chatterjee
2021-07-03 10:06:07 +05:30
parent f5dd7153cc
commit e4027efbb1
7 changed files with 108 additions and 14 deletions
+56
View File
@@ -0,0 +1,56 @@
import React from "react";
import { Pressable, StyleSheet, View, Text } from "react-native";
import { Switch, List } from "react-native-paper";
const SwitchSetting = ({ label, description, onPress, theme, icon, value }) => (
<Pressable
android_ripple={{ color: theme.rippleColor }}
style={styles.container}
onPress={onPress}
>
<View style={{ flexDirection: "row", flex: 1 }}>
{icon && (
<List.Icon
color={theme.colorAccent}
icon={icon}
style={{ margin: 0 }}
/>
)}
<View style={[icon && { marginLeft: 16 }]}>
<Text
style={{
color: theme.textColorPrimary,
fontSize: 16,
flex: 1,
textAlignVertical: "center",
}}
>
{label}
</Text>
{description && (
<Text style={{ color: theme.textColorSecondary }}>
{description}
</Text>
)}
</View>
</View>
<Switch
value={value}
onValueChange={onPress}
color={theme.colorAccent}
style={{ marginRight: 8 }}
/>
</Pressable>
);
export default SwitchSetting;
const styles = StyleSheet.create({
container: {
paddingHorizontal: 16,
paddingVertical: 12,
flexDirection: "row",
justifyContent: "space-between",
},
});
+2
View File
@@ -59,6 +59,8 @@ const initialState = {
swipeGestures: true,
incognitoMode: false,
searchAllSources: false,
textSelectable: false,
updateLibraryOnLaunch: false,
};
const settingsReducer = (state = initialState, action) => {
+7 -5
View File
@@ -70,7 +70,11 @@ const Chapter = ({ route, navigation }) => {
const showScrollPercentage = useSelector(
(state) => state.settingsReducer.showScrollPercentage
);
const { swipeGestures = true, incognitoMode = false } = useSettings();
const {
swipeGestures = true,
incognitoMode = false,
textSelectable = false,
} = useSettings();
const [hidden, setHidden] = useState(true);
@@ -85,7 +89,6 @@ const Chapter = ({ route, navigation }) => {
const [scrollPercentage, setScrollPercentage] = useState(0);
const [firstLayout, setFirstLayout] = useState(true);
const [selectText, setSelectText] = useState(false);
const [contentSize, setContentSize] = useState(0);
@@ -341,7 +344,7 @@ const Chapter = ({ route, navigation }) => {
<Text
style={readerStyles}
onLayout={scrollToSavedProgress}
selectable={selectText}
selectable={textSelectable}
onPress={() => setHidden(!hidden)}
>
{chapter.chapterText
@@ -357,8 +360,7 @@ const Chapter = ({ route, navigation }) => {
reader={reader}
dispatch={dispatch}
bottomSheetRef={readerSheetRef}
selectText={selectText}
setSelectText={setSelectText}
selectText={textSelectable}
showScrollPercentage={showScrollPercentage}
/>
</Portal>
@@ -18,7 +18,6 @@ const ReaderSheet = ({
dispatch,
bottomSheetRef,
selectText,
setSelectText,
showScrollPercentage,
}) => {
const [fontMenu, setFontMenu] = useState(false);
@@ -412,7 +411,14 @@ const ReaderSheet = ({
</View>
<Switch
value={selectText}
onValueChange={setSelectText}
onValueChange={() =>
dispatch(
setAppSettings(
"textSelectable",
!selectText
)
)
}
color={theme.colorAccent}
/>
</Row>
+10 -4
View File
@@ -1,15 +1,13 @@
import React, { useState, useCallback, useRef } from "react";
import React, { useState, useCallback, useRef, useEffect } from "react";
import {
StyleSheet,
Text,
View,
RefreshControl,
ActivityIndicator,
TouchableOpacity,
} from "react-native";
import { useFocusEffect } from "@react-navigation/native";
import { useSelector, useDispatch } from "react-redux";
import MaterialCommunityIcons from "react-native-vector-icons/MaterialCommunityIcons";
import { Searchbar } from "../../components/Searchbar";
import NovelList from "../../components/NovelList";
@@ -29,7 +27,11 @@ import LibraryFilterSheet from "./components/LibraryFilterSheet";
const LibraryScreen = ({ navigation }) => {
const theme = useTheme();
const dispatch = useDispatch();
const { showNumberOfNovels, incognitoMode = false } = useSettings();
const {
showNumberOfNovels,
incognitoMode = false,
updateLibraryOnLaunch = false,
} = useSettings();
const libraryFilterSheetRef = useRef(null);
@@ -49,6 +51,10 @@ const LibraryScreen = ({ navigation }) => {
}, [getLibraryAction, sort, filter])
);
useEffect(() => {
updateLibraryOnLaunch && dispatch(updateLibraryAction());
}, []);
const onRefresh = () => {
setRefreshing(true);
dispatch(updateLibraryAction());
+22 -2
View File
@@ -10,12 +10,16 @@ import {
} from "../../components/List";
import { ScreenContainer } from "../../components/Common";
import { useTheme } from "../../hooks/reduxHooks";
import { useSettings, useTheme } from "../../hooks/reduxHooks";
import DisplayModeModal from "./components/DisplayModeModal";
import GridSizeModal from "./components/GridSizeModal";
import ThemeModal from "./components/ThemeModal";
import { setAccentColor } from "../../redux/settings/settings.actions";
import {
setAccentColor,
setAppSettings,
} from "../../redux/settings/settings.actions";
import ColorPickerModal from "../../components/ColorPickerModal";
import SwitchSetting from "../../components/Switch/Switch";
const GenralSettings = ({ navigation }) => {
const theme = useTheme();
@@ -25,6 +29,8 @@ const GenralSettings = ({ navigation }) => {
(state) => state.settingsReducer
);
const { updateLibraryOnLaunch = false } = useSettings();
const displayModeLabel = (displayMode) => {
const label = {
0: "Compact Grid",
@@ -81,6 +87,20 @@ const GenralSettings = ({ navigation }) => {
theme={theme}
/>
<Divider theme={theme} />
<ListSubHeader theme={theme}>Library</ListSubHeader>
<SwitchSetting
label="Update library on launch"
value={updateLibraryOnLaunch}
onPress={() =>
dispatch(
setAppSettings(
"updateLibraryOnLaunch",
!updateLibraryOnLaunch
)
)
}
theme={theme}
/>
<ListSubHeader theme={theme}>Theme</ListSubHeader>
<ListItem
title="Theme"
+3 -1
View File
@@ -175,7 +175,9 @@ export const updateAllNovels = async () => {
}
});
await BackgroundService.start(veryIntensiveTask, options);
if (libraryNovels.length > 0) {
await BackgroundService.start(veryIntensiveTask, options);
}
};
export const parseChapterNumber = (chapterName) => {