Andy would be almost immediately disbarred and might also be held in contempt of court.
Andy would be disbarred for reasons including his violations of the duty of confidentiality owed by Andy to his client Dave under Rule of Professional Conduct 1.6 in a context like this one. This would be considered an open and shut blatant violation of one of the highest and most serious ethical obligations that an attorney has, and is neck and neck with the rule against stealing money from your clients as a ground for near automatic disbarment. The clarity and severity of the breach of professional ethics by Andy in this regard (and other aspects such as his fiduciary duties to his clients and duty of zealous and diligent advocacy for his client) leaves no ambiguity regarding the appropriate level of discipline.
Andy might be held in contempt of court for reasons including knowingly disrupting a court proceeding in which he was or is an attorney of record. He can't quit representing Dave until the court grants his permission to do so.
Dave's trial would probably not go forward or his conviction would be set aside. In all likelihood, a trial with a new prosecutor not exposed to the information would be arranged to avoid the taint of the breach of privilege.
This would be because providing the prosecutor with inadmissible evidence taints the ability of the prosecutor to proceed untainted by inadmissible evidence and would constitute ineffective assistance of counsel which is one of the grounds for setting aside a conviction for a violation of the 6th Amendment to the US Constitution, which grants the right to effective counsel.
what if Dave was openly admitting to having committed the crime,
This is utterly irrelevant. Criminal defense lawyers aren't only or mostly for innocent people, and their main job isn't really to get people acquitted of crimes they committed. Instead, a criminal defense lawyer's job is to hold the prosecution to their duties to prove their case, to force the criminal justice system to comply with civil liberties protections, to prevent convictions of excessive charges for the conduct committed, and finally to secure appropriate sentences for their clients (which usually means negotiating a plea bargain). Criminal defense lawyers prevent defendants from being convicted and sentenced in circumstances where they wouldn't have been convicted or sentenced if they weren't ignorant of the legal system (which most criminal defendants are).
what if Dave was . . . was boasting about committing more crimes as
soon as Andy gets him off the hook.
A vague statement like this does not trigger any right of Dave to take any action differently. It's basically bravado or a statement about his own character in general.
What if Dave was openly boasting about acts of terrorism he was about
to commit, etc.
If he was about to commit an act of terrorism but was thwarted, Andy needs to keep his mouth shut.
If Andy knows that Dave is about to imminently commit a specific terrorist act then this very distinct fact pattern raised different issues and belongs in a separate question. The crime-fraud exception to the duty of confidentiality, and the way that an ethical lawyer can take appropriate action in a way that minimizes harm to the client, all involve considerations very different from those in the main question.
Is Andy forced to be a tool/bystander to Dave's
villainy? Is Andy ever allowed to take action against Dave without
The duty of a lawyer not to use his services to further a crime is also a very distinct fact pattern. But, failing to report imminent unilateral acts by a client in furtherance of a crime or fraud is very different from not using information about a client's past actions or vague future intentions against the client, and is also different from using a lawyer as a tool to commit a crime or fraud.
These are three distinct situations. A different analysis applies to each one.