Skip to content

Commit cb7789d

Browse files
authored
Merge pull request #299 from gamer3dx/master
Android Support Library + NotificationChannels
2 parents 6cfa621 + c1fd9f7 commit cb7789d

File tree

8 files changed

+52
-16
lines changed

8 files changed

+52
-16
lines changed

.travis.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@ android:
1111
- platform-tools
1212

1313
# The BuildTools version used by your project
14-
- build-tools-25.0.2
14+
- build-tools-26.0.1
1515

1616
# The SDK version used to compile your project
17-
- android-25
17+
- android-26
1818

1919
# Additional components
2020
- extra-google-m2repository

build.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ buildscript {
2222
allprojects {
2323
repositories {
2424
jcenter()
25+
maven { url 'http://maven.google.com' }
2526
mavenCentral()
2627
}
2728
}

uploadservice-ftp/build.gradle

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,14 @@ def projectGroup = "net.gotev"
1010
group = projectGroup
1111
version = "3.3.1"
1212

13-
def sdkVersion = 25;
13+
def sdkVersion = 26;
1414

1515
android {
1616
compileSdkVersion sdkVersion
17-
buildToolsVersion '25.0.2'
17+
buildToolsVersion '26.0.1'
1818

1919
defaultConfig {
20-
minSdkVersion 10
20+
minSdkVersion 14
2121
targetSdkVersion sdkVersion
2222
versionCode 13
2323
versionName version

uploadservice-okhttp/build.gradle

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,14 @@ def projectGroup = "net.gotev"
1010
group = projectGroup
1111
version = "3.3.1"
1212

13-
def sdkVersion = 25;
13+
def sdkVersion = 26;
1414

1515
android {
1616
compileSdkVersion sdkVersion
17-
buildToolsVersion '25.0.2'
17+
buildToolsVersion '26.0.1'
1818

1919
defaultConfig {
20-
minSdkVersion 10
20+
minSdkVersion 14
2121
targetSdkVersion sdkVersion
2222
versionCode 11
2323
versionName version

uploadservice/build.gradle

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,14 @@ def projectGroup = "net.gotev"
1010
group = projectGroup
1111
version = "3.3.1"
1212

13-
def sdkVersion = 25;
13+
def sdkVersion = 26;
1414

1515
android {
1616
compileSdkVersion sdkVersion
17-
buildToolsVersion '25.0.2'
17+
buildToolsVersion '26.0.1'
1818

1919
defaultConfig {
20-
minSdkVersion 10
20+
minSdkVersion 14
2121
targetSdkVersion sdkVersion
2222
versionCode 27
2323
versionName version
@@ -33,7 +33,7 @@ android {
3333
}
3434
}
3535

36-
def supportLibraryVersion = "25.3.1"
36+
def supportLibraryVersion = "26.0.0"
3737

3838
dependencies {
3939
compile "com.android.support:appcompat-v7:${supportLibraryVersion}"

uploadservice/src/main/java/net/gotev/uploadservice/UploadNotificationConfig.java

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import android.graphics.Bitmap;
55
import android.os.Parcel;
66
import android.os.Parcelable;
7+
import android.support.annotation.NonNull;
78

89
/**
910
* Contains the configuration of the upload notification.
@@ -14,6 +15,11 @@ public final class UploadNotificationConfig implements Parcelable {
1415

1516
private boolean ringToneEnabled;
1617

18+
/**
19+
* Notification channel ID
20+
*/
21+
private String notificationChannelId;
22+
1723
private UploadNotificationStatusConfig progress;
1824
private UploadNotificationStatusConfig completed;
1925
private UploadNotificationStatusConfig error;
@@ -167,6 +173,17 @@ public final UploadNotificationConfig setRingToneEnabled(Boolean enabled) {
167173
return this;
168174
}
169175

176+
/**
177+
* Sets notification channel ID
178+
*
179+
* @param channelId notification channel ID
180+
* @return {@link UploadNotificationConfig}
181+
*/
182+
public final UploadNotificationConfig setNotificationChannelId(@NonNull String channelId){
183+
this.notificationChannelId = channelId;
184+
return this;
185+
}
186+
170187
public boolean isRingToneEnabled() {
171188
return ringToneEnabled;
172189
}
@@ -187,13 +204,18 @@ public UploadNotificationStatusConfig getCancelled() {
187204
return cancelled;
188205
}
189206

207+
public String getNotificationChannelId(){
208+
return notificationChannelId;
209+
}
210+
190211
@Override
191212
public int describeContents() {
192213
return 0;
193214
}
194215

195216
@Override
196217
public void writeToParcel(Parcel dest, int flags) {
218+
dest.writeString(this.notificationChannelId);
197219
dest.writeByte(this.ringToneEnabled ? (byte) 1 : (byte) 0);
198220
dest.writeParcelable(this.progress, flags);
199221
dest.writeParcelable(this.completed, flags);
@@ -202,6 +224,7 @@ public void writeToParcel(Parcel dest, int flags) {
202224
}
203225

204226
protected UploadNotificationConfig(Parcel in) {
227+
this.notificationChannelId = in.readString();
205228
this.ringToneEnabled = in.readByte() != 0;
206229
this.progress = in.readParcelable(UploadNotificationStatusConfig.class.getClassLoader());
207230
this.completed = in.readParcelable(UploadNotificationStatusConfig.class.getClassLoader());

uploadservice/src/main/java/net/gotev/uploadservice/UploadNotificationStatusConfig.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ public void writeToParcel(Parcel dest, int flags) {
9898
dest.writeTypedList(this.actions);
9999
}
100100

101-
public UploadNotificationStatusConfig() {
101+
public UploadNotificationStatusConfig(){
102102
}
103103

104104
protected UploadNotificationStatusConfig(Parcel in) {

uploadservice/src/main/java/net/gotev/uploadservice/UploadTask.java

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
package net.gotev.uploadservice;
22

33
import android.app.Notification;
4+
import android.app.NotificationChannel;
45
import android.app.NotificationManager;
56
import android.content.Context;
67
import android.content.Intent;
78
import android.media.RingtoneManager;
9+
import android.os.Build;
810
import android.os.Handler;
911
import android.support.v4.app.NotificationCompat;
1012

@@ -115,6 +117,16 @@ public UploadTask() {
115117
*/
116118
protected void init(UploadService service, Intent intent) throws IOException {
117119
this.notificationManager = (NotificationManager) service.getSystemService(Context.NOTIFICATION_SERVICE);
120+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
121+
String notificationChannelId = params.notificationConfig.getNotificationChannelId();
122+
if (notificationChannelId == null) {
123+
notificationChannelId = UploadService.NAMESPACE;
124+
}
125+
if (notificationManager.getNotificationChannel(notificationChannelId) == null) {
126+
NotificationChannel channel = new NotificationChannel(notificationChannelId, "Upload Service channel", NotificationManager.IMPORTANCE_DEFAULT);
127+
notificationManager.createNotificationChannel(channel);
128+
}
129+
}
118130
this.service = service;
119131
this.mainThreadHandler = new Handler(service.getMainLooper());
120132
this.params = intent.getParcelableExtra(UploadService.PARAM_TASK_PARAMETERS);
@@ -430,7 +442,7 @@ private void createNotification(UploadInfo uploadInfo) {
430442

431443
UploadNotificationStatusConfig statusConfig = params.notificationConfig.getProgress();
432444

433-
NotificationCompat.Builder notification = new NotificationCompat.Builder(service)
445+
NotificationCompat.Builder notification = new NotificationCompat.Builder(service, params.notificationConfig.getNotificationChannelId())
434446
.setContentTitle(Placeholders.replace(statusConfig.title, uploadInfo))
435447
.setContentText(Placeholders.replace(statusConfig.message, uploadInfo))
436448
.setContentIntent(statusConfig.getClickIntent(service))
@@ -462,7 +474,7 @@ private void updateNotificationProgress(UploadInfo uploadInfo) {
462474

463475
UploadNotificationStatusConfig statusConfig = params.notificationConfig.getProgress();
464476

465-
NotificationCompat.Builder notification = new NotificationCompat.Builder(service)
477+
NotificationCompat.Builder notification = new NotificationCompat.Builder(service, params.notificationConfig.getNotificationChannelId())
466478
.setContentTitle(Placeholders.replace(statusConfig.title, uploadInfo))
467479
.setContentText(Placeholders.replace(statusConfig.message, uploadInfo))
468480
.setContentIntent(statusConfig.getClickIntent(service))
@@ -501,7 +513,7 @@ private void updateNotification(UploadInfo uploadInfo, UploadNotificationStatusC
501513
if (statusConfig.message == null) return;
502514

503515
if (!statusConfig.autoClear) {
504-
NotificationCompat.Builder notification = new NotificationCompat.Builder(service)
516+
NotificationCompat.Builder notification = new NotificationCompat.Builder(service, params.notificationConfig.getNotificationChannelId())
505517
.setContentTitle(Placeholders.replace(statusConfig.title, uploadInfo))
506518
.setContentText(Placeholders.replace(statusConfig.message, uploadInfo))
507519
.setContentIntent(statusConfig.getClickIntent(service))

0 commit comments

Comments
 (0)