prevented card from duplicating when switching formats
This commit is contained in:
parent
e78f83ac73
commit
4d859ee8d4
22 changed files with 89 additions and 72 deletions
|
|
@ -55,7 +55,7 @@
|
|||
</intent-filter>
|
||||
</activity>
|
||||
<activity
|
||||
android:name=".ui.downloadLogs.DownloadLogListActivity"
|
||||
android:name=".ui.more.downloadLogs.DownloadLogListActivity"
|
||||
android:configChanges="layoutDirection|locale"
|
||||
android:parentActivityName=".MainActivity"
|
||||
android:exported="true">
|
||||
|
|
@ -75,9 +75,9 @@
|
|||
</intent-filter>
|
||||
</activity>
|
||||
<activity
|
||||
android:name=".ui.downloadLogs.DownloadLogActivity"
|
||||
android:name=".ui.more.downloadLogs.DownloadLogActivity"
|
||||
android:configChanges="layoutDirection|locale"
|
||||
android:parentActivityName=".ui.downloadLogs.DownloadLogListActivity"
|
||||
android:parentActivityName=".ui.more.downloadLogs.DownloadLogListActivity"
|
||||
android:exported="true">
|
||||
<intent-filter>
|
||||
<action android:name="ytdlnis.downloadLogs.DownloadLogActivity" />
|
||||
|
|
@ -85,7 +85,7 @@
|
|||
</intent-filter>
|
||||
</activity>
|
||||
<activity
|
||||
android:name=".ui.settings.SettingsActivity"
|
||||
android:name=".ui.more.settings.SettingsActivity"
|
||||
android:configChanges="layoutDirection|locale"
|
||||
android:parentActivityName=".MainActivity"
|
||||
android:exported="true">
|
||||
|
|
@ -95,7 +95,7 @@
|
|||
</intent-filter>
|
||||
</activity>
|
||||
<activity
|
||||
android:name=".ui.CustomCommandActivity"
|
||||
android:name=".ui.more.CustomCommandActivity"
|
||||
android:configChanges="layoutDirection|locale"
|
||||
android:theme="@style/AppDefaultTheme"
|
||||
android:parentActivityName=".MainActivity"
|
||||
|
|
|
|||
|
|
@ -52,11 +52,6 @@ class App : Application() {
|
|||
.getInt("concurrent_downloads", 1)))
|
||||
.build())
|
||||
|
||||
|
||||
|
||||
val locale = getSharedPreferences("root_preferences", MODE_PRIVATE)
|
||||
.getString("app_language", Locale.getDefault().language)!!
|
||||
AppCompatDelegate.setApplicationLocales(LocaleListCompat.forLanguageTags(locale))
|
||||
}
|
||||
@Throws(YoutubeDLException::class)
|
||||
private fun initLibraries() {
|
||||
|
|
|
|||
|
|
@ -1,7 +1,6 @@
|
|||
package com.deniscerri.ytdlnis
|
||||
|
||||
import android.Manifest
|
||||
import android.content.ClipboardManager
|
||||
import android.content.Context
|
||||
import android.content.DialogInterface
|
||||
import android.content.Intent
|
||||
|
|
@ -17,7 +16,6 @@ import android.view.MenuItem
|
|||
import android.view.View
|
||||
import android.view.WindowInsets
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
import androidx.coordinatorlayout.widget.CoordinatorLayout
|
||||
import androidx.core.app.ActivityCompat
|
||||
import androidx.core.view.WindowInsetsCompat
|
||||
import androidx.fragment.app.Fragment
|
||||
|
|
@ -29,11 +27,10 @@ import com.deniscerri.ytdlnis.service.IDownloaderService
|
|||
import com.deniscerri.ytdlnis.ui.DownloadQueueActivity
|
||||
import com.deniscerri.ytdlnis.ui.HistoryFragment
|
||||
import com.deniscerri.ytdlnis.ui.HomeFragment
|
||||
import com.deniscerri.ytdlnis.ui.MoreFragment
|
||||
import com.deniscerri.ytdlnis.ui.settings.SettingsActivity
|
||||
import com.deniscerri.ytdlnis.ui.more.MoreFragment
|
||||
import com.deniscerri.ytdlnis.ui.more.settings.SettingsActivity
|
||||
import com.deniscerri.ytdlnis.util.UpdateUtil
|
||||
import com.google.android.material.dialog.MaterialAlertDialogBuilder
|
||||
import com.google.android.material.snackbar.Snackbar
|
||||
import java.io.BufferedReader
|
||||
import java.io.File
|
||||
import java.io.InputStreamReader
|
||||
|
|
|
|||
|
|
@ -49,22 +49,10 @@ class ResultRepository(private val resultDao: ResultDao, private val commandTemp
|
|||
}
|
||||
|
||||
suspend fun getOne(inputQuery: String, resetResults: Boolean) : ArrayList<ResultItem?>{
|
||||
var el: Array<String?> =
|
||||
inputQuery.split("/".toRegex()).dropLastWhile { it.isEmpty() }
|
||||
.toTypedArray()
|
||||
var query = el[el.size - 1]
|
||||
if (query!!.contains("watch?v=")) {
|
||||
query = query.substring(8)
|
||||
}
|
||||
el = query.split("&".toRegex()).dropLastWhile { it.isEmpty() }
|
||||
.toTypedArray()
|
||||
query = el[0]
|
||||
el = query!!.split("\\?".toRegex()).dropLastWhile { it.isEmpty() }
|
||||
.toTypedArray()
|
||||
query = el[0]
|
||||
val infoUtil = InfoUtil(context)
|
||||
val query = infoUtil.getIDFromYoutubeURL(inputQuery)
|
||||
try {
|
||||
val v = infoUtil.getVideo(query!!)
|
||||
val v = infoUtil.getVideo(query)
|
||||
if (resetResults) deleteAll()
|
||||
itemCount.postValue(1)
|
||||
resultDao.insert(v!!)
|
||||
|
|
|
|||
|
|
@ -108,7 +108,7 @@ class ShareActivity : AppCompatActivity() {
|
|||
}
|
||||
|
||||
resultViewModel.items.observe(this) {
|
||||
if (it.isNotEmpty()){
|
||||
if (it.isNotEmpty() && supportFragmentManager.findFragmentByTag("downloadSingleSheet") == null){
|
||||
if(resultViewModel.itemCount.value!! == it.size){
|
||||
loadingBottomSheet.cancel()
|
||||
showDownloadSheet(it[0])
|
||||
|
|
@ -211,6 +211,5 @@ class ShareActivity : AppCompatActivity() {
|
|||
|
||||
companion object {
|
||||
private const val TAG = "ShareActivity"
|
||||
|
||||
}
|
||||
}
|
||||
|
|
@ -162,10 +162,10 @@ class DownloadAudioFragment(private var resultItem: ResultItem) : Fragment() {
|
|||
if (containers.contains(formats[formats.lastIndex].container)){
|
||||
formats[formats.lastIndex].container
|
||||
}else{
|
||||
containers[0]
|
||||
sharedPreferences.getString("audio_format", "mp3")!!
|
||||
}
|
||||
}catch (e: Exception){
|
||||
containers[0]
|
||||
sharedPreferences.getString("audio_format", "mp3")!!
|
||||
}
|
||||
|
||||
downloadItem.format.container = selectedContainer
|
||||
|
|
|
|||
|
|
@ -135,7 +135,7 @@ class DownloadBottomSheetDialog(private val resultItem: ResultItem, private val
|
|||
|
||||
|
||||
val timepicker = MaterialTimePicker.Builder()
|
||||
.setTimeFormat(TimeFormat.CLOCK_12H)
|
||||
.setTimeFormat(TimeFormat.CLOCK_24H)
|
||||
.setHour(currentDate.get(Calendar.HOUR_OF_DAY))
|
||||
.setMinute(currentDate.get(Calendar.MINUTE))
|
||||
.build()
|
||||
|
|
|
|||
|
|
@ -58,7 +58,7 @@ class DownloadVideoFragment(private val resultItem: ResultItem) : Fragment() {
|
|||
fragmentView = inflater.inflate(R.layout.fragment_download_video, container, false)
|
||||
activity = getActivity()
|
||||
downloadViewModel = ViewModelProvider(this)[DownloadViewModel::class.java]
|
||||
resultViewModel = ViewModelProvider(this)[ResultViewModel::class.java]
|
||||
resultViewModel = ViewModelProvider(this@DownloadVideoFragment)[ResultViewModel::class.java]
|
||||
downloadItem = downloadViewModel.createDownloadItemFromResult(resultItem, Type.video)
|
||||
fileUtil = FileUtil()
|
||||
uiUtil = UiUtil(fileUtil)
|
||||
|
|
@ -151,7 +151,12 @@ class DownloadVideoFragment(private val resultItem: ResultItem) : Fragment() {
|
|||
}else{
|
||||
containerAutoCompleteTextView.setText(containers[0], false)
|
||||
}
|
||||
|
||||
lifecycleScope.launch {
|
||||
withContext(Dispatchers.IO){
|
||||
resultItem.formats = ArrayList(allFormats)
|
||||
resultViewModel.update(resultItem)
|
||||
}
|
||||
}
|
||||
formats = allFormats.toMutableList()
|
||||
uiUtil.populateFormatCard(formatCard, item)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -17,6 +17,7 @@ import androidx.coordinatorlayout.widget.CoordinatorLayout
|
|||
import androidx.core.view.get
|
||||
import androidx.core.view.size
|
||||
import androidx.lifecycle.ViewModelProvider
|
||||
import androidx.lifecycle.lifecycleScope
|
||||
import androidx.viewpager2.widget.ViewPager2
|
||||
import com.deniscerri.ytdlnis.R
|
||||
import com.deniscerri.ytdlnis.database.models.DownloadItem
|
||||
|
|
@ -37,6 +38,9 @@ import com.google.android.material.datepicker.MaterialDatePicker
|
|||
import com.google.android.material.tabs.TabLayout
|
||||
import com.google.android.material.timepicker.MaterialTimePicker
|
||||
import com.google.android.material.timepicker.TimeFormat
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.launch
|
||||
import kotlinx.coroutines.withContext
|
||||
import java.util.*
|
||||
|
||||
|
||||
|
|
@ -73,20 +77,24 @@ class FormatSelectionBottomSheetDialog(private val item: DownloadItem, private v
|
|||
val refreshBtn = view.findViewById<Button>(R.id.format_refresh)
|
||||
if (formats.none { it.filesize == 0L }) refreshBtn.visibility = View.GONE
|
||||
refreshBtn.setOnClickListener {
|
||||
try {
|
||||
refreshBtn.isEnabled = false
|
||||
val res = infoUtil.getFromYTDL(item.url)
|
||||
formats = res[0]!!.formats.filter { it.filesize != 0L }
|
||||
formats = when(item.type){
|
||||
Type.audio -> formats.filter { it.format_note.contains("audio", ignoreCase = true) }
|
||||
else -> formats.filter { !it.format_note.contains("audio", ignoreCase = true) }
|
||||
lifecycleScope.launch {
|
||||
try {
|
||||
refreshBtn.isEnabled = false
|
||||
val res = withContext(Dispatchers.IO){
|
||||
infoUtil.getFormats(item.url)
|
||||
}
|
||||
formats = res.formats.filter { it.filesize != 0L }
|
||||
formats = when(item.type){
|
||||
Type.audio -> formats.filter { it.format_note.contains("audio", ignoreCase = true) }
|
||||
else -> formats.filter { !it.format_note.contains("audio", ignoreCase = true) }
|
||||
}
|
||||
addFormatsToView(linearLayout)
|
||||
refreshBtn.visibility = View.GONE
|
||||
}catch (e: Exception){
|
||||
refreshBtn.isEnabled = true
|
||||
e.printStackTrace()
|
||||
Toast.makeText(context, getString(R.string.error_updating_formats), Toast.LENGTH_SHORT).show()
|
||||
}
|
||||
addFormatsToView(linearLayout)
|
||||
refreshBtn.visibility = View.GONE
|
||||
}catch (e: Exception){
|
||||
refreshBtn.isEnabled = true
|
||||
e.printStackTrace()
|
||||
Toast.makeText(context, getString(R.string.error_updating_formats), Toast.LENGTH_SHORT).show()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
package com.deniscerri.ytdlnis.ui
|
||||
package com.deniscerri.ytdlnis.ui.more
|
||||
|
||||
import android.Manifest
|
||||
import android.app.Notification
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
package com.deniscerri.ytdlnis.ui
|
||||
package com.deniscerri.ytdlnis.ui.more
|
||||
|
||||
import android.app.Activity
|
||||
import android.app.Application
|
||||
|
|
@ -1,17 +1,14 @@
|
|||
package com.deniscerri.ytdlnis.ui.downloadLogs
|
||||
package com.deniscerri.ytdlnis.ui.more.downloadLogs
|
||||
|
||||
import android.content.Context
|
||||
import android.os.Build
|
||||
import android.os.Bundle
|
||||
import android.os.FileObserver
|
||||
import android.util.Log
|
||||
import android.view.View
|
||||
import android.widget.TextView
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
import androidx.core.widget.NestedScrollView
|
||||
import com.deniscerri.ytdlnis.R
|
||||
import com.google.android.material.appbar.MaterialToolbar
|
||||
import kotlinx.coroutines.runBlocking
|
||||
import java.io.File
|
||||
|
||||
|
||||
|
|
@ -1,27 +1,19 @@
|
|||
package com.deniscerri.ytdlnis.ui.downloadLogs
|
||||
package com.deniscerri.ytdlnis.ui.more.downloadLogs
|
||||
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.os.*
|
||||
import android.text.InputType
|
||||
import android.util.Log
|
||||
import android.view.LayoutInflater
|
||||
import android.view.MenuItem
|
||||
import android.view.View
|
||||
import android.widget.RelativeLayout
|
||||
import android.widget.TextView
|
||||
import android.widget.Toast
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
import androidx.appcompat.widget.SearchView
|
||||
import androidx.recyclerview.widget.LinearLayoutManager
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import com.deniscerri.ytdlnis.R
|
||||
import com.deniscerri.ytdlnis.adapter.DownloadLogsAdapter
|
||||
import com.deniscerri.ytdlnis.util.InfoUtil
|
||||
import com.google.android.material.appbar.MaterialToolbar
|
||||
import com.google.android.material.button.MaterialButton
|
||||
import java.io.File
|
||||
import java.util.ArrayList
|
||||
|
||||
|
||||
class DownloadLogListActivity : AppCompatActivity(), DownloadLogsAdapter.OnItemClickListener {
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
package com.deniscerri.ytdlnis.ui.settings
|
||||
package com.deniscerri.ytdlnis.ui.more.settings
|
||||
|
||||
import android.content.Context
|
||||
import android.content.res.Configuration
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
package com.deniscerri.ytdlnis.ui.settings
|
||||
package com.deniscerri.ytdlnis.ui.more.settings
|
||||
|
||||
import android.app.Activity
|
||||
import android.content.Intent
|
||||
|
|
@ -20,6 +20,7 @@ import java.io.InputStreamReader
|
|||
import java.net.HttpURLConnection
|
||||
import java.net.URL
|
||||
import java.util.*
|
||||
import java.util.regex.Pattern
|
||||
import kotlin.collections.ArrayList
|
||||
|
||||
class InfoUtil(context: Context) {
|
||||
|
|
@ -449,6 +450,41 @@ class InfoUtil(context: Context) {
|
|||
return items
|
||||
}
|
||||
|
||||
fun getIDFromYoutubeURL(inputQuery: String) : String {
|
||||
var el: Array<String?> =
|
||||
inputQuery.split("/".toRegex()).dropLastWhile { it.isEmpty() }
|
||||
.toTypedArray()
|
||||
var query = el[el.size - 1]
|
||||
if (query!!.contains("watch?v=")) {
|
||||
query = query.substring(8)
|
||||
}
|
||||
el = query.split("&".toRegex()).dropLastWhile { it.isEmpty() }
|
||||
.toTypedArray()
|
||||
query = el[0]
|
||||
el = query!!.split("\\?".toRegex()).dropLastWhile { it.isEmpty() }
|
||||
.toTypedArray()
|
||||
query = el[0]
|
||||
return query!!
|
||||
}
|
||||
|
||||
fun getFormats(url: String) : ResultItem {
|
||||
init()
|
||||
val p = Pattern.compile("^(https?)://(www.)?youtu(.be)?")
|
||||
val m = p.matcher(url)
|
||||
return if(m.find() && useInvidous){
|
||||
val id = getIDFromYoutubeURL(url)
|
||||
Log.e("Aa", id)
|
||||
val res = genericRequest(invidousURL + "videos/" + id)
|
||||
Log.e("aa", res.toString())
|
||||
if (res.length() == 0) getFromYTDL(url)[0]!!
|
||||
else createVideofromInvidiousJSON(
|
||||
res
|
||||
)!!
|
||||
}else{
|
||||
getFromYTDL(url)[0]!!
|
||||
}
|
||||
}
|
||||
|
||||
fun getFromYTDL(query: String): ArrayList<ResultItem?> {
|
||||
init()
|
||||
items = ArrayList()
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@
|
|||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
tools:context="com.deniscerri.ytdlnis.ui.CustomCommandActivity">
|
||||
tools:context="com.deniscerri.ytdlnis.ui.more.CustomCommandActivity">
|
||||
|
||||
<com.google.android.material.appbar.AppBarLayout
|
||||
android:layout_width="match_parent"
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@
|
|||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
tools:context="com.deniscerri.ytdlnis.ui.CustomCommandActivity">
|
||||
tools:context="com.deniscerri.ytdlnis.ui.more.CustomCommandActivity">
|
||||
|
||||
<FrameLayout
|
||||
android:id="@+id/custom_command_frame_layout"
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@
|
|||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
tools:context="com.deniscerri.ytdlnis.ui.CustomCommandActivity">
|
||||
tools:context="com.deniscerri.ytdlnis.ui.more.CustomCommandActivity">
|
||||
|
||||
<com.google.android.material.appbar.AppBarLayout
|
||||
android:layout_width="match_parent"
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@
|
|||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
tools:context="com.deniscerri.ytdlnis.ui.CustomCommandActivity">
|
||||
tools:context="com.deniscerri.ytdlnis.ui.more.CustomCommandActivity">
|
||||
|
||||
<com.google.android.material.appbar.AppBarLayout
|
||||
android:layout_width="match_parent"
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@
|
|||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
tools:context="com.deniscerri.ytdlnis.ui.CustomCommandActivity">
|
||||
tools:context="com.deniscerri.ytdlnis.ui.more.CustomCommandActivity">
|
||||
|
||||
<com.google.android.material.appbar.AppBarLayout
|
||||
android:layout_width="match_parent"
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@
|
|||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
tools:context="com.deniscerri.ytdlnis.ui.settings.SettingsActivity">
|
||||
tools:context="com.deniscerri.ytdlnis.ui.more.settings.SettingsActivity">
|
||||
|
||||
<FrameLayout
|
||||
android:id="@+id/settings_frame_layout"
|
||||
|
|
|
|||
Loading…
Reference in a new issue