Skip to content

Commit

Permalink
ignore ConnectivityManager state on first connect after resuming the app
Browse files Browse the repository at this point in the history
  • Loading branch information
c99koder committed Nov 30, 2016
1 parent 2ff522e commit 6673cbe
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 5 deletions.
2 changes: 1 addition & 1 deletion .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ android {
useLibrary 'org.apache.http.legacy'

defaultConfig {
versionCode 94
versionCode 95
versionName "3.12"
minSdkVersion 10
targetSdkVersion 25
Expand Down
8 changes: 6 additions & 2 deletions src/com/irccloud/android/NetworkConnection.java
Original file line number Diff line number Diff line change
Expand Up @@ -1040,8 +1040,12 @@ public boolean hasResult(BaseTransaction<List<Model>> baseTransaction, List<Mode
saveTimer.schedule(saveTimerTask, delay);*/
}

public void connect() {
connect(false);
}

@TargetApi(24)
public synchronized void connect() {
public synchronized void connect(boolean ignoreNetworkState) {
Crashlytics.log(Log.DEBUG, TAG, "connect()");
Context ctx = IRCCloudApplication.getInstance().getApplicationContext();
session = ctx.getSharedPreferences("prefs", 0).getString("session_key", "");
Expand All @@ -1059,7 +1063,7 @@ public synchronized void connect() {
if(cm != null) {
NetworkInfo ni = cm.getActiveNetworkInfo();

if (ni != null && !ni.isConnectedOrConnecting()) {
if (!ignoreNetworkState && ni != null && !ni.isConnectedOrConnecting()) {
Crashlytics.log(Log.INFO, TAG, "No active network connection");
cancel_idle_timer();
state = STATE_DISCONNECTED;
Expand Down
2 changes: 1 addition & 1 deletion src/com/irccloud/android/activity/BaseActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ protected void onPostResume() {
if(conn != null){
Crashlytics.log(Log.INFO, "IRCCloud", "App resumed, websocket state: " + conn.getState());
if(conn.getState() == NetworkConnection.STATE_DISCONNECTED || conn.getState() == NetworkConnection.STATE_DISCONNECTING)
conn.connect();
conn.connect(true);
}
}

Expand Down

0 comments on commit 6673cbe

Please sign in to comment.