Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore:(37) upgrade agp #40

Merged
merged 5 commits into from
Oct 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ jobs:

steps:
- uses: actions/checkout@v2.4.2
- name: set up JDK 11
- name: set up JDK 17
uses: actions/setup-java@v2
with:
java-version: '11'
java-version: '17'
distribution: 'adopt'
cache: gradle

Expand All @@ -33,7 +33,7 @@ jobs:
with:
fail_ci_if_error: true
token: ${{ secrets.CODECOV_TOKEN }}
files: "app/build/reports/jacoco/createDebugCoverage/createDebugCoverage.xml,data/build/reports/jacoco/createDebugCoverage/createDebugCoverage.xml,features/player/presentation/build/reports/jacoco/createDebugCoverage/createDebugCoverage.xml,core/design/build/reports/jacoco/createDebugCoverage/createDebugCoverage.xml,app/build/reports/coverage/androidTest/debug/connected/report.xml,core/design/build/reports/coverage/androidTest/debug/connected/report.xml,feature/player/presentation/build/reports/coverage/androidTest/debug/connected/report.xml,data/build/reports/coverage/androidTest/debug/connected/report.xml"
files: "feature/playlist/presentation/build/reports/jacoco/createDebugCoverage/createDebugCoverage.xml,feature/catalog/presentation/build/reports/jacoco/createDebugCoverage/createDebugCoverage.xml,data/build/reports/jacoco/createDebugCoverage/createDebugCoverage.xml,features/player/presentation/build/reports/jacoco/createDebugCoverage/createDebugCoverage.xml,core/design/build/reports/jacoco/createDebugCoverage/createDebugCoverage.xml,core/design/build/reports/coverage/androidTest/debug/connected/report.xml,feature/player/presentation/build/reports/coverage/androidTest/debug/connected/report.xml,data/build/reports/coverage/androidTest/debug/connected/report.xml"
- name: Upload test report artifact
if: ${{ failure() }}
uses: actions/upload-artifact@v3
Expand Down
8 changes: 4 additions & 4 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2.4.2
- name: Set up JDK 11
- name: Set up JDK 17
uses: actions/setup-java@v1
with:
java-version: 11
java-version: 17
- name: Create google-services.json
run: |
echo '${{ secrets.FIREBASE_GOOGLE_SERVICES_JSON }}' > app/google-services.json
Expand All @@ -27,10 +27,10 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2.4.2
- name: Set up JDK 11
- name: Set up JDK 17
uses: actions/setup-java@v1
with:
java-version: 11
java-version: 17
- name: Create keystore
run: |
echo "${{ secrets.RELEASE_KEYSTORE }}" > release.keystore.asc
Expand Down
13 changes: 13 additions & 0 deletions .idea/androidTestResultsUserPreferences.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions .idea/compiler.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion .idea/kotlinc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ android {
versionName = "1.2.2"
}

buildFeatures {
buildConfig = true
}

buildTypes {
release {
signingConfig = signingConfigs.getByName("release")
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*
* Copyright 2023 Marco Cattaneo
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package dev.marcocattaneo.sleep.di

import androidx.test.ext.junit.rules.ActivityScenarioRule
import dev.marcocattaneo.sleep.MainActivity
import org.junit.Assert.*
import org.junit.Rule
import org.junit.Test


internal class SleepifyApplicationTest {

@get:Rule
var rule: ActivityScenarioRule<MainActivity> = ActivityScenarioRule(MainActivity::class.java)

@Test
fun testOnCreate() {
// Given
val scenario = rule.scenario

// When
scenario.onActivity { activity ->
// then
assertEquals(SleepifyApplication::class.java, activity.application::class.java)
}
}

}
1 change: 1 addition & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android">

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,22 @@

package dev.marcocattaneo.sleep.ui.notification

import android.Manifest
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.content.pm.PackageManager
import android.os.Build
import androidx.core.app.ActivityCompat
import androidx.core.app.NotificationCompat
import androidx.core.app.NotificationManagerCompat
import androidx.media.app.NotificationCompat.MediaStyle
import dagger.hilt.android.qualifiers.ApplicationContext
import dev.marcocattaneo.sleep.R
import dev.marcocattaneo.sleep.player.presentation.R as PlayerR
import dev.marcocattaneo.sleep.R as AppR
import dev.marcocattaneo.sleep.player.presentation.AudioPlayer
import javax.inject.Inject

Expand All @@ -51,18 +55,19 @@ class PlayerNotificationManager @Inject constructor(
private val stopPendingIntent: PendingIntent
get() = createPendingIntent(PlayerNotificationService.Action.STOP)

private fun createPendingIntent(action: PlayerNotificationService.Action) = PendingIntent.getService(
context,
0,
Intent(context, PlayerNotificationService::class.java).setAction(action.key),
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) PendingIntent.FLAG_IMMUTABLE else 0
)
private fun createPendingIntent(action: PlayerNotificationService.Action) =
PendingIntent.getService(
context,
0,
Intent(context, PlayerNotificationService::class.java).setAction(action.key),
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) PendingIntent.FLAG_IMMUTABLE else 0
)

init {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
val channel = NotificationChannel(
CHANNEL_ID,
context.getString(R.string.app_name),
context.getString(AppR.string.app_name),
NotificationManager.IMPORTANCE_LOW
).apply {
description = "Audio Player"
Expand All @@ -75,32 +80,59 @@ class PlayerNotificationManager @Inject constructor(
}
}

private fun NotificationCompat.Builder.show() =
NotificationManagerCompat.from(context).notify(NOTIFICATION_ID, build())
private fun NotificationCompat.Builder.show() = if (
Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU &&
ActivityCompat.checkSelfPermission(
context,
Manifest.permission.POST_NOTIFICATIONS
) != PackageManager.PERMISSION_GRANTED
) {
throw IllegalStateException("You need to add the permission ${Manifest.permission.POST_NOTIFICATIONS} to your AndroidManifest.xml")
} else NotificationManagerCompat.from(context).notify(NOTIFICATION_ID, build())

private fun baseNotification(
cancelable: Boolean
) = NotificationCompat.Builder(context, CHANNEL_ID)
.setVisibility(NotificationCompat.VISIBILITY_PUBLIC)
.setContentTitle(context.getString(R.string.app_name))
.setContentTitle(context.getString(AppR.string.app_name))
.setContentIntent(audioPlayer.controller.sessionActivity)
.setDeleteIntent(createPendingIntent(PlayerNotificationService.Action.STOP))
.setSmallIcon(R.mipmap.ic_launcher)
.setSmallIcon(AppR.mipmap.ic_launcher)
.setAutoCancel(cancelable)


fun updateNotification(
isPlaying: Boolean,
) = baseNotification(cancelable = !isPlaying)
.apply {
addAction(NotificationCompat.Action.Builder(R.drawable.ic_baseline_close_24, "Stop", stopPendingIntent).build())
addAction(
NotificationCompat.Action.Builder(
PlayerR.drawable.ic_baseline_close_24,
"Stop",
stopPendingIntent
).build()
)
if (isPlaying) {
addAction(NotificationCompat.Action.Builder(R.drawable.ic_baseline_pause_24, "Pause", pausePendingIntent).build())
addAction(
NotificationCompat.Action.Builder(
PlayerR.drawable.ic_baseline_pause_24,
"Pause",
pausePendingIntent
).build()
)
} else {
addAction(NotificationCompat.Action.Builder(R.drawable.ic_baseline_play_arrow_24, "Play", playPendingIntent).build())
addAction(
NotificationCompat.Action.Builder(
PlayerR.drawable.ic_baseline_play_arrow_24,
"Play",
playPendingIntent
).build()
)
}
}
.setStyle(MediaStyle().setShowActionsInCompactView(1).setMediaSession(audioPlayer.sessionToken))
.setStyle(
MediaStyle().setShowActionsInCompactView(1).setMediaSession(audioPlayer.sessionToken)
)
.show()

fun removeNotification() = NotificationManagerCompat.from(context).cancel(NOTIFICATION_ID)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,11 @@ import javax.inject.Inject
class PlayerNotificationService : Service() {

sealed class Action(val key: String) {
object PLAY : Action("dev.marcocattaneo.sleep.PlayerNotificationService.PLAY")
data object PLAY : Action("dev.marcocattaneo.sleep.PlayerNotificationService.PLAY")

object PAUSE : Action("dev.marcocattaneo.sleep.PlayerNotificationService.PAUSE")
data object PAUSE : Action("dev.marcocattaneo.sleep.PlayerNotificationService.PAUSE")

object STOP : Action("dev.marcocattaneo.sleep.PlayerNotificationService.STOP")
data object STOP : Action("dev.marcocattaneo.sleep.PlayerNotificationService.STOP")
}

@Inject
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ package sleep.buildtools.android
* Defines the shared configuration for Android targets.
*/
internal object AndroidConfigs {
const val COMPILE_SDK: Int = 33
const val COMPILE_SDK: Int = 34
const val MIN_SDK: Int = 24
const val TARGET_SDK: Int = 33

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ internal class AndroidAppConvention : BuildConvention {

ext.compileSdk = AndroidConfigs.COMPILE_SDK

ext.packagingOptions {
ext.packaging {
resources {
excludes += "/META-INF/{AL2.0,LGPL2.1}"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import sleep.buildtools.utils.libsCatalog

internal class AndroidComposeConvention : BuildConvention {
override fun apply(target: Project) {
target.extensions.configure<CommonExtension<*, *, *, *>> { ext ->
target.extensions.configure<CommonExtension<*, *, *, *, *>> { ext ->
ext.buildFeatures {
compose = true
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ internal class AndroidConvention : BuildConvention {
}
}

target.extensions.configure<CommonExtension<*, *, *, *>> { ext ->
target.extensions.configure<CommonExtension<*, *, *, *, *>> { ext ->
ext.compileSdk = AndroidConfigs.COMPILE_SDK

ext.defaultConfig {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ internal class AndroidLibraryConvention : BuildConvention {
}

ext.defaultConfig {
targetSdk = AndroidConfigs.TARGET_SDK
minSdk = AndroidConfigs.MIN_SDK
testInstrumentationRunner = AndroidConfigs.TEST_INSTRUMENTATION_RUNNER
vectorDrawables.useSupportLibrary = true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

package sleep.buildtools.jacoco

object JacocoOptions {
internal object JacocoOptions {
val EXCLUDED_FILES = listOf(
// data binding
"android/databinding/**/*.class",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,4 @@ inline fun <reified T : Any> MockKMatcherScope.anyInline(): T =
this.isAccessible = true
val valueType = parameters[0].type.classifier as KClass<*>
call(match(ConstantMatcher(true), valueType))
}

fun <T : Any> MockKMatcherScope.match(matcher: Matcher<T>, type: KClass<T>): T =
(getProperty("callRecorder") as MockKGateway.CallRecorder).matcher(matcher, type)
}
4 changes: 4 additions & 0 deletions data/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ plugins {
android {
namespace 'dev.marcocattaneo.sleep.data'

buildFeatures {
buildConfig = true
}

defaultConfig {
buildConfigField("String", "BASE_URL", "\"https://europe-west2-sleep-app-mobile.cloudfunctions.net/\"")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
package dev.marcocattaneo.sleep.data.repository

import arrow.core.Either
import arrow.core.computations.either
import arrow.core.raise.either
import dev.marcocattaneo.sleep.data.auth.AuthDataSource
import dev.marcocattaneo.sleep.data.http.SleepService
import dev.marcocattaneo.sleep.data.mapper.MediaFileMapper
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import dev.marcocattaneo.sleep.data.mapper.MediaFileMapper
import dev.marcocattaneo.sleep.data.model.MediaFile
import dev.marcocattaneo.sleep.data.model.MediaUrl
import dev.marcocattaneo.sleep.domain.AppException
import dev.marcocattaneo.sleep.domain.cache.CachePolicy
import dev.marcocattaneo.sleep.domain.cache.CacheService
import dev.marcocattaneo.sleep.domain.model.MediaFileEntity
import dev.marcocattaneo.sleep.domain.repository.MediaRepository
Expand Down Expand Up @@ -54,7 +55,7 @@ internal class MediaRepositoryImplTest {
fun setup() {
MockKAnnotations.init(this)

coEvery { mediaFileCache.getValue(any(), any()) } returns null
coEvery { mediaFileCache.getValue(any(), any<CachePolicy>()) } returns null
coEvery { mediaFileCache.setValue(any(), any(), any()) } just Runs
coEvery { authDataSource.getAuthToken() } returns Either.Right("token")

Expand Down
Loading
Loading