|
|
@@ -4,7 +4,7 @@ import { useDidShow, usePullDownRefresh, useShareAppMessage } from "@tarojs/taro
|
|
|
import { useTranslation } from "react-i18next";
|
|
|
import Segment from '@/components/navigation/Segment'
|
|
|
import { useEffect, useState } from "react";
|
|
|
-import { kIsAndroid, rpxToPx } from "@/utils/tools";
|
|
|
+import { kIsAndroid, kIsIOS, rpxToPx } from "@/utils/tools";
|
|
|
import './setting.scss'
|
|
|
import { getNotifySettings, postNotifySettings } from "@/services/notifications";
|
|
|
import { ColorType } from "@/context/themes/color";
|
|
|
@@ -18,10 +18,22 @@ import Modal from "@/components/layout/Modal.weapp";
|
|
|
import Layout from "@/components/layout/layout";
|
|
|
import { NaviBarTitleShowType, TemplateType } from "@/utils/types";
|
|
|
import TitleView from "@/features/trackTimeDuration/components/TitleView";
|
|
|
+import showAlert from "@/components/basic/Alert";
|
|
|
|
|
|
let useNavigation;
|
|
|
let AppState, Switch;
|
|
|
+let OneSignal
|
|
|
+let NativeAppEventEmitter
|
|
|
+let Jto
|
|
|
+let PushNotification
|
|
|
+let checkNotification
|
|
|
if (process.env.TARO_ENV == 'rn') {
|
|
|
+ OneSignal = require('react-native-onesignal').OneSignal
|
|
|
+ NativeAppEventEmitter = require('react-native').NativeAppEventEmitter
|
|
|
+ Jto = require('react-native').NativeModules.NativeBridge;
|
|
|
+ PushNotification = require('react-native-push-notification')
|
|
|
+ checkNotification = require('@/utils/native_permission_check').checkNotification;
|
|
|
+
|
|
|
AppState = require("react-native").AppState
|
|
|
Switch = require("react-native").Switch
|
|
|
useNavigation = require("@react-navigation/native").useNavigation
|
|
|
@@ -39,7 +51,7 @@ export default function Page() {
|
|
|
const [systemFast, setSystemFast] = useState(true)
|
|
|
const [systemExtra, setSystemExtra] = useState(true)
|
|
|
const [systemSun, setSystemSun] = useState(true)
|
|
|
-
|
|
|
+ const [isAuthorized, setIsAuthorized] = useState(false)
|
|
|
const [showMemberAlert, setShowMemberAlert] = useState(false)
|
|
|
const user = useSelector((state: any) => state.user);
|
|
|
const accessObj = useSelector((state: any) => state.access);
|
|
|
@@ -65,21 +77,14 @@ export default function Page() {
|
|
|
headerTitle: '',
|
|
|
});
|
|
|
AppState.addEventListener('change', handleAppStateChange);
|
|
|
- // AppState.addEventListener('change', handleAppStateChange);
|
|
|
- // navigation.addListener('focus', () => {
|
|
|
- // checkSetting()
|
|
|
- // });
|
|
|
-
|
|
|
- // // 当页面即将消失时执行
|
|
|
- // navigation.addListener('blur', () => {
|
|
|
- // console.log('notfication setting blur')
|
|
|
- // });
|
|
|
+ rnNotification()
|
|
|
|
|
|
}
|
|
|
|
|
|
if (process.env.TARO_ENV == 'rn') {
|
|
|
// AppState.addEventListener('change', handleAppStateChange);
|
|
|
navigation.addListener('focus', () => {
|
|
|
+ rnNotification()
|
|
|
getMemberStatus()
|
|
|
});
|
|
|
|
|
|
@@ -96,13 +101,49 @@ export default function Page() {
|
|
|
return
|
|
|
}
|
|
|
if (nextAppState == 'active') {
|
|
|
+ rnNotification()
|
|
|
checkSetting()
|
|
|
getMemberStatus()
|
|
|
}
|
|
|
|
|
|
};
|
|
|
|
|
|
-
|
|
|
+ function rnNotification() {
|
|
|
+ if (kIsIOS) {
|
|
|
+ Jto.getNotificationAuthStatus()
|
|
|
+ NativeAppEventEmitter.addListener('notificationResult', (data) => {
|
|
|
+ global.notification = data
|
|
|
+ setIsAuthorized(data == 'authorized')
|
|
|
+ })
|
|
|
+ NativeAppEventEmitter.addListener('operateNotificationResult', (data) => {
|
|
|
+ global.notification = data
|
|
|
+ setIsAuthorized(data == 'authorized')
|
|
|
+ })
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ OneSignal.Notifications.canRequestPermission().then((status) => {
|
|
|
+ if (status) {
|
|
|
+ OneSignal.Notifications.getPermissionAsync().then((res) => {
|
|
|
+ if (res) {
|
|
|
+ global.notification = 'authorized'
|
|
|
+ setIsAuthorized(true)
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ global.notification = 'denied'
|
|
|
+ setIsAuthorized(false)
|
|
|
+ }
|
|
|
+ })
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ global.notification = 'not_determined'
|
|
|
+ setIsAuthorized(false)
|
|
|
+ }
|
|
|
+ })
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
|
|
|
function getMemberStatus() {
|
|
|
const { access } = accessObj
|
|
|
@@ -245,12 +286,37 @@ export default function Page() {
|
|
|
<View className='fast_alert_confirm' onClick={confirm}>
|
|
|
<Text style={{ fontWeight: 'bold', color: ColorType.black }}>Become a Pro Member</Text>
|
|
|
</View>
|
|
|
- <View className="fast_alert_cancel" onClick={()=>{setShowMemberAlert(false)}}>Not now</View>
|
|
|
+ <View className="fast_alert_cancel" onClick={() => { setShowMemberAlert(false) }}>Not now</View>
|
|
|
|
|
|
</View>
|
|
|
</View>
|
|
|
}
|
|
|
|
|
|
+ function notificationOpen(){
|
|
|
+ if (process.env.TARO_ENV === 'rn') {
|
|
|
+ PushNotification.checkPermissions((res) => {
|
|
|
+ //允许授权
|
|
|
+ if ((kIsIOS && res.authorizationStatus == 2) || (!kIsIOS && res.alert)) {
|
|
|
+ setIsAuthorized(true)
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ showAlert({
|
|
|
+ title: 'title',
|
|
|
+ content: 'content',
|
|
|
+ cancelText: t('feature.track_time_duration.reminders.later'),
|
|
|
+ confirmText: t('feature.track_time_duration.reminders.open'),
|
|
|
+ showCancel: true,
|
|
|
+ cancel: () => {
|
|
|
+ },
|
|
|
+ confirm: () => {
|
|
|
+ checkNotification()
|
|
|
+ }
|
|
|
+ })
|
|
|
+ }
|
|
|
+ })
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
function pro(isLogin: boolean) {
|
|
|
return <ScrollView style={{ flex: 1 }}>
|
|
|
{/* <ProductList /> */}
|
|
|
@@ -272,11 +338,16 @@ export default function Page() {
|
|
|
<Text className="setting_header">Extra Reminders (Pro)</Text>
|
|
|
<View className="setting_cell">
|
|
|
<Text className="setting_cell_title" style={{ flex: 1 }}>Missed previous action</Text>
|
|
|
- <Switch className="myswitch" value={isLogin ? isExtra : false} color={ColorType.fast} trackColor={{ true: ColorType.fast }} onChange={(e) => {
|
|
|
+ <Switch className="myswitch" value={isLogin ? (isAuthorized ? isExtra : false) : false} color={ColorType.fast} trackColor={{ true: ColorType.fast }} onChange={(e) => {
|
|
|
if (!isLogin) {
|
|
|
jumpPage('/pages/account/ChooseAuth', 'ChooseAuth', navigation)
|
|
|
return
|
|
|
}
|
|
|
+
|
|
|
+ if (!isAuthorized) {
|
|
|
+ notificationOpen()
|
|
|
+ return
|
|
|
+ }
|
|
|
const value = e.nativeEvent.value
|
|
|
if (e.nativeEvent.value) {
|
|
|
if (accessObj && accessObj.access && accessObj.access.member.status == 'NON_MEMBER') {
|
|
|
@@ -312,12 +383,16 @@ export default function Page() {
|
|
|
<View className="setting_cell_group">
|
|
|
<View className="setting_cell_group_item">
|
|
|
<Text className="setting_cell_title" style={{ flex: 1 }}>Sunrise</Text>
|
|
|
- <Switch className="myswitch" value={isLogin ? isSunrise : false} color={ColorType.fast} trackColor={{ true: ColorType.fast }} onChange={(e) => {
|
|
|
+ <Switch className="myswitch" value={isLogin ? (isAuthorized ? isSunrise : false) : false} color={ColorType.fast} trackColor={{ true: ColorType.fast }} onChange={(e) => {
|
|
|
// setIsMulti(e.nativeEvent.value)
|
|
|
if (!isLogin) {
|
|
|
jumpPage('/pages/account/ChooseAuth', 'ChooseAuth', navigation)
|
|
|
return
|
|
|
}
|
|
|
+ if (!isAuthorized) {
|
|
|
+ notificationOpen()
|
|
|
+ return
|
|
|
+ }
|
|
|
const value = e.nativeEvent.value
|
|
|
if (e.nativeEvent.value) {
|
|
|
if (accessObj && accessObj.access && accessObj.access.member.status == 'NON_MEMBER') {
|
|
|
@@ -349,12 +424,16 @@ export default function Page() {
|
|
|
<View className="new_item_cell_line" />
|
|
|
<View className="setting_cell_group_item">
|
|
|
<Text className="setting_cell_title" style={{ flex: 1 }}>Sunset</Text>
|
|
|
- <Switch className="myswitch" value={isLogin ? isSunset : false} trackColor={{ true: ColorType.fast }} color={ColorType.fast} onChange={(e) => {
|
|
|
+ <Switch className="myswitch" value={isLogin ? (isAuthorized ? isSunset : false) : false} trackColor={{ true: ColorType.fast }} color={ColorType.fast} onChange={(e) => {
|
|
|
// setIsMulti(e.nativeEvent.value)
|
|
|
if (!isLogin) {
|
|
|
jumpPage('/pages/account/ChooseAuth', 'ChooseAuth', navigation)
|
|
|
return
|
|
|
}
|
|
|
+ if (!isAuthorized) {
|
|
|
+ notificationOpen()
|
|
|
+ return
|
|
|
+ }
|
|
|
const value = e.nativeEvent.value
|
|
|
if (e.nativeEvent.value) {
|
|
|
if (accessObj && accessObj.access && accessObj.access.member.status == 'NON_MEMBER') {
|
|
|
@@ -385,12 +464,16 @@ export default function Page() {
|
|
|
<View className="new_item_cell_line" />
|
|
|
<View className="setting_cell_group_item">
|
|
|
<Text className="setting_cell_title" style={{ flex: 1 }}>Solar noon</Text>
|
|
|
- <Switch className="myswitch" value={isLogin ? isSolarNoon : false} trackColor={{ true: ColorType.fast }} color={ColorType.fast} onChange={(e) => {
|
|
|
+ <Switch className="myswitch" value={isLogin ? (isAuthorized ? isSolarNoon : false) : false} trackColor={{ true: ColorType.fast }} color={ColorType.fast} onChange={(e) => {
|
|
|
// setIsMulti(e.nativeEvent.value)
|
|
|
if (!isLogin) {
|
|
|
jumpPage('/pages/account/ChooseAuth', 'ChooseAuth', navigation)
|
|
|
return
|
|
|
}
|
|
|
+ if (!isAuthorized) {
|
|
|
+ notificationOpen()
|
|
|
+ return
|
|
|
+ }
|
|
|
const value = e.nativeEvent.value
|
|
|
if (e.nativeEvent.value) {
|
|
|
if (accessObj && accessObj.access && accessObj.access.member.status == 'NON_MEMBER') {
|