Skip to content

Commit

Permalink
Fix media3 audio player bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
ismartcoding committed Feb 3, 2024
1 parent 9e163a9 commit 2865bbf
Show file tree
Hide file tree
Showing 103 changed files with 361 additions and 233 deletions.
8 changes: 3 additions & 5 deletions app/src/main/java/com/ismartcoding/plain/data/UIDataCache.kt
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.ismartcoding.plain.data

import com.ismartcoding.lib.helpers.JsonHelper
import com.ismartcoding.lib.helpers.JsonHelper.jsonDecode
import com.ismartcoding.plain.InitQuery
import com.ismartcoding.plain.NetworkQuery
import com.ismartcoding.plain.TempData
Expand Down Expand Up @@ -49,12 +51,8 @@ class UIDataCache {
configs = data.configs.map { it.configFragment }.toMutableList()
rules = configs?.filter { it.group == ConfigType.RULE.value }?.map { it.toRule() }?.toMutableList()
routes = configs?.filter { it.group == ConfigType.ROUTE.value }?.map { it.toRoute() }?.toMutableList()
val json =
Json {
ignoreUnknownKeys = true
}
configs?.find { it.group == ConfigType.SYSTEM.value }?.let {
systemConfig = json.decodeFromString(it.value)
systemConfig = jsonDecode(it.value)
}
wireGuards = data.wireGuards.map { it.wireGuardFragment.toWireGuard() }.toMutableList()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import androidx.datastore.preferences.core.stringPreferencesKey
import androidx.datastore.preferences.core.stringSetPreferencesKey
import com.ismartcoding.lib.helpers.CoroutinesHelper.coMain
import com.ismartcoding.lib.helpers.CryptoHelper
import com.ismartcoding.lib.helpers.JsonHelper.jsonDecode
import com.ismartcoding.lib.helpers.JsonHelper.jsonEncode
import com.ismartcoding.lib.helpers.StringHelper
import com.ismartcoding.plain.TempData
Expand Down Expand Up @@ -228,7 +229,7 @@ object ExchangeRatePreference : BasePreference<String>() {
if (str.isEmpty()) {
return ExchangeConfig()
}
return Json.decodeFromString(str)
return jsonDecode(str)
}

suspend fun putAsync(
Expand Down Expand Up @@ -298,9 +299,6 @@ object AudioPlayModePreference : BasePreference<Int>() {
) {
putAsync(context, value.ordinal)
TempData.audioPlayMode = value
coMain {
AudioPlayer.setRepeatMode()
}
}

suspend fun getValueAsync(context: Context): MediaPlayMode {
Expand Down Expand Up @@ -451,7 +449,7 @@ object ScanHistoryPreference : BasePreference<String>() {
if (str.isEmpty()) {
return listOf()
}
return Json.decodeFromString(str)
return jsonDecode(str)
}

suspend fun putAsync(
Expand All @@ -471,7 +469,7 @@ object AudioPlaylistPreference : BasePreference<String>() {
if (str.isEmpty()) {
return listOf()
}
return Json.decodeFromString(str)
return jsonDecode(str)
}

suspend fun putAsync(
Expand Down Expand Up @@ -527,7 +525,7 @@ object VideoPlaylistPreference : BasePreference<String>() {
if (str.isEmpty()) {
return listOf()
}
return Json.decodeFromString(str)
return jsonDecode(str)
}

suspend fun putAsync(
Expand Down
8 changes: 5 additions & 3 deletions app/src/main/java/com/ismartcoding/plain/db/DChat.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package com.ismartcoding.plain.db

import androidx.room.*
import com.ismartcoding.lib.helpers.JsonHelper
import com.ismartcoding.lib.helpers.JsonHelper.jsonDecode
import com.ismartcoding.lib.helpers.JsonHelper.jsonEncode
import com.ismartcoding.lib.helpers.StringHelper
import com.ismartcoding.plain.R
Expand Down Expand Up @@ -78,13 +80,13 @@ data class DChat(
val valueJson = obj.optString("value")
when (message.type) {
DMessageType.TEXT.value -> {
message.value = Json.decodeFromString<DMessageText>(valueJson)
message.value = jsonDecode<DMessageText>(valueJson)
}
DMessageType.IMAGES.value -> {
message.value = Json.decodeFromString<DMessageImages>(valueJson)
message.value = jsonDecode<DMessageImages>(valueJson)
}
DMessageType.FILES.value -> {
message.value = Json.decodeFromString<DMessageFiles>(valueJson)
message.value = jsonDecode<DMessageFiles>(valueJson)
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
package com.ismartcoding.plain.extensions

import com.ismartcoding.lib.helpers.JsonHelper
import com.ismartcoding.lib.helpers.JsonHelper.jsonDecode
import com.ismartcoding.plain.features.route.Route
import com.ismartcoding.plain.features.rule.Rule
import com.ismartcoding.plain.fragment.ConfigFragment
import kotlinx.serialization.decodeFromString
import kotlinx.serialization.json.Json

fun ConfigFragment.toRule(): Rule {
val r = Json.decodeFromString<Rule>(value)
val r = jsonDecode<Rule>(value)
r.id = id
return r
}

fun ConfigFragment.toRoute(): Route {
val r = Json.decodeFromString<Route>(value)
val r = jsonDecode<Route>(value)
r.id = id
return r
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import com.aallam.openai.client.OpenAIConfig
import com.ismartcoding.lib.channel.receiveEventHandler
import com.ismartcoding.lib.channel.sendEvent
import com.ismartcoding.lib.helpers.CoroutinesHelper.coIO
import com.ismartcoding.lib.helpers.JsonHelper.jsonEncode
import com.ismartcoding.lib.helpers.SslHelper
import com.ismartcoding.lib.logcat.LogCat
import com.ismartcoding.plain.MainApp
Expand Down Expand Up @@ -200,7 +201,7 @@ object AppEvents {
val c = completion.choices.getOrNull(0)
data.put("content", c?.delta?.content ?: "")
data.put("finishReason", c?.finishReason ?: "")
LogCat.d(Json.encodeToString(completion))
LogCat.d(jsonEncode(completion))
sendEvent(WebSocketEvent(EventType.AI_CHAT_REPLIED, data.toString()))
}
} catch (ex: Exception) {
Expand Down
20 changes: 7 additions & 13 deletions app/src/main/java/com/ismartcoding/plain/features/Permissions.kt
Original file line number Diff line number Diff line change
Expand Up @@ -228,19 +228,13 @@ enum class Permission {
}
} else if (this == SCHEDULE_EXACT_ALARM) {
if (isSPlus()) {
val permission = this.toSysPermission()
val activity = MainActivity.instance.get()!!
if (ActivityCompat.shouldShowRequestPermissionRationale(activity, permission)) {
val intent = Intent(ACTION_REQUEST_SCHEDULE_EXACT_ALARM)
if (intent.resolveActivity(packageManager) != null) {
intentLauncher?.launch(intent)
} else {
DialogHelper.showMessage(
"ActivityNotFoundException: No Activity found to handle Intent act=android.settings.ACTION_REQUEST_SCHEDULE_EXACT_ALARM",
)
}
val intent = Intent(ACTION_REQUEST_SCHEDULE_EXACT_ALARM)
if (intent.resolveActivity(packageManager) != null) {
intentLauncher?.launch(intent)
} else {
launcher?.launch(permission)
DialogHelper.showMessage(
"ActivityNotFoundException: No Activity found to handle Intent act=android.settings.ACTION_REQUEST_SCHEDULE_EXACT_ALARM",
)
}
}
} else {
Expand Down Expand Up @@ -364,7 +358,7 @@ object Permissions {

private var canContinue = false

private suspend fun ensureNotificationAsync(context: Context): Boolean {
suspend fun ensureNotificationAsync(context: Context): Boolean {
val permission = Permission.POST_NOTIFICATIONS
val ready = isNotificationPermissionReadyWithRequest(context)
if (!ready) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import com.ismartcoding.lib.content.ContentWhere
import com.ismartcoding.lib.extensions.getLongValue
import com.ismartcoding.lib.extensions.getStringValue
import com.ismartcoding.lib.helpers.FilterField
import com.ismartcoding.lib.logcat.LogCat
import com.ismartcoding.plain.data.DMediaBucket
import com.ismartcoding.plain.features.BaseContentHelper
import com.ismartcoding.plain.features.file.FileSortBy
Expand Down
Loading

0 comments on commit 2865bbf

Please sign in to comment.