0
0
mirror of https://github.com/markusfisch/BinaryEye.git synced 2024-09-19 19:42:18 +02:00

Add a button to add generated codes to the history

So generated barcodes can be saved, too.
This commit is contained in:
Markus Fisch 2024-01-10 23:37:51 +01:00
parent 783f6e4892
commit 48d3588341
28 changed files with 99 additions and 2 deletions

View File

@ -10,10 +10,12 @@ import android.support.v4.app.Fragment
import android.view.*
import android.widget.EditText
import de.markusfisch.android.binaryeye.R
import de.markusfisch.android.binaryeye.app.db
import de.markusfisch.android.binaryeye.app.hasWritePermission
import de.markusfisch.android.binaryeye.content.copyToClipboard
import de.markusfisch.android.binaryeye.content.shareFile
import de.markusfisch.android.binaryeye.content.shareText
import de.markusfisch.android.binaryeye.database.toScan
import de.markusfisch.android.binaryeye.graphics.COLOR_BLACK
import de.markusfisch.android.binaryeye.graphics.COLOR_WHITE
import de.markusfisch.android.binaryeye.io.addSuffixIfNotGiven
@ -42,6 +44,7 @@ class BarcodeFragment : Fragment() {
private val scope = CoroutineScope(Dispatchers.IO + parentJob)
private lateinit var barcode: Barcode<*>
private lateinit var addToHistoryItem: MenuItem
override fun onCreate(state: Bundle?) {
super.onCreate(state)
@ -131,10 +134,18 @@ class BarcodeFragment : Fragment() {
override fun onCreateOptionsMenu(menu: Menu, inflater: MenuInflater) {
inflater.inflate(R.menu.fragment_barcode, menu)
addToHistoryItem = menu.findItem(R.id.add_to_history)
}
override fun onOptionsItemSelected(item: MenuItem): Boolean {
return when (item.itemId) {
R.id.add_to_history -> {
readAndAddToHistory(barcode.bitmap(), barcode.format)
addToHistoryItem.isVisible = false
context.toast(R.string.added_to_history)
true
}
R.id.copy_to_clipboard -> {
context.apply {
copyToClipboard(barcode.text())
@ -373,5 +384,31 @@ private fun Bitmap.saveAsPng(outputStream: OutputStream, quality: Int = 90) =
compress(Bitmap.CompressFormat.PNG, quality, outputStream)
private val fileNameCharacters = "[^A-Za-z0-9]".toRegex()
private fun encodeFileName(name: String): String =
fileNameCharacters.replace(name, "_").take(16).trim('_').lowercase(Locale.getDefault())
private fun encodeFileName(name: String): String = fileNameCharacters
.replace(name, "_")
.take(16)
.trim('_')
.lowercase(Locale.getDefault())
private fun readAndAddToHistory(
bitmap: Bitmap,
format: BarcodeFormat
) {
ZxingCpp.readBitmap(
bitmap,
0, 0,
bitmap.width, bitmap.height,
0,
ZxingCpp.ReaderOptions(
tryHarder = true,
tryRotate = true,
tryInvert = true,
tryDownscale = true,
maxNumberOfSymbols = 1,
formats = setOf(format)
)
)?.first {
db.insertScan(it.toScan())
true
}
}

View File

@ -0,0 +1,3 @@
<vector android:height="24dp" android:tint="#FFFFFF" android:viewportHeight="24.0" android:viewportWidth="24.0" android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
<path android:fillColor="#FF000000" android:pathData="M14.54,18.49L14.54,16.51L17.51,16.51L17.51,13.54L19.49,13.54L19.49,16.51L22.46,16.51L22.46,18.49L19.508,18.508L19.49,21.46L17.51,21.46L17.492,18.508L14.54,18.49ZM13.35,14.75L11,12.4L11,7L13,7L13,11.6L14.4,13L13.35,14.75ZM3,10L3,4L5,4L5,6.35C5.85,5.283 6.888,4.458 8.113,3.875C9.338,3.292 10.633,3 12,3C14.5,3 16.625,3.875 18.375,5.625C20.125,7.375 21,9.5 21,12L19,12C19,10.05 18.321,8.396 16.963,7.037C15.604,5.679 13.95,5 12,5C10.85,5 9.775,5.267 8.775,5.8C7.775,6.333 6.933,7.067 6.25,8L9,8L9,10L3,10ZM12,21C9.7,21 7.696,20.237 5.988,18.712C4.279,17.187 3.3,15.283 3.05,13L5.1,13C5.333,14.733 6.104,16.167 7.413,17.3C8.721,18.433 10.25,19 12,19C12.183,19 12.354,18.996 12.513,18.987C12.671,18.979 12.833,18.958 13,18.925L13,20.95C12.833,20.967 12.671,20.979 12.513,20.987C12.354,20.996 12.183,21 12,21Z"/>
</vector>

View File

@ -1,6 +1,11 @@
<menu
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:material="http://schemas.android.com/apk/res-auto">
<item
android:id="@+id/add_to_history"
android:title="@string/add_to_history"
android:icon="@drawable/ic_action_history_add"
material:showAsAction="ifRoom"/>
<item
android:id="@+id/copy_to_clipboard"
android:title="@string/copy_to_clipboard"

View File

@ -166,6 +166,8 @@
<string name="otpauth_add">Добави 2FA</string>
<string name="search_web">Търси в мрежата</string>
<string name="search_scan">Търсещо сканиране</string>
<string name="add_to_history">Add to history</string>
<string name="added_to_history">Added to history</string>
<string name="export_to_file">Извеждане в файл</string>
<string name="export_as">Извеждане като?</string>
<string name="export_csv_comma">CSV файл със запетаи</string>

View File

@ -166,6 +166,8 @@
<string name="otpauth_add">২এফএ যোগ করো</string>
<string name="search_web">ওয়েবে খুঁজো</string>
<string name="search_scan">আগেরগুলোতে খুঁজো</string>
<string name="add_to_history">Add to history</string>
<string name="added_to_history">Added to history</string>
<string name="export_to_file">নথিতে রপ্তানি করো</string>
<string name="export_as">রপ্তানির ধরণ?</string>
<string name="export_csv_comma">কমাসহ সিএসভি(.csv) নথি</string>

View File

@ -168,6 +168,8 @@
<string name="otpauth_add">Přidat 2FA</string>
<string name="search_web">Vyhledat na webu</string>
<string name="search_scan">Vyhledat sken</string>
<string name="add_to_history">Add to history</string>
<string name="added_to_history">Added to history</string>
<string name="export_to_file">Exportovat do souboru</string>
<string name="export_as">Exportovat jako</string>
<string name="export_csv_comma">CSV oddělené čárkami</string>

View File

@ -166,6 +166,8 @@
<string name="otpauth_add">Tilføj 2FA</string>
<string name="search_web">Søg på nettet</string>
<string name="search_scan">Søg scanning</string>
<string name="add_to_history">Add to history</string>
<string name="added_to_history">Added to history</string>
<string name="export_to_file">Eksporter til fil</string>
<string name="export_as">Eksporter som?</string>
<string name="export_csv_comma">CSV-fil med kommaer</string>

View File

@ -166,6 +166,8 @@
<string name="otpauth_add">2FA hinzufügen</string>
<string name="search_web">Suche im Internet</string>
<string name="search_scan">Code suchen</string>
<string name="add_to_history">Zu gespeicherten Codes hinzufügen</string>
<string name="added_to_history">Zu den gespeicherten Codes hinzugefügt</string>
<string name="export_to_file">In Datei exportieren</string>
<string name="export_as">Exportieren als?</string>
<string name="export_csv_comma">CSV Datei mit Kommas</string>

View File

@ -166,6 +166,8 @@
<string name="otpauth_add">Añadir 2FA</string>
<string name="search_web">Buscar en la web</string>
<string name="search_scan">Buscar escaneo</string>
<string name="add_to_history">Add to history</string>
<string name="added_to_history">Added to history</string>
<string name="export_to_file">Exportar a archivo</string>
<string name="export_as">¿Exportar como?</string>
<string name="export_csv_comma">Archivo CSV con comas</string>

View File

@ -166,6 +166,8 @@
<string name="otpauth_add">افزودن احراز هویت چندعاملی(2FA)</string>
<string name="search_web">جست‌وجوی وب</string>
<string name="search_scan">جست‌وجوی پویش</string>
<string name="add_to_history">Add to history</string>
<string name="added_to_history">Added to history</string>
<string name="export_to_file">برون‌ریزی به پرونده</string>
<string name="export_as">برون‌ریزی به عنوان؟</string>
<string name="export_csv_comma">پروندهٔ سی‌اس‌وی با ویرگول</string>

View File

@ -166,6 +166,8 @@
<string name="otpauth_add">Ajouter l\'authentification à deux facteurs</string>
<string name="search_web">Rechercher sur internet</string>
<string name="search_scan">Rechercher un scan</string>
<string name="add_to_history">Add to history</string>
<string name="added_to_history">Added to history</string>
<string name="export_to_file">Exporter en tant que fichier</string>
<string name="export_as">Exporter en tant que ?</string>
<string name="export_csv_comma">CSV avec virgules</string>

View File

@ -166,6 +166,8 @@
<string name="otpauth_add">Kétlépcsős hitelesítés hozzáadása</string>
<string name="search_web">Keresés a weben</string>
<string name="search_scan">Beolvasás keresése</string>
<string name="add_to_history">Add to history</string>
<string name="added_to_history">Added to history</string>
<string name="export_to_file">Exportálás fájlba</string>
<string name="export_as">Exportálja másként?</string>
<string name="export_csv_comma">CSV-fájl vesszővel</string>

View File

@ -165,6 +165,8 @@
<string name="otpauth_add">Tambahkan 2FA</string>
<string name="search_web">Cari secara daring</string>
<string name="search_scan">Cari pindaian</string>
<string name="add_to_history">Add to history</string>
<string name="added_to_history">Added to history</string>
<string name="export_to_file">Ekspor ke berkas</string>
<string name="export_as">Ekspor sebagai?</string>
<string name="export_csv_comma">CSV dengan koma</string>

View File

@ -166,6 +166,8 @@
<string name="otpauth_add">Aggiungi 2FA</string>
<string name="search_web">Cerca nel web</string>
<string name="search_scan">Cerca scansione</string>
<string name="add_to_history">Add to history</string>
<string name="added_to_history">Added to history</string>
<string name="export_to_file">Esporta su file</string>
<string name="export_as">Come esportare?</string>
<string name="export_csv_comma">CSV con virgole</string>

View File

@ -165,6 +165,8 @@
<string name="otpauth_add">二段階認証を追加</string>
<string name="search_web">ウェブで検索</string>
<string name="search_scan">スキャン結果を検索</string>
<string name="add_to_history">Add to history</string>
<string name="added_to_history">Added to history</string>
<string name="export_to_file">ファイルにエクスポート</string>
<string name="export_as">ファイル形式を選択</string>
<string name="export_csv_comma">コンマ区切りのCSVファイル</string>

View File

@ -166,6 +166,8 @@
<string name="otpauth_add">დავამატოთ 2FA</string>
<string name="search_web">ქსელში მოძებნა</string>
<string name="search_scan">სკანირების ძიება</string>
<string name="add_to_history">Add to history</string>
<string name="added_to_history">Added to history</string>
<string name="export_to_file">ექსპორტი ფაილში</string>
<string name="export_as">შესანახი ფაილის ფორმატი</string>
<string name="export_csv_comma">CSV (გამყოფი - მძიმე)</string>

View File

@ -165,6 +165,8 @@
<string name="otpauth_add">Add 2FA</string>
<string name="search_web">Search the web</string>
<string name="search_scan">Search scan</string>
<string name="add_to_history">Add to history</string>
<string name="added_to_history">Added to history</string>
<string name="export_to_file">Export to file</string>
<string name="export_as">Export as?</string>
<string name="export_csv_comma">CSV file with commas</string>

View File

@ -166,6 +166,8 @@
<string name="otpauth_add">2FA toevoegen</string>
<string name="search_web">Zoeken op internet</string>
<string name="search_scan">Scan op internet zoeken</string>
<string name="add_to_history">Add to history</string>
<string name="added_to_history">Added to history</string>
<string name="export_to_file">Uitvoer naar bestand</string>
<string name="export_as">Exporteren als?</string>
<string name="export_csv_comma">CSV bestand met komma\'s</string>

View File

@ -15,6 +15,8 @@
<string name="compose_barcode">Utwórz kod kreskowy</string>
<string name="history">Historia</string>
<string name="format">Format</string>
<string name="add_to_history">Add to history</string>
<string name="added_to_history">Added to history</string>
<string name="export_to_file">Eksportuj do pliku</string>
<string name="file_name">Nazwa pliku</string>
<string name="export_json">Eksportuj jako JSON</string>

View File

@ -166,6 +166,8 @@
<string name="otpauth_add">Adicionar 2FA</string>
<string name="search_web">Buscar na internet</string>
<string name="search_scan">Buscar nas digitalizações salvas</string>
<string name="add_to_history">Add to history</string>
<string name="added_to_history">Added to history</string>
<string name="export_to_file">Exportar para arquivo</string>
<string name="export_as">Exportar em qual formato?</string>
<string name="export_csv_comma">Arquivo CSV com vírgulas</string>

View File

@ -168,6 +168,8 @@
<string name="otpauth_add">Добавить 2FA</string>
<string name="search_web">Поиск в сети</string>
<string name="search_scan">Поиск сканирования</string>
<string name="add_to_history">Add to history</string>
<string name="added_to_history">Added to history</string>
<string name="export_to_file">Экспортировать в файл</string>
<string name="export_as">Формат файла экспорта</string>
<string name="export_csv_comma">CSV (разделитель запятая)</string>

View File

@ -166,6 +166,8 @@
<string name="otpauth_add">2FA\'ya ekle</string>
<string name="search_web">Web\'i ara</string>
<string name="search_scan">Taramayı ara</string>
<string name="add_to_history">Add to history</string>
<string name="added_to_history">Added to history</string>
<string name="export_to_file">Dosyaya dışa aktar</string>
<string name="export_as">Ne olarak dışa aktarılsın?</string>
<string name="export_csv_comma">Virgüller ile CSV</string>

View File

@ -167,6 +167,8 @@
<string name="otpauth_add">Додати 2FA</string>
<string name="search_web">Шукати в мережі</string>
<string name="search_scan">Шукати сканування</string>
<string name="add_to_history">Add to history</string>
<string name="added_to_history">Added to history</string>
<string name="export_to_file">Експортувати в файл</string>
<string name="export_as">Експортувати як?</string>
<string name="export_csv_comma">CSV із комами</string>

View File

@ -165,6 +165,8 @@
<string name="otpauth_add">Thêm xác thực hai bước</string>
<string name="search_web">Tìm kiếm web</string>
<string name="search_scan">Tìm kiếm lần quét</string>
<string name="add_to_history">Add to history</string>
<string name="added_to_history">Added to history</string>
<string name="export_to_file">Xuất thành tệp</string>
<string name="export_as">Xuất dưói dạng?</string>
<string name="export_csv_comma">Tệp CSV với dấu phẩy</string>

View File

@ -165,6 +165,8 @@
<string name="otpauth_add">添加两步验证</string>
<string name="search_web">在互联网中搜索</string>
<string name="search_scan">搜索扫描记录</string>
<string name="add_to_history">Add to history</string>
<string name="added_to_history">Added to history</string>
<string name="export_to_file">导出为文件</string>
<string name="export_as">另存为?</string>
<string name="export_csv_comma">逗号分隔的 CSV</string>

View File

@ -165,6 +165,8 @@
<string name="otpauth_add">加入雙重驗證 (2FA)</string>
<string name="search_web">在網路上搜尋</string>
<string name="search_scan">搜尋掃描記錄</string>
<string name="add_to_history">Add to history</string>
<string name="added_to_history">Added to history</string>
<string name="export_to_file">匯出檔案</string>
<string name="export_as">另存為?</string>
<string name="export_csv_comma">逗號分隔的 CSV 檔案</string>

View File

@ -166,6 +166,8 @@
<string name="otpauth_add">Add 2FA</string>
<string name="search_web">Search the web</string>
<string name="search_scan">Search scan</string>
<string name="add_to_history">Add to history</string>
<string name="added_to_history">Added to history</string>
<string name="export_to_file">Export to file</string>
<string name="export_as">Export as?</string>
<string name="export_csv_comma">CSV file with commas</string>

View File

@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<svg height="24" viewBox="0 0 24 24" width="24" xmlns="http://www.w3.org/2000/svg">
<path d="M 14.54 18.49 L 14.54 16.51 L 17.51 16.51 L 17.51 13.54 L 19.49 13.54 L 19.49 16.51 L 22.46 16.51 L 22.46 18.49 L 19.508 18.508 L 19.49 21.46 L 17.51 21.46 L 17.492 18.508 L 14.54 18.49 Z M 13.35 14.75 L 11 12.4 L 11 7 L 13 7 L 13 11.6 L 14.4 13 L 13.35 14.75 Z M 3 10 L 3 4 L 5 4 L 5 6.35 C 5.85 5.283 6.888 4.458 8.113 3.875 C 9.338 3.292 10.633 3 12 3 C 14.5 3 16.625 3.875 18.375 5.625 C 20.125 7.375 21 9.5 21 12 L 19 12 C 19 10.05 18.321 8.396 16.963 7.037 C 15.604 5.679 13.95 5 12 5 C 10.85 5 9.775 5.267 8.775 5.8 C 7.775 6.333 6.933 7.067 6.25 8 L 9 8 L 9 10 L 3 10 Z M 12 21 C 9.7 21 7.696 20.237 5.988 18.712 C 4.279 17.187 3.3 15.283 3.05 13 L 5.1 13 C 5.333 14.733 6.104 16.167 7.413 17.3 C 8.721 18.433 10.25 19 12 19 C 12.183 19 12.354 18.996 12.513 18.987 C 12.671 18.979 12.833 18.958 13 18.925 L 13 20.95 C 12.833 20.967 12.671 20.979 12.513 20.987 C 12.354 20.996 12.183 21 12 21 Z" style=""/>
</svg>

After

Width:  |  Height:  |  Size: 1.0 KiB