Changes For Folder Feature
This commit is contained in:
@@ -6,6 +6,7 @@ import android.os.Environment
|
||||
import android.os.Handler
|
||||
import android.os.Looper
|
||||
import android.util.Log
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.WindowManager
|
||||
import android.widget.EditText
|
||||
@@ -159,27 +160,33 @@ class HiddenActivity : AppCompatActivity() {
|
||||
|
||||
|
||||
private fun createNewFolder() {
|
||||
dialogUtil.createInputDialog(
|
||||
title = "Enter Folder Name To Create",
|
||||
hint = "",
|
||||
callback = object : DialogUtil.InputDialogCallback {
|
||||
override fun onPositiveButtonClicked(input: String) {
|
||||
if (input.trim().isNotEmpty()) {
|
||||
try {
|
||||
folderManager.createFolder(hiddenDir, input.trim())
|
||||
refreshCurrentView()
|
||||
} catch (e: Exception) {
|
||||
Log.e(TAG, "Error creating folder: ${e.message}")
|
||||
Toast.makeText(
|
||||
this@HiddenActivity,
|
||||
"Failed to create folder",
|
||||
Toast.LENGTH_SHORT
|
||||
).show()
|
||||
}
|
||||
val dialogView = LayoutInflater.from(this).inflate(R.layout.dialog_input, null)
|
||||
val inputEditText = dialogView.findViewById<EditText>(R.id.editText)
|
||||
|
||||
MaterialAlertDialogBuilder(this)
|
||||
.setTitle("Enter Folder Name To Create")
|
||||
.setView(dialogView)
|
||||
.setPositiveButton("Create") { dialog, _ ->
|
||||
val newName = inputEditText.text.toString().trim()
|
||||
if (newName.isNotEmpty()) {
|
||||
try {
|
||||
folderManager.createFolder(hiddenDir, newName)
|
||||
refreshCurrentView()
|
||||
} catch (e: Exception) {
|
||||
Log.e(TAG, "Error creating folder: ${e.message}")
|
||||
Toast.makeText(
|
||||
this@HiddenActivity,
|
||||
"Failed to create folder",
|
||||
Toast.LENGTH_SHORT
|
||||
).show()
|
||||
}
|
||||
}
|
||||
dialog.dismiss()
|
||||
}
|
||||
)
|
||||
.setNegativeButton("Cancel") { dialog, _ ->
|
||||
dialog.cancel()
|
||||
}
|
||||
.show()
|
||||
}
|
||||
|
||||
override fun onResume() {
|
||||
@@ -470,14 +477,14 @@ class HiddenActivity : AppCompatActivity() {
|
||||
}
|
||||
|
||||
private fun showEditFolderDialog(folder: File) {
|
||||
val inputEditText = EditText(this).apply {
|
||||
setText(folder.name)
|
||||
selectAll()
|
||||
}
|
||||
val dialogView = LayoutInflater.from(this).inflate(R.layout.dialog_input, null)
|
||||
val inputEditText = dialogView.findViewById<EditText>(R.id.editText)
|
||||
inputEditText.setText(folder.name)
|
||||
inputEditText.selectAll()
|
||||
|
||||
MaterialAlertDialogBuilder(this)
|
||||
.setTitle("Rename Folder")
|
||||
.setView(inputEditText)
|
||||
.setView(dialogView)
|
||||
.setPositiveButton("Rename") { dialog, _ ->
|
||||
val newName = inputEditText.text.toString().trim()
|
||||
if (newName.isNotEmpty() && newName != folder.name) {
|
||||
|
||||
@@ -8,6 +8,7 @@ import android.os.Bundle
|
||||
import android.os.Environment
|
||||
import android.os.Handler
|
||||
import android.os.Looper
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.animation.Animation
|
||||
import android.view.animation.AnimationUtils
|
||||
@@ -17,9 +18,13 @@ import androidx.activity.result.contract.ActivityResultContracts
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
import androidx.lifecycle.lifecycleScope
|
||||
import androidx.recyclerview.widget.GridLayoutManager
|
||||
import androidx.recyclerview.widget.LinearLayoutManager
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import com.google.android.material.dialog.MaterialAlertDialogBuilder
|
||||
import com.google.android.material.bottomsheet.BottomSheetDialog
|
||||
import devs.org.calculator.R
|
||||
import devs.org.calculator.adapters.FileAdapter
|
||||
import devs.org.calculator.adapters.FolderSelectionAdapter
|
||||
import devs.org.calculator.callbacks.FileProcessCallback
|
||||
import devs.org.calculator.databinding.ActivityViewFolderBinding
|
||||
import devs.org.calculator.databinding.ProccessingDialogBinding
|
||||
@@ -601,12 +606,18 @@ class ViewFolderActivity : AppCompatActivity() {
|
||||
return
|
||||
}
|
||||
|
||||
val folderNames = folders.map { it.name }.toTypedArray()
|
||||
MaterialAlertDialogBuilder(this)
|
||||
.setTitle(getString(R.string.select_destination_folder))
|
||||
.setItems(folderNames) { _, which ->
|
||||
onFolderSelected(folders[which])
|
||||
}
|
||||
.show()
|
||||
val bottomSheetView = LayoutInflater.from(this).inflate(R.layout.bottom_sheet_folder_selection, null)
|
||||
val recyclerView = bottomSheetView.findViewById<RecyclerView>(R.id.folderRecyclerView)
|
||||
|
||||
val bottomSheetDialog = BottomSheetDialog(this)
|
||||
bottomSheetDialog.setContentView(bottomSheetView)
|
||||
|
||||
recyclerView.layoutManager = LinearLayoutManager(this)
|
||||
recyclerView.adapter = FolderSelectionAdapter(folders) { selectedFolder ->
|
||||
bottomSheetDialog.dismiss()
|
||||
onFolderSelected(selectedFolder)
|
||||
}
|
||||
|
||||
bottomSheetDialog.show()
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
package devs.org.calculator.adapters
|
||||
|
||||
import android.annotation.SuppressLint
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.os.Handler
|
||||
@@ -346,15 +347,16 @@ class FileAdapter(
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressLint("MissingInflatedId")
|
||||
private fun renameFile(file: File) {
|
||||
val inputEditText = EditText(context).apply {
|
||||
setText(file.name)
|
||||
selectAll()
|
||||
}
|
||||
val dialogView = LayoutInflater.from(context).inflate(R.layout.dialog_input, null)
|
||||
val inputEditText = dialogView.findViewById<EditText>(R.id.editText)
|
||||
inputEditText.setText(file.name)
|
||||
inputEditText.selectAll()
|
||||
|
||||
MaterialAlertDialogBuilder(context)
|
||||
.setTitle(context.getString(R.string.rename_file))
|
||||
.setView(inputEditText)
|
||||
.setView(dialogView)
|
||||
.setPositiveButton(context.getString(R.string.rename)) { dialog, _ ->
|
||||
val newName = inputEditText.text.toString().trim()
|
||||
if (newName.isNotEmpty() && newName != file.name) {
|
||||
|
||||
@@ -0,0 +1,41 @@
|
||||
package devs.org.calculator.adapters
|
||||
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import android.widget.TextView
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import devs.org.calculator.R
|
||||
import java.io.File
|
||||
|
||||
class FolderSelectionAdapter(
|
||||
private val folders: List<File>,
|
||||
private val onFolderSelected: (File) -> Unit
|
||||
) : RecyclerView.Adapter<FolderSelectionAdapter.FolderViewHolder>() {
|
||||
|
||||
inner class FolderViewHolder(view: View) : RecyclerView.ViewHolder(view) {
|
||||
val folderName: TextView = view.findViewById(R.id.folderName)
|
||||
|
||||
init {
|
||||
view.setOnClickListener {
|
||||
val position = adapterPosition
|
||||
if (position != RecyclerView.NO_POSITION) {
|
||||
onFolderSelected(folders[position])
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): FolderViewHolder {
|
||||
val view = LayoutInflater.from(parent.context)
|
||||
.inflate(R.layout.item_folder_selection, parent, false)
|
||||
return FolderViewHolder(view)
|
||||
}
|
||||
|
||||
override fun onBindViewHolder(holder: FolderViewHolder, position: Int) {
|
||||
val folder = folders[position]
|
||||
holder.folderName.text = folder.name
|
||||
}
|
||||
|
||||
override fun getItemCount() = folders.size
|
||||
}
|
||||
@@ -55,7 +55,7 @@
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginBottom="16dp"
|
||||
app:cardElevation="2dp">
|
||||
app:cardElevation="1dp">
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
@@ -125,7 +125,7 @@
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginBottom="16dp"
|
||||
app:cardElevation="2dp">
|
||||
app:cardElevation="1dp">
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
@@ -169,7 +169,7 @@
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginBottom="16dp"
|
||||
app:cardElevation="2dp">
|
||||
app:cardElevation="1dp">
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
@@ -232,7 +232,7 @@
|
||||
<com.google.android.material.card.MaterialCardView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
app:cardElevation="2dp">
|
||||
app:cardElevation="1dp">
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
@@ -261,7 +261,7 @@
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginVertical="10dp"
|
||||
app:cardElevation="2dp">
|
||||
app:cardElevation="1dp">
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
|
||||
33
app/src/main/res/layout/bottom_sheet_folder_selection.xml
Normal file
33
app/src/main/res/layout/bottom_sheet_folder_selection.xml
Normal file
@@ -0,0 +1,33 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical"
|
||||
android:padding="16dp">
|
||||
|
||||
<androidx.cardview.widget.CardView
|
||||
android:layout_width="100dp"
|
||||
android:layout_height="3dp"
|
||||
android:layout_gravity="center"
|
||||
app:cardCornerRadius="100dp"
|
||||
android:backgroundTint="#808080"
|
||||
app:cardElevation="0dp"
|
||||
android:layout_marginBottom="10dp"/>
|
||||
|
||||
<TextView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/select_destination_folder"
|
||||
android:textSize="20sp"
|
||||
android:padding="8dp"
|
||||
android:textStyle="bold"
|
||||
android:layout_marginBottom="16dp"/>
|
||||
|
||||
<androidx.recyclerview.widget.RecyclerView
|
||||
android:id="@+id/folderRecyclerView"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:maxHeight="400dp"/>
|
||||
|
||||
</LinearLayout>
|
||||
24
app/src/main/res/layout/item_folder_selection.xml
Normal file
24
app/src/main/res/layout/item_folder_selection.xml
Normal file
@@ -0,0 +1,24 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="horizontal"
|
||||
android:padding="12dp"
|
||||
android:gravity="center_vertical">
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/folderIcon"
|
||||
android:layout_width="34dp"
|
||||
android:layout_height="34dp"
|
||||
android:src="@drawable/ic_folder"
|
||||
app:tint="?attr/colorPrimary" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/folderName"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="16dp"
|
||||
android:textSize="18sp"/>
|
||||
|
||||
</LinearLayout>
|
||||
Reference in New Issue
Block a user