# Framed environment covers caption of figure in afterpage

I'm using packages framed to create my own quote environment with a nice frame. However, when using the package afterpage to shift a figure to the next page and the first thing on the next page is a frame, than the frame covers the caption of the figure. This does not happen if there's some text between the figure and the frame.

How can I change my framed environment so that it does not cover the caption?

MWE:

\documentclass[12pt,a4paper,twoside,openany,fleqn]{book}
\usepackage[ngerman]{babel}
\usepackage{lipsum}
\usepackage{xcolor}
\usepackage{framed}
\usepackage{changepage}
\usepackage{afterpage}

\definecolor{lightgray}{HTML}{F0F0F0}
\definecolor{darkerlightgray}{HTML}{E0E0E0}

\newenvironment{myQuote}{%
\OuterFrameSep=0pt % space before and after box
\def\FrameCommand{%
\fcolorbox{darkerlightgray}{lightgray}%
}%
\noindent% disable indenting first paragraph
\vspace{-0.5\parskip}%
}
{%
}

\renewenvironment{quote}{\begin{myQuote}\em}{\end{myQuote}}

\begin{document}
\chapter{First Chapter}

\lipsum[2]

\afterpage{
\begin{figure}[htp]
\rule{\textwidth}{0.2\textheight}
\caption{my first figure}
\end{figure}
}

\lipsum[6]

\begin{quote}
Quote OK
\end{quote}

\lipsum[6]

\begin{quote}
Quote not OK (caption is covered)
\end{quote}

\lipsum[1]

\afterpage{
\begin{figure}[htp]
\rule{\textwidth}{0.2\textheight}
\caption{my second figure}
\end{figure}
}

\lipsum[1-2]

\begin{quote}
Quote OK
\end{quote}

\lipsum[1]

\end{document}


I recognized, that tcolorbox handles footnotes differently than the framed package. Since I need all footnotes to be on the bottom of the page, I fiddled with the package code and came up with this solution:
\usepackage{etoolbox}