Skip to content

Commit

Permalink
expire unresolved requests after a timeout
Browse files Browse the repository at this point in the history
  • Loading branch information
or-else committed May 24, 2019
1 parent 9ce02cd commit dac8e1f
Show file tree
Hide file tree
Showing 7 changed files with 82 additions and 72 deletions.
21 changes: 11 additions & 10 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -55,21 +55,22 @@ static def gitVersionName() {
dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation project(path: ':tinodesdk')
implementation 'androidx.appcompat:appcompat:1.1.0-alpha04'
implementation 'androidx.appcompat:appcompat:1.1.0-alpha05'
implementation 'androidx.cardview:cardview:1.0.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
implementation 'androidx.legacy:legacy-support-v13:1.0.0'
implementation 'androidx.lifecycle:lifecycle-extensions:2.1.0-alpha04'
implementation 'androidx.preference:preference:1.1.0-alpha04'
implementation 'androidx.recyclerview:recyclerview:1.1.0-alpha04'
implementation 'androidx.recyclerview:recyclerview-selection:1.1.0-alpha01'
implementation 'androidx.vectordrawable:vectordrawable:1.1.0-alpha01'
implementation 'com.crashlytics.sdk.android:crashlytics:2.9.9'
implementation 'androidx.lifecycle:lifecycle-extensions:2.2.0-alpha01'
implementation 'androidx.preference:preference:1.1.0-alpha05'
implementation 'androidx.recyclerview:recyclerview:1.1.0-alpha05'
implementation 'androidx.recyclerview:recyclerview-selection:1.1.0-alpha05'
implementation 'androidx.vectordrawable:vectordrawable:1.1.0-beta01'
implementation 'com.crashlytics.sdk.android:crashlytics:2.10.1'
implementation 'com.google.android:flexbox:1.1.0'
implementation 'com.google.android.material:material:1.1.0-alpha05'
implementation 'com.google.firebase:firebase-core:16.0.7'
implementation 'com.google.android.material:material:1.1.0-alpha06'
// Don't change version from 16.0.5. Google can't fix this bug for months.
implementation 'com.google.firebase:firebase-core:16.0.5'
implementation 'com.google.firebase:firebase-measurement-connector-impl:17.0.5'
implementation 'com.google.firebase:firebase-messaging:17.5.0'
implementation 'com.google.firebase:firebase-messaging:18.0.0'
implementation 'com.googlecode.libphonenumber:libphonenumber:8.9.2'
}
9 changes: 1 addition & 8 deletions app/src/main/java/co/tinode/tindroid/ChatsFragment.java
Original file line number Diff line number Diff line change
Expand Up @@ -224,14 +224,7 @@ public boolean onOptionsItemSelected(@NonNull MenuItem item) {
return true;

case R.id.action_offline:
try {
Cache.getTinode().reconnectNow();
} catch (IOException ex) {
Log.d(TAG, "Reconnect failure", ex);
String cause = ex.getCause().getMessage();
Toast.makeText(activity, activity.getString(R.string.error_connection_failed) + cause,
Toast.LENGTH_SHORT).show();
}
Cache.getTinode().reconnectNow();
break;
}
return false;
Expand Down
9 changes: 1 addition & 8 deletions app/src/main/java/co/tinode/tindroid/FindFragment.java
Original file line number Diff line number Diff line change
Expand Up @@ -315,14 +315,7 @@ public boolean onOptionsItemSelected(@NonNull MenuItem item) {
return true;

case R.id.action_offline:
try {
Cache.getTinode().reconnectNow();
} catch (IOException ex) {
Log.d(TAG, "Reconnect failure", ex);
String cause = ex.getCause().getMessage();
Toast.makeText(activity, activity.getString(R.string.error_connection_failed) + cause,
Toast.LENGTH_SHORT).show();
}
Cache.getTinode().reconnectNow();
return true;
}

Expand Down
9 changes: 1 addition & 8 deletions app/src/main/java/co/tinode/tindroid/MessagesFragment.java
Original file line number Diff line number Diff line change
Expand Up @@ -432,14 +432,7 @@ public PromisedReply<ServerMessage> onSuccess(ServerMessage result) {
return true;

case R.id.action_offline:
try {
Cache.getTinode().reconnectNow();
} catch (IOException ex) {
Log.d(TAG, "Reconnect failure", ex);
String cause = ex.getCause().getMessage();
Toast.makeText(activity, activity.getString(R.string.error_connection_failed) + cause,
Toast.LENGTH_SHORT).show();
}
Cache.getTinode().reconnectNow();
break;
default:
return super.onOptionsItemSelected(item);
Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ buildscript {
maven { url 'https://maven.fabric.io/public' }
}
dependencies {
classpath 'com.android.tools.build:gradle:3.4.0'
classpath 'com.android.tools.build:gradle:3.4.1'

// For FCM push notifications
classpath 'com.google.gms:google-services:4.2.0'
Expand Down
16 changes: 10 additions & 6 deletions tinodesdk/src/main/java/co/tinode/tinodesdk/PromisedReply.java
Original file line number Diff line number Diff line change
Expand Up @@ -164,10 +164,9 @@ public PromisedReply<T> thenCatch(FailureListener<T> failure) {
* thread which completed the promise: called either resolve() or reject().
*
* @param finished called when the promise is completed either way.
* @return promise for chaining
*/
public PromisedReply<T> thenFinally(final FinalListener<T> finished) {
return thenApply(new SuccessListener<T>() {
public void thenFinally(final FinalListener<T> finished) {
thenApply(new SuccessListener<T>() {
@Override
public PromisedReply<T> onSuccess(T result) throws Exception {
return finished.onFinally();
Expand Down Expand Up @@ -234,14 +233,17 @@ private void handleFailure(Exception e) throws Exception {
}
}

@SuppressWarnings("WeakerAccess")
public boolean isResolved() {
return mState == State.RESOLVED;
}

@SuppressWarnings("unused")
public boolean isRejected() {
return mState == State.REJECTED;
}

@SuppressWarnings({"WeakerAccess", "BooleanMethodIsAlwaysInverted"})
public boolean isDone() {
return mState == State.RESOLVED || mState == State.REJECTED;
}
Expand All @@ -250,9 +252,10 @@ public boolean isDone() {
/**
* Make this promise resolved.
* @param result results of resolution.
* @throws Exception
* @throws Exception if anything goes wrong during resolution.
*/
public void resolve(final T result) throws Exception {
@SuppressWarnings("WeakerAccess")
protected void resolve(final T result) throws Exception {
synchronized (this) {
if (mState == State.WAITING) {
mState = State.RESOLVED;
Expand All @@ -270,7 +273,8 @@ public void resolve(final T result) throws Exception {
}
}

public void reject(final Exception err) throws Exception {
@SuppressWarnings("WeakerAccess")
protected void reject(final Exception err) throws Exception {
Log.d(TAG, "REJECTING promise " + this, err);
synchronized (this) {
if (mState == State.WAITING) {
Expand Down
Loading

0 comments on commit dac8e1f

Please sign in to comment.