Leon il y a 1 an
Parent
commit
09ce4bb15d

Fichier diff supprimé car celui-ci est trop grand
+ 0 - 0
android/app/src/main/assets/index.android.bundle


Fichier diff supprimé car celui-ci est trop grand
+ 0 - 0
android/app/src/main/assets/index.android.map


+ 14 - 6
android/app/src/main/java/com/hola/AlarmReceiver.java

@@ -26,6 +26,7 @@ public class AlarmReceiver extends BroadcastReceiver {
         String channel = intent.getStringExtra("channel");
         String categoryId = intent.getStringExtra("categoryId");
         String strId = intent.getStringExtra("id");
+        String mode = intent.getStringExtra("mode");
         int msg_id = intent.getIntExtra("msg_id",0);
         Log.i("set alarm status:","收到推送设置");
 
@@ -84,20 +85,27 @@ public class AlarmReceiver extends BroadcastReceiver {
 
         notificationManager.notify(msg_id, builder.build());
 
-//        repeatNotify(context,categoryId);
-    }
+        Log.i("set alarm status:",mode);
+        if (mode.equals("RECURRING")){
+            repeatNotify(context,categoryId,title,message,strId,mode);
+        }
 
-    public static void repeatNotify(Context context,String categoryId){
+    }
 
+    public static void repeatNotify(Context context,String categoryId,String title,String body,String strId,String mode){
+        Log.i("set alarm status:","收到推送设置2");
         Intent intent = new Intent(context, AlarmReceiver.class);
-        intent.putExtra("title", "title");
-        intent.putExtra("message", "body");
+        intent.putExtra("title", title);
+        intent.putExtra("message", body);
         intent.putExtra("categoryId",categoryId);
+        intent.putExtra("id",strId);
+        intent.putExtra("mode",mode);
+
         PendingIntent pendingIntent = PendingIntent.getBroadcast(
                 context, 0, intent, android.app.PendingIntent.FLAG_UPDATE_CURRENT);
 
         AlarmManager alarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
-        alarmManager.setExact(AlarmManager.ELAPSED_REALTIME_WAKEUP, SystemClock.elapsedRealtime()+10*1000,pendingIntent);
+        alarmManager.setExact(AlarmManager.ELAPSED_REALTIME_WAKEUP, SystemClock.elapsedRealtime()+24*3600*1000,pendingIntent);
     }
 
 //    @Override

+ 81 - 40
android/app/src/main/java/com/hola/HolaModule.java

@@ -38,6 +38,7 @@ import org.json.JSONArray;
 import org.json.JSONException;
 import org.json.JSONObject;
 
+import java.time.LocalTime;
 import java.util.Arrays;
 import java.util.Calendar;
 import java.util.List;
@@ -57,7 +58,7 @@ public class HolaModule extends ReactContextBaseJavaModule {
     public HolaModule(@Nullable ReactApplicationContext reactContext) {
         super(reactContext);
     }
-    private static final String MODULE_NAME = "HolaModule";
+    private static final String MODULE_NAME = "NativeBridge";
     @NonNull
     @Override
     public String getName() {
@@ -148,6 +149,7 @@ public class HolaModule extends ReactContextBaseJavaModule {
                 intent.putExtra("id",strId);
                 intent.putExtra("categoryId",categoryId);
                 intent.putExtra("msg_id",i);
+                intent.putExtra("mode",mode);
                 intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
 
                 PendingIntent pendingIntent = PendingIntent.getBroadcast(
@@ -173,20 +175,38 @@ public class HolaModule extends ReactContextBaseJavaModule {
                     JSONObject recurring = jsonObject.getJSONObject("recurring");
                     String time = recurring.getString("time");
                     String[] parts = time.split(":");
-                    Calendar calendar = Calendar.getInstance();
-                    calendar.setTimeInMillis(System.currentTimeMillis());
-                    calendar.set(Calendar.HOUR_OF_DAY, Integer.parseInt(parts[0]));
-                    calendar.set(Calendar.MINUTE, Integer.parseInt(parts[1]));
-                    calendar.set(Calendar.SECOND,Integer.parseInt(parts[2]));
-
-                    // 如果当前时间已经超过 设定时间,则设置为明天
-                    if (calendar.getTimeInMillis() <= System.currentTimeMillis()) {
-                        calendar.add(Calendar.DAY_OF_YEAR, 1);
+
+
+                    // 获取当前系统时间
+                    Calendar currentTime = Calendar.getInstance();
+                    // 提取时、分、秒
+                    int hour = currentTime.get(Calendar.HOUR_OF_DAY);
+                    int minute = currentTime.get(Calendar.MINUTE);
+                    int second = currentTime.get(Calendar.SECOND);
+
+                    int currentSeconds = hour*3600+minute*60+second;
+                    int targetSeconds = Integer.parseInt(parts[0])*3600+Integer.parseInt(parts[1])*60+Integer.parseInt(parts[2]);
+
+                    int leftSeconds = targetSeconds-currentSeconds;
+                    if (leftSeconds<0){
+                        leftSeconds += 24*3600;
                     }
 
-                    alarmManager.setRepeating(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(),
-                            AlarmManager.INTERVAL_DAY, pendingIntent);
-                    Log.i("set alarm status:",time);
+                    alarmManager.setExact(AlarmManager.ELAPSED_REALTIME_WAKEUP, SystemClock.elapsedRealtime()+leftSeconds*1000,pendingIntent);
+
+//                    Calendar calendar = Calendar.getInstance();
+//                    calendar.setTimeInMillis(System.currentTimeMillis());
+//                    calendar.set(Calendar.HOUR_OF_DAY, Integer.parseInt(parts[0]));
+//                    calendar.set(Calendar.MINUTE, Integer.parseInt(parts[1]));
+//                    calendar.set(Calendar.SECOND,Integer.parseInt(parts[2]));
+//                    // 如果当前时间已经超过 设定时间,则设置为明天
+//                    if (calendar.getTimeInMillis() <= System.currentTimeMillis()) {
+//                        calendar.add(Calendar.DAY_OF_YEAR, 1);
+//                    }
+//
+//                    alarmManager.setRepeating(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(),
+//                            AlarmManager.INTERVAL_DAY, pendingIntent);
+//                    Log.i("set alarm status:",time);
 
                 }
 
@@ -205,6 +225,15 @@ public class HolaModule extends ReactContextBaseJavaModule {
         GlobalVariable.rnLoaded = true;
     }
 
+    private void createNotificationChannel(Context context,String channelId) {
+        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
+            NotificationChannel channel = new NotificationChannel(channelId, channelId, NotificationManager.IMPORTANCE_HIGH);
+            channel.setDescription(CHANNEL_DESCRIPTION);
+
+            NotificationManager notificationManager = context.getSystemService(NotificationManager.class);
+            notificationManager.createNotificationChannel(channel);
+        }
+    }
     @ReactMethod
     public void getLocation(Promise promise){
         Context context = getReactApplicationContext();
@@ -217,14 +246,37 @@ public class HolaModule extends ReactContextBaseJavaModule {
         //step2
         boolean hasGPS = locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER);
         boolean hasNetwork = locationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER);
+        boolean hasPassive = locationManager.isProviderEnabled(LocationManager.PASSIVE_PROVIDER);
         //step3
 
+        if (hasPassive){
+            Location location = locationManager.getLastKnownLocation(LocationManager.PASSIVE_PROVIDER);
+            if (location!=null){
+                resolveGPS(location);
+                stopLocation();
+                return;
+            }
+        }
+
+
         if (hasGPS) {
+            Location location = locationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER);
+            if (location!=null){
+                resolveGPS(location);
+                stopLocation();
+                return;
+            }
             locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 5000, 0f,
                     gpsListener);
         }
 
         if (hasNetwork){
+            Location location = locationManager.getLastKnownLocation(LocationManager.NETWORK_PROVIDER);
+            if (location!=null){
+                resolveGPS(location);
+                stopLocation();
+                return;
+            }
             locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 5000, 0f,
                     networkListener);
         }
@@ -238,20 +290,12 @@ public class HolaModule extends ReactContextBaseJavaModule {
                 stopLocation();
             }
         };
-        handler.postDelayed(runnable,300000);
+        handler.postDelayed(runnable,30000);
 
 
     }
 
-    private void createNotificationChannel(Context context,String channelId) {
-        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
-            NotificationChannel channel = new NotificationChannel(channelId, channelId, NotificationManager.IMPORTANCE_HIGH);
-            channel.setDescription(CHANNEL_DESCRIPTION);
 
-            NotificationManager notificationManager = context.getSystemService(NotificationManager.class);
-            notificationManager.createNotificationChannel(channel);
-        }
-    }
 
     private void stopLocation(){
         Context context = getReactApplicationContext();
@@ -290,14 +334,7 @@ public class HolaModule extends ReactContextBaseJavaModule {
             // 更新当前经纬度
             gpsLocation = arg0;
 
-            JSONObject data = new JSONObject();
-            try {
-                data.put("latitude", gpsLocation.getLatitude());
-                data.put("longitude", gpsLocation.getLongitude());
-            } catch (JSONException e) {
-                throw new RuntimeException(e);
-            }
-            locationPromise.resolve(data.toString());
+            resolveGPS(gpsLocation);
 
             stopLocation();
         }
@@ -328,19 +365,23 @@ public class HolaModule extends ReactContextBaseJavaModule {
             // TODO Auto-generated method stub
             // 更新当前经纬度
             networkLocation = arg0;
-
-            JSONObject data = new JSONObject();
-            try {
-                data.put("latitude", networkLocation.getLatitude());
-                data.put("longitude", networkLocation.getLongitude());
-            } catch (JSONException e) {
-                throw new RuntimeException(e);
-            }
-            locationPromise.resolve(data.toString());
-
+            resolveGPS(networkLocation);
             stopLocation();
         }
 
 
+
+
     };
+
+    private void resolveGPS(Location location){
+        JSONObject data = new JSONObject();
+        try {
+            data.put("latitude", location.getLatitude());
+            data.put("longitude", location.getLongitude());
+        } catch (JSONException e) {
+            throw new RuntimeException(e);
+        }
+        locationPromise.resolve(data.toString());
+    }
 }

+ 17 - 1
android/app/src/main/java/com/hola/MainActivity.java

@@ -72,7 +72,7 @@ public class MainActivity extends ReactActivity {
   protected void onCreate(Bundle savedInstanceState) {
     super.onCreate(null);
     checkNotification(getIntent());
-    demo2();
+//    demo2();
 //    demo();
 //    getLastKnownLocation();
 //    String action = getIntent().getAction();
@@ -88,15 +88,31 @@ public class MainActivity extends ReactActivity {
     //step2
     boolean hasGPS = locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER);
     boolean hasNetwork = locationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER);
+    boolean hasPassive = locationManager.isProviderEnabled(LocationManager.PASSIVE_PROVIDER);
     //step3
 
+    if (hasPassive){
+      Location location = locationManager.getLastKnownLocation(LocationManager.PASSIVE_PROVIDER);
+      if (location!=null){
+        Log.i("LLLLLLLLLLLLLLocation","passive enable");
+      }
+    }
+
     if (hasGPS) {
+      Location location = locationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER);
+      if (location!=null){
+        Log.i("LLLLLLLLLLLLLLocation","gps enable");
+      }
       locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 5000, 0f,
               gpsListener);
       Log.i("LLLLLLLLLLLLLLocation","GPS enable");
     }
 
     if (hasNetwork){
+      Location location = locationManager.getLastKnownLocation(LocationManager.NETWORK_PROVIDER);
+      if (location!=null){
+        Log.i("LLLLLLLLLLLLLLocation","network enable");
+      }
       locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 5000, 0f,
               networkListener);
       Log.i("LLLLLLLLLLLLLLocation","Network enable");

+ 55 - 112
src/features/daynight/DayNightSwiperPopup.tsx

@@ -6,7 +6,7 @@ import { useTranslation } from 'react-i18next'
 import Taro from '@tarojs/taro'
 import { systemLocation } from '@/services/common'
 import showAlert from '@/components/basic/Alert'
-import { getTimezone, kIsIOS, rpxToPx } from '@/utils/tools'
+import { getTimezone, kIsAndroid, kIsIOS, rpxToPx } from '@/utils/tools'
 import { clearLocation } from '@/services/user'
 import { TimeFormatter } from '@/utils/time_format'
 
@@ -180,7 +180,7 @@ export default function DayNightSwiperPopup(props: { authInfo: any }) {
                 authLocation()
             }
             else {
-                var Jto = require('react-native').NativeModules.HolaModule;
+                var Jto = require('react-native').NativeModules.NativeBridge;
                 Jto.checkSystemLocationService().then(res => {
                     console.log('授权状态', res)
                     if (res) {
@@ -205,85 +205,10 @@ export default function DayNightSwiperPopup(props: { authInfo: any }) {
     }
 
     function authLocation() {
-        var today = new Date()
-        var yesterday = new Date(today.getTime() - 24 * 3600 * 1000)
-        var tomorrow = new Date(today.getTime() + 24 * 3600 * 1000 * 5)
-        var strYesterday = `${yesterday.getFullYear()}-${TimeFormatter.padZero(yesterday.getMonth() + 1)}-${TimeFormatter.padZero(yesterday.getDate())}`
-        var strTomorrow = `${tomorrow.getFullYear()}-${TimeFormatter.padZero(tomorrow.getMonth() + 1)}-${TimeFormatter.padZero(tomorrow.getDate())}`
-
         if (process.env.TARO_ENV == 'rn') {
-            // var Geolocation = require('@react-native-community/geolocation').default
-            // Geolocation.getCurrentPosition(
-            //     ({ coords }) => {
-            //         console.log('location update success',coords)
-            //         const { latitude, longitude, altitude, accuracy, speed } = coords
-            //         const res = {
-            //             latitude,
-            //             longitude,
-            //             speed: speed ?? 0,
-            //             altitude: altitude ?? 0,
-            //             accuracy,
-            //             verticalAccuracy: 0,
-            //             horizontalAccuracy: 0,
-            //             errMsg: 'getLocation:ok'
-            //         }
-
-            //     },
-            //     (err) => {
-            //         console.log('location update failed',err)
-            //         const res = {
-            //             errMsg: 'getLocation fail',
-            //             err
-            //         }
-
-            //     },
-            //     {
-            //         // 当 maximumAge 为 0 时,如果不设置 timeout 或 timeout 太少可能会超时
-            //         timeout: 10000,
-            //         // maximumAge 设置为 0 则会获取当前位置,而不是获取一个前不久缓存的位置
-            //         maximumAge: 100000000,
-            //         enableHighAccuracy: true
-            //     }
-            // );
             Taro.getLocation({
-                highAccuracyExpireTime: 20000,
-                isHighAccuracy:true,
                 success(res) {
-                    systemLocation({
-                        lat: res.latitude,
-                        lng: res.longitude,
-                        date_start: strYesterday,
-                        date_end: strTomorrow,
-                        coordinate_system_standard: 'WGS-84'
-                    }).then(data => {
-                        global.swiperDayNightRefresh()
-                        global.refreshNight()
-                        global.refreshDay()
-                        // updateDate(data);
-                        global.locationDetail = data
-                        setAuthInfo(data as any)
-                        Taro.setStorage({
-                            key: 'gps',
-                            data: JSON.stringify(data as any)
-                        })
-                        // dispatch(updateMember({ isMember: isMember, gpsInfo: (data as any) }))
-                        // if (Taro.getSystemInfoSync().platform == 'android' && process.env.TARO_ENV == 'rn') {
-                        //     var ToastAndroid = require('react-native').ToastAndroid;
-                        //     ToastAndroid.show(t('feature.day_night.location_updated'), ToastAndroid.LONG);
-                        // }
-                        // else {
-                        showAlert({
-                            title: 'Success',
-                            content: t('feature.day_night.location_updated'),
-                            showCancel: false
-                        })
-                        // Taro.showToast({
-                        //     title: t('feature.day_night.location_updated'),
-                        //     icon: 'none'
-                        // })
-                        // }
-
-                    })
+                    uploadLocation(res);
                 },
                 fail(res) {
                     console.log('location update failed reason', res)
@@ -300,7 +225,7 @@ export default function DayNightSwiperPopup(props: { authInfo: any }) {
                                 }
                                 else {
                                     // Linking.openSettings()
-                                    var Jto = require('react-native').NativeModules.HolaModule;
+                                    var Jto = require('react-native').NativeModules.NativeBridge;
                                     Jto.openNotificationSettings()
                                 }
 
@@ -309,19 +234,23 @@ export default function DayNightSwiperPopup(props: { authInfo: any }) {
                     }
                     else {
                         if (Taro.getSystemInfoSync().platform == 'android' && process.env.TARO_ENV == 'rn') {
-                            var ToastAndroid = require('react-native').ToastAndroid;
-                            ToastAndroid.show(t('feature.day_night.location_failed'), ToastAndroid.LONG);
+
+                            var Jto = require('react-native').NativeModules.NativeBridge;
+                            Jto.getLocation().then(result => {
+                                uploadLocation(JSON.parse(result));
+
+                            }).catch(e => {
+                                console.log('rn location error', e)
+                                var ToastAndroid = require('react-native').ToastAndroid;
+                                ToastAndroid.show(t('feature.day_night.location_failed'), ToastAndroid.LONG);
+                            })
                         }
                         else {
                             showAlert({
                                 title: 'Error',
-                                content: t('feature.day_night.location_updated'),
+                                content: t('feature.day_night.location_failed'),
                                 showCancel: false
                             })
-                            // Taro.showToast({
-                            //     title: t('feature.day_night.location_failed'),
-                            //     icon: 'none'
-                            // })
                         }
                     }
                     console.log(res)
@@ -336,32 +265,7 @@ export default function DayNightSwiperPopup(props: { authInfo: any }) {
             latitude: authInfo && authInfo.lat ? authInfo.lat : undefined,
             longitude: authInfo && authInfo.lat ? authInfo.lng : undefined,
             success: function (res) {
-
-                systemLocation({
-                    lat: res.latitude,
-                    lng: res.longitude,
-                    name: res.name,
-                    address: res.address,
-                    date_start: strYesterday,
-                    date_end: strTomorrow,
-                    coordinate_system_standard: 'GCJ-02'
-                }).then(data => {
-                    // updateDate(data);
-                    global.locationDetail = data
-                    setAuthInfo(data as any)
-                    Taro.setStorage({
-                        key: 'gps',
-                        data: JSON.stringify(data as any)
-                    })
-                    // dispatch(updateMember({ isMember: isMember, gpsInfo: (data as any) }))
-
-                    if (global.swiperDayNightRefresh) {
-                        global.swiperDayNightRefresh()
-                    }
-                    global.refreshNight()
-                    global.refreshDay()
-                })
-
+                uploadLocation(res)
             },
             fail(res) {
                 Taro.showToast({
@@ -375,6 +279,45 @@ export default function DayNightSwiperPopup(props: { authInfo: any }) {
         })
     }
 
+    function uploadLocation(res) {
+        var today = new Date()
+        var yesterday = new Date(today.getTime() - 24 * 3600 * 1000)
+        var tomorrow = new Date(today.getTime() + 24 * 3600 * 1000 * 5)
+        var strYesterday = `${yesterday.getFullYear()}-${TimeFormatter.padZero(yesterday.getMonth() + 1)}-${TimeFormatter.padZero(yesterday.getDate())}`
+        var strTomorrow = `${tomorrow.getFullYear()}-${TimeFormatter.padZero(tomorrow.getMonth() + 1)}-${TimeFormatter.padZero(tomorrow.getDate())}`
+
+        systemLocation({
+            lat: res.latitude,
+            lng: res.longitude,
+            name: res.name,
+            address: res.address,
+            date_start: strYesterday,
+            date_end: strTomorrow,
+            coordinate_system_standard: process.env.TARO_ENV == 'weapp' ? 'GCJ-02' : 'WGS-84'
+        }).then(data => {
+            global.locationDetail = data
+            setAuthInfo(data as any)
+            Taro.setStorage({
+                key: 'gps',
+                data: JSON.stringify(data as any)
+            })
+            // dispatch(updateMember({ isMember: isMember, gpsInfo: (data as any) }))
+
+            if (global.swiperDayNightRefresh) {
+                global.swiperDayNightRefresh()
+            }
+            global.refreshNight()
+            global.refreshDay()
+            if (process.env.TARO_ENV == 'rn') {
+                showAlert({
+                    title: 'Success',
+                    content: t('feature.day_night.location_updated'),
+                    showCancel: false
+                })
+            }
+        })
+    }
+
     global.showDayNightSwiperPop = (isNight, strNight, strDay) => {
         setNightDate(strNight)
         setDayDate(strDay)

+ 4 - 4
src/features/trackTimeDuration/actions/TrackTimeActions.tsx

@@ -150,8 +150,8 @@ export const getLocalPush = () => {
                         return;
                     }
                     else {
-                        const { HolaModule } = NativeModules
-                        HolaModule.addLocalPush(JSON.stringify(messages))
+                        const { NativeBridge } = NativeModules
+                        NativeBridge.addLocalPush(JSON.stringify(messages))
                         return;
                     }
 
@@ -197,8 +197,8 @@ export const getLocalPush = () => {
                                     console.log('leon 9527')
                                     const { time, repeat_type } = item.recurring;
                                     const date = dayjs().format('YYYY-MM-DD')
-                                    const { HolaModule } = NativeModules
-                                    HolaModule.addLocalPush(item.title, item.body + '\nPress for actions >>', time)
+                                    const { NativeBridge } = NativeModules
+                                    NativeBridge.addLocalPush(item.title, item.body + '\nPress for actions >>', time)
                                     return;
 
                                     PushNotification.localNotificationSchedule({

+ 1 - 1
src/pages/clock/ClockMain.tsx

@@ -517,7 +517,7 @@ export default function Page() {
                     Jto.rnPageLoaded()
                 }
                 else {
-                    var Jto = require('react-native').NativeModules.HolaModule;
+                    var Jto = require('react-native').NativeModules.NativeBridge;
                     Jto.rnPageLoaded()
                 }
             }

+ 1 - 1
src/utils/native_permission_check.tsx

@@ -23,7 +23,7 @@ export const uploadPermissions = () => {
                 else {
                     global.notification = 'denied'
                 }
-                var Jto = require('react-native').NativeModules.HolaModule;
+                var Jto = require('react-native').NativeModules.NativeBridge;
                 Jto.checkSystemLocationService().then(enableLocation=>{
                     clientInfo({
                         perm: {

+ 2 - 1
src/utils/tools.ts

@@ -131,4 +131,5 @@ export function getTimezoneId() {
     }
 }
 
-export const kIsIOS = Taro.getSystemInfoSync().platform == 'ios'
+export const kIsIOS = Taro.getSystemInfoSync().platform == 'ios'
+export const kIsAndroid = Taro.getSystemInfoSync().platform == 'android'

Certains fichiers n'ont pas été affichés car il y a eu trop de fichiers modifiés dans ce diff