Prepare release: fix media player and splashscreen bug

This commit is contained in:
Ivan Agosto 2025-01-24 17:41:32 -06:00
parent 4de1408ba6
commit a1deaa844c
6 changed files with 58 additions and 35 deletions

View File

@ -1,4 +1,3 @@
plugins { plugins {
id "com.android.application" id "com.android.application"
id "kotlin-android" id "kotlin-android"
@ -7,11 +6,11 @@ plugins {
android { android {
defaultConfig { defaultConfig {
applicationId "org.libre.agosto.p2play" applicationId "org.libre.agosto.p2play"
compileSdk 34 compileSdk 35
minSdkVersion 26 minSdkVersion 26
targetSdkVersion 32 targetSdkVersion 32
versionCode 12 versionCode 13
versionName "0.8.1" versionName "0.8.2"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
vectorDrawables.useSupportLibrary = true vectorDrawables.useSupportLibrary = true
} }
@ -25,14 +24,17 @@ android {
viewBinding = true viewBinding = true
} }
compileOptions { compileOptions {
sourceCompatibility JavaVersion.VERSION_17 sourceCompatibility JavaVersion.VERSION_18
targetCompatibility JavaVersion.VERSION_17 targetCompatibility JavaVersion.VERSION_18
} }
namespace 'org.libre.agosto.p2play' namespace 'org.libre.agosto.p2play'
lint { lint {
abortOnError false abortOnError false
checkReleaseBuilds false checkReleaseBuilds false
} }
kotlinOptions {
jvmTarget = '18'
}
} }
dependencies { dependencies {

View File

@ -10,6 +10,8 @@ import android.util.Log
import androidx.appcompat.app.AppCompatActivity import androidx.appcompat.app.AppCompatActivity
import androidx.preference.PreferenceManager import androidx.preference.PreferenceManager
import org.libre.agosto.p2play.ajax.Auth import org.libre.agosto.p2play.ajax.Auth
import org.libre.agosto.p2play.helpers.TaskManager
import org.libre.agosto.p2play.models.TokenModel
import java.lang.Exception import java.lang.Exception
class SplashActivity : AppCompatActivity() { class SplashActivity : AppCompatActivity() {
@ -31,17 +33,15 @@ class SplashActivity : AppCompatActivity() {
val lastHost = settings.getString("last_host", "") val lastHost = settings.getString("last_host", "")
if (host != "") { if (host != "") {
if (lastHost != host) { if (lastHost != host) {
Handler().postDelayed({ Thread.sleep(2000)
startHostActivity() startHostActivity()
}, 2000)
} else { } else {
ManagerSingleton.url = host ManagerSingleton.url = host
checkUser() checkUser()
} }
} else { } else {
Handler().postDelayed({ Thread.sleep(2000)
startHostActivity() startHostActivity()
}, 2000)
} }
} }
@ -50,36 +50,31 @@ class SplashActivity : AppCompatActivity() {
try { try {
val token = db.getToken() val token = db.getToken()
val user = db.getUser() val user = db.getUser()
AsyncTask.execute {
if (Looper.myLooper() == null) {
Looper.prepare()
}
if (token.status == 1 && user.status == 1) { if (token.status == 1 && user.status == 1) {
val clientId = settings.getString("client_id", "")!! val clientId = settings.getString("client_id", "")!!
val clientSecret = settings.getString("client_secret", "")!! val clientSecret = settings.getString("client_secret", "")!!
val task = TaskManager<TokenModel>()
val newToken = client.refreshToken(token, clientId, clientSecret)
task.runTask({client.refreshToken(token, clientId, clientSecret)}, {
when (token.status.toString()) { when (token.status.toString()) {
"1" -> { "1" -> {
db.newToken(newToken) db.newToken(it)
ManagerSingleton.token = newToken ManagerSingleton.token = it
ManagerSingleton.user = user ManagerSingleton.user = user
} }
else -> ManagerSingleton.logout() else -> ManagerSingleton.logout()
} }
} else { })
ManagerSingleton.logout() } else {
} ManagerSingleton.logout()
startApp()
} }
startApp()
} catch (err: Exception) { } catch (err: Exception) {
err.printStackTrace() err.printStackTrace()
Handler().postDelayed({ Thread.sleep(2000)
startApp() startHostActivity()
}, 2000)
} }
} }

View File

@ -0,0 +1,22 @@
package org.libre.agosto.p2play.helpers
import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
class TaskManager<T> : ViewModel() {
val result = MutableLiveData<T>()
fun runTask(task: () -> T, callback: (T) -> Unit) {
viewModelScope.launch {
val data = withContext(Dispatchers.IO) {
task()
}
result.postValue(data)
callback(data)
}
}
}

View File

@ -2,6 +2,8 @@ package org.libre.agosto.p2play.services
import android.app.PendingIntent import android.app.PendingIntent
import android.content.Intent import android.content.Intent
import androidx.annotation.OptIn
import androidx.media3.common.util.UnstableApi
import androidx.media3.session.MediaSession import androidx.media3.session.MediaSession
import androidx.media3.session.MediaSessionService import androidx.media3.session.MediaSessionService
import org.libre.agosto.p2play.ReproductorActivity import org.libre.agosto.p2play.ReproductorActivity
@ -11,6 +13,7 @@ class PlaybackService : MediaSessionService() {
private var mediaSession: MediaSession? = null private var mediaSession: MediaSession? = null
// Create your Player and MediaSession in the onCreate lifecycle event // Create your Player and MediaSession in the onCreate lifecycle event
@OptIn(UnstableApi::class)
override fun onCreate() { override fun onCreate() {
super.onCreate() super.onCreate()
val player = PlaybackSingleton.player!! val player = PlaybackSingleton.player!!
@ -24,7 +27,8 @@ class PlaybackService : MediaSessionService() {
contentIntent, contentIntent,
PendingIntent.FLAG_MUTABLE, PendingIntent.FLAG_MUTABLE,
) )
mediaSession!!.setSessionActivity(pendingIntent)
mediaSession?.setSessionActivity(pendingIntent)
} }
// Remember to release the player and media session in onDestroy // Remember to release the player and media session in onDestroy

View File

@ -7,7 +7,7 @@ buildscript {
mavenCentral() mavenCentral()
} }
dependencies { dependencies {
classpath 'com.android.tools.build:gradle:8.3.2' classpath 'com.android.tools.build:gradle:8.8.0'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
// NOTE: Do not place your application dependencies here; they belong // NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files // in the individual module build.gradle files

View File

@ -1,6 +1,6 @@
#Mon Mar 18 13:17:32 CST 2024 #Fri Jan 24 15:00:50 CST 2025
distributionBase=GRADLE_USER_HOME distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.4-bin.zip distributionUrl=https\://services.gradle.org/distributions/gradle-8.10.2-bin.zip
zipStoreBase=GRADLE_USER_HOME zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists zipStorePath=wrapper/dists