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

Don't ask user to start G6 before connectivity #2757

Merged
merged 2 commits into from
Jun 24, 2023

Conversation

Navid200
Copy link
Collaborator

@Navid200 Navid200 commented Mar 31, 2023

After selecting G6 in source wizard, a red notification on the main screen asks user to start sensor or change settings.
Shortly after, a dialog appears asking user to start sensor.

This PR delays those until transmitter number of days resolves to a valid integer.
In the meantime, it shows the following instead.
Screenshot_20230331-004622

This PR complements this PR: #2746
But, the two PRs are independent. Meaning if you merge only one and hold off on the other for more info, there will be no issue. It will still be a step forward,

@@ -2612,7 +2614,12 @@ private void updateCurrentBgInfoCommon(DexCollectionType collector, TextView not
}

if (!isSensorActive) {
notificationText.setText(R.string.now_start_your_sensor);
boolean G6_not_connected_yet = Pref.getBooleanDefaultFalse("using_g6") && DexTimeKeeper.getTransmitterAgeInDays(getTransmitterID()) == -1;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could stick to the Java convention that variable names should be camelCase, i.e. start with a lower character.

Suggested change
boolean G6_not_connected_yet = Pref.getBooleanDefaultFalse("using_g6") && DexTimeKeeper.getTransmitterAgeInDays(getTransmitterID()) == -1;
boolean g6NotConnectedYet = Pref.getBooleanDefaultFalse("using_g6") && DexTimeKeeper.getTransmitterAgeInDays(getTransmitterID()) == -1;

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My objective is to get this change added so that xDrip functionality improves for the inexperienced user.
I am more than happy to make any necessary change to get approval.

Therefore, if I am told that this is what's holding this PR up, I will change it.

Let me add that looking at this same file, I can see plenty of existing uppercase instances. For example:

private static final int SHOWCASE_G5FIRMWARE = 9;

So, SHOWCASE_G5FIRMWARE is already there. If we are going to change the code for some reason, we should be consistent.
If, we want to say, let's leave the existing cases alone. But, let's follow this guideline for the new variables, I am happy to follow such a guideline if I can get an approval of it.

So, I thank you for having a look and making the suggestion. But, I am not going to make your requested change because I have no idea it is going to make any difference in what really matters in getting this approved or not.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It just caught my eye when skimming through your PR. The constant in line 258 is fine by convention. https://www.oracle.com/java/technologies/javase/codeconventions-namingconventions.html

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks a lot for providing this guidance.
I will change to follow the standard. I have no reason not to follow it.

@Navid200 Navid200 marked this pull request as draft April 7, 2023 23:12
@Navid200 Navid200 marked this pull request as ready for review April 7, 2023 23:46
@@ -2628,7 +2635,7 @@ private void updateCurrentBgInfoCommon(DexCollectionType collector, TextView not
dialog = builder.create();
dialog.show();
} else {
if (!Experience.gotData() && !QuickSettingsDialogs.isDialogShowing() && JoH.ratelimit("start-sensor_prompt", 20)) {
if (!Experience.gotData() && !QuickSettingsDialogs.isDialogShowing() && JoH.ratelimit("start-sensor_prompt", 20) && !notConnectedToG6Yet) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So your !notConnectedToG6Yet condition should come before the ratelimit as everything to the right of the ratelimit is not evaluated when the ratelimit has been exceeded. I believe in this case you would only want the ratelimit to restricting firing of the conditional block after all conditions have been met.

Copy link
Collaborator Author

@Navid200 Navid200 Apr 10, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have looked at this again. I don't believe there is any issue:

If anything in the if statement fails to be true, like the ratelimit, we don't care, we don't want it to be true then. In that case, we want the "if" statement to fail as it did before this PR anyway.

But, if everything in the "if" statement is true, we are adding one more check. In that case, only if the user has not selected G6, or G6 is already connected, do we allow the command to be executed.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In other words, if the user has not selected G6 or if they have and it is already connected, the dialog will be shown as it did before this PR.
However, if G6 is selected and is not connected yet, this PR does not allow the dialog to be shown.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes but if the user reaches the condition and the timekeeper condition is not met, but then the connection occurs in the background and would be true and the user then re-enters this conditional block again within the 20 second rate limit period, it will fail because the ratelimit has been triggered even though it otherwise would have passed if the check order is changed so the ratelimiting is last. The && operator means the other clauses are not evaluated once one is false. Simply checking the ratelimit by calling its method triggers the time to be stored so that the condition will fail the next time you call it within the specified time period.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm so sorry I don't follow you.
I keep comparing what xDrip does now to what I want it to do after this PR, to help me see that this PR is correct.

If ratelimit fails, xDrip does not show the dialog right now. In that case, I don't want xDrip to show the dialog after this PR either. So, I don't understand the dellima you are describing.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry!
I misunderstood the purpose of the bracket. As soon as ratelimit executes, it is going to show the dialog.
Thanks for catching this.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested

@jamorham
Copy link
Collaborator

This doesn't seem to be conditional on using dex collection type so I think it would break for other collector types as the condition can never be met.

@Navid200
Copy link
Collaborator Author

This doesn't seem to be conditional on using dex collection type so I think it would break for other collector types as the condition can never be met.

Thanks for the review.
I will respond to/modify PR with respect to your other comment separately. But, I would like to address this one first.

This PR behaves differently than what exists currently on two occasions only and in both of those G6 has been selected. Please let me explain.

Because of the following variable definition, it only becomes true if G6 has been selected.

boolean notConnectedToG6Yet = Pref.getBooleanDefaultFalse("using_g6") && DexTimeKeeper.getTransmitterAgeInDays(getTransmitterID()) == -1;

1- This is the first case where this PR behaves differently than before:

if (notConnectedToG6Yet) {
notificationText.setText(R.string.wait_to_connect);
}

And you can see that it happens only if the variable is true, meaning only if G6 is selected by the user.

2- This is the only other case this PR behaves differently than before:

if (!Experience.gotData() && !QuickSettingsDialogs.isDialogShowing() && JoH.ratelimit("start-sensor_prompt", 20) && !notConnectedToG6Yet) {

When the if condition above is true, the conditional command shows a dialog. If the user has chosen any sensor other than G6, "!notConnectedToG6Yet" will be true. In that case, the "if" condition result is not affected by this PR (A && TRUE = A). The only time the above "if" condition fails to be true due to this PR is if the user has selected a G6 and G6 is not connected yet. In that case, this change will not allow the dialog to be shown.



Therefore, the xDrip behavior is not affected by this PR if any sensor other than G6 is selected.

I admit that this is not very easy to understand.
Would this be accepted if I add comments to the code to explain all of this?

Again, I will make changes to address your comment about ratelimit.

@Navid200
Copy link
Collaborator Author

Now that the other PR is merged, should I edit this one to use the new method from it?
So that if some day it is modified, everything stays related and consistent?

@Navid200
Copy link
Collaborator Author

Resolved conflict after refactoring to utilitymodels.

Tested. Everything works fine.

@Navid200 Navid200 reopened this Apr 21, 2023
@Navid200
Copy link
Collaborator Author

Resolved conflicts after refactoring to models.

Tested. Everything works fine.

@jamorham
Copy link
Collaborator

jamorham commented May 2, 2023

I think if you test by selecting G6 from the source wizard and then change collector type to Libre then your condition will still be triggered as using_g6 is not sufficient to tell the collector type. You probably want something like getDexCollectionType() but even then you should test for using native mode for completeness. Let me know if you think this is incorrect?

@Navid200 Navid200 marked this pull request as draft May 2, 2023 17:12
@Navid200 Navid200 marked this pull request as ready for review May 5, 2023 04:03
@Navid200
Copy link
Collaborator Author

Navid200 commented May 5, 2023

Thanks for catching my error, and offering guidance.

@Navid200 Navid200 requested a review from jamorham May 10, 2023 05:20
Copy link
Collaborator

@jamorham jamorham left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this should work and I believe you have tested it.

@Navid200
Copy link
Collaborator Author

Yes, it is tested.
I hope you don't mind. But, we may need to tighten this. But, we may not. This is a first, and hopefully last, step.

@jamorham jamorham merged commit 67340c4 into NightscoutFoundation:master Jun 24, 2023
@Navid200 Navid200 deleted the Navid_2023_03_30 branch June 24, 2023 12:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants