From 8db18b30570917e5eaa82755564edcdc28df805b Mon Sep 17 00:00:00 2001 From: bruh Date: Mon, 24 Oct 2022 22:34:07 +0700 Subject: [PATCH] Fix TransactionTooLargeException when clicking the last crash of a huge list and fixes #37 --- .../scoop/core/data/crash/CrashLoader.java | 18 ------------------ .../taco/scoop/ui/activity/MainActivity.kt | 16 +++++++++++----- .../taco/scoop/ui/adapter/CrashAdapter.java | 14 ++++++++++++-- 3 files changed, 23 insertions(+), 25 deletions(-) diff --git a/app/src/main/java/taco/scoop/core/data/crash/CrashLoader.java b/app/src/main/java/taco/scoop/core/data/crash/CrashLoader.java index 9ddc0dc..2310d4d 100644 --- a/app/src/main/java/taco/scoop/core/data/crash/CrashLoader.java +++ b/app/src/main/java/taco/scoop/core/data/crash/CrashLoader.java @@ -91,7 +91,6 @@ public void loadData(MainActivity activity, boolean combineSameStackTrace, sortApps(listener, data); data = combineStackTraces(data); data = combineSameApps(data); - setupAdapterData(data); // Prefetch and cache the first items to avoid scroll lag. // There is the chance the Activity will be destroyed while the items // get prefetched but the chance is low as it doesn't take long to load @@ -169,21 +168,4 @@ private ArrayList combineSameApps(ArrayList crashes) { } return newData; } - - private void setupAdapterData(ArrayList crashes) { - // Set time to latest crash time and count together the.. count - for (Crash c : crashes) { - long newestTime = c.time; - int count = c.count; - if (c.children != null) { - for (Crash cc : c.children) { - count += cc.count; - if (cc.time > newestTime) - newestTime = cc.time; - } - } - c.time = newestTime; - c.displayCount = count; - } - } } diff --git a/app/src/main/java/taco/scoop/ui/activity/MainActivity.kt b/app/src/main/java/taco/scoop/ui/activity/MainActivity.kt index 8134b0c..196ee29 100644 --- a/app/src/main/java/taco/scoop/ui/activity/MainActivity.kt +++ b/app/src/main/java/taco/scoop/ui/activity/MainActivity.kt @@ -4,9 +4,11 @@ import android.content.Intent import android.os.Bundle import android.os.Handler import android.os.Looper +import android.util.Log import android.view.Menu import android.view.MenuItem import android.view.View +import android.widget.Toast import androidx.activity.result.contract.ActivityResultContracts.StartActivityForResult import androidx.appcompat.app.AlertDialog import androidx.appcompat.app.AppCompatActivity @@ -53,7 +55,8 @@ class MainActivity : AppCompatActivity(), CrashAdapter.Listener, SearchView.OnQu // a different app in the list return if (sVisible && sNewCrash != null) { - mAdapter.addCrash(sNewCrash) + //mAdapter.addCrash(sNewCrash) + mainViewModel.crashes.value!!.add(sNewCrash) updateViewStates(false) sNewCrash = null } else { @@ -91,13 +94,14 @@ class MainActivity : AppCompatActivity(), CrashAdapter.Listener, SearchView.OnQu val i = intent mHasCrash = i.hasExtra(EXTRA_CRASH) if (mHasCrash) { - val c: Crash? = mainViewModel.combinedCrash + val c = mainViewModel.combinedCrash val crashes = ArrayList() - crashes.add(c) - c?.children?.let(crashes::addAll) + //add a copy of the oldest crash without its children to fix TransactionTooLargeException when clicked + crashes.add(Crash(c.time, c.packageName, c.description, c.stackTrace)) + c.children?.let(crashes::addAll) mAdapter.setCrashes(crashes) supportActionBar?.title = - CrashLoader.getAppName(this, c?.packageName, true) + CrashLoader.getAppName(this, c.packageName, true) supportActionBar?.setDisplayHomeAsUpEnabled(true) } else { mainViewModel.crashes.observe(this) { @@ -224,6 +228,8 @@ class MainActivity : AppCompatActivity(), CrashAdapter.Listener, SearchView.OnQu .putExtra(EXTRA_CRASH, true) ) } else { + Log.d("Crash", crash.toString()) + Log.d("Crash", crash.stackTrace) startActivity( Intent(this, DetailActivity::class.java) .putExtra(DetailActivity.EXTRA_CRASH, crash) diff --git a/app/src/main/java/taco/scoop/ui/adapter/CrashAdapter.java b/app/src/main/java/taco/scoop/ui/adapter/CrashAdapter.java index 11d3d89..ac14cf9 100644 --- a/app/src/main/java/taco/scoop/ui/adapter/CrashAdapter.java +++ b/app/src/main/java/taco/scoop/ui/adapter/CrashAdapter.java @@ -155,9 +155,9 @@ public void onBindViewHolder(CrashViewHolder holder, int position) { CharSequence title; holder.crash = crash; holder.icon.setImageDrawable(CrashLoader.getAppIcon(context, pkg)); - holder.time.setReferenceTime(crash.time); String name = CrashLoader.getAppName(context, pkg, false); if (!mCombineSameApps) { + holder.time.setReferenceTime(crash.time); if (crash.count > 1) { title = context.getString(R.string.crash_count, name, crash.count); title = new SpannableString(title); @@ -170,7 +170,17 @@ public void onBindViewHolder(CrashViewHolder holder, int position) { holder.crashText.setText(crash.description); } else { title = name; - holder.crashText.setText(context.getResources().getQuantityString(R.plurals.items_children_count, crash.displayCount, crash.displayCount)); + long newestTime = crash.time; + int displayCount = 1; + if (crash.children != null) { + for (Crash cc : crash.children) { + displayCount += cc.count; + if (cc.time > newestTime) + newestTime = cc.time; + } + } + holder.time.setReferenceTime(newestTime); + holder.crashText.setText(context.getResources().getQuantityString(R.plurals.items_children_count, displayCount, displayCount)); } holder.title.setText(title); holder.itemView.setOnClickListener(holder);