diff --git a/app/src/main/java/io/github/wulkanowy/services/GradeNotify.java b/app/src/main/java/io/github/wulkanowy/services/GradeNotify.java new file mode 100644 index 00000000..609354e2 --- /dev/null +++ b/app/src/main/java/io/github/wulkanowy/services/GradeNotify.java @@ -0,0 +1,36 @@ +package io.github.wulkanowy.services; + +import android.annotation.TargetApi; +import android.app.Notification; +import android.app.NotificationChannel; +import android.app.NotificationManager; +import android.content.Context; + +import io.github.wulkanowy.R; + +class GradeNotify extends NotificationService { + + private static final String CHANNEL_ID = "Grade_Notify"; + + GradeNotify(Context context) { + super(context); + } + + @Override + @TargetApi(26) + void createChannel() { + String channelName = getString(R.string.notify_grade_channel); + + NotificationChannel notificationChannel = new NotificationChannel(CHANNEL_ID, channelName, + NotificationManager.IMPORTANCE_HIGH); + notificationChannel.enableLights(true); + notificationChannel.enableVibration(true); + notificationChannel.setLockscreenVisibility(Notification.VISIBILITY_PUBLIC); + getManager().createNotificationChannel(notificationChannel); + } + + @Override + String getChannelId() { + return CHANNEL_ID; + } +} diff --git a/app/src/main/java/io/github/wulkanowy/services/NotificationService.java b/app/src/main/java/io/github/wulkanowy/services/NotificationService.java index ab721f46..b6c49896 100644 --- a/app/src/main/java/io/github/wulkanowy/services/NotificationService.java +++ b/app/src/main/java/io/github/wulkanowy/services/NotificationService.java @@ -3,29 +3,22 @@ package io.github.wulkanowy.services; import android.annotation.TargetApi; import android.app.Notification; -import android.app.NotificationChannel; import android.app.NotificationManager; import android.content.Context; import android.os.Build; +import android.support.annotation.StringRes; import android.support.v4.app.NotificationCompat; import java.util.Random; -class NotificationService { - - private static final String CHANNEL_ID = "Wulkanowy_New_Grade_Channel"; - - private static final String CHANNEL_NAME = "New Grade Channel"; +public class NotificationService { private NotificationManager manager; private Context context; - NotificationService(Context context) { + public NotificationService(Context context) { this.context = context; - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { - createChannel(); - } } void notify(Notification notification) { @@ -33,23 +26,32 @@ class NotificationService { } NotificationCompat.Builder notificationBuilder() { - return new NotificationCompat.Builder(context, CHANNEL_ID); + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { + createChannel(); + } + return new NotificationCompat.Builder(context, getChannelId()); } - @TargetApi(26) - private void createChannel() { - NotificationChannel notificationChannel = new NotificationChannel(CHANNEL_ID, CHANNEL_NAME, - NotificationManager.IMPORTANCE_HIGH); - notificationChannel.enableLights(true); - notificationChannel.enableVibration(true); - notificationChannel.setLockscreenVisibility(Notification.VISIBILITY_PUBLIC); - getManager().createNotificationChannel(notificationChannel); + public void cancelAll() { + getManager().cancelAll(); } - private NotificationManager getManager() { + NotificationManager getManager() { if (manager == null) { manager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); } return manager; } -} + + String getString(@StringRes int stringId) { + return context.getString(stringId); + } + + @TargetApi(26) + void createChannel() { + } + + String getChannelId() { + return null; + } +} \ No newline at end of file diff --git a/app/src/main/java/io/github/wulkanowy/services/SyncJob.java b/app/src/main/java/io/github/wulkanowy/services/SyncJob.java index cefc8207..e91d5e7c 100644 --- a/app/src/main/java/io/github/wulkanowy/services/SyncJob.java +++ b/app/src/main/java/io/github/wulkanowy/services/SyncJob.java @@ -81,12 +81,12 @@ public class SyncJob extends SimpleJobService { } private void showNotification() { - NotificationService service = new NotificationService(getApplicationContext()); + GradeNotify gradeNotify = new GradeNotify(getApplicationContext()); - service.notify(service.notificationBuilder() + gradeNotify.notify(gradeNotify.notificationBuilder() .setContentTitle(getStringTitle()) .setContentText(getStringContent()) - .setSmallIcon(R.drawable.ic_stat_notify) + .setSmallIcon(R.drawable.ic_notify_grade) .setAutoCancel(true) .setDefaults(NotificationCompat.DEFAULT_ALL) .setPriority(NotificationCompat.PRIORITY_HIGH) diff --git a/app/src/main/java/io/github/wulkanowy/ui/splash/SplashActivity.java b/app/src/main/java/io/github/wulkanowy/ui/splash/SplashActivity.java index 3eb3fdfe..4fcf04d6 100644 --- a/app/src/main/java/io/github/wulkanowy/ui/splash/SplashActivity.java +++ b/app/src/main/java/io/github/wulkanowy/ui/splash/SplashActivity.java @@ -5,6 +5,7 @@ import android.os.Bundle; import javax.inject.Inject; import butterknife.ButterKnife; +import io.github.wulkanowy.services.NotificationService; import io.github.wulkanowy.services.SyncJob; import io.github.wulkanowy.ui.base.BaseActivity; import io.github.wulkanowy.ui.login.LoginActivity; @@ -47,4 +48,9 @@ public class SplashActivity extends BaseActivity implements SplashContract.View public void startSyncService(int interval, boolean useOnlyWifi) { SyncJob.start(getApplicationContext(), interval, useOnlyWifi); } + + @Override + public void cancelNotifications() { + new NotificationService(getApplicationContext()).cancelAll(); + } } diff --git a/app/src/main/java/io/github/wulkanowy/ui/splash/SplashContract.java b/app/src/main/java/io/github/wulkanowy/ui/splash/SplashContract.java index 515c842f..6d25853e 100644 --- a/app/src/main/java/io/github/wulkanowy/ui/splash/SplashContract.java +++ b/app/src/main/java/io/github/wulkanowy/ui/splash/SplashContract.java @@ -13,6 +13,8 @@ public interface SplashContract { void openMainActivity(); void startSyncService(int interval, boolean useOnlyWifi); + + void cancelNotifications(); } @PerActivity diff --git a/app/src/main/java/io/github/wulkanowy/ui/splash/SplashPresenter.java b/app/src/main/java/io/github/wulkanowy/ui/splash/SplashPresenter.java index 165fc4ff..cd452ffb 100644 --- a/app/src/main/java/io/github/wulkanowy/ui/splash/SplashPresenter.java +++ b/app/src/main/java/io/github/wulkanowy/ui/splash/SplashPresenter.java @@ -18,6 +18,8 @@ public class SplashPresenter extends BasePresenter @Override public void onStart(@NonNull SplashContract.View activity) { super.onStart(activity); + getView().cancelNotifications(); + if (getRepository().isServicesEnable()) { getView().startSyncService(getRepository().getServicesInterval(), getRepository().isMobileDisable()); diff --git a/app/src/main/res/drawable-hdpi/ic_notify_grade.png b/app/src/main/res/drawable-hdpi/ic_notify_grade.png new file mode 100644 index 00000000..ea5b85c8 Binary files /dev/null and b/app/src/main/res/drawable-hdpi/ic_notify_grade.png differ diff --git a/app/src/main/res/drawable-hdpi/ic_stat_notify.png b/app/src/main/res/drawable-hdpi/ic_stat_notify.png deleted file mode 100644 index 34544980..00000000 Binary files a/app/src/main/res/drawable-hdpi/ic_stat_notify.png and /dev/null differ diff --git a/app/src/main/res/drawable-mdpi/ic_notify_grade.png b/app/src/main/res/drawable-mdpi/ic_notify_grade.png new file mode 100644 index 00000000..64fd285d Binary files /dev/null and b/app/src/main/res/drawable-mdpi/ic_notify_grade.png differ diff --git a/app/src/main/res/drawable-mdpi/ic_stat_notify.png b/app/src/main/res/drawable-mdpi/ic_stat_notify.png deleted file mode 100644 index 5564049a..00000000 Binary files a/app/src/main/res/drawable-mdpi/ic_stat_notify.png and /dev/null differ diff --git a/app/src/main/res/drawable-xhdpi/ic_notify_grade.png b/app/src/main/res/drawable-xhdpi/ic_notify_grade.png new file mode 100644 index 00000000..83b2c443 Binary files /dev/null and b/app/src/main/res/drawable-xhdpi/ic_notify_grade.png differ diff --git a/app/src/main/res/drawable-xhdpi/ic_stat_notify.png b/app/src/main/res/drawable-xhdpi/ic_stat_notify.png deleted file mode 100644 index fabb8760..00000000 Binary files a/app/src/main/res/drawable-xhdpi/ic_stat_notify.png and /dev/null differ diff --git a/app/src/main/res/drawable-xxhdpi/ic_notify_grade.png b/app/src/main/res/drawable-xxhdpi/ic_notify_grade.png new file mode 100644 index 00000000..cba48ec2 Binary files /dev/null and b/app/src/main/res/drawable-xxhdpi/ic_notify_grade.png differ diff --git a/app/src/main/res/drawable-xxhdpi/ic_stat_notify.png b/app/src/main/res/drawable-xxhdpi/ic_stat_notify.png deleted file mode 100644 index c1d78d46..00000000 Binary files a/app/src/main/res/drawable-xxhdpi/ic_stat_notify.png and /dev/null differ diff --git a/app/src/main/res/drawable-xxxhdpi/ic_stat_notify.png b/app/src/main/res/drawable-xxxhdpi/ic_stat_notify.png deleted file mode 100644 index ee89e601..00000000 Binary files a/app/src/main/res/drawable-xxxhdpi/ic_stat_notify.png and /dev/null differ diff --git a/app/src/main/res/values-pl/strings.xml b/app/src/main/res/values-pl/strings.xml index da84ba42..da4fbbd7 100644 --- a/app/src/main/res/values-pl/strings.xml +++ b/app/src/main/res/values-pl/strings.xml @@ -122,4 +122,6 @@ Włącz odświeżanie danych w tle Interwał między odświeżaniem danych Synchronizacja tylko przez WiFi + + Nowe oceny diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 0c039698..84b60682 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -118,4 +118,6 @@ Enable background data refreshing Interval between data refreshing Synchronization via WiFi only + + New grades