Skip to content

Commit 17488fe

Browse files
committed
fix empty gallery issue
1 parent 71928cc commit 17488fe

File tree

3 files changed

+36
-1
lines changed

3 files changed

+36
-1
lines changed

app/src/main/java/app/grapheneos/camera/CamConfig.kt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -640,6 +640,15 @@ class CamConfig(private val mActivity: MainActivity) {
640640
lastCapturedItem = item
641641
}
642642

643+
fun clearLastCapturedItem() {
644+
commonPref.edit {
645+
remove(SettingValues.Key.LAST_CAPTURED_ITEM_TYPE)
646+
remove(SettingValues.Key.LAST_CAPTURED_ITEM_DATE_STRING)
647+
remove(SettingValues.Key.LAST_CAPTURED_ITEM_URI)
648+
}
649+
lastCapturedItem = null
650+
}
651+
643652
var requireLocation: Boolean = false
644653
get() {
645654
return mActivity.settingsDialog.locToggle.isChecked

app/src/main/java/app/grapheneos/camera/ui/activities/InAppGallery.kt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package app.grapheneos.camera.ui.activities
33
import android.animation.ArgbEvaluator
44
import android.animation.ValueAnimator
55
import android.annotation.SuppressLint
6+
import android.app.Activity
67
import android.content.ActivityNotFoundException
78
import android.content.Context
89
import android.content.Intent
@@ -84,6 +85,7 @@ class InAppGallery : AppCompatActivity() {
8485
const val INTENT_KEY_LAST_CAPTURED_ITEM = "last_captured_item"
8586

8687
const val LAST_VIEWED_ITEM_KEY = "LAST_VIEWED_ITEM_KEY"
88+
const val EMPTY_GALLERY = "empty_gallery"
8789

8890
@SuppressLint("SimpleDateFormat")
8991
fun convertTime(time: Long, showTimeZone: Boolean = true): String {
@@ -559,13 +561,20 @@ class InAppGallery : AppCompatActivity() {
559561
showUI()
560562
}
561563

564+
fun setEmptyGalleryResult() {
565+
val resultIntent = Intent()
566+
resultIntent.putExtra(EMPTY_GALLERY, true)
567+
setResult(Activity.RESULT_OK, resultIntent)
568+
}
569+
562570
fun asyncResultReady(items: ArrayList<CapturedItem>) {
563571
if (isDestroyed) {
564572
return
565573
}
566574

567575
if (items.isEmpty()) {
568576
Toast.makeText(applicationContext, R.string.empty_gallery, Toast.LENGTH_SHORT).show()
577+
setEmptyGalleryResult()
569578
finish()
570579
return
571580
}

app/src/main/java/app/grapheneos/camera/ui/activities/MainActivity.kt

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,19 @@ open class MainActivity : AppCompatActivity(),
269269
}
270270
}
271271

272+
private val galleryLauncher = registerForActivityResult(
273+
ActivityResultContracts.StartActivityForResult()
274+
) { result ->
275+
if (result.resultCode == RESULT_OK) {
276+
val data = result.data
277+
Log.i(TAG, "Gallery result: ${data?.getBooleanExtra(InAppGallery.EMPTY_GALLERY, false)}")
278+
if (data?.getBooleanExtra(InAppGallery.EMPTY_GALLERY, false) == true) {
279+
Log.i(TAG, "Gallery is empty.")
280+
camConfig.clearLastCapturedItem()
281+
}
282+
}
283+
}
284+
272285
// Used to request permission from the user
273286
private val requestPermissionLauncher = registerForActivityResult(
274287
RequestMultiplePermissions()
@@ -421,14 +434,18 @@ open class MainActivity : AppCompatActivity(),
421434
}
422435
it.putParcelableArrayListExtra(InAppGallery.INTENT_KEY_LIST_OF_SECURE_MODE_CAPTURED_ITEMS, list)
423436
} else {
437+
if(camConfig.lastCapturedItem == null) {
438+
showMessage(R.string.no_image)
439+
return
440+
}
424441
it.putExtra(InAppGallery.INTENT_KEY_VIDEO_ONLY_MODE, requiresVideoModeOnly)
425442
}
426443

427444
if (isThumbnailLoaded) { // indicates that last captured item is accessible
428445
it.putExtra(InAppGallery.INTENT_KEY_LAST_CAPTURED_ITEM, camConfig.lastCapturedItem)
429446
}
430447

431-
startActivity(it)
448+
galleryLauncher.launch(it)
432449
}
433450

434451
}

0 commit comments

Comments
 (0)