Skip to content

Commit

Permalink
bug fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
mkaflowski committed Jun 18, 2024
1 parent b981691 commit 63c3d49
Show file tree
Hide file tree
Showing 9 changed files with 48 additions and 9 deletions.
1 change: 0 additions & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
<uses-permission android:name="android.permission.FOREGROUND_SERVICE_MEDIA_PLAYBACK" />
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
<uses-permission android:name="android.permission.FOREGROUND_SERVICE_DATA_SYNC" />

<uses-feature android:name="android.hardware.type.watch" />

<application
Expand Down
6 changes: 3 additions & 3 deletions app/src/main/java/kaf/audiobookshelfwearos/app/ApiHandler.kt
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import kaf.audiobookshelfwearos.app.data.UserMediaProgress
import kaf.audiobookshelfwearos.app.userdata.UserDataManager
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.delay
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
import okhttp3.MediaType.Companion.toMediaTypeOrNull
Expand All @@ -29,7 +30,7 @@ import java.util.concurrent.TimeUnit


class ApiHandler(private val context: Context) {
private val timeout: Long = if (BuildConfig.DEBUG) 1 else 10
private val timeout: Long = if (BuildConfig.DEBUG) 3 else 7
private var client = OkHttpClient.Builder().connectTimeout(timeout, TimeUnit.SECONDS)
.readTimeout(timeout, TimeUnit.SECONDS).writeTimeout(timeout, TimeUnit.SECONDS).build()

Expand Down Expand Up @@ -84,7 +85,6 @@ class ApiHandler(private val context: Context) {
suspend fun getItem(id: String): LibraryItem? {
return withContext(Dispatchers.IO) {
val request = getRequest("/api/items/$id?expanded=1&include=progress")

try {
client.newCall(request).execute().use { response ->
if (!response.isSuccessful) {
Expand Down Expand Up @@ -233,7 +233,7 @@ class ApiHandler(private val context: Context) {
showToast("Connection problem")
return@withContext User()
}
}catch (e : Exception){
} catch (e: Exception) {
e.printStackTrace()
e.message?.let { showToast(it) }
return@withContext User()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import androidx.compose.ui.layout.onGloballyPositioned
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import androidx.wear.compose.foundation.lazy.ScalingLazyColumn
import androidx.wear.compose.foundation.lazy.ScalingLazyColumnDefaults
import androidx.wear.compose.foundation.lazy.itemsIndexed
Expand Down Expand Up @@ -193,6 +194,14 @@ class BookListActivity : ComponentActivity() {
.padding(start = 10.dp, end = 10.dp)
.fillMaxWidth()
)
Text(
text = item.author,
fontSize = 10.sp,
textAlign = TextAlign.Center,
modifier = Modifier
.padding(start = 10.dp, end = 10.dp)
.fillMaxWidth()
)
Spacer(modifier = Modifier.height(10.dp))
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ class ChapterListActivity : ComponentActivity() {

LaunchedEffect(isDownloading) {
while (isDownloading) {
delay(1000L)
// delay(1000L)
isDownloading = libraryItem.media.tracks.any { track ->
track.isDownloading(this@ChapterListActivity)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
package kaf.audiobookshelfwearos.app.activities

import android.content.Context
import android.content.Intent
import android.net.ConnectivityManager
import android.net.NetworkCapabilities
import android.os.Build
import android.os.Bundle
import android.text.Editable
import android.text.TextWatcher
Expand Down Expand Up @@ -90,10 +94,28 @@ class LoginActivity : ComponentActivity() {

loginButton.setOnClickListener {
Timber.d("Login clicked")
if(userDataManager.token.isNotEmpty() && !isInternetAvailable()){
startActivity(Intent(this, BookListActivity::class.java))
startActivity(intent)
}

viewModel.login()
}
}

private fun isInternetAvailable(): Boolean {
val connectivityManager = getSystemService(Context.CONNECTIVITY_SERVICE) as ConnectivityManager
val network = connectivityManager.activeNetwork ?: return false
val actNw = connectivityManager.getNetworkCapabilities(network) ?: return false
Timber.d(""+actNw.transportInfo)
return when {
actNw.hasTransport(NetworkCapabilities.TRANSPORT_WIFI) -> true
actNw.hasTransport(NetworkCapabilities.TRANSPORT_CELLULAR) -> false
actNw.hasTransport(NetworkCapabilities.TRANSPORT_ETHERNET) -> true
else -> false
}
}

private fun setSavedValues() {
userDataManager.apply {
protocol.takeIf { it.isNotEmpty() }?.let { this@LoginActivity.protocol.setText(it) }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,6 @@ class PlayerActivity : ComponentActivity() {

}


@Preview(showBackground = true, widthDp = 250, heightDp = 250)
@Composable
fun PlaybackControlsPreview() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,9 @@ data class LibraryItem(
set(value) {
media.metadata.title = value
}
var author: String
get() = media.metadata.authorName
set(value) {
media.metadata.authorName = value
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ data class Metadata(
var title: String = "",
val titleIgnorePrefix: String? = "",
val subtitle: String? = "",
val authorName: String = "",
var authorName: String = "",
val narratorName: String? = "",
val seriesName: String? = "",
val genres: List<String> = emptyList(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ class PlayerService : MediaSessionService() {
super.onMediaItemTransition(mediaItem, reason)
updateUIMetadata()
}

override fun onMediaMetadataChanged(mediaMetadata: MediaMetadata) {
super.onMediaMetadataChanged(mediaMetadata)
Timber.d("mediaMetadata - " + mediaMetadata.trackNumber)
Expand All @@ -89,7 +90,11 @@ class PlayerService : MediaSessionService() {
Player.STATE_BUFFERING -> Timber
.d("ExoPlayer is buffering")

Player.STATE_READY -> Timber.d("ExoPlayer is ready")
Player.STATE_READY -> {
Timber.d("ExoPlayer is ready " + exoPlayer.currentPosition)
updateUIMetadata()
}

Player.STATE_ENDED -> {
Timber.d("ExoPlayer has ended")
sendBroadcast(Intent("$packageName.ACTION_TRACK_ENDED"))
Expand Down Expand Up @@ -139,7 +144,7 @@ class PlayerService : MediaSessionService() {
}

fun updateUIMetadata() {
val timeInS = getCurrentTotalPositionInS()
val timeInS = getCurrentTotalPositionInS() + START_OFFSET_SECONDS + 1

var currentChapter = Chapter()
for (chapter in audiobook.media.chapters) {
Expand Down

0 comments on commit 63c3d49

Please sign in to comment.