Skip to content

Commit

Permalink
Merge pull request #176 from KieronQuinn/release/2.2.2
Browse files Browse the repository at this point in the history
release/2.2.2
  • Loading branch information
KieronQuinn committed Apr 20, 2023
2 parents 73060d0 + a7da2d1 commit a500e59
Show file tree
Hide file tree
Showing 10 changed files with 66 additions and 35 deletions.
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ apply plugin: 'com.google.android.gms.oss-licenses-plugin'
String DEFAULT_MANIFEST = "247:https://storage.googleapis.com/music-iq-db/updatable_ytm_db/20230402-030031/manifest.json"
String DEFAULT_MANIFEST_V3 = "3048:https://storage.googleapis.com/music-iq-db/updatable_db_v3/20230402-030031/manifest.json"

def tagName = '2.2.1'
def version = 221
def tagName = '2.2.2'
def version = 222

def getKeystoreProperties() {
def properties = new Properties()
Expand Down
4 changes: 2 additions & 2 deletions app/release/output-metadata.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
"type": "SINGLE",
"filters": [],
"attributes": [],
"versionCode": 221,
"versionName": "2.2.1",
"versionCode": 222,
"versionName": "2.2.2",
"outputFile": "app-release.apk"
}
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,19 @@ sealed class Player(
private const val PREFIX_YOUTUBE_MUSIC = "https://music.youtube.com"
private const val PREFIX_APPLE_MUSIC = "https://music.apple.com"
private const val PREFIX_DEEZER = "https://www.deezer.com"
private const val PREFIX_GOOGLE = "/g/"

fun getPlayers(
context: Context,
urls: Array<String>,
googleId: String?
googleId: String?,
trackName: String,
artist: String
): List<Player> {
val players = ArrayList<Player>()
val packageManager = context.packageManager
if(googleId != null && packageManager.isAppInstalled(PACKAGE_NAME_GSB)){
players.add(Assistant(googleId))
if(googleId?.isValid() == true && packageManager.isAppInstalled(PACKAGE_NAME_GSB)){
players.add(Assistant(googleId, trackName, artist))
}
urls.forEach {
getPlayerForUrl(it)?.let { player ->
Expand All @@ -56,6 +59,13 @@ sealed class Player(
else -> null
}
}

/**
* /m/ URLs are no longer valid for Assistant, so Chips should not be shown for them
*/
private fun String.isValid(): Boolean {
return startsWith(PREFIX_GOOGLE)
}
}

open fun getIntent(): Intent {
Expand All @@ -64,7 +74,11 @@ sealed class Player(
}
}

data class Assistant(override val url: String): Player(
data class Assistant(
override val url: String,
val trackName: String,
val artist: String
): Player(
url,
R.drawable.ic_chip_player_assistant,
R.string.recognition_chip_assistant,
Expand All @@ -76,6 +90,8 @@ sealed class Player(
override fun getIntent(): Intent {
return Intent("com.google.android.googlequicksearchbox.MUSIC_SEARCH").apply {
putExtra("android.soundsearch.extra.RECOGNIZED_TRACK_MID", url)
putExtra("android.soundsearch.extra.RECOGNIZED_TITLE", trackName)
putExtra("android.soundsearch.extra.RECOGNIZED_ARTIST", artist)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import android.net.Uri
import com.kieronquinn.app.ambientmusicmod.model.database.ShardTrackCacheDatabase
import com.kieronquinn.app.ambientmusicmod.model.shards.ShardTrack
import com.kieronquinn.app.ambientmusicmod.repositories.ShardsListRepository.GetState
import com.kieronquinn.app.ambientmusicmod.repositories.ShardsRepository.ShardCountry.Companion.CORE_SHARED_FILENAME
import com.kieronquinn.app.ambientmusicmod.utils.extensions.contentReceiverAsFlow
import com.kieronquinn.app.ambientmusicmod.utils.extensions.isArmv7
import com.kieronquinn.app.ambientmusicmod.utils.extensions.map
Expand Down Expand Up @@ -259,7 +260,7 @@ class ShardsListRepositoryImpl(
private fun List<List<ShardTrack>>.merge(): List<ShardTrack> {
//Merge the lists, then group by the shared ID and create the best track, then filter
return flatten().groupBy {
it.dbId
"${it.trackName}:${it.artist}"
}.map {
it.value.createBest()
}.distinctBy {
Expand All @@ -268,17 +269,19 @@ class ShardsListRepositoryImpl(
}

private fun List<ShardTrack>.createBest(): ShardTrack {
val preferred = firstOrNull { it.database != CORE_SHARED_FILENAME } ?: first()
val linear = firstOrNull { it.isLinear }
return ShardTrack(
first().dbId,
first().id,
first().trackName,
first().artist,
first().googleId,
firstOrNull { it.playerUrls.isNotEmpty() }?.playerUrls ?: emptyArray(),
firstOrNull { it.album != null }?.album,
firstOrNull { it.year != null }?.year,
linear?.dbId ?: preferred.dbId,
preferred.id,
preferred.trackName,
preferred.artist,
preferred.googleId,
map { it.playerUrls.toList() }.flatten().distinct().toTypedArray(),
preferred.album,
preferred.year,
any { it.isLinear },
first().database
preferred.database
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,7 @@ class UpdatesRepositoryImpl(
}

private val packageManager = context.packageManager

private val updatesCacheDir = File(context.cacheDir, "updates").apply {
mkdirs()
}

private val updatesCacheDir = File(context.cacheDir, "updates")
private val pamProvider = GitHubProvider.getGitHubProvider("NowPlaying")
private val ammProvider = GitHubProvider.getGitHubProvider("AmbientMusicMod")

Expand Down Expand Up @@ -192,6 +188,7 @@ class UpdatesRepositoryImpl(
}

private fun getUpdateCache(repository: String): GitHubRelease? {
updatesCacheDir.mkdirs()
val file = File(updatesCacheDir, "${repository}_${BuildConfig.VERSION_CODE}")
if(!file.exists()) return null
val cachedRelease = try {
Expand All @@ -207,6 +204,7 @@ class UpdatesRepositoryImpl(
}

private fun GitHubRelease.cacheRelease(repository: String) {
updatesCacheDir.mkdirs()
val file = File(updatesCacheDir, "${repository}_${BuildConfig.VERSION_CODE}")
val cachedRelease = gson.toJson(CachedGitHubRelease(System.currentTimeMillis(), this))
file.writeText(cachedRelease)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -533,7 +533,9 @@ class AmbientMusicModForegroundService: LifecycleService() {
when(settings.lockscreenOverlayClicked.get()) {
LockscreenOnTrackClicked.ASSISTANT -> {
val intent = Player.Assistant(
state.recognitionResult.googleId ?: return@whenCreated
state.recognitionResult.googleId ?: return@whenCreated,
state.recognitionResult.trackName,
state.recognitionResult.artist
).getIntent().apply {
addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -281,11 +281,8 @@ class ShizukuService: IShellProxy.Stub() {
if(context.isOnDemandConfigValueSet()) {
beginStreamingSearchViaSystem(request, callback)
}else{
if(!isRoot){
callback.onRecognitionFailed(request, MusicRecognitionManager_RECOGNITION_FAILED_NEEDS_ROOT)
}else{
beginStreamingSearchViaRoot(request, callback, thread, token)
}
//Assume root is available as UI checks, if not a genuine service error will be shown
beginStreamingSearchViaRoot(request, callback, thread, token)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import com.kieronquinn.app.ambientmusicmod.utils.extensions.takeUriPermission
import com.kieronquinn.app.ambientmusicmod.utils.extensions.whenResumed
import com.kieronquinn.app.ambientmusicmod.work.PeriodicBackupWorker
import org.koin.androidx.viewmodel.ext.android.viewModel
import java.net.URLDecoder
import java.time.Instant
import java.util.Date

Expand Down Expand Up @@ -136,7 +137,9 @@ class BackupRestoreFragment: BaseSettingsFragment(), BackAvailable {

private fun String.getKnownPathOrNull(): String? {
return if(contains("%3A")){
substring(lastIndexOf("%3A") + 3).replace("%2F", "/")
substring(lastIndexOf("%3A") + 3).let {
URLDecoder.decode(it, "UTF-8")
}
}else null
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -387,10 +387,13 @@ class RecognitionFragment: BoundDialogFragment<FragmentRecognitionBinding>(Fragm
}
when(state.result){
is RecogniseResult.Success -> {
val result = state.result.recognitionResult
val players = Player.getPlayers(
requireContext(),
state.result.recognitionResult.players,
state.result.recognitionResult.googleId
result.players,
result.googleId,
result.trackName,
result.artist
)
prepSuccess(state.result, players)
}
Expand All @@ -409,10 +412,13 @@ class RecognitionFragment: BoundDialogFragment<FragmentRecognitionBinding>(Fragm
delay(750L)
val newState = when(state.result){
is RecogniseResult.Success -> {
val result = state.result.recognitionResult
val players = Player.getPlayers(
requireContext(),
state.result.recognitionResult.players,
state.result.recognitionResult.googleId
result.players,
result.googleId,
result.trackName,
result.artist
)
State.Success(R.id.recognising_icon_to_success, state.result, players)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,13 @@ class TrackInfoBottomSheetFragment: BaseBottomSheetFragment<FragmentTrackInfoBot
}

private val players by lazy {
Player.getPlayers(requireContext(), track.playerUrls, track.googleId)
Player.getPlayers(
requireContext(),
track.playerUrls,
track.googleId,
track.trackName,
track.artist
)
}

private val adapter by lazy {
Expand Down

0 comments on commit a500e59

Please sign in to comment.