Skip to content

A fully open source & end-to-end encrypted note taking alternative to Evernote.

add PremiumService

ammarahm-ed1199768eeed5
diff --git a/apps/mobile/src/components/Premium/PremiumDialog.js b/apps/mobile/src/components/Premium/PremiumDialog.js
index 2e2bbe093..3dfcdddb6 100644
--- a/apps/mobile/src/components/Premium/PremiumDialog.js
+++ b/apps/mobile/src/components/Premium/PremiumDialog.js
@@ -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%"
/>
diff --git a/apps/mobile/src/provider/DefaultState.js b/apps/mobile/src/provider/DefaultState.js
index 6fb952a87..b2e0f072b 100644
--- a/apps/mobile/src/provider/DefaultState.js
+++ b/apps/mobile/src/provider/DefaultState.js
@@ -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",
diff --git a/apps/mobile/src/services/PremiumService.js b/apps/mobile/src/services/PremiumService.js
new file mode 100644
index 000000000..3b2212f28
--- /dev/null
+++ b/apps/mobile/src/services/PremiumService.js
@@ -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
+};
diff --git a/apps/mobile/src/utils/functions.js b/apps/mobile/src/utils/functions.js
index 8016a4e69..370f6dac1 100644
--- a/apps/mobile/src/utils/functions.js
+++ b/apps/mobile/src/utils/functions.js
@@ -1,61 +1,60 @@
-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) {
- if (item && item.dateCreated && history.selectedItemsList.length === 0) {
- history.selectedItemsList = [];
- history.selectedItemsList.push(item);
- }
+ if (item && item.dateCreated && history.selectedItemsList.length === 0) {
+ history.selectedItemsList = [];
+ history.selectedItemsList.push(item);
+ }
- for (var i = 0; i < history.selectedItemsList.length; i++) {
- let it = history.selectedItemsList[i];
- if (it.type === 'note') {
- await db.notes.delete(it.id);
- updateEvent({type: it.type});
- eSendEvent(eClearEditor);
- } else if (it.type === 'topic') {
- await db.notebooks.notebook(it.notebookId).topics.delete(it.title);
- eSendEvent(eOnNewTopicAdded);
- updateEveny({type: 'notebook'});
- ToastEvent.show('Topics deleted', 'success');
- } else if (it.type === 'notebook') {
- await db.notebooks.delete(it.id);
- updateEvent({type: it.type});
- }
- }
+ for (var i = 0; i < history.selectedItemsList.length; i++) {
+ let it = history.selectedItemsList[i];
+ if (it.type === 'note') {
+ await db.notes.delete(it.id);
+ updateEvent({type: it.type});
+ eSendEvent(eClearEditor);
+ } else if (it.type === 'topic') {
+ await db.notebooks.notebook(it.notebookId).topics.delete(it.title);
+ eSendEvent(eOnNewTopicAdded);
+ updateEveny({type: 'notebook'});
+ ToastEvent.show('Topics deleted', 'success');
+ } else if (it.type === 'notebook') {
+ await db.notebooks.delete(it.id);
+ updateEvent({type: it.type});
+ }
+ }
- 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'){
- ToastEvent.show(
- message,
- 'success',
- 'global',
- 6000,
- async () => {
- let trash = db.trash;
+ let msgPart = history.selectedItemsList.length === 1 ? ' item' : ' items';
+ let message = history.selectedItemsList.length + msgPart + ' moved to trash.';
- for (var i = 0; i < itemsCopy.length; i++) {
- 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')
- updateEvent({type: it.type});
- }
- updateEvent({type: Actions.TRASH});
- ToastEvent.hide();
- },
- 'Undo',
- );
-}
- updateEvent({type: Actions.CLEAR_SELECTION});
- updateEvent({type: Actions.SELECTION_MODE, enabled: false});
-}
+ let itemsCopy = [...history.selectedItemsList];
+ if (history.selectedItemsList[0].type !== 'topic') {
+ ToastEvent.show(
+ message,
+ 'success',
+ 'global',
+ 6000,
+ async () => {
+ let trash = db.trash;
+ for (var i = 0; i < itemsCopy.length; i++) {
+ 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');
+ updateEvent({type: it.type});
+ }
+ updateEvent({type: Actions.TRASH});
+ ToastEvent.hide();
+ },
+ 'Undo',
+ );
+ }
+ updateEvent({type: Actions.CLEAR_SELECTION});
+ updateEvent({type: Actions.SELECTION_MODE, enabled: false});
+}
diff --git a/apps/mobile/src/views/Settings/index.js b/apps/mobile/src/views/Settings/index.js
index 624d23d6e..2817dd2bd 100644
--- a/apps/mobile/src/views/Settings/index.js
+++ b/apps/mobile/src/views/Settings/index.js
@@ -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,19 +144,21 @@ export const Settings = ({navigation}) => {
];
const switchTheme = async () => {
- await setSetting(settings, 'useSystemTheme', !settings.useSystemTheme);
-
- if (!settings.useSystemTheme) {
- await MMKV.setStringAsync(
- 'theme',
- JSON.stringify({night: Appearance.getColorScheme() === 'dark'}),
- );
- changeColorScheme(
- Appearance.getColorScheme() === 'dark'
- ? COLOR_SCHEME_DARK
- : COLOR_SCHEME_LIGHT,
- );
- }
+ await PremiumService.verify(async () => {
+ await setSetting(settings, 'useSystemTheme', !settings.useSystemTheme);
+
+ if (!settings.useSystemTheme) {
+ await MMKV.setStringAsync(
+ 'theme',
+ JSON.stringify({night: Appearance.getColorScheme() === 'dark'}),
+ );
+ changeColorScheme(
+ Appearance.getColorScheme() === 'dark'
+ ? COLOR_SCHEME_DARK
+ : 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 () => {
- changeAccentColor(item);
-
- await MMKV.setStringAsync('accentColor', item);
+ 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 () => {
- changeAccentColor(item);
-
- await MMKV.setStringAsync('accentColor', item);
+ 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 setSetting(settings, 'reminder', item.value);
+ 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