Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix export/import function for version 2.4.1 #213

Merged
merged 4 commits into from
Sep 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ android {
applicationId = "com.lorenzovainigli.foodexpirationdates"
minSdk = 24
targetSdk = 34
versionCode = 32
versionName = "2.4.1"
versionCode = 33
versionName = "2.4.2"

base.archivesName.set("FoodExpirationDates-$versionName")

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package com.lorenzovainigli.foodexpirationdates.util

import android.util.Log

object FirebaseUtils {

private const val TAG = "FirebaseCrashlytics"

fun logToCrashlytics(message: String) {
try {
val crashlyticsClass = Class.forName("com.google.firebase.crashlytics.FirebaseCrashlytics")
val instanceMethod = crashlyticsClass.getMethod("getInstance")
val crashlyticsInstance = instanceMethod.invoke(null)
val logMethod = crashlyticsClass.getMethod("log", String::class.java)
val recordExceptionMethod = crashlyticsClass.getMethod("recordException", Throwable::class.java)
logMethod.invoke(crashlyticsInstance, message)
recordExceptionMethod.invoke(crashlyticsInstance, RuntimeException(message))
Log.i(TAG, "Logged message to Crashlytics: $message")
} catch (e: ClassNotFoundException) {
Log.i(TAG, "FirebaseCrashlytics SDK not found in this build variant")
} catch (e: NoSuchMethodException) {
Log.w(TAG, "Method not found in FirebaseCrashlytics SDK")
} catch (e: Exception) {
Log.e(TAG, "Error logging message to Crashlytics", e)
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.res.stringResource
import com.lorenzovainigli.foodexpirationdates.R
import com.lorenzovainigli.foodexpirationdates.util.FirebaseUtils
import com.lorenzovainigli.foodexpirationdates.util.OperationResult
import com.lorenzovainigli.foodexpirationdates.view.MainActivity

Expand Down Expand Up @@ -72,15 +73,23 @@ fun MainScreenMenu(
iconId = R.drawable.ic_export,
label = stringResource(R.string.export_data),
onClick = {
viewModel?.exportData(context)
if (viewModel != null) {
viewModel.exportData(context)
} else {
FirebaseUtils.logToCrashlytics("Cannot export data, viewModel is null")
}
isExpanded = false
}
),
MenuItem(
iconId = R.drawable.ic_import,
label = stringResource(R.string.import_data),
onClick = {
filePickerLauncher?.launch(arrayOf("*/*"))
if (filePickerLauncher != null){
filePickerLauncher.launch(arrayOf("*/*"))
} else {
FirebaseUtils.logToCrashlytics("Cannot import data, filePickerLauncher is null")
}
isExpanded = false
}
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ fun MyScaffold(
},
actions = {
if (destination?.contains(Screen.MainScreen.route) == true) {
MainScreenMenu()
MainScreenMenu(activity)
}
},
navigationIcon = {
Expand Down
Loading