Skip to content

Commit

Permalink
Implement alerts from service, implement setup alert, #6
Browse files Browse the repository at this point in the history
  • Loading branch information
cmtjk committed Dec 21, 2022
1 parent 64cac4e commit 609a01c
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 3 deletions.
2 changes: 1 addition & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ android {
minSdk 28
targetSdk 32
versionCode 1
versionName "1.3.3"
versionName "1.3.4-SNAPSHOT"

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
Expand Down
19 changes: 19 additions & 0 deletions app/src/main/java/de/cmtjk/linkupconnect/LinkUpConnectService.java
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,23 @@ private void sendToActivitiesLogView(String message) {
LocalBroadcastManager.getInstance(getApplicationContext()).sendBroadcast(intent);
}

private void showAlert(String message) {
Intent intent = new Intent(LOCAL_BROADCAST);
intent.putExtra("ALERT", message);
LocalBroadcastManager.getInstance(getApplicationContext()).sendBroadcast(intent);
}

private void showSetUpAlert() {
showAlert("No valid data received.\n\n" +
"Do you have connected your app?\n" +
"Libre 3/LibreLink ➡ Connected Apps ➡ LibreLinkUp\n\n" +
"Do you have accepted your connection in LibreLinkUp app?\n" +
"LibreLinkUp ➡ accept connection\n\n" +
"Do you have accepted the TOS?\n" +
"Libre 3/LibreLink ➡ accept TOS\n\n" +
"If you just set up your connection please wait a moment.");
}

@Override
public int onStartCommand(Intent intent, int flags, int startId) {
setUpNotification();
Expand Down Expand Up @@ -183,6 +200,7 @@ private void handleGraphResponse(JSONObject response, boolean xDripEnabled, bool

} catch (JSONException e) {
sendToActivitiesLogView("Getting measurement failed: " + e.getMessage());
showSetUpAlert();
}
}

Expand Down Expand Up @@ -336,6 +354,7 @@ private void handleConnectionResponse(JSONObject response, RequestQueue queue, S
queue.add(graphRequest);
} catch (JSONException e) {
sendToActivitiesLogView("Getting connections failed: " + e.getMessage());
showSetUpAlert();
}
}

Expand Down
25 changes: 23 additions & 2 deletions app/src/main/java/de/cmtjk/linkupconnect/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -156,21 +156,42 @@ private void configureLocalBroadcaster(TextView logTextView, ScrollView logScrol
new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
if (debugEnabled()) {
if (debugEnabled() && isLogMessage(intent)) {
logTextView.append("[" + LocalDateTime.now().format(DateTimeFormatter.ofPattern("HH:mm:ss")) + "] ");
logTextView.append(intent.getStringExtra("LOG"));
logTextView.append("\n");
logScrollView.fullScroll(ScrollView.FOCUS_DOWN);
}
}

if (isAlert(intent)) {
showAlert(intent.getStringExtra("ALERT"));
}

}
private boolean debugEnabled() {
return ((CheckBox) findViewById(R.id.debug)).isChecked();
}

private boolean isLogMessage(Intent intent) {
return intent.getStringExtra("LOG") != null && !intent.getStringExtra("LOG").isEmpty();
}

private boolean isAlert(Intent intent) {
return intent.getStringExtra("ALERT") != null && !intent.getStringExtra("ALERT").isEmpty();
}
}, new IntentFilter(LinkUpConnectService.LOCAL_BROADCAST)
);
}

private void showAlert(String message) {
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle("ℹ️ Information")
.setMessage(message)
.setPositiveButton("Ok", (dialog, id) -> {});
AlertDialog dialog = builder.create();
dialog.show();
}

private void configureDebugCheckBox(TextView logTextView) {
CheckBox debugCheckBox = findViewById(R.id.debug);
debugCheckBox.setOnCheckedChangeListener((compoundButton, checked) -> {
Expand Down

0 comments on commit 609a01c

Please sign in to comment.