$X$ is the count of Bernoulli trials before the first success.
$A_1$ and $A_2$ are the events of a success and failure (respectively) on the first trial. These events are mutually exclusive and exhaustive; they partition the outcome space.
$\begin{align}
\mathsf E(X) & = \sum_{x=0}^\infty x\mathsf P(X=x)
& \text{by definition of expectation}
\\[1ex] & = \sum_{x=0}^\infty x\,\big(\mathsf P(X=x\cap A_1)+\mathsf P(X=x\cap A_2)\big)
& \text{Law of Total Probability}
\\[1ex] & = \sum_{x=0}^\infty x\,\big(\mathsf P(X=x\mid A_1)\mathsf P(A_1)+\mathsf P(X=x\mid A_2)\mathsf P(A_2)\big)
& \text{by Conditional Probability}
\\[1ex] & = \mathsf P(A_1)\sum_{x=0}^\infty x\,\mathsf P(X=x\mid A_1)+\mathsf P(A_2)\sum_{x=0}^\infty x\, \mathsf P(X=x\mid A_2)
& \text{Rearranging}
\\[1ex] & = \mathsf P(A_1)\,\mathsf E(X\mid A_1)+\mathsf P(A_2)\,\mathsf E(X\mid A_2)
& \text{by definition of expectation}
\end{align}$
This result is called the Law of Iterated Expectation.
Notice that $A_1$ is the event that $X=0$ , and that $A_2$ is the event that $X>0$.
$\begin{align}
\mathsf E(X)
& = \mathsf P(X=0)\,\mathsf E(X\mid X=0) + \mathsf P(X>0)\,\mathsf E(X\mid X>0) & \text{Law of Iterated Expectation}
\\[1ex] & = p\,\mathsf E(X\mid X=0) + (1-p)\,\mathsf E(X\mid X>0) & \mathsf P(X=0)=p
\\[1ex] & = p\cdot 0 + (1-p)\,\mathsf E(X\mid X>0) & \mathsf E(X\mid X=0)=0
\\[1ex] & = p\cdot 0 + (1-p)\,(1+\mathsf E(X)) & \mathsf E(X\mid X>0)=1+\mathsf E(X)
\\[0ex] && \text{because the distribution is memoriless.}
\\[2ex]
\therefore \mathsf E(X) & = \frac{1-p}p
\end{align}$
why $\mathsf E(X\mid A_2)=1+\mathsf E(X)$ ? Memoriless means 'following next steps are completely independent from the previous step'?
Yes, and that means the expected number of failures after the $n^\text{th}$ trial and before the next success is the same as the expected number of failures after the $0^\text{th}$ trial and before the first success, for any $n$.
$\mathsf E(X\mid X>0)$ is the expected count of failures before the first success given that the first trial was a failure. That will be the first trial plus the expected count of failures after that first trial and before the first success. That is: $1+\mathsf E(X)$.