Skip to content

Commit

Permalink
Port to Oreo
Browse files Browse the repository at this point in the history
Register a notification channel for the overlay notification, add a build
flavor, and use newer versions of Gradle and build tools
  • Loading branch information
AdamNiederer committed May 16, 2018
1 parent f9fb0b9 commit 0c84f2c
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 17 deletions.
27 changes: 15 additions & 12 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ if(rootProject.file("keystore.properties").exists()) {

android {
compileSdkVersion 26
buildToolsVersion "26.0.1"
buildToolsVersion '27.0.3'

defaultConfig {
applicationId "com.jmstudios.redmoon"
Expand All @@ -66,10 +66,13 @@ android {
}
}
}
flavorDimensions "dist"
productFlavors {
fdroid {
dimension "dist"
}
playstore {
dimension "dist"
}
}
sourceSets {
Expand All @@ -81,17 +84,17 @@ android {
}

dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile "com.android.support:support-compat:$android_support_version"
compile "com.android.support:appcompat-v7:$android_support_version"
compile "com.android.support:design:$android_support_version"
compile 'com.luckycatlabs:SunriseSunsetCalculator:1.2'
compile 'com.github.paolorotolo:appintro:4.1.0'
compile 'de.cketti.library.changelog:ckchangelog:1.2.2'
compile "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
compile 'org.greenrobot:eventbus:3.0.0'
compile 'me.smichel.android:kpreferences:0.7.0'
playstoreCompile 'com.github.hotchemi:android-rate:1.0.1'
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation "com.android.support:support-compat:$android_support_version"
implementation "com.android.support:appcompat-v7:$android_support_version"
implementation "com.android.support:design:$android_support_version"
implementation 'com.luckycatlabs:SunriseSunsetCalculator:1.2'
implementation 'com.github.paolorotolo:appintro:4.1.0'
implementation 'de.cketti.library.changelog:ckchangelog:1.2.2'
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
implementation 'org.greenrobot:eventbus:3.0.0'
implementation 'me.smichel.android:kpreferences:0.7.0'
playstoreImplementation 'com.github.hotchemi:android-rate:1.0.1'
// annotationProcessor 'org.greenrobot:eventbus-annotation-processor:3.0.1'
}

Expand Down
21 changes: 19 additions & 2 deletions app/src/main/java/com/jmstudios/redmoon/filter/Notification.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,13 @@
package com.jmstudios.redmoon.filter

import android.app.Notification
import android.app.NotificationChannel
import android.app.NotificationManager
import android.app.PendingIntent
import android.content.Context
import android.content.Intent
import android.os.Build
import android.support.annotation.RequiresApi
import android.support.v4.app.NotificationCompat
import android.support.v4.content.ContextCompat

Expand All @@ -23,12 +27,25 @@ import com.jmstudios.redmoon.util.*
class Notification(
private val context: Context,
private val appMonitor: CurrentAppMonitor) {

private val notificationManager = context.getSystemService(Context.NOTIFICATION_SERVICE)
as NotificationManager

fun build(isOn: Boolean) : Notification {
return NotificationCompat.Builder(context).apply {
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O
&& notificationManager.getNotificationChannel(getString(R.string.notification_channel_overlay_id)) == null) {
// Register a notification channel for Oreo if we don't already have one
val channel = NotificationChannel(getString(R.string.notification_channel_overlay_id),
"Overlay Toggle", NotificationManager.IMPORTANCE_MIN)
channel.description = getString(R.string.notification_channel_overlay_description)
notificationManager.createNotificationChannel(channel)
}

return NotificationCompat.Builder(context, getString(R.string.notification_channel_overlay_id)).apply {
// Set notification appearance
setSmallIcon(R.drawable.notification_icon_half_moon)
color = ContextCompat.getColor(appContext, R.color.color_primary)
priority = Notification.PRIORITY_MIN
priority = NotificationCompat.PRIORITY_MIN

if (belowAPI(24)) { setContentTitle(getString(R.string.app_name)) }
setSubText(activeProfile.name)
Expand Down
3 changes: 3 additions & 0 deletions app/src/main/res/values/donottranslate.xml
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,9 @@
<string name="translation_url" translatable="false">https://hosted.weblate.org/engage/red-moon/</string>
<string name="contact_email_adress" translatable="false">mailto:marienraat@riseup.net,s@smichel.me</string>

<!-- Notification channel slug -->
<string name="notification_channel_overlay_id" translatable="false">com.jmstudios.redmoon.overlay</string>

<string-array name="time_toggle_values_array"
translatable="false">
<item>never</item>
Expand Down
3 changes: 3 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -187,4 +187,7 @@
<string name="time_toggle_options_array_0">Manual</string>
<string name="time_toggle_options_array_1">Automatic (sun)</string>
<string name="time_toggle_options_array_2">Automatic (custom)</string>

<!-- Notification channel descriptions -->
<string name="notification_channel_overlay_description">The persistent overlay control notification</string>
</resources>
3 changes: 2 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@ buildscript {
ext.kotlin_version = '1.1.4-3'
repositories {
jcenter()
google()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.3.3'
classpath 'com.android.tools.build:gradle:3.1.2'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath 'com.github.ben-manes:gradle-versions-plugin:0.15.0'

Expand Down
4 changes: 2 additions & 2 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#Fri Mar 24 09:18:40 EDT 2017
#Sat May 05 00:43:06 EDT 2018
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-3.3-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-4.4-all.zip

0 comments on commit 0c84f2c

Please sign in to comment.