Skip to content

Commit

Permalink
Fixed notification, change Miniplayer to Compose
Browse files Browse the repository at this point in the history
  • Loading branch information
maxrave-dev committed Apr 22, 2024
1 parent cb0744d commit b0c2009
Show file tree
Hide file tree
Showing 24 changed files with 805 additions and 499 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import android.content.Context
import android.content.Intent
import android.content.pm.PackageManager
import android.graphics.drawable.BitmapDrawable
import android.os.Bundle
import androidx.annotation.OptIn
import androidx.appcompat.content.res.AppCompatResources
import androidx.core.app.ActivityCompat
Expand All @@ -17,12 +16,10 @@ import androidx.core.app.NotificationManagerCompat
import androidx.core.graphics.drawable.toBitmap
import androidx.core.net.toUri
import androidx.media3.common.util.UnstableApi
import androidx.navigation.NavDeepLinkBuilder
import coil.ImageLoader
import coil.request.ImageRequest
import coil.request.SuccessResult
import com.maxrave.simpmusic.R
import com.maxrave.simpmusic.common.Config
import com.maxrave.simpmusic.ui.MainActivity
import kotlinx.coroutines.runBlocking

Expand Down Expand Up @@ -50,8 +47,8 @@ object NotificationHandler {
val request =
ImageRequest.Builder(context)
.data(
noti.single.firstOrNull()?.thumbnails?.lastOrNull()?.url
?: noti.album.firstOrNull()?.thumbnails?.lastOrNull()?.url,
noti.single.firstOrNull()?.thumbnail
?: noti.album.firstOrNull()?.thumbnail
)
.allowHardware(false) // Disable hardware bitmaps.
.build()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,19 @@ import android.util.Log
import androidx.hilt.work.HiltWorker
import androidx.work.CoroutineWorker
import androidx.work.WorkerParameters
import com.maxrave.kotlinytmusicscraper.models.AlbumItem
import com.maxrave.simpmusic.data.db.entities.ArtistEntity
import com.maxrave.simpmusic.data.db.entities.FollowedArtistSingleAndAlbum
import com.maxrave.simpmusic.data.db.entities.NotificationEntity
import com.maxrave.simpmusic.data.model.browse.artist.ResultAlbum
import com.maxrave.simpmusic.data.model.browse.artist.ResultSingle
import com.maxrave.simpmusic.data.repository.MainRepository
import com.maxrave.simpmusic.extension.symmetricDifference
import com.maxrave.simpmusic.utils.Resource
import com.maxrave.simpmusic.viewModel.MoreAlbumsViewModel
import dagger.assisted.Assisted
import dagger.assisted.AssistedInject
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.flow.combine
import kotlinx.coroutines.flow.first
import kotlinx.coroutines.withContext
import java.time.LocalDateTime
Expand All @@ -42,56 +44,49 @@ class NotifyWork
Log.w("NotifyWork", "doWork: $artistList")
Log.w("NotifyWork", "doWork: $listFollowedArtistSingleAndAlbum")
artistList.forEach { art ->
mainRepository.getArtistData(art.channelId).first().let { artistData ->
if (artistData is Resource.Success) {
val artist = artistData.data
if (artist != null) {
val single = artist.singles?.results
val album = artist.albums?.results
val savedSingle =
listFollowedArtistSingleAndAlbum.find { it.channelId == art.channelId }?.single
val savedAlbum =
listFollowedArtistSingleAndAlbum.find { it.channelId == art.channelId }?.album
if (!savedSingle.isNullOrEmpty() && single != null) {
val differentSingle =
single.map { it.browseId } symmetricDifference (savedSingle.map { it["browseId"] })
mapOfNotification.add(
NotificationModel(
name = art.name,
channelId = art.channelId,
single =
single.filter {
differentSingle.contains(it.browseId)
},
album = listOf(),
),
)
}
if (!savedAlbum.isNullOrEmpty() && album != null) {
val differentAlbum =
album.map { it.browseId } symmetricDifference (savedAlbum.map { it["browseId"] })
mapOfNotification.add(
NotificationModel(
name = art.name,
channelId = art.channelId,
single = listOf(),
album =
album.filter {
differentAlbum.contains(it.browseId)
},
),
)
}
mainRepository.insertFollowedArtistSingleAndAlbum(
FollowedArtistSingleAndAlbum(
channelId = art.channelId,
name = art.name,
single = single.toMap(),
album = album.toMap(),
),
)
}
combine(mainRepository.getAlbumMore("MPAD${art.channelId}", MoreAlbumsViewModel.ALBUM_PARAM), mainRepository.getAlbumMore("MPAD${art.channelId}", MoreAlbumsViewModel.SINGLE_PARAM)) {
album, single -> Pair(album, single)
}.first().let { pair ->
val albumItem = pair.first?.items?.firstOrNull()?.items
val singleItem = pair.second?.items?.firstOrNull()?.items
val savedAlbum = listFollowedArtistSingleAndAlbum.find { it.channelId == art.channelId }?.album
if (!savedAlbum.isNullOrEmpty() && !albumItem.isNullOrEmpty()) {
val differentAlbum =
albumItem.filter { ytItem ->
(albumItem.map { item -> item.id } symmetricDifference (savedAlbum.map { it["browseId"] })).contains(ytItem.id)
}.filterIsInstance<AlbumItem>()
mapOfNotification.add(
NotificationModel(
name = art.name,
channelId = art.channelId,
single = listOf(),
album = differentAlbum,
),
)
}
val savedSingle = listFollowedArtistSingleAndAlbum.find { it.channelId == art.channelId }?.single
if (!savedSingle.isNullOrEmpty() && !singleItem.isNullOrEmpty()) {
val differentSingle =
singleItem.filter { ytItem ->
(singleItem.map { item -> item.id } symmetricDifference (savedSingle.map { it["browseId"] })).contains(ytItem.id)
}.filterIsInstance<AlbumItem>()
mapOfNotification.add(
NotificationModel(
name = art.name,
channelId = art.channelId,
single = differentSingle,
album = listOf(),
),
)
}
mainRepository.insertFollowedArtistSingleAndAlbum(
FollowedArtistSingleAndAlbum(
channelId = art.channelId,
name = art.name,
single = singleItem.toMap(),
album = albumItem.toMap(),
),
)
}
}
Log.w("NotifyWork", "doWork: $mapOfNotification")
Expand Down Expand Up @@ -143,13 +138,23 @@ private fun List<Any>?.toMap(): List<Map<String, String>> {
}
}

is AlbumItem -> {
this.map {
val album = it as AlbumItem
mapOf(
"browseId" to album.id,
"title" to album.title,
"thumbnails" to album.thumbnail,
)
}
}
else -> listOf()
}
}

data class NotificationModel(
val name: String,
val channelId: String,
val single: List<ResultSingle>,
val album: List<ResultAlbum>,
val single: List<AlbumItem>,
val album: List<AlbumItem>,
)
Loading

0 comments on commit b0c2009

Please sign in to comment.