Skip to content

Commit

Permalink
Fix TransactionTooLargeException when clicking the last crash of a hu…
Browse files Browse the repository at this point in the history
…ge list and fixes TacoTheDank#37
  • Loading branch information
unbiaseduser-github committed Oct 24, 2022
1 parent 38d6911 commit 8db18b3
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 25 deletions.
18 changes: 0 additions & 18 deletions app/src/main/java/taco/scoop/core/data/crash/CrashLoader.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -169,21 +168,4 @@ private ArrayList<Crash> combineSameApps(ArrayList<Crash> crashes) {
}
return newData;
}

private void setupAdapterData(ArrayList<Crash> 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;
}
}
}
16 changes: 11 additions & 5 deletions app/src/main/java/taco/scoop/ui/activity/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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<Crash?>()
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) {
Expand Down Expand Up @@ -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)
Expand Down
14 changes: 12 additions & 2 deletions app/src/main/java/taco/scoop/ui/adapter/CrashAdapter.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
Expand Down

0 comments on commit 8db18b3

Please sign in to comment.