-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Bug: fixed minor bugs & introduced logger
- Loading branch information
1 parent
fb98fb3
commit 5fa2854
Showing
28 changed files
with
313 additions
and
51 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
Binary file not shown.
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
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
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
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
12 changes: 7 additions & 5 deletions
12
app/src/main/java/com/ferrariofilippo/saveapp/model/CurrencyApiResponse.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 |
---|---|---|
@@ -1,11 +1,13 @@ | ||
// Copyright (c) 2023 Filippo Ferrario | ||
// Copyright (c) 2024 Filippo Ferrario | ||
// Licensed under the MIT License. See the LICENSE. | ||
|
||
package com.ferrariofilippo.saveapp.model | ||
|
||
import com.squareup.moshi.Json | ||
|
||
data class CurrencyApiResponse( | ||
val amount: Int, | ||
val base: String, | ||
val date: String, | ||
val rates: Map<String, Double> | ||
@Json(name="amount") val amount: Int, | ||
@Json(name="base") val base: String, | ||
@Json(name="date") val date: String, | ||
@Json(name="rates") val rates: Map<String, Double> | ||
) |
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
20 changes: 20 additions & 0 deletions
20
app/src/main/java/com/ferrariofilippo/saveapp/util/ColorUtil.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,20 @@ | ||
// Copyright (c) 2024 Filippo Ferrario | ||
// Licensed under the MIT License. See the LICENSE. | ||
|
||
package com.ferrariofilippo.saveapp.util | ||
|
||
import android.content.Context | ||
import android.content.res.Resources | ||
import androidx.core.content.ContextCompat | ||
import com.ferrariofilippo.saveapp.R | ||
|
||
object ColorUtil { | ||
fun getColorOrDefault(ctx: Context, resId: Int): Int { | ||
return try { | ||
ContextCompat.getColor(ctx, resId) | ||
} catch (e: Resources.NotFoundException) { | ||
LogUtil.logException(e, javaClass.kotlin.simpleName ?: "", "getColorOrDefault") | ||
ContextCompat.getColor(ctx, R.color.emerald_500) | ||
} | ||
} | ||
} |
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
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
66 changes: 66 additions & 0 deletions
66
app/src/main/java/com/ferrariofilippo/saveapp/util/LogUtil.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,66 @@ | ||
// Copyright (c) 2024 Filippo Ferrario | ||
// Licensed under the MIT License. See the LICENSE. | ||
|
||
package com.ferrariofilippo.saveapp.util | ||
|
||
import java.io.FileInputStream | ||
import java.io.FileOutputStream | ||
import java.io.FileWriter | ||
import java.io.IOException | ||
import java.time.LocalDateTime | ||
import java.time.format.DateTimeFormatter | ||
|
||
object LogUtil { | ||
private var _logFilePath = "" | ||
|
||
fun setLogFilePath(path: String) { | ||
_logFilePath = "$path/saveapp.log" | ||
} | ||
|
||
fun logException(e: Throwable, className: String, methodName: String) { | ||
if (_logFilePath.isEmpty()) { | ||
return | ||
} | ||
|
||
try { | ||
val timeStamp = LocalDateTime | ||
.now() | ||
.format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")) | ||
val formattedClassName = className.padEnd(30, ' ').substring(0, 20) | ||
val formattedMethodName = methodName.padEnd(30, ' ').substring(0, 20) | ||
FileWriter(_logFilePath, true).use { | ||
it.write("$timeStamp|$formattedClassName|$formattedMethodName|${e.message}\n") | ||
it.write(e.stackTraceToString()) | ||
it.flush() | ||
} | ||
} catch (_: IOException) { | ||
} | ||
} | ||
|
||
fun exportLogTo(outStream: FileOutputStream?) { | ||
if (outStream == null) { | ||
return | ||
} | ||
|
||
try { | ||
val writer = outStream.bufferedWriter() | ||
FileInputStream(_logFilePath).use { input -> | ||
writer.write(input.reader().readText()) | ||
} | ||
writer.flush() | ||
outStream.flush() | ||
outStream.close() | ||
} catch (_: IOException) { | ||
} | ||
} | ||
|
||
fun clearLogs() { | ||
try { | ||
FileWriter(_logFilePath, false).use { | ||
it.write("") | ||
it.flush() | ||
} | ||
} catch (_: IOException) { | ||
} | ||
} | ||
} |
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
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
Oops, something went wrong.