Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid redundant calls #11

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 26 additions & 19 deletions lib/android/src/main/java/com/scan/AppUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,15 @@ public static void createNotifyRequestBluetooth(Context context) throws JSONExce
} catch (JSONException e) {
e.printStackTrace();
}

long now = System.currentTimeMillis();
Calendar calendar = Calendar.getInstance();
calendar.set(Calendar.HOUR_OF_DAY, 0);
calendar.set(Calendar.MINUTE, 0);
calendar.set(Calendar.SECOND, 0);
calendar.set(Calendar.MILLISECOND, 0);
long beginningOfToday = calendar.getTimeInMillis();

for (int i = 0; i < itemRepeatArray.length(); i++) {
JSONObject item = itemRepeatArray.getJSONObject(i);
if(!item.has("id")) {
Expand All @@ -270,13 +278,7 @@ public static void createNotifyRequestBluetooth(Context context) throws JSONExce
int dayStartTime = item.getInt("dayStartTime");
int repeatTime = item.getInt("repeatTime");

Calendar calendar = Calendar.getInstance();
calendar.setTimeInMillis(now);
calendar.set(Calendar.HOUR_OF_DAY, 0);
calendar.set(Calendar.MINUTE, 0);
calendar.set(Calendar.SECOND, 0);
calendar.set(Calendar.MILLISECOND, 0);
long iTime = calendar.getTimeInMillis() + dayStartTime;
long iTime = beginningOfToday + dayStartTime;
if (iTime < now) {
iTime += 86400000;
}
Expand Down Expand Up @@ -365,7 +367,14 @@ public static void createNotifyRequestLocation(Context context) throws JSONExcep
} catch (JSONException e) {
e.printStackTrace();
}

long now = System.currentTimeMillis();
Calendar calendar = Calendar.getInstance();
calendar.set(Calendar.HOUR_OF_DAY, 0);
calendar.set(Calendar.MINUTE, 0);
calendar.set(Calendar.MILLISECOND, 0);
long beginningOfToday = calendar.getTimeInMillis();

for (int i = 0; i < itemRepeatArray.length(); i++) {
JSONObject item = itemRepeatArray.getJSONObject(i);
if(!item.has("id")) {
Expand All @@ -375,12 +384,7 @@ public static void createNotifyRequestLocation(Context context) throws JSONExcep
int dayStartTime = item.getInt("dayStartTime");
int repeatTime = item.getInt("repeatTime");

Calendar calendar = Calendar.getInstance();
calendar.setTimeInMillis(now);
calendar.set(Calendar.HOUR_OF_DAY, 0);
calendar.set(Calendar.MINUTE, 0);
calendar.set(Calendar.MILLISECOND, 0);
long iTime = calendar.getTimeInMillis() + dayStartTime;
long iTime = beginningOfToday + dayStartTime;
if (iTime < now) {
iTime += 86400000;
}
Expand Down Expand Up @@ -450,7 +454,15 @@ public static void createNotifyRequestPermisson(Context context) throws JSONExce
} catch (JSONException e) {
e.printStackTrace();
}

long now = System.currentTimeMillis();
Calendar calendar = Calendar.getInstance();
calendar.set(Calendar.HOUR_OF_DAY, 0);
calendar.set(Calendar.MINUTE, 0);
calendar.set(Calendar.SECOND, 0);
calendar.set(Calendar.MILLISECOND, 0);
long beginningOfToday = calendar.getTimeInMillis();

for (int i = 0; i < itemRepeatArray.length(); i++) {
JSONObject item = itemRepeatArray.getJSONObject(i);
if(!item.has("id")) {
Expand All @@ -460,12 +472,7 @@ public static void createNotifyRequestPermisson(Context context) throws JSONExce
int dayStartTime = item.getInt("dayStartTime");
int repeatTime = item.getInt("repeatTime");

Calendar calendar = Calendar.getInstance();
calendar.setTimeInMillis(now);
calendar.set(Calendar.HOUR_OF_DAY, 0);
calendar.set(Calendar.MINUTE, 0);
calendar.set(Calendar.MILLISECOND, 0);
long iTime = calendar.getTimeInMillis() + dayStartTime;
long iTime = beginningOfToday + dayStartTime;
if (iTime < now) {
iTime += 86400000;
}
Expand Down