diff --git a/.idea/gradle.xml b/.idea/gradle.xml index a2d7c21..7b46144 100644 --- a/.idea/gradle.xml +++ b/.idea/gradle.xml @@ -7,6 +7,7 @@ + diff --git a/app/src/main/java/com/example/myapplication/MainActivity.kt b/app/src/main/java/com/example/myapplication/MainActivity.kt index 3394e95..ffbf8b7 100644 --- a/app/src/main/java/com/example/myapplication/MainActivity.kt +++ b/app/src/main/java/com/example/myapplication/MainActivity.kt @@ -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 = 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(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) + } } \ No newline at end of file diff --git a/app/src/main/java/com/example/myapplication/ui/compressing/CompressingAdapter.kt b/app/src/main/java/com/example/myapplication/ui/compressing/CompressingAdapter.kt new file mode 100644 index 0000000..343ce7b --- /dev/null +++ b/app/src/main/java/com/example/myapplication/ui/compressing/CompressingAdapter.kt @@ -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): RecyclerView.Adapter() { + 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 + } +} \ No newline at end of file diff --git a/app/src/main/java/com/example/myapplication/ui/compressing/CompressingFragment.kt b/app/src/main/java/com/example/myapplication/ui/compressing/CompressingFragment.kt index 4c99a79..ec5d3ef 100644 --- a/app/src/main/java/com/example/myapplication/ui/compressing/CompressingFragment.kt +++ b/app/src/main/java/com/example/myapplication/ui/compressing/CompressingFragment.kt @@ -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() { diff --git a/app/src/main/java/com/example/myapplication/ui/compressing/CompressingItem.kt b/app/src/main/java/com/example/myapplication/ui/compressing/CompressingItem.kt new file mode 100644 index 0000000..df3ab72 --- /dev/null +++ b/app/src/main/java/com/example/myapplication/ui/compressing/CompressingItem.kt @@ -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) \ No newline at end of file diff --git a/app/src/main/java/com/example/myapplication/ui/settings/SettingsFragment.kt b/app/src/main/java/com/example/myapplication/ui/settings/SettingsFragment.kt index 92669d7..8263de3 100644 --- a/app/src/main/java/com/example/myapplication/ui/settings/SettingsFragment.kt +++ b/app/src/main/java/com/example/myapplication/ui/settings/SettingsFragment.kt @@ -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() { diff --git a/app/src/main/res/layout/fragment_compressing.xml b/app/src/main/res/layout/fragment_compressing.xml index 2c7bf96..fe873fe 100644 --- a/app/src/main/res/layout/fragment_compressing.xml +++ b/app/src/main/res/layout/fragment_compressing.xml @@ -1,22 +1,13 @@ - + android:layout_height="match_parent" /> + \ No newline at end of file diff --git a/app/src/main/res/layout/item_compressing.xml b/app/src/main/res/layout/item_compressing.xml new file mode 100644 index 0000000..736978f --- /dev/null +++ b/app/src/main/res/layout/item_compressing.xml @@ -0,0 +1,29 @@ + + + + + + + + + + + \ No newline at end of file