mirror of
https://github.com/libre-tube/LibreTube.git
synced 2024-12-15 06:40:30 +05:30
add download fragment
This commit is contained in:
parent
193c9b0e46
commit
6bb065a870
@ -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<File>
|
||||
) : RecyclerView.Adapter<DownloadsViewHolder>() {
|
||||
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)
|
@ -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()
|
||||
)
|
||||
}
|
||||
}
|
19
app/src/main/res/layout/downloaded_media_row.xml
Normal file
19
app/src/main/res/layout/downloaded_media_row.xml
Normal file
@ -0,0 +1,19 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:orientation="horizontal"
|
||||
android:paddingHorizontal="10dp">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/fileName"
|
||||
android:layout_width="0dp"
|
||||
android:layout_weight="1"
|
||||
android:layout_height="wrap_content" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/fileSize"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content" />
|
||||
|
||||
</LinearLayout>
|
11
app/src/main/res/layout/fragment_downloads.xml
Normal file
11
app/src/main/res/layout/fragment_downloads.xml
Normal file
@ -0,0 +1,11 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
|
||||
<androidx.recyclerview.widget.RecyclerView
|
||||
android:id="@+id/downloads"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content" />
|
||||
|
||||
</LinearLayout>
|
@ -73,6 +73,32 @@
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/downloads"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginBottom="10dp"
|
||||
android:background="?attr/selectableItemBackground"
|
||||
android:orientation="horizontal"
|
||||
android:padding="10dp">
|
||||
|
||||
<ImageView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center"
|
||||
android:layout_marginStart="10dp"
|
||||
android:src="@drawable/ic_download" />
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="15dp"
|
||||
android:text="@string/downloads"
|
||||
android:textSize="18sp"
|
||||
android:textStyle="bold" />
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<RelativeLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
|
Loading…
Reference in New Issue
Block a user