animation_manager.c 23 KB

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