made video recommendations as optional
This commit is contained in:
parent
5b91db5834
commit
6b83fd7f46
6 changed files with 41 additions and 15 deletions
|
|
@ -1,6 +1,8 @@
|
|||
package com.deniscerri.ytdlnis.database.viewmodel
|
||||
|
||||
import android.app.Activity
|
||||
import android.app.Application
|
||||
import android.content.SharedPreferences
|
||||
import android.util.Log
|
||||
import androidx.lifecycle.AndroidViewModel
|
||||
import androidx.lifecycle.LiveData
|
||||
|
|
@ -25,6 +27,7 @@ class ResultViewModel(application: Application) : AndroidViewModel(application)
|
|||
val items : LiveData<List<ResultItem>>
|
||||
val loadingItems = MutableLiveData<Boolean>()
|
||||
var itemCount : LiveData<Int>
|
||||
private val sharedPreferences: SharedPreferences
|
||||
|
||||
init {
|
||||
val dao = DBManager.getInstance(application).resultDao
|
||||
|
|
@ -34,20 +37,23 @@ class ResultViewModel(application: Application) : AndroidViewModel(application)
|
|||
items = repository.allResults
|
||||
loadingItems.postValue(false)
|
||||
itemCount = repository.itemCount
|
||||
sharedPreferences = application.getSharedPreferences("root_preferences", Activity.MODE_PRIVATE)
|
||||
}
|
||||
|
||||
fun checkTrending() = viewModelScope.launch(Dispatchers.IO){
|
||||
try {
|
||||
val item = repository.getFirstResult()
|
||||
if (
|
||||
item.playlistTitle == getApplication<App>().getString(R.string.trendingPlaylist)
|
||||
&& item.creationTime < (System.currentTimeMillis() / 1000) - 86400
|
||||
){
|
||||
if (sharedPreferences.getBoolean("home_recommendations", false)){
|
||||
try {
|
||||
val item = repository.getFirstResult()
|
||||
if (
|
||||
item.playlistTitle == getApplication<App>().getString(R.string.trendingPlaylist)
|
||||
&& item.creationTime < (System.currentTimeMillis() / 1000) - 86400
|
||||
){
|
||||
getTrending()
|
||||
}
|
||||
}catch (e : Exception){
|
||||
e.printStackTrace()
|
||||
getTrending()
|
||||
}
|
||||
}catch (e : Exception){
|
||||
e.printStackTrace()
|
||||
getTrending()
|
||||
}
|
||||
}
|
||||
fun getTrending() = viewModelScope.launch(Dispatchers.IO){
|
||||
|
|
|
|||
|
|
@ -44,6 +44,7 @@ class SettingsFragment : PreferenceFragmentCompat() {
|
|||
private var downloadCard: SwitchPreferenceCompat? = null
|
||||
private var meteredNetwork: SwitchPreferenceCompat? = null
|
||||
private var apiKey: EditTextPreference? = null
|
||||
private var homeRecommendations: SwitchPreferenceCompat? = null
|
||||
private var concurrentFragments: SeekBarPreference? = null
|
||||
private var concurrentDownloads: SeekBarPreference? = null
|
||||
private var limitRate: EditTextPreference? = null
|
||||
|
|
@ -110,6 +111,7 @@ class SettingsFragment : PreferenceFragmentCompat() {
|
|||
downloadCard = findPreference("download_card")
|
||||
meteredNetwork = findPreference("metered_networks")
|
||||
apiKey = findPreference("api_key")
|
||||
homeRecommendations = findPreference("home_recommendations")
|
||||
concurrentFragments = findPreference("concurrent_fragments")
|
||||
concurrentDownloads = findPreference("concurrent_downloads")
|
||||
limitRate = findPreference("limit_rate")
|
||||
|
|
@ -175,6 +177,7 @@ class SettingsFragment : PreferenceFragmentCompat() {
|
|||
editor.putBoolean("download_card", downloadCard!!.isChecked)
|
||||
editor.putBoolean("metered_networks", meteredNetwork!!.isChecked)
|
||||
editor.putString("api_key", apiKey!!.text)
|
||||
editor.putBoolean("home_recommendations", homeRecommendations!!.isChecked)
|
||||
editor.putInt("concurrent_fragments", concurrentFragments!!.value)
|
||||
editor.putInt("concurrent_downloads", concurrentDownloads!!.value)
|
||||
editor.putString("limit_rate", limitRate!!.text)
|
||||
|
|
@ -311,6 +314,13 @@ class SettingsFragment : PreferenceFragmentCompat() {
|
|||
editor.apply()
|
||||
true
|
||||
}
|
||||
homeRecommendations!!.onPreferenceChangeListener =
|
||||
Preference.OnPreferenceChangeListener { _: Preference?, newValue: Any ->
|
||||
val enable = newValue as Boolean
|
||||
editor.putBoolean("home_recommendations", enable)
|
||||
editor.apply()
|
||||
true
|
||||
}
|
||||
concurrentFragments!!.onPreferenceChangeListener =
|
||||
Preference.OnPreferenceChangeListener { _: Preference?, newValue: Any ->
|
||||
val value = newValue.toString().toInt()
|
||||
|
|
|
|||
|
|
@ -489,8 +489,8 @@ class InfoUtil(private val context: Context) {
|
|||
init()
|
||||
val p = Pattern.compile("^(https?)://(www.)?youtu(.be)?")
|
||||
val m = p.matcher(url)
|
||||
val formatSource = sharedPreferences.getString("formats_source", context.getString(R.string.defaultValue))!!
|
||||
return if(m.find() && useInvidous && formatSource == "Default"){
|
||||
val formatSource = sharedPreferences.getString("formats_source", "yt-dlp")
|
||||
return if(m.find() && useInvidous && formatSource == "invidious"){
|
||||
val id = getIDFromYoutubeURL(url)
|
||||
val res = genericRequest(invidousURL + "videos/" + id)
|
||||
if (res.length() == 0) getFromYTDL(url)[0]!!
|
||||
|
|
|
|||
|
|
@ -117,12 +117,12 @@
|
|||
</array>
|
||||
|
||||
<array name="formats_source">
|
||||
<item>@string/defaultValue</item>
|
||||
<item>Invidious API [Youtube]</item>
|
||||
<item>yt-dlp</item>
|
||||
</array>
|
||||
|
||||
<array name="formats_source_values">
|
||||
<item>Default</item>
|
||||
<item>invidious</item>
|
||||
<item>yt-dlp</item>
|
||||
</array>
|
||||
</resources>
|
||||
|
|
@ -212,4 +212,6 @@
|
|||
<string name="save_subs_desc">Write subtitle file</string>
|
||||
<string name="subtitle_languages">Subtitle languages</string>
|
||||
<string name="format_source">Formats Source</string>
|
||||
<string name="video_recommendations">Video Recommendations</string>
|
||||
<string name="video_recommendations_summary">Get Recommended Youtube Videos on the Home Screen from Invidious</string>
|
||||
</resources>
|
||||
|
|
@ -90,6 +90,14 @@
|
|||
app:summary="@string/api_key_summary"
|
||||
app:title="@string/api_key" />
|
||||
|
||||
<SwitchPreferenceCompat
|
||||
android:widgetLayout="@layout/preferece_material_switch"
|
||||
app:defaultValue="false"
|
||||
android:icon="@drawable/baseline_recommend_24"
|
||||
android:key="home_recommendations"
|
||||
app:summary="@string/video_recommendations_summary"
|
||||
app:title="@string/video_recommendations" />
|
||||
|
||||
<SeekBarPreference
|
||||
app:dependency="aria2"
|
||||
android:defaultValue="3"
|
||||
|
|
@ -276,12 +284,12 @@
|
|||
app:title="@string/update_formats" />
|
||||
|
||||
<ListPreference
|
||||
android:defaultValue="Default"
|
||||
android:defaultValue="yt-dlp"
|
||||
android:entries="@array/formats_source"
|
||||
android:entryValues="@array/formats_source_values"
|
||||
android:icon="@drawable/baseline_manage_search_24"
|
||||
app:key="formats_source"
|
||||
app:summary="@string/defaultValue"
|
||||
app:summary="yt-dlp"
|
||||
app:title="@string/format_source" />
|
||||
|
||||
<SwitchPreferenceCompat
|
||||
|
|
|
|||
Loading…
Reference in a new issue