Skip to content

Commit

Permalink
Merge pull request #2 from chenxiaolong/sdk-32
Browse files Browse the repository at this point in the history
Target SDK 32 instead of the Tiramisu preview
  • Loading branch information
chenxiaolong authored May 19, 2022
2 parents 00d77c5 + e76035c commit 9c3ae4b
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 30 deletions.
4 changes: 2 additions & 2 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ plugins {
}

android {
compileSdkPreview = "Tiramisu"
compileSdk = 32

defaultConfig {
applicationId = "com.chiller3.bcr"
minSdk = 29
targetSdkPreview = "Tiramisu"
targetSdk = 32
versionCode = 1
versionName = "1.0"

Expand Down
6 changes: 1 addition & 5 deletions app/src/main/java/com/chiller3/bcr/Permissions.kt
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,7 @@ import androidx.core.content.ContextCompat
import androidx.core.os.BuildCompat

object Permissions {
private val REQUIRED_33: Array<String> = arrayOf(Manifest.permission.POST_NOTIFICATIONS)

@BuildCompat.PrereleaseSdkCheck
val REQUIRED: Array<String> = if (BuildCompat.isAtLeastT()) { REQUIRED_33 } else { arrayOf() } +
arrayOf(Manifest.permission.RECORD_AUDIO)
val REQUIRED: Array<String> = arrayOf(Manifest.permission.RECORD_AUDIO)

private fun isGranted(context: Context, permission: String) =
ContextCompat.checkSelfPermission(context, permission) == PackageManager.PERMISSION_GRANTED
Expand Down
21 changes: 21 additions & 0 deletions app/src/main/java/com/chiller3/bcr/RecorderApplication.kt
Original file line number Diff line number Diff line change
@@ -1,13 +1,34 @@
package com.chiller3.bcr

import android.app.Application
import android.app.NotificationChannel
import android.app.NotificationManager
import com.google.android.material.color.DynamicColors

class RecorderApplication : Application() {
companion object {
const val CHANNEL_ID = "persistent"
}

override fun onCreate() {
super.onCreate()

// Enable Material You colors
DynamicColors.applyToActivitiesIfAvailable(this)

createNotificationChannel()
}

/**
* Create a low priority notification channel for the persistent notification.
*/
private fun createNotificationChannel() {
val name: CharSequence = getString(R.string.notification_channel_persistent_name)
val description = getString(R.string.notification_channel_persistent_desc)
val channel = NotificationChannel(CHANNEL_ID, name, NotificationManager.IMPORTANCE_LOW)
channel.description = description

val notificationManager = getSystemService(NotificationManager::class.java)
notificationManager.createNotificationChannel(channel)
}
}
23 changes: 1 addition & 22 deletions app/src/main/java/com/chiller3/bcr/RecorderInCallService.kt
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package com.chiller3.bcr

import android.app.Notification
import android.app.NotificationChannel
import android.app.NotificationManager
import android.app.PendingIntent
import android.content.Intent
import android.net.Uri
Expand All @@ -16,7 +14,6 @@ import android.util.Log
class RecorderInCallService : InCallService(), RecorderThread.OnRecordingCompletedListener {
companion object {
private val TAG = RecorderInCallService::class.java.simpleName
private const val CHANNEL_ID = "persistent"
}

private val handler = Handler(Looper.getMainLooper())
Expand All @@ -42,11 +39,6 @@ class RecorderInCallService : InCallService(), RecorderThread.OnRecordingComplet
}
}

override fun onCreate() {
super.onCreate()
createNotificationChannel()
}

override fun onCallAdded(call: Call) {
super.onCallAdded(call)
Log.d(TAG, "onCallAdded: $call")
Expand Down Expand Up @@ -114,19 +106,6 @@ class RecorderInCallService : InCallService(), RecorderThread.OnRecordingComplet
}
}

/**
* Create a low priority notification channel for the persistent notification.
*/
private fun createNotificationChannel() {
val name: CharSequence = getString(R.string.notification_channel_persistent_name)
val description = getString(R.string.notification_channel_persistent_desc)
val channel = NotificationChannel(CHANNEL_ID, name, NotificationManager.IMPORTANCE_LOW)
channel.description = description

val notificationManager = getSystemService(NotificationManager::class.java)
notificationManager.createNotificationChannel(channel)
}

/**
* Create a persistent notification for use during recording. The notification appearance is
* fully static and in progress call recording is represented by the presence or absence of the
Expand All @@ -137,7 +116,7 @@ class RecorderInCallService : InCallService(), RecorderThread.OnRecordingComplet
val pendingIntent = PendingIntent.getActivity(
this, 0, notificationIntent, PendingIntent.FLAG_IMMUTABLE
)
val builder = Notification.Builder(this, CHANNEL_ID)
val builder = Notification.Builder(this, RecorderApplication.CHANNEL_ID)
builder.setContentTitle(getText(R.string.recording_in_progress))
builder.setSmallIcon(R.drawable.ic_launcher_foreground)
builder.setContentIntent(pendingIntent)
Expand Down
1 change: 0 additions & 1 deletion app/src/main/java/com/chiller3/bcr/SettingsActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import android.net.Uri
import android.os.Bundle
import androidx.activity.result.contract.ActivityResultContracts
import androidx.appcompat.app.AppCompatActivity
import androidx.appcompat.widget.Toolbar
import androidx.preference.Preference
import androidx.preference.PreferenceFragmentCompat
import androidx.preference.SwitchPreferenceCompat
Expand Down

0 comments on commit 9c3ae4b

Please sign in to comment.