From ea96291bfca3dcb089b2033a62eef50143c19082 Mon Sep 17 00:00:00 2001
From: rebelonion <87634197+rebelonion@users.noreply.github.com>
Date: Thu, 18 Jan 2024 22:20:56 -0600
Subject: [PATCH] add optional username in crash report
---
app/src/main/java/ani/dantotsu/App.kt | 20 +++++++
.../connections/anilist/AnilistQueries.kt | 7 +++
.../ani/dantotsu/settings/SettingsActivity.kt | 56 ++++++++++++-------
app/src/main/res/layout/activity_settings.xml | 18 ++++++
app/src/main/res/values/strings.xml | 1 +
5 files changed, 82 insertions(+), 20 deletions(-)
diff --git a/app/src/main/java/ani/dantotsu/App.kt b/app/src/main/java/ani/dantotsu/App.kt
index 7552e50cca..b9eba235ab 100644
--- a/app/src/main/java/ani/dantotsu/App.kt
+++ b/app/src/main/java/ani/dantotsu/App.kt
@@ -13,7 +13,9 @@ import ani.dantotsu.parsers.AnimeSources
import ani.dantotsu.parsers.MangaSources
import ani.dantotsu.parsers.NovelSources
import ani.dantotsu.parsers.novel.NovelExtensionManager
+import ani.dantotsu.settings.SettingsActivity
import com.google.android.material.color.DynamicColors
+import com.google.firebase.crashlytics.FirebaseCrashlytics
import com.google.firebase.crashlytics.ktx.crashlytics
import com.google.firebase.ktx.Firebase
import eu.kanade.tachiyomi.data.notification.Notifications
@@ -58,6 +60,24 @@ class App : MultiDexApplication() {
registerActivityLifecycleCallbacks(mFTActivityLifecycleCallbacks)
Firebase.crashlytics.setCrashlyticsCollectionEnabled(!DisabledReports)
+ getSharedPreferences(
+ getString(R.string.preference_file_key),
+ Context.MODE_PRIVATE
+ ).getBoolean("shared_user_id", true).let {
+ if (!it) return@let
+ val dUsername = getSharedPreferences(
+ getString(R.string.preference_file_key),
+ Context.MODE_PRIVATE
+ ).getString("discord_username", null)
+ val aUsername = getSharedPreferences(
+ getString(R.string.preference_file_key),
+ Context.MODE_PRIVATE
+ ).getString("anilist_username", null)
+ if (dUsername != null || aUsername != null) {
+ Firebase.crashlytics.setUserId("$dUsername - $aUsername")
+ }
+ }
+ FirebaseCrashlytics.getInstance().setCustomKey("device Info", SettingsActivity.getDeviceInfo())
Injekt.importModule(AppModule(this))
Injekt.importModule(PreferenceModule(this))
diff --git a/app/src/main/java/ani/dantotsu/connections/anilist/AnilistQueries.kt b/app/src/main/java/ani/dantotsu/connections/anilist/AnilistQueries.kt
index 8a6a813e75..5c344b5937 100644
--- a/app/src/main/java/ani/dantotsu/connections/anilist/AnilistQueries.kt
+++ b/app/src/main/java/ani/dantotsu/connections/anilist/AnilistQueries.kt
@@ -35,6 +35,13 @@ class AnilistQueries {
}.also { println("time : $it") }
val user = response?.data?.user ?: return false
+ currContext()?.let {
+ it.getSharedPreferences(it.getString(R.string.preference_file_key), Context.MODE_PRIVATE)
+ .edit()
+ .putString("anilist_username", user.name)
+ .apply()
+ }
+
Anilist.userid = user.id
Anilist.username = user.name
Anilist.bg = user.bannerImage
diff --git a/app/src/main/java/ani/dantotsu/settings/SettingsActivity.kt b/app/src/main/java/ani/dantotsu/settings/SettingsActivity.kt
index 84de579243..3104bae912 100644
--- a/app/src/main/java/ani/dantotsu/settings/SettingsActivity.kt
+++ b/app/src/main/java/ani/dantotsu/settings/SettingsActivity.kt
@@ -80,26 +80,7 @@ class SettingsActivity : AppCompatActivity(), SimpleDialog.OnDialogResultListene
binding.settingsVersion.text = getString(R.string.version_current, BuildConfig.VERSION_NAME)
binding.settingsVersion.setOnLongClickListener {
- fun getArch(): String {
- SUPPORTED_ABIS.forEach {
- when (it) {
- "arm64-v8a" -> return "aarch64"
- "armeabi-v7a" -> return "arm"
- "x86_64" -> return "x86_64"
- "x86" -> return "i686"
- }
- }
- return System.getProperty("os.arch") ?: System.getProperty("os.product.cpu.abi")
- ?: "Unknown Architecture"
- }
-
- val info = """
- dantotsu Version: ${BuildConfig.VERSION_NAME}
- Device: $BRAND $DEVICE
- Architecture: ${getArch()}
- OS Version: $CODENAME $RELEASE ($SDK_INT)
- """.trimIndent()
- copyToClipboard(info, false)
+ copyToClipboard(getDeviceInfo(), false)
toast(getString(R.string.copied_device_info))
return@setOnLongClickListener true
}
@@ -404,6 +385,17 @@ class SettingsActivity : AppCompatActivity(), SimpleDialog.OnDialogResultListene
binding.settingsRecentlyListOnly.setOnCheckedChangeListener { _, isChecked ->
saveData("recently_list_only", isChecked)
}
+ binding.settingsShareUsername.isChecked = getSharedPreferences(
+ getString(R.string.preference_file_key),
+ Context.MODE_PRIVATE
+ ).getBoolean("shared_user_id", true)
+ binding.settingsShareUsername.setOnCheckedChangeListener { _, isChecked ->
+ getSharedPreferences(
+ getString(R.string.preference_file_key),
+ Context.MODE_PRIVATE
+ ).edit().putBoolean("shared_user_id", isChecked).apply()
+ }
+
binding.settingsPreferDub.isChecked = loadData("settings_prefer_dub") ?: false
binding.settingsPreferDub.setOnCheckedChangeListener { _, isChecked ->
saveData("settings_prefer_dub", isChecked)
@@ -853,4 +845,28 @@ class SettingsActivity : AppCompatActivity(), SimpleDialog.OnDialogResultListene
show()
}
}
+
+ companion object {
+ fun getDeviceInfo(): String {
+ return """
+ dantotsu Version: ${BuildConfig.VERSION_NAME}
+ Device: $BRAND $DEVICE
+ Architecture: ${getArch()}
+ OS Version: $CODENAME $RELEASE ($SDK_INT)
+ """.trimIndent()
+ }
+
+ private fun getArch(): String {
+ SUPPORTED_ABIS.forEach {
+ when (it) {
+ "arm64-v8a" -> return "aarch64"
+ "armeabi-v7a" -> return "arm"
+ "x86_64" -> return "x86_64"
+ "x86" -> return "i686"
+ }
+ }
+ return System.getProperty("os.arch") ?: System.getProperty("os.product.cpu.abi")
+ ?: "Unknown Architecture"
+ }
+ }
}
diff --git a/app/src/main/res/layout/activity_settings.xml b/app/src/main/res/layout/activity_settings.xml
index 52c9591597..564e3fec45 100644
--- a/app/src/main/res/layout/activity_settings.xml
+++ b/app/src/main/res/layout/activity_settings.xml
@@ -1044,6 +1044,24 @@
app:showText="false"
app:thumbTint="@color/button_switch_track" />
+
+
Delete all Manga Downloads
Delete all Novel Downloads
Requires Android 12+
+ Share username in crash reports