Skip to content

Commit

Permalink
Merge pull request #61 from apivideo/feature/android_work
Browse files Browse the repository at this point in the history
feat(java): improve Android work API
  • Loading branch information
bot-api-video authored Apr 4, 2023
2 parents 6407371 + 0964e11 commit 7404608
Show file tree
Hide file tree
Showing 14 changed files with 253 additions and 98 deletions.
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,7 @@ build.sbt
post-generate.sh

# Android files
/local.properties
/local.properties

# macOS
.DS_Store
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
# Changelog
All changes to this project will be documented in this file.

## [1.3.1] - 2023-04-04
- Add custom tag for WorkManager
- Fix tag for progressive upload in WorkManager
- Worker now returns the file in case developer want to delete it after upload.

## [1.3.0] - 2023-02-28
- Introduce WorkManager dedicated API

Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ Add this dependency to your project's POM:
<dependency>
<groupId>video.api</groupId>
<artifactId>android-api-client</artifactId>
<version>1.3.0</version>
<version>1.3.1</version>
<scope>compile</scope>
</dependency>
```
Expand All @@ -67,7 +67,7 @@ Add this dependency to your project's POM:
Add this dependency to your project's build file:

```groovy
implementation "video.api:android-api-client:1.3.0"
implementation "video.api:android-api-client:1.3.1"
```

### Others
Expand All @@ -80,7 +80,7 @@ mvn clean package

Then manually install the following JARs:

* `target/android-api-client-1.3.0.jar`
* `target/android-api-client-1.3.1.jar`
* `target/lib/*.jar`

## Code sample
Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ apply plugin: 'maven-publish'
apply plugin: 'kotlin-android'

group = 'video.api'
version = '1.3.0'
version = '1.3.1'

buildscript {
repositories {
Expand Down
4 changes: 2 additions & 2 deletions maven-push.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ apply plugin: 'maven-publish'
apply plugin: 'signing'

def isReleaseBuild() {
return !"1.3.0".contains("SNAPSHOT")
return !"1.3.1".contains("SNAPSHOT")
}

def getReleaseRepositoryUrl() {
Expand Down Expand Up @@ -47,7 +47,7 @@ afterEvaluate { project ->

groupId = "video.api"
artifactId = "android-api-client"
version = "1.3.0"
version = "1.3.1"

pom {
name = "video.api:android-api-client"
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<artifactId>android-api-client</artifactId>
<packaging>jar</packaging>
<name>${project.groupId}:${project.artifactId}</name>
<version>1.3.0</version>
<version>1.3.1</version>
<url>https://github.com/apivideo/api.video-android-client</url>
<description>api.video Android API client</description>
<scm>
Expand Down
15 changes: 8 additions & 7 deletions src/androidTest/java/video/api/integration/UploadWorkerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

import java.io.File;
import java.io.IOException;
import java.util.Collections;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;

Expand Down Expand Up @@ -70,7 +71,7 @@ public void uploadVideo() throws IOException, InterruptedException {

CountDownLatch successLatch = new CountDownLatch(1);

OperationWithRequest operationWithRequest = UploadWorkerHelper.upload(workManager, testVideo.getVideoId(), mp4File);
OperationWithRequest operationWithRequest = UploadWorkerHelper.upload(workManager, testVideo.getVideoId(), mp4File, Collections.emptyList());
InstrumentationRegistry.getInstrumentation().runOnMainSync(() ->
workManager.getWorkInfoByIdLiveData(operationWithRequest.getRequest().getId()).observeForever(workInfo -> {
if (workInfo != null) {
Expand All @@ -92,7 +93,7 @@ public void uploadVideoWithError() throws IOException, InterruptedException {
CountDownLatch successLatch = new CountDownLatch(0);
CountDownLatch errorLatch = new CountDownLatch(1);

OperationWithRequest operationWithRequest = UploadWorkerHelper.upload(workManager, "WRONG VIDEO ID", mp4File);
OperationWithRequest operationWithRequest = UploadWorkerHelper.upload(workManager, "WRONG VIDEO ID", mp4File, Collections.emptyList());
InstrumentationRegistry.getInstrumentation().runOnMainSync(() ->
workManager.getWorkInfoByIdLiveData(operationWithRequest.getRequest().getId()).observeForever(workInfo -> {
if (workInfo != null) {
Expand All @@ -119,7 +120,7 @@ public void cancelUploadVideo() throws IOException, InterruptedException {
CountDownLatch cancelLatch = new CountDownLatch(1);
CountDownLatch successLatch = new CountDownLatch(0);

OperationWithRequest operationWithRequest = UploadWorkerHelper.upload(workManager, testVideo.getVideoId(), mp4File);
OperationWithRequest operationWithRequest = UploadWorkerHelper.upload(workManager, testVideo.getVideoId(), mp4File, Collections.emptyList());
InstrumentationRegistry.getInstrumentation().runOnMainSync(() ->
workManager.getWorkInfoByIdLiveData(operationWithRequest.getRequest().getId()).observeForever(workInfo -> {
if (workInfo != null) {
Expand Down Expand Up @@ -169,7 +170,7 @@ public void uploadVideo() throws IOException, InterruptedException {

CountDownLatch successLatch = new CountDownLatch(1);

OperationWithRequest operationWithRequest = UploadWorkerHelper.uploadWithUploadToken(workManager, testUploadToken.getToken(), mp4File, null);
OperationWithRequest operationWithRequest = UploadWorkerHelper.uploadWithUploadToken(workManager, testUploadToken.getToken(), mp4File, null, Collections.emptyList());
InstrumentationRegistry.getInstrumentation().runOnMainSync(() ->
workManager.getWorkInfoByIdLiveData(operationWithRequest.getRequest().getId()).observeForever(workInfo -> {
if (workInfo != null) {
Expand Down Expand Up @@ -216,9 +217,9 @@ public void uploadVideo() throws IOException, InterruptedException {
CountDownLatch successLatch = new CountDownLatch(3);

VideosApi.UploadProgressiveSession uploadProgressiveSession = apiClient.videos().createUploadProgressiveSession(this.testVideo.getVideoId());
OperationWithRequest operationWithRequest1 = UploadWorkerHelper.uploadPart(workManager, uploadProgressiveSession, part1, false);
OperationWithRequest operationWithRequest2 = UploadWorkerHelper.uploadPart(workManager, uploadProgressiveSession, part2, false);
OperationWithRequest operationWithRequest3 = UploadWorkerHelper.uploadPart(workManager, uploadProgressiveSession, part3, true);
OperationWithRequest operationWithRequest1 = UploadWorkerHelper.uploadPart(workManager, uploadProgressiveSession, part1, false, null, Collections.emptyList());
OperationWithRequest operationWithRequest2 = UploadWorkerHelper.uploadPart(workManager, uploadProgressiveSession, part2, false, null, Collections.emptyList());
OperationWithRequest operationWithRequest3 = UploadWorkerHelper.uploadPart(workManager, uploadProgressiveSession, part3, true, null, Collections.emptyList());

InstrumentationRegistry.getInstrumentation().runOnMainSync(() -> {
workManager.getWorkInfoByIdLiveData(operationWithRequest1.getRequest().getId()).observeForever(workInfo -> {
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/video/api/client/api/ApiClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ private OkHttpClient initHttpClient(List<Interceptor> interceptors) {
private void init() {
verifyingSsl = true;
json = new JSON();
addDefaultHeader("AV-Origin-Client", "android:1.3.0");
addDefaultHeader("AV-Origin-Client", "android:1.3.1");
}

private boolean isValid(String regex, String field) {
Expand Down
39 changes: 39 additions & 0 deletions src/main/java/video/api/client/api/work/DataExtensions.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package video.api.client.api.work

import androidx.work.Data
import video.api.client.api.JSON
import video.api.client.api.models.Video
import video.api.client.api.work.workers.AbstractUploadWorker
import java.io.File

/**
* Extension functions for [Data] to deserialize the [Video].
*
* @return The [Video] object
*/
fun Data.toVideo() = JSON().deserialize(
this.getString(
AbstractUploadWorker.VIDEO_KEY
), Video::class.java
) as Video

/**
* Extension functions for [Data] to retrieve the file.
*
* @return The [File]
*/
fun Data.toFile(): File {
val filePath = this.getString(AbstractUploadWorker.FILE_PATH_KEY)
return if (filePath != null) {
File(filePath)
} else {
throw IllegalStateException("File path is null")
}
}

/**
* Extension functions for [Data] to retrieve the progress.
*
* @return The progress
*/
fun Data.toProgress(): Int = this.getInt(AbstractUploadWorker.PROGRESS_KEY, 0)
Loading

0 comments on commit 7404608

Please sign in to comment.