Browse Source

Add ask user to enable GPS switcher
https://dev.wormwood.com.sg/zentao/task-view-200.html

vbea 2 years ago
parent
commit
18deb86077

+ 3 - 2
Strides-APP/android/build.gradle

@@ -6,7 +6,8 @@ buildscript {
         minSdkVersion = 23
         compileSdkVersion = 33
         targetSdkVersion = 33
-        playServicesVersion = "18.0.0"
+        kotlinVersion = "1.6.21"
+        playServicesVersion = "17.0.0"
         firebaseMessagingVersion = "21.1.0"
         ndkVersion = "23.1.7779620"
         enableHermes = true
@@ -16,7 +17,7 @@ buildscript {
         mavenCentral()
     }
     dependencies {
-        classpath('com.android.tools.build:gradle')
+        classpath("com.android.tools.build:gradle:7.4.2")
         classpath("com.google.gms:google-services:4.3.15")
         classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:1.7.22")
         classpath("com.facebook.react:react-native-gradle-plugin")

+ 1 - 1
Strides-APP/app/pages/chargeV2/SummaryV3.js

@@ -248,7 +248,7 @@ export default class SummaryV3 extends Component {
                     <TextView style={styles.label}>{item.voucherName}</TextView>
                     <TextView style={styles.voucherDesc}>{item.voucherDesc}</TextView>
                   </View>
-                  <TextView style={styles.text}>{"(" + item.voucherValue + ")"}</TextView>
+                  <TextView style={styles.text}>{"(" + item.voucherCurrencySymbol + " " + item.voucherCredit + ")"}</TextView>
                 </View>)
               )}
             </View>

+ 16 - 0
Strides-APP/app/pages/home/Home.js

@@ -43,10 +43,19 @@ export default class HomePage extends Component {
     };
     this.stateListener;
     this.forceUpdateDialog = undefined;
+    this.locationListener = undefined;
   }
 
   componentDidMount() {
     const navigation = this.props.navigation;
+    if (this.locationListener) {
+      this.locationListener.removeListener();
+      this.locationListener = undefined;
+    }
+    this.locationListener = new LocationPermission.LocationListener();
+    if (this.locationListener) {
+      this.locationListener.addListener();
+    }
     navigation.addListener('focus', () => {
       //toastShort('onResume')
       this.setState({
@@ -137,6 +146,12 @@ export default class HomePage extends Component {
     }
   }
 
+  checkGPS() {
+    if (this.locationListener) {
+      this.locationListener.check();
+    }
+  }
+
   onMapReady() {
     this.setState({
       mapReady: true
@@ -207,6 +222,7 @@ export default class HomePage extends Component {
   }
 
   checkPermission2Geo(refresh) {
+    this.checkGPS();
     if (this.state.hasPermission) {
       if (refresh) {
         //避免关闭自动移动地图后无法点击按钮移动地图

+ 45 - 1
Strides-APP/app/pages/home/maps/LocationPermission.js

@@ -7,8 +7,51 @@ import { StyleSheet, View } from 'react-native';
 import { check, openSettings, PERMISSIONS, request, RESULTS } from 'react-native-permissions';
 import Button from '../../../components/Button';
 import TextView from '../../../components/TextView';
+import LocationEnabler from 'react-native-location-enabler';
 
 //global.hasPermission = false;
+const {
+  PRIORITIES: { HIGH_ACCURACY },
+  addListener,
+  checkSettings,
+  requestResolutionSettings
+} = LocationEnabler;
+
+class LocationListener {
+  constructor() {
+    this.listener = undefined;
+    this.config = {
+      priority: HIGH_ACCURACY, // default BALANCED_POWER_ACCURACY
+      alwaysShow: false, // default false
+      needBle: false // default false
+    };
+    this.status = undefined;
+  }
+  
+  addListener() {
+    this.listener = addListener(({ locationEnabled }) => {
+      if (!locationEnabled) {
+        console.log("status: " + this.status  + "," + locationEnabled);
+        if (this.status != locationEnabled) {
+          this.status = locationEnabled;
+          requestResolutionSettings(this.config);
+        }
+      }
+    })
+  }
+
+  removeListener() {
+    if (this.listener) {
+      this.listener.remove();
+    }
+  }
+
+  check() {
+    this.status = undefined;
+    checkSettings(this.config)
+  }
+}
+
 
 /**
  * 检查是否有定位权限
@@ -150,5 +193,6 @@ const styles = StyleSheet.create({
 export default {
   VIEW: LocationPermission,
   checkPermission: checkPermission,
-  requestPermission: getPermission
+  requestPermission: getPermission,
+  LocationListener: LocationListener
 }

+ 1 - 0
Strides-APP/package.json

@@ -47,6 +47,7 @@
     "react-native-gradients": "^2.0.1",
     "react-native-i18n": "https://gitee.com/vbes/react-native-i18n.git",
     "react-native-image-crop-picker": "^0.40.0",
+    "react-native-location-enabler": "^4.1.1",
     "react-native-map-clustering": "^3.4.2",
     "react-native-map-link": "^2.7.27",
     "react-native-maps": "https://gitee.com/vbes/react-native-maps.git",