Add implementation of the downloaded list view
This commit is contained in:
parent
28dc11863c
commit
f716ff6cb1
@ -7,6 +7,7 @@
|
||||
<option name="testRunner" value="GRADLE" />
|
||||
<option name="distributionType" value="DEFAULT_WRAPPED" />
|
||||
<option name="externalProjectPath" value="$PROJECT_DIR$" />
|
||||
<option name="gradleJvm" value="11" />
|
||||
<option name="modules">
|
||||
<set>
|
||||
<option value="$PROJECT_DIR$" />
|
||||
|
@ -2,18 +2,28 @@ package com.example.myapplication
|
||||
|
||||
import android.os.Bundle
|
||||
import android.view.Menu
|
||||
import com.google.android.material.bottomnavigation.BottomNavigationView
|
||||
import android.view.MenuItem
|
||||
import android.view.View
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
import androidx.navigation.findNavController
|
||||
import androidx.navigation.ui.AppBarConfiguration
|
||||
import androidx.navigation.ui.setupActionBarWithNavController
|
||||
import androidx.navigation.ui.setupWithNavController
|
||||
import androidx.recyclerview.widget.LinearLayoutManager
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import com.example.myapplication.databinding.ActivityMainBinding
|
||||
import com.example.myapplication.ui.compressing.CompressingAdapter
|
||||
import com.example.myapplication.ui.compressing.CompressingItem
|
||||
import com.google.android.material.bottomnavigation.BottomNavigationView
|
||||
import java.util.*
|
||||
|
||||
class MainActivity : AppCompatActivity() {
|
||||
|
||||
private val compressingItems: MutableList<CompressingItem> = mutableListOf()
|
||||
|
||||
private lateinit var binding: ActivityMainBinding
|
||||
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
|
||||
@ -35,4 +45,15 @@ class MainActivity : AppCompatActivity() {
|
||||
menuInflater.inflate(R.menu.action_bar_menu, menu)
|
||||
return super.onCreateOptionsMenu(menu)
|
||||
}
|
||||
|
||||
override fun onOptionsItemSelected(item: MenuItem): Boolean {
|
||||
if (item.itemId == R.id.add) {
|
||||
val compressingRecycler = findViewById<View>(R.id.compressing_recycler_view) as? RecyclerView
|
||||
compressingRecycler?.adapter = CompressingAdapter(compressingItems)
|
||||
compressingRecycler?.layoutManager = LinearLayoutManager(this)
|
||||
val compressingItem = CompressingItem("Testing", 0.5, Date(1))
|
||||
compressingItems.add(compressingItem)
|
||||
}
|
||||
return super.onOptionsItemSelected(item)
|
||||
}
|
||||
}
|
@ -0,0 +1,34 @@
|
||||
package com.example.myapplication.ui.compressing
|
||||
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import android.widget.ProgressBar
|
||||
import android.widget.TextView
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import com.example.myapplication.R
|
||||
|
||||
class CompressingAdapter(private val mCompressingItems: MutableList<CompressingItem>): RecyclerView.Adapter<CompressingAdapter.ViewHolder>() {
|
||||
inner class ViewHolder(itemView: View): RecyclerView.ViewHolder(itemView) {
|
||||
val filename: TextView = itemView.findViewById(R.id.compressing_filename)
|
||||
val date: TextView = itemView.findViewById(R.id.compressing_date)
|
||||
val progress: ProgressBar = itemView.findViewById(R.id.compressing_progress)
|
||||
}
|
||||
|
||||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
|
||||
val compressingItemView = LayoutInflater.from(parent.context).inflate(R.layout.item_compressing, parent, false)
|
||||
return ViewHolder(compressingItemView)
|
||||
}
|
||||
|
||||
override fun onBindViewHolder(holder: ViewHolder, position: Int) {
|
||||
val compressingItem: CompressingItem = mCompressingItems[position]
|
||||
holder.filename.text = compressingItem.filename
|
||||
holder.date.text = compressingItem.date.toString()
|
||||
holder.progress.progress = compressingItem.progress.toInt()
|
||||
|
||||
}
|
||||
|
||||
override fun getItemCount(): Int {
|
||||
return mCompressingItems.size
|
||||
}
|
||||
}
|
@ -4,7 +4,6 @@ import android.os.Bundle
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import android.widget.TextView
|
||||
import androidx.fragment.app.Fragment
|
||||
import androidx.lifecycle.ViewModelProvider
|
||||
import com.example.myapplication.databinding.FragmentCompressingBinding
|
||||
@ -17,22 +16,11 @@ class CompressingFragment : Fragment() {
|
||||
// onDestroyView.
|
||||
private val binding get() = _binding!!
|
||||
|
||||
override fun onCreateView(
|
||||
inflater: LayoutInflater,
|
||||
container: ViewGroup?,
|
||||
savedInstanceState: Bundle?
|
||||
): View {
|
||||
val homeViewModel =
|
||||
ViewModelProvider(this).get(CompressingViewModel::class.java)
|
||||
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View {
|
||||
ViewModelProvider(this)[CompressingViewModel::class.java]
|
||||
|
||||
_binding = FragmentCompressingBinding.inflate(inflater, container, false)
|
||||
val root: View = binding.root
|
||||
|
||||
val textView: TextView = binding.textCompressing
|
||||
homeViewModel.text.observe(viewLifecycleOwner) {
|
||||
textView.text = it
|
||||
}
|
||||
return root
|
||||
return binding.root
|
||||
}
|
||||
|
||||
override fun onDestroyView() {
|
||||
|
@ -0,0 +1,5 @@
|
||||
package com.example.myapplication.ui.compressing
|
||||
|
||||
import java.util.Date
|
||||
|
||||
data class CompressingItem(val filename: String, val progress: Double, val date: Date)
|
@ -18,21 +18,14 @@ class SettingsFragment : Fragment() {
|
||||
private val binding get() = _binding!!
|
||||
|
||||
override fun onCreateView(
|
||||
inflater: LayoutInflater,
|
||||
container: ViewGroup?,
|
||||
savedInstanceState: Bundle?
|
||||
inflater: LayoutInflater,
|
||||
container: ViewGroup?,
|
||||
savedInstanceState: Bundle?
|
||||
): View {
|
||||
val homeViewModel =
|
||||
ViewModelProvider(this)[SettingsViewModel::class.java]
|
||||
ViewModelProvider(this)[SettingsViewModel::class.java]
|
||||
|
||||
_binding = FragmentSettingsBinding.inflate(inflater, container, false)
|
||||
val root: View = binding.root
|
||||
|
||||
// val textView: TextView = binding.textSettings
|
||||
// homeViewModel.text.observe(viewLifecycleOwner) {
|
||||
// textView.text = it
|
||||
// }
|
||||
return root
|
||||
return binding.root
|
||||
}
|
||||
|
||||
override fun onDestroyView() {
|
||||
|
@ -1,22 +1,13 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
tools:context=".ui.settings.SettingsFragment">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/text_compressing"
|
||||
<androidx.recyclerview.widget.RecyclerView
|
||||
android:id="@+id/compressing_recycler_view"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="8dp"
|
||||
android:layout_marginTop="8dp"
|
||||
android:layout_marginEnd="8dp"
|
||||
android:textAlignment="center"
|
||||
android:textSize="20sp"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent" />
|
||||
android:layout_height="match_parent" />
|
||||
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
29
app/src/main/res/layout/item_compressing.xml
Normal file
29
app/src/main/res/layout/item_compressing.xml
Normal file
@ -0,0 +1,29 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:orientation="horizontal"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:paddingTop="10dp"
|
||||
android:paddingBottom="10dp">
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/compressing_filename"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/compressing_date"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content" />
|
||||
</LinearLayout>
|
||||
|
||||
<ProgressBar
|
||||
android:id="@+id/compressing_progress"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content" />
|
||||
</LinearLayout>
|
Loading…
Reference in New Issue
Block a user