diff --git a/app/src/main/java/com/deniscerri/ytdlnis/ui/downloadcard/DownloadAudioFragment.kt b/app/src/main/java/com/deniscerri/ytdlnis/ui/downloadcard/DownloadAudioFragment.kt index 6078fc88..18d9d23a 100644 --- a/app/src/main/java/com/deniscerri/ytdlnis/ui/downloadcard/DownloadAudioFragment.kt +++ b/app/src/main/java/com/deniscerri/ytdlnis/ui/downloadcard/DownloadAudioFragment.kt @@ -35,6 +35,7 @@ import com.google.gson.Gson import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.launch import kotlinx.coroutines.withContext +import java.io.File class DownloadAudioFragment(private var resultItem: ResultItem, private var currentDownloadItem: DownloadItem?) : Fragment() { @@ -48,6 +49,7 @@ class DownloadAudioFragment(private var resultItem: ResultItem, private var curr private lateinit var title : TextInputLayout private lateinit var author : TextInputLayout private lateinit var saveDir : TextInputLayout + private lateinit var freeSpace : TextView lateinit var downloadItem : DownloadItem override fun onCreateView( @@ -111,6 +113,11 @@ class DownloadAudioFragment(private var resultItem: ResultItem, private var curr intent.addFlags(Intent.FLAG_GRANT_PERSISTABLE_URI_PERMISSION) audioPathResultLauncher.launch(intent) } + freeSpace = view.findViewById(R.id.freespace) + freeSpace.text = getString(R.string.freespace) + ": " + fileUtil.convertFileSize( + File(fileUtil.formatPath(downloadItem.downloadPath)).freeSpace + ) + var formats = resultItem.formats.filter { it.format_note.contains("audio", ignoreCase = true) } @@ -208,6 +215,10 @@ class DownloadAudioFragment(private var resultItem: ResultItem, private var curr downloadItem.downloadPath = result.data?.data.toString() //downloadViewModel.updateDownload(downloadItem) saveDir.editText?.setText(fileUtil.formatPath(result.data?.data.toString()), TextView.BufferType.EDITABLE) + + freeSpace.text = getString(R.string.freespace) + ": " + fileUtil.convertFileSize( + File(fileUtil.formatPath(downloadItem.downloadPath)).freeSpace + ) } } diff --git a/app/src/main/java/com/deniscerri/ytdlnis/ui/downloadcard/DownloadCommandFragment.kt b/app/src/main/java/com/deniscerri/ytdlnis/ui/downloadcard/DownloadCommandFragment.kt index b02cd4e5..5861097b 100644 --- a/app/src/main/java/com/deniscerri/ytdlnis/ui/downloadcard/DownloadCommandFragment.kt +++ b/app/src/main/java/com/deniscerri/ytdlnis/ui/downloadcard/DownloadCommandFragment.kt @@ -35,6 +35,7 @@ import com.google.gson.Gson import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.launch import kotlinx.coroutines.withContext +import java.io.File class DownloadCommandFragment(private val resultItem: ResultItem, private var currentDownloadItem: DownloadItem?) : Fragment() { private var _binding : FragmentHomeBinding? = null @@ -45,6 +46,7 @@ class DownloadCommandFragment(private val resultItem: ResultItem, private var cu private lateinit var fileUtil : FileUtil private lateinit var uiUtil : UiUtil private lateinit var saveDir : TextInputLayout + private lateinit var freeSpace : TextView lateinit var downloadItem: DownloadItem @@ -76,22 +78,10 @@ class DownloadCommandFragment(private val resultItem: ResultItem, private var cu } } - val sharedPreferences = requireContext().getSharedPreferences("root_preferences", Activity.MODE_PRIVATE) try { val templates : MutableList = withContext(Dispatchers.IO){ commandTemplateViewModel.getAll().toMutableList() } -// val id = sharedPreferences.getLong("commandTemplate", templates[0].id) -// val chosenCommand = templates.find { it.id == id } -// downloadItem.format = Format( -// chosenCommand!!.title, -// "", -// "", -// "", -// "", -// 0, -// chosenCommand.content -// ) val chosenCommandView = view.findViewById(R.id.content) chosenCommandView.editText!!.setText(downloadItem.format.format_note) @@ -160,6 +150,11 @@ class DownloadCommandFragment(private val resultItem: ResultItem, private var cu commandPathResultLauncher.launch(intent) } + freeSpace = view.findViewById(R.id.freespace) + freeSpace.text = getString(R.string.freespace) + ": " + fileUtil.convertFileSize( + File(fileUtil.formatPath(downloadItem.downloadPath)).freeSpace + ) + val newTemplate : Chip = view.findViewById(R.id.newTemplate) newTemplate.setOnClickListener { uiUtil.showCommandTemplateCreationOrUpdatingSheet(null, requireActivity(), viewLifecycleOwner, commandTemplateViewModel) { @@ -240,6 +235,10 @@ class DownloadCommandFragment(private val resultItem: ResultItem, private var cu downloadItem.downloadPath = result.data?.data.toString() //downloadviewmodel.updateDownload(downloadItem) saveDir.editText?.setText(fileUtil.formatPath(result.data?.data.toString()), TextView.BufferType.EDITABLE) + + freeSpace.text = getString(R.string.freespace) + ": " + fileUtil.convertFileSize( + File(fileUtil.formatPath(downloadItem.downloadPath)).freeSpace + ) } } } \ No newline at end of file diff --git a/app/src/main/java/com/deniscerri/ytdlnis/ui/downloadcard/DownloadVideoFragment.kt b/app/src/main/java/com/deniscerri/ytdlnis/ui/downloadcard/DownloadVideoFragment.kt index 15530552..c78d1559 100644 --- a/app/src/main/java/com/deniscerri/ytdlnis/ui/downloadcard/DownloadVideoFragment.kt +++ b/app/src/main/java/com/deniscerri/ytdlnis/ui/downloadcard/DownloadVideoFragment.kt @@ -35,6 +35,7 @@ import com.google.gson.Gson import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.launch import kotlinx.coroutines.withContext +import java.io.File class DownloadVideoFragment(private val resultItem: ResultItem, private var currentDownloadItem: DownloadItem?) : Fragment() { @@ -49,6 +50,7 @@ class DownloadVideoFragment(private val resultItem: ResultItem, private var curr private lateinit var title : TextInputLayout private lateinit var author : TextInputLayout private lateinit var saveDir : TextInputLayout + private lateinit var freeSpace : TextView lateinit var downloadItem: DownloadItem @@ -117,6 +119,11 @@ class DownloadVideoFragment(private val resultItem: ResultItem, private var curr videoPathResultLauncher.launch(intent) } + freeSpace = view.findViewById(R.id.freespace) + freeSpace.text = getString(R.string.freespace) + ": " + fileUtil.convertFileSize( + File(fileUtil.formatPath(downloadItem.downloadPath)).freeSpace + ) + var formats = mutableListOf() formats.addAll(resultItem.formats.filter { !it.format_note.contains("audio", ignoreCase = true) }) val videoFormats = resources.getStringArray(R.array.video_formats) @@ -236,6 +243,10 @@ class DownloadVideoFragment(private val resultItem: ResultItem, private var curr downloadItem.downloadPath = result.data?.data.toString() //downloadviewmodel.updateDownload(downloadItem) saveDir.editText?.setText(fileUtil.formatPath(result.data?.data.toString()), TextView.BufferType.EDITABLE) + + freeSpace.text = getString(R.string.freespace) + ": " + fileUtil.convertFileSize( + File(fileUtil.formatPath(downloadItem.downloadPath)).freeSpace + ) } } diff --git a/app/src/main/res/layout/fragment_download_audio.xml b/app/src/main/res/layout/fragment_download_audio.xml index 8e18fc7f..d56bfe83 100644 --- a/app/src/main/res/layout/fragment_download_audio.xml +++ b/app/src/main/res/layout/fragment_download_audio.xml @@ -149,6 +149,14 @@ + + + + + + + Temporary files cleared Download worker is running. Try again later yt-dlp Version + Free space \ No newline at end of file