Skip to content

Commit

Permalink
Merge pull request #48 from apivideo/feature/android_service
Browse files Browse the repository at this point in the history
Feature/android service
  • Loading branch information
bot-api-video committed Aug 22, 2022
2 parents 14571e3 + 44d373c commit 88e702d
Show file tree
Hide file tree
Showing 26 changed files with 1,615 additions and 201 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,6 @@ git_push.sh
.openapi-generator-ignore
build.sbt
post-generate.sh

# Android files
/local.properties
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
# Changelog
All changes to this project will be documented in this file.

## [1.2.0] - 2022-08-22
- Add an upload Service

## [1.1.0] - 2022-07-12
- Add Async APIs

Expand Down
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ Add this dependency to your project's POM:
<dependency>
<groupId>video.api</groupId>
<artifactId>android-api-client</artifactId>
<version>1.1.0</version>
<version>1.2.0</version>
<scope>compile</scope>
</dependency>
```
Expand All @@ -66,7 +66,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.1.0"
implementation "video.api:android-api-client:1.2.0"
```

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

Then manually install the following JARs:

* `target/android-api-client-1.1.0.jar`
* `target/android-api-client-1.2.0.jar`
* `target/lib/*.jar`

## Code sample
Expand Down Expand Up @@ -450,7 +450,7 @@ val client = ApiVideoClient()
## Recommendation

It's recommended to create an instance of `ApiClient` per thread in a multithreaded environment to avoid any potential issues.
Do not call API from the main thread, otherwise you will get a android.os.NetworkOnMainThreadException. Dispatch API calls with Thread, Executors or Kotlin coroutine to avoid this. Alternatively, most APIs comes with an asynchronous counterpart (`createAsync` for `create`).
Do not call API from the main thread, otherwise you will get a android.os.NetworkOnMainThreadException. Dispatch API calls with Thread, Executors or Kotlin coroutine to avoid this. Alternatively, APIs come with an asynchronous counterpart (`createAsync` for `create`) except the upload endpoint. In this case, you can use the customisable `UploadService` that manages background uploads and as well as notifications.

## Have you gotten use from this API client?

Expand Down
7 changes: 6 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@ apply plugin: 'idea'
apply plugin: 'eclipse'
apply plugin: 'com.diffplug.spotless'
apply plugin: 'maven-publish'
apply plugin: 'kotlin-android'

group = 'video.api'
version = '1.1.0'
version = '1.2.0'

buildscript {
repositories {
Expand Down Expand Up @@ -89,6 +90,8 @@ dependencies {
implementation 'org.openapitools:jackson-databind-nullable:0.2.1'
implementation group: 'org.apache.commons', name: 'commons-lang3', version: '3.10'
implementation 'org.threeten:threetenbp:1.4.3'
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.6.10"
implementation 'androidx.core:core-ktx:1.3.2'
testImplementation 'org.junit.jupiter:junit-jupiter-engine:5.8.0'
testImplementation 'junit:junit:4.13.1'
testImplementation 'org.mockito:mockito-core:3.11.2'
Expand All @@ -97,6 +100,8 @@ dependencies {
androidTestImplementation "com.google.truth:truth:1.1.3"
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'

androidTestImplementation 'androidx.test:rules:1.4.0'
androidTestImplementation 'androidx.test:core:1.4.0'
androidTestImplementation 'androidx.test:runner:1.4.0'
androidTestImplementation 'org.junit.jupiter:junit-jupiter-api:5.8.0'
androidTestImplementation 'de.mannodermaus.junit5:android-test-core:1.3.0'
Expand Down
3 changes: 3 additions & 0 deletions example/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />

<application
android:allowBackup="true"
Expand All @@ -22,6 +23,8 @@
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>

<service android:name=".CustomUploaderService" />
</application>

</manifest>
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package video.api.client.example

import android.app.Notification
import androidx.core.app.NotificationCompat
import video.api.client.api.models.Video
import video.api.client.api.services.UploadService

class CustomUploaderService : UploadService(
notificationId = DEFAULT_NOTIFICATION_ID,
channelId = DEFAULT_NOTIFICATION_CHANNEL_ID,
channelNameResourceId = R.string.channel_name,
) {
companion object {
const val DEFAULT_NOTIFICATION_CHANNEL_ID =
"video.api.client.example.CustomUploaderService"
const val DEFAULT_NOTIFICATION_ID = 3535 // Unique ID for the notification
}

/**
* You can override each of [UploadService] notification methods to customize notifications.
*/
override fun onUploadSuccessNotification(video: Video): Notification {
// Return your custom the notification
return NotificationCompat.Builder(this, channelId)
.setStyle(notificationIconResourceId, notificationColorResourceId)
.setContentTitle(getString(R.string.upload_success_notification_text))
.build()
}
}

0 comments on commit 88e702d

Please sign in to comment.