added automatic format updates & removed app from recents when terminated
This commit is contained in:
parent
57f8520e03
commit
9dbf92a5d1
10 changed files with 64 additions and 25 deletions
|
|
@ -46,13 +46,12 @@ class ResultViewModel(application: Application) : AndroidViewModel(application)
|
|||
getTrending()
|
||||
}
|
||||
}catch (e : Exception){
|
||||
e.printStackTrace()
|
||||
getTrending()
|
||||
}
|
||||
}
|
||||
fun getTrending() = viewModelScope.launch(Dispatchers.IO){
|
||||
loadingItems.postValue(true)
|
||||
repository.updateTrending()
|
||||
loadingItems.postValue(false)
|
||||
}
|
||||
|
||||
suspend fun parseQuery(inputQuery: String, resetResults: Boolean) : ArrayList<ResultItem?> {
|
||||
|
|
|
|||
|
|
@ -205,11 +205,14 @@ class HomeFragment : Fragment(), HomeAdapter.OnItemClickListener, View.OnClickLi
|
|||
} catch (ignored: Exception) {
|
||||
}
|
||||
}
|
||||
} else {
|
||||
resultViewModel.checkTrending()
|
||||
}
|
||||
}
|
||||
|
||||
override fun onResume() {
|
||||
super.onResume()
|
||||
resultViewModel.checkTrending()
|
||||
}
|
||||
|
||||
private fun initMenu() {
|
||||
val searchView = requireView().findViewById<SearchView>(R.id.search_view)
|
||||
infoUtil = InfoUtil(requireContext())
|
||||
|
|
|
|||
|
|
@ -1,8 +1,10 @@
|
|||
package com.deniscerri.ytdlnis.ui.downloadcard
|
||||
|
||||
import android.annotation.SuppressLint
|
||||
import android.app.Activity
|
||||
import android.app.Dialog
|
||||
import android.content.DialogInterface
|
||||
import android.content.SharedPreferences
|
||||
import android.os.Bundle
|
||||
import android.util.DisplayMetrics
|
||||
import android.util.Log
|
||||
|
|
@ -10,6 +12,7 @@ import android.view.LayoutInflater
|
|||
import android.view.View
|
||||
import android.widget.*
|
||||
import androidx.constraintlayout.widget.ConstraintLayout
|
||||
import androidx.core.view.isVisible
|
||||
import androidx.lifecycle.lifecycleScope
|
||||
import com.deniscerri.ytdlnis.R
|
||||
import com.deniscerri.ytdlnis.database.models.DownloadItem
|
||||
|
|
@ -32,12 +35,14 @@ class FormatSelectionBottomSheetDialog(private val item: DownloadItem, private v
|
|||
private lateinit var fileUtil: FileUtil
|
||||
private lateinit var infoUtil: InfoUtil
|
||||
private lateinit var uiUtil: UiUtil
|
||||
private lateinit var sharedPreferences: SharedPreferences
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
fileUtil = FileUtil()
|
||||
uiUtil = UiUtil(fileUtil)
|
||||
infoUtil = InfoUtil(requireActivity().applicationContext)
|
||||
sharedPreferences = requireContext().getSharedPreferences("root_preferences", Activity.MODE_PRIVATE)
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -95,6 +100,9 @@ class FormatSelectionBottomSheetDialog(private val item: DownloadItem, private v
|
|||
}
|
||||
}
|
||||
}
|
||||
if (sharedPreferences.getBoolean("update_formats", false) && refreshBtn.isVisible){
|
||||
refreshBtn.performClick()
|
||||
}
|
||||
}
|
||||
|
||||
private fun addFormatsToView(linearLayout: LinearLayout){
|
||||
|
|
|
|||
|
|
@ -105,10 +105,12 @@ class MoreFragment : Fragment() {
|
|||
mainSharedPreferencesEditor.putBoolean("ask_terminate_app", false)
|
||||
mainSharedPreferencesEditor.commit()
|
||||
}
|
||||
mainActivity.finishAndRemoveTask()
|
||||
exitProcess(0)
|
||||
}
|
||||
terminateDialog.show()
|
||||
}else{
|
||||
mainActivity.finishAndRemoveTask()
|
||||
exitProcess(0)
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -56,6 +56,7 @@ class SettingsFragment : PreferenceFragmentCompat() {
|
|||
private var videoQuality: ListPreference? = null
|
||||
private var updateYTDL: Preference? = null
|
||||
private var updateNightlyYTDL: SwitchPreferenceCompat? = null
|
||||
private var updateFormats: SwitchPreferenceCompat? = null
|
||||
private var updateApp: SwitchPreferenceCompat? = null
|
||||
private var exportPreferences : Preference? = null
|
||||
private var importPreferences : Preference? = null
|
||||
|
|
@ -117,6 +118,7 @@ class SettingsFragment : PreferenceFragmentCompat() {
|
|||
videoQuality = findPreference("video_quality")
|
||||
updateYTDL = findPreference("update_ytdl")
|
||||
updateNightlyYTDL = findPreference("nightly_ytdl")
|
||||
updateFormats = findPreference("update_formats")
|
||||
updateApp = findPreference("update_app")
|
||||
exportPreferences = findPreference("export_preferences")
|
||||
importPreferences = findPreference("import_preferences")
|
||||
|
|
@ -175,6 +177,7 @@ class SettingsFragment : PreferenceFragmentCompat() {
|
|||
editor.putInt("audio_quality", audioQuality!!.value)
|
||||
editor.putString("video_quality", videoQuality!!.value)
|
||||
editor.putBoolean("nightly_ytdl", updateNightlyYTDL!!.isChecked)
|
||||
editor.putBoolean("update_formats", updateFormats!!.isChecked)
|
||||
editor.putBoolean("update_app", updateApp!!.isChecked)
|
||||
editor.apply()
|
||||
}
|
||||
|
|
@ -438,6 +441,13 @@ class SettingsFragment : PreferenceFragmentCompat() {
|
|||
}
|
||||
true
|
||||
}
|
||||
updateFormats!!.onPreferenceChangeListener =
|
||||
Preference.OnPreferenceChangeListener { _: Preference?, newValue: Any ->
|
||||
val enable = newValue as Boolean
|
||||
editor.putBoolean("update_formats", enable)
|
||||
editor.apply()
|
||||
true
|
||||
}
|
||||
updateNightlyYTDL!!.onPreferenceChangeListener =
|
||||
Preference.OnPreferenceChangeListener { _: Preference?, newValue: Any ->
|
||||
val enable = newValue as Boolean
|
||||
|
|
|
|||
|
|
@ -319,7 +319,7 @@ class InfoUtil(context: Context) {
|
|||
val req = URL(url)
|
||||
conn = req.openConnection() as HttpURLConnection
|
||||
conn.requestMethod = "GET"
|
||||
conn.connectTimeout = 10000
|
||||
conn.connectTimeout = 3000
|
||||
conn.readTimeout = 5000
|
||||
if (conn.responseCode < 300) {
|
||||
reader = BufferedReader(InputStreamReader(conn.inputStream))
|
||||
|
|
@ -350,7 +350,7 @@ class InfoUtil(context: Context) {
|
|||
val req = URL(url)
|
||||
conn = req.openConnection() as HttpURLConnection
|
||||
conn.requestMethod = "GET"
|
||||
conn.connectTimeout = 10000
|
||||
conn.connectTimeout = 3000
|
||||
conn.readTimeout = 5000
|
||||
if (conn.responseCode < 300) {
|
||||
reader = BufferedReader(InputStreamReader(conn.inputStream))
|
||||
|
|
@ -393,9 +393,10 @@ class InfoUtil(context: Context) {
|
|||
|
||||
@Throws(JSONException::class)
|
||||
fun getTrending(context: Context): ArrayList<ResultItem?> {
|
||||
init()
|
||||
items = ArrayList()
|
||||
return if (key!!.isEmpty()) {
|
||||
items
|
||||
if (useInvidous) getTrendingFromInvidous(context) else ArrayList()
|
||||
} else getTrendingFromKey(context)
|
||||
}
|
||||
|
||||
|
|
@ -429,23 +430,23 @@ class InfoUtil(context: Context) {
|
|||
return items
|
||||
}
|
||||
|
||||
// private fun getTrendingFromInvidous(context: Context): ArrayList<ResultItem?> {
|
||||
// val url = invidousURL + "trending?type=music®ion=" + countryCODE
|
||||
// val res = genericArrayRequest(url)
|
||||
// try {
|
||||
// for (i in 0 until res.length()) {
|
||||
// val element = res.getJSONObject(i)
|
||||
// if (element.getString("type") != "video") continue
|
||||
// val v = createVideofromInvidiousJSON(element)
|
||||
// if (v == null || v.thumb.isEmpty()) continue
|
||||
// v.playlistTitle = context.getString(R.string.trendingPlaylist)
|
||||
// items.add(v)
|
||||
// }
|
||||
// } catch (e: Exception) {
|
||||
// e.printStackTrace()
|
||||
// }
|
||||
// return items
|
||||
// }
|
||||
private fun getTrendingFromInvidous(context: Context): ArrayList<ResultItem?> {
|
||||
val url = invidousURL + "trending?type=music®ion=" + countryCODE
|
||||
val res = genericArrayRequest(url)
|
||||
try {
|
||||
for (i in 0 until res.length()) {
|
||||
val element = res.getJSONObject(i)
|
||||
if (element.getString("type") != "video") continue
|
||||
val v = createVideofromInvidiousJSON(element)
|
||||
if (v == null || v.thumb.isEmpty()) continue
|
||||
v.playlistTitle = context.getString(R.string.trendingPlaylist)
|
||||
items.add(v)
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
e.printStackTrace()
|
||||
}
|
||||
return items
|
||||
}
|
||||
|
||||
fun getIDFromYoutubeURL(inputQuery: String) : String {
|
||||
var el: Array<String?> =
|
||||
|
|
|
|||
5
app/src/main/res/drawable/ic_format.xml
Normal file
5
app/src/main/res/drawable/ic_format.xml
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
<vector android:height="24dp"
|
||||
android:viewportHeight="24" android:viewportWidth="24"
|
||||
android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<path android:fillColor="?android:colorAccent" android:pathData="M19,3L5,3c-1.11,0 -2,0.9 -2,2v14c0,1.1 0.89,2 2,2h14c1.1,0 2,-0.9 2,-2L21,5c0,-1.1 -0.9,-2 -2,-2zM11,15L9.5,15v-2h-2v2L6,15L6,9h1.5v2.5h2L9.5,9L11,9v6zM13,9h4c0.55,0 1,0.45 1,1v4c0,0.55 -0.45,1 -1,1h-4L13,9zM14.5,13.5h2v-3h-2v3z"/>
|
||||
</vector>
|
||||
|
|
@ -71,7 +71,9 @@
|
|||
<com.google.android.material.appbar.AppBarLayout
|
||||
android:id="@+id/home_appbarlayout"
|
||||
app:liftOnScroll="true"
|
||||
android:background="@android:color/transparent"
|
||||
android:background="@null"
|
||||
android:elevation="0dp"
|
||||
app:elevation="0dp"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content">
|
||||
|
||||
|
|
|
|||
|
|
@ -188,4 +188,5 @@
|
|||
<string name="dont_ask_again">Don\'t ask again</string>
|
||||
<string name="end">End</string>
|
||||
<string name="start">Start</string>
|
||||
<string name="update_formats_summary">Automatically search for missing formats when clicking the format card</string>
|
||||
</resources>
|
||||
|
|
@ -246,6 +246,14 @@
|
|||
android:title="@string/update_ytdl_nightly"
|
||||
/>
|
||||
|
||||
<SwitchPreferenceCompat
|
||||
android:widgetLayout="@layout/preferece_material_switch"
|
||||
app:defaultValue="false"
|
||||
android:icon="@drawable/ic_format"
|
||||
android:key="update_formats"
|
||||
app:summary="@string/update_formats_summary"
|
||||
app:title="@string/update_formats" />
|
||||
|
||||
<SwitchPreferenceCompat
|
||||
android:widgetLayout="@layout/preferece_material_switch"
|
||||
app:defaultValue="true"
|
||||
|
|
|
|||
Loading…
Reference in a new issue