diff --git a/app/src/main/java/com/wirelessalien/zipxtract/fragment/ArchiveFragment.kt b/app/src/main/java/com/wirelessalien/zipxtract/fragment/ArchiveFragment.kt index a7dacf5..cc24eb5 100644 --- a/app/src/main/java/com/wirelessalien/zipxtract/fragment/ArchiveFragment.kt +++ b/app/src/main/java/com/wirelessalien/zipxtract/fragment/ArchiveFragment.kt @@ -596,13 +596,12 @@ class ArchiveFragment : Fragment(), FileAdapter.OnItemClickListener { val lastModifiedTextView = dialogView.findViewById<TextView>(R.id.last_modified) val okButton = dialogView.findViewById<Button>(R.id.ok_button) - fileNameTextView.text = getString(R.string.file_name, file.name) - filePathTextView.text = getString(R.string.file_path, file.absolutePath) + fileNameTextView.text = file.name + filePathTextView.text = file.absolutePath val fileSizeText = bytesToString(file.length()) - fileSizeTextView.text = getString(R.string.file_size, fileSizeText) - val dateFormat = - DateFormat.getDateTimeInstance(DateFormat.DEFAULT, DateFormat.SHORT, Locale.getDefault()) - lastModifiedTextView.text = getString(R.string.last_modified, dateFormat.format(Date(file.lastModified()))) + fileSizeTextView.text = fileSizeText + val dateFormat = DateFormat.getDateTimeInstance(DateFormat.DEFAULT, DateFormat.SHORT, Locale.getDefault()) + lastModifiedTextView.text = dateFormat.format(Date(file.lastModified())) val dialog = MaterialAlertDialogBuilder(requireContext(), R.style.MaterialDialog) .setView(dialogView) .create() diff --git a/app/src/main/java/com/wirelessalien/zipxtract/fragment/MainFragment.kt b/app/src/main/java/com/wirelessalien/zipxtract/fragment/MainFragment.kt index 95b43f8..5d7f864 100644 --- a/app/src/main/java/com/wirelessalien/zipxtract/fragment/MainFragment.kt +++ b/app/src/main/java/com/wirelessalien/zipxtract/fragment/MainFragment.kt @@ -38,6 +38,7 @@ import android.os.Handler import android.os.Looper import android.os.storage.StorageManager import android.provider.Settings +import android.text.Editable import android.view.LayoutInflater import android.view.Menu import android.view.MenuInflater @@ -53,6 +54,7 @@ import androidx.appcompat.app.AlertDialog import androidx.appcompat.app.AppCompatActivity import androidx.appcompat.view.ActionMode import androidx.appcompat.widget.SearchView +import androidx.core.app.NotificationManagerCompat import androidx.core.content.ContextCompat import androidx.core.content.FileProvider import androidx.core.view.MenuHost @@ -74,7 +76,6 @@ import com.google.android.material.snackbar.Snackbar import com.google.android.material.textfield.TextInputEditText import com.google.android.material.transition.MaterialSharedAxis import com.wirelessalien.zipxtract.BuildConfig -import com.wirelessalien.zipxtract.viewmodel.FileOperationViewModel import com.wirelessalien.zipxtract.R import com.wirelessalien.zipxtract.activity.SettingsActivity import com.wirelessalien.zipxtract.adapter.FileAdapter @@ -100,6 +101,7 @@ import com.wirelessalien.zipxtract.service.ExtractCsArchiveService import com.wirelessalien.zipxtract.service.ExtractMultipart7zService import com.wirelessalien.zipxtract.service.ExtractMultipartZipService import com.wirelessalien.zipxtract.service.ExtractRarService +import com.wirelessalien.zipxtract.viewmodel.FileOperationViewModel import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.Job @@ -246,6 +248,17 @@ class MainFragment : Fragment(), FileAdapter.OnItemClickListener, FileAdapter.On } } + private val requestNotificationPermissionLauncher = registerForActivityResult( + ActivityResultContracts.RequestPermission() + ) { isGranted: Boolean -> + if (isGranted) { + // Permission granted + } else { + // Permission denied + Toast.makeText(requireContext(), getString(R.string.permission_denied), Toast.LENGTH_SHORT).show() + } + } + private fun navigateToParentDir(parentDir: File) { val fragment = MainFragment().apply { arguments = Bundle().apply { @@ -272,6 +285,12 @@ class MainFragment : Fragment(), FileAdapter.OnItemClickListener, FileAdapter.On super.onCreate(savedInstanceState) enterTransition = MaterialSharedAxis(MaterialSharedAxis.Z, true) exitTransition = MaterialSharedAxis(MaterialSharedAxis.Z, false) + + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) { + if (!NotificationManagerCompat.from(requireContext()).areNotificationsEnabled()) { + requestNotificationPermissionLauncher.launch(Manifest.permission.POST_NOTIFICATIONS) + } + } } override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View { @@ -1321,35 +1340,37 @@ class MainFragment : Fragment(), FileAdapter.OnItemClickListener, FileAdapter.On private fun showFileInfo(file: File) { val dialogView = LayoutInflater.from(requireContext()).inflate(R.layout.dialog_file_info, null) - val fileNameTextView = dialogView.findViewById<TextView>(R.id.file_name) - val filePathTextView = dialogView.findViewById<TextView>(R.id.file_path) + val fileNameTextView = dialogView.findViewById<TextInputEditText>(R.id.file_name) + val filePathTextView = dialogView.findViewById<TextInputEditText>(R.id.file_path) val fileSizeTextView = dialogView.findViewById<TextView>(R.id.file_size) val lastModifiedTextView = dialogView.findViewById<TextView>(R.id.last_modified) val okButton = dialogView.findViewById<Button>(R.id.ok_button) - fileNameTextView.text = getString(R.string.file_name, file.name) - filePathTextView.text = getString(R.string.file_path, file.absolutePath) + fileNameTextView.text = Editable.Factory.getInstance().newEditable(file.name) + filePathTextView.text = Editable.Factory.getInstance().newEditable(file.absolutePath) val fileSizeText = bytesToString(file.length()) - fileSizeTextView.text = getString(R.string.file_size, fileSizeText) + fileSizeTextView.text = fileSizeText val dateFormat = DateFormat.getDateTimeInstance(DateFormat.DEFAULT, DateFormat.SHORT, Locale.getDefault()) - lastModifiedTextView.text = getString(R.string.last_modified, dateFormat.format(Date(file.lastModified()))) + lastModifiedTextView.text = dateFormat.format(Date(file.lastModified())) val clipboardManager = requireContext().getSystemService(Context.CLIPBOARD_SERVICE) as ClipboardManager - - fileNameTextView.setOnClickListener { + fileNameTextView.setOnLongClickListener { val clip = ClipData.newPlainText("File Name", file.name) clipboardManager.setPrimaryClip(clip) Toast.makeText(requireContext(), getString(R.string.copied_to_clipboard), Toast.LENGTH_SHORT).show() + true } - filePathTextView.setOnClickListener { + filePathTextView.setOnLongClickListener { val clip = ClipData.newPlainText("File Path", file.absolutePath) clipboardManager.setPrimaryClip(clip) Toast.makeText(requireContext(), getString(R.string.copied_to_clipboard), Toast.LENGTH_SHORT).show() + true } val dialog = MaterialAlertDialogBuilder(requireContext(), R.style.MaterialDialog) .setView(dialogView) + .setTitle(getString(R.string.file_info)) .create() okButton.setOnClickListener { diff --git a/app/src/main/res/layout/dialog_file_info.xml b/app/src/main/res/layout/dialog_file_info.xml index be830fb..28420b9 100644 --- a/app/src/main/res/layout/dialog_file_info.xml +++ b/app/src/main/res/layout/dialog_file_info.xml @@ -22,36 +22,82 @@ android:orientation="vertical" android:padding="16dp"> - <TextView - android:id="@+id/file_name" + <com.google.android.material.textfield.TextInputLayout android:layout_width="match_parent" android:layout_height="wrap_content" - android:textStyle="bold" - android:textSize="16sp" - android:paddingBottom="16dp" /> + android:hint="@string/name"> - <TextView - android:id="@+id/file_path" + <com.google.android.material.textfield.TextInputEditText + android:id="@+id/file_name" + android:layout_width="match_parent" + android:layout_height="wrap_content" + style="@style/Widget.Material3.TextInputEditText.OutlinedBox.Dense" + android:textStyle="bold" + android:inputType="none" + android:cursorVisible="false" + android:clickable="true" + android:focusable="false"/> + </com.google.android.material.textfield.TextInputLayout> + + <com.google.android.material.textfield.TextInputLayout android:layout_width="match_parent" android:layout_height="wrap_content" - android:paddingBottom="16dp" /> + android:layout_marginTop="16dp" + android:hint="@string/file_path"> + + <com.google.android.material.textfield.TextInputEditText + android:id="@+id/file_path" + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:textSize="14sp" + style="@style/Widget.Material3.TextInputEditText.OutlinedBox.Dense" + android:inputType="none" + android:cursorVisible="false" + android:clickable="false" + android:focusable="false"/> + </com.google.android.material.textfield.TextInputLayout> - <TextView - android:id="@+id/file_size" + <com.google.android.material.textfield.TextInputLayout android:layout_width="match_parent" android:layout_height="wrap_content" - android:paddingBottom="16dp" /> + android:layout_marginTop="16dp" + android:hint="@string/file_size"> - <TextView - android:id="@+id/last_modified" + <com.google.android.material.textfield.TextInputEditText + android:id="@+id/file_size" + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:textSize="14sp" + style="@style/Widget.Material3.TextInputEditText.OutlinedBox.Dense" + android:inputType="none" + android:cursorVisible="false" + android:clickable="false" + android:focusable="false"/> + </com.google.android.material.textfield.TextInputLayout> + + <com.google.android.material.textfield.TextInputLayout android:layout_width="match_parent" android:layout_height="wrap_content" - android:paddingBottom="16dp" /> + android:layout_marginTop="16dp" + android:hint="@string/last_modified"> + + <com.google.android.material.textfield.TextInputEditText + android:id="@+id/last_modified" + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:textSize="14sp" + style="@style/Widget.Material3.TextInputEditText.OutlinedBox.Dense" + android:inputType="none" + android:cursorVisible="false" + android:clickable="false" + android:focusable="false"/> + </com.google.android.material.textfield.TextInputLayout> <com.google.android.material.button.MaterialButton android:id="@+id/ok_button" android:layout_width="match_parent" android:layout_height="wrap_content" + android:layout_marginTop="16dp" app:cornerRadius="5dp" style="@style/Widget.Material3.Button.TonalButton" android:text="@string/ok" /> diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index b4150af..bcea31e 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -141,10 +141,9 @@ <string name="confirm_delete">Confirm Delete</string> <string name="confirm_delete_message">Do you really want to delete?</string> <string name="file_deleted">Deleted</string> - <string name="file_name">Name: %1$s</string> - <string name="file_path">Path: %1$s</string> - <string name="file_size">Size: %1$s</string> - <string name="last_modified">Last Modified: %1$s</string> + <string name="file_path">Path</string> + <string name="file_size">Size</string> + <string name="last_modified">Last Modified</string> <string name="grant_access">Allow Access</string> <string name="storage_access_permission_text">This app needs access to your device storage to function properly. Please grant the necessary permissions.</string> <string name="archive_success">File archived successfully</string>