package Ġcom . sm k . pub lik . mak ass ar . account . presentation . password Ċ Ċ import Ġandroidx . lifecycle . LiveData Ċ import Ġandroidx . lifecycle . Mutable LiveData Ċ import Ġcom . google . firebase . crash ly t ics . k tx . crash ly t ics Ċ import Ġcom . google . firebase . k tx . Firebase Ċ import Ġcom . or h ano but . logger . Logger Ċ import Ġcom . sm k . pub lik . mak ass ar . account . data . Password Repository Ċ import Ġcom . sm k . pub lik . mak ass ar . account . domain . Password Ċ import Ġcom . sm k . pub lik . mak ass ar . core . domain . State Ċ import Ġcom . sm k . pub lik . mak ass ar . core . presentation . Base ViewModel Ċ import Ġkotlinx . coroutines . flow . Mutable State Flow Ċ import Ġkotlinx . coroutines . flow . State Flow Ċ import Ġkotlinx . coroutines . flow . catch Ċ import Ġkotlinx . coroutines . flow . collect Ċ import Ġkotlinx . coroutines . launch Ċ Ċ /* Ċ Ġ* ĠCopyright Ġ( c ) Ġ 2 0 2 1 ĠDesign ed Ġand Ġdeveloped Ġby ĠJose ph ĠSan j aya , ĠS . T ., ĠM . K om ., ĠAll ĠRights ĠReserved . Ċ Ġ* Ġ@ Github Ġ( https :// github . com / J ose ph San j aya ), Ċ Ġ* Ġ@ Linked In Ġ( https :// www . linkedin . com / in / j ose ph san j aya / )) Ċ Ġ*/ Ċ Ċ class ĠPassword ViewModel ( ĊĠĠĠ Ġprivate Ġval Ġrepository : ĠPassword Repository Ċ ) Ġ: ĠBase ViewModel () Ġ{ ĊĊĠĠĠ Ġprivate Ġval Ġ_ send Forgot Ġ= ĠMutable State Flow < State < Boolean >>( State . Idle ()) ĊĠĠĠ Ġval Ġsend Forgot : ĠState Flow < State < Boolean >> Ġget () Ġ= Ġ_ send Forgot ĊĊĠĠĠ Ġfun Ġreset Send Forgot State () Ġ{ ĊĠĠĠĠĠĠĠ Ġ_ send Forgot . value Ġ= ĠState . Idle () ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġfun Ġsend Forgot Password ( email : ĠString ) Ġ= Ġdefault Scope . launch Ġ{ ĊĠĠĠĠĠĠĠ Ġrepository . send Password Reset Email ( email ) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. catch Ġ{ Ġ_ send Forgot . emit ( State . Failed ( get HttpException ( it ))) Ġ} ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. collect Ġ{ Ġ_ send Forgot . emit ( it ) Ġ} ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġprivate Ġval Ġ_ verify Code Password Ġ= ĠMutable State Flow < State < String >>( State . Idle ()) ĊĠĠĠ Ġval Ġverify Code Password : ĠState Flow < State < String >> Ġget () Ġ= Ġ_ verify Code Password ĊĊĠĠĠ Ġfun Ġreset Verify Code Password State () Ġ{ ĊĠĠĠĠĠĠĠ Ġ_ verify Code Password . value Ġ= ĠState . Idle () ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġfun Ġverify Code Password ( code : ĠString ) Ġ= Ġdefault Scope . launch Ġ{ ĊĠĠĠĠĠĠĠ Ġrepository . verify Password Reset Code ( code ) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. catch Ġ{ Ġ_ verify Code Password . emit ( State . Failed ( get HttpException ( it ))) Ġ} ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. collect Ġ{ Ġ_ verify Code Password . emit ( it ) Ġ} ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġprivate Ġval Ġ_ confirm Reset Ġ= ĠMutable State Flow < State < Boolean >>( State . Idle ()) ĊĠĠĠ Ġval Ġconfirm Reset : ĠState Flow < State < Boolean >> Ġget () Ġ= Ġ_ confirm Reset ĊĊĠĠĠ Ġfun Ġreset Confirm Reset State () Ġ{ ĊĠĠĠĠĠĠĠ Ġ_ confirm Reset . value Ġ= ĠState . Idle () ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġfun Ġconfirm Password Reset ( code : ĠString , Ġemail : ĠString ) Ġ= Ġdefault Scope . launch Ġ{ ĊĠĠĠĠĠĠĠ Ġrepository . confirm Password Reset ( code , Ġemail ) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. catch Ġ{ Ġ_ confirm Reset . emit ( State . Failed ( get HttpException ( it ))) Ġ} ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. collect Ġ{ Ġ_ confirm Reset . emit ( it ) Ġ} ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġprivate Ġval Ġ_ change Password Ġ= ĠMutable State Flow < State < Boolean >>( State . Idle ()) ĊĠĠĠ Ġval Ġchange Password : ĠState Flow < State < Boolean >> Ġget () Ġ= Ġ_ change Password ĊĊĠĠĠ Ġfun Ġreset Change Password State () Ġ{ ĊĠĠĠĠĠĠĠ Ġ_ change Password . value Ġ= ĠState . Idle () ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġfun Ġchange Password ( old Password : ĠString , Ġnew Password : ĠString ) Ġ= Ġdefault Scope . launch Ġ{ ĊĠĠĠĠĠĠĠ Ġrepository . change Password ( old Password , Ġnew Password ) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. catch Ġ{ Ġ_ change Password . emit ( State . Failed ( get HttpException ( it ))) Ġ} ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. collect Ġ{ Ġ_ change Password . emit ( it ) Ġ} ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġprivate Ġval Ġ_ validation Ġ= ĠMutable LiveData < Pair < List < Password ? >, ĠBoolean >>() ĊĠĠĠ Ġval Ġm Validation : ĠLive Data < Pair < List < Password ? >, ĠBoolean >> Ġget () Ġ= Ġ_ validation ĊĊĠĠĠ Ġfun Ġpassword Validation ( password : ĠString ) Ġ= Ġdefault Scope . launch Ġ{ ĊĠĠĠĠĠĠĠ Ġrepository . validate Password ( password ). catch Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ ĠFirebase . crash ly t ics . record Exception ( it ) ĊĠĠĠĠĠĠĠĠĠĠĠ ĠLogger . e ( it , Ġ" Error ĠValid asi ĠPassword ") ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. collect Ġ{ Ġ_ validation . post Value ( it ) Ġ} ĊĠĠĠ Ġ} Ċ } Ċ