package Ġme . anon . grow Ċ Ċ import Ġandroid . os . Bundle Ċ import Ġandroid . view . View Ċ import Ġandroidx . appcompat . app . AlertDialog Ċ import Ġandroidx . appcompat . widget . Toolbar Ċ import Ġme . anon . grow . fragment . Water ing Fragment Ċ import Ġme . anon . lib . manager . Plant Manager Ċ Ċ class ĠEdit Water ing Activity Ġ: ĠBase Activity () Ċ { Ċ ĉ private Ġvar Ġplant Index : ĠInt Ġ= Ġ- 1 Ċ ĉ private Ġvar Ġfeed ing Index : ĠInt Ġ= Ġ- 1 ĊĊ ĉ override Ġfun ĠonCreate ( savedInstanceState : ĠBundle ?) Ċ ĉ { Ċĉ ĉ super . onCreate ( savedInstanceState ) ĊĊĉ ĉ set ContentView ( R . layout . fragment _ holder ) Ċĉ ĉ set Support ActionBar ( findViewById < View >( R . id . toolbar ) Ġas ĠToolbar ) Ċĉ ĉ setTitle ( R . string . edit _ feed ing ) ĊĊĉ ĉ plant Index Ġ= Ġ- 1 Ċĉ ĉ feed ing Index Ġ= Ġ- 1 ĊĊĉ ĉ if Ġ( intent . extras Ġ!= Ġnull ) Ċĉ ĉ { Ċĉĉ ĉ plant Index Ġ= Ġintent . extras !!. getInt (" plant _ index ", Ġ- 1 ) Ċĉĉ ĉ feed ing Index Ġ= Ġintent . extras !!. getInt (" action _ index ", Ġ- 1 ) Ċĉ ĉ } ĊĊĉ ĉ if Ġ( plant Index Ġ< Ġ 0 ) Ċĉ ĉ { Ċĉĉ ĉ finish () Ċĉĉ ĉ return Ċĉ ĉ } ĊĊĉ ĉ if Ġ( support FragmentManager . find Fragment By Tag (" fragment ") Ġ== Ġnull ) Ċĉ ĉ { Ċĉĉ ĉ support FragmentManager . beginTransaction () Ċĉĉĉ ĉ . replace ( R . id . fragment _ holder , ĠWater ing Fragment . newInstance ( int ArrayOf ( plant Index ), Ġfeed ing Index , Ġ- 1 ), Ġ" fragment ") Ċĉĉĉ ĉ . commit () Ċĉ ĉ } Ċ ĉ } ĊĊ ĉ override Ġfun Ġon Back Pressed () Ċ ĉ { Ċĉ ĉ AlertDialog . Builder ( this ) Ċĉĉ ĉ . setTitle ( R . string . confirm _ title ) Ċĉĉ ĉ . setMessage ( R . string . confirm _ quit ) Ċĉĉ ĉ . set Positive Button ( R . string . accept _ quit , Ġ{ Ġindex , Ġdialog Ġ-> Ċĉĉĉ ĉ if Ġ( intent . extras ?. getBoolean (" new _ water ") Ġ== Ġtrue ) Ċĉĉĉ ĉ { Ċĉĉĉĉ ĉ Plant Manager . instance . pl ants [ plant Index ]. actions ?. remove At ( feed ing Index ) Ċĉĉĉ ĉ } ĊĊĉĉĉ ĉ super . on Back Pressed () Ċĉĉ ĉ }) Ċĉĉ ĉ . set Negative Button ( R . string . cancel , Ġnull ) Ċĉĉ ĉ . show () Ċ ĉ } Ċ } Ċ