Skip to content

Commit 8550452

Browse files
refactor code with api changes
1 parent 87a932d commit 8550452

File tree

2 files changed

+11
-11
lines changed

2 files changed

+11
-11
lines changed

src/main/java/org/medicmobile/webapp/mobile/EmbeddedBrowserActivity.java

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ public void onCreate(Bundle savedInstanceState) {
144144
String recentNavigation = settings.getLastUrl();
145145
if (isValidNavigationUrl(appUrl, recentNavigation)) {
146146
container.loadUrl(recentNavigation);
147-
initializeNotificationWorker(this);
147+
initNotificationWorker(this);
148148
}
149149

150150
}
@@ -238,20 +238,22 @@ protected void onActivityResult(int requestCd, int resultCode, Intent intent) {
238238
}
239239
}
240240

241-
private void initializeNotificationWorker(Context context) {
241+
private void initNotificationWorker(Context context) {
242242
container.setWebViewClient(new WebViewClient() {
243243
@Override
244244
public void onPageFinished(WebView view, String url) {
245245
String jsCheckApi = "(() => typeof window.CHTCore.AndroidApi.v1.taskNotifications === 'function')();";
246246
container.evaluateJavascript(jsCheckApi, new ValueCallback<String>() {
247247
@Override
248-
public void onReceiveValue(String s) {
249-
if (!hasCheckedForNotificationApi && Objects.equals(s, "true")) {
248+
public void onReceiveValue(String hasApi) {
249+
if (!hasCheckedForNotificationApi && !Objects.equals(hasApi, "null")) {
250250
hasCheckedForNotificationApi = true;
251-
if (appNotificationManager.hasNotificationPermission()) {
251+
if (Objects.equals(hasApi, "true") &&
252+
appNotificationManager.hasNotificationPermission()) {
252253
startNotificationWorker(context);
253254
} else {
254255
WorkManager.getInstance(context).cancelAllWorkByTag(NOTIFICATION_WORK_REQUEST_TAG);
256+
log(this, "initNotificationWorker() :: stopped notification worker manager");
255257
}
256258
}
257259
}

src/main/java/org/medicmobile/webapp/mobile/NotificationWorker.java

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,8 @@ public Result doWork() {
4949
public void onPageFinished(WebView view, String url) {
5050
String js = "(async function (){" +
5151
" const api = window.CHTCore.AndroidApi;" +
52-
" if (api && api.v1 && api.v1.taskNotifications) {" +
53-
" const tasks = await api.v1.taskNotifications();" +
54-
" CHTNotificationBridge.onJsResult(JSON.stringify(tasks));" +
55-
" }" +
52+
" const tasks = await api.v1.taskNotifications();" +
53+
" CHTNotificationBridge.onJsResult(JSON.stringify(tasks));" +
5654
"})();";
5755
view.evaluateJavascript(js, null);
5856
}
@@ -99,8 +97,8 @@ public void onJsResult(String data) throws JSONException {
9997
JSONObject task = dataArray.getJSONObject(i);
10098
String contentText = task.getString("contentText");
10199
String title = task.getString("title");
102-
long authoredOn = task.getLong("authoredOn");
103-
int notificationId = (int) (authoredOn % Integer.MAX_VALUE);
100+
long readyAt = task.getLong("readyAt");
101+
int notificationId = (int) (readyAt % Integer.MAX_VALUE);
104102
appNotificationManager.showNotification(notificationId + i, title, contentText);
105103
}
106104
latch.countDown();

0 commit comments

Comments
 (0)