Skip to content

Commit d1fc4c1

Browse files
committed
enhance toaster, prepare for release
1 parent 89a5623 commit d1fc4c1

22 files changed

Lines changed: 58 additions & 92 deletions

File tree

CHANGELOG.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,16 @@ patch-level version changes can be found in [commit messages](../../commits/mast
77
## Next_Ver
88
-->
99

10+
## 20250209
11+
12+
- Update dependency versions
13+
- Add a shortcut to google keyboard (fixes #76)
14+
- Add SVG image support
15+
- Code quality improvements
16+
- Use xLog (https://github.com/elvishew/xLog) to capture today's logs (to assist with debugging)
17+
- Make PNG sticker fallback configurable and improve share sheet (fixes #80)
18+
- Improve toast logging experience
19+
1020
## 20240825
1121

1222
- Add case insensitive sort

app/src/main/java/com/fredhappyface/ewesticker/MainActivity.kt

Lines changed: 18 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,9 @@ import kotlinx.coroutines.launch
3232
import kotlinx.coroutines.withContext
3333
import java.io.File
3434
import java.text.SimpleDateFormat
35-
import java.util.Locale
3635
import java.util.Calendar
3736
import java.util.Date
37+
import java.util.Locale
3838

3939
/** MainActivity class inherits from the AppCompatActivity class - provides the settings view */
4040
class MainActivity : AppCompatActivity() {
@@ -61,7 +61,6 @@ class MainActivity : AppCompatActivity() {
6161
File(filesDir, "logs").path
6262
).fileNameGenerator(DateFileNameGenerator()).build()
6363

64-
6564
XLog.init(logConfig, androidPrinter, filePrinter)
6665

6766
XLog.i("=".repeat(80))
@@ -111,7 +110,6 @@ class MainActivity : AppCompatActivity() {
111110

112111
}
113112

114-
115113
/**
116114
* Handles ACTION_OPEN_DOCUMENT_TREE result and adds stickerDirPath, lastUpdateDate to
117115
* this.sharedPreferences and resets recentCache, compatCache
@@ -142,22 +140,22 @@ class MainActivity : AppCompatActivity() {
142140

143141
private val saveFileLauncher =
144142
registerForActivityResult(ActivityResultContracts.StartActivityForResult()) { result ->
145-
if (result.resultCode == RESULT_OK) {
146-
result.data?.data?.also { uri ->
147-
val dateFormatter = SimpleDateFormat("yyyy-MM-dd", Locale.US)
148-
val currentDate = Date()
149-
val logFileName = dateFormatter.format(currentDate)
150-
val file = File(filesDir, "logs/$logFileName")
151-
if (file.exists()) {
152-
contentResolver.openOutputStream(uri)?.use { outputStream ->
153-
file.inputStream().use { inputStream ->
154-
inputStream.copyTo(outputStream)
143+
if (result.resultCode == RESULT_OK) {
144+
result.data?.data?.also { uri ->
145+
val dateFormatter = SimpleDateFormat("yyyy-MM-dd", Locale.US)
146+
val currentDate = Date()
147+
val logFileName = dateFormatter.format(currentDate)
148+
val file = File(filesDir, "logs/$logFileName")
149+
if (file.exists()) {
150+
contentResolver.openOutputStream(uri)?.use { outputStream ->
151+
file.inputStream().use { inputStream ->
152+
inputStream.copyTo(outputStream)
153+
}
155154
}
156155
}
157156
}
158157
}
159158
}
160-
}
161159

162160
/**
163161
* Called on button press to launch settings
@@ -230,14 +228,12 @@ class MainActivity : AppCompatActivity() {
230228
StickerImporter(baseContext, toaster, progressBar).importStickers(stickerDirPath)
231229

232230
withContext(Dispatchers.Main) {
233-
toaster.toastOnState(
234-
arrayOf(
235-
getString(R.string.imported_020, totalStickers),
236-
getString(R.string.imported_031, totalStickers),
237-
getString(R.string.imported_032, totalStickers),
238-
getString(R.string.imported_033, totalStickers),
239-
),
240-
)
231+
if (toaster.messages.size > 0) {
232+
toaster.toastOnMessages()
233+
} else {
234+
toaster.toast(getString(R.string.imported_020, totalStickers))
235+
}
236+
241237
val editor = sharedPreferences.edit()
242238
editor.putInt("numStickersImported", totalStickers)
243239
editor.apply()

app/src/main/java/com/fredhappyface/ewesticker/utilities/StickerImporter.kt

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import android.os.Looper
77
import android.view.View
88
import androidx.documentfile.provider.DocumentFile
99
import com.elvishew.xlog.XLog
10+
import com.fredhappyface.ewesticker.R
1011

1112
import com.google.android.material.progressindicator.LinearProgressIndicator
1213
import kotlinx.coroutines.Dispatchers
@@ -66,7 +67,7 @@ class StickerImporter(
6667
val leafNodes = fileWalk(DocumentFile.fromTreeUri(context, Uri.parse(stickerDirPath)))
6768
if (leafNodes.size > MAX_FILES) {
6869
XLog.w("Found more than $MAX_FILES stickers, notify user")
69-
toaster.setState(1)
70+
toaster.setMessage(context.getString(R.string.imported_031, MAX_FILES))
7071
}
7172

7273
withContext(Dispatchers.Main) {
@@ -107,12 +108,19 @@ class StickerImporter(
107108
val packSize = packSizes[parentDir] ?: 0
108109
if (packSize > MAX_PACK_SIZE) {
109110
XLog.w("Found more than $MAX_PACK_SIZE stickers in '$parentDir', notify user")
110-
toaster.setState(2)
111+
toaster.setMessage(context.getString(R.string.imported_032, MAX_PACK_SIZE, parentDir))
111112
return
112113
}
113114
if (sticker.type !in supportedMimes) {
114115
XLog.w("'$parentDir/${sticker.name}' is not a supported mimetype (${sticker.type}), notify user")
115-
toaster.setState(3)
116+
toaster.setMessage(
117+
context.getString(
118+
R.string.imported_033,
119+
sticker.type,
120+
parentDir,
121+
sticker.name
122+
)
123+
)
116124
return
117125
}
118126
packSizes[parentDir] = packSize + 1

app/src/main/java/com/fredhappyface/ewesticker/utilities/Toaster.kt

Lines changed: 13 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package com.fredhappyface.ewesticker.utilities
22

33
import android.content.Context
44
import android.widget.Toast
5+
import com.elvishew.xlog.XLog
56

67
/**
78
* The Toaster class provides a simplified interface to android.widget.Toast. Pass in the
@@ -11,7 +12,7 @@ import android.widget.Toast
1112
* @property context: android.content.Context. e.g. baseContext
1213
*/
1314
class Toaster(private val context: Context) {
14-
private var state = 0
15+
var messages: MutableList<String> = mutableListOf()
1516

1617
/**
1718
* Call toaster.toast with some string to always create a toast notification. Context is set when
@@ -33,31 +34,21 @@ class Toaster(private val context: Context) {
3334
}
3435

3536
/**
36-
* Call toaster.toastOnState with an array of messages to create a toast notification.
37-
* Context is set when Toaster is instantiated. Duration is determined based on
38-
* text length. The message is selected based on the state (which can be set in a callback
39-
* function or elsewhere
4037
*
41-
* @param strings: Array<String>. Array of potential messages to output.
42-
*/
43-
fun toastOnState(strings: Array<String>) {
44-
if (this.state < strings.size) {
45-
this.toast(strings[this.state])
46-
} else {
47-
this.toast("toaster.state=${this.state} out of range strings.size=${strings.size}")
38+
**/
39+
fun toastOnMessages() {
40+
XLog.i("Messages: [${this.messages.joinToString(", ")}]")
41+
for (idx in this.messages.take(3).indices) {
42+
this.toast(messages[idx])
4843
}
44+
this.messages = mutableListOf()
4945
}
5046

5147
/**
52-
* Set the state to some integer value
53-
*
54-
* @param state: Int
55-
*/
56-
fun setState(state: Int) {
57-
if (state < 0) {
58-
this.state = 0
59-
} else {
60-
this.state = state
61-
}
48+
* Set a message
49+
**/
50+
fun setMessage(message: String) {
51+
XLog.i("Adding message: '$message' to toaster")
52+
this.messages.add(message)
6253
}
6354
}

app/src/main/res/values-ar/strings.xml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,9 +71,6 @@
7171
<string name="pref_000">تم تغيير التفضيلات. أعد تحميل لوحة المفاتيح لتطبيق الإعدادات</string>
7272
<string name="imported_010">بدء عملية الاستيراد. قد يستغرق ذلك بعض الوقت!</string>
7373
<string name="imported_020">تم استيراد %1$d ملصق. أعد تحميل لوحة المفاتيح لعرض الملصقات الجديدة</string>
74-
<string name="imported_031">E031: فشل بعض الملصقات في الاستيراد (%1$d تم استيرادها). تم الوصول إلى الحد الأقصى للملصقات</string>
75-
<string name="imported_032">E032: فشل بعض الملصقات في الاستيراد (%1$d تم استيرادها). تم الوصول إلى الحد الأقصى لحجم الحزمة</string>
76-
<string name="imported_033">E033: فشل بعض الملصقات في الاستيراد (%1$d تم استيرادها). تم العثور على تنسيقات غير مدعومة</string>
7774
<string name="imported_034">E034: فشلت عملية إعادة تحميل الملصقات، حاول اختيار مجلد مصدر الملصقات</string>
7875
<string name="fallback_041">E041: حدث استثناء غير متوقع أثناء تحويل الملصق</string>
7976
<!-- Keyboard -->

app/src/main/res/values-bn/strings.xml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,9 +71,6 @@ EweSticker কাস্টমাইজেশন বিকল্প, বিভি
7171
<string name="pref_000">পছন্দস্থান পরিবর্তন হয়েছে। সেটিংস প্রয়োগ করার জন্য কীবোর্ড পুনরায় লোড করুন</string>
7272
<string name="imported_010">আমদানি শুরু হয়েছে। এটি কিছু সময় নিতে পারে!</string>
7373
<string name="imported_020">%1$d টি স্টিকার আমদানি করা হয়েছে। নতুন স্টিকার দেখানোর জন্য কীবোর্ড পুনরায় লোড করুন</string>
74-
<string name="imported_031">E031: কিছু স্টিকার আমদানি করা হয়নি (%1$d টি আমদানি করা হয়েছে)। সর্বাধিক স্টিকার পৌঁছানো হয়েছে</string>
75-
<string name="imported_032">E032: কিছু স্টিকার আমদানি করা হয়নি (%1$d টি আমদানি করা হয়েছে)। সর্বমোট প্যাক সাইজ পৌঁছানো হয়েছে</string>
76-
<string name="imported_033">E033: কিছু স্টিকার আমদানি করা হয়নি (%1$d টি আমদানি করা হয়েছে)। সমর্থিত ফর্ম্যাট পাওয়া হয়নি</string>
7774
<string name="imported_034">E034: স্টিকার পুনরায় লোড করা যায়নি, স্টিকার শোর্স ডিরেক্টরি চয়ন করার চেষ্টা করুন</string>
7875
<string name="fallback_041">E041: অপ্রত্যাশিত IOException যখন স্টিকার রুপান্তর করা হয়</string>
7976
<!-- Keyboard -->

app/src/main/res/values-de/strings.xml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,9 +71,6 @@ EweSticker bietet eine breite Palette an Anpassungsoptionen, vielfältige Format
7171
<string name="pref_000">Einstellungen geändert. Lade die Tastatur neu, damit die Einstellungen wirksam werden</string>
7272
<string name="imported_010">Import wird gestartet. Dies könnte einige Zeit dauern!</string>
7373
<string name="imported_020">%1$d Sticker importiert. Lade die Tastatur neu, um neue Sticker anzuzeigen</string>
74-
<string name="imported_031">E031: Einige Sticker konnten nicht importiert werden (%1$d importiert). Max. Sticker erreicht</string>
75-
<string name="imported_032">E032: Einige Sticker konnten nicht importiert werden (%1$d importiert). Max. Packungsgröße erreicht</string>
76-
<string name="imported_033">E033: Einige Sticker konnten nicht importiert werden (%1$d importiert). Nicht unterstützte Formate gefunden</string>
7774
<string name="imported_034">E034: Neuladen der Sticker fehlgeschlagen, versuche ein Sticker-Quellverzeichnis auszuwählen</string>
7875
<string name="fallback_041">E041: Unerwarteter IOException beim Konvertieren des Stickers</string>
7976
<!-- Keyboard -->

app/src/main/res/values-es/strings.xml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,9 +71,6 @@ EweSticker ofrece una amplia variedad de opciones de personalización, soporte p
7171
<string name="pref_000">Preferencias modificadas. Vuelva a cargar el teclado para que se apliquen los ajustes</string>
7272
<string name="imported_010">Comenzando la importación. ¡Esto puede llevar algún tiempo!</string>
7373
<string name="imported_020">Importado %1$d stickers. Recargar el teclado para que se muestren los nuevos stickers</string>
74-
<string name="imported_031">E031: Algunos stickers han fallado al importar (%1$d importado). Máx. stickers importados</string>
75-
<string name="imported_032">E032: No se han podido importar algunos stickers (%1$d importadas). Se ha alcanzado el tamaño máximo del paquete</string>
76-
<string name="imported_033">E033: Ha fallado la importación de algunos stickers (%1$d importadas). Se han encontrado formatos no compatibles</string>
7774
<string name="imported_034">E034: Falló la recarga de stickers, intente elegir un directorio de origen de los stickers</string>
7875
<string name="fallback_041">E041: IOException inesperado al convertir el sticker</string>
7976
<!-- Keyboard -->

app/src/main/res/values-fr/strings.xml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
<string name="update_sticker_pack_button">Choisissez le répertoire source d’autocollants</string>
1010
<string name="reload_sticker_pack_button">Recharger les autocollants</string>
1111
<string name="update_sticker_pack_info_path_lbl">- Chemin:</string>
12-
<string name="imported_033">E033: Certains autocollants n’ont pas été importés (%1$d importés). Formats non pris en charge trouvés</string>
1312
<string name="imported_034">E034: Impossible de recharger les autocollants, essayez de choisir un répertoire source d’autocollants</string>
1413
<string name="fallback_041">E041: IOException inattendue lors de la conversion de l’autocollant</string>
1514
<string name="update_sticker_pack_info">Informations actuelles sur les autocollants chargés:</string>
@@ -65,8 +64,6 @@ EweSticker offre une large gamme d'options de personnalisation, prend en charge
6564
<string name="pref_000">Les préférences ont changé. Recharger le clavier pour les appliquer</string>
6665
<string name="imported_010">Démarrage de l’importation. Ceci va prendre du temps!</string>
6766
<string name="imported_020">Autocollants importés %1$d. Recharger le clavier pour afficher les nouveaux autocollants</string>
68-
<string name="imported_031">E031: Certains autocollants n’ont pas été importés (%1$d importés). Nombre maximal atteint</string>
69-
<string name="imported_032">E032: Certains autocollants n’ont pas été importés (%1$d importés). Taille maximale du paquet atteint</string>
7067
<!-- Keyboard -->
7168
<string name="sticker_pack_info">%1$s (Pack : %2$s)</string>
7269
<string name="options_insensitive_sort">Activer le tri des paquets sans tenir compte de la casse</string>

app/src/main/res/values-hi/strings.xml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,9 +70,6 @@ EweSticker विभिन्न संविदान विकल्पों,
7070
<string name="pref_000">प्राथमिकताएँ बदल गईं। सेटिंग्स को लागू करने के लिए कीबोर्ड को पुनः लोड करें</string>
7171
<string name="imported_010">आयात शुरू हुआ। इसमें कुछ समय लग सकता है!</string>
7272
<string name="imported_020">%1$d स्टिकर्स का आयात हुआ। नए स्टिकर्स दिखाने के लिए कीबोर्ड को पुनः लोड करें</string>
73-
<string name="imported_031">E031: कुछ स्टिकर्स का आयात असफल रहा (%1$d आयात किए गए)। मैक्सिमम स्टिकर्स तक पहुँच गई है</string>
74-
<string name="imported_032">E032: कुछ स्टिकर्स का आयात असफल रहा (%1$d आयात किए गए)। मैक्स पैक आकार तक पहुँच गई है</string>
75-
<string name="imported_033">E033: कुछ स्टिकर्स का आयात असफल रहा (%1$d आयात किए गए)। असमर्थित प्रारूप मिला</string>
7673
<string name="imported_034">E034: स्टिकर्स को पुनः लोड करने में विफलता हुई, कृपया स्टिकर स्रोत निर्दिष्ट करने का प्रयास करें</string>
7774
<string name="fallback_041">E041: स्टिकर कन्वर्ट करते समय अप्रत्याशित IOException</string>
7875
<!-- Keyboard -->

0 commit comments

Comments
 (0)