Skip to content

Commit

Permalink
Fix delete button not working on error views - also move deletion log…
Browse files Browse the repository at this point in the history
…ic to their own methods
  • Loading branch information
rwliang committed Jan 24, 2016
1 parent 608ded7 commit 021f169
Showing 1 changed file with 40 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,38 @@ void shareHeapDump() {
startActivity(Intent.createChooser(intent, getString(R.string.leak_canary_share_with)));
}

void deleteVisibleLeak() {
Leak visibleLeak = getVisibleLeak();
File heapDumpFile = visibleLeak.heapDump.heapDumpFile;
File resultFile = visibleLeak.resultFile;
boolean resultDeleted = resultFile.delete();
if (!resultDeleted) {
CanaryLog.d("Could not delete result file %s", resultFile.getPath());
}
boolean heapDumpDeleted = heapDumpFile.delete();
if (!heapDumpDeleted) {
CanaryLog.d("Could not delete heap dump file %s", heapDumpFile.getPath());
}
visibleLeakRefKey = null;
leaks.remove(visibleLeak);
updateUi();
}

void deleteAllLeaks() {
File leakDirectory = getLeakDirectory(DisplayLeakActivity.this);
File[] files = leakDirectory.listFiles();
if (files != null) {
for (File file : files) {
boolean deleted = file.delete();
if (!deleted) {
CanaryLog.d("Could not delete file %s", file.getPath());
}
}
}
leaks = Collections.emptyList();
updateUi();
}

void updateUi() {
if (leaks == null) {
setTitle("Loading leaks...");
Expand Down Expand Up @@ -249,6 +281,12 @@ void updateUi() {
getActionBar().setDisplayHomeAsUpEnabled(true);
actionButton.setVisibility(VISIBLE);
actionButton.setText(R.string.leak_canary_delete);
actionButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
deleteVisibleLeak();
}
});
listView.setAdapter(null);
} else {
final DisplayLeakAdapter adapter;
Expand All @@ -269,20 +307,7 @@ public void onItemClick(AdapterView<?> parent, View view, int position, long id)
actionButton.setText(R.string.leak_canary_delete);
actionButton.setOnClickListener(new View.OnClickListener() {
@Override public void onClick(View v) {
Leak visibleLeak = getVisibleLeak();
File heapDumpFile = visibleLeak.heapDump.heapDumpFile;
File resultFile = visibleLeak.resultFile;
boolean resultDeleted = resultFile.delete();
if (!resultDeleted) {
CanaryLog.d("Could not delete result file %s", resultFile.getPath());
}
boolean heapDumpDeleted = heapDumpFile.delete();
if (!heapDumpDeleted) {
CanaryLog.d("Could not delete heap dump file %s", heapDumpFile.getPath());
}
visibleLeakRefKey = null;
leaks.remove(visibleLeak);
updateUi();
deleteVisibleLeak();
}
});
}
Expand Down Expand Up @@ -311,18 +336,7 @@ public void onItemClick(AdapterView<?> parent, View view, int position, long id)
actionButton.setText(R.string.leak_canary_delete_all);
actionButton.setOnClickListener(new View.OnClickListener() {
@Override public void onClick(View v) {
File leakDirectory = getLeakDirectory(DisplayLeakActivity.this);
File[] files = leakDirectory.listFiles();
if (files != null) {
for (File file : files) {
boolean deleted = file.delete();
if (!deleted) {
CanaryLog.d("Could not delete file %s", file.getPath());
}
}
}
leaks = Collections.emptyList();
updateUi();
deleteAllLeaks();
}
});
}
Expand Down

0 comments on commit 021f169

Please sign in to comment.