mirror of
				https://github.com/recloudstream/cloudstream.git
				synced 2024-08-15 01:53:11 +00:00 
			
		
		
		
	[Additional feature] Also apply quality filter to HomePage list
This commit is contained in:
		
							parent
							
								
									dce6f06368
								
							
						
					
					
						commit
						ed9ae3d0e0
					
				
					 2 changed files with 39 additions and 14 deletions
				
			
		|  | @ -256,19 +256,41 @@ object APIHolder { | |||
| 
 | ||||
|     fun Context.filterSearchResultByFilmQuality(data: List<SearchResponse>): List<SearchResponse> { | ||||
|         // Filter results omitting entries with certain quality | ||||
|         if (data.isEmpty()) { | ||||
|             return data | ||||
|         if (data.isNotEmpty()) { | ||||
|             val filteredSearchQuality = PreferenceManager.getDefaultSharedPreferences(this) | ||||
|                 ?.getStringSet(getString(R.string.pref_filter_search_quality_key), setOf()) | ||||
|                 ?.mapNotNull { entry -> | ||||
|                     entry.toIntOrNull() ?: return@mapNotNull null | ||||
|                 } ?: listOf() | ||||
|             if (filteredSearchQuality.isNotEmpty()) { | ||||
|                 return data.filter { item -> | ||||
|                     val searchQualVal = item.quality?.ordinal ?: -1 | ||||
|                     //Log.i("filterSearch", "QuickSearch item => ${item.toJson()}") | ||||
|                     !filteredSearchQuality.contains(searchQualVal) | ||||
|                 } | ||||
|             } | ||||
|         } | ||||
|         val filteredSearchQuality = PreferenceManager.getDefaultSharedPreferences(this) | ||||
|             ?.getStringSet(getString(R.string.pref_filter_search_quality_key), setOf()) | ||||
|             ?.mapNotNull { entry -> | ||||
|                 entry.toIntOrNull() ?: return@mapNotNull null | ||||
|             } ?: listOf() | ||||
|         if (filteredSearchQuality.isNotEmpty()) { | ||||
|             return data.filter { item -> | ||||
|                 val searchQualVal = item.quality?.ordinal ?: -1 | ||||
|                 //Log.i("filterSearch", "QuickSearch item => ${item.toJson()}") | ||||
|                 !filteredSearchQuality.contains(searchQualVal) | ||||
|         return data | ||||
|     } | ||||
| 
 | ||||
|     fun Context.filterHomePageListByFilmQuality(data: HomePageList): HomePageList { | ||||
|         // Filter results omitting entries with certain quality | ||||
|         if (data.list.isNotEmpty()) { | ||||
|             val filteredSearchQuality = PreferenceManager.getDefaultSharedPreferences(this) | ||||
|                 ?.getStringSet(getString(R.string.pref_filter_search_quality_key), setOf()) | ||||
|                 ?.mapNotNull { entry -> | ||||
|                     entry.toIntOrNull() ?: return@mapNotNull null | ||||
|                 } ?: listOf() | ||||
|             if (filteredSearchQuality.isNotEmpty()) { | ||||
|                 return HomePageList( | ||||
|                     name = data.name, | ||||
|                     isHorizontalImages = data.isHorizontalImages, | ||||
|                     list = data.list.filter { item -> | ||||
|                         val searchQualVal = item.quality?.ordinal ?: -1 | ||||
|                         //Log.i("filterSearch", "QuickSearch item => ${item.toJson()}") | ||||
|                         !filteredSearchQuality.contains(searchQualVal) | ||||
|                     } | ||||
|                 ) | ||||
|             } | ||||
|         } | ||||
|         return data | ||||
|  |  | |||
|  | @ -5,7 +5,9 @@ import androidx.lifecycle.MutableLiveData | |||
| import androidx.lifecycle.ViewModel | ||||
| import androidx.lifecycle.viewModelScope | ||||
| import com.lagradost.cloudstream3.APIHolder.apis | ||||
| import com.lagradost.cloudstream3.APIHolder.filterHomePageListByFilmQuality | ||||
| import com.lagradost.cloudstream3.APIHolder.filterProviderByPreferredMedia | ||||
| import com.lagradost.cloudstream3.APIHolder.filterSearchResultByFilmQuality | ||||
| import com.lagradost.cloudstream3.APIHolder.getApiFromNameNull | ||||
| import com.lagradost.cloudstream3.AcraApplication.Companion.context | ||||
| import com.lagradost.cloudstream3.AcraApplication.Companion.getKey | ||||
|  | @ -225,8 +227,9 @@ class HomeViewModel : ViewModel() { | |||
|                         expandable.clear() | ||||
|                         data.value.forEach { home -> | ||||
|                             home?.items?.forEach { list -> | ||||
|                                 val filteredList = context?.filterHomePageListByFilmQuality(list) ?: list | ||||
|                                 expandable[list.name] = | ||||
|                                     ExpandableHomepageList(list, 1, home.hasNext) | ||||
|                                     ExpandableHomepageList(filteredList, 1, home.hasNext) | ||||
|                             } | ||||
|                         } | ||||
|                         _page.postValue(Resource.Success(expandable)) | ||||
|  | @ -241,7 +244,7 @@ class HomeViewModel : ViewModel() { | |||
|                                     .toList() | ||||
| 
 | ||||
|                             if (currentList.isNotEmpty()) { | ||||
|                                 val randomItems = currentList.shuffled() | ||||
|                                 val randomItems = context?.filterSearchResultByFilmQuality(currentList.shuffled()) ?: currentList.shuffled() | ||||
| 
 | ||||
|                                 _randomItems.postValue(randomItems) | ||||
|                             } | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue