Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions app/src/main/java/app/grapheneos/camera/CamConfig.kt
Original file line number Diff line number Diff line change
Expand Up @@ -640,6 +640,15 @@ class CamConfig(private val mActivity: MainActivity) {
lastCapturedItem = item
}

fun clearLastCapturedItem() {
commonPref.edit {
remove(SettingValues.Key.LAST_CAPTURED_ITEM_TYPE)
remove(SettingValues.Key.LAST_CAPTURED_ITEM_DATE_STRING)
remove(SettingValues.Key.LAST_CAPTURED_ITEM_URI)
}
lastCapturedItem = null
}

var requireLocation: Boolean = false
get() {
return mActivity.settingsDialog.locToggle.isChecked
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ class GallerySliderAdapter(
gActivity.showMessage(
gActivity.getString(R.string.existing_no_image)
)
gActivity.setEmptyGalleryResult()
gActivity.finish()
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package app.grapheneos.camera.ui.activities
import android.animation.ArgbEvaluator
import android.animation.ValueAnimator
import android.annotation.SuppressLint
import android.app.Activity
import android.content.ActivityNotFoundException
import android.content.Context
import android.content.Intent
Expand Down Expand Up @@ -84,6 +85,7 @@ class InAppGallery : AppCompatActivity() {
const val INTENT_KEY_LAST_CAPTURED_ITEM = "last_captured_item"

const val LAST_VIEWED_ITEM_KEY = "LAST_VIEWED_ITEM_KEY"
const val EMPTY_GALLERY = "empty_gallery"

@SuppressLint("SimpleDateFormat")
fun convertTime(time: Long, showTimeZone: Boolean = true): String {
Expand Down Expand Up @@ -559,13 +561,20 @@ class InAppGallery : AppCompatActivity() {
showUI()
}

fun setEmptyGalleryResult() {
val resultIntent = Intent()
resultIntent.putExtra(EMPTY_GALLERY, true)
setResult(Activity.RESULT_OK, resultIntent)
}

fun asyncResultReady(items: ArrayList<CapturedItem>) {
if (isDestroyed) {
return
}

if (items.isEmpty()) {
Toast.makeText(applicationContext, R.string.empty_gallery, Toast.LENGTH_SHORT).show()
setEmptyGalleryResult()
finish()
return
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,19 @@ open class MainActivity : AppCompatActivity(),
}
}

private val galleryLauncher = registerForActivityResult(
ActivityResultContracts.StartActivityForResult()
) { result ->
if (result.resultCode == RESULT_OK) {
val data = result.data
Log.i(TAG, "Gallery result: ${data?.getBooleanExtra(InAppGallery.EMPTY_GALLERY, false)}")
if (data?.getBooleanExtra(InAppGallery.EMPTY_GALLERY, false) == true) {
Log.i(TAG, "Gallery is empty.")
camConfig.clearLastCapturedItem()
}
}
}

// Used to request permission from the user
private val requestPermissionLauncher = registerForActivityResult(
RequestMultiplePermissions()
Expand Down Expand Up @@ -421,14 +434,18 @@ open class MainActivity : AppCompatActivity(),
}
it.putParcelableArrayListExtra(InAppGallery.INTENT_KEY_LIST_OF_SECURE_MODE_CAPTURED_ITEMS, list)
} else {
if(camConfig.lastCapturedItem == null) {
showMessage(R.string.no_image)
return
}
it.putExtra(InAppGallery.INTENT_KEY_VIDEO_ONLY_MODE, requiresVideoModeOnly)
}

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

startActivity(it)
galleryLauncher.launch(it)
}

}
Expand Down