animation_manager.c 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574
  1. #include <gui/view_stack.h>
  2. #include <stdint.h>
  3. #include <furi.h>
  4. #include <furi_hal.h>
  5. #include <portmacro.h>
  6. #include <dolphin/dolphin.h>
  7. #include <power/power_service/power.h>
  8. #include <storage/storage.h>
  9. #include <assets_icons.h>
  10. #include "views/bubble_animation_view.h"
  11. #include "views/one_shot_animation_view.h"
  12. #include "animation_storage.h"
  13. #include "animation_manager.h"
  14. #define TAG "AnimationManager"
  15. #define HARDCODED_ANIMATION_NAME "L1_Tv_128x47"
  16. #define NO_SD_ANIMATION_NAME "L1_NoSd_128x49"
  17. #define BAD_BATTERY_ANIMATION_NAME "L1_BadBattery_128x47"
  18. #define NO_DB_ANIMATION_NAME "L0_NoDb_128x51"
  19. #define BAD_SD_ANIMATION_NAME "L0_SdBad_128x51"
  20. #define SD_OK_ANIMATION_NAME "L0_SdOk_128x51"
  21. #define URL_ANIMATION_NAME "L0_Url_128x51"
  22. #define NEW_MAIL_ANIMATION_NAME "L0_NewMail_128x51"
  23. typedef enum {
  24. AnimationManagerStateIdle,
  25. AnimationManagerStateBlocked,
  26. AnimationManagerStateFreezedIdle,
  27. AnimationManagerStateFreezedBlocked,
  28. } AnimationManagerState;
  29. struct AnimationManager {
  30. bool sd_show_url;
  31. bool sd_shown_no_db;
  32. bool sd_shown_sd_ok;
  33. bool levelup_pending;
  34. bool levelup_active;
  35. AnimationManagerState state;
  36. FuriPubSubSubscription* pubsub_subscription_storage;
  37. FuriPubSubSubscription* pubsub_subscription_dolphin;
  38. BubbleAnimationView* animation_view;
  39. OneShotView* one_shot_view;
  40. FuriTimer* idle_animation_timer;
  41. StorageAnimation* current_animation;
  42. AnimationManagerInteractCallback interact_callback;
  43. AnimationManagerSetNewIdleAnimationCallback new_idle_callback;
  44. AnimationManagerSetNewIdleAnimationCallback check_blocking_callback;
  45. void* context;
  46. FuriString* freezed_animation_name;
  47. int32_t freezed_animation_time_left;
  48. ViewStack* view_stack;
  49. };
  50. static StorageAnimation*
  51. animation_manager_select_idle_animation(AnimationManager* animation_manager);
  52. static void animation_manager_replace_current_animation(
  53. AnimationManager* animation_manager,
  54. StorageAnimation* storage_animation);
  55. static void animation_manager_start_new_idle(AnimationManager* animation_manager);
  56. static bool animation_manager_check_blocking(AnimationManager* animation_manager);
  57. static bool animation_manager_is_valid_idle_animation(
  58. const StorageAnimationManifestInfo* info,
  59. const DolphinStats* stats);
  60. static void animation_manager_switch_to_one_shot_view(AnimationManager* animation_manager);
  61. static void animation_manager_switch_to_animation_view(AnimationManager* animation_manager);
  62. void animation_manager_set_context(AnimationManager* animation_manager, void* context) {
  63. furi_assert(animation_manager);
  64. animation_manager->context = context;
  65. }
  66. void animation_manager_set_new_idle_callback(
  67. AnimationManager* animation_manager,
  68. AnimationManagerSetNewIdleAnimationCallback callback) {
  69. furi_assert(animation_manager);
  70. animation_manager->new_idle_callback = callback;
  71. }
  72. void animation_manager_set_check_callback(
  73. AnimationManager* animation_manager,
  74. AnimationManagerCheckBlockingCallback callback) {
  75. furi_assert(animation_manager);
  76. animation_manager->check_blocking_callback = callback;
  77. }
  78. void animation_manager_set_interact_callback(
  79. AnimationManager* animation_manager,
  80. AnimationManagerInteractCallback callback) {
  81. furi_assert(animation_manager);
  82. animation_manager->interact_callback = callback;
  83. }
  84. static void animation_manager_check_blocking_callback(const void* message, void* context) {
  85. const StorageEvent* storage_event = message;
  86. switch(storage_event->type) {
  87. case StorageEventTypeCardMount:
  88. case StorageEventTypeCardUnmount:
  89. case StorageEventTypeCardMountError:
  90. furi_assert(context);
  91. AnimationManager* animation_manager = context;
  92. if(animation_manager->check_blocking_callback) {
  93. animation_manager->check_blocking_callback(animation_manager->context);
  94. }
  95. break;
  96. default:
  97. break;
  98. }
  99. }
  100. static void animation_manager_timer_callback(void* context) {
  101. furi_assert(context);
  102. AnimationManager* animation_manager = context;
  103. if(animation_manager->new_idle_callback) {
  104. animation_manager->new_idle_callback(animation_manager->context);
  105. }
  106. }
  107. static void animation_manager_interact_callback(void* context) {
  108. furi_assert(context);
  109. AnimationManager* animation_manager = context;
  110. if(animation_manager->interact_callback) {
  111. animation_manager->interact_callback(animation_manager->context);
  112. }
  113. }
  114. /* reaction to animation_manager->check_blocking_callback() */
  115. void animation_manager_check_blocking_process(AnimationManager* animation_manager) {
  116. furi_assert(animation_manager);
  117. if(animation_manager->state == AnimationManagerStateIdle) {
  118. bool blocked = animation_manager_check_blocking(animation_manager);
  119. if(!blocked) {
  120. Dolphin* dolphin = furi_record_open(RECORD_DOLPHIN);
  121. DolphinStats stats = dolphin_stats(dolphin);
  122. furi_record_close(RECORD_DOLPHIN);
  123. const StorageAnimationManifestInfo* manifest_info =
  124. animation_storage_get_meta(animation_manager->current_animation);
  125. bool valid = animation_manager_is_valid_idle_animation(manifest_info, &stats);
  126. if(!valid) {
  127. animation_manager_start_new_idle(animation_manager);
  128. }
  129. }
  130. }
  131. }
  132. /* reaction to animation_manager->new_idle_callback() */
  133. void animation_manager_new_idle_process(AnimationManager* animation_manager) {
  134. furi_assert(animation_manager);
  135. if(animation_manager->state == AnimationManagerStateIdle) {
  136. animation_manager_start_new_idle(animation_manager);
  137. }
  138. }
  139. /* reaction to animation_manager->interact_callback() */
  140. bool animation_manager_interact_process(AnimationManager* animation_manager) {
  141. furi_assert(animation_manager);
  142. bool consumed = true;
  143. if(animation_manager->levelup_pending) {
  144. animation_manager->levelup_pending = false;
  145. animation_manager->levelup_active = true;
  146. animation_manager_switch_to_one_shot_view(animation_manager);
  147. Dolphin* dolphin = furi_record_open(RECORD_DOLPHIN);
  148. dolphin_upgrade_level(dolphin);
  149. furi_record_close(RECORD_DOLPHIN);
  150. } else if(animation_manager->levelup_active) {
  151. animation_manager->levelup_active = false;
  152. animation_manager_start_new_idle(animation_manager);
  153. animation_manager_switch_to_animation_view(animation_manager);
  154. } else if(animation_manager->state == AnimationManagerStateBlocked) {
  155. bool blocked = animation_manager_check_blocking(animation_manager);
  156. if(!blocked) {
  157. animation_manager_start_new_idle(animation_manager);
  158. }
  159. } else {
  160. consumed = false;
  161. }
  162. return consumed;
  163. }
  164. static void animation_manager_start_new_idle(AnimationManager* animation_manager) {
  165. furi_assert(animation_manager);
  166. StorageAnimation* new_animation = animation_manager_select_idle_animation(animation_manager);
  167. animation_manager_replace_current_animation(animation_manager, new_animation);
  168. const BubbleAnimation* bubble_animation =
  169. animation_storage_get_bubble_animation(animation_manager->current_animation);
  170. animation_manager->state = AnimationManagerStateIdle;
  171. furi_timer_start(animation_manager->idle_animation_timer, bubble_animation->duration * 1000);
  172. }
  173. static bool animation_manager_check_blocking(AnimationManager* animation_manager) {
  174. furi_assert(animation_manager);
  175. StorageAnimation* blocking_animation = NULL;
  176. Storage* storage = furi_record_open(RECORD_STORAGE);
  177. FS_Error sd_status = storage_sd_status(storage);
  178. if(sd_status == FSE_INTERNAL) {
  179. blocking_animation = animation_storage_find_animation(BAD_SD_ANIMATION_NAME);
  180. furi_assert(blocking_animation);
  181. } else if(sd_status == FSE_NOT_READY) {
  182. animation_manager->sd_shown_sd_ok = false;
  183. animation_manager->sd_shown_no_db = false;
  184. } else if(sd_status == FSE_OK) {
  185. if(!animation_manager->sd_shown_sd_ok) {
  186. blocking_animation = animation_storage_find_animation(SD_OK_ANIMATION_NAME);
  187. furi_assert(blocking_animation);
  188. animation_manager->sd_shown_sd_ok = true;
  189. } else if(!animation_manager->sd_shown_no_db) {
  190. if(!storage_file_exists(storage, EXT_PATH("Manifest"))) {
  191. blocking_animation = animation_storage_find_animation(NO_DB_ANIMATION_NAME);
  192. furi_assert(blocking_animation);
  193. animation_manager->sd_shown_no_db = true;
  194. animation_manager->sd_show_url = true;
  195. }
  196. } else if(animation_manager->sd_show_url) {
  197. blocking_animation = animation_storage_find_animation(URL_ANIMATION_NAME);
  198. furi_assert(blocking_animation);
  199. animation_manager->sd_show_url = false;
  200. }
  201. }
  202. Dolphin* dolphin = furi_record_open(RECORD_DOLPHIN);
  203. DolphinStats stats = dolphin_stats(dolphin);
  204. furi_record_close(RECORD_DOLPHIN);
  205. if(!blocking_animation && stats.level_up_is_pending) {
  206. blocking_animation = animation_storage_find_animation(NEW_MAIL_ANIMATION_NAME);
  207. furi_assert(blocking_animation);
  208. if(blocking_animation) {
  209. animation_manager->levelup_pending = true;
  210. }
  211. }
  212. if(blocking_animation) {
  213. furi_timer_stop(animation_manager->idle_animation_timer);
  214. animation_manager_replace_current_animation(animation_manager, blocking_animation);
  215. /* no timer starting because this is blocking animation */
  216. animation_manager->state = AnimationManagerStateBlocked;
  217. }
  218. furi_record_close(RECORD_STORAGE);
  219. return !!blocking_animation;
  220. }
  221. static void animation_manager_replace_current_animation(
  222. AnimationManager* animation_manager,
  223. StorageAnimation* storage_animation) {
  224. furi_assert(storage_animation);
  225. StorageAnimation* previous_animation = animation_manager->current_animation;
  226. const BubbleAnimation* animation = animation_storage_get_bubble_animation(storage_animation);
  227. bubble_animation_view_set_animation(animation_manager->animation_view, animation);
  228. const char* new_name = animation_storage_get_meta(storage_animation)->name;
  229. FURI_LOG_I(TAG, "Select \'%s\' animation", new_name);
  230. animation_manager->current_animation = storage_animation;
  231. if(previous_animation) {
  232. animation_storage_free_storage_animation(&previous_animation);
  233. }
  234. }
  235. AnimationManager* animation_manager_alloc(void) {
  236. AnimationManager* animation_manager = malloc(sizeof(AnimationManager));
  237. animation_manager->animation_view = bubble_animation_view_alloc();
  238. animation_manager->view_stack = view_stack_alloc();
  239. View* animation_view = bubble_animation_get_view(animation_manager->animation_view);
  240. view_stack_add_view(animation_manager->view_stack, animation_view);
  241. animation_manager->freezed_animation_name = furi_string_alloc();
  242. animation_manager->idle_animation_timer =
  243. furi_timer_alloc(animation_manager_timer_callback, FuriTimerTypeOnce, animation_manager);
  244. bubble_animation_view_set_interact_callback(
  245. animation_manager->animation_view, animation_manager_interact_callback, animation_manager);
  246. Storage* storage = furi_record_open(RECORD_STORAGE);
  247. animation_manager->pubsub_subscription_storage = furi_pubsub_subscribe(
  248. storage_get_pubsub(storage), animation_manager_check_blocking_callback, animation_manager);
  249. furi_record_close(RECORD_STORAGE);
  250. Dolphin* dolphin = furi_record_open(RECORD_DOLPHIN);
  251. animation_manager->pubsub_subscription_dolphin = furi_pubsub_subscribe(
  252. dolphin_get_pubsub(dolphin), animation_manager_check_blocking_callback, animation_manager);
  253. furi_record_close(RECORD_DOLPHIN);
  254. animation_manager->sd_shown_sd_ok = true;
  255. if(!animation_manager_check_blocking(animation_manager)) {
  256. animation_manager_start_new_idle(animation_manager);
  257. }
  258. return animation_manager;
  259. }
  260. void animation_manager_free(AnimationManager* animation_manager) {
  261. furi_assert(animation_manager);
  262. Dolphin* dolphin = furi_record_open(RECORD_DOLPHIN);
  263. furi_pubsub_unsubscribe(
  264. dolphin_get_pubsub(dolphin), animation_manager->pubsub_subscription_dolphin);
  265. furi_record_close(RECORD_DOLPHIN);
  266. Storage* storage = furi_record_open(RECORD_STORAGE);
  267. furi_pubsub_unsubscribe(
  268. storage_get_pubsub(storage), animation_manager->pubsub_subscription_storage);
  269. furi_record_close(RECORD_STORAGE);
  270. furi_string_free(animation_manager->freezed_animation_name);
  271. View* animation_view = bubble_animation_get_view(animation_manager->animation_view);
  272. view_stack_remove_view(animation_manager->view_stack, animation_view);
  273. bubble_animation_view_free(animation_manager->animation_view);
  274. furi_timer_free(animation_manager->idle_animation_timer);
  275. }
  276. View* animation_manager_get_animation_view(AnimationManager* animation_manager) {
  277. furi_assert(animation_manager);
  278. return view_stack_get_view(animation_manager->view_stack);
  279. }
  280. static bool animation_manager_is_valid_idle_animation(
  281. const StorageAnimationManifestInfo* info,
  282. const DolphinStats* stats) {
  283. furi_assert(info);
  284. furi_assert(info->name);
  285. bool result = true;
  286. if(!strcmp(info->name, BAD_BATTERY_ANIMATION_NAME)) {
  287. Power* power = furi_record_open(RECORD_POWER);
  288. bool battery_is_well = power_is_battery_healthy(power);
  289. furi_record_close(RECORD_POWER);
  290. result = !battery_is_well;
  291. }
  292. if(!strcmp(info->name, NO_SD_ANIMATION_NAME)) {
  293. Storage* storage = furi_record_open(RECORD_STORAGE);
  294. FS_Error sd_status = storage_sd_status(storage);
  295. furi_record_close(RECORD_STORAGE);
  296. result = (sd_status == FSE_NOT_READY);
  297. }
  298. if((stats->butthurt < info->min_butthurt) || (stats->butthurt > info->max_butthurt)) {
  299. result = false;
  300. }
  301. if((stats->level < info->min_level) || (stats->level > info->max_level)) {
  302. result = false;
  303. }
  304. return result;
  305. }
  306. static StorageAnimation*
  307. animation_manager_select_idle_animation(AnimationManager* animation_manager) {
  308. UNUSED(animation_manager);
  309. StorageAnimationList_t animation_list;
  310. StorageAnimationList_init(animation_list);
  311. animation_storage_fill_animation_list(&animation_list);
  312. Dolphin* dolphin = furi_record_open(RECORD_DOLPHIN);
  313. DolphinStats stats = dolphin_stats(dolphin);
  314. furi_record_close(RECORD_DOLPHIN);
  315. uint32_t whole_weight = 0;
  316. StorageAnimationList_it_t it;
  317. for(StorageAnimationList_it(it, animation_list); !StorageAnimationList_end_p(it);) {
  318. StorageAnimation* storage_animation = *StorageAnimationList_ref(it);
  319. const StorageAnimationManifestInfo* manifest_info =
  320. animation_storage_get_meta(storage_animation);
  321. bool valid = animation_manager_is_valid_idle_animation(manifest_info, &stats);
  322. if(valid) {
  323. whole_weight += manifest_info->weight;
  324. StorageAnimationList_next(it);
  325. } else {
  326. animation_storage_free_storage_animation(&storage_animation);
  327. /* remove and increase iterator */
  328. StorageAnimationList_remove(animation_list, it);
  329. }
  330. }
  331. uint32_t lucky_number = furi_hal_random_get() % whole_weight;
  332. uint32_t weight = 0;
  333. StorageAnimation* selected = NULL;
  334. for
  335. M_EACH(item, animation_list, StorageAnimationList_t) {
  336. if(lucky_number < weight) {
  337. break;
  338. }
  339. weight += animation_storage_get_meta(*item)->weight;
  340. selected = *item;
  341. }
  342. for
  343. M_EACH(item, animation_list, StorageAnimationList_t) {
  344. if(*item != selected) {
  345. animation_storage_free_storage_animation(item);
  346. }
  347. }
  348. StorageAnimationList_clear(animation_list);
  349. /* cache animation, if failed - choose reliable animation */
  350. if(!animation_storage_get_bubble_animation(selected)) {
  351. const char* name = animation_storage_get_meta(selected)->name;
  352. FURI_LOG_E(TAG, "Can't upload animation described in manifest: \'%s\'", name);
  353. animation_storage_free_storage_animation(&selected);
  354. selected = animation_storage_find_animation(HARDCODED_ANIMATION_NAME);
  355. }
  356. furi_assert(selected);
  357. return selected;
  358. }
  359. bool animation_manager_is_animation_loaded(AnimationManager* animation_manager) {
  360. furi_assert(animation_manager);
  361. return animation_manager->current_animation;
  362. }
  363. void animation_manager_unload_and_stall_animation(AnimationManager* animation_manager) {
  364. furi_assert(animation_manager);
  365. furi_assert(animation_manager->current_animation);
  366. furi_assert(!furi_string_size(animation_manager->freezed_animation_name));
  367. furi_assert(
  368. (animation_manager->state == AnimationManagerStateIdle) ||
  369. (animation_manager->state == AnimationManagerStateBlocked));
  370. if(animation_manager->state == AnimationManagerStateBlocked) {
  371. animation_manager->state = AnimationManagerStateFreezedBlocked;
  372. } else if(animation_manager->state == AnimationManagerStateIdle) {
  373. animation_manager->state = AnimationManagerStateFreezedIdle;
  374. animation_manager->freezed_animation_time_left =
  375. xTimerGetExpiryTime(animation_manager->idle_animation_timer) - xTaskGetTickCount();
  376. if(animation_manager->freezed_animation_time_left < 0) {
  377. animation_manager->freezed_animation_time_left = 0;
  378. }
  379. furi_timer_stop(animation_manager->idle_animation_timer);
  380. } else {
  381. furi_assert(0);
  382. }
  383. FURI_LOG_I(
  384. TAG,
  385. "Unload animation \'%s\'",
  386. animation_storage_get_meta(animation_manager->current_animation)->name);
  387. StorageAnimationManifestInfo* meta =
  388. animation_storage_get_meta(animation_manager->current_animation);
  389. /* copy str, not move, because it can be internal animation */
  390. furi_string_set(animation_manager->freezed_animation_name, meta->name);
  391. bubble_animation_freeze(animation_manager->animation_view);
  392. animation_storage_free_storage_animation(&animation_manager->current_animation);
  393. }
  394. void animation_manager_load_and_continue_animation(AnimationManager* animation_manager) {
  395. furi_assert(animation_manager);
  396. furi_assert(!animation_manager->current_animation);
  397. furi_assert(furi_string_size(animation_manager->freezed_animation_name));
  398. furi_assert(
  399. (animation_manager->state == AnimationManagerStateFreezedIdle) ||
  400. (animation_manager->state == AnimationManagerStateFreezedBlocked));
  401. if(animation_manager->state == AnimationManagerStateFreezedBlocked) {
  402. StorageAnimation* restore_animation = animation_storage_find_animation(
  403. furi_string_get_cstr(animation_manager->freezed_animation_name));
  404. /* all blocked animations must be in flipper -> we can
  405. * always find blocking animation */
  406. furi_assert(restore_animation);
  407. animation_manager_replace_current_animation(animation_manager, restore_animation);
  408. animation_manager->state = AnimationManagerStateBlocked;
  409. } else if(animation_manager->state == AnimationManagerStateFreezedIdle) {
  410. /* check if we missed some system notifications, and set current_animation */
  411. bool blocked = animation_manager_check_blocking(animation_manager);
  412. if(!blocked) {
  413. /* if no blocking - try restore last one idle */
  414. StorageAnimation* restore_animation = animation_storage_find_animation(
  415. furi_string_get_cstr(animation_manager->freezed_animation_name));
  416. if(restore_animation) {
  417. Dolphin* dolphin = furi_record_open(RECORD_DOLPHIN);
  418. DolphinStats stats = dolphin_stats(dolphin);
  419. furi_record_close(RECORD_DOLPHIN);
  420. const StorageAnimationManifestInfo* manifest_info =
  421. animation_storage_get_meta(restore_animation);
  422. bool valid = animation_manager_is_valid_idle_animation(manifest_info, &stats);
  423. if(valid) {
  424. animation_manager_replace_current_animation(
  425. animation_manager, restore_animation);
  426. animation_manager->state = AnimationManagerStateIdle;
  427. if(animation_manager->freezed_animation_time_left) {
  428. furi_timer_start(
  429. animation_manager->idle_animation_timer,
  430. animation_manager->freezed_animation_time_left);
  431. } else {
  432. const BubbleAnimation* animation = animation_storage_get_bubble_animation(
  433. animation_manager->current_animation);
  434. furi_timer_start(
  435. animation_manager->idle_animation_timer, animation->duration * 1000);
  436. }
  437. }
  438. } else {
  439. FURI_LOG_E(
  440. TAG,
  441. "Failed to restore \'%s\'",
  442. furi_string_get_cstr(animation_manager->freezed_animation_name));
  443. }
  444. }
  445. } else {
  446. /* Unknown state is an error. But not in release version.*/
  447. furi_assert(0);
  448. }
  449. /* if can't restore previous animation - select new */
  450. if(!animation_manager->current_animation) {
  451. animation_manager_start_new_idle(animation_manager);
  452. }
  453. FURI_LOG_I(
  454. TAG,
  455. "Load animation \'%s\'",
  456. animation_storage_get_meta(animation_manager->current_animation)->name);
  457. bubble_animation_unfreeze(animation_manager->animation_view);
  458. furi_string_reset(animation_manager->freezed_animation_name);
  459. furi_assert(animation_manager->current_animation);
  460. }
  461. static void animation_manager_switch_to_one_shot_view(AnimationManager* animation_manager) {
  462. furi_assert(animation_manager);
  463. furi_assert(!animation_manager->one_shot_view);
  464. Dolphin* dolphin = furi_record_open(RECORD_DOLPHIN);
  465. DolphinStats stats = dolphin_stats(dolphin);
  466. furi_record_close(RECORD_DOLPHIN);
  467. animation_manager->one_shot_view = one_shot_view_alloc();
  468. one_shot_view_set_interact_callback(
  469. animation_manager->one_shot_view, animation_manager_interact_callback, animation_manager);
  470. View* prev_view = bubble_animation_get_view(animation_manager->animation_view);
  471. View* next_view = one_shot_view_get_view(animation_manager->one_shot_view);
  472. view_stack_remove_view(animation_manager->view_stack, prev_view);
  473. view_stack_add_view(animation_manager->view_stack, next_view);
  474. if(stats.level == 1) {
  475. one_shot_view_start_animation(animation_manager->one_shot_view, &A_Levelup1_128x64);
  476. } else if(stats.level == 2) {
  477. one_shot_view_start_animation(animation_manager->one_shot_view, &A_Levelup2_128x64);
  478. } else {
  479. furi_assert(0);
  480. }
  481. }
  482. static void animation_manager_switch_to_animation_view(AnimationManager* animation_manager) {
  483. furi_assert(animation_manager);
  484. furi_assert(animation_manager->one_shot_view);
  485. View* prev_view = one_shot_view_get_view(animation_manager->one_shot_view);
  486. View* next_view = bubble_animation_get_view(animation_manager->animation_view);
  487. view_stack_remove_view(animation_manager->view_stack, prev_view);
  488. view_stack_add_view(animation_manager->view_stack, next_view);
  489. one_shot_view_free(animation_manager->one_shot_view);
  490. animation_manager->one_shot_view = NULL;
  491. }