First commit
This commit is contained in:
BIN
app/src/main/assets/logo.png
Normal file
BIN
app/src/main/assets/logo.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 24 KiB |
@@ -54,7 +54,7 @@ class AudioGalleryActivity : BaseGalleryActivity() {
|
||||
}
|
||||
}
|
||||
|
||||
override fun openPreview(file: File) {
|
||||
override fun openPreview() {
|
||||
// Implement audio preview
|
||||
}
|
||||
}
|
||||
@@ -62,7 +62,7 @@ abstract class BaseGalleryActivity : AppCompatActivity() {
|
||||
adapter.submitList(files)
|
||||
}
|
||||
|
||||
abstract fun openPreview(file: File)
|
||||
abstract fun openPreview()
|
||||
|
||||
private fun checkPermissions() {
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
|
||||
|
||||
@@ -54,7 +54,7 @@ class DocumentsActivity : BaseGalleryActivity() {
|
||||
}
|
||||
}
|
||||
|
||||
override fun openPreview(file: File) {
|
||||
override fun openPreview() {
|
||||
// Implement document preview
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,6 @@
|
||||
package devs.org.calculator.activities
|
||||
|
||||
import android.app.RecoverableSecurityException
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.net.Uri
|
||||
import android.os.Build
|
||||
@@ -14,10 +13,8 @@ import androidx.activity.result.ActivityResultLauncher
|
||||
import androidx.activity.result.IntentSenderRequest
|
||||
import androidx.activity.result.contract.ActivityResultContracts
|
||||
import androidx.documentfile.provider.DocumentFile
|
||||
import androidx.lifecycle.lifecycleScope
|
||||
import devs.org.calculator.utils.FileManager
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.launch
|
||||
import kotlinx.coroutines.withContext
|
||||
import java.io.File
|
||||
|
||||
@@ -28,62 +25,6 @@ class ImageGalleryActivity : BaseGalleryActivity() {
|
||||
private var selectedImageUri: Uri? = null
|
||||
private lateinit var pickImageLauncher: ActivityResultLauncher<Intent>
|
||||
|
||||
private suspend fun deletePhotoFromExternalStorage(photoUri: Uri) {
|
||||
withContext(Dispatchers.IO) {
|
||||
try {
|
||||
// First try to delete using DocumentFile
|
||||
val documentFile = DocumentFile.fromSingleUri(this@ImageGalleryActivity, photoUri)
|
||||
if (documentFile?.exists() == true && documentFile.canWrite()) {
|
||||
val deleted = documentFile.delete()
|
||||
withContext(Dispatchers.Main) {
|
||||
if (deleted) {
|
||||
Toast.makeText(this@ImageGalleryActivity, "File deleted successfully", Toast.LENGTH_SHORT).show()
|
||||
selectedImageUri = null
|
||||
} else {
|
||||
Toast.makeText(this@ImageGalleryActivity, "Failed to delete file", Toast.LENGTH_SHORT).show()
|
||||
}
|
||||
}
|
||||
return@withContext
|
||||
}
|
||||
|
||||
// If DocumentFile approach fails, try content resolver
|
||||
try {
|
||||
contentResolver.delete(photoUri, null, null)
|
||||
withContext(Dispatchers.Main) {
|
||||
Toast.makeText(this@ImageGalleryActivity, "File deleted successfully", Toast.LENGTH_SHORT).show()
|
||||
}
|
||||
} catch (e: SecurityException) {
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
|
||||
val intentSender = when {
|
||||
Build.VERSION.SDK_INT >= Build.VERSION_CODES.R -> {
|
||||
MediaStore.createDeleteRequest(contentResolver, listOf(photoUri)).intentSender
|
||||
}
|
||||
else -> {
|
||||
val recoverableSecurityException = e as? RecoverableSecurityException
|
||||
recoverableSecurityException?.userAction?.actionIntent?.intentSender
|
||||
}
|
||||
}
|
||||
intentSender?.let { sender ->
|
||||
withContext(Dispatchers.Main) {
|
||||
intentSenderLauncher.launch(
|
||||
IntentSenderRequest.Builder(sender).build()
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
withContext(Dispatchers.Main) {
|
||||
Toast.makeText(
|
||||
this@ImageGalleryActivity,
|
||||
"Error deleting file: ${e.message}",
|
||||
Toast.LENGTH_LONG
|
||||
).show()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
setupIntentSenderLauncher()
|
||||
@@ -156,10 +97,9 @@ class ImageGalleryActivity : BaseGalleryActivity() {
|
||||
}
|
||||
}
|
||||
|
||||
override fun openPreview(file: File) {
|
||||
override fun openPreview() {
|
||||
val intent = Intent(this, PreviewActivity::class.java).apply {
|
||||
putExtra(PreviewActivity.EXTRA_FILE_PATH, file.absolutePath)
|
||||
putExtra(PreviewActivity.EXTRA_FILE_TYPE, fileType.name)
|
||||
putExtra("type", fileType)
|
||||
}
|
||||
startActivity(intent)
|
||||
}
|
||||
|
||||
@@ -55,10 +55,9 @@ class VideoGalleryActivity : BaseGalleryActivity() {
|
||||
}
|
||||
}
|
||||
|
||||
override fun openPreview(file: File) {
|
||||
override fun openPreview() {
|
||||
val intent = Intent(this, PreviewActivity::class.java).apply {
|
||||
putExtra(PreviewActivity.EXTRA_FILE_PATH, file.absolutePath)
|
||||
putExtra(PreviewActivity.EXTRA_FILE_TYPE, fileType.name)
|
||||
putExtra("type", fileType)
|
||||
}
|
||||
startActivity(intent)
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
<androidx.constraintlayout.widget.ConstraintLayout 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="match_parent"
|
||||
android:orientation="vertical">
|
||||
@@ -8,12 +9,44 @@
|
||||
android:id="@+id/toolbar"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="?attr/actionBarSize"
|
||||
android:background="?attr/colorPrimary" />
|
||||
android:background="?attr/colorPrimary"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent" />
|
||||
|
||||
<androidx.viewpager.widget.ViewPager
|
||||
android:id="@+id/viewPager"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="0dp"
|
||||
android:layout_weight="1" />
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@+id/toolbar" />
|
||||
|
||||
</LinearLayout>
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:gravity="center_horizontal"
|
||||
android:orientation="horizontal"
|
||||
android:padding="8dp"
|
||||
app:layout_constraintBottom_toBottomOf="@+id/viewPager"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent">
|
||||
|
||||
<com.google.android.material.button.MaterialButton
|
||||
android:id="@+id/unhide"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_margin="6dp"
|
||||
android:text="Unhide" />
|
||||
|
||||
<com.google.android.material.button.MaterialButton
|
||||
android:id="@+id/delete"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_margin="6dp"
|
||||
android:text="Delete" />
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
Reference in New Issue
Block a user