Skip to content

Commit

Permalink
add optional username in crash report
Browse files Browse the repository at this point in the history
  • Loading branch information
rebelonion committed Jan 19, 2024
1 parent b1eedce commit ea96291
Show file tree
Hide file tree
Showing 5 changed files with 82 additions and 20 deletions.
20 changes: 20 additions & 0 deletions app/src/main/java/ani/dantotsu/App.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
56 changes: 36 additions & 20 deletions app/src/main/java/ani/dantotsu/settings/SettingsActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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"
}
}
}
18 changes: 18 additions & 0 deletions app/src/main/res/layout/activity_settings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1044,6 +1044,24 @@
app:showText="false"
app:thumbTint="@color/button_switch_track" />

<com.google.android.material.materialswitch.MaterialSwitch
android:id="@+id/settingsShareUsername"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:checked="false"
android:drawableStart="@drawable/ic_round_search_24"
android:drawablePadding="16dp"
android:elegantTextHeight="true"
android:fontFamily="@font/poppins_bold"
android:minHeight="64dp"
android:text="@string/share_username_in_crash_reports"
android:textAlignment="viewStart"
android:textColor="?attr/colorOnBackground"
app:cornerRadius="0dp"
app:drawableTint="?attr/colorPrimary"
app:showText="false"
app:thumbTint="@color/button_switch_track" />

</ani.dantotsu.others.Xpandable>

<ani.dantotsu.others.Xpandable
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -652,5 +652,6 @@
<string name="purge_manga_downloads">Delete all Manga Downloads</string>
<string name="purge_novel_downloads">Delete all Novel Downloads</string>
<string name="requires_android_12">Requires Android 12+</string>
<string name="share_username_in_crash_reports">Share username in crash reports</string>

</resources>

0 comments on commit ea96291

Please sign in to comment.