So, An is not zero when n=4k.
Yes, look $|\sin (x)|$ is $\pi$-periodic; $\cos(nx/2)$ is $\pi$-periodic iff $n=4k$. Now thinks go easier:
$$
A_{4k}=\frac{2}{\pi}\int_0^\pi \sin (x) \cos (2kx)\,dx=
$$
where we halved interval but doubled coefficient (due to $\pi$-periodicity), then follow your calculations
$$
\frac{1}{\pi} \int_0^\pi \Bigl[ \sin ((2k+1)x)-\sin ((2k-1)x)\Bigr]\,dx =
\frac{1}{\pi} \Bigl[ -\frac{1}{2k+1}\cos ((2k+1)x)+\frac{1}{2k-1}\cos ((2k-1)x)\Bigr]_0^\pi =
-\frac{4}{\pi(k^2-1)}$$
as in your calculations but we do not need to analyze cases. In particular, $A_0=\frac{4}{\pi}$.
So
$$
u(x,t)= \frac{2}{\pi} -\sum_{k=0}^\infty \frac{4}{\pi(k^2-1)}\cos (2kx)e^{-4k^2t}.
$$