feat(stations): клиент скрывает оффлайн-станции с бэкенда (системно)
При обновлении каталога тянем GET /stations/offline-ids и удаляем эти станции из локальной БД. Мёртвые плитки теперь пропадают сами (бэк их метит health-check'ом), без пересборки приложения. Фолбэк на статичный enabled, если бэк недоступен. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -23,6 +23,9 @@ interface StationDao {
|
||||
@Insert(onConflict = OnConflictStrategy.REPLACE)
|
||||
suspend fun insertAll(stations: List<StationEntity>)
|
||||
|
||||
@Query("DELETE FROM stations WHERE id IN (:ids)")
|
||||
suspend fun deleteByIds(ids: List<Int>)
|
||||
|
||||
@Update
|
||||
suspend fun update(station: StationEntity)
|
||||
|
||||
|
||||
@@ -30,6 +30,10 @@ interface RadiolaApi {
|
||||
@GET("now-playing")
|
||||
suspend fun getNowPlaying(): List<BackendNowPlayingDto>
|
||||
|
||||
// station_id оффлайн-станций — скрываем их в каталоге (мёртвые потоки)
|
||||
@GET("stations/offline-ids")
|
||||
suspend fun getOfflineStationIds(): List<Int>
|
||||
|
||||
@GET("users/me")
|
||||
suspend fun getMe(): JsonObject
|
||||
|
||||
|
||||
@@ -5,6 +5,7 @@ import com.radiola.data.local.AppDatabase
|
||||
import com.radiola.data.local.entity.StationEntity
|
||||
import com.radiola.data.local.entity.TagEntity
|
||||
import com.radiola.data.remote.RecordApi
|
||||
import com.radiola.data.remote.RadiolaApi
|
||||
import com.radiola.data.remote.ApiMapper.toDomain
|
||||
import com.radiola.domain.model.Station
|
||||
import com.radiola.domain.repository.StationRepository
|
||||
@@ -16,6 +17,7 @@ import javax.inject.Inject
|
||||
|
||||
class StationRepositoryImpl @Inject constructor(
|
||||
private val api: RecordApi,
|
||||
private val radiolaApi: RadiolaApi,
|
||||
private val db: AppDatabase,
|
||||
private val localDataSource: LocalStationDataSource
|
||||
) : StationRepository {
|
||||
@@ -88,6 +90,18 @@ class StationRepositoryImpl @Inject constructor(
|
||||
db.stationDao().insertAll(entities)
|
||||
android.util.Log.d("StationRepo", "Inserted ${entities.size} stations into DB")
|
||||
|
||||
// 4b. Скрываем станции, которые бэкенд пометил оффлайн (мёртвые потоки).
|
||||
// Если бэкенд недоступен — оставляем как есть (фолбэк на статичный enabled).
|
||||
try {
|
||||
val offlineIds = radiolaApi.getOfflineStationIds()
|
||||
if (offlineIds.isNotEmpty()) {
|
||||
db.stationDao().deleteByIds(offlineIds)
|
||||
android.util.Log.d("StationRepo", "Скрыто оффлайн-станций: ${offlineIds.size}")
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
android.util.Log.w("StationRepo", "Не удалось получить offline-id: ${e.message}")
|
||||
}
|
||||
|
||||
// 5. Update tags: group names + API tags
|
||||
val groupNames = localGroups.map { it.name }.filter { it.isNotBlank() }
|
||||
val allTags = (groupNames + apiTags).distinct().sorted()
|
||||
|
||||
Reference in New Issue
Block a user