<commit_before>package de.markusfisch.android.binaryeye.actions.vtype.vcard

import android.content.ContentValues
import android.content.Context
import android.content.Intent
import android.os.Build
import android.provider.ContactsContract
import de.markusfisch.android.binaryeye.R
import de.markusfisch.android.binaryeye.actions.IntentAction
import de.markusfisch.android.binaryeye.actions.vtype.VTypeParser
import java.util.*
import kotlin.collections.ArrayList

object VCardAction : IntentAction() {
	override val iconResId: Int
		get() = R.drawable.ic_action_vcard
	override val titleResId: Int
		get() = R.string.vcard_add
	override val errorMsg: Int
		get() = R.string.vcard_failed

	override fun canExecuteOn(data: ByteArray): Boolean {
		return VTypeParser.parseVType(String(data)) == "VCARD"
	}

	override suspend fun createIntent(context: Context, data: ByteArray): Intent {
		val info = VTypeParser.parseMap(String(data))

		return Intent(Intent.ACTION_INSERT_OR_EDIT).apply {
			type = ContactsContract.Contacts.CONTENT_ITEM_TYPE
			info["FN"]?.singleOrNull()?.also { name ->
				putExtra(ContactsContract.Intents.Insert.NAME, name.value)
			} ?: info["N"]?.singleOrNull()?.also { name ->
				putExtra(ContactsContract.Intents.Insert.NAME, name.value.nameFormat)<commit_msg>Add support for MECARD contact format<commit_after>package de.markusfisch.android.binaryeye.actions.vtype.vcard

import android.content.ContentValues
import android.content.Context
import android.content.Intent
import android.os.Build
import android.provider.ContactsContract
import de.markusfisch.android.binaryeye.R
import de.markusfisch.android.binaryeye.actions.IntentAction
import de.markusfisch.android.binaryeye.actions.vtype.VTypeParser
import java.util.*
import kotlin.collections.ArrayList

object VCardAction : IntentAction() {
	override val iconResId: Int
		get() = R.drawable.ic_action_vcard
	override val titleResId: Int
		get() = R.string.vcard_add
	override val errorMsg: Int
		get() = R.string.vcard_failed

	override fun canExecuteOn(data: ByteArray): Boolean {
		var stringData = String(data)
		// Quick & dirty MECARD support: simply make it a VCARD.
		if (stringData.startsWith("MECARD:")) {
			stringData = stringData
				.trim()
				.replace("MECARD:", "BEGIN:VCARD\n")
				.replace(";;", "\nEND:VCARD\n")
				.replace(";", "\n")
		}
		return VTypeParser.parseVType(stringData) == "VCARD"
	}

	override suspend fun createIntent(context: Context, data: ByteArray): Intent {
		val info = VTypeParser.parseMap(String(data))

		return Intent(Intent.ACTION_INSERT_OR_EDIT).apply {
			type = ContactsContract.Contacts.CONTENT_ITEM_TYPE
			info["FN"]?.singleOrNull()?.also { name ->
				putExtra(ContactsContract.Intents.Insert.NAME, name.value)
			} ?: info["N"]?.singleOrNull()?.also { name ->
				putExtra(ContactsContract.Intents.Insert.NAME, name.value.nameFormat)
{'fraction_non_alphanumeric': 0.11703239289446186, 'fraction_numerical': 0.0, 'mean_word_length': 5.243478260869566, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '834511', 'n_tokens_mistral': 983, 'n_tokens_neox': 910, 'n_words': 175}