Skip to content

Commit

Permalink
a few fix
Browse files Browse the repository at this point in the history
  • Loading branch information
WirelessAlien committed Dec 17, 2024
1 parent 4db1084 commit 14e5d3e
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -597,12 +597,12 @@ class MainActivity : AppCompatActivity(), FileAdapter.OnItemClickListener, FileA

private fun initRecyclerView() {
// Initialize RecyclerView and adapter as before
recyclerView = findViewById(R.id.recyclerView)
recyclerView.layoutManager = LinearLayoutManager(this)
binding.recyclerView.layoutManager = LinearLayoutManager(this)
binding.recyclerView.isNestedScrollingEnabled = false
adapter = FileAdapter(this, this, ArrayList())
adapter.setOnItemClickListener(this)
adapter.setOnFileLongClickListener(this)
recyclerView.adapter = adapter
binding.recyclerView.adapter = adapter
// Update the adapter with the initial file list
updateAdapterWithFullList()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ object BroadcastConstants {
const val ACTION_MULTI_ZIP_EXTRACTION_CANCEL = "ACTION_ZIP_EXTRACTION_CANCEL"
const val ACTION_ARCHIVE_7Z_CANCEL = "ACTION_7Z_ARCHIVE_CANCEL"
const val ACTION_ARCHIVE_ZIP_CANCEL = "ACTION_ZIP_ARCHIVE_CANCEL"
const val ACTION_ARCHIVE_TAR_CANCEL = "ACTION_TAR_ARCHIVE_CANCEL"
const val ACTION_ARCHIVE_SPLIT_ZIP_CANCEL = "ACTION_SPLIT_ZIP_ARCHIVE_CANCEL"
const val ACTION_ARCHIVE_COMPLETE = "ACTION_ARCHIVE_COMPLETE"
const val ACTION_ARCHIVE_ERROR = "ACTION_ARCHIVE_ERROR"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ import com.wirelessalien.zipxtract.R
import com.wirelessalien.zipxtract.constant.BroadcastConstants
import com.wirelessalien.zipxtract.constant.BroadcastConstants.ACTION_ARCHIVE_COMPLETE
import com.wirelessalien.zipxtract.constant.BroadcastConstants.ACTION_ARCHIVE_ERROR
import com.wirelessalien.zipxtract.constant.BroadcastConstants.ARCHIVE_NOTIFICATION_CHANNEL_ID
import com.wirelessalien.zipxtract.constant.BroadcastConstants.EXTRA_PROGRESS
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.Job
Expand All @@ -53,7 +55,6 @@ class Archive7zService : Service() {

companion object {
const val NOTIFICATION_ID = 808
const val CHANNEL_ID = "archive_service_channel"
const val EXTRA_ARCHIVE_NAME = "archiveName"
const val EXTRA_PASSWORD = "password"
const val EXTRA_COMPRESSION_LEVEL = "compressionLevel"
Expand Down Expand Up @@ -109,8 +110,8 @@ class Archive7zService : Service() {
private fun createNotificationChannel() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
val channel = NotificationChannel(
CHANNEL_ID,
"Archive Service",
ARCHIVE_NOTIFICATION_CHANNEL_ID,
getString(R.string.compress_archive_notification_name),
NotificationManager.IMPORTANCE_LOW
)
val notificationManager = getSystemService(NotificationManager::class.java)
Expand All @@ -119,11 +120,11 @@ class Archive7zService : Service() {
}

private fun createNotification(progress: Int): Notification {
val builder = NotificationCompat.Builder(this, CHANNEL_ID)
.setContentTitle("Creating Archive")
val builder = NotificationCompat.Builder(this, ARCHIVE_NOTIFICATION_CHANNEL_ID)
.setContentTitle(getString(R.string.archive_ongoing))
.setSmallIcon(R.drawable.ic_notification_icon)
.setProgress(100, progress, progress == 0)
.addAction(R.drawable.ic_round_cancel, "Cancel", createCancelIntent())
.addAction(R.drawable.ic_round_cancel, getString(R.string.cancel), createCancelIntent())
.setOngoing(true)

return builder.build()
Expand Down Expand Up @@ -180,7 +181,7 @@ class Archive7zService : Service() {
}

override fun getStream(i: Int): ISequentialInStream {
if (archiveJob?.isCancelled == true) throw SevenZipException("Extraction cancelled")
if (archiveJob?.isCancelled == true) throw SevenZipException(getString(R.string.operation_cancelled))

return RandomAccessFileInStream(RandomAccessFile(filesToArchive[i], "r"))
}
Expand All @@ -196,16 +197,16 @@ class Archive7zService : Service() {
}
} catch (e: SevenZipException) {
e.printStackTrace()
showErrorNotification("Archive creation failed: ${e.message}")
sendLocalBroadcast(Intent(ACTION_ARCHIVE_ERROR).putExtra("error_message", "Archive creation failed: ${e.message}"))
showErrorNotification(": ${e.message}")
sendLocalBroadcast(Intent(ACTION_ARCHIVE_ERROR).putExtra(EXTRA_PROGRESS, ": ${e.message}"))
} catch (e: IOException) {
e.printStackTrace()
showErrorNotification("Archive creation failed: ${e.message}")
sendLocalBroadcast(Intent(ACTION_ARCHIVE_ERROR).putExtra("error_message", "Archive creation failed: ${e.message}"))
showErrorNotification(": ${e.message}")
sendLocalBroadcast(Intent(ACTION_ARCHIVE_ERROR).putExtra(EXTRA_PROGRESS, ": ${e.message}"))
} catch (e: OutOfMemoryError) {
e.printStackTrace()
showErrorNotification("Archive creation failed: ${e.message}")
sendLocalBroadcast(Intent(ACTION_ARCHIVE_ERROR).putExtra("error_message", "Archive creation failed: ${e.message}"))
showErrorNotification(": ${e.message}")
sendLocalBroadcast(Intent(ACTION_ARCHIVE_ERROR).putExtra(EXTRA_PROGRESS, ": ${e.message}"))
}
}

Expand All @@ -215,13 +216,13 @@ class Archive7zService : Service() {
notificationManager.notify(NOTIFICATION_ID, notification)

sendLocalBroadcast(Intent(BroadcastConstants.ACTION_ARCHIVE_PROGRESS).putExtra(
BroadcastConstants.EXTRA_PROGRESS, progress))
EXTRA_PROGRESS, progress))
}

private fun showErrorNotification(error: String) {
stopForegroundService()
val notification = NotificationCompat.Builder(this, CHANNEL_ID)
.setContentTitle("Archive Creation Failed")
val notification = NotificationCompat.Builder(this, ARCHIVE_NOTIFICATION_CHANNEL_ID)
.setContentTitle(getString(R.string.sevenz_creation_failed))
.setContentText(error)
.setSmallIcon(R.drawable.ic_notification_icon)
.setAutoCancel(true)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import com.wirelessalien.zipxtract.R
import com.wirelessalien.zipxtract.constant.BroadcastConstants
import com.wirelessalien.zipxtract.constant.BroadcastConstants.ACTION_ARCHIVE_COMPLETE
import com.wirelessalien.zipxtract.constant.BroadcastConstants.ACTION_ARCHIVE_ERROR
import com.wirelessalien.zipxtract.constant.BroadcastConstants.ARCHIVE_NOTIFICATION_CHANNEL_ID
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.Job
Expand All @@ -51,7 +52,6 @@ class ArchiveSplitZipService : Service() {

companion object {
const val NOTIFICATION_ID = 754
const val CHANNEL_ID = "split_zip_service_channel"
const val EXTRA_ARCHIVE_NAME = "archiveName"
const val EXTRA_PASSWORD = "password"
const val EXTRA_COMPRESSION_METHOD = "compressionMethod"
Expand Down Expand Up @@ -113,8 +113,8 @@ class ArchiveSplitZipService : Service() {
private fun createNotificationChannel() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
val channel = NotificationChannel(
CHANNEL_ID,
"Split Zip Service",
ARCHIVE_NOTIFICATION_CHANNEL_ID,
getString(R.string.compress_archive_notification_name),
NotificationManager.IMPORTANCE_LOW
)
val notificationManager = getSystemService(NotificationManager::class.java)
Expand All @@ -123,11 +123,11 @@ class ArchiveSplitZipService : Service() {
}

private fun createNotification(progress: Int): Notification {
val builder = NotificationCompat.Builder(this, CHANNEL_ID)
.setContentTitle("Creating Split Zip Archive")
val builder = NotificationCompat.Builder(this, ARCHIVE_NOTIFICATION_CHANNEL_ID)
.setContentTitle(getString(R.string.archive_ongoing))
.setSmallIcon(R.drawable.ic_notification_icon)
.setProgress(100, progress, progress == 0)
.addAction(R.drawable.ic_round_cancel, "Cancel", createCancelIntent())
.addAction(R.drawable.ic_round_cancel, getString(R.string.cancel), createCancelIntent())
.setOngoing(true)

return builder.build()
Expand Down Expand Up @@ -209,7 +209,7 @@ class ArchiveSplitZipService : Service() {
showCompletionNotification("$archiveName.zip created successfully")
sendLocalBroadcast(Intent(ACTION_ARCHIVE_COMPLETE))
} else {
showErrorNotification("Archive creation failed")
showErrorNotification(getString(R.string.zip_creation_failed))
sendLocalBroadcast(Intent(ACTION_ARCHIVE_ERROR).putExtra("error_message", "Archive creation failed: ${progressMonitor.result}"))
}

Expand Down Expand Up @@ -241,7 +241,7 @@ class ArchiveSplitZipService : Service() {

private fun showErrorNotification(error: String) {
stopForegroundService()
val notification = NotificationCompat.Builder(this, CHANNEL_ID)
val notification = NotificationCompat.Builder(this, ARCHIVE_NOTIFICATION_CHANNEL_ID)
.setContentTitle("Archive Creation Failed")
.setContentText(error)
.setSmallIcon(R.drawable.ic_folder_zip)
Expand All @@ -255,7 +255,7 @@ class ArchiveSplitZipService : Service() {
private fun showCompletionNotification(message: String) {
stopForegroundService()

val notification = NotificationCompat.Builder(this, CHANNEL_ID)
val notification = NotificationCompat.Builder(this, ARCHIVE_NOTIFICATION_CHANNEL_ID)
.setContentTitle("Archive Creation Complete")
.setContentText(message)
.setSmallIcon(R.drawable.ic_notification_icon)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,13 @@ import android.os.IBinder
import androidx.core.app.NotificationCompat
import androidx.localbroadcastmanager.content.LocalBroadcastManager
import com.wirelessalien.zipxtract.R
import com.wirelessalien.zipxtract.constant.BroadcastConstants
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.EXTRACTION_NOTIFICATION_CHANNEL_ID
import com.wirelessalien.zipxtract.constant.BroadcastConstants.EXTRA_ERROR_MESSAGE
import com.wirelessalien.zipxtract.constant.BroadcastConstants.EXTRA_PROGRESS
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.Job
Expand Down Expand Up @@ -106,7 +107,7 @@ class ExtractCsArchiveService : Service() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
val channel = NotificationChannel(
EXTRACTION_NOTIFICATION_CHANNEL_ID,
"Extraction Service",
getString(R.string.extract_archive_notification_name),
NotificationManager.IMPORTANCE_LOW
)
val notificationManager = getSystemService(NotificationManager::class.java)
Expand Down Expand Up @@ -189,16 +190,17 @@ class ExtractCsArchiveService : Service() {
e.printStackTrace()
showErrorNotification(e.message ?: getString(R.string.extraction_failed))
sendLocalBroadcast(Intent(ACTION_EXTRACTION_ERROR).putExtra(EXTRA_ERROR_MESSAGE, e.message ?: getString(R.string.extraction_failed)))
} finally {
stopForegroundService()
}
}

private fun updateProgress(progress: Int) {
val notification = createNotification(progress)
val notificationManager = getSystemService(NotificationManager::class.java)
notificationManager.notify(ExtractArchiveService.NOTIFICATION_ID, notification)
notificationManager.notify(NOTIFICATION_ID, notification)

sendLocalBroadcast(Intent(BroadcastConstants.ACTION_EXTRACTION_PROGRESS).putExtra(
BroadcastConstants.EXTRA_PROGRESS, progress))
sendLocalBroadcast(Intent(ACTION_EXTRACTION_PROGRESS).putExtra(EXTRA_PROGRESS, progress))
}

private fun showCompletionNotification() {
Expand Down
5 changes: 5 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -103,4 +103,9 @@
<string name="extension">Extension</string>
<string name="unsupported_compression_format">Unsupported compression format</string>
<string name="extraction_ongoing">Extracting file</string>
<string name="archive_ongoing">Archiving file</string>
<string name="operation_cancelled">Operation cancelled</string>
<string name="compress_archive_notification_name">Compress Archive</string>
<string name="extract_archive_notification_name">Extract Archive</string>
<string name="tar_creation_failed">Tar creation failed</string>
</resources>

0 comments on commit 14e5d3e

Please sign in to comment.