Merge branch 'dev'
This commit is contained in:
@@ -46,9 +46,8 @@ class StreamViewModel @Inject constructor(
|
|||||||
|
|
||||||
private var stash: HomeStash = mutableMapOf()
|
private var stash: HomeStash = mutableMapOf()
|
||||||
|
|
||||||
fun contract(): StreamContract {
|
private val streamContract: StreamContract
|
||||||
return webStreamHelper
|
get() = webStreamHelper
|
||||||
}
|
|
||||||
|
|
||||||
fun getStreamBundle(category: StreamContract.Category, type: StreamContract.Type) {
|
fun getStreamBundle(category: StreamContract.Category, type: StreamContract.Type) {
|
||||||
liveData.postValue(ViewState.Loading)
|
liveData.postValue(ViewState.Loading)
|
||||||
@@ -68,12 +67,12 @@ class StreamViewModel @Inject constructor(
|
|||||||
|
|
||||||
//Fetch new stream bundle
|
//Fetch new stream bundle
|
||||||
val newBundle = if (bundle.hasCluster()) {
|
val newBundle = if (bundle.hasCluster()) {
|
||||||
contract().nextStreamBundle(
|
streamContract.nextStreamBundle(
|
||||||
category,
|
category,
|
||||||
bundle.streamNextPageUrl
|
bundle.streamNextPageUrl
|
||||||
)
|
)
|
||||||
} else {
|
} else {
|
||||||
contract().fetch(type, category)
|
streamContract.fetch(type, category)
|
||||||
}
|
}
|
||||||
|
|
||||||
//Update old bundle
|
//Update old bundle
|
||||||
@@ -100,7 +99,7 @@ class StreamViewModel @Inject constructor(
|
|||||||
try {
|
try {
|
||||||
if (streamCluster.hasNext()) {
|
if (streamCluster.hasNext()) {
|
||||||
val newCluster =
|
val newCluster =
|
||||||
contract().nextStreamCluster(streamCluster.clusterNextPageUrl)
|
streamContract.nextStreamCluster(streamCluster.clusterNextPageUrl)
|
||||||
updateCluster(category, streamCluster.id, newCluster)
|
updateCluster(category, streamCluster.id, newCluster)
|
||||||
liveData.postValue(ViewState.Success(stash))
|
liveData.postValue(ViewState.Success(stash))
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -39,9 +39,9 @@ import javax.inject.Inject
|
|||||||
@HiltViewModel
|
@HiltViewModel
|
||||||
class SearchResultViewModel @Inject constructor(
|
class SearchResultViewModel @Inject constructor(
|
||||||
val filterProvider: FilterProvider,
|
val filterProvider: FilterProvider,
|
||||||
authProvider: AuthProvider,
|
private val authProvider: AuthProvider,
|
||||||
searchHelper: SearchHelper,
|
private val searchHelper: SearchHelper,
|
||||||
webSearchHelper: WebSearchHelper
|
private val webSearchHelper: WebSearchHelper
|
||||||
) : ViewModel() {
|
) : ViewModel() {
|
||||||
|
|
||||||
private val TAG = SearchResultViewModel::class.java.simpleName
|
private val TAG = SearchResultViewModel::class.java.simpleName
|
||||||
@@ -50,11 +50,8 @@ class SearchResultViewModel @Inject constructor(
|
|||||||
|
|
||||||
private var searchBundle: SearchBundle = SearchBundle()
|
private var searchBundle: SearchBundle = SearchBundle()
|
||||||
|
|
||||||
private val helper: SearchContract = if (authProvider.isAnonymous) {
|
private val helper: SearchContract
|
||||||
webSearchHelper
|
get() = if (authProvider.isAnonymous) webSearchHelper else searchHelper
|
||||||
} else {
|
|
||||||
searchHelper
|
|
||||||
}
|
|
||||||
|
|
||||||
fun observeSearchResults(query: String) {
|
fun observeSearchResults(query: String) {
|
||||||
//Clear old results
|
//Clear old results
|
||||||
|
|||||||
@@ -35,19 +35,16 @@ import javax.inject.Inject
|
|||||||
|
|
||||||
@HiltViewModel
|
@HiltViewModel
|
||||||
class SearchSuggestionViewModel @Inject constructor(
|
class SearchSuggestionViewModel @Inject constructor(
|
||||||
authProvider: AuthProvider,
|
private val authProvider: AuthProvider,
|
||||||
searchHelper: SearchHelper,
|
private val searchHelper: SearchHelper,
|
||||||
webSearchHelper: WebSearchHelper
|
private val webSearchHelper: WebSearchHelper
|
||||||
) : ViewModel() {
|
) : ViewModel() {
|
||||||
|
|
||||||
private val _searchSuggestions = MutableStateFlow<List<SearchSuggestEntry>>(emptyList())
|
private val _searchSuggestions = MutableStateFlow<List<SearchSuggestEntry>>(emptyList())
|
||||||
val searchSuggestions = _searchSuggestions.asStateFlow()
|
val searchSuggestions = _searchSuggestions.asStateFlow()
|
||||||
|
|
||||||
private val helper: SearchContract = if (authProvider.isAnonymous) {
|
private val helper: SearchContract
|
||||||
webSearchHelper
|
get() = if (authProvider.isAnonymous) webSearchHelper else searchHelper
|
||||||
} else {
|
|
||||||
searchHelper
|
|
||||||
}
|
|
||||||
|
|
||||||
fun observeStreamBundles(query: String) {
|
fun observeStreamBundles(query: String) {
|
||||||
viewModelScope.launch(Dispatchers.IO) {
|
viewModelScope.launch(Dispatchers.IO) {
|
||||||
|
|||||||
@@ -46,9 +46,8 @@ class CategoryStreamViewModel @Inject constructor(
|
|||||||
|
|
||||||
private var stash: MutableMap<String, StreamBundle> = mutableMapOf()
|
private var stash: MutableMap<String, StreamBundle> = mutableMapOf()
|
||||||
|
|
||||||
fun contract(): CategoryStreamContract {
|
private val categoryStreamContract: CategoryStreamContract
|
||||||
return webCategoryStreamHelper
|
get() = webCategoryStreamHelper
|
||||||
}
|
|
||||||
|
|
||||||
fun getStreamBundle(category: StreamContract.Category) {
|
fun getStreamBundle(category: StreamContract.Category) {
|
||||||
liveData.postValue(ViewState.Loading)
|
liveData.postValue(ViewState.Loading)
|
||||||
@@ -69,9 +68,9 @@ class CategoryStreamViewModel @Inject constructor(
|
|||||||
|
|
||||||
//Fetch new stream bundle
|
//Fetch new stream bundle
|
||||||
val newBundle = if (bundle.streamClusters.isEmpty()) {
|
val newBundle = if (bundle.streamClusters.isEmpty()) {
|
||||||
contract().fetch(category.value)
|
categoryStreamContract.fetch(category.value)
|
||||||
} else {
|
} else {
|
||||||
contract().nextStreamBundle(
|
categoryStreamContract.nextStreamBundle(
|
||||||
category,
|
category,
|
||||||
bundle.streamNextPageUrl
|
bundle.streamNextPageUrl
|
||||||
)
|
)
|
||||||
@@ -101,7 +100,7 @@ class CategoryStreamViewModel @Inject constructor(
|
|||||||
try {
|
try {
|
||||||
if (streamCluster.hasNext()) {
|
if (streamCluster.hasNext()) {
|
||||||
val newCluster =
|
val newCluster =
|
||||||
contract().nextStreamCluster(streamCluster.clusterNextPageUrl)
|
categoryStreamContract.nextStreamCluster(streamCluster.clusterNextPageUrl)
|
||||||
updateCluster(category, streamCluster.id, newCluster)
|
updateCluster(category, streamCluster.id, newCluster)
|
||||||
liveData.postValue(ViewState.Success(stash))
|
liveData.postValue(ViewState.Success(stash))
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -42,9 +42,8 @@ class TopChartViewModel @Inject constructor(
|
|||||||
|
|
||||||
val liveData: MutableLiveData<ViewState> = MutableLiveData()
|
val liveData: MutableLiveData<ViewState> = MutableLiveData()
|
||||||
|
|
||||||
private fun contract(): TopChartsContract {
|
private val topChartsContract: TopChartsContract
|
||||||
return webTopChartsHelper
|
get() = webTopChartsHelper
|
||||||
}
|
|
||||||
|
|
||||||
fun getStreamCluster(type: TopChartsContract.Type, chart: TopChartsContract.Chart) {
|
fun getStreamCluster(type: TopChartsContract.Type, chart: TopChartsContract.Chart) {
|
||||||
viewModelScope.launch(Dispatchers.IO) {
|
viewModelScope.launch(Dispatchers.IO) {
|
||||||
@@ -53,7 +52,7 @@ class TopChartViewModel @Inject constructor(
|
|||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
val cluster = contract().getCluster(type.value, chart.value)
|
val cluster = topChartsContract.getCluster(type.value, chart.value)
|
||||||
updateCluster(type, chart, cluster)
|
updateCluster(type, chart, cluster)
|
||||||
liveData.postValue(ViewState.Success(stash))
|
liveData.postValue(ViewState.Success(stash))
|
||||||
} catch (_: Exception) {
|
} catch (_: Exception) {
|
||||||
@@ -67,7 +66,7 @@ class TopChartViewModel @Inject constructor(
|
|||||||
try {
|
try {
|
||||||
val target = targetCluster(type, chart)
|
val target = targetCluster(type, chart)
|
||||||
if (target.hasNext()) {
|
if (target.hasNext()) {
|
||||||
val newCluster = contract().getNextStreamCluster(
|
val newCluster = topChartsContract.getNextStreamCluster(
|
||||||
target.clusterNextPageUrl
|
target.clusterNextPageUrl
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user