-
-
Notifications
You must be signed in to change notification settings - Fork 90
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
show action dialog for supported actionable qr codes
- Loading branch information
1 parent
663f549
commit 0c9e9a1
Showing
3 changed files
with
110 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
86 changes: 86 additions & 0 deletions
86
app/src/main/java/app/grapheneos/camera/ui/dialog/ActionableQrDialog.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
package app.grapheneos.camera.ui.dialog | ||
|
||
import android.app.Activity | ||
import androidx.annotation.StringRes | ||
import androidx.appcompat.app.AlertDialog | ||
import app.grapheneos.camera.R | ||
import app.grapheneos.camera.qr.data.GEO | ||
import app.grapheneos.camera.qr.data.Mail | ||
import app.grapheneos.camera.qr.data.MeCard | ||
import app.grapheneos.camera.qr.data.Phone | ||
import app.grapheneos.camera.qr.data.SMS | ||
import app.grapheneos.camera.qr.data.VCard | ||
import app.grapheneos.camera.qr.parser.parseGeo | ||
import app.grapheneos.camera.qr.parser.parseMail | ||
import app.grapheneos.camera.qr.parser.parseMeCard | ||
import app.grapheneos.camera.qr.parser.parsePhoneOrFacetime | ||
import app.grapheneos.camera.qr.parser.parseSMS | ||
import app.grapheneos.camera.qr.parser.parseVCard | ||
|
||
private data class DialogContent( | ||
@StringRes val title: Int, | ||
val message: String, | ||
@StringRes val action: Int | ||
) | ||
|
||
fun showActionableDialog(activity: Activity, rawContent: String, onDismiss: () -> Unit): Boolean { | ||
|
||
val card = parsePhoneOrFacetime(rawContent) | ||
?: parseSMS(rawContent) | ||
?: parseGeo(rawContent) | ||
?: parseMeCard(rawContent) | ||
?: parseMail(rawContent) | ||
?: parseVCard(rawContent) | ||
?: return false | ||
|
||
val (title, message, action) = when (card) { | ||
is GEO -> DialogContent( | ||
R.string.address, | ||
activity.getString(R.string.address_message, card.long, card.lat), | ||
R.string.open_in_maps | ||
) | ||
|
||
is MeCard -> DialogContent( | ||
R.string.contact_card_me_card, | ||
activity.getString(R.string.mecard_message), | ||
R.string.add_to_contacts | ||
) | ||
|
||
is Phone -> DialogContent( | ||
R.string.phone, | ||
activity.getString(R.string.call_message, "${card.number}"), | ||
R.string.call | ||
) | ||
|
||
is SMS -> DialogContent( | ||
R.string.message, | ||
activity.getString(R.string.sms_message, card.number), | ||
R.string.message | ||
) | ||
|
||
is Mail -> DialogContent( | ||
R.string.mail, | ||
activity.getString(R.string.mail_message, card.mailTo.to), | ||
R.string.mail, | ||
) | ||
|
||
is VCard -> DialogContent( | ||
R.string.contact_card_vcard, | ||
activity.getString(R.string.vcard_message), | ||
R.string.add_to_contacts | ||
) | ||
} | ||
|
||
activity.runOnUiThread { | ||
AlertDialog.Builder(activity) | ||
.setTitle(title) | ||
.setMessage(message) | ||
.setOnDismissListener { onDismiss() } | ||
.setNegativeButton(android.R.string.cancel, null) | ||
.setPositiveButton(action) { _, _ -> | ||
activity.startActivity(card.toActionIntent(activity)) | ||
}.show() | ||
} | ||
|
||
return true | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters