Merge pull request #3087 from utafrali/fix/issue-3086-feature-request-timestamp-in-the-export-

Add timestamp to export filename
This commit is contained in:
Sylvia van Os
2026-04-14 20:34:35 +02:00
committed by GitHub
2 changed files with 16 additions and 1 deletions

View File

@@ -27,6 +27,9 @@ import protect.card_locker.importexport.ImportExportResultType
import java.io.IOException
import java.io.InputStream
import java.io.OutputStream
import java.text.SimpleDateFormat
import java.util.Date
import java.util.Locale
class ImportExportActivity : CatimaAppCompatActivity() {
private lateinit var binding: ImportExportActivityBinding
@@ -45,6 +48,11 @@ class ImportExportActivity : CatimaAppCompatActivity() {
companion object {
private const val TAG = "Catima"
internal fun getExportFilename(): String {
val sdf = SimpleDateFormat("yyyyMMdd", Locale.US)
return "catima_${sdf.format(Date())}.zip"
}
}
override fun onCreate(savedInstanceState: Bundle?) {
@@ -107,7 +115,7 @@ class ImportExportActivity : CatimaAppCompatActivity() {
val intentCreateDocumentAction = Intent(Intent.ACTION_CREATE_DOCUMENT).apply {
addCategory(Intent.CATEGORY_OPENABLE)
type = "application/zip"
putExtra(Intent.EXTRA_TITLE, "catima.zip")
putExtra(Intent.EXTRA_TITLE, getExportFilename())
}
val exportButton: Button = binding.exportButton

View File

@@ -7,6 +7,7 @@ import android.content.pm.ApplicationInfo
import android.content.pm.ResolveInfo
import android.view.View
import org.junit.Assert.assertEquals
import org.junit.Assert.assertTrue
import org.junit.Test
import org.junit.runner.RunWith
import org.robolectric.Robolectric
@@ -61,6 +62,12 @@ class ImportExportActivityTest {
assertEquals(state, buttonView.visibility)
}
@Test
fun testExportFilenameHasTimestamp() {
val filename = ImportExportActivity.getExportFilename()
assertTrue(filename.matches(Regex("catima_\\d{8}\\.zip")))
}
@Test
fun testAllOptionsAvailable() {
registerIntentHandler(Intent.ACTION_PICK)