From 7c7040af7434b7acfa3bbb58e41cb315960b4d50 Mon Sep 17 00:00:00 2001 From: WirelessAlien <121420261+WirelessAlien@users.noreply.github.com> Date: Mon, 23 Dec 2024 21:11:10 +0530 Subject: [PATCH] remove cancel intent --- .../zipxtract/activity/MainActivity.kt | 1 - .../zipxtract/adapter/FileAdapter.kt | 18 ++- .../zipxtract/fragment/MainFragment.kt | 152 +++--------------- app/src/main/res/layout/fragment_archive.xml | 1 + app/src/main/res/layout/fragment_main.xml | 4 +- app/src/main/res/menu/menu_action.xml | 6 +- 6 files changed, 40 insertions(+), 142 deletions(-) diff --git a/app/src/main/java/com/wirelessalien/zipxtract/activity/MainActivity.kt b/app/src/main/java/com/wirelessalien/zipxtract/activity/MainActivity.kt index e3c8da8..6a16165 100644 --- a/app/src/main/java/com/wirelessalien/zipxtract/activity/MainActivity.kt +++ b/app/src/main/java/com/wirelessalien/zipxtract/activity/MainActivity.kt @@ -50,7 +50,6 @@ class MainActivity : AppCompatActivity() { } } - // Load the default fragment if (savedInstanceState == null) { bottomNavigationView.selectedItemId = R.id.home } diff --git a/app/src/main/java/com/wirelessalien/zipxtract/adapter/FileAdapter.kt b/app/src/main/java/com/wirelessalien/zipxtract/adapter/FileAdapter.kt index 81d6ec4..1c0dd34 100644 --- a/app/src/main/java/com/wirelessalien/zipxtract/adapter/FileAdapter.kt +++ b/app/src/main/java/com/wirelessalien/zipxtract/adapter/FileAdapter.kt @@ -220,11 +220,19 @@ class FileAdapter(private val context: Context, private val mainFragment: MainFr } private fun getFileTimeOfCreation(file: File): Long { - return if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { - val attr = Files.readAttributes(file.toPath(), BasicFileAttributes::class.java) - attr.lastModifiedTime().toMillis() - } else { - file.lastModified() + return try { + if (file.exists()) { + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { + val attr = Files.readAttributes(file.toPath(), BasicFileAttributes::class.java) + attr.lastModifiedTime().toMillis() + } else { + file.lastModified() + } + } else { + System.currentTimeMillis() + } + } catch (e: NoSuchFileException) { + System.currentTimeMillis() } } 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 4ee6d1c..824af08 100644 --- a/app/src/main/java/com/wirelessalien/zipxtract/fragment/MainFragment.kt +++ b/app/src/main/java/com/wirelessalien/zipxtract/fragment/MainFragment.kt @@ -20,7 +20,6 @@ package com.wirelessalien.zipxtract.fragment import android.Manifest import android.annotation.SuppressLint import android.app.Activity -import android.app.ActivityManager import android.content.BroadcastReceiver import android.content.Context import android.content.Intent @@ -59,6 +58,7 @@ import androidx.fragment.app.FragmentTransaction import androidx.lifecycle.Lifecycle import androidx.localbroadcastmanager.content.LocalBroadcastManager import androidx.recyclerview.widget.LinearLayoutManager +import androidx.transition.TransitionInflater import com.google.android.material.bottomsheet.BottomSheetDialog import com.google.android.material.button.MaterialButton import com.google.android.material.chip.Chip @@ -68,22 +68,13 @@ import com.google.android.material.textfield.TextInputEditText import com.wirelessalien.zipxtract.BuildConfig import com.wirelessalien.zipxtract.R import com.wirelessalien.zipxtract.adapter.FileAdapter -import com.wirelessalien.zipxtract.constant.BroadcastConstants.ACTION_ARCHIVE_7Z_CANCEL import com.wirelessalien.zipxtract.constant.BroadcastConstants.ACTION_ARCHIVE_COMPLETE import com.wirelessalien.zipxtract.constant.BroadcastConstants.ACTION_ARCHIVE_ERROR import com.wirelessalien.zipxtract.constant.BroadcastConstants.ACTION_ARCHIVE_PROGRESS -import com.wirelessalien.zipxtract.constant.BroadcastConstants.ACTION_ARCHIVE_SPLIT_ZIP_CANCEL -import com.wirelessalien.zipxtract.constant.BroadcastConstants.ACTION_ARCHIVE_TAR_CANCEL -import com.wirelessalien.zipxtract.constant.BroadcastConstants.ACTION_ARCHIVE_ZIP_CANCEL -import com.wirelessalien.zipxtract.constant.BroadcastConstants.ACTION_COMPRESS_CANCEL import com.wirelessalien.zipxtract.constant.BroadcastConstants.ACTION_EXTRACTION_COMPLETE import com.wirelessalien.zipxtract.constant.BroadcastConstants.ACTION_EXTRACTION_ERROR import com.wirelessalien.zipxtract.constant.BroadcastConstants.ACTION_EXTRACTION_PROGRESS -import com.wirelessalien.zipxtract.constant.BroadcastConstants.ACTION_EXTRACT_CANCEL -import com.wirelessalien.zipxtract.constant.BroadcastConstants.ACTION_EXTRACT_CS_CANCEL -import com.wirelessalien.zipxtract.constant.BroadcastConstants.ACTION_MULTI_7Z_EXTRACTION_CANCEL -import com.wirelessalien.zipxtract.constant.BroadcastConstants.ACTION_MULTI_ZIP_EXTRACTION_CANCEL -import com.wirelessalien.zipxtract.constant.BroadcastConstants.ACTION_RAR_EXTRACTION_CANCEL +import com.wirelessalien.zipxtract.constant.BroadcastConstants.EXTRA_DIR_PATH import com.wirelessalien.zipxtract.constant.BroadcastConstants.EXTRA_ERROR_MESSAGE import com.wirelessalien.zipxtract.constant.BroadcastConstants.EXTRA_PROGRESS import com.wirelessalien.zipxtract.databinding.FragmentMainBinding @@ -136,7 +127,8 @@ class MainFragment : Fragment(), FileAdapter.OnItemClickListener, FileAdapter.On private var searchRunnable: Runnable? = null private lateinit var eProgressDialog: AlertDialog private lateinit var aProgressDialog: AlertDialog - private lateinit var progressText: TextView + private lateinit var aProgressText: TextView + private lateinit var eProgressText: TextView private var areFabsVisible: Boolean = false private lateinit var eProgressBar: LinearProgressIndicator private lateinit var aProgressBar: LinearProgressIndicator @@ -147,6 +139,8 @@ class MainFragment : Fragment(), FileAdapter.OnItemClickListener, FileAdapter.On override fun onReceive(context: Context?, intent: Intent?) { when (intent?.action) { ACTION_EXTRACTION_COMPLETE -> { + val dirPath = intent.getStringExtra(EXTRA_DIR_PATH) + unselectAllFiles() eProgressDialog.dismiss() Toast.makeText(requireContext(), getString(R.string.extraction_success), Toast.LENGTH_SHORT).show() @@ -161,9 +155,11 @@ class MainFragment : Fragment(), FileAdapter.OnItemClickListener, FileAdapter.On val progress = intent.getIntExtra(EXTRA_PROGRESS, 0) updateProgressBar(progress) eProgressBar.progress = progress - progressText.text = getString(R.string.extracting_progress, progress) + eProgressText.text = getString(R.string.extracting_progress, progress) } ACTION_ARCHIVE_COMPLETE -> { + val dirPath = intent.getStringExtra(EXTRA_DIR_PATH) + unselectAllFiles() aProgressDialog.dismiss() Toast.makeText(requireContext(), getString(R.string.compression_success), Toast.LENGTH_SHORT).show() @@ -178,7 +174,7 @@ class MainFragment : Fragment(), FileAdapter.OnItemClickListener, FileAdapter.On val progress = intent.getIntExtra(EXTRA_PROGRESS, 0) updateProgressBar(progress) aProgressBar.progress = progress - progressText.text = getString(R.string.compressing_progress, progress) + aProgressText.text = getString(R.string.compressing_progress, progress) } } } @@ -194,6 +190,13 @@ class MainFragment : Fragment(), FileAdapter.OnItemClickListener, FileAdapter.On updateActionModeTitle() } + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + val inflater = TransitionInflater.from(requireContext()) + enterTransition = inflater.inflateTransition(R.transition.fade_through) + exitTransition = inflater.inflateTransition(R.transition.fade_through) + } + override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View { binding = FragmentMainBinding.inflate(inflater, container, false) return binding.root @@ -432,70 +435,12 @@ class MainFragment : Fragment(), FileAdapter.OnItemClickListener, FileAdapter.On actionMode?.finish() } - @Suppress("DEPRECATION") private fun archiveProgressDialog() { val aDialogView = layoutInflater.inflate(R.layout.progress_dialog_archive, null) aProgressBar = aDialogView.findViewById(R.id.progressBar) - progressText = aDialogView.findViewById(R.id.progressText) - val cancelButton = aDialogView.findViewById