mirror of
https://github.com/owenlejeune/TVTime.git
synced 2025-11-08 21:02:44 -05:00
only create guest session when trying to rate
This commit is contained in:
@@ -7,13 +7,15 @@ import retrofit2.Response
|
||||
import retrofit2.http.Body
|
||||
import retrofit2.http.DELETE
|
||||
import retrofit2.http.GET
|
||||
import retrofit2.http.HTTP
|
||||
|
||||
interface AuthenticationApi {
|
||||
|
||||
@GET("authentication/guest_session/new")
|
||||
suspend fun getNewGuestSession(): Response<GuestSessionResponse>
|
||||
|
||||
@DELETE("authentication/session")
|
||||
// @DELETE("authentication/session")
|
||||
@HTTP(method = "DELETE", path = "authentication/session", hasBody = true)
|
||||
suspend fun deleteSession(@Body body: DeleteSessionBody): Response<DeleteSessionResponse>
|
||||
|
||||
}
|
||||
@@ -296,7 +296,7 @@ private fun RateButton(
|
||||
})
|
||||
|
||||
CreateSessionDialog(showDialog = showSessionDialog, onSessionReturned = {
|
||||
|
||||
showRatingDialog.value = it
|
||||
})
|
||||
}
|
||||
|
||||
@@ -306,19 +306,46 @@ private fun CreateSessionDialog(showDialog: MutableState<Boolean>, onSessionRetu
|
||||
AlertDialog(
|
||||
modifier = Modifier.wrapContentHeight(),
|
||||
onDismissRequest = { showDialog.value = false },
|
||||
title = { Text(text = "Sign In") },
|
||||
title = { Text(text = stringResource(R.string.sign_in_dialog_title)) },
|
||||
confirmButton = {},
|
||||
dismissButton = {
|
||||
Button(
|
||||
TextButton(
|
||||
modifier = Modifier.height(40.dp),
|
||||
onClick = {
|
||||
showDialog.value = false
|
||||
}
|
||||
) {
|
||||
Text(stringResource(R.string.action_cancel))
|
||||
Text(text = stringResource(R.string.action_cancel))
|
||||
}
|
||||
},
|
||||
text = {}
|
||||
text = {
|
||||
Column(verticalArrangement = Arrangement.spacedBy(8.dp)) {
|
||||
Button(
|
||||
modifier = Modifier.fillMaxWidth(),
|
||||
onClick = {
|
||||
CoroutineScope(Dispatchers.IO).launch {
|
||||
SessionManager.requestNewGuestSession()?.let {
|
||||
withContext(Dispatchers.Main) {
|
||||
showDialog.value = false
|
||||
onSessionReturned(true)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
) {
|
||||
Text(text = stringResource(R.string.action_continue_as_guest))
|
||||
}
|
||||
|
||||
Button(
|
||||
modifier = Modifier.fillMaxWidth(),
|
||||
onClick = {
|
||||
showDialog.value = false
|
||||
}
|
||||
) {
|
||||
Text(text = stringResource(R.string.action_sign_in))
|
||||
}
|
||||
}
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.owenlejeune.tvtime.ui.screens.tabs.bottom
|
||||
|
||||
import android.widget.Toast
|
||||
import androidx.compose.foundation.clickable
|
||||
import androidx.compose.foundation.layout.*
|
||||
import androidx.compose.foundation.rememberScrollState
|
||||
@@ -17,6 +18,7 @@ import androidx.compose.runtime.remember
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.graphics.Color
|
||||
import androidx.compose.ui.platform.LocalContext
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import androidx.compose.ui.text.TextStyle
|
||||
import androidx.compose.ui.unit.dp
|
||||
@@ -93,6 +95,7 @@ fun SettingsTab(preferences: AppPreferences = get(AppPreferences::class.java)) {
|
||||
|
||||
@Composable
|
||||
private fun DebugOptions(preferences: AppPreferences = get(AppPreferences::class.java)) {
|
||||
val context = LocalContext.current
|
||||
val shouldShowPalette = remember { mutableStateOf(false) }
|
||||
Text(
|
||||
text = "Show material palette",
|
||||
@@ -117,7 +120,9 @@ private fun DebugOptions(preferences: AppPreferences = get(AppPreferences::class
|
||||
.clickable(
|
||||
onClick = {
|
||||
preferences.guestSessionId = ""
|
||||
SessionManager.clearSession()
|
||||
SessionManager.clearSession {
|
||||
Toast.makeText(context, "Cleared session: $it", Toast.LENGTH_SHORT).show()
|
||||
}
|
||||
}
|
||||
)
|
||||
)
|
||||
|
||||
@@ -1,13 +1,14 @@
|
||||
package com.owenlejeune.tvtime.utils
|
||||
|
||||
import com.owenlejeune.tvtime.api.tmdb.GuestSessionApi
|
||||
import com.owenlejeune.tvtime.api.tmdb.TmdbClient
|
||||
import com.owenlejeune.tvtime.api.tmdb.model.DeleteSessionBody
|
||||
import com.owenlejeune.tvtime.api.tmdb.model.RatedEpisode
|
||||
import com.owenlejeune.tvtime.api.tmdb.model.RatedMedia
|
||||
import com.owenlejeune.tvtime.api.tmdb.model.RatedMovie
|
||||
import com.owenlejeune.tvtime.api.tmdb.model.RatedTv
|
||||
import com.owenlejeune.tvtime.preferences.AppPreferences
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.launch
|
||||
import kotlinx.coroutines.withContext
|
||||
import org.koin.core.component.KoinComponent
|
||||
import org.koin.core.component.inject
|
||||
@@ -22,8 +23,22 @@ object SessionManager: KoinComponent {
|
||||
|
||||
private val authenticationService by lazy { TmdbClient().createAuthenticationService() }
|
||||
|
||||
fun clearSession() {
|
||||
_currentSession = null
|
||||
fun clearSession(onResponse: (isSuccessful: Boolean) -> Unit) {
|
||||
currentSession?.let { session ->
|
||||
CoroutineScope(Dispatchers.IO).launch {
|
||||
val deleteResponse = authenticationService.deleteSession(
|
||||
DeleteSessionBody(
|
||||
session.sessionId
|
||||
)
|
||||
)
|
||||
withContext(Dispatchers.Main) {
|
||||
if (deleteResponse.isSuccessful) {
|
||||
_currentSession = null
|
||||
}
|
||||
onResponse(deleteResponse.isSuccessful)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
suspend fun initialize() {
|
||||
@@ -34,7 +49,7 @@ object SessionManager: KoinComponent {
|
||||
}
|
||||
}
|
||||
|
||||
private suspend fun requestNewGuestSession(): Session? {
|
||||
suspend fun requestNewGuestSession(): Session? {
|
||||
val response = authenticationService.getNewGuestSession()
|
||||
if (response.isSuccessful) {
|
||||
preferences.guestSessionId = response.body()?.guestSessionId ?: ""
|
||||
@@ -78,10 +93,9 @@ object SessionManager: KoinComponent {
|
||||
override var _ratedTvShows: List<RatedTv> = emptyList()
|
||||
override var _ratedTvEpisodes: List<RatedEpisode> = emptyList()
|
||||
|
||||
private lateinit var service: GuestSessionApi
|
||||
private val service by lazy { TmdbClient().createGuestSessionService() }
|
||||
|
||||
override suspend fun initialize() {
|
||||
service = TmdbClient().createGuestSessionService()
|
||||
refresh()
|
||||
}
|
||||
|
||||
|
||||
@@ -35,6 +35,9 @@
|
||||
<string name="updated_at_label">Updated at: %1$s</string>
|
||||
<string name="no_reviews_label">No reviews</string>
|
||||
|
||||
<string name="sign_in_dialog_title">Sign In to Rate</string>
|
||||
<string name="action_continue_as_guest">Continue as Guest</string>
|
||||
<string name="action_sign_in">Sign In</string>
|
||||
<string name="rate_action_label">Rate</string>
|
||||
<string name="delete_rating_action_label">Delete Rating</string>
|
||||
<string name="add_to_list_action_label">Add to List</string>
|
||||
|
||||
Reference in New Issue
Block a user