Skip to content
This repository has been archived by the owner on Jul 25, 2024. It is now read-only.

Connection Status: Show SnackBar on changing network state #316

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

nitish1211
Copy link
Collaborator

Fixes #312

I've added the the snackbar which shows up whenever there is change in network state.
The snackbar showing offline status stays there till connection is re-established.
Once the connection is established the snackbar showing connection established dismisses after a short interval.

@kunall17 @Sam1301 Can you please review this. And I am working on #82 , so will update the PR soon.

@smarx
Copy link

smarx commented Jan 21, 2017

Automated message from Dropbox CLA bot

@nitish1211, it looks like you've already signed the Dropbox CLA. Thanks!

@nitish1211 nitish1211 force-pushed the network branch 2 times, most recently from b204acd to 47521cd Compare January 21, 2017 03:19
boolean isConnected = intent.getBooleanExtra(ConnectivityManager.EXTRA_NO_CONNECTIVITY, false);
if(isConnected){
//Disable fab when there is no connectivity
fab.setEnabled(false);
Copy link
Collaborator

Choose a reason for hiding this comment

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

What if the chatBox is displayed currently, there should be a check if that's visible close that one as well!

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Here I was thinking that the chat box would change to fab on scrolling and once it changes to fab we cant go back to chat box as fab is disabled.

Copy link
Collaborator

Choose a reason for hiding this comment

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

But there can be case where the user is being displayed the chatbox and a network change occurs,
Maybe just disable the asyncSend button also save the state, like if the user network disconnects and they were writing a message so we can show the chatbox again when the network connects, for a better UX

Copy link
Collaborator Author

@nitish1211 nitish1211 Jan 24, 2017

Choose a reason for hiding this comment

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

This is how its currently is working @kunall17 Please suggest any changes that need to be added.

g_20170123_0106563

The displaying of the snackbar at the bottim of the screen takes the chatbox out of the view and as soon as the network connection is reestablished the text that the user had entered is still present.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Hmmm, something is going wrong mostly the snackbar moves the FAB above to make space for itself and not appear on top of it, can you check why?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Its because we have a set a custom app:layout_behaviour in main.xml for our fab which does not include moving up on snackbar's appearance. The moving up on snackbar's appearance is included in the default behaviour of a fab though this can be fixed by creating a different custom layout behaviour class.

@kunall17
Copy link
Collaborator

How does the snackbar looks in the night mode?

Copy link
Collaborator

@kunall17 kunall17 left a comment

Choose a reason for hiding this comment

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

I haven't tried this out, but does this works on a API 21 (lollipop) device?
AFAIR we have to use a NetworkRequest right?

EDIT: Found this bug on SO http://stackoverflow.com/questions/27144026/how-can-i-receive-a-notification-when-the-device-loses-network-connectivity-in-a

//Disable fab when there is no connectivity
fab.setEnabled(false);
fab.setVisibility(View.INVISIBLE);
Snackbar.make(coordinatorLayout,"No Connection!",Snackbar.LENGTH_INDEFINITE).show();
Copy link
Collaborator

Choose a reason for hiding this comment

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

Use displayed text in strings.xml

//Enabling fab when connection is reestablished
fab.setEnabled(true);
fab.setVisibility(View.VISIBLE);
Snackbar.make(coordinatorLayout,"Connection Established",Snackbar.LENGTH_SHORT).show();
Copy link
Collaborator

Choose a reason for hiding this comment

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

Use displayed text in strings.xml

@nitish1211
Copy link
Collaborator Author

Looks fine

screenshot_20170121-093359

@kunall17
Copy link
Collaborator

@nitish1211
Copy link
Collaborator Author

nitish1211 commented Jan 21, 2017

The BroadcastReceiver and IntentFilter filter = new IntentFilter(ConnectivityManager.CONNECTIVITY_ACTION); are working fine, I've tested it on a API 24 device and on API 23 and 19 on the emulator.

@nitish1211 nitish1211 force-pushed the network branch 3 times, most recently from c4b00d3 to 0243a2a Compare January 21, 2017 12:53
@ShailyTyagi
Copy link

Even when the device is offline the snackbar displays 'connection esatblished' .I ran it on an API level 22 device.
2017_01_21_23_01_55

@kunall17
Copy link
Collaborator

Also you have only checked if we are connected to wifi, It would be better for checking if the internet is working while connected to wifi!

@nitish1211 nitish1211 force-pushed the network branch 3 times, most recently from e92d3b2 to bf9b221 Compare January 24, 2017 16:02
@nitish1211
Copy link
Collaborator Author

nitish1211 commented Jan 24, 2017

Here I've added a new layout_behaviour file for fab. The fab now animates in and out of view like this

g_20170124_2135569

Also added a line to hide the chat box when network is lost.
The BroadcastReceiver has also been unregistered during onPause() and registered onResume().
The BroadcastReceiver is called anytime a change in network connectivity has occurred so there I've placed a check for network connectivity isNetworkAvailable() .
@kunall17 any other changes you would suggest?

@nitish1211 nitish1211 force-pushed the network branch 2 times, most recently from 95c7c1c to 04c8a0e Compare January 26, 2017 17:37
@nitish1211
Copy link
Collaborator Author

I've also disabled the refresh button in the overflow menu when the device goes offline.
screenshot_20170127-010301

And I'm working on the offline display of messages #82 . I'll send a separate PR for that.
@kunall17 @Sam1301 Can you please review the changes done till now, would really like any suggestions from your side.

@kunall17
Copy link
Collaborator

@nitish1211 Its better to include #82 in this PR only as they both are connected and will be easier to debug!
For this #82 you just need to play with fetch() method here https://github.com/zulip/zulip-android/blob/master/app/src/main/java/com/zulip/android/activities/MessageListFragment.java#L244 this is how we fetch messages!

@nitish1211
Copy link
Collaborator Author

nitish1211 commented Jan 29, 2017

I've added Offline compatibility now the messages stored offline load into the view.
Here's how it looks like now:

g_20170129_1206563

I have used the fetch method by giving a call to onReadyToDisplay()
@kunall17 can you please review this.

@kunall17
Copy link
Collaborator

@nitish1211 awesome!
split the commit which deals with offline messages display!

@nitish1211
Copy link
Collaborator Author

@kunall17 Done.

@kunall17
Copy link
Collaborator

The android docs say about the isConnected()

Indicates whether network connectivity exists and it is possible to establish connections and pass data.

I'm still not clear by the docs in a scenario where the wifi is connected by the internet isn't working, what happens in this case?

@kunall17
Copy link
Collaborator

I tried this branch I kept my wifi on but did not start the zulip dev server!
And it showed me connection established!

Same goes in the case where my wifi is connected it will show the same messages!

device-2017-01-31-234441
Still overlaps the FAB

Just an suggestion: try to test with the error thrown

java.net.ConnectException: Failed to connect to /10.0.3.2:9991

@@ -1972,6 +1965,18 @@ public boolean onCreateOptionsMenu(Menu menu) {
return false;
}

@Override
public boolean onPrepareOptionsMenu(Menu menu) {
Log.d("nitish","status"+networkStatus);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Remove this. @vishwesh3 already told you about this. #316 (comment)

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 was using it when debugging. Force of habit 😉 will remove it sorry.

@@ -834,9 +831,6 @@ protected void onActivityResult(int requestCode, int resultCode, Intent data) {
Intent photoSendIntent = new Intent(this, PhotoSendActivity.class);
photoSendIntent.putExtra(Intent.EXTRA_TEXT, mCurrentPhotoPath);
startActivity(photoSendIntent);

// activity transition animation
ActivityTransitionAnim.transition(ZulipActivity.this);
Copy link
Collaborator

Choose a reason for hiding this comment

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

why are you removing this?

@@ -1109,7 +1100,7 @@ public void onClick(View view) {
*/
private void showSoftKeyboard() {
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
imm.toggleSoftInput(InputMethodManager.SHOW_IMPLICIT,InputMethodManager.HIDE_IMPLICIT_ONLY);
imm.toggleSoftInput(InputMethodManager.SHOW_IMPLICIT, InputMethodManager.HIDE_IMPLICIT_ONLY);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Remove this change.

Copy link
Member

Choose a reason for hiding this comment

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

I think its probably fine to retain code refactor changes. These occur clearly because someone forgot to refactor code and it was merged. I think it'd be reasonable to include such changes in a different commit :).

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This is because of formatting of the code.Should I include it in a different commit??

Copy link
Member

Choose a reason for hiding this comment

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

yep 👍

@@ -1818,7 +1810,7 @@ private void narrowPMWith(final Person person) {
if (!person.getEmail().equals(app.getYou().getEmail()))
list.add(app.getYou());
doNarrow(new NarrowFilterPM(list));
onNarrowFillSendBoxPrivate(new Person[]{person},false);
onNarrowFillSendBoxPrivate(new Person[]{person}, false);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Remove this too.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Same case of code formatting :)

@nitish1211
Copy link
Collaborator Author

nitish1211 commented Mar 1, 2017

@saketkumar95 @vishwesh3 @kunall17 @Sam1301 Any other changes you guys can suggest ? 😄

@jainkuniya
Copy link
Member

I can't find #316 (comment)

Snackbar overlaps the FAB

148837387481825

@nitish1211
Copy link
Collaborator Author

nitish1211 commented Mar 1, 2017

There is a new Behaviour file been addedRemoveFabOnScroll.java for the Fab which makes sure that the FAB scales out every time the snackbar comes into view.

@nitish1211 nitish1211 force-pushed the network branch 2 times, most recently from 2eab021 to 23c47ee Compare March 1, 2017 15:06
@nitish1211
Copy link
Collaborator Author

This is a demo of how it works currently. 🙂
g_20170301_2039103

@saketkumar
Copy link
Collaborator

@nitish1211 When narrowed to any stream , i got this even when i was connected to the internet.

screen

Steps to reproduce :

Connect to the internet.
Narrow to the any stream.
Disconnect the internet, and reconnect again.
I waited till 1 min, but the it was showing waiting for network, even through the net was working.

@nitish1211
Copy link
Collaborator Author

@saketkumar95 How long did you leave it disconnected?
Because the time to send connect polls increases the longer you leave it offline thus making it take longer to reconnect.
It increases to 33 seconds on just the 7th failure.
The solution to this would be to add a retry button in the snackbar. Which would allow the user to send the poll request when he pleases, instead of the app sending it after a set time period.
What are your thoughts on this?

Its working fine but takes a lot of time to reconnect:
g_20170303_1115523

@nitish1211
Copy link
Collaborator Author

Added a Retry Button and removed the Connection Established SnackBar. I've observed in most of the Google apps that Snackbars are only used to show loss of connectivity and are dismissed when connectivity is reestablished.
@saketkumar95 what are your thoughts on this?

So this is how it currently works now:
g_20170303_1538413

@saketkumar
Copy link
Collaborator

saketkumar commented Mar 5, 2017

@nitish1211 I don't think disabling the refresh button makes sense. If someone is running on slow internet connection , then they might want to refresh the app, but sometimes on slow connection maybe the refresh button gets disabled. This happens sometimes on slow connections. Instead we can have like when no connection is there then just display a snackbar or toast of network unavailable.
@kunall17 What do you think?

@nitish1211
Copy link
Collaborator Author

That's the reason I've added the RETRY button to the snackbar so that people with slow network connections can hit retry to refresh their feed.

@saketkumar
Copy link
Collaborator

No need for that. Refresh can do that. I think you should remove retry and enable the refresh again. If network is not available we can have anythink like toast, snackbar , or an alert dialog with network unavailable message. Alert dialog is used in this cases in whatsapp.

@nitish1211
Copy link
Collaborator Author

How about I keep both enabled the refresh and the RETRY button??
Makes it faster for the user to refresh feed. :)

@saketkumar
Copy link
Collaborator

yeah! That sounds good too. For me it's good to be implemented but lets first confirm with @kunall17 :)

@nitish1211
Copy link
Collaborator Author

@saketkumar95 Just figured out that the refresh button should not be kept Enabled when offline, because on pressing the refresh button everything is reset. The Database is cleared and the the coonncetionState is reset. This causes the offline DB to be wiped out. Therefore I believe that the refresh button should be kept disabled when offline.

@zulipbot
Copy link
Member

zulipbot commented May 9, 2017

Heads up @nitish1211, we just merged some commits (latest: 68e3463) that conflict with the changes your made in this pull request! You can review this repository's recent commits to see where the conflicts occur. Please rebase your feature branch against the upstream/master branch and resolve your pull request's merge conflicts accordingly.

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

Successfully merging this pull request may close these issues.

9 participants