Skip to content
This repository has been archived by the owner on Feb 11, 2022. It is now read-only.

Issue 29 Network State #34

Merged
merged 34 commits into from
Sep 15, 2014
Merged

Issue 29 Network State #34

merged 34 commits into from
Sep 15, 2014

Conversation

Mecharyry
Copy link
Contributor

This pull request addresses issue #29 Provide the Current Network State.

Just adds two methods into Merlin class which will retrieve the network info from a given context and return the network status.

I was tempted to create a dummy Application in the android manifest and have it static so that you would not be required to pass a context in order to retrieve a network status, but there wouldn't be any guarantee that the onCreate would be called before someone tried to access the isConnected method.

^^ Me forgetting that this is a library 👅

@blundell
Copy link
Contributor

@Mecharyry onCreate of a DummyApplication would never be called. This is a library, so it's Application class is never instantiated .. as it is not an application. It is used by another application.

@Mecharyry
Copy link
Contributor Author

Oh yea of course. Just as well I didn't go for that option then 👅

@blundell
Copy link
Contributor

This Merlin object appears to have another responsibility and can't be newed up directly by a client.

The methods are static, so what about a new class? Also a from(Context context) method allows easy statics but with the creation of a class.

MerlinSleeve.from(context).isConnected();

Example useage

private MerlinSleeve merlinSleeve;

onCreate() {
 merlinSleeve =  MerlinSleeve.from(this);
}

onClick() {
   if(merlinSleeve.isConnected()) {
      // waaat
   }
}

Debate away @Mecharyry @ouchadam

@blundell
Copy link
Contributor

or MerlinsBeard lol

@@ -42,6 +46,16 @@ public void registerBindable(Bindable bindable) {
registerer.registerBindable(bindable);
}

public static boolean isConnected(Context context) {
Copy link
Contributor

Choose a reason for hiding this comment

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

❌ the whole point of Merlin is to provide a connected state which has done a network ping to guarantee the network is available. It should use the state attained by the MerlinService

Copy link
Contributor

Choose a reason for hiding this comment

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

yeah so if we move this to another class and have it javadoc'd correctly we can have this quicker method with the caveat that it is not as accurate. (this is what the github issue defines?)

Copy link
Contributor

Choose a reason for hiding this comment

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

what I mean is that this logic is duplicating what the MerlinService does. The isConnected state is fetched in callbacks.

The issue meant the state within the service, which can be created via the builder with or without host pinging (if you want a less reliable result)

Copy link
Contributor

Choose a reason for hiding this comment

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

but that's a lot of setup and service binding where this is 1 synchronous call?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thought I should probably comment here 👅 Does this issue want a network connectivity method, which is the solution above. Or does the issue call for knowledge on whether the endpoint is active, in my opinion these are two separate issues. @ouchadam We create two separate issues to handle the two use cases?

@xrigau
Copy link
Contributor

xrigau commented Sep 10, 2014

return new MerlinsBeard(context);
}

private MerlinsBeard(Context context) {
Copy link
Contributor

Choose a reason for hiding this comment

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

👎 would prefer a newInstance which takes a context but a constructor which takes a ConnectivityManager!

Copy link
Contributor

Choose a reason for hiding this comment

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

good point @ouchadam (from is more client facing friendly than newInstance tho)

Copy link
Contributor

Choose a reason for hiding this comment

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

and lets not forget the tests 👻

Copy link
Contributor Author

Choose a reason for hiding this comment

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

👍

@blundell
Copy link
Contributor

LGTM @ouchadam the constructor comment needs addressing. Then as we discussed the NoTils change, can that be in another PR. As the public interface here looks good?

@ouchadam
Copy link
Contributor

👍 that's good with me

@Mecharyry
Copy link
Contributor Author

Sorry @ouchadam should have said that I ran the tests again, they all passed.
screen shot 2014-09-11 at 12 33 26

@ouchadam
Copy link
Contributor

👍 good stuff, but it also means there's an untested class 😉

@Mecharyry
Copy link
Contributor Author

Sorry @ouchadam didn't notice this comment. Which class are you talking about? The MerlinService? That one is tested, it couldn't be tested as well as it could have been due to the constructor. I am happy to write a test if you let me know which one you are talking about.

@ouchadam
Copy link
Contributor

The CurrentNetworkStatusFetcher seems to have 0 tests

@Mecharyry
Copy link
Contributor Author

Right, I'm on it. 😄

@Mecharyry
Copy link
Contributor Author

@ouchadam Tests added 😃

}

@Test
public void getPerformsHostPingerPingWhenIsConnectedReturnsTrue() {
Copy link
Contributor

Choose a reason for hiding this comment

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

it's preferential to write these method names givenwhenthen rather than thenwhengiven. Just easier to think about going from A - B rather than backwards B - A

Copy link
Contributor

Choose a reason for hiding this comment

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

i.e. whenNetworkIsConnectedHostPingerPings()

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'll add that to my notes 👅

public void get(Context context) {
NetworkInfo activeNetworkInfo = getNetworkInfo(context);
if (isConnectable(activeNetworkInfo)) {
public void get() {

Choose a reason for hiding this comment

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

A public get() method that is void? There must be a better name for that method.

Copy link
Contributor

Choose a reason for hiding this comment

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

💯

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Any suggestions? getAndReturnInCallback?

Copy link
Contributor

Choose a reason for hiding this comment

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

fetch()

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fetch() going once......twice.......sold

Copy link
Contributor

Choose a reason for hiding this comment

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

fetchViaPing?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Doesn't always perform a ping though, only if available.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Do you not think that we should highlight that the result is retrieved via a callback?

public void get(Context context) {
NetworkInfo activeNetworkInfo = getNetworkInfo(context);
if (isConnectable(activeNetworkInfo)) {
public void fetch() {
Copy link
Contributor

Choose a reason for hiding this comment

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

maybe fetchWithPing() makes more sense now I read the other methid

Copy link
Contributor

Choose a reason for hiding this comment

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

fetchWithPing fetchWithoutPing? both should follow the same prefix

Copy link
Contributor

Choose a reason for hiding this comment

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

no because fetch and get are two different commands.

fetch is go fetch this and come back to me when you have done it - callback

get is GET THIS NOW - return value

Copy link
Contributor

Choose a reason for hiding this comment

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

makes sense, but the class needs a new name in that case!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sorry, will change it back then....

Copy link
Contributor

Choose a reason for hiding this comment

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

Retreiver? haha i think the class name is fine for now

Copy link
Contributor

Choose a reason for hiding this comment

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

💯 @Mecharyry after this change to Retreiver I'll be happy to merge

@blundell
Copy link
Contributor

LGTM

@ouchadam 👀

<Button
android:id="@+id/currentStatus"
Copy link
Contributor

Choose a reason for hiding this comment

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

this id should be underscored not camelCase!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sorry thought I had changed this....

ouchadam added a commit that referenced this pull request Sep 15, 2014
@ouchadam ouchadam merged commit 08f1a00 into master Sep 15, 2014
@ouchadam ouchadam deleted the Issue_29_NetworkState branch September 15, 2014 11:11
@xrigau
Copy link
Contributor

xrigau commented Sep 15, 2014

👍 nice one @Mecharyry

@xrigau
Copy link
Contributor

xrigau commented Sep 15, 2014

@ouchadam @blundell @Mecharyry has this been released?

@blundell
Copy link
Contributor

that is on @Mecharyry 's //TODO list

@ouchadam
Copy link
Contributor

@xrigau #12

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants