@ -24,7 +24,9 @@ import net.pokeranalytics.android.calculus.optimalduration.CashGameOptimalDurati
import net.pokeranalytics.android.exceptions.PAIllegalStateException
import net.pokeranalytics.android.model.LiveData
import net.pokeranalytics.android.model.extensions.SessionState
import net.pokeranalytics.android.model.extensions.cancelStopNotification
import net.pokeranalytics.android.model.extensions.getState
import net.pokeranalytics.android.model.extensions.scheduleStopNotification
import net.pokeranalytics.android.model.interfaces.SaveValidityStatus
import net.pokeranalytics.android.model.realm.Location
import net.pokeranalytics.android.model.realm.Session
@ -266,6 +268,7 @@ class SessionFragment : RealmFragment(), RowRepresentableDelegate {
SessionRow . BUY _IN , SessionRow . TIPS , SessionRow . START _DATE ,
SessionRow . END _DATE , SessionRow . BANKROLL , SessionRow . BREAK _TIME -> updateSessionUI ( )
}
}
/ * *
@ -401,8 +404,8 @@ class SessionFragment : RealmFragment(), RowRepresentableDelegate {
if ( !is Detached ) {
optimalDuration ?. let {
val delay = it . toLong ( )
scheduleNotification ( delay , " stop notif tag " )
val delay = 5000L //it.toLong( )
currentSession . scheduleStop Notification ( requireContext ( ) , delay )
val formattedDuration = ( it / 3600 / 1000 ) . formattedHourlyDuration ( )
Timber . d ( " Setting stop notification in: $formattedDuration " )
@ -414,29 +417,11 @@ class SessionFragment : RealmFragment(), RowRepresentableDelegate {
}
private fun scheduleNotification ( timeDelay : Long , tag : String ) {
val title = requireContext ( ) . getString ( R . string . stop _notification _title )
val body = requireContext ( ) . getString ( R . string . stop _notification _body )
val data = Data . Builder ( )
. putString ( NotificationSchedule . ParamKeys . TITLE . value , title )
. putString ( NotificationSchedule . ParamKeys . BODY . value , body )
val work = OneTimeWorkRequestBuilder < NotificationSchedule > ( )
. setInitialDelay ( timeDelay , TimeUnit . MILLISECONDS )
. setInputData ( data . build ( ) )
. addTag ( tag )
. build ( )
WorkManager . getInstance ( requireContext ( ) ) . enqueue ( work )
}
/ * *
* Stop the current session
* /
private fun stopSession ( ) {
currentSession . stop ( )
this . currentSession . stop ( requireContext ( ) )
updateSessionUI ( )
}
@ -463,6 +448,8 @@ class SessionFragment : RealmFragment(), RowRepresentableDelegate {
* Delete a session
* /
private fun deleteSession ( ) {
this . currentSession . cancelStopNotification ( requireContext ( ) )
this . currentSession . bankroll ?. id ?. let { bankrollId ->
BankrollReportManager . notifyBankrollReportImpact ( bankrollId )
}