|
|
@@ -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());
|
|
|
+ }
|
|
|
}
|