package Ġcom . s jn . stamp . model . dao Ċ Ċ import Ġcom . s jn . stamp . model . Song Ċ import Ġcom . s jn . stamp . model . Song History Ċ import Ġcom . s jn . stamp . model . constant . Record Type Ċ import Ġio . realm . Realm Ċ import Ġio . realm . Sort Ċ import Ġjava . util .* ĊĊ Ċ object ĠSong History Dao Ġ: ĠBase Dao < Song History >() Ġ{ ĊĊĠĠĠ Ġfun Ġwhere ( realm : ĠRealm , Ġfrom : ĠDate ?, Ġto : ĠDate ?, Ġrecord Type : ĠString ): ĠList < Song History > Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġquery Ġ= Ġrealm . where ( Song History :: class . java ). equalTo (" record Type ", Ġrecord Type ) ĊĠĠĠĠĠĠĠ Ġif Ġ( from Ġ!= Ġnull ) Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġquery . greater Than OrEqualTo (" re corded At ", Ġfrom ) ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠĠĠĠĠ Ġif Ġ( to Ġ!= Ġnull ) Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġquery . less Than OrEqualTo (" re corded At ", Ġto ) ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠĠĠĠĠ Ġreturn Ġquery . findAll () Ġ?: Ġempty List () ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġfun Ġis Exists ( realm : ĠRealm ): ĠBoolean Ġ= Ġrealm . where ( Song History :: class . java ). findFirst () Ġ!= Ġnull ĊĊĠĠĠ Ġfun Ġtimeline ( realm : ĠRealm , Ġrecord Type : ĠString ): ĠList < Song History > Ġ= ĊĠĠĠĠĠĠĠĠĠĠĠ ĠfindAll ( realm , Ġrecord Type ) ĊĊĠĠĠ Ġfun ĠfindAll ( realm : ĠRealm , Ġrecord Type : ĠString ): ĠList < Song History > Ġ= ĊĠĠĠĠĠĠĠĠĠĠĠ Ġrealm . where ( Song History :: class . java ). equalTo (" record Type ", Ġrecord Type ). findAll Sorted (" re corded At ", ĠSort . DESC ENDING ) ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ?: Ġempty List () ĊĊĠĠĠ Ġfun Ġfind Play Record By Artist ( realm : ĠRealm , Ġartist Name : ĠString ): ĠList < Song History > Ġ= ĊĠĠĠĠĠĠĠĠĠĠĠ Ġrealm . where ( Song History :: class . java ). equalTo (" record Type ", ĠRecord Type . PLAY . database Value ). equalTo (" song . artist . name ", Ġartist Name ). findAll () ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ?: Ġempty List () ĊĊĠĠĠ Ġfun Ġfind Ol dest By Artist ( realm : ĠRealm , Ġartist Name : ĠString ): ĠSong History ? Ġ= ĊĠĠĠĠĠĠĠĠĠĠĠ Ġrealm . where ( Song History :: class . java ). equalTo (" record Type ", ĠRecord Type . PLAY . database Value ). equalTo (" song . artist . name ", Ġartist Name ). findAll Sorted (" re corded At ", ĠSort . ASC ENDING ). first () ĊĊĠĠĠ Ġfun Ġfind Ol dest ( realm : ĠRealm , Ġsong Id : ĠLong ): ĠSong History ? Ġ= ĊĠĠĠĠĠĠĠĠĠĠĠ Ġrealm . where ( Song History :: class . java ). equalTo (" song . id ", Ġsong Id ). equalTo (" record Type ", ĠRecord Type . PLAY . database Value ). findAll Sorted (" re corded At ", ĠSort . ASC ENDING ). first () ĊĊĠĠĠ Ġfun Ġcreate ( realm : ĠRealm , Ġraw Song : ĠSong , Ġrecord Type : ĠRecord Type , Ġdate : ĠDate , Ġcount : ĠInt ) Ġ{ ĊĠĠĠĠĠĠĠ ĠSong Dao . findById ( realm , Ġraw Song . id )?. let Ġ{ Ġsong Ġ-> ĊĠĠĠĠĠĠĠĠĠĠĠ Ġrealm . execute Transaction Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġrealm . copy To Realm ( Song History (). apply Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġthis . id Ġ= Ġget Auto Increment Id ( realm ) ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġthis . device Ġ= ĠDevice Dao . find OrCreate ( realm ) ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġthis . record Type Ġ= Ġrecord Type . database Value ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġthis . re corded At Ġ= Ġdate ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġthis . count Ġ= Ġcount ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġthis . song Ġ= Ġsong ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ}) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ} ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġfun Ġdelete ( realm : ĠRealm , Ġsong History Id : ĠLong ) Ġ{ ĊĠĠĠĠĠĠĠ Ġrealm . execute Transaction Async Ġ{ Ġr Ġ-> Ġr . where ( Song History :: class . java ). equalTo (" id ", Ġsong History Id ). findFirst (). delete From Realm () Ġ} ĊĠĠĠ Ġ} Ċ Ċ }