Skip to content

Commit

Permalink
add support for custom naming of the proof zip file
Browse files Browse the repository at this point in the history
  • Loading branch information
n8fr8 committed Dec 17, 2024
1 parent 458dfeb commit 2d51419
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 32 deletions.
81 changes: 49 additions & 32 deletions app/src/main/java/org/witness/proofmode/ShareProofActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import android.view.View
import android.webkit.MimeTypeMap
import android.widget.CheckBox
import android.widget.CompoundButton
import android.widget.EditText
import android.widget.TextView
import androidx.activity.result.contract.ActivityResultContracts
import androidx.appcompat.app.AlertDialog
Expand Down Expand Up @@ -193,43 +194,51 @@ class ShareProofActivity : AppCompatActivity() {
}

fun clickNotarize(button: View?) {
shareProof(false, false)
shareProof("", false, false)
}

fun clickAll(button: View?) {


shareProof(sendMedia, true)

/**
val options = arrayOf(getString(R.string.action_share_proof_zip),getString(R.string.action_add_content_credentials_c2pa))
val builder = AlertDialog.Builder(this)
builder.setItems(options, DialogInterface.OnClickListener { dialog, which ->
// The 'which' argument contains the index position
// of the selected item
if (which == 0)
{
shareProof(sendMedia, true)
val inputEditTextField = EditText(this)
val dialog = AlertDialog.Builder(this)
.setTitle(getString(R.string.optional_filename))
.setMessage(getString(R.string.set_a_custom_name_for_the_proof_zip))
.setView(inputEditTextField)
.setPositiveButton(getString(android.R.string.ok)) { _, _ ->
val editTextInput = inputEditTextField .text.toString()
shareProof(editTextInput, sendMedia, true)
}
else if (which == 1)
{
signProof(sendMedia, true)
.setNegativeButton(getString(android.R.string.cancel)) { _, _ ->
shareProof("", sendMedia, true)
}
.create()
dialog.show()

})
.setCancelable(true)

val alert = builder.create()
alert.show()
**/


}

fun saveAll(button: View?) {
saveProof(sendMedia, true)

val inputEditTextField = EditText(this)
val dialog = AlertDialog.Builder(this)
.setTitle(getString(R.string.optional_filename))
.setMessage(getString(R.string.set_a_custom_name_for_the_proof_zip))
.setView(inputEditTextField)
.setPositiveButton(getString(android.R.string.ok)) { _, _ ->
val editTextInput = inputEditTextField .text.toString()
shareProof(editTextInput, sendMedia, true)
saveProof(sendMedia, true)
}
.setNegativeButton(getString(android.R.string.cancel)) { _, _ ->
shareProof("", sendMedia, true)
}
.create()
dialog.show()


}

fun signAll(button: View?) {
Expand Down Expand Up @@ -500,9 +509,9 @@ class ShareProofActivity : AppCompatActivity() {
return fileProofDownloads
}

private fun shareProof(shareMedia: Boolean, shareProof: Boolean) {
private fun shareProof(fileName: String, shareMedia: Boolean, shareProof: Boolean) {
displayProgress(getString(R.string.progress_building_proof))
ShareProofTask(this).execute(shareMedia, shareProof)
ShareProofTask(this, fileName).execute(shareMedia, shareProof)
}

private fun signProof(shareMedia: Boolean, shareProof: Boolean) {
Expand Down Expand Up @@ -631,7 +640,9 @@ class ShareProofActivity : AppCompatActivity() {
if (response.code == 200) {
var rs = response.body?.byteStream()

Timber.d("success uploading to proofsign: " + fileZip.absolutePath)
var contentType = response.body?.contentType().toString()

Timber.d("response from proofsign: type=$contentType path=$fileZip.absolutePath");

displayProgressAsync(getString(R.string.status_download_content_credentials))

Expand Down Expand Up @@ -685,14 +696,20 @@ class ShareProofActivity : AppCompatActivity() {

@Synchronized
@Throws(IOException::class, PGPException::class)
private fun shareProofAsync(shareMedia: Boolean, shareProof: Boolean): Boolean {
private fun shareProofAsync(fileNameOrig: String, shareMedia: Boolean, shareProof: Boolean): Boolean {

// Get intent, action and MIME type
val intent = intent
val action = intent.action
val shareUris = ArrayList<Uri?>()
val shareItems = ArrayList<ProofableItem>()

var fileName = fileNameOrig
if (fileNameOrig.isEmpty())
{
fileName = "proofmode"
}

val shareText = StringBuffer()
if (Intent.ACTION_SEND_MULTIPLE == action) {
val mediaUris = intent.getParcelableArrayListExtra<Uri>(Intent.EXTRA_STREAM) ?: emptyList()
Expand Down Expand Up @@ -755,7 +772,7 @@ class ShareProofActivity : AppCompatActivity() {
val sdf = SimpleDateFormat(ZIP_FILE_DATETIME_FORMAT)
val dateString = sdf.format(Date())
val userId = pgpUtils.publicKeyFingerprint
val fileZip = File(fileCacheFolder, "proofmode-0x$userId-$dateString.zip")
val fileZip = File(fileCacheFolder, "${fileName}-0x$userId-$dateString.zip")
Timber.d("Preparing proof bundle zip: " + fileZip.absolutePath)
try {
zipProof(shareUris, fileZip)
Expand All @@ -765,10 +782,10 @@ class ShareProofActivity : AppCompatActivity() {
}
if (fileZip.length() > 0) {
Timber.d("Proof zip completed. Size:" + fileZip.length())
val encryptZip = false
val encryptZip = false //we never do this
if (encryptZip) {
val fileZipEnc =
File(fileCacheFolder, "proofmode-0x$userId-$dateString.zip.gpg")
File(fileCacheFolder, fileZip.name + ".gpg")
try {
pgpUtils.encrypt(
FileInputStream(fileZip),
Expand Down Expand Up @@ -947,12 +964,12 @@ class ShareProofActivity : AppCompatActivity() {
}

private class ShareProofTask // only retain a weak reference to the activity
internal constructor(private val activity: ShareProofActivity) :
internal constructor(private val activity: ShareProofActivity, val fileName: String) :
AsyncTask<Boolean?, Void?, Boolean>() {
override fun doInBackground(vararg params: Boolean?): Boolean {
var result = false
return try {
result = activity.shareProofAsync(params[0]!!, params[1]!!)
result = activity.shareProofAsync(fileName, params[0]!!, params[1]!!)
result
} catch (e: IOException) {
Timber.e(e, "error sharing proof")
Expand Down
8 changes: 8 additions & 0 deletions app/src/main/res/layout/activity_share.xml
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,14 @@
android:text="@string/share_save_robust"
android:onClick="saveAll"
/>
<Button
android:layout_width="160dp"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:text="@string/share_sign_robust"
android:onClick="signAll"
android:visibility="gone"
/>

</LinearLayout>

Expand Down
2 changes: 2 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -212,5 +212,7 @@
<string name="previous">Previous</string>
<string name="content_credentials">Content Credentials</string>
<string name="share_content_credentials_info">Shares image or video directly with proof metadata directly embedded in the file itself, verified and signed by ProofMode.org</string>
<string name="optional_filename">Optional Filename</string>
<string name="set_a_custom_name_for_the_proof_zip">Set a custom name for the proof zip</string>

</resources>

0 comments on commit 2d51419

Please sign in to comment.