mirror of
https://github.com/streetwriters/notesnook.git
synced 2025-12-23 23:19:40 +01:00
add PremiumService
This commit is contained in:
@@ -79,6 +79,8 @@ class PremiumDialog extends React.Component {
|
||||
alignSelf: 'center',
|
||||
borderRadius: 10,
|
||||
marginBottom: DDS.isTab ? 50 : 0,
|
||||
borderBottomRightRadius:0,
|
||||
borderBottomLeftRadius:0
|
||||
}}
|
||||
onOpen={async () => {
|
||||
await this.getSkus();
|
||||
@@ -115,7 +117,7 @@ class PremiumDialog extends React.Component {
|
||||
paddingTop: 10,
|
||||
alignSelf: 'center',
|
||||
}}>
|
||||
Notesnook Pro
|
||||
Get Notesnook Pro
|
||||
</Text>
|
||||
|
||||
<ScrollView
|
||||
@@ -198,6 +200,7 @@ class PremiumDialog extends React.Component {
|
||||
fontFamily: WEIGHT.regular,
|
||||
fontSize: SIZE.xs + 1,
|
||||
maxWidth: '85%',
|
||||
fontWeight:'400',
|
||||
color: colors.icon,
|
||||
}}>
|
||||
{item.description}
|
||||
@@ -230,6 +233,7 @@ class PremiumDialog extends React.Component {
|
||||
fontSize: 12,
|
||||
color: colors.pri,
|
||||
fontFamily: WEIGHT.regular,
|
||||
fontWeight:"400"
|
||||
}}>
|
||||
{this.state.user
|
||||
? 'Cancel anytime in Subscriptions on Google Play'
|
||||
@@ -270,6 +274,7 @@ class PremiumDialog extends React.Component {
|
||||
title={
|
||||
this.state.user ? 'Subscribe to Notesnook Pro' : 'Sign Up Now'
|
||||
}
|
||||
type="accent"
|
||||
height={50}
|
||||
width="100%"
|
||||
/>
|
||||
|
||||
@@ -22,8 +22,8 @@ export const defaultState = {
|
||||
showKeyboardOnOpen: false,
|
||||
fontScale: 1,
|
||||
forcePortraitOnTablet: false,
|
||||
useSystemTheme:true,
|
||||
reminder:'weekly',
|
||||
useSystemTheme:false,
|
||||
reminder:'off',
|
||||
encryptedBackups:false,
|
||||
homepage:'Home',
|
||||
sort:"default",
|
||||
|
||||
39
apps/mobile/src/services/PremiumService.js
Normal file
39
apps/mobile/src/services/PremiumService.js
Normal file
@@ -0,0 +1,39 @@
|
||||
import { db } from "../utils/DB";
|
||||
import { eOpenPremiumDialog } from "../utils/Events";
|
||||
import { eSendEvent } from "./EventManager";
|
||||
|
||||
let premiumStatus = null;
|
||||
|
||||
function setPremiumStatus(status) {
|
||||
try {
|
||||
let user = await db.user.get();
|
||||
if (!user || !user.id) {
|
||||
premiumStatus = null;
|
||||
} else {
|
||||
premiumStatus = user.subscription.status
|
||||
}
|
||||
} catch (e) {
|
||||
premiumStatus = null
|
||||
}
|
||||
}
|
||||
|
||||
async function verify(callback) {
|
||||
try {
|
||||
let user = await db.user.get();
|
||||
|
||||
if (!user || !user.id) {
|
||||
eSendEvent(eOpenPremiumDialog);
|
||||
return;
|
||||
} else {
|
||||
if (!callback) console.warn('You must provide a callback function');
|
||||
await callback();
|
||||
}
|
||||
} catch (e) {
|
||||
// show error dialog TODO
|
||||
}
|
||||
}
|
||||
|
||||
export default {
|
||||
verify,
|
||||
setPremiumStatus
|
||||
};
|
||||
@@ -1,9 +1,9 @@
|
||||
import { history } from ".";
|
||||
import { updateEvent } from "../components/DialogManager/Recievers";
|
||||
import { Actions } from "../provider/Actions";
|
||||
import { eSendEvent, ToastEvent } from "../services/EventManager";
|
||||
import { db } from "./DB";
|
||||
import { eClearEditor, eOnNewTopicAdded } from "./Events";
|
||||
import {history} from '.';
|
||||
import {updateEvent} from '../components/DialogManager/recievers';
|
||||
import {Actions} from '../provider/Actions';
|
||||
import {eSendEvent, ToastEvent} from '../services/EventManager';
|
||||
import {db} from './DB';
|
||||
import {eClearEditor, eOnNewTopicAdded, eOpenPremiumDialog} from './Events';
|
||||
|
||||
|
||||
export async function deleteItems(item) {
|
||||
@@ -29,11 +29,11 @@ export async function deleteItems(item) {
|
||||
}
|
||||
}
|
||||
|
||||
let msgPart = history.selectedItemsList.length === 1? ' item' : " items"
|
||||
let message = history.selectedItemsList.length + msgPart + " moved to trash."
|
||||
let msgPart = history.selectedItemsList.length === 1 ? ' item' : ' items';
|
||||
let message = history.selectedItemsList.length + msgPart + ' moved to trash.';
|
||||
|
||||
let itemsCopy = [...history.selectedItemsList];
|
||||
if (history.selectedItemsList[0].type !== 'topic'){
|
||||
if (history.selectedItemsList[0].type !== 'topic') {
|
||||
ToastEvent.show(
|
||||
message,
|
||||
'success',
|
||||
@@ -46,7 +46,7 @@ export async function deleteItems(item) {
|
||||
let it = itemsCopy[i];
|
||||
let trashItem = trash.all.find((item) => item.itemId === it.id);
|
||||
await db.trash.restore(trashItem.id);
|
||||
console.log(it.type,'type')
|
||||
console.log(it.type, 'type');
|
||||
updateEvent({type: it.type});
|
||||
}
|
||||
updateEvent({type: Actions.TRASH});
|
||||
@@ -54,8 +54,7 @@ export async function deleteItems(item) {
|
||||
},
|
||||
'Undo',
|
||||
);
|
||||
}
|
||||
}
|
||||
updateEvent({type: Actions.CLEAR_SELECTION});
|
||||
updateEvent({type: Actions.SELECTION_MODE, enabled: false});
|
||||
}
|
||||
|
||||
|
||||
@@ -1,22 +1,38 @@
|
||||
import React, {createRef, useCallback, useEffect} from 'react';
|
||||
import React, { createRef, useCallback, useEffect } from 'react';
|
||||
import {
|
||||
Appearance,
|
||||
Linking,
|
||||
Platform,
|
||||
|
||||
ScrollView,
|
||||
StatusBar,
|
||||
|
||||
Text,
|
||||
TouchableOpacity,
|
||||
View,
|
||||
View
|
||||
} from 'react-native';
|
||||
import * as Animatable from 'react-native-animatable';
|
||||
import Menu, { MenuItem } from 'react-native-reanimated-material-menu';
|
||||
import Icon from 'react-native-vector-icons/MaterialCommunityIcons';
|
||||
import {Button} from '../../components/Button';
|
||||
import {PressableButton} from '../../components/PressableButton';
|
||||
import { Button } from '../../components/Button';
|
||||
import { PressableButton } from '../../components/PressableButton';
|
||||
import Seperator from '../../components/Seperator';
|
||||
import {useTracked} from '../../provider';
|
||||
import {Actions} from '../../provider/Actions';
|
||||
import {eSendEvent, ToastEvent} from '../../services/EventManager';
|
||||
import { ListHeaderComponent } from '../../components/SimpleList/ListHeaderComponent';
|
||||
import { useTracked } from '../../provider';
|
||||
import { Actions } from '../../provider/Actions';
|
||||
import Backup from '../../services/Backup';
|
||||
import { DDS } from '../../services/DeviceDetection';
|
||||
import { eSendEvent, ToastEvent } from '../../services/EventManager';
|
||||
import NavigationService from '../../services/Navigation';
|
||||
import PremiumService from '../../services/PremiumService';
|
||||
import { dWidth, MenuItemsList, setSetting } from '../../utils';
|
||||
import {
|
||||
ACCENT,
|
||||
COLOR_SCHEME,
|
||||
COLOR_SCHEME_DARK,
|
||||
COLOR_SCHEME_LIGHT,
|
||||
setColorScheme
|
||||
} from '../../utils/Colors';
|
||||
import { hexToRGBA, RGB_Linear_Shade } from '../../utils/ColorUtils';
|
||||
import { db } from '../../utils/DB';
|
||||
import {
|
||||
eCloseProgressDialog,
|
||||
eOpenLoginDialog,
|
||||
@@ -26,27 +42,11 @@ import {
|
||||
eOpenRestoreDialog,
|
||||
eResetApp,
|
||||
eScrollEvent,
|
||||
eUpdateSearchState,
|
||||
eUpdateSearchState
|
||||
} from '../../utils/Events';
|
||||
import NavigationService from '../../services/Navigation';
|
||||
import storage from '../../utils/storage';
|
||||
import {setSetting, dWidth, MenuItemsList} from '../../utils';
|
||||
import {hexToRGBA, RGB_Linear_Shade} from '../../utils/ColorUtils';
|
||||
import {sleep} from '../../utils/TimeUtils';
|
||||
import {
|
||||
ACCENT,
|
||||
COLOR_SCHEME,
|
||||
COLOR_SCHEME_DARK,
|
||||
COLOR_SCHEME_LIGHT,
|
||||
setColorScheme,
|
||||
} from '../../utils/Colors';
|
||||
import {opacity, pv, SIZE, WEIGHT} from '../../utils/SizeUtils';
|
||||
import {db} from '../../utils/DB';
|
||||
import {DDS} from '../../services/DeviceDetection';
|
||||
import {MMKV} from '../../utils/mmkv';
|
||||
import Backup from '../../services/Backup';
|
||||
import Menu, {MenuItem} from 'react-native-material-menu';
|
||||
import {ListHeaderComponent} from '../../components/SimpleList/ListHeaderComponent';
|
||||
import { MMKV } from '../../utils/mmkv';
|
||||
import { opacity, pv, SIZE, WEIGHT } from '../../utils/SizeUtils';
|
||||
import { sleep } from '../../utils/TimeUtils';
|
||||
|
||||
let menuRef = createRef();
|
||||
export const Settings = ({navigation}) => {
|
||||
@@ -64,7 +64,7 @@ export const Settings = ({navigation}) => {
|
||||
}
|
||||
|
||||
const onFocus = useCallback(() => {
|
||||
eSendEvent('showSearch', true);
|
||||
eSendEvent(eScrollEvent, {name: 'Settings', type: 'in'});
|
||||
dispatch({
|
||||
type: Actions.HEADER_STATE,
|
||||
state: true,
|
||||
@@ -91,6 +91,7 @@ export const Settings = ({navigation}) => {
|
||||
useEffect(() => {
|
||||
navigation.addListener('focus', onFocus);
|
||||
return () => {
|
||||
eSendEvent(eScrollEvent, {name: 'Settings', type: 'back'});
|
||||
navigation.removeListener('focus', onFocus);
|
||||
};
|
||||
});
|
||||
@@ -143,6 +144,7 @@ export const Settings = ({navigation}) => {
|
||||
];
|
||||
|
||||
const switchTheme = async () => {
|
||||
await PremiumService.verify(async () => {
|
||||
await setSetting(settings, 'useSystemTheme', !settings.useSystemTheme);
|
||||
|
||||
if (!settings.useSystemTheme) {
|
||||
@@ -156,6 +158,7 @@ export const Settings = ({navigation}) => {
|
||||
: COLOR_SCHEME_LIGHT,
|
||||
);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
const CustomButton = ({title, tagline, customComponent, onPress}) => (
|
||||
@@ -204,7 +207,6 @@ export const Settings = ({navigation}) => {
|
||||
backgroundColor: colors.bg,
|
||||
}}>
|
||||
<ScrollView
|
||||
|
||||
onScroll={(e) =>
|
||||
eSendEvent(eScrollEvent, e.nativeEvent.contentOffset.y)
|
||||
}
|
||||
@@ -476,9 +478,10 @@ export const Settings = ({navigation}) => {
|
||||
alpha={!colors.night ? -0.1 : 0.1}
|
||||
opacity={1}
|
||||
onPress={async () => {
|
||||
await PremiumService.verify(async () => {
|
||||
changeAccentColor(item);
|
||||
|
||||
await MMKV.setStringAsync('accentColor', item);
|
||||
});
|
||||
}}
|
||||
customStyle={{
|
||||
flexDirection: 'row',
|
||||
@@ -517,9 +520,11 @@ export const Settings = ({navigation}) => {
|
||||
alpha={!colors.night ? -0.1 : 0.1}
|
||||
opacity={1}
|
||||
onPress={async () => {
|
||||
console.log('called');
|
||||
await PremiumService.verify(async () => {
|
||||
changeAccentColor(item);
|
||||
|
||||
await MMKV.setStringAsync('accentColor', item);
|
||||
});
|
||||
}}
|
||||
customStyle={{
|
||||
flexDirection: 'row',
|
||||
@@ -592,8 +597,8 @@ export const Settings = ({navigation}) => {
|
||||
<CustomButton
|
||||
title="Homepage"
|
||||
tagline={'Default screen to open on app startup '}
|
||||
onPress={() => {
|
||||
menuRef.current?.show();
|
||||
onPress={async () => {
|
||||
await PremiumService.verify(menuRef.current?.show);
|
||||
}}
|
||||
customComponent={
|
||||
<Menu
|
||||
@@ -605,8 +610,8 @@ export const Settings = ({navigation}) => {
|
||||
}}
|
||||
button={
|
||||
<TouchableOpacity
|
||||
onPress={() => {
|
||||
menuRef.current?.show();
|
||||
onPress={async () => {
|
||||
await PremiumService.verify(menuRef.current?.show);
|
||||
}}
|
||||
style={{
|
||||
flexDirection: 'row',
|
||||
@@ -785,6 +790,7 @@ export const Settings = ({navigation}) => {
|
||||
fontFamily: WEIGHT.regular,
|
||||
textAlignVertical: 'center',
|
||||
color: colors.pri,
|
||||
maxWidth: '60%',
|
||||
}}>
|
||||
Auto Backup{'\n'}
|
||||
<Text
|
||||
@@ -805,6 +811,10 @@ export const Settings = ({navigation}) => {
|
||||
alignItems: 'center',
|
||||
}}>
|
||||
{[
|
||||
{
|
||||
title: 'Off',
|
||||
value: 'off',
|
||||
},
|
||||
{
|
||||
title: 'Daily',
|
||||
value: 'daily',
|
||||
@@ -817,7 +827,9 @@ export const Settings = ({navigation}) => {
|
||||
<TouchableOpacity
|
||||
activeOpacity={1}
|
||||
onPress={async () => {
|
||||
await PremiumService.verify(async () => {
|
||||
await setSetting(settings, 'reminder', item.value);
|
||||
});
|
||||
}}
|
||||
key={item.value}
|
||||
style={{
|
||||
@@ -827,7 +839,7 @@ export const Settings = ({navigation}) => {
|
||||
: colors.nav,
|
||||
justifyContent: 'center',
|
||||
alignItems: 'center',
|
||||
width: 60,
|
||||
width: 50,
|
||||
height: 20,
|
||||
}}>
|
||||
<Text
|
||||
|
||||
Reference in New Issue
Block a user