Skip to content

Commit

Permalink
Merge pull request #6 from RLD-JL/version-1.0.3
Browse files Browse the repository at this point in the history
Version 1.0.3
  • Loading branch information
RLD-JL authored Jun 5, 2022
2 parents b9cb747 + 7a0d24f commit 96a2103
Show file tree
Hide file tree
Showing 14 changed files with 152 additions and 108 deletions.
16 changes: 6 additions & 10 deletions androidApp/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@ dependencies {
implementation("androidx.palette:palette-ktx:1.0.0")

implementation("androidx.compose.ui:ui-util:1.2.0-beta02")
implementation("androidx.compose.animation:animation:1.1.1")
implementation("androidx.compose.material:material:1.2.0-beta02")
implementation("androidx.compose.ui:ui:1.2.0-beta02")
implementation("androidx.compose.animation:animation:1.1.1")
debugImplementation("androidx.compose.ui:ui-tooling:1.1.1")
implementation("androidx.compose.ui:ui-tooling-preview:1.1.1")
implementation("androidx.compose.material:material:1.2.0-beta02")

implementation("com.google.android.exoplayer:exoplayer:2.17.1")
implementation("com.google.android.exoplayer:extension-mediasession:2.17.1")
Expand All @@ -32,14 +32,10 @@ dependencies {
implementation("io.coil-kt:coil-compose:2.1.0")
implementation("com.google.dagger:hilt-android:2.38.1")
kapt("com.google.dagger:hilt-android-compiler:2.38.1")
implementation("com.github.bumptech.glide:glide:4.13.2")
annotationProcessor("com.github.bumptech.glide:compiler:4.13.2")

implementation("com.google.accompanist:accompanist-swiperefresh:0.24.1-alpha")
implementation("androidx.core:core-splashscreen:1.0.0-rc01")



androidTestImplementation("androidx.compose.ui:ui-test-junit4:${rootProject.extra["compose_version"]}")
debugImplementation("androidx.compose.ui:ui-tooling:${rootProject.extra["compose_version"]}")
debugImplementation("com.squareup.leakcanary:leakcanary-android:2.7")
Expand All @@ -50,13 +46,13 @@ kapt {
}

android {
compileSdk = 31
compileSdk = 32
defaultConfig {
applicationId = "com.rld.justlisten.android"
minSdk = 21
targetSdk = 31
versionCode = 14
versionName = "1.0.2"
targetSdk = 32
versionCode = 15
versionName = "1.0.3"
vectorDrawables {
useSupportLibrary = true
}
Expand Down
30 changes: 19 additions & 11 deletions androidApp/proguard-rules.pro
Original file line number Diff line number Diff line change
Expand Up @@ -45,17 +45,25 @@
kotlinx.serialization.KSerializer serializer(...);
}

# @Serializable and @Polymorphic are used at runtime for polymorphic serialization.
-keepattributes RuntimeVisibleAnnotations,AnnotationDefault

-keep public class * implements com.bumptech.glide.module.GlideModule
-keep class * extends com.bumptech.glide.module.AppGlideModule {
<init>(...);
# Allow R8 to optimize away the FastServiceLoader.
# Together with ServiceLoader optimization in R8
# this results in direct instantiation when loading Dispatchers.Main
-assumenosideeffects class kotlinx.coroutines.internal.MainDispatcherLoader {
boolean FAST_SERVICE_LOADER_ENABLED return false;
}
-keep public enum com.bumptech.glide.load.ImageHeaderParser$** {
**[] $VALUES;
public *;

-assumenosideeffects class kotlinx.coroutines.internal.FastServiceLoaderKt {
boolean ANDROID_DETECTED return true;
}
-keep class com.bumptech.glide.load.data.ParcelFileDescriptorRewinder$InternalRewinder {
*** rewind();

# Disable support for "Missing Main Dispatcher", since we always have Android main dispatcher
-assumenosideeffects class kotlinx.coroutines.internal.MainDispatchersKt {
boolean SUPPORT_MISSING return false;
}

# Statically turn off all debugging facilities and assertions
-assumenosideeffects class kotlinx.coroutines.DebugKt {
boolean getASSERTIONS_ENABLED() return false;
boolean getDEBUG() return false;
boolean getRECOVER_STACK_TRACES() return false;
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,14 @@ package com.rld.justlisten.android.exoplayer
import android.app.PendingIntent
import android.content.Context
import android.graphics.Bitmap
import android.graphics.drawable.BitmapDrawable
import android.net.Uri
import android.support.v4.media.session.MediaControllerCompat
import android.support.v4.media.session.MediaSessionCompat
import com.bumptech.glide.Glide
import com.bumptech.glide.load.engine.DiskCacheStrategy
import com.bumptech.glide.request.RequestOptions
import coil.ImageLoader
import coil.request.CachePolicy
import coil.request.ImageRequest
import coil.request.SuccessResult
import com.google.android.exoplayer2.Player
import com.google.android.exoplayer2.ui.PlayerNotificationManager
import com.rld.justlisten.android.R
Expand Down Expand Up @@ -98,19 +100,24 @@ class MusicNotificationManager(

private suspend fun resolveUriAsBitmap(uri: Uri): Bitmap? {
return withContext(Dispatchers.IO) {
// Block on downloading artwork.
Glide.with(context).applyDefaultRequestOptions(glideOptions)
.asBitmap()
.load(uri)
.submit(NOTIFICATION_LARGE_ICON_SIZE, NOTIFICATION_LARGE_ICON_SIZE)
.get()
getBitmap(uri)
}
}
}
}

const val NOTIFICATION_LARGE_ICON_SIZE = 144 // px

private val glideOptions = RequestOptions()
.fallback(R.drawable.ic_add_to_playlist_background)
.diskCacheStrategy(DiskCacheStrategy.DATA)
private suspend fun getBitmap(uri: Uri): Bitmap? {
val loader = ImageLoader(context)
val request = ImageRequest.Builder(context)
.data(uri)
.memoryCachePolicy(CachePolicy.ENABLED)
.diskCachePolicy(CachePolicy.ENABLED)
.allowHardware(false) // Disable hardware bitmaps.
.build()
return try {
val result = (loader.execute(request) as SuccessResult).drawable
(result as BitmapDrawable).bitmap
} catch (e: Exception) {
null
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,21 @@ import android.support.v4.media.MediaDescriptionCompat
import android.support.v4.media.MediaMetadataCompat
import android.support.v4.media.session.MediaSessionCompat
import androidx.media.MediaBrowserServiceCompat
import com.google.android.exoplayer2.ExoPlayer
import com.google.android.exoplayer2.Player
import com.google.android.exoplayer2.ext.mediasession.MediaSessionConnector
import com.google.android.exoplayer2.ext.mediasession.TimelineQueueNavigator
import com.rld.justlisten.android.exoplayer.callbacks.MusicPlaybackPreparer
import com.rld.justlisten.android.exoplayer.callbacks.MusicPlayerEventListener
import com.rld.justlisten.android.exoplayer.callbacks.MusicPlayerNotificationListener
import com.rld.justlisten.android.exoplayer.library.extension.toMediaItem
import com.rld.justlisten.android.exoplayer.utils.Constants.MEDIA_ROOT_ID
import com.rld.justlisten.android.exoplayer.utils.Constants.NETWORK_ERROR
import com.google.android.exoplayer2.ExoPlayer
import com.google.android.exoplayer2.Player
import com.google.android.exoplayer2.ext.mediasession.MediaSessionConnector
import com.google.android.exoplayer2.ext.mediasession.TimelineQueueNavigator
import dagger.hilt.android.AndroidEntryPoint
import kotlinx.coroutines.*
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.SupervisorJob
import kotlinx.coroutines.cancel
import javax.inject.Inject

private const val SERVICE_TAG = "MusicService"
Expand All @@ -32,7 +35,7 @@ class MusicService : MediaBrowserServiceCompat() {

lateinit var musicNotificationManager: MusicNotificationManager

private val serviceJob = Job()
private val serviceJob = SupervisorJob()
private val serviceScope = CoroutineScope(Dispatchers.Main + serviceJob)

private lateinit var mediaSession: MediaSessionCompat
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import kotlinx.coroutines.*
import javax.inject.Inject

class MusicServiceConnection @Inject constructor(
val musicSource: MusicSource,
private val musicSource: MusicSource,
context: Context
) {

Expand Down Expand Up @@ -75,13 +75,14 @@ class MusicServiceConnection @Inject constructor(
serviceScope.launch {
while (!sliderClicked.value) {
ensureActive()
delay(100L)
val pos = playbackState.value?.currentPlaybackPosition
if (songDuration.value != pos) {
pos?.let {
songDuration.value = it
}
}
delay(1000L)
delay(900L)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package com.rld.justlisten.android.exoplayer.callbacks

import android.widget.Toast
import com.rld.justlisten.android.exoplayer.MusicNotificationManager
import com.rld.justlisten.android.exoplayer.MusicService
import com.google.android.exoplayer2.ExoPlayer
import com.google.android.exoplayer2.PlaybackException
import com.google.android.exoplayer2.Player
import com.rld.justlisten.android.exoplayer.MusicNotificationManager
import com.rld.justlisten.android.exoplayer.MusicService

class MusicPlayerEventListener(
private val musicService: MusicService,
Expand All @@ -22,7 +22,7 @@ class MusicPlayerEventListener(

override fun onPlayerError(error: PlaybackException) {
super.onPlayerError(error)
Toast.makeText(musicService, "Error", Toast.LENGTH_SHORT).show()
Toast.makeText(musicService, "Unfortunately this song has issues, try another one", Toast.LENGTH_SHORT).show()
}

override fun onPlaybackStateChanged(playbackState: Int) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
package com.rld.justlisten.android.ui.bottombars.playbar.components

import android.media.session.PlaybackState
import android.support.v4.media.session.PlaybackStateCompat
import android.support.v4.media.session.PlaybackStateCompat.*
import androidx.compose.foundation.BorderStroke
import androidx.compose.foundation.clickable
import androidx.compose.foundation.interaction.DragInteraction
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.remember
import androidx.compose.foundation.interaction.MutableInteractionSource
import androidx.compose.foundation.interaction.PressInteraction
import androidx.compose.foundation.layout.*
Expand All @@ -16,7 +13,6 @@ import androidx.compose.material.*
import androidx.compose.runtime.*
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.unit.Dp
Expand All @@ -26,10 +22,8 @@ import com.rld.justlisten.android.exoplayer.MusicService
import com.rld.justlisten.android.exoplayer.MusicServiceConnection
import com.rld.justlisten.android.ui.extensions.ModifiedSlider
import com.rld.justlisten.android.ui.utils.offsetX
import com.rld.justlisten.android.ui.utils.offsetY
import com.rld.justlisten.android.ui.utils.widthSize
import kotlinx.coroutines.InternalCoroutinesApi
import kotlinx.coroutines.flow.collect

@InternalCoroutinesApi
@Composable
Expand All @@ -48,13 +42,17 @@ fun PlayBarActionsMaximized(
interactionSource.interactions.collect { interaction ->
when (interaction) {
is PressInteraction.Press -> {
musicServiceConnection.sliderClicked.value = true
}
is PressInteraction.Release -> {
musicServiceConnection.transportControls.seekTo(musicServiceConnection.songDuration.value)
musicServiceConnection.sliderClicked.value = false
musicServiceConnection.updateSong()
}
is PressInteraction.Release -> {}
is PressInteraction.Cancel -> {}
is DragInteraction.Start -> {}
is DragInteraction.Start -> {
musicServiceConnection.sliderClicked.value = true
}
is DragInteraction.Stop -> {
musicServiceConnection.transportControls.seekTo(musicServiceConnection.songDuration.value)
musicServiceConnection.sliderClicked.value = false
Expand Down Expand Up @@ -87,7 +85,6 @@ fun PlayBarActionsMaximized(
.offset(x = offsetX(currentFraction, maxWidth).dp)
.width(widthSize(currentFraction, maxWidth).dp),
value = sliderPosition, onValueChange = {
musicServiceConnection.sliderClicked.value = true
musicServiceConnection.songDuration.value =
(it * MusicService.curSongDuration).toLong()
})
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
package com.rld.justlisten.android.ui.playlistdetailscreen.components

import androidx.compose.animation.core.animateDpAsState
import androidx.compose.foundation.*
import androidx.compose.foundation.layout.*
import androidx.compose.foundation.BorderStroke
import androidx.compose.foundation.Image
import androidx.compose.foundation.border
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material.MaterialTheme
import androidx.compose.material.MaterialTheme.typography
Expand All @@ -13,6 +18,7 @@ import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.painter.Painter
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.unit.Dp
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
Expand All @@ -35,8 +41,10 @@ fun BoxTopSection(scrollState: MutableState<Float>, playlistDetailState: Playlis
.padding(8.dp)
)
Text(
text = playlistDetailState.playlistName,
style = typography.h5.copy(fontWeight = FontWeight.ExtraBold),
text = playlistDetailState.playListCreatedBy,
style = typography.subtitle2.copy(fontWeight = FontWeight.ExtraBold),
maxLines = 1,
textAlign = TextAlign.Center,
modifier = Modifier.padding(8.dp),
)
Text(
Expand All @@ -51,7 +59,9 @@ fun BoxTopSection(scrollState: MutableState<Float>, playlistDetailState: Playlis
.padding(vertical = 4.dp, horizontal = 24.dp)
)
Text(
text = "Playlist created by ${playlistDetailState.playListCreatedBy}",
text = "Created by ${playlistDetailState.playlistName}",
maxLines = 1,
textAlign = TextAlign.Center,
style = typography.subtitle2,
modifier = Modifier.padding(4.dp)
)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.rld.justlisten.android.ui.screenpicker

import androidx.compose.runtime.*
import androidx.compose.runtime.saveable.rememberSaveable
import androidx.compose.ui.ExperimentalComposeUiApi
import com.rld.justlisten.Navigation
import com.rld.justlisten.ScreenIdentifier
Expand Down Expand Up @@ -44,7 +45,7 @@ fun Navigation.ScreenPicker(
musicServiceConnection: MusicServiceConnection,
settingsUpdated: () -> Unit
) {
val isPlayerReady: MutableState<Boolean> = remember {
val isPlayerReady: MutableState<Boolean> = rememberSaveable{
mutableStateOf(false)
}

Expand Down Expand Up @@ -107,7 +108,7 @@ fun Navigation.ScreenPicker(
},
onSearchClicked = { navigate(Search) },
refreshScreen = { events.refreshScreen() },
onSongPressed = { songId, title, user, songIcon ->
onSongPressed = { songId, _, _, _ ->
if (isPlayerReady.value) {
isPlayerReady.value = false
}
Expand Down Expand Up @@ -158,7 +159,7 @@ fun Navigation.ScreenPicker(
isPlayerReady.value = false
},
searchScreenState = stateProvider.get(screenIdentifier = screenIdentifier),
onSongPressed = { songId, title, user, songIcon ->
onSongPressed = { songId, _, _, _ ->
playMusicFromId(
musicServiceConnection,
(stateProvider.get(screenIdentifier = screenIdentifier) as SearchScreenState).searchResultTracks,
Expand Down
13 changes: 6 additions & 7 deletions shared/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTarget
plugins {
kotlin("multiplatform")
id("com.android.library")
kotlin("plugin.serialization") version "1.6.20"
kotlin("plugin.serialization") version "1.6.21"
id("com.squareup.sqldelight")
}

Expand All @@ -24,16 +24,15 @@ kotlin {
}
}
sourceSets {
val ktor_version = "1.6.3"
val ktor_version = "2.0.2"
val commonMain by getting {
dependencies {
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.6.1")
implementation("org.jetbrains.kotlinx:kotlinx-serialization-json:1.3.2")
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.6.2")
implementation("org.jetbrains.kotlinx:kotlinx-datetime:0.3.2")
implementation("io.ktor:ktor-client-core:$ktor_version")
implementation("io.ktor:ktor-client-json:$ktor_version")
implementation("io.ktor:ktor-client-content-negotiation:$ktor_version")
implementation("io.ktor:ktor-serialization-kotlinx-json:$ktor_version")
implementation("io.ktor:ktor-client-logging:$ktor_version")
implementation("io.ktor:ktor-client-serialization:$ktor_version")
implementation("org.jetbrains.kotlinx:kotlinx-datetime:0.3.2")
}
}
val commonTest by getting {
Expand Down
Loading

0 comments on commit 96a2103

Please sign in to comment.