Skip to content

Commit

Permalink
Temporary fix, release a hotfix and wait for the major fix
Browse files Browse the repository at this point in the history
  • Loading branch information
maxrave-dev committed Dec 22, 2024
1 parent c77f927 commit 9b08c4c
Show file tree
Hide file tree
Showing 37 changed files with 309 additions and 354 deletions.
7 changes: 3 additions & 4 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ android {
applicationId = "com.maxrave.simpmusic"
minSdk = 26
targetSdk = 35
versionCode = 21
versionName = "0.2.4"
versionCode = 22
versionName = "0.2.5"
vectorDrawables.useSupportLibrary = true

ksp {
Expand Down Expand Up @@ -225,6 +225,7 @@ dependencies {
implementation(libs.media3.exoplayer.smoothstreaming)
implementation(libs.media3.exoplayer.workmanager)
implementation(libs.media3.datasource.okhttp)
implementation(libs.okhttp3.logging.interceptor)

// Palette Color
implementation(libs.palette.ktx)
Expand Down Expand Up @@ -307,8 +308,6 @@ dependencies {
implementation(libs.koin.android)
implementation(libs.koin.workmanager)
implementation(libs.koin.androidx.compose)
implementation(libs.koin.annotations)
ksp(libs.koin.ksp)

// Store5
implementation(libs.store)
Expand Down
35 changes: 24 additions & 11 deletions app/src/main/java/com/maxrave/simpmusic/common/Config.kt
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ object SUPPORTED_LANGUAGE {
"Azerbaijani",
"हिन्दी",
"ภาษาไทย",
"Nederlands"
"Nederlands",
)
val codes: Array<String> =
arrayOf(
Expand All @@ -219,8 +219,9 @@ object SUPPORTED_LANGUAGE {
"az-AZ",
"hi-IN",
"th-TH",
"nl-NL"
"nl-NL",
)

fun getLanguageFromCode(code: String?): String {
val index = codes.indexOf(code)
Log.d("Config", "getLanguageFromCode: $index")
Expand All @@ -230,6 +231,7 @@ object SUPPORTED_LANGUAGE {
Log.w("Config", "getLanguageFromCode: ${items.get(index)}")
return (items.getOrNull(index) ?: "English").toString()
}

fun getCodeFromLanguage(language: String?): String {
val index = items.indexOf(language ?: "English")
Log.d("Config", "getCodeFromLanguage: $index")
Expand Down Expand Up @@ -263,6 +265,7 @@ object LIMIT_CACHE_SIZE {
val index = items.indexOf(item)
return data.getOrNull(index) ?: -1
}

fun getItemFromData(input: Int?): CharSequence {
val index = data.indexOf(input)
return items.getOrNull(index) ?: ""
Expand All @@ -284,22 +287,32 @@ object SPONSOR_BLOCK {
R.string.poi_highlight,
R.string.filter,
)
fun fromDbToName(context: Context, list: List<CharSequence>): List<String> {

fun fromDbToName(
context: Context,
list: List<CharSequence>,
): List<String> {
val result = mutableListOf<String>()
for (item in list) {
val index = list.indexOf(item)
result.add(context.getString(listName[index]))
}
return result
}
fun fromNameToDb(context: Context, input: List<String>): List<CharSequence> {

fun fromNameToDb(
context: Context,
input: List<String>,
): List<CharSequence> {
val allString = fromDbToName(context, list.toList())
val listIndex = allString.map {
allString.indexOf(it)
}
val result = listIndex.mapNotNull {
list.getOrNull(it)
}
val listIndex =
allString.map {
allString.indexOf(it)
}
val result =
listIndex.mapNotNull {
list.getOrNull(it)
}
return result
}
}
Expand Down Expand Up @@ -464,4 +477,4 @@ const val LOCAL_PLAYLIST_ID_DOWNLOADED = "LOCAL_PLAYLIST_ID_DOWNLOADED"
const val LOCAL_PLAYLIST_ID_LIKED = "LOCAL_PLAYLIST_ID_LIKED"
const val LOCAL_PLAYLIST_ID = "LOCAL_PLAYLIST_ID"
const val ASC = "ASC"
const val DESC = "DESC"
const val DESC = "DESC"
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ import kotlinx.coroutines.delay
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.collectLatest
import kotlinx.coroutines.flow.combine
import kotlinx.coroutines.flow.distinctUntilChanged
import kotlinx.coroutines.flow.first
import kotlinx.coroutines.flow.firstOrNull
import kotlinx.coroutines.flow.flow
Expand Down Expand Up @@ -153,47 +154,53 @@ class MainRepository(
}
youTube.cachePath = File(context.cacheDir, "http-cache")
scope.launch {
val localeJob = launch {
combine(dataStoreManager.location, dataStoreManager.language) { location, language ->
Pair(location, language)
}.collectLatest { (location, language) ->
youTube.locale = YouTubeLocale(location, language.substring(0..1))
val localeJob =
launch {
combine(dataStoreManager.location, dataStoreManager.language) { location, language ->
Pair(location, language)
}.collectLatest { (location, language) ->
youTube.locale = YouTubeLocale(location, language.substring(0..1))
}
}
}
val ytCookieJob = launch {
dataStoreManager.cookie.collectLatest { cookie ->
if (cookie.isNotEmpty()) {
youTube.cookie = cookie
} else {
youTube.cookie = null
val ytCookieJob =
launch {
dataStoreManager.cookie.distinctUntilChanged().collectLatest { cookie ->
if (cookie.isNotEmpty()) {
youTube.cookie = cookie
} else {
youTube.cookie = null
}
}
}
}
val musixmatchCookieJob = launch {
dataStoreManager.musixmatchCookie.collectLatest { cookie ->
youTube.musixMatchCookie = cookie
val musixmatchCookieJob =
launch {
dataStoreManager.musixmatchCookie.collectLatest { cookie ->
youTube.musixMatchCookie = cookie
}
}
}
val usingProxy = launch {
combine(dataStoreManager.usingProxy,
dataStoreManager.proxyType,
dataStoreManager.proxyHost,
dataStoreManager.proxyPort) { usingProxy, proxyType, proxyHost, proxyPort ->
Pair(usingProxy == DataStoreManager.TRUE, Triple(proxyType, proxyHost, proxyPort))
}.collectLatest { (usingProxy, data) ->
if (usingProxy) {
withContext(Dispatchers.IO) {
youTube.setProxy(
data.first == DataStoreManager.Settings.ProxyType.PROXY_TYPE_HTTP,
data.second,
data.third
)
val usingProxy =
launch {
combine(
dataStoreManager.usingProxy,
dataStoreManager.proxyType,
dataStoreManager.proxyHost,
dataStoreManager.proxyPort,
) { usingProxy, proxyType, proxyHost, proxyPort ->
Pair(usingProxy == DataStoreManager.TRUE, Triple(proxyType, proxyHost, proxyPort))
}.collectLatest { (usingProxy, data) ->
if (usingProxy) {
withContext(Dispatchers.IO) {
youTube.setProxy(
data.first == DataStoreManager.Settings.ProxyType.PROXY_TYPE_HTTP,
data.second,
data.third,
)
}
} else {
youTube.removeProxy()
}
} else {
youTube.removeProxy()
}
}
}

localeJob.join()
ytCookieJob.join()
Expand All @@ -203,8 +210,9 @@ class MainRepository(
}

fun getMusixmatchCookie() = youTube.getMusixmatchCookie()

fun getYouTubeCookie() = youTube.cookie

// Database
fun closeDatabase() {
if (database.isOpen) {
Expand Down Expand Up @@ -2864,7 +2872,7 @@ class MainRepository(
}
}
if (format == null) {
format = response.streamingData?.adaptiveFormats?.lastOrNull()
format = response.streamingData?.adaptiveFormats?.lastOrNull() ?: response.streamingData?.formats?.lastOrNull()
}
Log.w("Stream", "format: $format")
Log.d("Stream", "expireInSeconds ${response.streamingData?.expiresInSeconds}")
Expand Down
12 changes: 11 additions & 1 deletion app/src/main/java/com/maxrave/simpmusic/di/MediaServiceModule.kt
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ import kotlinx.coroutines.flow.singleOrNull
import kotlinx.coroutines.launch
import kotlinx.coroutines.runBlocking
import okhttp3.OkHttpClient
import okhttp3.logging.HttpLoggingInterceptor
import org.koin.android.ext.koin.androidContext
import org.koin.core.qualifier.named
import org.koin.dsl.module
Expand Down Expand Up @@ -221,6 +222,8 @@ private fun provideResolvingDataSourceFactory(
true,
).singleOrNull()
?.let {
Log.d("Stream", it)
Log.w("Stream", "Video")
dataSpecReturn = dataSpec.withUri(it.toUri()).subrange(dataSpec.uriPositionOffset, CHUNK_LENGTH)
}
} else {
Expand All @@ -230,6 +233,8 @@ private fun provideResolvingDataSourceFactory(
isVideo = false,
).singleOrNull()
?.let {
Log.d("Stream", it)
Log.w("Stream", "Audio")
dataSpecReturn = dataSpec.withUri(it.toUri()).subrange(dataSpec.uriPositionOffset, CHUNK_LENGTH)
}
}
Expand Down Expand Up @@ -346,7 +351,12 @@ private fun provideCacheDataSource(
OkHttpDataSource.Factory(
OkHttpClient
.Builder()
.build(),
.addInterceptor(
HttpLoggingInterceptor()
.apply {
level = HttpLoggingInterceptor.Level.HEADERS
},
).build(),
),
),
),
Expand Down
34 changes: 22 additions & 12 deletions app/src/main/java/com/maxrave/simpmusic/extension/UIExt.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import android.content.ContextWrapper
import android.graphics.Point
import android.os.Build
import android.util.Log
import android.util.Rational
import android.view.WindowManager
import androidx.activity.ComponentActivity
import androidx.annotation.ColorInt
Expand Down Expand Up @@ -45,12 +46,15 @@ import androidx.compose.ui.graphics.ColorMatrix
import androidx.compose.ui.graphics.Paint
import androidx.compose.ui.graphics.drawscope.ContentDrawScope
import androidx.compose.ui.graphics.drawscope.drawIntoCanvas
import androidx.compose.ui.graphics.toAndroidRectF
import androidx.compose.ui.layout.boundsInWindow
import androidx.compose.ui.layout.onGloballyPositioned
import androidx.compose.ui.platform.LocalConfiguration
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.platform.LocalDensity
import androidx.compose.ui.unit.IntSize
import androidx.core.graphics.ColorUtils
import androidx.core.graphics.toRect
import com.kmpalette.palette.graphics.Palette
import com.maxrave.simpmusic.ui.theme.md_theme_dark_background
import com.maxrave.simpmusic.ui.theme.shimmerBackground
Expand Down Expand Up @@ -492,15 +496,16 @@ fun PipListenerPreAPI12() {
val context = LocalContext.current
DisposableEffect(context) {
val onUserLeaveBehavior: () -> Unit = {
context.findActivity()
context
.findActivity()
.enterPictureInPictureMode(PictureInPictureParams.Builder().build())
}
context.findActivity().addOnUserLeaveHintListener(
onUserLeaveBehavior
onUserLeaveBehavior,
)
onDispose {
context.findActivity().removeOnUserLeaveHintListener(
onUserLeaveBehavior
onUserLeaveBehavior,
)
}
}
Expand All @@ -513,20 +518,25 @@ fun PipListenerPreAPI12() {
/**
* Android 12 and above Picture in Picture mode
*/
fun Modifier.pipModifier(context: Context) = this.onGloballyPositioned { layoutCoordinates ->
val builder = PictureInPictureParams.Builder()

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
builder.setAutoEnterEnabled(true)
fun Modifier.pipModifier(context: Context) =
this.onGloballyPositioned { layoutCoordinates ->
val builder = PictureInPictureParams.Builder()
val sourceRect = layoutCoordinates.boundsInWindow().toAndroidRectF().toRect()
builder.setSourceRectHint(sourceRect)
builder.setAspectRatio(
Rational(16, 9),
)
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
builder.setAutoEnterEnabled(true)
}
Log.w("PiP info", "layoutCoordinates: $layoutCoordinates")
context.findActivity().setPictureInPictureParams(builder.build())
}
Log.w("PiP info", "layoutCoordinates: $layoutCoordinates")
context.findActivity().setPictureInPictureParams(builder.build())
}

@RequiresOptIn(
level = RequiresOptIn.Level.WARNING,
message = "This will be migrate to Compose. I use this to mark which fragment need to be migrate to Compose",
)
@Retention(AnnotationRetention.BINARY)
@Target(AnnotationTarget.CLASS, AnnotationTarget.FUNCTION)
annotation class IntermediaryMigrateApi
annotation class IntermediaryMigrateApi
5 changes: 1 addition & 4 deletions app/src/main/java/com/maxrave/simpmusic/ui/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,11 @@ package com.maxrave.simpmusic.ui

import android.Manifest
import android.content.ComponentName
import android.content.Context
import android.content.Intent
import android.content.ServiceConnection
import android.content.res.Configuration
import android.graphics.Rect
import android.graphics.drawable.ColorDrawable
import android.net.ConnectivityManager
import android.net.NetworkCapabilities
import android.net.Uri
import android.os.Build
import android.os.Bundle
Expand Down Expand Up @@ -688,7 +685,7 @@ class MainActivity : AppCompatActivity() {
private fun checkForUpdate() {
viewModel.checkForUpdate()
viewModel.githubResponse.observe(this) { response ->
if (response != null) {
if (response != null && !this.isInPictureInPictureMode) {
if (response.tagName != getString(R.string.version_name)) {
val inputFormat =
SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'", Locale.getDefault())
Expand Down
Loading

0 comments on commit 9b08c4c

Please sign in to comment.