mirror of
https://github.com/JustinZeus/Wholphin.git
synced 2026-07-08 23:51:21 +02:00
Remove unused code
This commit is contained in:
parent
ce4f8475b0
commit
025c253a42
2 changed files with 88 additions and 176 deletions
|
|
@ -4,8 +4,6 @@ import android.content.Context
|
||||||
import com.github.damontecres.wholphin.R
|
import com.github.damontecres.wholphin.R
|
||||||
import com.github.damontecres.wholphin.data.model.BaseItem
|
import com.github.damontecres.wholphin.data.model.BaseItem
|
||||||
import com.github.damontecres.wholphin.ui.SlimItemFields
|
import com.github.damontecres.wholphin.ui.SlimItemFields
|
||||||
import com.github.damontecres.wholphin.ui.main.LatestData
|
|
||||||
import com.github.damontecres.wholphin.ui.main.supportedLatestCollectionTypes
|
|
||||||
import com.github.damontecres.wholphin.util.HomeRowLoadingState
|
import com.github.damontecres.wholphin.util.HomeRowLoadingState
|
||||||
import com.github.damontecres.wholphin.util.supportItemKinds
|
import com.github.damontecres.wholphin.util.supportItemKinds
|
||||||
import dagger.hilt.android.qualifiers.ApplicationContext
|
import dagger.hilt.android.qualifiers.ApplicationContext
|
||||||
|
|
@ -21,6 +19,7 @@ import org.jellyfin.sdk.api.client.extensions.tvShowsApi
|
||||||
import org.jellyfin.sdk.api.client.extensions.userLibraryApi
|
import org.jellyfin.sdk.api.client.extensions.userLibraryApi
|
||||||
import org.jellyfin.sdk.api.client.extensions.userViewsApi
|
import org.jellyfin.sdk.api.client.extensions.userViewsApi
|
||||||
import org.jellyfin.sdk.model.api.BaseItemKind
|
import org.jellyfin.sdk.model.api.BaseItemKind
|
||||||
|
import org.jellyfin.sdk.model.api.CollectionType
|
||||||
import org.jellyfin.sdk.model.api.UserDto
|
import org.jellyfin.sdk.model.api.UserDto
|
||||||
import org.jellyfin.sdk.model.api.request.GetLatestMediaRequest
|
import org.jellyfin.sdk.model.api.request.GetLatestMediaRequest
|
||||||
import org.jellyfin.sdk.model.api.request.GetNextUpRequest
|
import org.jellyfin.sdk.model.api.request.GetNextUpRequest
|
||||||
|
|
@ -188,3 +187,17 @@ class LatestNextUpService
|
||||||
return@withContext result
|
return@withContext result
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
val supportedLatestCollectionTypes =
|
||||||
|
setOf(
|
||||||
|
CollectionType.MOVIES,
|
||||||
|
CollectionType.TVSHOWS,
|
||||||
|
CollectionType.HOMEVIDEOS,
|
||||||
|
// Exclude Live TV because a recording folder view will be used instead
|
||||||
|
null, // Recordings & mixed collection types
|
||||||
|
)
|
||||||
|
|
||||||
|
data class LatestData(
|
||||||
|
val title: String,
|
||||||
|
val request: GetLatestMediaRequest,
|
||||||
|
)
|
||||||
|
|
|
||||||
|
|
@ -1,10 +1,8 @@
|
||||||
package com.github.damontecres.wholphin.ui.main
|
package com.github.damontecres.wholphin.ui.main
|
||||||
|
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import androidx.lifecycle.MutableLiveData
|
|
||||||
import androidx.lifecycle.ViewModel
|
import androidx.lifecycle.ViewModel
|
||||||
import androidx.lifecycle.viewModelScope
|
import androidx.lifecycle.viewModelScope
|
||||||
import com.github.damontecres.wholphin.R
|
|
||||||
import com.github.damontecres.wholphin.data.NavDrawerItemRepository
|
import com.github.damontecres.wholphin.data.NavDrawerItemRepository
|
||||||
import com.github.damontecres.wholphin.data.ServerRepository
|
import com.github.damontecres.wholphin.data.ServerRepository
|
||||||
import com.github.damontecres.wholphin.data.model.BaseItem
|
import com.github.damontecres.wholphin.data.model.BaseItem
|
||||||
|
|
@ -13,17 +11,14 @@ import com.github.damontecres.wholphin.services.BackdropService
|
||||||
import com.github.damontecres.wholphin.services.DatePlayedService
|
import com.github.damontecres.wholphin.services.DatePlayedService
|
||||||
import com.github.damontecres.wholphin.services.FavoriteWatchManager
|
import com.github.damontecres.wholphin.services.FavoriteWatchManager
|
||||||
import com.github.damontecres.wholphin.services.HomeSettingsService
|
import com.github.damontecres.wholphin.services.HomeSettingsService
|
||||||
import com.github.damontecres.wholphin.services.LatestNextUpService
|
|
||||||
import com.github.damontecres.wholphin.services.NavigationManager
|
import com.github.damontecres.wholphin.services.NavigationManager
|
||||||
import com.github.damontecres.wholphin.services.UserPreferencesService
|
import com.github.damontecres.wholphin.services.UserPreferencesService
|
||||||
import com.github.damontecres.wholphin.ui.launchIO
|
import com.github.damontecres.wholphin.ui.launchIO
|
||||||
import com.github.damontecres.wholphin.ui.main.settings.Library
|
import com.github.damontecres.wholphin.ui.main.settings.Library
|
||||||
import com.github.damontecres.wholphin.ui.nav.ServerNavDrawerItem
|
import com.github.damontecres.wholphin.ui.nav.ServerNavDrawerItem
|
||||||
import com.github.damontecres.wholphin.ui.setValueOnMain
|
|
||||||
import com.github.damontecres.wholphin.ui.showToast
|
import com.github.damontecres.wholphin.ui.showToast
|
||||||
import com.github.damontecres.wholphin.util.ExceptionHandler
|
import com.github.damontecres.wholphin.util.ExceptionHandler
|
||||||
import com.github.damontecres.wholphin.util.HomeRowLoadingState
|
import com.github.damontecres.wholphin.util.HomeRowLoadingState
|
||||||
import com.github.damontecres.wholphin.util.LoadingExceptionHandler
|
|
||||||
import com.github.damontecres.wholphin.util.LoadingState
|
import com.github.damontecres.wholphin.util.LoadingState
|
||||||
import dagger.hilt.android.lifecycle.HiltViewModel
|
import dagger.hilt.android.lifecycle.HiltViewModel
|
||||||
import dagger.hilt.android.qualifiers.ApplicationContext
|
import dagger.hilt.android.qualifiers.ApplicationContext
|
||||||
|
|
@ -38,9 +33,6 @@ import kotlinx.coroutines.launch
|
||||||
import kotlinx.coroutines.sync.Semaphore
|
import kotlinx.coroutines.sync.Semaphore
|
||||||
import kotlinx.coroutines.sync.withPermit
|
import kotlinx.coroutines.sync.withPermit
|
||||||
import kotlinx.coroutines.withContext
|
import kotlinx.coroutines.withContext
|
||||||
import org.jellyfin.sdk.api.client.ApiClient
|
|
||||||
import org.jellyfin.sdk.model.api.CollectionType
|
|
||||||
import org.jellyfin.sdk.model.api.request.GetLatestMediaRequest
|
|
||||||
import timber.log.Timber
|
import timber.log.Timber
|
||||||
import java.util.UUID
|
import java.util.UUID
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
|
|
@ -50,22 +42,15 @@ class HomeViewModel
|
||||||
@Inject
|
@Inject
|
||||||
constructor(
|
constructor(
|
||||||
@param:ApplicationContext private val context: Context,
|
@param:ApplicationContext private val context: Context,
|
||||||
val api: ApiClient,
|
private val serverRepository: ServerRepository,
|
||||||
val navigationManager: NavigationManager,
|
private val navDrawerItemRepository: NavDrawerItemRepository,
|
||||||
val serverRepository: ServerRepository,
|
|
||||||
val navDrawerItemRepository: NavDrawerItemRepository,
|
|
||||||
private val homeSettingsService: HomeSettingsService,
|
private val homeSettingsService: HomeSettingsService,
|
||||||
private val favoriteWatchManager: FavoriteWatchManager,
|
private val favoriteWatchManager: FavoriteWatchManager,
|
||||||
private val datePlayedService: DatePlayedService,
|
private val datePlayedService: DatePlayedService,
|
||||||
private val latestNextUpService: LatestNextUpService,
|
|
||||||
private val backdropService: BackdropService,
|
private val backdropService: BackdropService,
|
||||||
private val userPreferencesService: UserPreferencesService,
|
private val userPreferencesService: UserPreferencesService,
|
||||||
|
val navigationManager: NavigationManager,
|
||||||
) : ViewModel() {
|
) : ViewModel() {
|
||||||
val loadingState = MutableLiveData<LoadingState>(LoadingState.Pending)
|
|
||||||
val refreshState = MutableLiveData<LoadingState>(LoadingState.Pending)
|
|
||||||
val watchingRows = MutableLiveData<List<HomeRowLoadingState>>(listOf())
|
|
||||||
val latestRows = MutableLiveData<List<HomeRowLoadingState>>(listOf())
|
|
||||||
|
|
||||||
private val _state = MutableStateFlow(HomeState.EMPTY)
|
private val _state = MutableStateFlow(HomeState.EMPTY)
|
||||||
val state: StateFlow<HomeState> = _state
|
val state: StateFlow<HomeState> = _state
|
||||||
|
|
||||||
|
|
@ -75,25 +60,11 @@ class HomeViewModel
|
||||||
}
|
}
|
||||||
|
|
||||||
fun init() {
|
fun init() {
|
||||||
viewModelScope.launch(
|
viewModelScope.launchIO {
|
||||||
Dispatchers.IO +
|
|
||||||
LoadingExceptionHandler(
|
|
||||||
loadingState,
|
|
||||||
"Error loading home page",
|
|
||||||
),
|
|
||||||
) {
|
|
||||||
Timber.d("init HomeViewModel")
|
Timber.d("init HomeViewModel")
|
||||||
val reload = loadingState.value != LoadingState.Success
|
try {
|
||||||
if (reload) {
|
|
||||||
loadingState.setValueOnMain(LoadingState.Loading)
|
|
||||||
}
|
|
||||||
refreshState.setValueOnMain(LoadingState.Loading)
|
|
||||||
val preferences = userPreferencesService.getCurrent()
|
val preferences = userPreferencesService.getCurrent()
|
||||||
val prefs = preferences.appPreferences.homePagePreferences
|
val prefs = preferences.appPreferences.homePagePreferences
|
||||||
val limit = prefs.maxItemsPerRow
|
|
||||||
if (reload) {
|
|
||||||
backdropService.clearBackdrop()
|
|
||||||
}
|
|
||||||
|
|
||||||
val navDrawerItems =
|
val navDrawerItems =
|
||||||
navDrawerItemRepository
|
navDrawerItemRepository
|
||||||
|
|
@ -167,72 +138,14 @@ class HomeViewModel
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
|
||||||
serverRepository.currentUserDto.value?.let { userDto ->
|
|
||||||
val includedIds =
|
|
||||||
navDrawerItemRepository
|
|
||||||
.getFilteredNavDrawerItems(navDrawerItemRepository.getNavDrawerItems())
|
|
||||||
.filter { it is ServerNavDrawerItem }
|
|
||||||
.map { (it as ServerNavDrawerItem).itemId }
|
|
||||||
val resume = latestNextUpService.getResume(userDto.id, limit, true)
|
|
||||||
val nextUp =
|
|
||||||
latestNextUpService.getNextUp(
|
|
||||||
userDto.id,
|
|
||||||
limit,
|
|
||||||
prefs.enableRewatchingNextUp,
|
|
||||||
false,
|
|
||||||
)
|
|
||||||
val watching =
|
|
||||||
buildList {
|
|
||||||
if (prefs.combineContinueNext) {
|
|
||||||
val items = latestNextUpService.buildCombined(resume, nextUp)
|
|
||||||
add(
|
|
||||||
HomeRowLoadingState.Success(
|
|
||||||
title = context.getString(R.string.continue_watching),
|
|
||||||
items = items,
|
|
||||||
),
|
|
||||||
)
|
|
||||||
} else {
|
|
||||||
if (resume.isNotEmpty()) {
|
|
||||||
add(
|
|
||||||
HomeRowLoadingState.Success(
|
|
||||||
title = context.getString(R.string.continue_watching),
|
|
||||||
items = resume,
|
|
||||||
),
|
|
||||||
)
|
|
||||||
}
|
|
||||||
if (nextUp.isNotEmpty()) {
|
|
||||||
add(
|
|
||||||
HomeRowLoadingState.Success(
|
|
||||||
title = context.getString(R.string.next_up),
|
|
||||||
items = nextUp,
|
|
||||||
),
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
val latest = latestNextUpService.getLatest(userDto, limit, includedIds)
|
|
||||||
val pendingLatest = latest.map { HomeRowLoadingState.Loading(it.title) }
|
|
||||||
|
|
||||||
withContext(Dispatchers.Main) {
|
|
||||||
this@HomeViewModel.watchingRows.value = watching
|
|
||||||
if (reload) {
|
|
||||||
this@HomeViewModel.latestRows.value = pendingLatest
|
|
||||||
}
|
|
||||||
loadingState.value = LoadingState.Success
|
|
||||||
}
|
|
||||||
refreshState.setValueOnMain(LoadingState.Success)
|
|
||||||
val loadedLatest = latestNextUpService.loadLatest(latest)
|
|
||||||
this@HomeViewModel.latestRows.setValueOnMain(loadedLatest)
|
|
||||||
}
|
|
||||||
} catch (ex: Exception) {
|
} catch (ex: Exception) {
|
||||||
Timber.e(ex)
|
Timber.e(ex, "Exception during home page loading")
|
||||||
if (!reload) {
|
if (state.value.loadingState == LoadingState.Success) {
|
||||||
loadingState.setValueOnMain(LoadingState.Error(ex))
|
|
||||||
} else {
|
|
||||||
showToast(context, "Error refreshing home: ${ex.localizedMessage}")
|
showToast(context, "Error refreshing home: ${ex.localizedMessage}")
|
||||||
|
} else {
|
||||||
|
_state.update {
|
||||||
|
it.copy(loadingState = LoadingState.Error(ex))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -265,20 +178,6 @@ class HomeViewModel
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
val supportedLatestCollectionTypes =
|
|
||||||
setOf(
|
|
||||||
CollectionType.MOVIES,
|
|
||||||
CollectionType.TVSHOWS,
|
|
||||||
CollectionType.HOMEVIDEOS,
|
|
||||||
// Exclude Live TV because a recording folder view will be used instead
|
|
||||||
null, // Recordings & mixed collection types
|
|
||||||
)
|
|
||||||
|
|
||||||
data class LatestData(
|
|
||||||
val title: String,
|
|
||||||
val request: GetLatestMediaRequest,
|
|
||||||
)
|
|
||||||
|
|
||||||
data class HomeState(
|
data class HomeState(
|
||||||
val loadingState: LoadingState,
|
val loadingState: LoadingState,
|
||||||
val refreshState: LoadingState,
|
val refreshState: LoadingState,
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue