diff --git a/app/build.gradle b/app/build.gradle index 965e828..265aec1 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -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" } diff --git a/app/src/main/java/de/cmtjk/linkupconnect/LinkUpConnectService.java b/app/src/main/java/de/cmtjk/linkupconnect/LinkUpConnectService.java index b80f004..2019521 100644 --- a/app/src/main/java/de/cmtjk/linkupconnect/LinkUpConnectService.java +++ b/app/src/main/java/de/cmtjk/linkupconnect/LinkUpConnectService.java @@ -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(); @@ -183,6 +200,7 @@ private void handleGraphResponse(JSONObject response, boolean xDripEnabled, bool } catch (JSONException e) { sendToActivitiesLogView("Getting measurement failed: " + e.getMessage()); + showSetUpAlert(); } } @@ -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(); } } diff --git a/app/src/main/java/de/cmtjk/linkupconnect/MainActivity.java b/app/src/main/java/de/cmtjk/linkupconnect/MainActivity.java index 3041169..c651118 100644 --- a/app/src/main/java/de/cmtjk/linkupconnect/MainActivity.java +++ b/app/src/main/java/de/cmtjk/linkupconnect/MainActivity.java @@ -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) -> {