Updates the for you view model to support displaying a loading state when data hasn't loaded yet. This is a somewhat involved CL, because there are multiple ways in which data could be loading: We could have topics, but the feed itself could be loading after we selected a new set of topics. Change-Id: I8662140c7132b195f85e69fee8e18745829ae975pull/2/head
parent
2e4c763db5
commit
a5f679063d
@ -0,0 +1,41 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2022 The Android Open Source Project
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* https://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.google.samples.apps.nowinandroid.feature.foryou
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A sealed hierarchy for the user's current followed interests state.
|
||||||
|
*/
|
||||||
|
sealed interface FollowedInterestsState {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The current state is unknown (hasn't loaded yet)
|
||||||
|
*/
|
||||||
|
object Unknown : FollowedInterestsState
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The user hasn't followed any interests yet.
|
||||||
|
*/
|
||||||
|
object None : FollowedInterestsState
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The user has followed the given (non-empty) set of [topicIds] or [authorIds].
|
||||||
|
*/
|
||||||
|
data class FollowedInterests(
|
||||||
|
val topicIds: Set<String>,
|
||||||
|
val authorIds: Set<String>
|
||||||
|
) : FollowedInterestsState
|
||||||
|
}
|
@ -0,0 +1,39 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2022 The Android Open Source Project
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* https://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.google.samples.apps.nowinandroid.feature.foryou
|
||||||
|
|
||||||
|
import com.google.samples.apps.nowinandroid.core.model.data.SaveableNewsResource
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A sealed hierarchy describing the state of the feed on the for you screen.
|
||||||
|
*/
|
||||||
|
sealed interface ForYouFeedState {
|
||||||
|
/**
|
||||||
|
* The feed is still loading.
|
||||||
|
*/
|
||||||
|
object Loading : ForYouFeedState
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The feed is loaded with the given list of news resources.
|
||||||
|
*/
|
||||||
|
data class Success(
|
||||||
|
/**
|
||||||
|
* The list of news resources contained in this [PopulatedFeed].
|
||||||
|
*/
|
||||||
|
val feed: List<SaveableNewsResource>
|
||||||
|
) : ForYouFeedState
|
||||||
|
}
|
@ -0,0 +1,49 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2022 The Android Open Source Project
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* https://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.google.samples.apps.nowinandroid.feature.foryou
|
||||||
|
|
||||||
|
import com.google.samples.apps.nowinandroid.core.model.data.FollowableAuthor
|
||||||
|
import com.google.samples.apps.nowinandroid.core.model.data.FollowableTopic
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A sealed hierarchy describing the interests selection state for the for you screen.
|
||||||
|
*/
|
||||||
|
sealed interface ForYouInterestsSelectionState {
|
||||||
|
/**
|
||||||
|
* The interests selection state is loading.
|
||||||
|
*/
|
||||||
|
object Loading : ForYouInterestsSelectionState
|
||||||
|
|
||||||
|
/**
|
||||||
|
* There is no interests selection state.
|
||||||
|
*/
|
||||||
|
object NoInterestsSelection : ForYouInterestsSelectionState
|
||||||
|
|
||||||
|
/**
|
||||||
|
* There is a interests selection state, with the given lists of topics and authors.
|
||||||
|
*/
|
||||||
|
data class WithInterestsSelection(
|
||||||
|
val topics: List<FollowableTopic>,
|
||||||
|
val authors: List<FollowableAuthor>
|
||||||
|
) : ForYouInterestsSelectionState {
|
||||||
|
/**
|
||||||
|
* True if the current in-progress selection can be saved.
|
||||||
|
*/
|
||||||
|
val canSaveInterests: Boolean get() =
|
||||||
|
topics.any { it.isFollowed } || authors.any { it.isFollowed }
|
||||||
|
}
|
||||||
|
}
|
File diff suppressed because it is too large
Load Diff
Loading…
Reference in new issue