diff --git a/app/src/main/java/com/github/libretube/adapters/DownloadsAdapter.kt b/app/src/main/java/com/github/libretube/adapters/DownloadsAdapter.kt new file mode 100644 index 000000000..978b87d62 --- /dev/null +++ b/app/src/main/java/com/github/libretube/adapters/DownloadsAdapter.kt @@ -0,0 +1,38 @@ +package com.github.libretube.adapters + +import android.annotation.SuppressLint +import android.view.LayoutInflater +import android.view.ViewGroup +import androidx.recyclerview.widget.RecyclerView +import com.github.libretube.databinding.DownloadedMediaRowBinding +import java.io.File + +class DownloadsAdapter( + private val files: List +) : RecyclerView.Adapter() { + override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): DownloadsViewHolder { + val binding = DownloadedMediaRowBinding.inflate( + LayoutInflater.from(parent.context), + parent, + false + ) + return DownloadsViewHolder(binding) + } + + @SuppressLint("SetTextI18n") + override fun onBindViewHolder(holder: DownloadsViewHolder, position: Int) { + val file = files[position] + holder.binding.apply { + fileName.text = file.name + fileSize.text = "${file.length() / (1024 * 1024)} MiB" + } + } + + override fun getItemCount(): Int { + return files.size + } +} + +class DownloadsViewHolder( + val binding: DownloadedMediaRowBinding +) : RecyclerView.ViewHolder(binding.root) diff --git a/app/src/main/java/com/github/libretube/fragments/DownloadsFragment.kt b/app/src/main/java/com/github/libretube/fragments/DownloadsFragment.kt new file mode 100644 index 000000000..3722a78a0 --- /dev/null +++ b/app/src/main/java/com/github/libretube/fragments/DownloadsFragment.kt @@ -0,0 +1,38 @@ +package layout + +import android.os.Bundle +import android.view.LayoutInflater +import android.view.View +import android.view.ViewGroup +import androidx.recyclerview.widget.LinearLayoutManager +import com.github.libretube.adapters.DownloadsAdapter +import com.github.libretube.databinding.FragmentDownloadsBinding +import com.github.libretube.extensions.BaseFragment +import java.io.File + +class DownloadsFragment : BaseFragment() { + private lateinit var binding: FragmentDownloadsBinding + + override fun onCreateView( + inflater: LayoutInflater, + container: ViewGroup?, + savedInstanceState: Bundle? + ): View { + binding = FragmentDownloadsBinding.inflate(layoutInflater) + return binding.root + } + + override fun onViewCreated(view: View, savedInstanceState: Bundle?) { + super.onViewCreated(view, savedInstanceState) + + val downloadDir = File( + context?.getExternalFilesDir(null), + "video" + ) + + binding.downloads.layoutManager = LinearLayoutManager(context) + binding.downloads.adapter = DownloadsAdapter( + downloadDir.listFiles()?.toList() ?: listOf() + ) + } +} diff --git a/app/src/main/res/layout/downloaded_media_row.xml b/app/src/main/res/layout/downloaded_media_row.xml new file mode 100644 index 000000000..6f11d1877 --- /dev/null +++ b/app/src/main/res/layout/downloaded_media_row.xml @@ -0,0 +1,19 @@ + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/fragment_downloads.xml b/app/src/main/res/layout/fragment_downloads.xml new file mode 100644 index 000000000..7ae172103 --- /dev/null +++ b/app/src/main/res/layout/fragment_downloads.xml @@ -0,0 +1,11 @@ + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/fragment_library.xml b/app/src/main/res/layout/fragment_library.xml index 4287fa15e..dfa0b5e8d 100644 --- a/app/src/main/res/layout/fragment_library.xml +++ b/app/src/main/res/layout/fragment_library.xml @@ -73,6 +73,32 @@ + + + + + + + +