Clean app and add delete

This commit is contained in:
Isaac Shoebottom 2022-12-06 22:47:10 -04:00
parent 62ea78dc3c
commit e68a984411
10 changed files with 47 additions and 52 deletions

View File

@ -6,7 +6,6 @@ import android.content.Intent
import android.content.pm.PackageManager
import android.media.MediaMetadataRetriever
import android.net.Uri
import android.os.Build
import android.os.Bundle
import android.os.Handler
import android.os.Looper
@ -30,7 +29,6 @@ import com.example.myapplication.ui.completed.CompletedAdapter
import com.example.myapplication.ui.completed.CompletedItem
import com.example.myapplication.ui.compressing.CompressingAdapter
import com.example.myapplication.ui.compressing.CompressingItem
import com.example.myapplication.ui.settings.SettingsFragment
import com.example.myapplication.ui.settings.SettingsViewModel
import com.google.android.material.bottomnavigation.BottomNavigationView
import java.io.File
@ -152,11 +150,11 @@ class MainActivity : AppCompatActivity() {
Log.i("ethan",command)
val session = FFmpegKit.executeAsync(command) {
compressingItems.remove(item)
adapter.refreshList(this)
completedAdapter.refreshList(this)
handler.post {
Toast.makeText(this, "Finished converting $fileName", Toast.LENGTH_SHORT).show()
adapter.notifyDataSetChanged()
compressingAdapter.notifyDataSetChanged()
}
}
@ -165,7 +163,7 @@ class MainActivity : AppCompatActivity() {
Log.i("Tag", session.output)
adapter.notifyDataSetChanged()
compressingAdapter.notifyDataSetChanged()
}else{
Toast.makeText(applicationContext,"File is less than target size",Toast.LENGTH_LONG).show()
}

View File

@ -1,6 +1,7 @@
package com.example.myapplication.ui.completed
import android.annotation.SuppressLint
import android.app.AlertDialog
import android.content.Context
import android.content.Intent
import android.net.Uri
@ -20,7 +21,8 @@ class CompletedAdapter(private val mCompletedList: MutableList<CompletedItem>):
inner class ViewHolder(itemView: View): RecyclerView.ViewHolder(itemView) {
val filename: TextView = itemView.findViewById(R.id.compressed_filename)
val date: TextView = itemView.findViewById(R.id.compressed_date)
var shareButton: ImageButton = itemView.findViewById(R.id.compressed_share)
val shareButton: ImageButton = itemView.findViewById(R.id.compressed_share)
val deleteButton: ImageButton = itemView.findViewById(R.id.compressed_delete)
}
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
@ -33,12 +35,30 @@ class CompletedAdapter(private val mCompletedList: MutableList<CompletedItem>):
holder.filename.text = compressingItem.filename
holder.date.text = compressingItem.date.toString()
holder.shareButton.setOnClickListener { shareFile(holder.itemView.context, compressingItem.uri) }
holder.deleteButton.setOnClickListener { deleteFile(holder.itemView.context, compressingItem.uri) }
}
@SuppressLint("NotifyDataSetChanged")
private fun deleteFile(context: Context?, uri: Uri) {
val policy = VmPolicy.Builder().build()
StrictMode.setVmPolicy(policy) // this is a hack to allow the file to be deleted
AlertDialog.Builder(context)
.setTitle("Delete file")
.setMessage("Are you sure you want to delete this file?")
.setPositiveButton("Yes") { _, _ ->
val file = java.io.File(uri.path!!)
file.delete()
refreshList(context!!)
}
.setNegativeButton("No") { _, _ -> }
.show()
}
private fun shareFile(context: Context?, uri: Uri) {
val builder = VmPolicy.Builder()
StrictMode.setVmPolicy(builder.build()) // this is a hack to allow sharing files from the app
val policy = VmPolicy.Builder().build()
StrictMode.setVmPolicy(policy) // this is a hack to allow sharing files from the app
val intent = Intent(Intent.ACTION_SEND)
@ -57,7 +77,7 @@ class CompletedAdapter(private val mCompletedList: MutableList<CompletedItem>):
mCompletedList.clear()
context.getExternalFilesDir(null)?.listFiles()?.forEach {
if (it.name.endsWith(".mp4")) {
val completedItem = CompletedItem(it.name, Date(it.lastModified()), ImageButton(context), Uri.fromFile(it))
val completedItem = CompletedItem(it.name, Date(it.lastModified()), ImageButton(context), ImageButton(context), Uri.fromFile(it))
mCompletedList.add(completedItem)
}
}

View File

@ -26,8 +26,6 @@ class CompletedFragment : Fragment() {
container: ViewGroup?,
savedInstanceState: Bundle?
): View {
val dashboardViewModel = ViewModelProvider(this).get(CompletedViewModel::class.java)
_binding = FragmentCompletedBinding.inflate(inflater, container, false)
val root: View = binding.root
@ -36,10 +34,6 @@ class CompletedFragment : Fragment() {
completedRecycler?.layoutManager = LinearLayoutManager(binding.root.context)
MainActivity.completedAdapter.refreshList(binding.root.context)
dashboardViewModel.text.observe(viewLifecycleOwner) {
//do nothing
}
return binding.root
}

View File

@ -4,4 +4,4 @@ import android.net.Uri
import android.widget.ImageButton
import java.util.*
data class CompletedItem(val filename: String, val date: Date, val button: ImageButton, val uri: Uri)
data class CompletedItem(val filename: String, val date: Date, val shareButton: ImageButton, val deleteButton: ImageButton, val uri: Uri)

View File

@ -1,13 +0,0 @@
package com.example.myapplication.ui.completed
import androidx.lifecycle.LiveData
import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.ViewModel
class CompletedViewModel : ViewModel() {
private val _text = MutableLiveData<String>().apply {
value = "This is completed Fragment"
}
val text: LiveData<String> = _text
}

View File

@ -23,8 +23,6 @@ class CompressingFragment : Fragment() {
private val binding get() = _binding!!
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View {
ViewModelProvider(this)[CompressingViewModel::class.java]
_binding = FragmentCompressingBinding.inflate(inflater, container, false)
@ -32,9 +30,6 @@ class CompressingFragment : Fragment() {
compressingRecycler?.adapter = MainActivity.compressingAdapter
compressingRecycler?.layoutManager = LinearLayoutManager(binding.root.context)
return binding.root
}

View File

@ -1,13 +0,0 @@
package com.example.myapplication.ui.compressing
import androidx.lifecycle.LiveData
import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.ViewModel
class CompressingViewModel : ViewModel() {
private val _text = MutableLiveData<String>().apply {
value = "This is compressing Fragment"
}
val text: LiveData<String> = _text
}

View File

@ -0,0 +1,5 @@
<vector android:height="24dp" android:tint="#000000"
android:viewportHeight="24" android:viewportWidth="24"
android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
<path android:fillColor="@android:color/white" android:pathData="M6,19c0,1.1 0.9,2 2,2h8c1.1,0 2,-0.9 2,-2L18,7L6,7v12zM8,9h8v10L8,19L8,9zM15.5,4l-1,-1h-5l-1,1L5,4v2h14L19,4z"/>
</vector>

View File

@ -5,9 +5,9 @@
android:layout_height="wrap_content">
<LinearLayout
android:layout_width="match_parent"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="3"
android:layout_weight="5"
android:orientation="vertical">
<TextView
@ -26,6 +26,14 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
app:srcCompat="@drawable/ic_share"
android:contentDescription="@string/share_button" />
android:contentDescription="@string/share_button"
app:srcCompat="@drawable/ic_share" />
<ImageButton
android:id="@+id/compressed_delete"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:contentDescription="@string/delete"
app:srcCompat="@drawable/ic_delete" />
</LinearLayout>

View File

@ -12,5 +12,6 @@
<string name="settings_custom_size_hint">Enter Size in MB</string>
<string name="files">Files</string>
<string name="youtube">Youtube</string>
<string name="share_button">Share Button</string>
<string name="share_button">Share</string>
<string name="delete">Delete</string>
</resources>