To factor $ 1+x+xy+x^2y $ we can use factoring by grouping.
Group $ \color{blue}{ 1 }$ with $ \color{blue}{ x }$ and $ \color{red}{ xy }$ with $ \color{red}{ x^2y }$ then factor each group.
$$ \begin{aligned} 1+x+xy+x^2y &= ( \color{blue}{ 1+x } ) + ( \color{red}{ xy+x^2y }) = \\ &= \color{blue}{ 1( 1+x )} + \color{red}{ xy( 1+x ) } = \\ &= (1+xy)(1+x) \end{aligned} $$