-
Notifications
You must be signed in to change notification settings - Fork 65
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #404 from apptentive/next
Prepare for 3.4.1 release
- Loading branch information
Showing
44 changed files
with
1,995 additions
and
78 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
71 changes: 71 additions & 0 deletions
71
...droidTest/java/com/apptentive/android/sdk/util/threading/ConcurrentDispatchQueueTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
/* | ||
* Copyright (c) 2017, Apptentive, Inc. All Rights Reserved. | ||
* Please refer to the LICENSE file for the terms and conditions | ||
* under which redistribution and use of this file is permitted. | ||
*/ | ||
|
||
package com.apptentive.android.sdk.util.threading; | ||
|
||
import android.support.test.runner.AndroidJUnit4; | ||
|
||
import com.apptentive.android.sdk.TestCaseBase; | ||
|
||
import org.junit.After; | ||
import org.junit.Before; | ||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
|
||
@RunWith(AndroidJUnit4.class) | ||
public class ConcurrentDispatchQueueTest extends TestCaseBase { | ||
private DispatchQueue dispatchQueue; | ||
|
||
@Before | ||
public void setUp() { | ||
dispatchQueue = DispatchQueue.createBackgroundQueue("Test Queue", DispatchQueueType.Concurrent); | ||
} | ||
|
||
@After | ||
public void tearDown() { | ||
dispatchQueue.stop(); | ||
} | ||
|
||
@Test | ||
public void testDispatch() { | ||
dispatchQueue.dispatchAsync(new DispatchTask() { | ||
@Override | ||
protected void execute() { | ||
sleep(500); | ||
addResult("task-1"); | ||
} | ||
}); | ||
dispatchQueue.dispatchAsync(new DispatchTask() { | ||
@Override | ||
protected void execute() { | ||
sleep(200); | ||
addResult("task-2"); | ||
} | ||
}); | ||
dispatchQueue.dispatchAsync(new DispatchTask() { | ||
@Override | ||
protected void execute() { | ||
addResult("task-3"); | ||
} | ||
}); | ||
sleep(1000); // give tasks a chance to finish | ||
assertResult("task-3", "task-2", "task-1"); // task should be executed concurrently | ||
} | ||
|
||
@Test | ||
public void testStoppingDispatchDelayed() { | ||
dispatchQueue.dispatchAsync(new DispatchTask() { | ||
@Override | ||
protected void execute() { | ||
addResult("task"); | ||
} | ||
}, 100); | ||
dispatchQueue.stop(); | ||
sleep(1000); // wait just for the case if the task still runs | ||
|
||
assertResult(); // no tasks should run | ||
} | ||
} |
93 changes: 93 additions & 0 deletions
93
...c/androidTest/java/com/apptentive/android/sdk/util/threading/SerialDispatchQueueTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
/* | ||
* Copyright (c) 2017, Apptentive, Inc. All Rights Reserved. | ||
* Please refer to the LICENSE file for the terms and conditions | ||
* under which redistribution and use of this file is permitted. | ||
*/ | ||
|
||
package com.apptentive.android.sdk.util.threading; | ||
|
||
import android.support.test.runner.AndroidJUnit4; | ||
|
||
import com.apptentive.android.sdk.TestCaseBase; | ||
|
||
import org.junit.After; | ||
import org.junit.Before; | ||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
|
||
@RunWith(AndroidJUnit4.class) | ||
public class SerialDispatchQueueTest extends TestCaseBase { | ||
|
||
private DispatchQueue dispatchQueue; | ||
|
||
@Before | ||
public void setUp() { | ||
dispatchQueue = DispatchQueue.createBackgroundQueue("Test Queue", DispatchQueueType.Serial); | ||
} | ||
|
||
@After | ||
public void tearDown() { | ||
dispatchQueue.stop(); | ||
} | ||
|
||
@Test | ||
public void testDispatch() { | ||
dispatchQueue.dispatchAsync(new DispatchTask() { | ||
@Override | ||
protected void execute() { | ||
sleep(500); | ||
addResult("task-1"); | ||
} | ||
}); | ||
dispatchQueue.dispatchAsync(new DispatchTask() { | ||
@Override | ||
protected void execute() { | ||
sleep(100); | ||
addResult("task-2"); | ||
} | ||
}); | ||
dispatchQueue.dispatchAsync(new DispatchTask() { | ||
@Override | ||
protected void execute() { | ||
addResult("task-3"); | ||
} | ||
}); | ||
sleep(1000); // give tasks a chance to finish | ||
assertResult("task-1", "task-2", "task-3"); // task should be executed serially | ||
} | ||
|
||
@Test | ||
public void testStoppingDispatch() { | ||
dispatchQueue.dispatchAsync(new DispatchTask() { | ||
@Override | ||
protected void execute() { | ||
sleep(500); | ||
addResult("task-1"); | ||
} | ||
}); | ||
dispatchQueue.dispatchAsync(new DispatchTask() { | ||
@Override | ||
protected void execute() { | ||
addResult("task-2"); | ||
} | ||
}); | ||
dispatchQueue.stop(); | ||
sleep(1000); // wait for the first task to finish | ||
|
||
assertResult("task-1"); // task-2 should not run | ||
} | ||
|
||
@Test | ||
public void testStoppingDispatchDelayed() { | ||
dispatchQueue.dispatchAsync(new DispatchTask() { | ||
@Override | ||
protected void execute() { | ||
addResult("task"); | ||
} | ||
}, 100); | ||
dispatchQueue.stop(); | ||
sleep(1000); // wait just for the case if the task still runs | ||
|
||
assertResult(); // no tasks should run | ||
} | ||
} |
52 changes: 52 additions & 0 deletions
52
apptentive/src/main/java/com/apptentive/android/sdk/ApptentiveBaseActivity.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package com.apptentive.android.sdk; | ||
|
||
import android.os.Bundle; | ||
import android.support.annotation.Nullable; | ||
import android.support.v7.app.AppCompatActivity; | ||
|
||
import com.apptentive.android.sdk.notifications.ApptentiveNotification; | ||
import com.apptentive.android.sdk.notifications.ApptentiveNotificationCenter; | ||
import com.apptentive.android.sdk.notifications.ApptentiveNotificationObserver; | ||
|
||
import static com.apptentive.android.sdk.ApptentiveInternal.NOTIFICATION_INTERACTIONS_SHOULD_DISMISS; | ||
|
||
/** A base class for any SDK activity */ | ||
public class ApptentiveBaseActivity extends AppCompatActivity implements ApptentiveNotificationObserver { | ||
|
||
//region Activity life cycle | ||
|
||
@Override | ||
protected void onCreate(@Nullable Bundle savedInstanceState) { | ||
super.onCreate(savedInstanceState); | ||
registerNotifications(); | ||
} | ||
|
||
@Override | ||
protected void onDestroy() { | ||
super.onDestroy(); | ||
unregisterNotification(); | ||
} | ||
|
||
//endregion | ||
|
||
//region Notifications | ||
|
||
private void registerNotifications() { | ||
ApptentiveNotificationCenter.defaultCenter().addObserver(NOTIFICATION_INTERACTIONS_SHOULD_DISMISS, this); | ||
} | ||
|
||
private void unregisterNotification() { | ||
ApptentiveNotificationCenter.defaultCenter().removeObserver(this); | ||
} | ||
|
||
//endregion | ||
|
||
//region ApptentiveNotificationObserver | ||
|
||
@Override | ||
public void onReceiveNotification(ApptentiveNotification notification) { | ||
// handle notification in subclasses | ||
} | ||
|
||
//endregion | ||
} |
Oops, something went wrong.