|
|
@@ -14,6 +14,19 @@ import { updateFast, updateSleep } from "@/store/set_target";
|
|
|
import { setPlan } from "@/services/trackTimeDuration";
|
|
|
import showAlert from "@/components/basic/Alert";
|
|
|
import Taro from "@tarojs/taro";
|
|
|
+import { getLocalPush } from "@/features/trackTimeDuration/actions/TrackTimeActions";
|
|
|
+
|
|
|
+let OneSignal
|
|
|
+let NativeAppEventEmitter
|
|
|
+let Jto
|
|
|
+let uploadPermissions,checkNotification
|
|
|
+if (process.env.TARO_ENV == 'rn') {
|
|
|
+ OneSignal = require('react-native-onesignal').OneSignal
|
|
|
+ NativeAppEventEmitter = require('react-native').NativeAppEventEmitter
|
|
|
+ Jto = require('react-native').NativeModules.NativeBridge;
|
|
|
+ uploadPermissions = require('@/utils/native_permission_check').uploadPermissions;
|
|
|
+ checkNotification = require('@/utils/native_permission_check').checkNotification;
|
|
|
+}
|
|
|
|
|
|
export default function SetGoal() {
|
|
|
|
|
|
@@ -37,14 +50,60 @@ export default function SetGoal() {
|
|
|
const [showTimePicker, setShowTimePicker] = useState(false)
|
|
|
const [isFast, setIsFast] = useState(true)
|
|
|
const [isStart, setIsStart] = useState(true)
|
|
|
+ const [authStatus, setAuthStatus] = useState('')
|
|
|
const { t } = useTranslation()
|
|
|
const dispatch = useDispatch();
|
|
|
|
|
|
+ useEffect(() => {
|
|
|
+ if (process.env.TARO_ENV == 'rn') {
|
|
|
+ rnNotification()
|
|
|
+ }
|
|
|
+ }, [])
|
|
|
+
|
|
|
useEffect(() => {
|
|
|
getFastDuration()
|
|
|
getSleepDuration()
|
|
|
}, [target.fast, target.sleep])
|
|
|
|
|
|
+
|
|
|
+ function rnNotification() {
|
|
|
+ if (Taro.getSystemInfoSync().platform == 'ios') {
|
|
|
+ Jto.getNotificationAuthStatus()
|
|
|
+ NativeAppEventEmitter.addListener('notificationResult', (data) => {
|
|
|
+ setAuthStatus(data)
|
|
|
+ global.notification = data
|
|
|
+ uploadPermissions()
|
|
|
+ })
|
|
|
+ NativeAppEventEmitter.addListener('operateNotificationResult', (data) => {
|
|
|
+ getLocalPush()
|
|
|
+ global.notification = data
|
|
|
+ navigation.popToTop()
|
|
|
+ uploadPermissions()
|
|
|
+ })
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ OneSignal.Notifications.canRequestPermission().then((status) => {
|
|
|
+ if (status) {
|
|
|
+ OneSignal.Notifications.getPermissionAsync().then((res) => {
|
|
|
+ if (res) {
|
|
|
+ global.notification = 'authorized'
|
|
|
+ uploadPermissions()
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ global.notification = 'denied'
|
|
|
+ uploadPermissions()
|
|
|
+ }
|
|
|
+ })
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ global.notification = 'not_determined'
|
|
|
+ uploadPermissions()
|
|
|
+ }
|
|
|
+ })
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
function getFastDuration() {
|
|
|
var obj = target.fast.schedule.fast
|
|
|
var duration = obj.end_time.split(':')[0] * 60 + obj.end_time.split(':')[1] * 1 - (obj.start_time.split(':')[0] * 60 + obj.start_time.split(':')[1] * 1)
|
|
|
@@ -183,6 +242,7 @@ export default function SetGoal() {
|
|
|
}
|
|
|
|
|
|
function confirm() {
|
|
|
+ debugger
|
|
|
var params: any = {
|
|
|
method: parseInt(router.params.isSelf + '') == 1 ? 'USER_SET' : 'SUGGEST',
|
|
|
schedule: {
|
|
|
@@ -233,13 +293,13 @@ export default function SetGoal() {
|
|
|
global.indexPageRefresh()
|
|
|
}
|
|
|
|
|
|
- // if (process.env.TARO_ENV === 'rn') {
|
|
|
- // popRNAlert()
|
|
|
- // }
|
|
|
- // else {
|
|
|
- // popAlert()
|
|
|
- // }
|
|
|
- popAlert()
|
|
|
+ if (process.env.TARO_ENV === 'rn') {
|
|
|
+ popRNAlert()
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ popAlert()
|
|
|
+ }
|
|
|
+ // popAlert()
|
|
|
|
|
|
|
|
|
}).catch(e => {
|
|
|
@@ -271,50 +331,108 @@ export default function SetGoal() {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- function popRNAlert() {
|
|
|
- // if (target.isMixed) {
|
|
|
-
|
|
|
- // }
|
|
|
- // else {
|
|
|
- // const JPush = require('jpush-react-native').default;
|
|
|
- // JPush.isNotificationEnabled((res) => {
|
|
|
- // if (res) {
|
|
|
- // showAlert({
|
|
|
- // title: t('feature.track_time_duration.reminders.schedule_title'),
|
|
|
- // content:
|
|
|
- // t('feature.track_time_duration.reminders.enable_schedule_fast_content', { time: fastTarget.start_time }),
|
|
|
- // showCancel: false,
|
|
|
- // confirmText: t('feature.track_time_duration.reminders.ok'),
|
|
|
- // cancel: () => {
|
|
|
- // navigation.popToTop()
|
|
|
- // },
|
|
|
- // confirm: () => {
|
|
|
- // navigation.popToTop()
|
|
|
- // },
|
|
|
- // })
|
|
|
- // }
|
|
|
- // else {
|
|
|
- // showAlert({
|
|
|
- // title: t('feature.track_time_duration.reminders.schedule_title'),
|
|
|
- // content:
|
|
|
- // t('feature.track_time_duration.reminders.schedule_fast_content', { time: fastTarget.start_time }),
|
|
|
- // cancelText: t('feature.track_time_duration.reminders.later'),
|
|
|
- // confirmText: t('feature.track_time_duration.reminders.open'),
|
|
|
- // showCancel: true,
|
|
|
- // cancel: () => {
|
|
|
- // navigation.popToTop()
|
|
|
- // },
|
|
|
- // confirm: () => {
|
|
|
- // // if (authStatus != 'not_determined') {
|
|
|
- // // navigation.popToTop()
|
|
|
- // // }
|
|
|
- // // checkNotification()
|
|
|
- // // Linking.openURL('app-settings:notifications')
|
|
|
- // }
|
|
|
- // })
|
|
|
- // }
|
|
|
- // })
|
|
|
- // }
|
|
|
+ function popRNAlert(){
|
|
|
+ debugger
|
|
|
+ if (target.isMixed) {
|
|
|
+ popMixScheduleAlert(fastTarget.start_time, sleepTarget.start_time)
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ popScheduleAlert({
|
|
|
+ name: 'FAST'
|
|
|
+ }, fastTarget.start_time)
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ function popScheduleAlert(scenario, startTime) {
|
|
|
+ if (process.env.TARO_ENV === 'rn') {
|
|
|
+ const JPush = require('jpush-react-native').default;
|
|
|
+ JPush.isNotificationEnabled((res) => {
|
|
|
+ if (res) {
|
|
|
+ getLocalPush();
|
|
|
+ showAlert({
|
|
|
+ title: t('feature.track_time_duration.reminders.schedule_title'),
|
|
|
+ content: scenario.name == 'FAST' ?
|
|
|
+ t('feature.track_time_duration.reminders.enable_schedule_fast_content', { time: startTime }) :
|
|
|
+ t('feature.track_time_duration.reminders.enable_schedule_sleep_content', { time: startTime }),
|
|
|
+ showCancel: false,
|
|
|
+ confirmText: t('feature.track_time_duration.reminders.ok'),
|
|
|
+ cancel: () => {
|
|
|
+ navigation.popToTop()
|
|
|
+ },
|
|
|
+ confirm: () => {
|
|
|
+ navigation.popToTop()
|
|
|
+ },
|
|
|
+ })
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ showAlert({
|
|
|
+ title: t('feature.track_time_duration.reminders.schedule_title'),
|
|
|
+ content: scenario.name == 'FAST' ?
|
|
|
+ t('feature.track_time_duration.reminders.schedule_fast_content', { time: startTime }) :
|
|
|
+ t('feature.track_time_duration.reminders.schedule_sleep_content', { time: startTime }),
|
|
|
+ cancelText: t('feature.track_time_duration.reminders.later'),
|
|
|
+ confirmText: t('feature.track_time_duration.reminders.open'),
|
|
|
+ showCancel: true,
|
|
|
+ cancel: () => {
|
|
|
+ navigation.popToTop()
|
|
|
+ },
|
|
|
+ confirm: () => {
|
|
|
+ if (authStatus != 'not_determined') {
|
|
|
+ navigation.popToTop()
|
|
|
+ }
|
|
|
+ checkNotification()
|
|
|
+ // Linking.openURL('app-settings:notifications')
|
|
|
+ }
|
|
|
+ })
|
|
|
+ }
|
|
|
+ })
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ function popMixScheduleAlert(time1, time2) {
|
|
|
+ console.log(time1, time2)
|
|
|
+ if (process.env.TARO_ENV === 'rn') {
|
|
|
+ const JPush = require('jpush-react-native').default;
|
|
|
+ const checkNotification = require('@/utils/native_permission_check').checkNotification;
|
|
|
+ JPush.isNotificationEnabled((res) => {
|
|
|
+ if (res) {
|
|
|
+ getLocalPush();
|
|
|
+ showAlert({
|
|
|
+ title: t('feature.track_time_duration.reminders.schedule_title'),
|
|
|
+ content: t('feature.track_time_duration.reminders.enable_schedule_mix_content', { time1: time1, time2: time2 }),
|
|
|
+ showCancel: false,
|
|
|
+ confirmText: t('feature.track_time_duration.reminders.ok'),
|
|
|
+ cancel: () => {
|
|
|
+ navigation.popToTop()
|
|
|
+ },
|
|
|
+ confirm: () => {
|
|
|
+ navigation.popToTop()
|
|
|
+ },
|
|
|
+ })
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ showAlert({
|
|
|
+ title: t('feature.track_time_duration.reminders.schedule_title'),
|
|
|
+ content:
|
|
|
+ t('feature.track_time_duration.reminders.schedule_mix_content'),
|
|
|
+ cancelText: t('feature.track_time_duration.reminders.later'),
|
|
|
+ confirmText: t('feature.track_time_duration.reminders.open'),
|
|
|
+ showCancel: true,
|
|
|
+ cancel: () => {
|
|
|
+ navigation.popToTop()
|
|
|
+ },
|
|
|
+ confirm: () => {
|
|
|
+ if (authStatus != 'not_determined') {
|
|
|
+ navigation.popToTop()
|
|
|
+ }
|
|
|
+ checkNotification()
|
|
|
+ // Linking.openURL('app-settings:notifications')
|
|
|
+ }
|
|
|
+
|
|
|
+ })
|
|
|
+ }
|
|
|
+ })
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
function isNextDay(isFast: boolean, isStart: boolean) {
|