Clean up code
This commit is contained in:
		@@ -46,7 +46,8 @@ class MainActivity : AppCompatActivity() {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        // VERIFY PERMISSIONS
 | 
					        // VERIFY PERMISSIONS
 | 
				
			||||||
        val permission = ActivityCompat.checkSelfPermission(this, Manifest.permission.READ_EXTERNAL_STORAGE)
 | 
					        val permission =
 | 
				
			||||||
 | 
					            ActivityCompat.checkSelfPermission(this, Manifest.permission.READ_EXTERNAL_STORAGE)
 | 
				
			||||||
        if (permission != PackageManager.PERMISSION_GRANTED) {
 | 
					        if (permission != PackageManager.PERMISSION_GRANTED) {
 | 
				
			||||||
            ActivityCompat.requestPermissions(
 | 
					            ActivityCompat.requestPermissions(
 | 
				
			||||||
                this,
 | 
					                this,
 | 
				
			||||||
@@ -63,8 +64,11 @@ class MainActivity : AppCompatActivity() {
 | 
				
			|||||||
        val navController = findNavController(R.id.nav_host_fragment_activity_main)
 | 
					        val navController = findNavController(R.id.nav_host_fragment_activity_main)
 | 
				
			||||||
        // Passing each menu ID as a set of Ids because each
 | 
					        // Passing each menu ID as a set of Ids because each
 | 
				
			||||||
        // menu should be considered as top level destinations.
 | 
					        // menu should be considered as top level destinations.
 | 
				
			||||||
        val appBarConfiguration = AppBarConfiguration(setOf(
 | 
					        val appBarConfiguration = AppBarConfiguration(
 | 
				
			||||||
                R.id.navigation_compressing, R.id.navigation_completed,R.id.navigation_settings))
 | 
					            setOf(
 | 
				
			||||||
 | 
					                R.id.navigation_compressing, R.id.navigation_completed, R.id.navigation_settings
 | 
				
			||||||
 | 
					            )
 | 
				
			||||||
 | 
					        )
 | 
				
			||||||
        setupActionBarWithNavController(navController, appBarConfiguration)
 | 
					        setupActionBarWithNavController(navController, appBarConfiguration)
 | 
				
			||||||
        navView.setupWithNavController(navController)
 | 
					        navView.setupWithNavController(navController)
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
@@ -81,7 +85,6 @@ class MainActivity : AppCompatActivity() {
 | 
				
			|||||||
        return when (item.itemId) {
 | 
					        return when (item.itemId) {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					 | 
				
			||||||
            //runs when pressing "Files"
 | 
					            //runs when pressing "Files"
 | 
				
			||||||
            R.id.addFile -> {
 | 
					            R.id.addFile -> {
 | 
				
			||||||
                val intent = Intent()
 | 
					                val intent = Intent()
 | 
				
			||||||
@@ -93,12 +96,14 @@ class MainActivity : AppCompatActivity() {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
                resultLauncher.launch(intent)
 | 
					                resultLauncher.launch(intent)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                //Toast.makeText(applicationContext, "Files", Toast.LENGTH_LONG).show()
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
                return true
 | 
					                return true
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
            R.id.addYoutube ->{
 | 
					            R.id.addYoutube -> {
 | 
				
			||||||
                Toast.makeText(applicationContext, "Youtube downloading is currently not available", Toast.LENGTH_LONG).show()
 | 
					                Toast.makeText(
 | 
				
			||||||
 | 
					                    applicationContext,
 | 
				
			||||||
 | 
					                    "Youtube downloading is currently not available",
 | 
				
			||||||
 | 
					                    Toast.LENGTH_LONG
 | 
				
			||||||
 | 
					                ).show()
 | 
				
			||||||
                return true
 | 
					                return true
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
            else -> super.onOptionsItemSelected(item)
 | 
					            else -> super.onOptionsItemSelected(item)
 | 
				
			||||||
@@ -107,68 +112,78 @@ class MainActivity : AppCompatActivity() {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    //grabs output from pressing files, used for grabbing URI
 | 
					    //grabs output from pressing files, used for grabbing URI
 | 
				
			||||||
    @SuppressLint("NotifyDataSetChanged") // Needed because of custom adapter
 | 
					    @SuppressLint("NotifyDataSetChanged") // Needed because of custom adapter
 | 
				
			||||||
    private var resultLauncher = registerForActivityResult(ActivityResultContracts.StartActivityForResult()) { result ->
 | 
					    private var resultLauncher =
 | 
				
			||||||
        if (result.resultCode == RESULT_OK) {
 | 
					        registerForActivityResult(ActivityResultContracts.StartActivityForResult()) { result ->
 | 
				
			||||||
 | 
					            if (result.resultCode == RESULT_OK) {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            // There are no request codes
 | 
					                // There are no request codes
 | 
				
			||||||
            val data: Uri? = result.data?.data
 | 
					                val data: Uri? = result.data?.data
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            val inUri = FFmpegKitConfig.getSafParameterForRead(this, data)
 | 
					                val inUri = FFmpegKitConfig.getSafParameterForRead(this, data)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            val cursor = contentResolver.query(data!!, null, null, null, null)
 | 
					                val cursor = contentResolver.query(data!!, null, null, null, null)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            cursor?.moveToFirst()
 | 
					                cursor?.moveToFirst()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            val fileDate = Date(System.currentTimeMillis())
 | 
					                val fileDate = Date(System.currentTimeMillis())
 | 
				
			||||||
            val fileName =
 | 
					                val fileName =
 | 
				
			||||||
                cursor?.getString(cursor.getColumnIndexOrThrow(MediaStore.MediaColumns.DISPLAY_NAME))
 | 
					                    cursor?.getString(cursor.getColumnIndexOrThrow(MediaStore.MediaColumns.DISPLAY_NAME))
 | 
				
			||||||
            val fileSize =
 | 
					                val fileSize =
 | 
				
			||||||
                cursor?.getString(cursor.getColumnIndexOrThrow(MediaStore.MediaColumns.SIZE))
 | 
					                    cursor?.getString(cursor.getColumnIndexOrThrow(MediaStore.MediaColumns.SIZE))
 | 
				
			||||||
                    ?.toDouble()
 | 
					                        ?.toDouble()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            if (fileSize!! / 1000000 > settingsViewModel.getSize()) {
 | 
					                if (fileSize!! / 1000000 > settingsViewModel.getSize()) {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                val mmr = MediaMetadataRetriever()
 | 
					                    val mmr = MediaMetadataRetriever()
 | 
				
			||||||
                mmr.setDataSource(this, data)
 | 
					                    mmr.setDataSource(this, data)
 | 
				
			||||||
                val duration =
 | 
					                    val duration =
 | 
				
			||||||
                    mmr.extractMetadata(MediaMetadataRetriever.METADATA_KEY_DURATION)?.toDouble()
 | 
					                        mmr.extractMetadata(MediaMetadataRetriever.METADATA_KEY_DURATION)
 | 
				
			||||||
                Log.i("ethan", duration.toString())
 | 
					                            ?.toDouble()
 | 
				
			||||||
 | 
					                    Log.i("ethan", duration.toString())
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                Log.i("ethan", settingsViewModel.getSize().toString())
 | 
					                    Log.i("ethan", settingsViewModel.getSize().toString())
 | 
				
			||||||
                Log.i("ethan", fileSize.toString())
 | 
					                    Log.i("ethan", fileSize.toString())
 | 
				
			||||||
                val bitrate = (settingsViewModel.getSize()*1000000) / (duration!!/1000)
 | 
					                    val bitrate = (settingsViewModel.getSize() * 1000000) / (duration!! / 1000)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                val item = CompressingItem(fileName!!, 0.0, fileDate)
 | 
					                    val item = CompressingItem(fileName!!, 0.0, fileDate)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                val outputFile = File(this.getExternalFilesDir(null), "converted_$fileName")
 | 
					                    val outputFile = File(this.getExternalFilesDir(null), "converted_$fileName")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                compressingItems.add(item)
 | 
					                    compressingItems.add(item)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                val handler = Handler(Looper.getMainLooper())
 | 
					                    val handler = Handler(Looper.getMainLooper())
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                val command = "-i $inUri -b:v $bitrate ${outputFile.absolutePath} -y"
 | 
					                    val command = "-i $inUri -b:v $bitrate ${outputFile.absolutePath} -y"
 | 
				
			||||||
                Log.i("ethan",command)
 | 
					                    Log.i("ethan", command)
 | 
				
			||||||
                val session = FFmpegKit.executeAsync(command) {
 | 
					                    val session = FFmpegKit.executeAsync(command) {
 | 
				
			||||||
                    compressingItems.remove(item)
 | 
					                        compressingItems.remove(item)
 | 
				
			||||||
                    completedAdapter.refreshList(this)
 | 
					                        completedAdapter.refreshList(this)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                    handler.post {
 | 
					                        handler.post {
 | 
				
			||||||
                        Toast.makeText(this, "Finished converting $fileName", Toast.LENGTH_SHORT).show()
 | 
					                            Toast.makeText(
 | 
				
			||||||
                        compressingAdapter.notifyDataSetChanged()
 | 
					                                this,
 | 
				
			||||||
 | 
					                                "Finished converting $fileName",
 | 
				
			||||||
 | 
					                                Toast.LENGTH_SHORT
 | 
				
			||||||
 | 
					                            ).show()
 | 
				
			||||||
 | 
					                            compressingAdapter.notifyDataSetChanged()
 | 
				
			||||||
 | 
					                        }
 | 
				
			||||||
                    }
 | 
					                    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                    Log.i("Tag", Arrays.deepToString(session.arguments))
 | 
				
			||||||
 | 
					                    Log.i("Tag", session.output)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                    compressingAdapter.notifyDataSetChanged()
 | 
				
			||||||
 | 
					                } else {
 | 
				
			||||||
 | 
					                    Toast.makeText(
 | 
				
			||||||
 | 
					                        applicationContext,
 | 
				
			||||||
 | 
					                        "File is less than target size",
 | 
				
			||||||
 | 
					                        Toast.LENGTH_LONG
 | 
				
			||||||
 | 
					                    ).show()
 | 
				
			||||||
                }
 | 
					                }
 | 
				
			||||||
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
                Log.i("Tag", Arrays.deepToString(session.arguments))
 | 
					 | 
				
			||||||
                Log.i("Tag", session.output)
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
                compressingAdapter.notifyDataSetChanged()
 | 
					 | 
				
			||||||
            }else{
 | 
					 | 
				
			||||||
                Toast.makeText(applicationContext,"File is less than target size",Toast.LENGTH_LONG).show()
 | 
					 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
    companion object {
 | 
					    companion object {
 | 
				
			||||||
        val compressingItems: MutableList<CompressingItem> = mutableListOf()
 | 
					        val compressingItems: MutableList<CompressingItem> = mutableListOf()
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -17,8 +17,9 @@ import com.example.myapplication.R
 | 
				
			|||||||
import java.util.*
 | 
					import java.util.*
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
class CompletedAdapter(private val mCompletedList: MutableList<CompletedItem>): RecyclerView.Adapter<CompletedAdapter.ViewHolder>() {
 | 
					class CompletedAdapter(private val mCompletedList: MutableList<CompletedItem>) :
 | 
				
			||||||
    inner class ViewHolder(itemView: View): RecyclerView.ViewHolder(itemView) {
 | 
					    RecyclerView.Adapter<CompletedAdapter.ViewHolder>() {
 | 
				
			||||||
 | 
					    inner class ViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {
 | 
				
			||||||
        val filename: TextView = itemView.findViewById(R.id.compressed_filename)
 | 
					        val filename: TextView = itemView.findViewById(R.id.compressed_filename)
 | 
				
			||||||
        val date: TextView = itemView.findViewById(R.id.compressed_date)
 | 
					        val date: TextView = itemView.findViewById(R.id.compressed_date)
 | 
				
			||||||
        val shareButton: ImageButton = itemView.findViewById(R.id.compressed_share)
 | 
					        val shareButton: ImageButton = itemView.findViewById(R.id.compressed_share)
 | 
				
			||||||
@@ -26,7 +27,8 @@ class CompletedAdapter(private val mCompletedList: MutableList<CompletedItem>):
 | 
				
			|||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
 | 
					    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
 | 
				
			||||||
        val compressingItemView = LayoutInflater.from(parent.context).inflate(R.layout.item_compressed, parent, false)
 | 
					        val compressingItemView =
 | 
				
			||||||
 | 
					            LayoutInflater.from(parent.context).inflate(R.layout.item_compressed, parent, false)
 | 
				
			||||||
        return ViewHolder(compressingItemView)
 | 
					        return ViewHolder(compressingItemView)
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -34,8 +36,18 @@ class CompletedAdapter(private val mCompletedList: MutableList<CompletedItem>):
 | 
				
			|||||||
        val compressingItem: CompletedItem = mCompletedList[position]
 | 
					        val compressingItem: CompletedItem = mCompletedList[position]
 | 
				
			||||||
        holder.filename.text = compressingItem.filename
 | 
					        holder.filename.text = compressingItem.filename
 | 
				
			||||||
        holder.date.text = compressingItem.date.toString()
 | 
					        holder.date.text = compressingItem.date.toString()
 | 
				
			||||||
        holder.shareButton.setOnClickListener { shareFile(holder.itemView.context, compressingItem.uri) }
 | 
					        holder.shareButton.setOnClickListener {
 | 
				
			||||||
        holder.deleteButton.setOnClickListener { deleteFile(holder.itemView.context, compressingItem.uri) }
 | 
					            shareFile(
 | 
				
			||||||
 | 
					                holder.itemView.context,
 | 
				
			||||||
 | 
					                compressingItem.uri
 | 
				
			||||||
 | 
					            )
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					        holder.deleteButton.setOnClickListener {
 | 
				
			||||||
 | 
					            deleteFile(
 | 
				
			||||||
 | 
					                holder.itemView.context,
 | 
				
			||||||
 | 
					                compressingItem.uri
 | 
				
			||||||
 | 
					            )
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -77,7 +89,13 @@ class CompletedAdapter(private val mCompletedList: MutableList<CompletedItem>):
 | 
				
			|||||||
        mCompletedList.clear()
 | 
					        mCompletedList.clear()
 | 
				
			||||||
        context.getExternalFilesDir(null)?.listFiles()?.forEach {
 | 
					        context.getExternalFilesDir(null)?.listFiles()?.forEach {
 | 
				
			||||||
            if (it.name.endsWith(".mp4")) {
 | 
					            if (it.name.endsWith(".mp4")) {
 | 
				
			||||||
                val completedItem = CompletedItem(it.name, Date(it.lastModified()), ImageButton(context), ImageButton(context), Uri.fromFile(it))
 | 
					                val completedItem = CompletedItem(
 | 
				
			||||||
 | 
					                    it.name,
 | 
				
			||||||
 | 
					                    Date(it.lastModified()),
 | 
				
			||||||
 | 
					                    ImageButton(context),
 | 
				
			||||||
 | 
					                    ImageButton(context),
 | 
				
			||||||
 | 
					                    Uri.fromFile(it)
 | 
				
			||||||
 | 
					                )
 | 
				
			||||||
                mCompletedList.add(completedItem)
 | 
					                mCompletedList.add(completedItem)
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -4,9 +4,7 @@ import android.os.Bundle
 | 
				
			|||||||
import android.view.LayoutInflater
 | 
					import android.view.LayoutInflater
 | 
				
			||||||
import android.view.View
 | 
					import android.view.View
 | 
				
			||||||
import android.view.ViewGroup
 | 
					import android.view.ViewGroup
 | 
				
			||||||
import android.widget.TextView
 | 
					 | 
				
			||||||
import androidx.fragment.app.Fragment
 | 
					import androidx.fragment.app.Fragment
 | 
				
			||||||
import androidx.lifecycle.ViewModelProvider
 | 
					 | 
				
			||||||
import androidx.recyclerview.widget.LinearLayoutManager
 | 
					import androidx.recyclerview.widget.LinearLayoutManager
 | 
				
			||||||
import androidx.recyclerview.widget.RecyclerView
 | 
					import androidx.recyclerview.widget.RecyclerView
 | 
				
			||||||
import com.example.myapplication.MainActivity
 | 
					import com.example.myapplication.MainActivity
 | 
				
			||||||
@@ -22,14 +20,15 @@ class CompletedFragment : Fragment() {
 | 
				
			|||||||
    private val binding get() = _binding!!
 | 
					    private val binding get() = _binding!!
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    override fun onCreateView(
 | 
					    override fun onCreateView(
 | 
				
			||||||
            inflater: LayoutInflater,
 | 
					        inflater: LayoutInflater,
 | 
				
			||||||
            container: ViewGroup?,
 | 
					        container: ViewGroup?,
 | 
				
			||||||
            savedInstanceState: Bundle?
 | 
					        savedInstanceState: Bundle?
 | 
				
			||||||
    ): View {
 | 
					    ): View {
 | 
				
			||||||
        _binding = FragmentCompletedBinding.inflate(inflater, container, false)
 | 
					        _binding = FragmentCompletedBinding.inflate(inflater, container, false)
 | 
				
			||||||
        val root: View = binding.root
 | 
					        val root: View = binding.root
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        val completedRecycler = binding.root.findViewById<View>(R.id.compressed_recycler_view) as? RecyclerView
 | 
					        val completedRecycler =
 | 
				
			||||||
 | 
					            binding.root.findViewById<View>(R.id.compressed_recycler_view) as? RecyclerView
 | 
				
			||||||
        completedRecycler?.adapter = MainActivity.completedAdapter
 | 
					        completedRecycler?.adapter = MainActivity.completedAdapter
 | 
				
			||||||
        completedRecycler?.layoutManager = LinearLayoutManager(binding.root.context)
 | 
					        completedRecycler?.layoutManager = LinearLayoutManager(binding.root.context)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -4,4 +4,10 @@ import android.net.Uri
 | 
				
			|||||||
import android.widget.ImageButton
 | 
					import android.widget.ImageButton
 | 
				
			||||||
import java.util.*
 | 
					import java.util.*
 | 
				
			||||||
 | 
					
 | 
				
			||||||
data class CompletedItem(val filename: String, val date: Date, val shareButton: ImageButton, val deleteButton: ImageButton, val uri: Uri)
 | 
					data class CompletedItem(
 | 
				
			||||||
 | 
					    val filename: String,
 | 
				
			||||||
 | 
					    val date: Date,
 | 
				
			||||||
 | 
					    val shareButton: ImageButton,
 | 
				
			||||||
 | 
					    val deleteButton: ImageButton,
 | 
				
			||||||
 | 
					    val uri: Uri
 | 
				
			||||||
 | 
					)
 | 
				
			||||||
@@ -1,6 +1,5 @@
 | 
				
			|||||||
package com.example.myapplication.ui.compressing
 | 
					package com.example.myapplication.ui.compressing
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import android.content.Context
 | 
					 | 
				
			||||||
import android.view.LayoutInflater
 | 
					import android.view.LayoutInflater
 | 
				
			||||||
import android.view.View
 | 
					import android.view.View
 | 
				
			||||||
import android.view.ViewGroup
 | 
					import android.view.ViewGroup
 | 
				
			||||||
@@ -8,18 +7,18 @@ import android.widget.ProgressBar
 | 
				
			|||||||
import android.widget.TextView
 | 
					import android.widget.TextView
 | 
				
			||||||
import androidx.recyclerview.widget.RecyclerView
 | 
					import androidx.recyclerview.widget.RecyclerView
 | 
				
			||||||
import com.example.myapplication.R
 | 
					import com.example.myapplication.R
 | 
				
			||||||
import com.example.myapplication.ui.completed.CompletedItem
 | 
					 | 
				
			||||||
import java.util.*
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
class CompressingAdapter(private val mCompressingItems: MutableList<CompressingItem>): RecyclerView.Adapter<CompressingAdapter.ViewHolder>() {
 | 
					class CompressingAdapter(private val mCompressingItems: MutableList<CompressingItem>) :
 | 
				
			||||||
    inner class ViewHolder(itemView: View): RecyclerView.ViewHolder(itemView) {
 | 
					    RecyclerView.Adapter<CompressingAdapter.ViewHolder>() {
 | 
				
			||||||
 | 
					    inner class ViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {
 | 
				
			||||||
        val filename: TextView = itemView.findViewById(R.id.compressing_filename)
 | 
					        val filename: TextView = itemView.findViewById(R.id.compressing_filename)
 | 
				
			||||||
        val date: TextView = itemView.findViewById(R.id.compressing_date)
 | 
					        val date: TextView = itemView.findViewById(R.id.compressing_date)
 | 
				
			||||||
        val progress: ProgressBar = itemView.findViewById(R.id.compressing_progress)
 | 
					        val progress: ProgressBar = itemView.findViewById(R.id.compressing_progress)
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
 | 
					    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
 | 
				
			||||||
        val compressingItemView = LayoutInflater.from(parent.context).inflate(R.layout.item_compressing, parent, false)
 | 
					        val compressingItemView =
 | 
				
			||||||
 | 
					            LayoutInflater.from(parent.context).inflate(R.layout.item_compressing, parent, false)
 | 
				
			||||||
        return ViewHolder(compressingItemView)
 | 
					        return ViewHolder(compressingItemView)
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -5,7 +5,6 @@ import android.view.LayoutInflater
 | 
				
			|||||||
import android.view.View
 | 
					import android.view.View
 | 
				
			||||||
import android.view.ViewGroup
 | 
					import android.view.ViewGroup
 | 
				
			||||||
import androidx.fragment.app.Fragment
 | 
					import androidx.fragment.app.Fragment
 | 
				
			||||||
import androidx.lifecycle.ViewModelProvider
 | 
					 | 
				
			||||||
import androidx.recyclerview.widget.LinearLayoutManager
 | 
					import androidx.recyclerview.widget.LinearLayoutManager
 | 
				
			||||||
import androidx.recyclerview.widget.RecyclerView
 | 
					import androidx.recyclerview.widget.RecyclerView
 | 
				
			||||||
import com.example.myapplication.MainActivity
 | 
					import com.example.myapplication.MainActivity
 | 
				
			||||||
@@ -17,16 +16,20 @@ class CompressingFragment : Fragment() {
 | 
				
			|||||||
    private var _binding: FragmentCompressingBinding? = null
 | 
					    private var _binding: FragmentCompressingBinding? = null
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					 | 
				
			||||||
    // This property is only valid between onCreateView and
 | 
					    // This property is only valid between onCreateView and
 | 
				
			||||||
    // onDestroyView.
 | 
					    // onDestroyView.
 | 
				
			||||||
    private val binding get() = _binding!!
 | 
					    private val binding get() = _binding!!
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View {
 | 
					    override fun onCreateView(
 | 
				
			||||||
 | 
					        inflater: LayoutInflater,
 | 
				
			||||||
 | 
					        container: ViewGroup?,
 | 
				
			||||||
 | 
					        savedInstanceState: Bundle?
 | 
				
			||||||
 | 
					    ): View {
 | 
				
			||||||
        _binding = FragmentCompressingBinding.inflate(inflater, container, false)
 | 
					        _binding = FragmentCompressingBinding.inflate(inflater, container, false)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        val compressingRecycler = binding.root.findViewById<View>(R.id.compressing_recycler_view) as? RecyclerView
 | 
					        val compressingRecycler =
 | 
				
			||||||
 | 
					            binding.root.findViewById<View>(R.id.compressing_recycler_view) as? RecyclerView
 | 
				
			||||||
        compressingRecycler?.adapter = MainActivity.compressingAdapter
 | 
					        compressingRecycler?.adapter = MainActivity.compressingAdapter
 | 
				
			||||||
        compressingRecycler?.layoutManager = LinearLayoutManager(binding.root.context)
 | 
					        compressingRecycler?.layoutManager = LinearLayoutManager(binding.root.context)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1,5 +1,5 @@
 | 
				
			|||||||
package com.example.myapplication.ui.compressing
 | 
					package com.example.myapplication.ui.compressing
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import java.util.Date
 | 
					import java.util.*
 | 
				
			||||||
 | 
					
 | 
				
			||||||
data class CompressingItem(val filename: String, val progress: Double, val date: Date)
 | 
					data class CompressingItem(val filename: String, val progress: Double, val date: Date)
 | 
				
			||||||
@@ -56,9 +56,6 @@ class SettingsFragment : Fragment() {
 | 
				
			|||||||
                    settingsViewModel.size.value = 0.0
 | 
					                    settingsViewModel.size.value = 0.0
 | 
				
			||||||
                }
 | 
					                }
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
 | 
					 | 
				
			||||||
            Toast.makeText(root.context,"" + settingsViewModel.size.value,Toast.LENGTH_SHORT).show()
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        //updates size when the custom value changes
 | 
					        //updates size when the custom value changes
 | 
				
			||||||
@@ -77,7 +74,6 @@ class SettingsFragment : Fragment() {
 | 
				
			|||||||
                    }catch (e: NumberFormatException){
 | 
					                    }catch (e: NumberFormatException){
 | 
				
			||||||
                        settingsViewModel.size.value = 0.0
 | 
					                        settingsViewModel.size.value = 0.0
 | 
				
			||||||
                    }
 | 
					                    }
 | 
				
			||||||
                    Toast.makeText(root.context,"" + settingsViewModel.size.value,Toast.LENGTH_SHORT).show()
 | 
					 | 
				
			||||||
                }
 | 
					                }
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
        )
 | 
					        )
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -17,7 +17,7 @@ class SettingsViewModel : ViewModel() {
 | 
				
			|||||||
    }
 | 
					    }
 | 
				
			||||||
    val size: MutableLiveData<Double> = _size
 | 
					    val size: MutableLiveData<Double> = _size
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    fun getSize(): Double{
 | 
					    fun getSize(): Double {
 | 
				
			||||||
        return size.value!!
 | 
					        return size.value!!
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
		Reference in New Issue
	
	Block a user