Skip to content

Commit

Permalink
prevent crash when change network connection before client setupAppID
Browse files Browse the repository at this point in the history
  • Loading branch information
ariefnurputranto committed Dec 16, 2020
1 parent 8236543 commit 7efbc37
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 11 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ Second, you need to add SDK dependencies inside your app .gradle. Then, you need
```
dependencies {
...
implementation 'com.qiscus.sdk:chat-core:1.3.25'
implementation 'com.qiscus.sdk:chat-core:1.3.26'
}
```

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -525,6 +525,15 @@ public static boolean hasSetupUser() {
return appServer != null && localDataManager.isLogged();
}

/**
* For checking is client has been setupAppID
*
* @return true if already hasSetupAppID, false if not yet
*/
public static boolean hasSetupAppID() {
return appServer != null;
}

/**
* Accessor to get current qiscus user account
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.util.Log;

import com.qiscus.sdk.chat.core.QiscusCore;
import com.qiscus.sdk.chat.core.data.remote.QiscusResendCommentHelper;
Expand All @@ -35,14 +36,19 @@ public class QiscusNetworkStateReceiver extends BroadcastReceiver {

@Override
public void onReceive(Context context, Intent intent) {
boolean isConnected = QiscusAndroidUtil.isNetworkAvailable();
QiscusLogger.print(TAG, "isConnected : " + isConnected);
QiscusAndroidUtil.runOnBackgroundThread(() -> {
if (needResend(isConnected)) {
QiscusResendCommentHelper.cancelAll();
QiscusResendCommentHelper.tryResendPendingComment();
}
});

if (QiscusCore.hasSetupAppID()) {
boolean isConnected = QiscusAndroidUtil.isNetworkAvailable();
QiscusLogger.print(TAG, "isConnected : " + isConnected);
QiscusAndroidUtil.runOnBackgroundThread(() -> {
if (needResend(isConnected)) {
QiscusResendCommentHelper.cancelAll();
QiscusResendCommentHelper.tryResendPendingComment();
}
});
} else {
Log.d("QiscusCore", "Logger from change network connection, please setup your appID first");
}
}

private boolean needResend(boolean isConnected) {
Expand Down
2 changes: 1 addition & 1 deletion docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ Secondly, you need to add SDK dependencies inside your app .gradle. Then, you ne
```
dependencies {
...
implementation 'com.qiscus.sdk:chat-core:1.3.25'
implementation 'com.qiscus.sdk:chat-core:1.3.26'
}
```

Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ chatVersionPatch=17
# === qiscus chat-core library version ===
chatCoreVersionMajor=1
chatCoreVersionMinor=3
chatCoreVersionPatch=25
chatCoreVersionPatch=26

# === qiscus default base url
BASE_URL_SERVER="https://api.qiscus.com/"
Expand Down

0 comments on commit 7efbc37

Please sign in to comment.