@@ -32,9 +32,9 @@ import kotlinx.coroutines.launch
3232import kotlinx.coroutines.withContext
3333import java.io.File
3434import java.text.SimpleDateFormat
35- import java.util.Locale
3635import java.util.Calendar
3736import java.util.Date
37+ import java.util.Locale
3838
3939/* * MainActivity class inherits from the AppCompatActivity class - provides the settings view */
4040class 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 ()
0 commit comments