Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix delete button not working on error views - also move deletion logic to their own methods #408

Merged
merged 1 commit into from
Mar 19, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Override should be inlined. I'll format the file after merging.

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