diff --git a/matrixConsole/View/RoomTitleView.h b/matrixConsole/View/RoomTitleView.h index d44b4091a..1c8857517 100644 --- a/matrixConsole/View/RoomTitleView.h +++ b/matrixConsole/View/RoomTitleView.h @@ -31,6 +31,7 @@ - (void)dismissKeyboard; - (void)startTopicAnimation; -- (void)stopTopicAnimation; +// return YES if the animation has been stopped +- (BOOL)stopTopicAnimation; @end \ No newline at end of file diff --git a/matrixConsole/View/RoomTitleView.m b/matrixConsole/View/RoomTitleView.m index 277855e5a..f24e0b7b6 100644 --- a/matrixConsole/View/RoomTitleView.m +++ b/matrixConsole/View/RoomTitleView.m @@ -26,12 +26,26 @@ // do not start the topic animation asap NSTimer * animationTimer; + + // restart a killed animation when the application is debackgrounded + BOOL restartAnimationWhenActive; } @property (weak, nonatomic) IBOutlet NSLayoutConstraint *displayNameTextFieldTopConstraint; @end @implementation RoomTitleView +- (id) initWithCoder:(NSCoder *)aDecoder { + self = [super initWithCoder:aDecoder]; + + if (self) { + [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(appEnteredBackground) name:UIApplicationDidEnterBackgroundNotification object:nil]; + [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(appEnteredForeground) name:UIApplicationWillEnterForegroundNotification object:nil]; + } + + return self; +} + - (void)dealloc { if (messagesListener && _mxRoom) { [_mxRoom removeListener:messagesListener]; @@ -41,6 +55,21 @@ // stop any animation [self stopTopicAnimation]; + + [[NSNotificationCenter defaultCenter] removeObserver:self name:UIApplicationDidEnterBackgroundNotification object:nil]; + [[NSNotificationCenter defaultCenter] removeObserver:self name:UIApplicationWillEnterForegroundNotification object:nil]; +} + + +- (void)appEnteredBackground { + restartAnimationWhenActive = [self stopTopicAnimation]; +} + +- (void)appEnteredForeground { + if (restartAnimationWhenActive) { + [self startTopicAnimation]; + restartAnimationWhenActive = NO; + } } - (void)refreshDisplay { @@ -179,7 +208,7 @@ }]; } -- (void)stopTopicAnimation { +- (BOOL)stopTopicAnimation { // stop running timers if (animationTimer) { [animationTimer invalidate]; @@ -196,7 +225,11 @@ label = nil; [self addSubview:_topicTextField]; + + return YES; } + + return NO; } - (void)dismissKeyboard { @@ -209,7 +242,7 @@ [self startTopicAnimation]; } -- (void) setFrame:(CGRect)frame { +- (void)setFrame:(CGRect)frame { // restart only if there is a frame update BOOL restartAnimation = !CGRectEqualToRect(CGRectIntegral(frame), CGRectIntegral(self.frame));