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