User ID added for crash analysis
This commit is contained in:
@@ -31,10 +31,12 @@ import com.google.android.gms.common.GooglePlayServicesNotAvailableException
|
||||
import com.google.android.gms.common.GooglePlayServicesRepairableException
|
||||
import com.google.android.gms.security.ProviderInstaller
|
||||
import com.google.firebase.analytics.FirebaseAnalytics
|
||||
import com.google.firebase.crashlytics.FirebaseCrashlytics
|
||||
import xyz.quaver.proxy
|
||||
import xyz.quaver.pupil.util.Histories
|
||||
import xyz.quaver.pupil.util.getProxy
|
||||
import java.io.File
|
||||
import java.util.*
|
||||
|
||||
class Pupil : MultiDexApplication() {
|
||||
|
||||
@@ -48,6 +50,16 @@ class Pupil : MultiDexApplication() {
|
||||
override fun onCreate() {
|
||||
val preference = PreferenceManager.getDefaultSharedPreferences(this)
|
||||
|
||||
val userID =
|
||||
if (preference.getString("user_id", "").isNullOrEmpty()) {
|
||||
UUID.randomUUID().toString().also {
|
||||
preference.edit().putString("user_id", it).apply()
|
||||
}
|
||||
} else
|
||||
preference.getString("user_id", "") ?: ""
|
||||
|
||||
FirebaseCrashlytics.getInstance().setUserId(userID)
|
||||
|
||||
proxy = getProxy(this)
|
||||
|
||||
try {
|
||||
|
||||
@@ -19,11 +19,11 @@
|
||||
package xyz.quaver.pupil.ui.fragment
|
||||
|
||||
import android.Manifest
|
||||
import android.content.Intent
|
||||
import android.content.SharedPreferences
|
||||
import android.content.*
|
||||
import android.content.pm.PackageManager
|
||||
import android.os.Build
|
||||
import android.os.Bundle
|
||||
import android.widget.Toast
|
||||
import androidx.appcompat.app.AlertDialog
|
||||
import androidx.appcompat.app.AppCompatDelegate
|
||||
import androidx.core.app.ActivityCompat
|
||||
@@ -53,11 +53,7 @@ class SettingsFragment :
|
||||
Preference.OnPreferenceChangeListener,
|
||||
SharedPreferences.OnSharedPreferenceChangeListener {
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
|
||||
PreferenceManager.getDefaultSharedPreferences(requireContext()).registerOnSharedPreferenceChangeListener(this)
|
||||
}
|
||||
lateinit var sharedPreference: SharedPreferences
|
||||
|
||||
override fun onResume() {
|
||||
super.onResume()
|
||||
@@ -202,6 +198,12 @@ class SettingsFragment :
|
||||
activity?.startActivityForResult(intent, REQUEST_IMPORT_OLD_GALLERIES_OLD)
|
||||
}
|
||||
}
|
||||
"user_id" -> {
|
||||
(context.getSystemService(Context.CLIPBOARD_SERVICE) as ClipboardManager).setPrimaryClip(
|
||||
ClipData.newPlainText("user_id", sharedPreference.getString("user_id", ""))
|
||||
)
|
||||
Toast.makeText(context, R.string.settings_user_id_toast, Toast.LENGTH_SHORT).show()
|
||||
}
|
||||
else -> return false
|
||||
}
|
||||
}
|
||||
@@ -247,6 +249,9 @@ class SettingsFragment :
|
||||
override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) {
|
||||
setPreferencesFromResource(R.xml.root_preferences, rootKey)
|
||||
|
||||
sharedPreference = PreferenceManager.getDefaultSharedPreferences(requireContext())
|
||||
sharedPreference.registerOnSharedPreferenceChangeListener(this)
|
||||
|
||||
initPreferences()
|
||||
}
|
||||
|
||||
@@ -293,7 +298,7 @@ class SettingsFragment :
|
||||
onPreferenceClickListener = this@SettingsFragment
|
||||
}
|
||||
"default_query" -> {
|
||||
summary = PreferenceManager.getDefaultSharedPreferences(requireContext()).getString("default_query", "") ?: ""
|
||||
summary = sharedPreference.getString("default_query", "") ?: ""
|
||||
|
||||
onPreferenceClickListener = this@SettingsFragment
|
||||
}
|
||||
@@ -337,6 +342,10 @@ class SettingsFragment :
|
||||
"old_import_galleries" -> {
|
||||
onPreferenceClickListener = this@SettingsFragment
|
||||
}
|
||||
"user_id" -> {
|
||||
summary = sharedPreference.getString("user_id", "")
|
||||
onPreferenceClickListener = this@SettingsFragment
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -259,8 +259,12 @@ class Cache(context: Context) : ContextWrapper(context) {
|
||||
it.createNewFile()
|
||||
}
|
||||
|
||||
FileOutputStream(cache).use {
|
||||
it.write(data)
|
||||
try {
|
||||
FileOutputStream(cache).use {
|
||||
it.write(data)
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
cache.delete()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -296,7 +296,7 @@ class DownloadWorker private constructor(context: Context) : ContextWrapper(cont
|
||||
val callback = object : Callback {
|
||||
override fun onFailure(call: Call, e: IOException) {
|
||||
Log.i("PUPILD", "FAIL ${call.request().tag()} (${e.message})")
|
||||
if (e.message != "Canceled")
|
||||
if (e.message?.contains("cancel", true) != true)
|
||||
FirebaseCrashlytics.getInstance().recordException(e)
|
||||
|
||||
progress[galleryID]?.set(i, Float.NaN)
|
||||
|
||||
Reference in New Issue
Block a user