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

View File

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

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

View File

@ -7,7 +7,7 @@ buildscript {
mavenCentral()
}
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"
// NOTE: Do not place your application dependencies here; they belong
// 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
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
zipStorePath=wrapper/dists