-
Notifications
You must be signed in to change notification settings - Fork 246
Connection Status: Show SnackBar on changing network state #316
base: master
Are you sure you want to change the base?
Conversation
Automated message from Dropbox CLA bot @nitish1211, it looks like you've already signed the Dropbox CLA. Thanks! |
b204acd
to
47521cd
Compare
boolean isConnected = intent.getBooleanExtra(ConnectivityManager.EXTRA_NO_CONNECTIVITY, false); | ||
if(isConnected){ | ||
//Disable fab when there is no connectivity | ||
fab.setEnabled(false); |
There was a problem hiding this comment.
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!
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
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.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
How does the snackbar looks in the night mode? |
There was a problem hiding this 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(); |
There was a problem hiding this comment.
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(); |
There was a problem hiding this comment.
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
Also unregister the receiver like https://github.com/zulip/zulip-android/blob/master/app/src/main/java/com/zulip/android/activities/ZulipActivity.java#L1998 |
The BroadcastReceiver and |
c4b00d3
to
0243a2a
Compare
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! |
e92d3b2
to
bf9b221
Compare
Here I've added a new Also added a line to hide the chat box when network is lost. |
95c7c1c
to
04c8a0e
Compare
@nitish1211 Its better to include #82 in this PR only as they both are connected and will be easier to debug! |
I've added Offline compatibility now the messages stored offline load into the view. I have used the fetch method by giving a call to |
@nitish1211 awesome! |
@kunall17 Done. |
The android docs say about the isConnected()
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? |
I tried this branch I kept my wifi on but did not start the zulip dev server! Same goes in the case where my wifi is connected it will show the same messages! Just an suggestion: try to test with the error thrown
|
@@ -1972,6 +1965,18 @@ public boolean onCreateOptionsMenu(Menu menu) { | |||
return false; | |||
} | |||
|
|||
@Override | |||
public boolean onPrepareOptionsMenu(Menu menu) { | |||
Log.d("nitish","status"+networkStatus); |
There was a problem hiding this comment.
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)
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove this change.
There was a problem hiding this comment.
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 :).
There was a problem hiding this comment.
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??
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove this too.
There was a problem hiding this comment.
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 :)
0f79f03
to
f241f94
Compare
@saketkumar95 @vishwesh3 @kunall17 @Sam1301 Any other changes you guys can suggest ? 😄 |
I can't find #316 (comment) Snackbar overlaps the FAB |
There is a new Behaviour file been added |
2eab021
to
23c47ee
Compare
@nitish1211 When narrowed to any stream , i got this even when i was connected to the internet. Steps to reproduce : Connect to the internet. |
@saketkumar95 How long did you leave it disconnected? |
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. |
@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. |
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. |
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. |
How about I keep both enabled the refresh and the RETRY button?? |
yeah! That sounds good too. For me it's good to be implemented but lets first confirm with @kunall17 :) |
@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. |
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 |
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.