Skip to content
Snippets Groups Projects
Verified Commit 52e46ada authored by Janne Mareike Koschinski's avatar Janne Mareike Koschinski
Browse files

Crashes reports are now shared as file instead of text

- This fixes crashes in situations where the crash report was larger
  than the maximum allowed size of text to be shared
- Improves UX, as now the text is added as attachment to Emails instead
  of being used as text
parent 7b1b2b82
Branches
Tags v1.0.9
No related merge requests found
Pipeline #325 passed
......@@ -244,6 +244,16 @@
android:description="@string/connection_service_description"
android:exported="false"
android:label="@string/connection_service_title" />
<provider
android:name="androidx.core.content.FileProvider"
android:authorities="de.kuschku.quasseldroid.fileprovider"
android:exported="false"
android:grantUriPermissions="true">
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="@xml/filepaths" />
</provider>
</application>
</manifest>
......@@ -20,6 +20,7 @@
package de.kuschku.quasseldroid.ui.clientsettings.crash
import android.content.Intent
import android.net.Uri
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
......@@ -35,12 +36,12 @@ import org.threeten.bp.Instant
import org.threeten.bp.ZoneId
import org.threeten.bp.format.DateTimeFormatter
class CrashAdapter : ListAdapter<Pair<Report, String>, CrashAdapter.CrashViewHolder>(
object : DiffUtil.ItemCallback<Pair<Report, String>>() {
override fun areItemsTheSame(oldItem: Pair<Report, String>, newItem: Pair<Report, String>) =
class CrashAdapter : ListAdapter<Pair<Report, Uri>, CrashAdapter.CrashViewHolder>(
object : DiffUtil.ItemCallback<Pair<Report, Uri>>() {
override fun areItemsTheSame(oldItem: Pair<Report, Uri>, newItem: Pair<Report, Uri>) =
oldItem.second == newItem.second
override fun areContentsTheSame(oldItem: Pair<Report, String>, newItem: Pair<Report, String>) =
override fun areContentsTheSame(oldItem: Pair<Report, Uri>, newItem: Pair<Report, Uri>) =
oldItem == newItem
}
) {
......@@ -49,8 +50,8 @@ class CrashAdapter : ListAdapter<Pair<Report, String>, CrashAdapter.CrashViewHol
)
override fun onBindViewHolder(holder: CrashViewHolder, position: Int) {
val (report, data) = getItem(position)
holder.bind(report, data)
val (report, uri) = getItem(position)
holder.bind(report, uri)
}
class CrashViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {
......@@ -64,20 +65,21 @@ class CrashAdapter : ListAdapter<Pair<Report, String>, CrashAdapter.CrashViewHol
lateinit var error: TextView
var item: Report? = null
var data: String? = null
var uri: Uri? = null
private val dateTimeFormatter = DateTimeFormatter.ofPattern("uuuu-MM-dd HH:mm:ss")
init {
ButterKnife.bind(this, itemView)
itemView.setOnClickListener {
data?.let {
val intent = Intent(Intent.ACTION_SEND)
intent.type = "application/json"
intent.putExtra(Intent.EXTRA_TEXT, it)
uri?.let {
itemView.context.startActivity(
Intent.createChooser(
intent,
Intent(Intent.ACTION_SEND).apply {
type = "application/json"
putExtra(Intent.EXTRA_STREAM, uri)
flags = Intent.FLAG_GRANT_READ_URI_PERMISSION
},
itemView.context.getString(R.string.label_share_crashreport)
)
)
......@@ -85,9 +87,9 @@ class CrashAdapter : ListAdapter<Pair<Report, String>, CrashAdapter.CrashViewHol
}
}
fun bind(item: Report, data: String) {
fun bind(item: Report, uri: Uri) {
this.item = item
this.data = data
this.uri = uri
this.crashTime.text = item.environment?.crashTime?.let {
dateTimeFormatter.format(Instant.ofEpochMilli(it).atZone(ZoneId.systemDefault()))
......
......@@ -19,10 +19,12 @@
package de.kuschku.quasseldroid.ui.clientsettings.crash
import android.net.Uri
import android.os.Bundle
import android.os.Handler
import android.os.HandlerThread
import android.view.*
import androidx.core.content.FileProvider
import androidx.core.view.ViewCompat
import androidx.recyclerview.widget.DividerItemDecoration
import androidx.recyclerview.widget.LinearLayoutManager
......@@ -80,13 +82,18 @@ class CrashFragment : DaggerFragment() {
handler.post {
val crashDir = this.crashDir
val gson = this.gson
val context = this.context
if (crashDir != null) {
if (crashDir != null && context != null) {
crashDir.mkdirs()
val list: List<Pair<Report, String>> = crashDir.listFiles()
val list: List<Pair<Report, Uri>> = crashDir.listFiles()
.orEmpty()
.map { it.readText() }
.map { Pair<Report, String>(gson.fromJson(it), it) }
.map {
Pair<Report, Uri>(
gson.fromJson(it.readText()),
FileProvider.getUriForFile(context, "de.kuschku.quasseldroid.fileprovider", it)
)
}
.sortedByDescending { it.first.environment?.crashTime }
activity?.runOnUiThread {
......
<?xml version="1.0" encoding="utf-8"?>
<paths>
<cache-path
name="crashes"
path="crashes" />
</paths>
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment