Skip to content

Commit

Permalink
add ability to remove file path (archive)
Browse files Browse the repository at this point in the history
  • Loading branch information
WirelessAlien committed Dec 16, 2024
1 parent 636917f commit f97af42
Show file tree
Hide file tree
Showing 5 changed files with 83 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,10 @@ import android.view.View
import android.view.ViewGroup
import android.view.Window
import androidx.fragment.app.DialogFragment
import androidx.recyclerview.widget.LinearLayoutManager
import com.wirelessalien.zipxtract.activity.MainActivity
import com.wirelessalien.zipxtract.adapter.FileAdapter
import com.wirelessalien.zipxtract.adapter.FilePathAdapter
import com.wirelessalien.zipxtract.databinding.SevenZOptionDialogBinding
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
Expand All @@ -38,7 +40,8 @@ class SevenZOptionDialogFragment : DialogFragment() {

private lateinit var binding: SevenZOptionDialogBinding
private lateinit var adapter: FileAdapter
private lateinit var selectedFilePaths: List<String>
private lateinit var selectedFilePaths: MutableList<String>
private lateinit var filePathAdapter: FilePathAdapter

override fun onCreateView(
inflater: LayoutInflater, container: ViewGroup?,
Expand All @@ -57,24 +60,37 @@ class SevenZOptionDialogFragment : DialogFragment() {
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)

// Show the progress bar
binding.progressIndicator.visibility = View.VISIBLE

// Launch a coroutine to fetch the selected file paths
CoroutineScope(Dispatchers.Main).launch {
selectedFilePaths = withContext(Dispatchers.IO) {
adapter.getSelectedFilesPaths()
adapter.getSelectedFilesPaths().toMutableList()
}

// Hide the progress bar
binding.progressIndicator.visibility = View.GONE

// Initialize the rest of the UI with the fetched data
initializeUI()
}
}

private fun initializeUI() {
filePathAdapter = FilePathAdapter(selectedFilePaths) { filePath ->
selectedFilePaths.remove(filePath)
filePathAdapter.removeFilePath(filePath)
filePathAdapter.notifyDataSetChanged()
}

binding.filePathsRv.layoutManager = LinearLayoutManager(context)
binding.filePathsRv.adapter = filePathAdapter

binding.toggleFileViewBtn.setOnClickListener {
if (binding.filePathsRv.visibility == View.GONE) {
binding.filePathsRv.visibility = View.VISIBLE
} else {
binding.filePathsRv.visibility = View.GONE
}
}

binding.okButton.setOnClickListener {
val defaultName = if (selectedFilePaths.isNotEmpty()) {
File(selectedFilePaths.first()).name
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,18 @@ package com.wirelessalien.zipxtract.fragment
import android.R
import android.app.Dialog
import android.os.Bundle
import android.util.Log
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.view.Window
import android.widget.AdapterView
import android.widget.ArrayAdapter
import androidx.fragment.app.DialogFragment
import androidx.recyclerview.widget.LinearLayoutManager
import com.wirelessalien.zipxtract.activity.MainActivity
import com.wirelessalien.zipxtract.adapter.FileAdapter
import com.wirelessalien.zipxtract.adapter.FilePathAdapter
import com.wirelessalien.zipxtract.databinding.ZipOptionDialogBinding
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
Expand All @@ -45,7 +48,9 @@ class ZipOptionDialogFragment : DialogFragment() {

private lateinit var binding: ZipOptionDialogBinding
private lateinit var adapter: FileAdapter
private lateinit var selectedFilePaths: List<String>
private lateinit var selectedFilePaths: MutableList<String>
private lateinit var filePathAdapter: FilePathAdapter


override fun onCreateView(
inflater: LayoutInflater, container: ViewGroup?,
Expand All @@ -68,16 +73,33 @@ class ZipOptionDialogFragment : DialogFragment() {

CoroutineScope(Dispatchers.Main).launch {
selectedFilePaths = withContext(Dispatchers.IO) {
adapter.getSelectedFilesPaths()
adapter.getSelectedFilesPaths().toMutableList()
}

Log.d("ZipOptionDialogFragment", "Selected file paths: $selectedFilePaths")
binding.progressIndicator.visibility = View.GONE

initializeUI()
}
}

private fun initializeUI() {
filePathAdapter = FilePathAdapter(selectedFilePaths) { filePath ->
selectedFilePaths.remove(filePath)
filePathAdapter.removeFilePath(filePath)
filePathAdapter.notifyDataSetChanged()
}

binding.filePathsRv.layoutManager = LinearLayoutManager(context)
binding.filePathsRv.adapter = filePathAdapter

binding.toggleFileViewBtn.setOnClickListener {
if (binding.filePathsRv.visibility == View.GONE) {
binding.filePathsRv.visibility = View.VISIBLE
} else {
binding.filePathsRv.visibility = View.GONE
}
}

val compressionMethodSpinner = binding.compressionMethodInput
val compressionLevelSpinner = binding.compressionLevelInput
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/layout/list_item_file.xml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
<com.google.android.material.card.MaterialCardView
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:cardCornerRadius="10dp">
app:cardCornerRadius="5dp">

<RelativeLayout
android:layout_width="match_parent"
Expand Down
20 changes: 18 additions & 2 deletions app/src/main/res/layout/seven_z_option_dialog.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
~ along with this program. If not, see <https://www.gnu.org/licenses/>.
-->

<androidx.core.widget.NestedScrollView xmlns:android="http://schemas.android.com/apk/res/android"
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
Expand Down Expand Up @@ -46,6 +46,22 @@
android:visibility="gone"
android:indeterminate="true"/>

<com.google.android.material.button.MaterialButton
android:id="@+id/toggleFileViewBtn"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="5dp"
app:cornerRadius="5dp"
style="@style/Widget.Material3.Button.TonalButton"
android:text="Show/Hide File Paths" />

<androidx.recyclerview.widget.RecyclerView
android:id="@+id/filePathsRv"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:visibility="gone" />

<com.google.android.material.textfield.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
Expand Down Expand Up @@ -165,4 +181,4 @@
style="@style/Widget.Material3.Button.TonalButton"
android:text="@string/no_password" />
</LinearLayout>
</androidx.core.widget.NestedScrollView>
</ScrollView>
20 changes: 18 additions & 2 deletions app/src/main/res/layout/zip_option_dialog.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
~ along with this program. If not, see <https://www.gnu.org/licenses/>.
-->

<androidx.core.widget.NestedScrollView xmlns:android="http://schemas.android.com/apk/res/android"
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fitsSystemWindows="true"
Expand Down Expand Up @@ -48,6 +48,22 @@
android:visibility="gone"
android:indeterminate="true"/>

<com.google.android.material.button.MaterialButton
android:id="@+id/toggleFileViewBtn"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="5dp"
app:cornerRadius="5dp"
style="@style/Widget.Material3.Button.TonalButton"
android:text="Show/Hide File Paths" />

<androidx.recyclerview.widget.RecyclerView
android:id="@+id/filePathsRv"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:visibility="gone" />

<com.google.android.material.textfield.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
Expand Down Expand Up @@ -267,4 +283,4 @@
app:cornerRadius="5dp"
android:text="@string/cancel" />
</LinearLayout>
</androidx.core.widget.NestedScrollView>
</ScrollView>

0 comments on commit f97af42

Please sign in to comment.